UNPKG

@frontify/fondue-charts

Version:

Frontify's data viz library

41 lines (40 loc) • 1.35 kB
import { useState as k, useEffect as p } from "react"; import { truncateTextLabel as u } from "../../BarChart/helpers/truncateText.es.js"; import { getSVGTextDimensions as O } from "../helpers/getSVGTextDimensions.es.js"; const b = { bottom: 24, left: 52.265625, right: 20, top: 10 }, S = ({ ticks: t, tickLabelStyle: e, valueFormatter: s, maxLabelLength: o }) => t.reduce((a, n) => { const r = s ? u(s(n), o) : u(String(n), o), i = O(r, e).width ?? 0; return Math.max(a, i); }, 0), x = ({ tickLabelStyle: t, tickLength: e }) => { const s = typeof t.dx == "string" ? parseFloat(t.dx) : t.dx ?? 0; return e + Math.abs(s); }, F = (t) => { const { tickLabelStyle: e, ticks: s, valueFormatter: o, tickLength: a, maxLabelHeight: n = 6, firstLabelOverflowsBy: r = 0, maxLabelLength: i } = t, [L, d] = k(b), f = x({ tickLabelStyle: e, tickLength: a }), g = JSON.stringify(s), l = JSON.stringify(e); return p(() => { const m = JSON.parse(g), h = JSON.parse(l); let c = S({ ticks: m, tickLabelStyle: h, tickLength: m.length, valueFormatter: o, maxLabelLength: i }) + f; r > c && (c = r), d({ top: 10, right: 20, bottom: n + 18, left: c }); }, [g, l, o, n, r, f, i]), L; }; export { F as useMargin }; //# sourceMappingURL=useMargin.es.js.map