UNPKG

@frontify/fondue-charts

Version:

Frontify's data viz library

98 lines (97 loc) • 3.58 kB
import { jsxs as L, jsx as r } from "react/jsx-runtime"; import { XYChart as O, Grid as _ } from "@visx/xychart"; import { useState as n } from "react"; import { BandwidthAdjuster as w } from "./components/BandwidthAdjuster.es.js"; import { getInitialBandTicks as D } from "./helpers/getInitialBandTicks.es.js"; import { Legend as y } from "../common/components/Legend.es.js"; import { colorAccessorByKey as H } from "../common/helpers/accessors.es.js"; import { getLinearScaleTicks as M } from "../common/helpers/getLinearScaleTicks.es.js"; import { getNonZeroLinearScaleDomain as R } from "../common/helpers/getNonZeroLinearScaleDomain.es.js"; import { useMargin as v } from "../common/hooks/useMargin.es.js"; import { BASE_COLORS as N } from "../../theme/consts.es.js"; import { createTheme as j } from "../../theme/createTheme.es.js"; import C from "./BarChart.module.scss.es.js"; import { Axes as F } from "./components/Axes.es.js"; import { Bars as G } from "./components/Bars.es.js"; import { Tooltip as U } from "../common/components/Tooltip/Tooltip.es.js"; const I = 5, K = (e) => String(e), Y = (e) => e, ce = ({ series: e, height: T, width: S, horizontal: t = !1, displayStyle: l = "default", hideLegend: p = !1, allowDecimalTickValues: k = !0, legendPosition: d = "top", valueFormatter: s = K, labelFormatter: f = Y, onBarClick: g }) => { const [b, A] = n(0), [u, x] = n(0), [B, E] = n(() => D(e)), a = l === "overlapped" ? 0.2 : 0, c = j(N), i = R(e, 0), m = M(i, I, k), h = v({ ticks: t ? B : m, tickLabelStyle: c.axisStyles.y.left.tickLabel, tickLength: c.axisStyles.y.left.tickLength, valueFormatter: s, maxLabelHeight: b, firstLabelOverflowsBy: u }); return /* @__PURE__ */ L("div", { className: C.root, children: [ !p && d === "top" && /* @__PURE__ */ r(y, { style: "rectangle", names: e.map((o) => o.name) }), /* @__PURE__ */ r("span", { className: g ? "bar-chart-cursor-pointer" : "", children: /* @__PURE__ */ L( O, { theme: c, width: S, height: T, horizontal: t, xScale: t ? { type: "linear", padding: a, domain: i } : { type: "band", padding: a }, yScale: t ? { type: "band", padding: a } : { type: "linear", padding: a, domain: i }, margin: h, onPointerDown: g, children: [ /* @__PURE__ */ r(w, { horizontal: t }), /* @__PURE__ */ r( _, { rows: !t, columns: t, numTicks: m.length - 1, stroke: "var(--fc-grid-stroke-color)" }, "grid" ), /* @__PURE__ */ r( F, { linearAxesTicks: m, horizontal: t, updateFirstLabelOverflowsBy: x, updateMaxLabelHeight: A, updateBandScaleTicks: E, valueFormatter: s, labelFormatter: f } ), /* @__PURE__ */ r(G, { series: e, horizontal: t, displayStyle: l }), /* @__PURE__ */ r( U, { crossHairStyle: "bar", hideGlyphs: !0, colorAccessor: (o) => H(o, e), horizontal: t, scalePadding: a, valueFormatter: s, labelFormatter: f } ) ] } ) }), !p && d === "bottom" && /* @__PURE__ */ r(y, { style: "rectangle", names: e.map((o) => o.name) }) ] }); }; export { ce as BarChart }; //# sourceMappingURL=BarChart.es.js.map