UNPKG

@frontify/fondue-charts

Version:

Frontify's data viz library

84 lines (83 loc) • 2.66 kB
import { jsxs as f, jsx as e } from "react/jsx-runtime"; import { Treemap as P, treemapBinary as g } from "@visx/hierarchy"; import { useTooltipInPortal as k } from "@visx/tooltip"; import { useRef as q, useState as l } from "react"; import { colorAccessor as w } from "./helpers/accessors.es.js"; import { transformToHierarchyData as H } from "./helpers/transformers.es.js"; import { useDataGroupedBySize as O } from "./hooks/useDataGroupedBySize.es.js"; import { Legend as W } from "../common/components/Legend.es.js"; import T from "./Treemap.module.scss.es.js"; import { Nodes as $ } from "./components/Nodes/Nodes.es.js"; import { TreemapTooltip as C } from "./components/TreemapTooltip/TreemapTooltip.es.js"; const I = ({ data: h, childSumLabel: y, missingValueLabel: N = "", colorLabelMap: o, valueFormatter: D, width: n, height: a, legendItems: r, sizeThresholds: G = { mobile: 20, desktop: 15 } }) => { var c, u; const { containerRef: R, TooltipInPortal: S } = k({ scroll: !0 }), v = q(null), [i, z] = l(null), [s, x] = l(null), { groupedData: B, wasGrouped: m } = O(h, s, o), j = H(B), A = m && s === 0 || s !== null && !m, p = r == null ? void 0 : r.map((t) => t.label); return /* @__PURE__ */ f("div", { className: T.root, children: [ p && p.length > 0 && /* @__PURE__ */ e( W, { names: p, style: "square", colorAccessor: (t) => { var d; return w((d = r == null ? void 0 : r[t]) == null ? void 0 : d.color); } } ), /* @__PURE__ */ e("div", { ref: v, className: T.chartWrapper, children: /* @__PURE__ */ f("svg", { width: n, height: a, ref: R, children: [ /* @__PURE__ */ e( P, { top: 0, root: j, size: [n - 1, a - 1], tile: g, round: !0, paddingOuter: 3, paddingInner: 1, children: (t) => /* @__PURE__ */ e( $, { treemap: t, setTooltipState: z, setSizeThreshold: x, isReadyToBeRendered: A, sizeThresholds: G } ) } ), i !== null && /* @__PURE__ */ e( C, { TooltipInPortal: S, childSumLabel: y, missingValueLabel: N, valueFormatter: D, groupformatter: (u = o == null ? void 0 : o[((c = i.activeNode.parent) == null ? void 0 : c.data.color) || ""]) == null ? void 0 : u.group, colorLabelMap: o, ...i } ) ] }) }) ] }); }; export { I as Treemap }; //# sourceMappingURL=Treemap.es.js.map