UNPKG

@frontify/fondue-charts

Version:

Frontify's data viz library

60 lines (59 loc) • 1.86 kB
import { jsxs as s, jsx as o } from "react/jsx-runtime"; import { useTooltipInPortal as y } from "@visx/tooltip"; import { useState as h } from "react"; import { LinearGaugeTooltip as P } from "./components/LinearGaugeTooltip.es.js"; import { Section as T } from "./components/Section.es.js"; import { Legend as L } from "../common/components/Legend.es.js"; import { colorAccessorByIndex as S } from "../common/helpers/accessors.es.js"; import "@visx/scale"; import c from "./LinearGauge.module.scss.es.js"; const M = ({ sections: r, totalLabel: l, totalValue: m }) => { const { containerRef: p, TooltipInPortal: f } = y({ scroll: !0 }), [n, a] = h(null), u = r.map(({ name: e }) => e), i = r.map((e, t) => ({ color: S(t) ?? "var(--fc-primary-base-color)", title: e.name, value: e.label })); l && i.unshift({ color: "", title: l, value: m }); const d = (e) => { const t = e.currentTarget.parentElement, v = (t == null ? void 0 : t.getBoundingClientRect().left) ?? 0, x = (t == null ? void 0 : t.getBoundingClientRect().top) ?? 0; a({ x: e.clientX - v, y: e.clientY - x }); }, g = () => { a(null); }; return /* @__PURE__ */ s("div", { ref: p, children: [ /* @__PURE__ */ s("div", { className: c.stack, children: [ /* @__PURE__ */ o(L, { names: u, style: "square" }), /* @__PURE__ */ o( "div", { onPointerMove: (e) => d(e), onPointerLeave: g, className: c.bar, children: r.map((e, t) => /* @__PURE__ */ o(T, { index: t, percentage: e.percentage }, e.name)) } ) ] }), n !== null && /* @__PURE__ */ o( P, { TooltipInPortal: f, x: n.x, y: n.y, entries: i } ) ] }); }; export { M as LinearGauge }; //# sourceMappingURL=LinearGauge.es.js.map