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