@anuma/sdk 11.0.1 → 11.1.0
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/react/index.cjs +323 -54
- package/dist/react/index.d.mts +5 -1
- package/dist/react/index.d.ts +5 -1
- package/dist/react/index.mjs +324 -54
- package/dist/tools/index.cjs +23 -2
- package/dist/tools/index.d.mts +4 -1
- package/dist/tools/index.d.ts +4 -1
- package/dist/tools/index.mjs +23 -2
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -36448,7 +36448,8 @@ function ChartTooltipContent({
|
|
|
36448
36448
|
formatter,
|
|
36449
36449
|
color,
|
|
36450
36450
|
nameKey,
|
|
36451
|
-
labelKey
|
|
36451
|
+
labelKey,
|
|
36452
|
+
valueFormatter
|
|
36452
36453
|
}) {
|
|
36453
36454
|
const { config } = useChart();
|
|
36454
36455
|
const tooltipLabel = React2.useMemo(() => {
|
|
@@ -36515,7 +36516,7 @@ function ChartTooltipContent({
|
|
|
36515
36516
|
nestLabel ? tooltipLabel : null,
|
|
36516
36517
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-muted-foreground", children: itemConfig?.label || item.name })
|
|
36517
36518
|
] }),
|
|
36518
|
-
item.value && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-foreground font-
|
|
36519
|
+
item.value !== void 0 && item.value !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-foreground font-medium tabular-nums", children: valueFormatter && typeof item.value === "number" ? valueFormatter(item.value) : item.value.toLocaleString() })
|
|
36519
36520
|
]
|
|
36520
36521
|
}
|
|
36521
36522
|
)
|
|
@@ -36561,7 +36562,7 @@ function ChartLegendContent({
|
|
|
36561
36562
|
style: { backgroundColor: item.color }
|
|
36562
36563
|
}
|
|
36563
36564
|
),
|
|
36564
|
-
itemConfig?.label
|
|
36565
|
+
itemConfig?.label ?? cellText(item.value)
|
|
36565
36566
|
]
|
|
36566
36567
|
},
|
|
36567
36568
|
String(item.value)
|
|
@@ -36588,19 +36589,16 @@ var DEFAULT_COLORS = [
|
|
|
36588
36589
|
"var(--chart-4)",
|
|
36589
36590
|
"var(--chart-5)"
|
|
36590
36591
|
];
|
|
36592
|
+
var SURFACE = "var(--chart-surface)";
|
|
36593
|
+
var DOT_LIMIT = 12;
|
|
36594
|
+
var MAX_TICKS = 8;
|
|
36595
|
+
var MINUS = "\u2212";
|
|
36591
36596
|
function paletteColor(index) {
|
|
36592
36597
|
return index < DEFAULT_COLORS.length ? DEFAULT_COLORS[index] : `hsl(${Math.round(index * 137.508 % 360)} 65% 55%)`;
|
|
36593
36598
|
}
|
|
36594
|
-
var compactNumber = new Intl.NumberFormat(void 0, {
|
|
36595
|
-
notation: "compact",
|
|
36596
|
-
maximumSignificantDigits: 3
|
|
36597
|
-
});
|
|
36598
36599
|
function cellText(value) {
|
|
36599
36600
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
36600
36601
|
}
|
|
36601
|
-
function formatTick(value) {
|
|
36602
|
-
return typeof value === "number" ? compactNumber.format(value) : String(value);
|
|
36603
|
-
}
|
|
36604
36602
|
var VISUALLY_HIDDEN = {
|
|
36605
36603
|
position: "absolute",
|
|
36606
36604
|
width: 1,
|
|
@@ -36612,6 +36610,90 @@ var VISUALLY_HIDDEN = {
|
|
|
36612
36610
|
whiteSpace: "nowrap",
|
|
36613
36611
|
border: 0
|
|
36614
36612
|
};
|
|
36613
|
+
function tickDigits(ticks) {
|
|
36614
|
+
if (!ticks || ticks.length < 2) return 3;
|
|
36615
|
+
const step = ticks[1] - ticks[0];
|
|
36616
|
+
const magnitude = Math.max(...ticks.map(Math.abs));
|
|
36617
|
+
if (step <= 0 || magnitude === 0) return 3;
|
|
36618
|
+
const needed = Math.floor(Math.log10(magnitude)) - Math.floor(Math.log10(step)) + 1;
|
|
36619
|
+
return Math.min(21, Math.max(3, needed));
|
|
36620
|
+
}
|
|
36621
|
+
function keepSmall(options) {
|
|
36622
|
+
const small = new Intl.NumberFormat(void 0, { ...options, maximumSignificantDigits: 3 });
|
|
36623
|
+
const regular = new Intl.NumberFormat(void 0, { ...options, maximumFractionDigits: 2 });
|
|
36624
|
+
return (n, format) => format(n !== 0 && Math.abs(n) < 1 ? small : regular, n);
|
|
36625
|
+
}
|
|
36626
|
+
function buildFormatters(format, currency, ticks) {
|
|
36627
|
+
const digits = tickDigits(ticks);
|
|
36628
|
+
if (format === "currency") {
|
|
36629
|
+
const money = (options) => new Intl.NumberFormat(void 0, {
|
|
36630
|
+
style: "currency",
|
|
36631
|
+
currency: currency ?? "USD",
|
|
36632
|
+
...options
|
|
36633
|
+
});
|
|
36634
|
+
const compact2 = money({ notation: "compact", maximumSignificantDigits: 3 });
|
|
36635
|
+
const tick2 = money({ notation: "compact", maximumSignificantDigits: digits });
|
|
36636
|
+
const small2 = money({ maximumSignificantDigits: 4 });
|
|
36637
|
+
const cents = money({ minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
36638
|
+
const value2 = (n) => Math.abs(n) >= 1e6 ? compact2.format(n) : n !== 0 && Math.abs(n) < 1 ? small2.format(n) : cents.format(n);
|
|
36639
|
+
return { tick: (n) => tick2.format(n), value: value2, change: (d) => value2(Math.abs(d)) };
|
|
36640
|
+
}
|
|
36641
|
+
if (format === "percent") {
|
|
36642
|
+
const percent = keepSmall({ style: "percent" });
|
|
36643
|
+
const points = keepSmall({});
|
|
36644
|
+
const tick2 = new Intl.NumberFormat(void 0, {
|
|
36645
|
+
style: "percent",
|
|
36646
|
+
maximumSignificantDigits: digits
|
|
36647
|
+
});
|
|
36648
|
+
return {
|
|
36649
|
+
tick: (n) => tick2.format(n / 100),
|
|
36650
|
+
value: (n) => percent(n, (formatter) => formatter.format(n / 100)),
|
|
36651
|
+
change: (d) => `${points(Math.abs(d), (formatter, n) => formatter.format(n))} pts`
|
|
36652
|
+
};
|
|
36653
|
+
}
|
|
36654
|
+
const tick = new Intl.NumberFormat(void 0, {
|
|
36655
|
+
notation: "compact",
|
|
36656
|
+
maximumSignificantDigits: digits
|
|
36657
|
+
});
|
|
36658
|
+
const compact = new Intl.NumberFormat(void 0, {
|
|
36659
|
+
notation: "compact",
|
|
36660
|
+
maximumSignificantDigits: 3
|
|
36661
|
+
});
|
|
36662
|
+
const small = new Intl.NumberFormat(void 0, { maximumSignificantDigits: 4 });
|
|
36663
|
+
const plain2 = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 });
|
|
36664
|
+
const value = (n) => Math.abs(n) >= 1e6 ? compact.format(n) : n !== 0 && Math.abs(n) < 1 ? small.format(n) : plain2.format(n);
|
|
36665
|
+
return { tick: (n) => tick.format(n), value, change: (d) => value(Math.abs(d)) };
|
|
36666
|
+
}
|
|
36667
|
+
function seriesValues(points, keys) {
|
|
36668
|
+
return points.flatMap(
|
|
36669
|
+
(point) => keys.map((key3) => point[key3]).filter((v) => typeof v === "number")
|
|
36670
|
+
);
|
|
36671
|
+
}
|
|
36672
|
+
function niceStep(rough) {
|
|
36673
|
+
const exponent = Math.floor(Math.log10(rough));
|
|
36674
|
+
const base = 10 ** exponent;
|
|
36675
|
+
const fraction = rough / base;
|
|
36676
|
+
const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
|
|
36677
|
+
return nice * base;
|
|
36678
|
+
}
|
|
36679
|
+
function niceTicks(values) {
|
|
36680
|
+
if (values.length === 0) return void 0;
|
|
36681
|
+
const min = Math.min(...values);
|
|
36682
|
+
const max = Math.max(...values);
|
|
36683
|
+
const span = max - min || Math.abs(max) * 0.02 || 1;
|
|
36684
|
+
const low = min - span * 0.1;
|
|
36685
|
+
const high = max + span * 0.1;
|
|
36686
|
+
const step = niceStep((high - low) / 3);
|
|
36687
|
+
const start = min >= 0 ? Math.max(0, Math.floor(low / step) * step) : Math.floor(low / step) * step;
|
|
36688
|
+
const ticks = [];
|
|
36689
|
+
for (let index = 0; index <= MAX_TICKS; index++) {
|
|
36690
|
+
const tick = Number((start + index * step).toPrecision(15));
|
|
36691
|
+
if (ticks.length > 0 && tick <= ticks[ticks.length - 1]) break;
|
|
36692
|
+
ticks.push(tick);
|
|
36693
|
+
if (tick >= high) break;
|
|
36694
|
+
}
|
|
36695
|
+
return ticks.length >= 2 ? ticks : void 0;
|
|
36696
|
+
}
|
|
36615
36697
|
function buildChartConfig(dataKeys, colors) {
|
|
36616
36698
|
const config = {};
|
|
36617
36699
|
dataKeys.forEach((key3, i) => {
|
|
@@ -36623,9 +36705,71 @@ function buildChartConfig(dataKeys, colors) {
|
|
|
36623
36705
|
});
|
|
36624
36706
|
return config;
|
|
36625
36707
|
}
|
|
36708
|
+
function lastValueIndex(points, key3) {
|
|
36709
|
+
for (let index = points.length - 1; index >= 0; index--) {
|
|
36710
|
+
if (typeof points[index][key3] === "number") return index;
|
|
36711
|
+
}
|
|
36712
|
+
return -1;
|
|
36713
|
+
}
|
|
36714
|
+
function usePrefersReducedMotion() {
|
|
36715
|
+
const [reduced, setReduced] = React2.useState(false);
|
|
36716
|
+
React2.useEffect(() => {
|
|
36717
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
|
36718
|
+
const query = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
36719
|
+
setReduced(query.matches);
|
|
36720
|
+
const onChange = (event) => setReduced(event.matches);
|
|
36721
|
+
query.addEventListener?.("change", onChange);
|
|
36722
|
+
return () => query.removeEventListener?.("change", onChange);
|
|
36723
|
+
}, []);
|
|
36724
|
+
return reduced;
|
|
36725
|
+
}
|
|
36726
|
+
function buildTrend(values, format, formatters) {
|
|
36727
|
+
if (values.length < 2) return void 0;
|
|
36728
|
+
const first = values[0];
|
|
36729
|
+
const last = values[values.length - 1];
|
|
36730
|
+
const difference = last - first;
|
|
36731
|
+
const direction = difference > 0 ? "up" : difference < 0 ? "down" : "flat";
|
|
36732
|
+
const sign = direction === "up" ? "+" : direction === "down" ? MINUS : "";
|
|
36733
|
+
const percent = format !== "percent" && first !== 0 ? ` (${sign}${new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }).format(
|
|
36734
|
+
Math.abs(difference / Math.abs(first) * 100)
|
|
36735
|
+
)}%)` : "";
|
|
36736
|
+
return {
|
|
36737
|
+
value: formatters.value(last),
|
|
36738
|
+
change: `${sign}${formatters.change(difference)}${percent}`,
|
|
36739
|
+
direction
|
|
36740
|
+
};
|
|
36741
|
+
}
|
|
36742
|
+
var TREND_CLASS = {
|
|
36743
|
+
up: "text-emerald-600 dark:text-emerald-400",
|
|
36744
|
+
down: "text-red-600 dark:text-red-400",
|
|
36745
|
+
flat: "text-muted-foreground"
|
|
36746
|
+
};
|
|
36747
|
+
var TREND_ARROW = { up: "\u25B2", down: "\u25BC", flat: "" };
|
|
36748
|
+
function ChartHeader({
|
|
36749
|
+
title,
|
|
36750
|
+
trend,
|
|
36751
|
+
range
|
|
36752
|
+
}) {
|
|
36753
|
+
if (!trend) {
|
|
36754
|
+
return title ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mb-3 text-sm font-medium", children: title }) : null;
|
|
36755
|
+
}
|
|
36756
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mb-3", "data-testid": "chart-header", children: [
|
|
36757
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-sm text-muted-foreground", children: title }),
|
|
36758
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mt-0.5 text-2xl font-semibold tracking-tight text-foreground", children: trend.value }),
|
|
36759
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "mt-0.5 flex flex-wrap items-center gap-x-1.5 text-xs", children: [
|
|
36760
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: cx("font-medium", TREND_CLASS[trend.direction]), children: [
|
|
36761
|
+
TREND_ARROW[trend.direction] && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-hidden": "true", className: "mr-1 text-[0.6rem]", children: TREND_ARROW[trend.direction] }),
|
|
36762
|
+
trend.change
|
|
36763
|
+
] }),
|
|
36764
|
+
range && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-muted-foreground", children: range })
|
|
36765
|
+
] })
|
|
36766
|
+
] });
|
|
36767
|
+
}
|
|
36626
36768
|
function ChartCard({ data }) {
|
|
36627
36769
|
const containerRef = React2.useRef(null);
|
|
36628
36770
|
const [ready, setReady] = React2.useState(false);
|
|
36771
|
+
const gradientId = `chart-fill-${React2.useId().replace(/:/g, "")}`;
|
|
36772
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
36629
36773
|
React2.useEffect(() => {
|
|
36630
36774
|
const frame = requestAnimationFrame(() => setReady(true));
|
|
36631
36775
|
return () => cancelAnimationFrame(frame);
|
|
@@ -36633,25 +36777,84 @@ function ChartCard({ data }) {
|
|
|
36633
36777
|
if ("error" in data) {
|
|
36634
36778
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "my-4 max-w-lg", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rounded-xl bg-sidebar dark:bg-card px-4 py-3", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-sm text-muted-foreground", children: "Couldn't display this chart." }) }) });
|
|
36635
36779
|
}
|
|
36636
|
-
const {
|
|
36780
|
+
const {
|
|
36781
|
+
chartType,
|
|
36782
|
+
title,
|
|
36783
|
+
data: chartData,
|
|
36784
|
+
dataKeys,
|
|
36785
|
+
xAxisKey,
|
|
36786
|
+
colors,
|
|
36787
|
+
valueFormat,
|
|
36788
|
+
currency
|
|
36789
|
+
} = data;
|
|
36637
36790
|
const chartConfig = buildChartConfig(dataKeys, colors);
|
|
36638
36791
|
const seriesColor = (key3) => chartConfig[key3]?.color;
|
|
36639
|
-
const
|
|
36640
|
-
|
|
36641
|
-
|
|
36642
|
-
|
|
36643
|
-
|
|
36644
|
-
|
|
36792
|
+
const isTrendChart = chartType === "line" || chartType === "area";
|
|
36793
|
+
const plottedKeys = chartType === "pie" ? dataKeys.slice(0, 1) : dataKeys;
|
|
36794
|
+
const values = seriesValues(chartData, plottedKeys);
|
|
36795
|
+
const yTicks = isTrendChart ? niceTicks(values) : void 0;
|
|
36796
|
+
const yDomain = yTicks ? [yTicks[0], yTicks[yTicks.length - 1]] : void 0;
|
|
36797
|
+
const formatters = buildFormatters(valueFormat, currency, yTicks);
|
|
36798
|
+
const trend = isTrendChart && dataKeys.length === 1 ? buildTrend(values, valueFormat, formatters) : void 0;
|
|
36799
|
+
const trendRows = trend ? chartData.filter((point) => typeof point[dataKeys[0]] === "number") : [];
|
|
36800
|
+
const range = trend && xAxisKey ? [trendRows[0], trendRows[trendRows.length - 1]].map((point) => cellText(point[xAxisKey])).filter(Boolean).join(" \u2013 ") : void 0;
|
|
36801
|
+
const headerTitle = title ?? (trend ? chartConfig[dataKeys[0]]?.label : void 0);
|
|
36802
|
+
const tickSamples = [...yDomain ?? [], ...values].map((value) => formatters.tick(value));
|
|
36803
|
+
const longestTick = tickSamples.reduce((max, label) => Math.max(max, label.length), 0);
|
|
36804
|
+
const animate = !reducedMotion;
|
|
36805
|
+
const showDots = chartData.length <= DOT_LIMIT;
|
|
36806
|
+
const curve = showDots ? "linear" : "monotone";
|
|
36807
|
+
const hasNegative = values.some((value) => value < 0);
|
|
36808
|
+
const margin = { top: 8, right: 8, bottom: 0, left: 0 };
|
|
36809
|
+
const xAxis = xAxisKey && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36810
|
+
import_recharts.XAxis,
|
|
36811
|
+
{
|
|
36812
|
+
dataKey: xAxisKey,
|
|
36813
|
+
tickLine: false,
|
|
36814
|
+
axisLine: false,
|
|
36815
|
+
tickMargin: 8,
|
|
36816
|
+
minTickGap: 16,
|
|
36817
|
+
interval: "preserveStartEnd",
|
|
36818
|
+
padding: isTrendChart ? { left: 12, right: 12 } : void 0
|
|
36819
|
+
}
|
|
36645
36820
|
);
|
|
36646
|
-
const
|
|
36647
|
-
|
|
36648
|
-
|
|
36649
|
-
|
|
36650
|
-
|
|
36651
|
-
|
|
36821
|
+
const yAxis = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36822
|
+
import_recharts.YAxis,
|
|
36823
|
+
{
|
|
36824
|
+
tickLine: false,
|
|
36825
|
+
axisLine: false,
|
|
36826
|
+
tickCount: yTicks ? void 0 : 4,
|
|
36827
|
+
ticks: yTicks,
|
|
36828
|
+
tickMargin: 4,
|
|
36829
|
+
tickFormatter: formatters.tick,
|
|
36830
|
+
domain: yDomain,
|
|
36831
|
+
allowDataOverflow: false,
|
|
36832
|
+
width: Math.min(120, Math.max(36, longestTick * 7 + 12))
|
|
36833
|
+
}
|
|
36834
|
+
);
|
|
36835
|
+
const tooltip = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36836
|
+
ChartTooltip,
|
|
36837
|
+
{
|
|
36838
|
+
cursor: chartType === "bar" ? { fill: "var(--muted)", opacity: 0.5 } : { stroke: "var(--border)", strokeWidth: 1 },
|
|
36839
|
+
content: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36840
|
+
ChartTooltipContent,
|
|
36841
|
+
{
|
|
36842
|
+
indicator: chartType === "bar" ? "dot" : "line",
|
|
36843
|
+
valueFormatter: formatters.value
|
|
36844
|
+
}
|
|
36845
|
+
)
|
|
36846
|
+
}
|
|
36847
|
+
);
|
|
36848
|
+
const legend = dataKeys.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartLegend, { content: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartLegendContent, {}) });
|
|
36849
|
+
const marker = (key3, r) => ({
|
|
36850
|
+
r,
|
|
36851
|
+
fill: seriesColor(key3),
|
|
36852
|
+
stroke: SURFACE,
|
|
36853
|
+
strokeWidth: 2
|
|
36854
|
+
});
|
|
36855
|
+
const lineDot = (key3) => showDots ? marker(key3, 4) : (props) => props.index === lastValueIndex(chartData, key3) && typeof props.cx === "number" && typeof props.cy === "number" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: props.cx, cy: props.cy, ...marker(key3, 4) }, `end-${key3}`) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("g", {}, `dot-${key3}-${props.index}`);
|
|
36652
36856
|
const labelKey = chartType === "pie" ? xAxisKey || "name" : xAxisKey;
|
|
36653
|
-
const
|
|
36654
|
-
const tableColumns = labelKey ? [labelKey, ...valueKeys] : valueKeys;
|
|
36857
|
+
const tableColumns = labelKey ? [labelKey, ...plottedKeys] : plottedKeys;
|
|
36655
36858
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36656
36859
|
"div",
|
|
36657
36860
|
{
|
|
@@ -36659,8 +36862,8 @@ function ChartCard({ data }) {
|
|
|
36659
36862
|
ref: containerRef,
|
|
36660
36863
|
role: "figure",
|
|
36661
36864
|
"aria-label": [title, `${chartType} chart`].filter(Boolean).join(", "),
|
|
36662
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rounded-xl bg-sidebar dark:bg-card px-5 py-4", children: [
|
|
36663
|
-
|
|
36865
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rounded-xl bg-sidebar dark:bg-card px-5 py-4 [--chart-surface:var(--sidebar)] dark:[--chart-surface:var(--card)]", children: [
|
|
36866
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartHeader, { title: headerTitle, trend, range }),
|
|
36664
36867
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("table", { style: VISUALLY_HIDDEN, children: [
|
|
36665
36868
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: tableColumns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { scope: "col", children: column }, column)) }) }),
|
|
36666
36869
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tbody", { children: chartData.map((point, row) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: tableColumns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { children: cellText(point[column]) }, column)) }, row)) })
|
|
@@ -36669,50 +36872,87 @@ function ChartCard({ data }) {
|
|
|
36669
36872
|
ChartContainer,
|
|
36670
36873
|
{
|
|
36671
36874
|
config: chartConfig,
|
|
36672
|
-
className: "aspect-auto h-[
|
|
36875
|
+
className: "aspect-auto h-[220px] w-full",
|
|
36673
36876
|
"aria-hidden": "true",
|
|
36674
|
-
children: chartType === "bar" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_recharts.BarChart, { data: chartData, children: [
|
|
36877
|
+
children: chartType === "bar" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_recharts.BarChart, { data: chartData, margin, barGap: 2, barCategoryGap: "24%", children: [
|
|
36675
36878
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_recharts.CartesianGrid, { vertical: false }),
|
|
36676
|
-
|
|
36677
|
-
|
|
36678
|
-
|
|
36679
|
-
|
|
36680
|
-
dataKeys.map((key3) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36681
|
-
|
|
36879
|
+
xAxis,
|
|
36880
|
+
yAxis,
|
|
36881
|
+
tooltip,
|
|
36882
|
+
legend,
|
|
36883
|
+
dataKeys.map((key3) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36884
|
+
import_recharts.Bar,
|
|
36885
|
+
{
|
|
36886
|
+
dataKey: key3,
|
|
36887
|
+
fill: seriesColor(key3),
|
|
36888
|
+
maxBarSize: 24,
|
|
36889
|
+
radius: hasNegative ? 2 : [4, 4, 0, 0],
|
|
36890
|
+
isAnimationActive: animate
|
|
36891
|
+
},
|
|
36892
|
+
key3
|
|
36893
|
+
))
|
|
36894
|
+
] }) : chartType === "line" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_recharts.LineChart, { data: chartData, margin, children: [
|
|
36682
36895
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_recharts.CartesianGrid, { vertical: false }),
|
|
36683
|
-
|
|
36684
|
-
|
|
36685
|
-
|
|
36686
|
-
|
|
36896
|
+
xAxis,
|
|
36897
|
+
yAxis,
|
|
36898
|
+
tooltip,
|
|
36899
|
+
legend,
|
|
36687
36900
|
dataKeys.map((key3) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36688
36901
|
import_recharts.Line,
|
|
36689
36902
|
{
|
|
36903
|
+
type: curve,
|
|
36690
36904
|
dataKey: key3,
|
|
36691
36905
|
stroke: seriesColor(key3),
|
|
36692
36906
|
strokeWidth: 2,
|
|
36693
|
-
|
|
36907
|
+
strokeLinecap: "round",
|
|
36908
|
+
strokeLinejoin: "round",
|
|
36909
|
+
dot: lineDot(key3),
|
|
36910
|
+
activeDot: marker(key3, 5),
|
|
36911
|
+
isAnimationActive: animate,
|
|
36912
|
+
animationDuration: 600
|
|
36694
36913
|
},
|
|
36695
36914
|
key3
|
|
36696
36915
|
))
|
|
36697
|
-
] }) : chartType === "area" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_recharts.AreaChart, { data: chartData, children: [
|
|
36916
|
+
] }) : chartType === "area" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_recharts.AreaChart, { data: chartData, margin, children: [
|
|
36917
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("defs", { children: dataKeys.map((key3, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
36918
|
+
"linearGradient",
|
|
36919
|
+
{
|
|
36920
|
+
id: `${gradientId}-${index}`,
|
|
36921
|
+
x1: "0",
|
|
36922
|
+
y1: "0",
|
|
36923
|
+
x2: "0",
|
|
36924
|
+
y2: "1",
|
|
36925
|
+
children: [
|
|
36926
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("stop", { offset: "0%", stopColor: seriesColor(key3), stopOpacity: 0.24 }),
|
|
36927
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("stop", { offset: "100%", stopColor: seriesColor(key3), stopOpacity: 0 })
|
|
36928
|
+
]
|
|
36929
|
+
},
|
|
36930
|
+
key3
|
|
36931
|
+
)) }),
|
|
36698
36932
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_recharts.CartesianGrid, { vertical: false }),
|
|
36699
|
-
|
|
36700
|
-
|
|
36701
|
-
|
|
36702
|
-
|
|
36703
|
-
dataKeys.map((key3) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36933
|
+
xAxis,
|
|
36934
|
+
yAxis,
|
|
36935
|
+
tooltip,
|
|
36936
|
+
legend,
|
|
36937
|
+
dataKeys.map((key3, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36704
36938
|
import_recharts.Area,
|
|
36705
36939
|
{
|
|
36940
|
+
type: curve,
|
|
36706
36941
|
dataKey: key3,
|
|
36707
|
-
fill: seriesColor(key3),
|
|
36708
36942
|
stroke: seriesColor(key3),
|
|
36709
|
-
|
|
36943
|
+
strokeWidth: 2,
|
|
36944
|
+
fill: `url(#${gradientId}-${index})`,
|
|
36945
|
+
dot: lineDot(key3),
|
|
36946
|
+
activeDot: marker(key3, 5),
|
|
36947
|
+
baseValue: "dataMin",
|
|
36948
|
+
isAnimationActive: animate,
|
|
36949
|
+
animationDuration: 600
|
|
36710
36950
|
},
|
|
36711
36951
|
key3
|
|
36712
36952
|
))
|
|
36713
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_recharts.PieChart, { children: [
|
|
36714
|
-
|
|
36715
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.
|
|
36953
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_recharts.PieChart, { margin, children: [
|
|
36954
|
+
tooltip,
|
|
36955
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
36716
36956
|
import_recharts.Pie,
|
|
36717
36957
|
{
|
|
36718
36958
|
data: chartData,
|
|
@@ -36720,14 +36960,43 @@ function ChartCard({ data }) {
|
|
|
36720
36960
|
nameKey: xAxisKey || "name",
|
|
36721
36961
|
cx: "50%",
|
|
36722
36962
|
cy: "50%",
|
|
36723
|
-
|
|
36724
|
-
|
|
36963
|
+
innerRadius: "58%",
|
|
36964
|
+
outerRadius: "86%",
|
|
36965
|
+
paddingAngle: chartData.length > 1 ? 1 : 0,
|
|
36966
|
+
stroke: SURFACE,
|
|
36967
|
+
strokeWidth: 2,
|
|
36968
|
+
isAnimationActive: animate,
|
|
36969
|
+
children: [
|
|
36970
|
+
chartData.map((_, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_recharts.Cell, { fill: paletteColor(index) }, index)),
|
|
36971
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36972
|
+
import_recharts.Label,
|
|
36973
|
+
{
|
|
36974
|
+
position: "center",
|
|
36975
|
+
content: ({ viewBox }) => {
|
|
36976
|
+
const box = viewBox;
|
|
36977
|
+
if (box?.cx === void 0 || box.cy === void 0) return null;
|
|
36978
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("text", { x: box.cx, y: box.cy, textAnchor: "middle", dominantBaseline: "middle", children: [
|
|
36979
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36980
|
+
"tspan",
|
|
36981
|
+
{
|
|
36982
|
+
x: box.cx,
|
|
36983
|
+
y: box.cy - 6,
|
|
36984
|
+
className: "fill-foreground text-lg font-semibold",
|
|
36985
|
+
children: formatters.value(values.reduce((sum, value) => sum + value, 0))
|
|
36986
|
+
}
|
|
36987
|
+
),
|
|
36988
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tspan", { x: box.cx, y: box.cy + 14, className: "fill-muted-foreground", children: "Total" })
|
|
36989
|
+
] });
|
|
36990
|
+
}
|
|
36991
|
+
}
|
|
36992
|
+
)
|
|
36993
|
+
]
|
|
36725
36994
|
}
|
|
36726
36995
|
),
|
|
36727
36996
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartLegend, { content: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartLegendContent, { nameKey: xAxisKey || "name" }) })
|
|
36728
36997
|
] })
|
|
36729
36998
|
}
|
|
36730
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "h-[
|
|
36999
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "h-[220px] w-full" })
|
|
36731
37000
|
] })
|
|
36732
37001
|
}
|
|
36733
37002
|
);
|
package/dist/react/index.d.mts
CHANGED
|
@@ -14419,6 +14419,7 @@ declare function renderAnumaTree(node: AnumaNode): React.ReactElement | null;
|
|
|
14419
14419
|
declare function renderAnumaJsx(jsx: string): React.ReactElement | null;
|
|
14420
14420
|
|
|
14421
14421
|
type ChartDataPoint = Record<string, string | number>;
|
|
14422
|
+
type ChartValueFormat = "number" | "currency" | "percent";
|
|
14422
14423
|
type DisplayChartResult = {
|
|
14423
14424
|
chartType: "bar" | "line" | "area" | "pie";
|
|
14424
14425
|
title?: string;
|
|
@@ -14426,6 +14427,8 @@ type DisplayChartResult = {
|
|
|
14426
14427
|
dataKeys: string[];
|
|
14427
14428
|
xAxisKey?: string;
|
|
14428
14429
|
colors?: Record<string, string>;
|
|
14430
|
+
valueFormat?: ChartValueFormat;
|
|
14431
|
+
currency?: string;
|
|
14429
14432
|
} | {
|
|
14430
14433
|
error: string;
|
|
14431
14434
|
};
|
|
@@ -14455,12 +14458,13 @@ declare function ChartContainer({ id, className, children, config, ...props }: R
|
|
|
14455
14458
|
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
|
|
14456
14459
|
}): react_jsx_runtime.JSX.Element;
|
|
14457
14460
|
declare const ChartTooltip: typeof RechartsPrimitive.Tooltip;
|
|
14458
|
-
declare function ChartTooltipContent({ active, payload, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> & React.ComponentProps<"div"> & {
|
|
14461
|
+
declare function ChartTooltipContent({ active, payload, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, valueFormatter, }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> & React.ComponentProps<"div"> & {
|
|
14459
14462
|
hideLabel?: boolean;
|
|
14460
14463
|
hideIndicator?: boolean;
|
|
14461
14464
|
indicator?: "line" | "dot" | "dashed";
|
|
14462
14465
|
nameKey?: string;
|
|
14463
14466
|
labelKey?: string;
|
|
14467
|
+
valueFormatter?: (value: number) => string;
|
|
14464
14468
|
}): react_jsx_runtime.JSX.Element | null;
|
|
14465
14469
|
declare const ChartLegend: typeof RechartsPrimitive.Legend;
|
|
14466
14470
|
declare function ChartLegendContent({ className, hideIcon, payload, verticalAlign, nameKey, }: React.ComponentProps<"div"> & Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
package/dist/react/index.d.ts
CHANGED
|
@@ -14419,6 +14419,7 @@ declare function renderAnumaTree(node: AnumaNode): React.ReactElement | null;
|
|
|
14419
14419
|
declare function renderAnumaJsx(jsx: string): React.ReactElement | null;
|
|
14420
14420
|
|
|
14421
14421
|
type ChartDataPoint = Record<string, string | number>;
|
|
14422
|
+
type ChartValueFormat = "number" | "currency" | "percent";
|
|
14422
14423
|
type DisplayChartResult = {
|
|
14423
14424
|
chartType: "bar" | "line" | "area" | "pie";
|
|
14424
14425
|
title?: string;
|
|
@@ -14426,6 +14427,8 @@ type DisplayChartResult = {
|
|
|
14426
14427
|
dataKeys: string[];
|
|
14427
14428
|
xAxisKey?: string;
|
|
14428
14429
|
colors?: Record<string, string>;
|
|
14430
|
+
valueFormat?: ChartValueFormat;
|
|
14431
|
+
currency?: string;
|
|
14429
14432
|
} | {
|
|
14430
14433
|
error: string;
|
|
14431
14434
|
};
|
|
@@ -14455,12 +14458,13 @@ declare function ChartContainer({ id, className, children, config, ...props }: R
|
|
|
14455
14458
|
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
|
|
14456
14459
|
}): react_jsx_runtime.JSX.Element;
|
|
14457
14460
|
declare const ChartTooltip: typeof RechartsPrimitive.Tooltip;
|
|
14458
|
-
declare function ChartTooltipContent({ active, payload, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> & React.ComponentProps<"div"> & {
|
|
14461
|
+
declare function ChartTooltipContent({ active, payload, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, valueFormatter, }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> & React.ComponentProps<"div"> & {
|
|
14459
14462
|
hideLabel?: boolean;
|
|
14460
14463
|
hideIndicator?: boolean;
|
|
14461
14464
|
indicator?: "line" | "dot" | "dashed";
|
|
14462
14465
|
nameKey?: string;
|
|
14463
14466
|
labelKey?: string;
|
|
14467
|
+
valueFormatter?: (value: number) => string;
|
|
14464
14468
|
}): react_jsx_runtime.JSX.Element | null;
|
|
14465
14469
|
declare const ChartLegend: typeof RechartsPrimitive.Legend;
|
|
14466
14470
|
declare function ChartLegendContent({ className, hideIcon, payload, verticalAlign, nameKey, }: React.ComponentProps<"div"> & Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
package/dist/react/index.mjs
CHANGED
|
@@ -34413,6 +34413,7 @@ import {
|
|
|
34413
34413
|
BarChart,
|
|
34414
34414
|
CartesianGrid,
|
|
34415
34415
|
Cell,
|
|
34416
|
+
Label,
|
|
34416
34417
|
Line as Line2,
|
|
34417
34418
|
LineChart,
|
|
34418
34419
|
Pie,
|
|
@@ -34502,7 +34503,8 @@ function ChartTooltipContent({
|
|
|
34502
34503
|
formatter,
|
|
34503
34504
|
color,
|
|
34504
34505
|
nameKey,
|
|
34505
|
-
labelKey
|
|
34506
|
+
labelKey,
|
|
34507
|
+
valueFormatter
|
|
34506
34508
|
}) {
|
|
34507
34509
|
const { config } = useChart();
|
|
34508
34510
|
const tooltipLabel = React2.useMemo(() => {
|
|
@@ -34569,7 +34571,7 @@ function ChartTooltipContent({
|
|
|
34569
34571
|
nestLabel ? tooltipLabel : null,
|
|
34570
34572
|
/* @__PURE__ */ jsx2("span", { className: "text-muted-foreground", children: itemConfig?.label || item.name })
|
|
34571
34573
|
] }),
|
|
34572
|
-
item.value && /* @__PURE__ */ jsx2("span", { className: "text-foreground font-
|
|
34574
|
+
item.value !== void 0 && item.value !== null && /* @__PURE__ */ jsx2("span", { className: "text-foreground font-medium tabular-nums", children: valueFormatter && typeof item.value === "number" ? valueFormatter(item.value) : item.value.toLocaleString() })
|
|
34573
34575
|
]
|
|
34574
34576
|
}
|
|
34575
34577
|
)
|
|
@@ -34615,7 +34617,7 @@ function ChartLegendContent({
|
|
|
34615
34617
|
style: { backgroundColor: item.color }
|
|
34616
34618
|
}
|
|
34617
34619
|
),
|
|
34618
|
-
itemConfig?.label
|
|
34620
|
+
itemConfig?.label ?? cellText(item.value)
|
|
34619
34621
|
]
|
|
34620
34622
|
},
|
|
34621
34623
|
String(item.value)
|
|
@@ -34642,19 +34644,16 @@ var DEFAULT_COLORS = [
|
|
|
34642
34644
|
"var(--chart-4)",
|
|
34643
34645
|
"var(--chart-5)"
|
|
34644
34646
|
];
|
|
34647
|
+
var SURFACE = "var(--chart-surface)";
|
|
34648
|
+
var DOT_LIMIT = 12;
|
|
34649
|
+
var MAX_TICKS = 8;
|
|
34650
|
+
var MINUS = "\u2212";
|
|
34645
34651
|
function paletteColor(index) {
|
|
34646
34652
|
return index < DEFAULT_COLORS.length ? DEFAULT_COLORS[index] : `hsl(${Math.round(index * 137.508 % 360)} 65% 55%)`;
|
|
34647
34653
|
}
|
|
34648
|
-
var compactNumber = new Intl.NumberFormat(void 0, {
|
|
34649
|
-
notation: "compact",
|
|
34650
|
-
maximumSignificantDigits: 3
|
|
34651
|
-
});
|
|
34652
34654
|
function cellText(value) {
|
|
34653
34655
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
34654
34656
|
}
|
|
34655
|
-
function formatTick(value) {
|
|
34656
|
-
return typeof value === "number" ? compactNumber.format(value) : String(value);
|
|
34657
|
-
}
|
|
34658
34657
|
var VISUALLY_HIDDEN = {
|
|
34659
34658
|
position: "absolute",
|
|
34660
34659
|
width: 1,
|
|
@@ -34666,6 +34665,90 @@ var VISUALLY_HIDDEN = {
|
|
|
34666
34665
|
whiteSpace: "nowrap",
|
|
34667
34666
|
border: 0
|
|
34668
34667
|
};
|
|
34668
|
+
function tickDigits(ticks) {
|
|
34669
|
+
if (!ticks || ticks.length < 2) return 3;
|
|
34670
|
+
const step = ticks[1] - ticks[0];
|
|
34671
|
+
const magnitude = Math.max(...ticks.map(Math.abs));
|
|
34672
|
+
if (step <= 0 || magnitude === 0) return 3;
|
|
34673
|
+
const needed = Math.floor(Math.log10(magnitude)) - Math.floor(Math.log10(step)) + 1;
|
|
34674
|
+
return Math.min(21, Math.max(3, needed));
|
|
34675
|
+
}
|
|
34676
|
+
function keepSmall(options) {
|
|
34677
|
+
const small = new Intl.NumberFormat(void 0, { ...options, maximumSignificantDigits: 3 });
|
|
34678
|
+
const regular = new Intl.NumberFormat(void 0, { ...options, maximumFractionDigits: 2 });
|
|
34679
|
+
return (n, format) => format(n !== 0 && Math.abs(n) < 1 ? small : regular, n);
|
|
34680
|
+
}
|
|
34681
|
+
function buildFormatters(format, currency, ticks) {
|
|
34682
|
+
const digits = tickDigits(ticks);
|
|
34683
|
+
if (format === "currency") {
|
|
34684
|
+
const money = (options) => new Intl.NumberFormat(void 0, {
|
|
34685
|
+
style: "currency",
|
|
34686
|
+
currency: currency ?? "USD",
|
|
34687
|
+
...options
|
|
34688
|
+
});
|
|
34689
|
+
const compact2 = money({ notation: "compact", maximumSignificantDigits: 3 });
|
|
34690
|
+
const tick2 = money({ notation: "compact", maximumSignificantDigits: digits });
|
|
34691
|
+
const small2 = money({ maximumSignificantDigits: 4 });
|
|
34692
|
+
const cents = money({ minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
34693
|
+
const value2 = (n) => Math.abs(n) >= 1e6 ? compact2.format(n) : n !== 0 && Math.abs(n) < 1 ? small2.format(n) : cents.format(n);
|
|
34694
|
+
return { tick: (n) => tick2.format(n), value: value2, change: (d) => value2(Math.abs(d)) };
|
|
34695
|
+
}
|
|
34696
|
+
if (format === "percent") {
|
|
34697
|
+
const percent = keepSmall({ style: "percent" });
|
|
34698
|
+
const points = keepSmall({});
|
|
34699
|
+
const tick2 = new Intl.NumberFormat(void 0, {
|
|
34700
|
+
style: "percent",
|
|
34701
|
+
maximumSignificantDigits: digits
|
|
34702
|
+
});
|
|
34703
|
+
return {
|
|
34704
|
+
tick: (n) => tick2.format(n / 100),
|
|
34705
|
+
value: (n) => percent(n, (formatter) => formatter.format(n / 100)),
|
|
34706
|
+
change: (d) => `${points(Math.abs(d), (formatter, n) => formatter.format(n))} pts`
|
|
34707
|
+
};
|
|
34708
|
+
}
|
|
34709
|
+
const tick = new Intl.NumberFormat(void 0, {
|
|
34710
|
+
notation: "compact",
|
|
34711
|
+
maximumSignificantDigits: digits
|
|
34712
|
+
});
|
|
34713
|
+
const compact = new Intl.NumberFormat(void 0, {
|
|
34714
|
+
notation: "compact",
|
|
34715
|
+
maximumSignificantDigits: 3
|
|
34716
|
+
});
|
|
34717
|
+
const small = new Intl.NumberFormat(void 0, { maximumSignificantDigits: 4 });
|
|
34718
|
+
const plain2 = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 });
|
|
34719
|
+
const value = (n) => Math.abs(n) >= 1e6 ? compact.format(n) : n !== 0 && Math.abs(n) < 1 ? small.format(n) : plain2.format(n);
|
|
34720
|
+
return { tick: (n) => tick.format(n), value, change: (d) => value(Math.abs(d)) };
|
|
34721
|
+
}
|
|
34722
|
+
function seriesValues(points, keys) {
|
|
34723
|
+
return points.flatMap(
|
|
34724
|
+
(point) => keys.map((key3) => point[key3]).filter((v) => typeof v === "number")
|
|
34725
|
+
);
|
|
34726
|
+
}
|
|
34727
|
+
function niceStep(rough) {
|
|
34728
|
+
const exponent = Math.floor(Math.log10(rough));
|
|
34729
|
+
const base = 10 ** exponent;
|
|
34730
|
+
const fraction = rough / base;
|
|
34731
|
+
const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
|
|
34732
|
+
return nice * base;
|
|
34733
|
+
}
|
|
34734
|
+
function niceTicks(values) {
|
|
34735
|
+
if (values.length === 0) return void 0;
|
|
34736
|
+
const min = Math.min(...values);
|
|
34737
|
+
const max = Math.max(...values);
|
|
34738
|
+
const span = max - min || Math.abs(max) * 0.02 || 1;
|
|
34739
|
+
const low = min - span * 0.1;
|
|
34740
|
+
const high = max + span * 0.1;
|
|
34741
|
+
const step = niceStep((high - low) / 3);
|
|
34742
|
+
const start = min >= 0 ? Math.max(0, Math.floor(low / step) * step) : Math.floor(low / step) * step;
|
|
34743
|
+
const ticks = [];
|
|
34744
|
+
for (let index = 0; index <= MAX_TICKS; index++) {
|
|
34745
|
+
const tick = Number((start + index * step).toPrecision(15));
|
|
34746
|
+
if (ticks.length > 0 && tick <= ticks[ticks.length - 1]) break;
|
|
34747
|
+
ticks.push(tick);
|
|
34748
|
+
if (tick >= high) break;
|
|
34749
|
+
}
|
|
34750
|
+
return ticks.length >= 2 ? ticks : void 0;
|
|
34751
|
+
}
|
|
34669
34752
|
function buildChartConfig(dataKeys, colors) {
|
|
34670
34753
|
const config = {};
|
|
34671
34754
|
dataKeys.forEach((key3, i) => {
|
|
@@ -34677,9 +34760,71 @@ function buildChartConfig(dataKeys, colors) {
|
|
|
34677
34760
|
});
|
|
34678
34761
|
return config;
|
|
34679
34762
|
}
|
|
34763
|
+
function lastValueIndex(points, key3) {
|
|
34764
|
+
for (let index = points.length - 1; index >= 0; index--) {
|
|
34765
|
+
if (typeof points[index][key3] === "number") return index;
|
|
34766
|
+
}
|
|
34767
|
+
return -1;
|
|
34768
|
+
}
|
|
34769
|
+
function usePrefersReducedMotion() {
|
|
34770
|
+
const [reduced, setReduced] = React2.useState(false);
|
|
34771
|
+
React2.useEffect(() => {
|
|
34772
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
|
34773
|
+
const query = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
34774
|
+
setReduced(query.matches);
|
|
34775
|
+
const onChange = (event) => setReduced(event.matches);
|
|
34776
|
+
query.addEventListener?.("change", onChange);
|
|
34777
|
+
return () => query.removeEventListener?.("change", onChange);
|
|
34778
|
+
}, []);
|
|
34779
|
+
return reduced;
|
|
34780
|
+
}
|
|
34781
|
+
function buildTrend(values, format, formatters) {
|
|
34782
|
+
if (values.length < 2) return void 0;
|
|
34783
|
+
const first = values[0];
|
|
34784
|
+
const last = values[values.length - 1];
|
|
34785
|
+
const difference = last - first;
|
|
34786
|
+
const direction = difference > 0 ? "up" : difference < 0 ? "down" : "flat";
|
|
34787
|
+
const sign = direction === "up" ? "+" : direction === "down" ? MINUS : "";
|
|
34788
|
+
const percent = format !== "percent" && first !== 0 ? ` (${sign}${new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }).format(
|
|
34789
|
+
Math.abs(difference / Math.abs(first) * 100)
|
|
34790
|
+
)}%)` : "";
|
|
34791
|
+
return {
|
|
34792
|
+
value: formatters.value(last),
|
|
34793
|
+
change: `${sign}${formatters.change(difference)}${percent}`,
|
|
34794
|
+
direction
|
|
34795
|
+
};
|
|
34796
|
+
}
|
|
34797
|
+
var TREND_CLASS = {
|
|
34798
|
+
up: "text-emerald-600 dark:text-emerald-400",
|
|
34799
|
+
down: "text-red-600 dark:text-red-400",
|
|
34800
|
+
flat: "text-muted-foreground"
|
|
34801
|
+
};
|
|
34802
|
+
var TREND_ARROW = { up: "\u25B2", down: "\u25BC", flat: "" };
|
|
34803
|
+
function ChartHeader({
|
|
34804
|
+
title,
|
|
34805
|
+
trend,
|
|
34806
|
+
range
|
|
34807
|
+
}) {
|
|
34808
|
+
if (!trend) {
|
|
34809
|
+
return title ? /* @__PURE__ */ jsx2("p", { className: "mb-3 text-sm font-medium", children: title }) : null;
|
|
34810
|
+
}
|
|
34811
|
+
return /* @__PURE__ */ jsxs("div", { className: "mb-3", "data-testid": "chart-header", children: [
|
|
34812
|
+
title && /* @__PURE__ */ jsx2("p", { className: "text-sm text-muted-foreground", children: title }),
|
|
34813
|
+
/* @__PURE__ */ jsx2("p", { className: "mt-0.5 text-2xl font-semibold tracking-tight text-foreground", children: trend.value }),
|
|
34814
|
+
/* @__PURE__ */ jsxs("p", { className: "mt-0.5 flex flex-wrap items-center gap-x-1.5 text-xs", children: [
|
|
34815
|
+
/* @__PURE__ */ jsxs("span", { className: cx("font-medium", TREND_CLASS[trend.direction]), children: [
|
|
34816
|
+
TREND_ARROW[trend.direction] && /* @__PURE__ */ jsx2("span", { "aria-hidden": "true", className: "mr-1 text-[0.6rem]", children: TREND_ARROW[trend.direction] }),
|
|
34817
|
+
trend.change
|
|
34818
|
+
] }),
|
|
34819
|
+
range && /* @__PURE__ */ jsx2("span", { className: "text-muted-foreground", children: range })
|
|
34820
|
+
] })
|
|
34821
|
+
] });
|
|
34822
|
+
}
|
|
34680
34823
|
function ChartCard({ data }) {
|
|
34681
34824
|
const containerRef = React2.useRef(null);
|
|
34682
34825
|
const [ready, setReady] = React2.useState(false);
|
|
34826
|
+
const gradientId = `chart-fill-${React2.useId().replace(/:/g, "")}`;
|
|
34827
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
34683
34828
|
React2.useEffect(() => {
|
|
34684
34829
|
const frame = requestAnimationFrame(() => setReady(true));
|
|
34685
34830
|
return () => cancelAnimationFrame(frame);
|
|
@@ -34687,25 +34832,84 @@ function ChartCard({ data }) {
|
|
|
34687
34832
|
if ("error" in data) {
|
|
34688
34833
|
return /* @__PURE__ */ jsx2("div", { className: "my-4 max-w-lg", children: /* @__PURE__ */ jsx2("div", { className: "rounded-xl bg-sidebar dark:bg-card px-4 py-3", children: /* @__PURE__ */ jsx2("p", { className: "text-sm text-muted-foreground", children: "Couldn't display this chart." }) }) });
|
|
34689
34834
|
}
|
|
34690
|
-
const {
|
|
34835
|
+
const {
|
|
34836
|
+
chartType,
|
|
34837
|
+
title,
|
|
34838
|
+
data: chartData,
|
|
34839
|
+
dataKeys,
|
|
34840
|
+
xAxisKey,
|
|
34841
|
+
colors,
|
|
34842
|
+
valueFormat,
|
|
34843
|
+
currency
|
|
34844
|
+
} = data;
|
|
34691
34845
|
const chartConfig = buildChartConfig(dataKeys, colors);
|
|
34692
34846
|
const seriesColor = (key3) => chartConfig[key3]?.color;
|
|
34693
|
-
const
|
|
34694
|
-
|
|
34695
|
-
|
|
34696
|
-
|
|
34697
|
-
|
|
34698
|
-
|
|
34847
|
+
const isTrendChart = chartType === "line" || chartType === "area";
|
|
34848
|
+
const plottedKeys = chartType === "pie" ? dataKeys.slice(0, 1) : dataKeys;
|
|
34849
|
+
const values = seriesValues(chartData, plottedKeys);
|
|
34850
|
+
const yTicks = isTrendChart ? niceTicks(values) : void 0;
|
|
34851
|
+
const yDomain = yTicks ? [yTicks[0], yTicks[yTicks.length - 1]] : void 0;
|
|
34852
|
+
const formatters = buildFormatters(valueFormat, currency, yTicks);
|
|
34853
|
+
const trend = isTrendChart && dataKeys.length === 1 ? buildTrend(values, valueFormat, formatters) : void 0;
|
|
34854
|
+
const trendRows = trend ? chartData.filter((point) => typeof point[dataKeys[0]] === "number") : [];
|
|
34855
|
+
const range = trend && xAxisKey ? [trendRows[0], trendRows[trendRows.length - 1]].map((point) => cellText(point[xAxisKey])).filter(Boolean).join(" \u2013 ") : void 0;
|
|
34856
|
+
const headerTitle = title ?? (trend ? chartConfig[dataKeys[0]]?.label : void 0);
|
|
34857
|
+
const tickSamples = [...yDomain ?? [], ...values].map((value) => formatters.tick(value));
|
|
34858
|
+
const longestTick = tickSamples.reduce((max, label) => Math.max(max, label.length), 0);
|
|
34859
|
+
const animate = !reducedMotion;
|
|
34860
|
+
const showDots = chartData.length <= DOT_LIMIT;
|
|
34861
|
+
const curve = showDots ? "linear" : "monotone";
|
|
34862
|
+
const hasNegative = values.some((value) => value < 0);
|
|
34863
|
+
const margin = { top: 8, right: 8, bottom: 0, left: 0 };
|
|
34864
|
+
const xAxis = xAxisKey && /* @__PURE__ */ jsx2(
|
|
34865
|
+
XAxis,
|
|
34866
|
+
{
|
|
34867
|
+
dataKey: xAxisKey,
|
|
34868
|
+
tickLine: false,
|
|
34869
|
+
axisLine: false,
|
|
34870
|
+
tickMargin: 8,
|
|
34871
|
+
minTickGap: 16,
|
|
34872
|
+
interval: "preserveStartEnd",
|
|
34873
|
+
padding: isTrendChart ? { left: 12, right: 12 } : void 0
|
|
34874
|
+
}
|
|
34699
34875
|
);
|
|
34700
|
-
const
|
|
34701
|
-
|
|
34702
|
-
|
|
34703
|
-
|
|
34704
|
-
|
|
34705
|
-
|
|
34876
|
+
const yAxis = /* @__PURE__ */ jsx2(
|
|
34877
|
+
YAxis,
|
|
34878
|
+
{
|
|
34879
|
+
tickLine: false,
|
|
34880
|
+
axisLine: false,
|
|
34881
|
+
tickCount: yTicks ? void 0 : 4,
|
|
34882
|
+
ticks: yTicks,
|
|
34883
|
+
tickMargin: 4,
|
|
34884
|
+
tickFormatter: formatters.tick,
|
|
34885
|
+
domain: yDomain,
|
|
34886
|
+
allowDataOverflow: false,
|
|
34887
|
+
width: Math.min(120, Math.max(36, longestTick * 7 + 12))
|
|
34888
|
+
}
|
|
34889
|
+
);
|
|
34890
|
+
const tooltip = /* @__PURE__ */ jsx2(
|
|
34891
|
+
ChartTooltip,
|
|
34892
|
+
{
|
|
34893
|
+
cursor: chartType === "bar" ? { fill: "var(--muted)", opacity: 0.5 } : { stroke: "var(--border)", strokeWidth: 1 },
|
|
34894
|
+
content: /* @__PURE__ */ jsx2(
|
|
34895
|
+
ChartTooltipContent,
|
|
34896
|
+
{
|
|
34897
|
+
indicator: chartType === "bar" ? "dot" : "line",
|
|
34898
|
+
valueFormatter: formatters.value
|
|
34899
|
+
}
|
|
34900
|
+
)
|
|
34901
|
+
}
|
|
34902
|
+
);
|
|
34903
|
+
const legend = dataKeys.length > 1 && /* @__PURE__ */ jsx2(ChartLegend, { content: /* @__PURE__ */ jsx2(ChartLegendContent, {}) });
|
|
34904
|
+
const marker = (key3, r) => ({
|
|
34905
|
+
r,
|
|
34906
|
+
fill: seriesColor(key3),
|
|
34907
|
+
stroke: SURFACE,
|
|
34908
|
+
strokeWidth: 2
|
|
34909
|
+
});
|
|
34910
|
+
const lineDot = (key3) => showDots ? marker(key3, 4) : (props) => props.index === lastValueIndex(chartData, key3) && typeof props.cx === "number" && typeof props.cy === "number" ? /* @__PURE__ */ jsx2("circle", { cx: props.cx, cy: props.cy, ...marker(key3, 4) }, `end-${key3}`) : /* @__PURE__ */ jsx2("g", {}, `dot-${key3}-${props.index}`);
|
|
34706
34911
|
const labelKey = chartType === "pie" ? xAxisKey || "name" : xAxisKey;
|
|
34707
|
-
const
|
|
34708
|
-
const tableColumns = labelKey ? [labelKey, ...valueKeys] : valueKeys;
|
|
34912
|
+
const tableColumns = labelKey ? [labelKey, ...plottedKeys] : plottedKeys;
|
|
34709
34913
|
return /* @__PURE__ */ jsx2(
|
|
34710
34914
|
"div",
|
|
34711
34915
|
{
|
|
@@ -34713,8 +34917,8 @@ function ChartCard({ data }) {
|
|
|
34713
34917
|
ref: containerRef,
|
|
34714
34918
|
role: "figure",
|
|
34715
34919
|
"aria-label": [title, `${chartType} chart`].filter(Boolean).join(", "),
|
|
34716
|
-
children: /* @__PURE__ */ jsxs("div", { className: "rounded-xl bg-sidebar dark:bg-card px-5 py-4", children: [
|
|
34717
|
-
|
|
34920
|
+
children: /* @__PURE__ */ jsxs("div", { className: "rounded-xl bg-sidebar dark:bg-card px-5 py-4 [--chart-surface:var(--sidebar)] dark:[--chart-surface:var(--card)]", children: [
|
|
34921
|
+
/* @__PURE__ */ jsx2(ChartHeader, { title: headerTitle, trend, range }),
|
|
34718
34922
|
/* @__PURE__ */ jsxs("table", { style: VISUALLY_HIDDEN, children: [
|
|
34719
34923
|
/* @__PURE__ */ jsx2("thead", { children: /* @__PURE__ */ jsx2("tr", { children: tableColumns.map((column) => /* @__PURE__ */ jsx2("th", { scope: "col", children: column }, column)) }) }),
|
|
34720
34924
|
/* @__PURE__ */ jsx2("tbody", { children: chartData.map((point, row) => /* @__PURE__ */ jsx2("tr", { children: tableColumns.map((column) => /* @__PURE__ */ jsx2("td", { children: cellText(point[column]) }, column)) }, row)) })
|
|
@@ -34723,50 +34927,87 @@ function ChartCard({ data }) {
|
|
|
34723
34927
|
ChartContainer,
|
|
34724
34928
|
{
|
|
34725
34929
|
config: chartConfig,
|
|
34726
|
-
className: "aspect-auto h-[
|
|
34930
|
+
className: "aspect-auto h-[220px] w-full",
|
|
34727
34931
|
"aria-hidden": "true",
|
|
34728
|
-
children: chartType === "bar" ? /* @__PURE__ */ jsxs(BarChart, { data: chartData, children: [
|
|
34932
|
+
children: chartType === "bar" ? /* @__PURE__ */ jsxs(BarChart, { data: chartData, margin, barGap: 2, barCategoryGap: "24%", children: [
|
|
34729
34933
|
/* @__PURE__ */ jsx2(CartesianGrid, { vertical: false }),
|
|
34730
|
-
|
|
34731
|
-
|
|
34732
|
-
|
|
34733
|
-
|
|
34734
|
-
dataKeys.map((key3) => /* @__PURE__ */ jsx2(
|
|
34735
|
-
|
|
34934
|
+
xAxis,
|
|
34935
|
+
yAxis,
|
|
34936
|
+
tooltip,
|
|
34937
|
+
legend,
|
|
34938
|
+
dataKeys.map((key3) => /* @__PURE__ */ jsx2(
|
|
34939
|
+
Bar,
|
|
34940
|
+
{
|
|
34941
|
+
dataKey: key3,
|
|
34942
|
+
fill: seriesColor(key3),
|
|
34943
|
+
maxBarSize: 24,
|
|
34944
|
+
radius: hasNegative ? 2 : [4, 4, 0, 0],
|
|
34945
|
+
isAnimationActive: animate
|
|
34946
|
+
},
|
|
34947
|
+
key3
|
|
34948
|
+
))
|
|
34949
|
+
] }) : chartType === "line" ? /* @__PURE__ */ jsxs(LineChart, { data: chartData, margin, children: [
|
|
34736
34950
|
/* @__PURE__ */ jsx2(CartesianGrid, { vertical: false }),
|
|
34737
|
-
|
|
34738
|
-
|
|
34739
|
-
|
|
34740
|
-
|
|
34951
|
+
xAxis,
|
|
34952
|
+
yAxis,
|
|
34953
|
+
tooltip,
|
|
34954
|
+
legend,
|
|
34741
34955
|
dataKeys.map((key3) => /* @__PURE__ */ jsx2(
|
|
34742
34956
|
Line2,
|
|
34743
34957
|
{
|
|
34958
|
+
type: curve,
|
|
34744
34959
|
dataKey: key3,
|
|
34745
34960
|
stroke: seriesColor(key3),
|
|
34746
34961
|
strokeWidth: 2,
|
|
34747
|
-
|
|
34962
|
+
strokeLinecap: "round",
|
|
34963
|
+
strokeLinejoin: "round",
|
|
34964
|
+
dot: lineDot(key3),
|
|
34965
|
+
activeDot: marker(key3, 5),
|
|
34966
|
+
isAnimationActive: animate,
|
|
34967
|
+
animationDuration: 600
|
|
34748
34968
|
},
|
|
34749
34969
|
key3
|
|
34750
34970
|
))
|
|
34751
|
-
] }) : chartType === "area" ? /* @__PURE__ */ jsxs(AreaChart, { data: chartData, children: [
|
|
34971
|
+
] }) : chartType === "area" ? /* @__PURE__ */ jsxs(AreaChart, { data: chartData, margin, children: [
|
|
34972
|
+
/* @__PURE__ */ jsx2("defs", { children: dataKeys.map((key3, index) => /* @__PURE__ */ jsxs(
|
|
34973
|
+
"linearGradient",
|
|
34974
|
+
{
|
|
34975
|
+
id: `${gradientId}-${index}`,
|
|
34976
|
+
x1: "0",
|
|
34977
|
+
y1: "0",
|
|
34978
|
+
x2: "0",
|
|
34979
|
+
y2: "1",
|
|
34980
|
+
children: [
|
|
34981
|
+
/* @__PURE__ */ jsx2("stop", { offset: "0%", stopColor: seriesColor(key3), stopOpacity: 0.24 }),
|
|
34982
|
+
/* @__PURE__ */ jsx2("stop", { offset: "100%", stopColor: seriesColor(key3), stopOpacity: 0 })
|
|
34983
|
+
]
|
|
34984
|
+
},
|
|
34985
|
+
key3
|
|
34986
|
+
)) }),
|
|
34752
34987
|
/* @__PURE__ */ jsx2(CartesianGrid, { vertical: false }),
|
|
34753
|
-
|
|
34754
|
-
|
|
34755
|
-
|
|
34756
|
-
|
|
34757
|
-
dataKeys.map((key3) => /* @__PURE__ */ jsx2(
|
|
34988
|
+
xAxis,
|
|
34989
|
+
yAxis,
|
|
34990
|
+
tooltip,
|
|
34991
|
+
legend,
|
|
34992
|
+
dataKeys.map((key3, index) => /* @__PURE__ */ jsx2(
|
|
34758
34993
|
Area,
|
|
34759
34994
|
{
|
|
34995
|
+
type: curve,
|
|
34760
34996
|
dataKey: key3,
|
|
34761
|
-
fill: seriesColor(key3),
|
|
34762
34997
|
stroke: seriesColor(key3),
|
|
34763
|
-
|
|
34998
|
+
strokeWidth: 2,
|
|
34999
|
+
fill: `url(#${gradientId}-${index})`,
|
|
35000
|
+
dot: lineDot(key3),
|
|
35001
|
+
activeDot: marker(key3, 5),
|
|
35002
|
+
baseValue: "dataMin",
|
|
35003
|
+
isAnimationActive: animate,
|
|
35004
|
+
animationDuration: 600
|
|
34764
35005
|
},
|
|
34765
35006
|
key3
|
|
34766
35007
|
))
|
|
34767
|
-
] }) : /* @__PURE__ */ jsxs(PieChart, { children: [
|
|
34768
|
-
|
|
34769
|
-
/* @__PURE__ */
|
|
35008
|
+
] }) : /* @__PURE__ */ jsxs(PieChart, { margin, children: [
|
|
35009
|
+
tooltip,
|
|
35010
|
+
/* @__PURE__ */ jsxs(
|
|
34770
35011
|
Pie,
|
|
34771
35012
|
{
|
|
34772
35013
|
data: chartData,
|
|
@@ -34774,14 +35015,43 @@ function ChartCard({ data }) {
|
|
|
34774
35015
|
nameKey: xAxisKey || "name",
|
|
34775
35016
|
cx: "50%",
|
|
34776
35017
|
cy: "50%",
|
|
34777
|
-
|
|
34778
|
-
|
|
35018
|
+
innerRadius: "58%",
|
|
35019
|
+
outerRadius: "86%",
|
|
35020
|
+
paddingAngle: chartData.length > 1 ? 1 : 0,
|
|
35021
|
+
stroke: SURFACE,
|
|
35022
|
+
strokeWidth: 2,
|
|
35023
|
+
isAnimationActive: animate,
|
|
35024
|
+
children: [
|
|
35025
|
+
chartData.map((_, index) => /* @__PURE__ */ jsx2(Cell, { fill: paletteColor(index) }, index)),
|
|
35026
|
+
/* @__PURE__ */ jsx2(
|
|
35027
|
+
Label,
|
|
35028
|
+
{
|
|
35029
|
+
position: "center",
|
|
35030
|
+
content: ({ viewBox }) => {
|
|
35031
|
+
const box = viewBox;
|
|
35032
|
+
if (box?.cx === void 0 || box.cy === void 0) return null;
|
|
35033
|
+
return /* @__PURE__ */ jsxs("text", { x: box.cx, y: box.cy, textAnchor: "middle", dominantBaseline: "middle", children: [
|
|
35034
|
+
/* @__PURE__ */ jsx2(
|
|
35035
|
+
"tspan",
|
|
35036
|
+
{
|
|
35037
|
+
x: box.cx,
|
|
35038
|
+
y: box.cy - 6,
|
|
35039
|
+
className: "fill-foreground text-lg font-semibold",
|
|
35040
|
+
children: formatters.value(values.reduce((sum, value) => sum + value, 0))
|
|
35041
|
+
}
|
|
35042
|
+
),
|
|
35043
|
+
/* @__PURE__ */ jsx2("tspan", { x: box.cx, y: box.cy + 14, className: "fill-muted-foreground", children: "Total" })
|
|
35044
|
+
] });
|
|
35045
|
+
}
|
|
35046
|
+
}
|
|
35047
|
+
)
|
|
35048
|
+
]
|
|
34779
35049
|
}
|
|
34780
35050
|
),
|
|
34781
35051
|
/* @__PURE__ */ jsx2(ChartLegend, { content: /* @__PURE__ */ jsx2(ChartLegendContent, { nameKey: xAxisKey || "name" }) })
|
|
34782
35052
|
] })
|
|
34783
35053
|
}
|
|
34784
|
-
) : /* @__PURE__ */ jsx2("div", { className: "h-[
|
|
35054
|
+
) : /* @__PURE__ */ jsx2("div", { className: "h-[220px] w-full" })
|
|
34785
35055
|
] })
|
|
34786
35056
|
}
|
|
34787
35057
|
);
|
package/dist/tools/index.cjs
CHANGED
|
@@ -2529,6 +2529,16 @@ function createDisplayTool(options, config) {
|
|
|
2529
2529
|
}
|
|
2530
2530
|
|
|
2531
2531
|
// src/tools/chart.ts
|
|
2532
|
+
var VALUE_FORMATS = ["number", "currency", "percent"];
|
|
2533
|
+
var CURRENCY_CODE = /^[A-Z]{3}$/;
|
|
2534
|
+
function toValueFormat(value) {
|
|
2535
|
+
return VALUE_FORMATS.find((format) => format === value);
|
|
2536
|
+
}
|
|
2537
|
+
function toCurrencyCode(value) {
|
|
2538
|
+
if (typeof value !== "string") return void 0;
|
|
2539
|
+
const code = value.trim().toUpperCase();
|
|
2540
|
+
return CURRENCY_CODE.test(code) ? code : void 0;
|
|
2541
|
+
}
|
|
2532
2542
|
var NUMERIC_STRING = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i;
|
|
2533
2543
|
var THOUSANDS_GROUPED = /^[-+]?\d{1,3}(?:,\d{3})+(?:\.\d*)?$/;
|
|
2534
2544
|
function toNumber(value) {
|
|
@@ -2545,7 +2555,7 @@ function toNumber(value) {
|
|
|
2545
2555
|
function createChartTool(options) {
|
|
2546
2556
|
return createDisplayTool(options, {
|
|
2547
2557
|
name: "display_chart",
|
|
2548
|
-
description: 'Render a bar, line, area, or pie chart inline \u2014 visualize data, plot a trend over time, or graph a comparison. Use whenever the user asks to chart, plot, graph, or visualize numbers (sales, prices, temperatures, metrics). You MUST pass the actual numeric values in the "data" array \u2014 they are never inferred. Do not chart price or market history (crypto, stocks, market caps) unless those values came from a tool result or a cited source earlier in this conversation; never fill a price series from memory.',
|
|
2558
|
+
description: 'Render a bar, line, area, or pie chart inline \u2014 visualize data, plot a trend over time, or graph a comparison. Use whenever the user asks to chart, plot, graph, or visualize numbers (sales, prices, temperatures, metrics). You MUST pass the actual numeric values in the "data" array \u2014 they are never inferred. Do not chart price or market history (crypto, stocks, market caps) unless those values came from a tool result or a cited source earlier in this conversation; never fill a price series from memory. Set valueFormat to "currency" for prices and money, or "percent" for percentage values.',
|
|
2549
2559
|
parameters: {
|
|
2550
2560
|
type: "object",
|
|
2551
2561
|
properties: {
|
|
@@ -2579,6 +2589,15 @@ function createChartTool(options) {
|
|
|
2579
2589
|
type: "object",
|
|
2580
2590
|
additionalProperties: { type: "string" },
|
|
2581
2591
|
description: "Optional color overrides. Map of dataKey to CSS color value (e.g. { 'revenue': '#2563eb' }). If omitted, uses theme chart colors."
|
|
2592
|
+
},
|
|
2593
|
+
valueFormat: {
|
|
2594
|
+
type: "string",
|
|
2595
|
+
enum: ["number", "currency", "percent"],
|
|
2596
|
+
description: 'How to display the values on the axis, tooltip and headline. "currency" for prices and money (set currency too), "percent" when values are already percentages (3.2 means 3.2%). Defaults to "number".'
|
|
2597
|
+
},
|
|
2598
|
+
currency: {
|
|
2599
|
+
type: "string",
|
|
2600
|
+
description: 'ISO 4217 currency code used when valueFormat is "currency", e.g. "USD" or "EUR". Defaults to USD.'
|
|
2582
2601
|
}
|
|
2583
2602
|
},
|
|
2584
2603
|
required: ["chartType", "data", "dataKeys"]
|
|
@@ -2630,7 +2649,9 @@ function createChartTool(options) {
|
|
|
2630
2649
|
data: points,
|
|
2631
2650
|
dataKeys,
|
|
2632
2651
|
xAxisKey: args.xAxisKey,
|
|
2633
|
-
colors: args.colors
|
|
2652
|
+
colors: args.colors,
|
|
2653
|
+
valueFormat: toValueFormat(args.valueFormat),
|
|
2654
|
+
currency: toCurrencyCode(args.currency)
|
|
2634
2655
|
};
|
|
2635
2656
|
}
|
|
2636
2657
|
});
|
package/dist/tools/index.d.mts
CHANGED
|
@@ -1390,6 +1390,7 @@ declare function createInteractiveTool(options: CreateUIToolsOptions, config: In
|
|
|
1390
1390
|
declare function createDisplayTool<TArgs = Record<string, unknown>, TResult = unknown>(options: CreateUIToolsOptions, config: DisplayToolConfig<TArgs, TResult>): ToolConfig;
|
|
1391
1391
|
|
|
1392
1392
|
type ChartDataPoint = Record<string, string | number>;
|
|
1393
|
+
type ChartValueFormat = "number" | "currency" | "percent";
|
|
1393
1394
|
type DisplayChartResult = {
|
|
1394
1395
|
chartType: "bar" | "line" | "area" | "pie";
|
|
1395
1396
|
title?: string;
|
|
@@ -1397,6 +1398,8 @@ type DisplayChartResult = {
|
|
|
1397
1398
|
dataKeys: string[];
|
|
1398
1399
|
xAxisKey?: string;
|
|
1399
1400
|
colors?: Record<string, string>;
|
|
1401
|
+
valueFormat?: ChartValueFormat;
|
|
1402
|
+
currency?: string;
|
|
1400
1403
|
} | {
|
|
1401
1404
|
error: string;
|
|
1402
1405
|
};
|
|
@@ -2929,4 +2932,4 @@ interface XGetMyPostsArgs {
|
|
|
2929
2932
|
*/
|
|
2930
2933
|
declare function createXTools(callProxy: XProxyCaller): Record<string, ToolConfig>;
|
|
2931
2934
|
|
|
2932
|
-
export { ADD_SLIDE_SCHEMA, APP_BUILDER_PROMPT, APP_COMPLETE_CONNECT_ACK_TYPE, APP_COMPLETE_CONNECT_TYPE, APP_COMPLETE_DEFAULT_TIMEOUT_MS, APP_COMPLETE_IFRAME_SHIM_SCRIPT, APP_COMPLETE_REQUEST_TYPE, APP_COMPLETE_RESPONSE_TYPE, APP_COMPLETE_STUB_SCRIPT, APP_FILE_TOOL_NAMES, APP_PREVIEW_BASELINE_CSS, AUDIT_DESIGN_SCHEMA, type AgentresAccount, type AgentresClient, type AgentresClientOptions, AgentresError, type AgentresErrorCode, type AgentresLinkStatus, type AgentresLinkStep, AgentresPathError, type AnchorMatch, type AnumaChild, AnumaJsxError, type AnumaNode, type AppCompleteBridge, type AppCompleteBridgeOptions, type AppFileRecord, type AppFileStorage, type AttrValue, type AuditIssue, type AuditIssueType, type AuditResult, type AuditSeverity, type AuditTokens, type BuildSlideSystemPromptOptions, CHOICE_TOOL_NAME, CONNECTOR_ERROR_MARKER, CREATE_DOCUMENT_SCHEMA, CREATE_FILE_SCHEMA, CRITIQUE_DESIGN_SCHEMA, type CalendarEvent, type ChartDataPoint, type ChoiceOption, type ConfirmParameter, type ConfirmToolResult, type ConnectorErrorCode, type ConnectorMintError, type ConnectorMintResult, type ConnectorTokenGetterOpts, type ConnectorTokenSource, type CreateAppGenerationToolsOptions, type CreateDocumentToolsOptions, type CreateEventArgs, type CreateFileArgs, type CreateSelectPaymentWalletToolOptions, type CreateSlideToolsOptions, type CreateUIToolsOptions, type CreateWalletPaymentToolOptions, type CreateWeatherToolOptions, DEFAULT_DESIGN_CRITIQUE_RUBRIC, DEFAULT_DOCUMENT_ID, DEFAULT_MAX_CONVERSATIONS, DEFAULT_MAX_DOCUMENT_CONVERSATIONS, DELETE_FILE_SCHEMA, DOCUMENT_BUILDER_PROMPT, DOCUMENT_TOOL_NAMES, type DisplayChartResult, type DisplayConnectorResult, type DisplayPhoneCallOfferResult, type DisplayToolConfig, type DisplayToolMigrations, type DisplayWeatherResult, type DocAttrValue, type DocChild, DocDslError, type DocNode, type DriveFile, type DropboxRequestAccess, type DropboxTokenGetter, type ExportAppOptions, FONT_LIBRARY, FONT_PRESETS, type FileChangeEvent, type FileSnippet, type FontCategory, type FontPreset, type FontSpec, type ForecastDay, type FormField, type FormFieldOption, type FormFieldType, type GetFileContentArgs, type GmailGetMessageArgs, type GmailMessageDetail, type GmailMessageSummary, type GmailRequestAccess, type GmailSearchArgs, type GmailSendConfirmation, type GmailSendMessageArgs, type GmailTokenGetter, type InteractiveToolConfig, type KnownTag, LAYOUT_MODES, LIST_FILES_SCHEMA, type LayoutMode, type LegacyDeckJson, type ListEventsArgs, type ListRecentFilesArgs, MapFileStorage, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMcpCaller, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, PATCH_DOCUMENT_SCHEMA, PATCH_FILE_SCHEMA, PATCH_SLIDES_SCHEMA, PLAN_DECK_SCHEMA, type PatchFailure, type PatchFailureReason, type PaymentWallet, type PdfTag, READ_DOCUMENT_SCHEMA, READ_FILE_SCHEMA, READ_SLIDES_SCHEMA, RUNTIME_ERROR_OVERLAY_SCRIPT, SELECT_PAYMENT_WALLET_TOOL_NAME, SLIDES_FILE_PATH, SLIDE_CANVAS_HEIGHT, SLIDE_CANVAS_WIDTH, type SearchFilesArgs, type SelectPaymentWalletResult, SiwxChallengeError, SiwxUnsupportedError, type SlackGetChannelHistoryArgs, type SlackGetThreadRepliesArgs, type SlackListChannelsArgs, type SlackListDmsArgs, type SlackListUsersArgs, type SlackPostMessageArgs, type SlackProxyCaller, type SlackSearchMessagesArgs, type SlideToolSet, type SolanaSignMessageFn, THEME_ATTRS, type ThemeAttr, type ToolConfig, type ToolExecutionErrorType, type ToolExecutionResult, type UIInteractionContext, type UpdateEventArgs, type UpdateFileArgs, VERIFY_APP_SCHEMA, type VerifyAppResult, WALLET_PAYMENT_TOOL_NAME, type WalletPaymentOutcome, type WalletPaymentPassenger, type WalletPaymentRequest, type WalletPaymentResult, type XGetMeArgs, type XGetMyPostsArgs, type XProxyCaller, applyPatches, auditDesign, buildAppFileManifest, buildAppSystemPrompt, buildConnectorErrorResult, buildDocumentSystemPrompt, buildFontsUrl, buildSlideSystemPrompt, callNotionMCPTool, connectorMintErrorToToolResult, convertLegacyDeckJson, createAgentresClient, createAppCompleteBridge, createAppGenerationTools, createChartTool, createChatTools, createChoiceTool, createConfirmTool, createConnectorOfferTool, createConnectorTokenGetter, createDisplayTool, createDocumentTools, createDriveTools, createDropboxTools, createFormTool, createGitHubTools, createGmailTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveCreateFileTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createGoogleDriveUpdateFileTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionProxyTools, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, createPhoneCallOfferTool, createSelectPaymentWalletTool, createSlackTools, createSlideTools, createWalletPaymentTool, createWeatherTool, createXTools, documentPath, exportAppToHtml, findById, findParentOfId, getFontByName, getId, getMCPEndpoints, getNumberAttr, getStringAttr, insertAfterId, insertChild, installAppCompleteIframeShim, isAnumaTag, isHtmlTag, isKnownFont, isLegacyDeckJson, isPdfTag, migrateDisplayResult, normalizePath, parseDocumentDsl, parseJsx, pdfStyleKeys, pdfTags, removeById, replaceById, serializeJsx, truncateContent, updateAttrs, walk };
|
|
2935
|
+
export { ADD_SLIDE_SCHEMA, APP_BUILDER_PROMPT, APP_COMPLETE_CONNECT_ACK_TYPE, APP_COMPLETE_CONNECT_TYPE, APP_COMPLETE_DEFAULT_TIMEOUT_MS, APP_COMPLETE_IFRAME_SHIM_SCRIPT, APP_COMPLETE_REQUEST_TYPE, APP_COMPLETE_RESPONSE_TYPE, APP_COMPLETE_STUB_SCRIPT, APP_FILE_TOOL_NAMES, APP_PREVIEW_BASELINE_CSS, AUDIT_DESIGN_SCHEMA, type AgentresAccount, type AgentresClient, type AgentresClientOptions, AgentresError, type AgentresErrorCode, type AgentresLinkStatus, type AgentresLinkStep, AgentresPathError, type AnchorMatch, type AnumaChild, AnumaJsxError, type AnumaNode, type AppCompleteBridge, type AppCompleteBridgeOptions, type AppFileRecord, type AppFileStorage, type AttrValue, type AuditIssue, type AuditIssueType, type AuditResult, type AuditSeverity, type AuditTokens, type BuildSlideSystemPromptOptions, CHOICE_TOOL_NAME, CONNECTOR_ERROR_MARKER, CREATE_DOCUMENT_SCHEMA, CREATE_FILE_SCHEMA, CRITIQUE_DESIGN_SCHEMA, type CalendarEvent, type ChartDataPoint, type ChartValueFormat, type ChoiceOption, type ConfirmParameter, type ConfirmToolResult, type ConnectorErrorCode, type ConnectorMintError, type ConnectorMintResult, type ConnectorTokenGetterOpts, type ConnectorTokenSource, type CreateAppGenerationToolsOptions, type CreateDocumentToolsOptions, type CreateEventArgs, type CreateFileArgs, type CreateSelectPaymentWalletToolOptions, type CreateSlideToolsOptions, type CreateUIToolsOptions, type CreateWalletPaymentToolOptions, type CreateWeatherToolOptions, DEFAULT_DESIGN_CRITIQUE_RUBRIC, DEFAULT_DOCUMENT_ID, DEFAULT_MAX_CONVERSATIONS, DEFAULT_MAX_DOCUMENT_CONVERSATIONS, DELETE_FILE_SCHEMA, DOCUMENT_BUILDER_PROMPT, DOCUMENT_TOOL_NAMES, type DisplayChartResult, type DisplayConnectorResult, type DisplayPhoneCallOfferResult, type DisplayToolConfig, type DisplayToolMigrations, type DisplayWeatherResult, type DocAttrValue, type DocChild, DocDslError, type DocNode, type DriveFile, type DropboxRequestAccess, type DropboxTokenGetter, type ExportAppOptions, FONT_LIBRARY, FONT_PRESETS, type FileChangeEvent, type FileSnippet, type FontCategory, type FontPreset, type FontSpec, type ForecastDay, type FormField, type FormFieldOption, type FormFieldType, type GetFileContentArgs, type GmailGetMessageArgs, type GmailMessageDetail, type GmailMessageSummary, type GmailRequestAccess, type GmailSearchArgs, type GmailSendConfirmation, type GmailSendMessageArgs, type GmailTokenGetter, type InteractiveToolConfig, type KnownTag, LAYOUT_MODES, LIST_FILES_SCHEMA, type LayoutMode, type LegacyDeckJson, type ListEventsArgs, type ListRecentFilesArgs, MapFileStorage, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMcpCaller, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, PATCH_DOCUMENT_SCHEMA, PATCH_FILE_SCHEMA, PATCH_SLIDES_SCHEMA, PLAN_DECK_SCHEMA, type PatchFailure, type PatchFailureReason, type PaymentWallet, type PdfTag, READ_DOCUMENT_SCHEMA, READ_FILE_SCHEMA, READ_SLIDES_SCHEMA, RUNTIME_ERROR_OVERLAY_SCRIPT, SELECT_PAYMENT_WALLET_TOOL_NAME, SLIDES_FILE_PATH, SLIDE_CANVAS_HEIGHT, SLIDE_CANVAS_WIDTH, type SearchFilesArgs, type SelectPaymentWalletResult, SiwxChallengeError, SiwxUnsupportedError, type SlackGetChannelHistoryArgs, type SlackGetThreadRepliesArgs, type SlackListChannelsArgs, type SlackListDmsArgs, type SlackListUsersArgs, type SlackPostMessageArgs, type SlackProxyCaller, type SlackSearchMessagesArgs, type SlideToolSet, type SolanaSignMessageFn, THEME_ATTRS, type ThemeAttr, type ToolConfig, type ToolExecutionErrorType, type ToolExecutionResult, type UIInteractionContext, type UpdateEventArgs, type UpdateFileArgs, VERIFY_APP_SCHEMA, type VerifyAppResult, WALLET_PAYMENT_TOOL_NAME, type WalletPaymentOutcome, type WalletPaymentPassenger, type WalletPaymentRequest, type WalletPaymentResult, type XGetMeArgs, type XGetMyPostsArgs, type XProxyCaller, applyPatches, auditDesign, buildAppFileManifest, buildAppSystemPrompt, buildConnectorErrorResult, buildDocumentSystemPrompt, buildFontsUrl, buildSlideSystemPrompt, callNotionMCPTool, connectorMintErrorToToolResult, convertLegacyDeckJson, createAgentresClient, createAppCompleteBridge, createAppGenerationTools, createChartTool, createChatTools, createChoiceTool, createConfirmTool, createConnectorOfferTool, createConnectorTokenGetter, createDisplayTool, createDocumentTools, createDriveTools, createDropboxTools, createFormTool, createGitHubTools, createGmailTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveCreateFileTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createGoogleDriveUpdateFileTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionProxyTools, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, createPhoneCallOfferTool, createSelectPaymentWalletTool, createSlackTools, createSlideTools, createWalletPaymentTool, createWeatherTool, createXTools, documentPath, exportAppToHtml, findById, findParentOfId, getFontByName, getId, getMCPEndpoints, getNumberAttr, getStringAttr, insertAfterId, insertChild, installAppCompleteIframeShim, isAnumaTag, isHtmlTag, isKnownFont, isLegacyDeckJson, isPdfTag, migrateDisplayResult, normalizePath, parseDocumentDsl, parseJsx, pdfStyleKeys, pdfTags, removeById, replaceById, serializeJsx, truncateContent, updateAttrs, walk };
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1390,6 +1390,7 @@ declare function createInteractiveTool(options: CreateUIToolsOptions, config: In
|
|
|
1390
1390
|
declare function createDisplayTool<TArgs = Record<string, unknown>, TResult = unknown>(options: CreateUIToolsOptions, config: DisplayToolConfig<TArgs, TResult>): ToolConfig;
|
|
1391
1391
|
|
|
1392
1392
|
type ChartDataPoint = Record<string, string | number>;
|
|
1393
|
+
type ChartValueFormat = "number" | "currency" | "percent";
|
|
1393
1394
|
type DisplayChartResult = {
|
|
1394
1395
|
chartType: "bar" | "line" | "area" | "pie";
|
|
1395
1396
|
title?: string;
|
|
@@ -1397,6 +1398,8 @@ type DisplayChartResult = {
|
|
|
1397
1398
|
dataKeys: string[];
|
|
1398
1399
|
xAxisKey?: string;
|
|
1399
1400
|
colors?: Record<string, string>;
|
|
1401
|
+
valueFormat?: ChartValueFormat;
|
|
1402
|
+
currency?: string;
|
|
1400
1403
|
} | {
|
|
1401
1404
|
error: string;
|
|
1402
1405
|
};
|
|
@@ -2929,4 +2932,4 @@ interface XGetMyPostsArgs {
|
|
|
2929
2932
|
*/
|
|
2930
2933
|
declare function createXTools(callProxy: XProxyCaller): Record<string, ToolConfig>;
|
|
2931
2934
|
|
|
2932
|
-
export { ADD_SLIDE_SCHEMA, APP_BUILDER_PROMPT, APP_COMPLETE_CONNECT_ACK_TYPE, APP_COMPLETE_CONNECT_TYPE, APP_COMPLETE_DEFAULT_TIMEOUT_MS, APP_COMPLETE_IFRAME_SHIM_SCRIPT, APP_COMPLETE_REQUEST_TYPE, APP_COMPLETE_RESPONSE_TYPE, APP_COMPLETE_STUB_SCRIPT, APP_FILE_TOOL_NAMES, APP_PREVIEW_BASELINE_CSS, AUDIT_DESIGN_SCHEMA, type AgentresAccount, type AgentresClient, type AgentresClientOptions, AgentresError, type AgentresErrorCode, type AgentresLinkStatus, type AgentresLinkStep, AgentresPathError, type AnchorMatch, type AnumaChild, AnumaJsxError, type AnumaNode, type AppCompleteBridge, type AppCompleteBridgeOptions, type AppFileRecord, type AppFileStorage, type AttrValue, type AuditIssue, type AuditIssueType, type AuditResult, type AuditSeverity, type AuditTokens, type BuildSlideSystemPromptOptions, CHOICE_TOOL_NAME, CONNECTOR_ERROR_MARKER, CREATE_DOCUMENT_SCHEMA, CREATE_FILE_SCHEMA, CRITIQUE_DESIGN_SCHEMA, type CalendarEvent, type ChartDataPoint, type ChoiceOption, type ConfirmParameter, type ConfirmToolResult, type ConnectorErrorCode, type ConnectorMintError, type ConnectorMintResult, type ConnectorTokenGetterOpts, type ConnectorTokenSource, type CreateAppGenerationToolsOptions, type CreateDocumentToolsOptions, type CreateEventArgs, type CreateFileArgs, type CreateSelectPaymentWalletToolOptions, type CreateSlideToolsOptions, type CreateUIToolsOptions, type CreateWalletPaymentToolOptions, type CreateWeatherToolOptions, DEFAULT_DESIGN_CRITIQUE_RUBRIC, DEFAULT_DOCUMENT_ID, DEFAULT_MAX_CONVERSATIONS, DEFAULT_MAX_DOCUMENT_CONVERSATIONS, DELETE_FILE_SCHEMA, DOCUMENT_BUILDER_PROMPT, DOCUMENT_TOOL_NAMES, type DisplayChartResult, type DisplayConnectorResult, type DisplayPhoneCallOfferResult, type DisplayToolConfig, type DisplayToolMigrations, type DisplayWeatherResult, type DocAttrValue, type DocChild, DocDslError, type DocNode, type DriveFile, type DropboxRequestAccess, type DropboxTokenGetter, type ExportAppOptions, FONT_LIBRARY, FONT_PRESETS, type FileChangeEvent, type FileSnippet, type FontCategory, type FontPreset, type FontSpec, type ForecastDay, type FormField, type FormFieldOption, type FormFieldType, type GetFileContentArgs, type GmailGetMessageArgs, type GmailMessageDetail, type GmailMessageSummary, type GmailRequestAccess, type GmailSearchArgs, type GmailSendConfirmation, type GmailSendMessageArgs, type GmailTokenGetter, type InteractiveToolConfig, type KnownTag, LAYOUT_MODES, LIST_FILES_SCHEMA, type LayoutMode, type LegacyDeckJson, type ListEventsArgs, type ListRecentFilesArgs, MapFileStorage, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMcpCaller, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, PATCH_DOCUMENT_SCHEMA, PATCH_FILE_SCHEMA, PATCH_SLIDES_SCHEMA, PLAN_DECK_SCHEMA, type PatchFailure, type PatchFailureReason, type PaymentWallet, type PdfTag, READ_DOCUMENT_SCHEMA, READ_FILE_SCHEMA, READ_SLIDES_SCHEMA, RUNTIME_ERROR_OVERLAY_SCRIPT, SELECT_PAYMENT_WALLET_TOOL_NAME, SLIDES_FILE_PATH, SLIDE_CANVAS_HEIGHT, SLIDE_CANVAS_WIDTH, type SearchFilesArgs, type SelectPaymentWalletResult, SiwxChallengeError, SiwxUnsupportedError, type SlackGetChannelHistoryArgs, type SlackGetThreadRepliesArgs, type SlackListChannelsArgs, type SlackListDmsArgs, type SlackListUsersArgs, type SlackPostMessageArgs, type SlackProxyCaller, type SlackSearchMessagesArgs, type SlideToolSet, type SolanaSignMessageFn, THEME_ATTRS, type ThemeAttr, type ToolConfig, type ToolExecutionErrorType, type ToolExecutionResult, type UIInteractionContext, type UpdateEventArgs, type UpdateFileArgs, VERIFY_APP_SCHEMA, type VerifyAppResult, WALLET_PAYMENT_TOOL_NAME, type WalletPaymentOutcome, type WalletPaymentPassenger, type WalletPaymentRequest, type WalletPaymentResult, type XGetMeArgs, type XGetMyPostsArgs, type XProxyCaller, applyPatches, auditDesign, buildAppFileManifest, buildAppSystemPrompt, buildConnectorErrorResult, buildDocumentSystemPrompt, buildFontsUrl, buildSlideSystemPrompt, callNotionMCPTool, connectorMintErrorToToolResult, convertLegacyDeckJson, createAgentresClient, createAppCompleteBridge, createAppGenerationTools, createChartTool, createChatTools, createChoiceTool, createConfirmTool, createConnectorOfferTool, createConnectorTokenGetter, createDisplayTool, createDocumentTools, createDriveTools, createDropboxTools, createFormTool, createGitHubTools, createGmailTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveCreateFileTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createGoogleDriveUpdateFileTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionProxyTools, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, createPhoneCallOfferTool, createSelectPaymentWalletTool, createSlackTools, createSlideTools, createWalletPaymentTool, createWeatherTool, createXTools, documentPath, exportAppToHtml, findById, findParentOfId, getFontByName, getId, getMCPEndpoints, getNumberAttr, getStringAttr, insertAfterId, insertChild, installAppCompleteIframeShim, isAnumaTag, isHtmlTag, isKnownFont, isLegacyDeckJson, isPdfTag, migrateDisplayResult, normalizePath, parseDocumentDsl, parseJsx, pdfStyleKeys, pdfTags, removeById, replaceById, serializeJsx, truncateContent, updateAttrs, walk };
|
|
2935
|
+
export { ADD_SLIDE_SCHEMA, APP_BUILDER_PROMPT, APP_COMPLETE_CONNECT_ACK_TYPE, APP_COMPLETE_CONNECT_TYPE, APP_COMPLETE_DEFAULT_TIMEOUT_MS, APP_COMPLETE_IFRAME_SHIM_SCRIPT, APP_COMPLETE_REQUEST_TYPE, APP_COMPLETE_RESPONSE_TYPE, APP_COMPLETE_STUB_SCRIPT, APP_FILE_TOOL_NAMES, APP_PREVIEW_BASELINE_CSS, AUDIT_DESIGN_SCHEMA, type AgentresAccount, type AgentresClient, type AgentresClientOptions, AgentresError, type AgentresErrorCode, type AgentresLinkStatus, type AgentresLinkStep, AgentresPathError, type AnchorMatch, type AnumaChild, AnumaJsxError, type AnumaNode, type AppCompleteBridge, type AppCompleteBridgeOptions, type AppFileRecord, type AppFileStorage, type AttrValue, type AuditIssue, type AuditIssueType, type AuditResult, type AuditSeverity, type AuditTokens, type BuildSlideSystemPromptOptions, CHOICE_TOOL_NAME, CONNECTOR_ERROR_MARKER, CREATE_DOCUMENT_SCHEMA, CREATE_FILE_SCHEMA, CRITIQUE_DESIGN_SCHEMA, type CalendarEvent, type ChartDataPoint, type ChartValueFormat, type ChoiceOption, type ConfirmParameter, type ConfirmToolResult, type ConnectorErrorCode, type ConnectorMintError, type ConnectorMintResult, type ConnectorTokenGetterOpts, type ConnectorTokenSource, type CreateAppGenerationToolsOptions, type CreateDocumentToolsOptions, type CreateEventArgs, type CreateFileArgs, type CreateSelectPaymentWalletToolOptions, type CreateSlideToolsOptions, type CreateUIToolsOptions, type CreateWalletPaymentToolOptions, type CreateWeatherToolOptions, DEFAULT_DESIGN_CRITIQUE_RUBRIC, DEFAULT_DOCUMENT_ID, DEFAULT_MAX_CONVERSATIONS, DEFAULT_MAX_DOCUMENT_CONVERSATIONS, DELETE_FILE_SCHEMA, DOCUMENT_BUILDER_PROMPT, DOCUMENT_TOOL_NAMES, type DisplayChartResult, type DisplayConnectorResult, type DisplayPhoneCallOfferResult, type DisplayToolConfig, type DisplayToolMigrations, type DisplayWeatherResult, type DocAttrValue, type DocChild, DocDslError, type DocNode, type DriveFile, type DropboxRequestAccess, type DropboxTokenGetter, type ExportAppOptions, FONT_LIBRARY, FONT_PRESETS, type FileChangeEvent, type FileSnippet, type FontCategory, type FontPreset, type FontSpec, type ForecastDay, type FormField, type FormFieldOption, type FormFieldType, type GetFileContentArgs, type GmailGetMessageArgs, type GmailMessageDetail, type GmailMessageSummary, type GmailRequestAccess, type GmailSearchArgs, type GmailSendConfirmation, type GmailSendMessageArgs, type GmailTokenGetter, type InteractiveToolConfig, type KnownTag, LAYOUT_MODES, LIST_FILES_SCHEMA, type LayoutMode, type LegacyDeckJson, type ListEventsArgs, type ListRecentFilesArgs, MapFileStorage, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMcpCaller, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, PATCH_DOCUMENT_SCHEMA, PATCH_FILE_SCHEMA, PATCH_SLIDES_SCHEMA, PLAN_DECK_SCHEMA, type PatchFailure, type PatchFailureReason, type PaymentWallet, type PdfTag, READ_DOCUMENT_SCHEMA, READ_FILE_SCHEMA, READ_SLIDES_SCHEMA, RUNTIME_ERROR_OVERLAY_SCRIPT, SELECT_PAYMENT_WALLET_TOOL_NAME, SLIDES_FILE_PATH, SLIDE_CANVAS_HEIGHT, SLIDE_CANVAS_WIDTH, type SearchFilesArgs, type SelectPaymentWalletResult, SiwxChallengeError, SiwxUnsupportedError, type SlackGetChannelHistoryArgs, type SlackGetThreadRepliesArgs, type SlackListChannelsArgs, type SlackListDmsArgs, type SlackListUsersArgs, type SlackPostMessageArgs, type SlackProxyCaller, type SlackSearchMessagesArgs, type SlideToolSet, type SolanaSignMessageFn, THEME_ATTRS, type ThemeAttr, type ToolConfig, type ToolExecutionErrorType, type ToolExecutionResult, type UIInteractionContext, type UpdateEventArgs, type UpdateFileArgs, VERIFY_APP_SCHEMA, type VerifyAppResult, WALLET_PAYMENT_TOOL_NAME, type WalletPaymentOutcome, type WalletPaymentPassenger, type WalletPaymentRequest, type WalletPaymentResult, type XGetMeArgs, type XGetMyPostsArgs, type XProxyCaller, applyPatches, auditDesign, buildAppFileManifest, buildAppSystemPrompt, buildConnectorErrorResult, buildDocumentSystemPrompt, buildFontsUrl, buildSlideSystemPrompt, callNotionMCPTool, connectorMintErrorToToolResult, convertLegacyDeckJson, createAgentresClient, createAppCompleteBridge, createAppGenerationTools, createChartTool, createChatTools, createChoiceTool, createConfirmTool, createConnectorOfferTool, createConnectorTokenGetter, createDisplayTool, createDocumentTools, createDriveTools, createDropboxTools, createFormTool, createGitHubTools, createGmailTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveCreateFileTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createGoogleDriveUpdateFileTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionProxyTools, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, createPhoneCallOfferTool, createSelectPaymentWalletTool, createSlackTools, createSlideTools, createWalletPaymentTool, createWeatherTool, createXTools, documentPath, exportAppToHtml, findById, findParentOfId, getFontByName, getId, getMCPEndpoints, getNumberAttr, getStringAttr, insertAfterId, insertChild, installAppCompleteIframeShim, isAnumaTag, isHtmlTag, isKnownFont, isLegacyDeckJson, isPdfTag, migrateDisplayResult, normalizePath, parseDocumentDsl, parseJsx, pdfStyleKeys, pdfTags, removeById, replaceById, serializeJsx, truncateContent, updateAttrs, walk };
|
package/dist/tools/index.mjs
CHANGED
|
@@ -2368,6 +2368,16 @@ function createDisplayTool(options, config) {
|
|
|
2368
2368
|
}
|
|
2369
2369
|
|
|
2370
2370
|
// src/tools/chart.ts
|
|
2371
|
+
var VALUE_FORMATS = ["number", "currency", "percent"];
|
|
2372
|
+
var CURRENCY_CODE = /^[A-Z]{3}$/;
|
|
2373
|
+
function toValueFormat(value) {
|
|
2374
|
+
return VALUE_FORMATS.find((format) => format === value);
|
|
2375
|
+
}
|
|
2376
|
+
function toCurrencyCode(value) {
|
|
2377
|
+
if (typeof value !== "string") return void 0;
|
|
2378
|
+
const code = value.trim().toUpperCase();
|
|
2379
|
+
return CURRENCY_CODE.test(code) ? code : void 0;
|
|
2380
|
+
}
|
|
2371
2381
|
var NUMERIC_STRING = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i;
|
|
2372
2382
|
var THOUSANDS_GROUPED = /^[-+]?\d{1,3}(?:,\d{3})+(?:\.\d*)?$/;
|
|
2373
2383
|
function toNumber(value) {
|
|
@@ -2384,7 +2394,7 @@ function toNumber(value) {
|
|
|
2384
2394
|
function createChartTool(options) {
|
|
2385
2395
|
return createDisplayTool(options, {
|
|
2386
2396
|
name: "display_chart",
|
|
2387
|
-
description: 'Render a bar, line, area, or pie chart inline \u2014 visualize data, plot a trend over time, or graph a comparison. Use whenever the user asks to chart, plot, graph, or visualize numbers (sales, prices, temperatures, metrics). You MUST pass the actual numeric values in the "data" array \u2014 they are never inferred. Do not chart price or market history (crypto, stocks, market caps) unless those values came from a tool result or a cited source earlier in this conversation; never fill a price series from memory.',
|
|
2397
|
+
description: 'Render a bar, line, area, or pie chart inline \u2014 visualize data, plot a trend over time, or graph a comparison. Use whenever the user asks to chart, plot, graph, or visualize numbers (sales, prices, temperatures, metrics). You MUST pass the actual numeric values in the "data" array \u2014 they are never inferred. Do not chart price or market history (crypto, stocks, market caps) unless those values came from a tool result or a cited source earlier in this conversation; never fill a price series from memory. Set valueFormat to "currency" for prices and money, or "percent" for percentage values.',
|
|
2388
2398
|
parameters: {
|
|
2389
2399
|
type: "object",
|
|
2390
2400
|
properties: {
|
|
@@ -2418,6 +2428,15 @@ function createChartTool(options) {
|
|
|
2418
2428
|
type: "object",
|
|
2419
2429
|
additionalProperties: { type: "string" },
|
|
2420
2430
|
description: "Optional color overrides. Map of dataKey to CSS color value (e.g. { 'revenue': '#2563eb' }). If omitted, uses theme chart colors."
|
|
2431
|
+
},
|
|
2432
|
+
valueFormat: {
|
|
2433
|
+
type: "string",
|
|
2434
|
+
enum: ["number", "currency", "percent"],
|
|
2435
|
+
description: 'How to display the values on the axis, tooltip and headline. "currency" for prices and money (set currency too), "percent" when values are already percentages (3.2 means 3.2%). Defaults to "number".'
|
|
2436
|
+
},
|
|
2437
|
+
currency: {
|
|
2438
|
+
type: "string",
|
|
2439
|
+
description: 'ISO 4217 currency code used when valueFormat is "currency", e.g. "USD" or "EUR". Defaults to USD.'
|
|
2421
2440
|
}
|
|
2422
2441
|
},
|
|
2423
2442
|
required: ["chartType", "data", "dataKeys"]
|
|
@@ -2469,7 +2488,9 @@ function createChartTool(options) {
|
|
|
2469
2488
|
data: points,
|
|
2470
2489
|
dataKeys,
|
|
2471
2490
|
xAxisKey: args.xAxisKey,
|
|
2472
|
-
colors: args.colors
|
|
2491
|
+
colors: args.colors,
|
|
2492
|
+
valueFormat: toValueFormat(args.valueFormat),
|
|
2493
|
+
currency: toCurrencyCode(args.currency)
|
|
2473
2494
|
};
|
|
2474
2495
|
}
|
|
2475
2496
|
});
|