@adoptai/genui-components 0.1.54 → 0.1.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6650,6 +6650,14 @@ init_ThemeContext();
6650
6650
  var TERRACOTTA = ACCENT;
6651
6651
  var POS = "#15803d";
6652
6652
  var NEG = "#dc2626";
6653
+ var _CURRENCY = /* @__PURE__ */ new Set(["$", "\u20AC", "\xA3", "\xA5", "\u20B9"]);
6654
+ function _abbrev(n) {
6655
+ const a = Math.abs(n);
6656
+ if (a >= 1e9) return `${(a / 1e9).toFixed(1).replace(/\.0$/, "")}B`;
6657
+ if (a >= 1e6) return `${(a / 1e6).toFixed(1).replace(/\.0$/, "")}M`;
6658
+ if (a >= 1e3) return `${(a / 1e3).toFixed(1).replace(/\.0$/, "")}K`;
6659
+ return `${a}`;
6660
+ }
6653
6661
  var tooltipStyle3 = {
6654
6662
  fontSize: "12px",
6655
6663
  borderRadius: "8px",
@@ -6664,6 +6672,15 @@ function WaterfallChartResolver(p) {
6664
6672
  const { isVisible, toggle } = useSeriesToggle(["Positive", "Negative", "Total"]);
6665
6673
  const unit = (_a2 = p.unit) != null ? _a2 : "";
6666
6674
  const bars = (_b = p.bars) != null ? _b : [];
6675
+ const fmtVal = (v, withSign = false) => {
6676
+ const sign = v < 0 ? "-" : withSign && v > 0 ? "+" : "";
6677
+ const body = _CURRENCY.has(unit) ? `${unit}${_abbrev(v)}` : `${_abbrev(v)}${unit}`;
6678
+ return `${sign}${body}`;
6679
+ };
6680
+ const yAxisWidth = Math.min(
6681
+ 72,
6682
+ Math.max(40, ...bars.map((b) => fmtVal(b.value).length * 7 + 8))
6683
+ );
6667
6684
  let running = 0;
6668
6685
  const chartData = bars.map((bar) => {
6669
6686
  const base = bar.isTotal ? 0 : running;
@@ -6673,7 +6690,7 @@ function WaterfallChartResolver(p) {
6673
6690
  }).filter((d) => isVisible(d.category));
6674
6691
  return /* @__PURE__ */ jsx(ComponentActions, { filename: (_c = p.title) != null ? _c : "waterfall-chart", children: /* @__PURE__ */ jsxs("div", { style: { width: "100%", display: "flex", flexDirection: "column", gap: "12px" }, children: [
6675
6692
  p.title && /* @__PURE__ */ jsx("p", { style: { fontFamily: "var(--font-serif)", fontSize: "15px", fontWeight: 600, color: "var(--foreground)", letterSpacing: "-0.005em" }, children: p.title }),
6676
- /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: 200, children: /* @__PURE__ */ jsxs(BarChart, { data: chartData, margin: { top: 4, right: 8, left: 0, bottom: 0 }, children: [
6693
+ /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: 200, children: /* @__PURE__ */ jsxs(BarChart, { data: chartData, margin: { top: 4, right: 8, left: 4, bottom: 0 }, children: [
6677
6694
  /* @__PURE__ */ jsx(
6678
6695
  XAxis,
6679
6696
  {
@@ -6689,17 +6706,14 @@ function WaterfallChartResolver(p) {
6689
6706
  tick: { fontSize: 11, fill: MUTED2 },
6690
6707
  axisLine: false,
6691
6708
  tickLine: false,
6692
- width: 42,
6693
- tickFormatter: (v) => `${v}${unit}`
6709
+ width: yAxisWidth,
6710
+ tickFormatter: (v) => fmtVal(Number(v))
6694
6711
  }
6695
6712
  ),
6696
6713
  /* @__PURE__ */ jsx(
6697
6714
  Tooltip,
6698
6715
  {
6699
- formatter: (value) => {
6700
- const v = Number(value);
6701
- return [`${v > 0 ? "+" : ""}${v}${unit}`, ""];
6702
- },
6716
+ formatter: (value) => [fmtVal(Number(value), true), ""],
6703
6717
  contentStyle: tooltipStyle3,
6704
6718
  cursor: { fill: "#f2f2f2" }
6705
6719
  }