UNPKG

@frontify/fondue-charts

Version:

Frontify's data viz library

64 lines (63 loc) • 2.17 kB
import { jsxs as L, jsx as r } from "react/jsx-runtime"; import { Group as y } from "@visx/group"; import { Pie as R } from "@visx/shape"; import { useState as S, useRef as $ } from "react"; import { DEFAULT_PADDING as j } from "./consts.es.js"; import { useResponsiveChart as C } from "./hooks/useResponsiveChart.es.js"; import { Legend as F } from "../common/components/Legend.es.js"; import { colorAccessorByIndex as G } from "../common/helpers/accessors.es.js"; import "@visx/scale"; import I from "./PieChart.module.scss.es.js"; import { Arc as N } from "./components/Arc.es.js"; const k = ({ size: p, data: t, valueFormatter: u, showLabelTitle: c = !1, showLabelValue: f = !1, showLabelPercentage: g = !1, shouldSortData: h = !1 }) => { const [v, b] = S(j), s = $(null), { radius: i, labelStyle: n, center: a, width: A, height: P } = C(p, s, v), m = t.filter((e) => e.value > 0), d = m.length > 0 ? m : t, D = h ? d.sort((e, l) => l.value - e.value) : d; return /* @__PURE__ */ L("div", { ref: s, className: I.root, children: [ /* @__PURE__ */ r("svg", { width: A, height: P, children: /* @__PURE__ */ r(y, { top: a[1], left: a[0], children: /* @__PURE__ */ r( R, { data: D, pieValue: (e) => e.value, outerRadius: i, pieSort: null, pieSortValues: null, children: ({ arcs: e, path: l }) => /* @__PURE__ */ r("g", { children: e.map((o, x) => /* @__PURE__ */ r( N, { arc: o, previousArc: e[x - 1], numberOfArcs: e.length, radius: i, isLabelHidden: n === "legend", showLabelValue: f, showLabelPercentage: g, showLabelTitle: c, path: l, setPaddingForLabels: b, valueFormatter: u }, `${o.startAngle}-${o.index}-${o.value}-${o.data.label}` )) }) } ) }) }), n === "legend" && /* @__PURE__ */ r( F, { names: t.map((e) => e.label), style: "circle", colorAccessor: G } ) ] }); }; export { k as PieChart }; //# sourceMappingURL=PieChart.es.js.map