@anuma/sdk 11.2.0 → 11.3.1
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 +221 -176
- package/dist/react/index.mjs +221 -176
- package/dist/tools/index.cjs +157 -0
- package/dist/tools/index.d.mts +41 -1
- package/dist/tools/index.d.ts +41 -1
- package/dist/tools/index.mjs +154 -0
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -36474,6 +36474,159 @@ function renderAnumaJsx(jsx3) {
|
|
|
36474
36474
|
var React2 = __toESM(require("react"));
|
|
36475
36475
|
var RechartsPrimitive = __toESM(require("recharts"));
|
|
36476
36476
|
var import_recharts = require("recharts");
|
|
36477
|
+
|
|
36478
|
+
// src/tools/chartModel.ts
|
|
36479
|
+
var DOT_LIMIT = 12;
|
|
36480
|
+
var MAX_TICKS = 8;
|
|
36481
|
+
var MINUS = "\u2212";
|
|
36482
|
+
function chartCellText(value) {
|
|
36483
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
36484
|
+
}
|
|
36485
|
+
function tickDigits(ticks) {
|
|
36486
|
+
if (!ticks || ticks.length < 2) return 3;
|
|
36487
|
+
const step = ticks[1] - ticks[0];
|
|
36488
|
+
const magnitude = Math.max(...ticks.map(Math.abs));
|
|
36489
|
+
if (step <= 0 || magnitude === 0) return 3;
|
|
36490
|
+
const needed = Math.floor(Math.log10(magnitude)) - Math.floor(Math.log10(step)) + 1;
|
|
36491
|
+
return Math.min(21, Math.max(3, needed));
|
|
36492
|
+
}
|
|
36493
|
+
function keepSmall(options) {
|
|
36494
|
+
const small = new Intl.NumberFormat(void 0, { ...options, maximumSignificantDigits: 3 });
|
|
36495
|
+
const regular = new Intl.NumberFormat(void 0, { ...options, maximumFractionDigits: 2 });
|
|
36496
|
+
return (n, format) => format(n !== 0 && Math.abs(n) < 1 ? small : regular, n);
|
|
36497
|
+
}
|
|
36498
|
+
function buildFormatters(format, currency, ticks) {
|
|
36499
|
+
const digits = tickDigits(ticks);
|
|
36500
|
+
if (format === "currency") {
|
|
36501
|
+
const money = (options) => new Intl.NumberFormat(void 0, {
|
|
36502
|
+
style: "currency",
|
|
36503
|
+
currency: currency ?? "USD",
|
|
36504
|
+
...options
|
|
36505
|
+
});
|
|
36506
|
+
const compact2 = money({ notation: "compact", maximumSignificantDigits: 3 });
|
|
36507
|
+
const tick2 = money({ notation: "compact", maximumSignificantDigits: digits });
|
|
36508
|
+
const small2 = money({ maximumSignificantDigits: 4 });
|
|
36509
|
+
const cents = money({ minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
36510
|
+
const value2 = (n) => Math.abs(n) >= 1e6 ? compact2.format(n) : n !== 0 && Math.abs(n) < 1 ? small2.format(n) : cents.format(n);
|
|
36511
|
+
return { tick: (n) => tick2.format(n), value: value2, change: (d) => value2(Math.abs(d)) };
|
|
36512
|
+
}
|
|
36513
|
+
if (format === "percent") {
|
|
36514
|
+
const percent = keepSmall({ style: "percent" });
|
|
36515
|
+
const points = keepSmall({});
|
|
36516
|
+
const tick2 = new Intl.NumberFormat(void 0, {
|
|
36517
|
+
style: "percent",
|
|
36518
|
+
maximumSignificantDigits: digits
|
|
36519
|
+
});
|
|
36520
|
+
return {
|
|
36521
|
+
tick: (n) => tick2.format(n / 100),
|
|
36522
|
+
value: (n) => percent(n, (formatter) => formatter.format(n / 100)),
|
|
36523
|
+
change: (d) => `${points(Math.abs(d), (formatter, n) => formatter.format(n))} pts`
|
|
36524
|
+
};
|
|
36525
|
+
}
|
|
36526
|
+
const tick = new Intl.NumberFormat(void 0, {
|
|
36527
|
+
notation: "compact",
|
|
36528
|
+
maximumSignificantDigits: digits
|
|
36529
|
+
});
|
|
36530
|
+
const compact = new Intl.NumberFormat(void 0, {
|
|
36531
|
+
notation: "compact",
|
|
36532
|
+
maximumSignificantDigits: 3
|
|
36533
|
+
});
|
|
36534
|
+
const small = new Intl.NumberFormat(void 0, { maximumSignificantDigits: 4 });
|
|
36535
|
+
const plain2 = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 });
|
|
36536
|
+
const value = (n) => Math.abs(n) >= 1e6 ? compact.format(n) : n !== 0 && Math.abs(n) < 1 ? small.format(n) : plain2.format(n);
|
|
36537
|
+
return { tick: (n) => tick.format(n), value, change: (d) => value(Math.abs(d)) };
|
|
36538
|
+
}
|
|
36539
|
+
function seriesValues(points, keys) {
|
|
36540
|
+
return points.flatMap(
|
|
36541
|
+
(point) => keys.map((key3) => point[key3]).filter((v) => typeof v === "number")
|
|
36542
|
+
);
|
|
36543
|
+
}
|
|
36544
|
+
function niceStep(rough) {
|
|
36545
|
+
const exponent = Math.floor(Math.log10(rough));
|
|
36546
|
+
const base = 10 ** exponent;
|
|
36547
|
+
const fraction = rough / base;
|
|
36548
|
+
const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
|
|
36549
|
+
return nice * base;
|
|
36550
|
+
}
|
|
36551
|
+
function niceTicks(values) {
|
|
36552
|
+
if (values.length === 0) return void 0;
|
|
36553
|
+
const min = Math.min(...values);
|
|
36554
|
+
const max = Math.max(...values);
|
|
36555
|
+
const span = max - min || Math.abs(max) * 0.02 || 1;
|
|
36556
|
+
const low = min - span * 0.1;
|
|
36557
|
+
const high = max + span * 0.1;
|
|
36558
|
+
const step = niceStep((high - low) / 3);
|
|
36559
|
+
const start = min >= 0 ? Math.max(0, Math.floor(low / step) * step) : Math.floor(low / step) * step;
|
|
36560
|
+
const ticks = [];
|
|
36561
|
+
for (let index = 0; index <= MAX_TICKS; index++) {
|
|
36562
|
+
const tick = Number((start + index * step).toPrecision(15));
|
|
36563
|
+
if (ticks.length > 0 && tick <= ticks[ticks.length - 1]) break;
|
|
36564
|
+
ticks.push(tick);
|
|
36565
|
+
if (tick >= high) break;
|
|
36566
|
+
}
|
|
36567
|
+
return ticks.length >= 2 ? ticks : void 0;
|
|
36568
|
+
}
|
|
36569
|
+
function buildTrend(values, format, formatters) {
|
|
36570
|
+
if (values.length < 2) return void 0;
|
|
36571
|
+
const first = values[0];
|
|
36572
|
+
const last = values[values.length - 1];
|
|
36573
|
+
const difference = last - first;
|
|
36574
|
+
const direction = difference > 0 ? "up" : difference < 0 ? "down" : "flat";
|
|
36575
|
+
const sign = direction === "up" ? "+" : direction === "down" ? MINUS : "";
|
|
36576
|
+
const percent = format !== "percent" && first !== 0 ? ` (${sign}${new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }).format(
|
|
36577
|
+
Math.abs(difference / Math.abs(first) * 100)
|
|
36578
|
+
)}%)` : "";
|
|
36579
|
+
return {
|
|
36580
|
+
value: formatters.value(last),
|
|
36581
|
+
change: `${sign}${formatters.change(difference)}${percent}`,
|
|
36582
|
+
direction
|
|
36583
|
+
};
|
|
36584
|
+
}
|
|
36585
|
+
function lastValueIndex(points, key3) {
|
|
36586
|
+
for (let index = points.length - 1; index >= 0; index--) {
|
|
36587
|
+
if (typeof points[index][key3] === "number") return index;
|
|
36588
|
+
}
|
|
36589
|
+
return -1;
|
|
36590
|
+
}
|
|
36591
|
+
function chartSeriesLabel(key3) {
|
|
36592
|
+
return key3.charAt(0).toUpperCase() + key3.slice(1);
|
|
36593
|
+
}
|
|
36594
|
+
function buildChartModel(spec) {
|
|
36595
|
+
const { chartType, title, data, dataKeys, xAxisKey, valueFormat, currency } = spec;
|
|
36596
|
+
const isTrendChart = chartType === "line" || chartType === "area";
|
|
36597
|
+
const plottedKeys = chartType === "pie" ? dataKeys.slice(0, 1) : dataKeys;
|
|
36598
|
+
const values = seriesValues(data, plottedKeys);
|
|
36599
|
+
const yTicks = isTrendChart ? niceTicks(values) : void 0;
|
|
36600
|
+
const yDomain = yTicks ? [yTicks[0], yTicks[yTicks.length - 1]] : void 0;
|
|
36601
|
+
const formatters = buildFormatters(valueFormat, currency, yTicks);
|
|
36602
|
+
const seriesLabels = Object.fromEntries(dataKeys.map((key3) => [key3, chartSeriesLabel(key3)]));
|
|
36603
|
+
const trendBase = isTrendChart && dataKeys.length === 1 ? buildTrend(values, valueFormat, formatters) : void 0;
|
|
36604
|
+
const trendRows = trendBase ? data.filter((point) => typeof point[dataKeys[0]] === "number") : [];
|
|
36605
|
+
const range = trendBase && xAxisKey ? [trendRows[0], trendRows[trendRows.length - 1]].map((point) => chartCellText(point[xAxisKey])).filter(Boolean).join(" \u2013 ") || void 0 : void 0;
|
|
36606
|
+
const trend = trendBase ? { ...trendBase, range } : void 0;
|
|
36607
|
+
const tickSamples = [...yDomain ?? [], ...values].map((value) => formatters.tick(value));
|
|
36608
|
+
const showDots = data.length <= DOT_LIMIT;
|
|
36609
|
+
return {
|
|
36610
|
+
isTrendChart,
|
|
36611
|
+
plottedKeys,
|
|
36612
|
+
seriesLabels,
|
|
36613
|
+
labelKey: chartType === "pie" ? xAxisKey || "name" : xAxisKey,
|
|
36614
|
+
values,
|
|
36615
|
+
yTicks,
|
|
36616
|
+
yDomain,
|
|
36617
|
+
formatters,
|
|
36618
|
+
trend,
|
|
36619
|
+
title: title ?? (trend ? seriesLabels[dataKeys[0]] : void 0),
|
|
36620
|
+
showDots,
|
|
36621
|
+
endIndexes: Object.fromEntries(plottedKeys.map((key3) => [key3, lastValueIndex(data, key3)])),
|
|
36622
|
+
curve: showDots ? "linear" : "monotone",
|
|
36623
|
+
hasNegative: values.some((value) => value < 0),
|
|
36624
|
+
longestTickLength: tickSamples.reduce((max, label) => Math.max(max, label.length), 0),
|
|
36625
|
+
total: values.reduce((sum, value) => sum + value, 0)
|
|
36626
|
+
};
|
|
36627
|
+
}
|
|
36628
|
+
|
|
36629
|
+
// src/react/chart.tsx
|
|
36477
36630
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
36478
36631
|
function cx(...classes) {
|
|
36479
36632
|
return classes.filter(Boolean).join(" ");
|
|
@@ -36670,7 +36823,7 @@ function ChartLegendContent({
|
|
|
36670
36823
|
style: { backgroundColor: item.color }
|
|
36671
36824
|
}
|
|
36672
36825
|
),
|
|
36673
|
-
itemConfig?.label ??
|
|
36826
|
+
itemConfig?.label ?? chartCellText(item.value)
|
|
36674
36827
|
]
|
|
36675
36828
|
},
|
|
36676
36829
|
String(item.value)
|
|
@@ -36698,15 +36851,9 @@ var DEFAULT_COLORS = [
|
|
|
36698
36851
|
"var(--chart-5)"
|
|
36699
36852
|
];
|
|
36700
36853
|
var SURFACE = "var(--chart-surface)";
|
|
36701
|
-
var DOT_LIMIT = 12;
|
|
36702
|
-
var MAX_TICKS = 8;
|
|
36703
|
-
var MINUS = "\u2212";
|
|
36704
36854
|
function paletteColor(index) {
|
|
36705
36855
|
return index < DEFAULT_COLORS.length ? DEFAULT_COLORS[index] : `hsl(${Math.round(index * 137.508 % 360)} 65% 55%)`;
|
|
36706
36856
|
}
|
|
36707
|
-
function cellText(value) {
|
|
36708
|
-
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
36709
|
-
}
|
|
36710
36857
|
var VISUALLY_HIDDEN = {
|
|
36711
36858
|
position: "absolute",
|
|
36712
36859
|
width: 1,
|
|
@@ -36718,107 +36865,17 @@ var VISUALLY_HIDDEN = {
|
|
|
36718
36865
|
whiteSpace: "nowrap",
|
|
36719
36866
|
border: 0
|
|
36720
36867
|
};
|
|
36721
|
-
function
|
|
36722
|
-
if (!ticks || ticks.length < 2) return 3;
|
|
36723
|
-
const step = ticks[1] - ticks[0];
|
|
36724
|
-
const magnitude = Math.max(...ticks.map(Math.abs));
|
|
36725
|
-
if (step <= 0 || magnitude === 0) return 3;
|
|
36726
|
-
const needed = Math.floor(Math.log10(magnitude)) - Math.floor(Math.log10(step)) + 1;
|
|
36727
|
-
return Math.min(21, Math.max(3, needed));
|
|
36728
|
-
}
|
|
36729
|
-
function keepSmall(options) {
|
|
36730
|
-
const small = new Intl.NumberFormat(void 0, { ...options, maximumSignificantDigits: 3 });
|
|
36731
|
-
const regular = new Intl.NumberFormat(void 0, { ...options, maximumFractionDigits: 2 });
|
|
36732
|
-
return (n, format) => format(n !== 0 && Math.abs(n) < 1 ? small : regular, n);
|
|
36733
|
-
}
|
|
36734
|
-
function buildFormatters(format, currency, ticks) {
|
|
36735
|
-
const digits = tickDigits(ticks);
|
|
36736
|
-
if (format === "currency") {
|
|
36737
|
-
const money = (options) => new Intl.NumberFormat(void 0, {
|
|
36738
|
-
style: "currency",
|
|
36739
|
-
currency: currency ?? "USD",
|
|
36740
|
-
...options
|
|
36741
|
-
});
|
|
36742
|
-
const compact2 = money({ notation: "compact", maximumSignificantDigits: 3 });
|
|
36743
|
-
const tick2 = money({ notation: "compact", maximumSignificantDigits: digits });
|
|
36744
|
-
const small2 = money({ maximumSignificantDigits: 4 });
|
|
36745
|
-
const cents = money({ minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
36746
|
-
const value2 = (n) => Math.abs(n) >= 1e6 ? compact2.format(n) : n !== 0 && Math.abs(n) < 1 ? small2.format(n) : cents.format(n);
|
|
36747
|
-
return { tick: (n) => tick2.format(n), value: value2, change: (d) => value2(Math.abs(d)) };
|
|
36748
|
-
}
|
|
36749
|
-
if (format === "percent") {
|
|
36750
|
-
const percent = keepSmall({ style: "percent" });
|
|
36751
|
-
const points = keepSmall({});
|
|
36752
|
-
const tick2 = new Intl.NumberFormat(void 0, {
|
|
36753
|
-
style: "percent",
|
|
36754
|
-
maximumSignificantDigits: digits
|
|
36755
|
-
});
|
|
36756
|
-
return {
|
|
36757
|
-
tick: (n) => tick2.format(n / 100),
|
|
36758
|
-
value: (n) => percent(n, (formatter) => formatter.format(n / 100)),
|
|
36759
|
-
change: (d) => `${points(Math.abs(d), (formatter, n) => formatter.format(n))} pts`
|
|
36760
|
-
};
|
|
36761
|
-
}
|
|
36762
|
-
const tick = new Intl.NumberFormat(void 0, {
|
|
36763
|
-
notation: "compact",
|
|
36764
|
-
maximumSignificantDigits: digits
|
|
36765
|
-
});
|
|
36766
|
-
const compact = new Intl.NumberFormat(void 0, {
|
|
36767
|
-
notation: "compact",
|
|
36768
|
-
maximumSignificantDigits: 3
|
|
36769
|
-
});
|
|
36770
|
-
const small = new Intl.NumberFormat(void 0, { maximumSignificantDigits: 4 });
|
|
36771
|
-
const plain2 = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 });
|
|
36772
|
-
const value = (n) => Math.abs(n) >= 1e6 ? compact.format(n) : n !== 0 && Math.abs(n) < 1 ? small.format(n) : plain2.format(n);
|
|
36773
|
-
return { tick: (n) => tick.format(n), value, change: (d) => value(Math.abs(d)) };
|
|
36774
|
-
}
|
|
36775
|
-
function seriesValues(points, keys) {
|
|
36776
|
-
return points.flatMap(
|
|
36777
|
-
(point) => keys.map((key3) => point[key3]).filter((v) => typeof v === "number")
|
|
36778
|
-
);
|
|
36779
|
-
}
|
|
36780
|
-
function niceStep(rough) {
|
|
36781
|
-
const exponent = Math.floor(Math.log10(rough));
|
|
36782
|
-
const base = 10 ** exponent;
|
|
36783
|
-
const fraction = rough / base;
|
|
36784
|
-
const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
|
|
36785
|
-
return nice * base;
|
|
36786
|
-
}
|
|
36787
|
-
function niceTicks(values) {
|
|
36788
|
-
if (values.length === 0) return void 0;
|
|
36789
|
-
const min = Math.min(...values);
|
|
36790
|
-
const max = Math.max(...values);
|
|
36791
|
-
const span = max - min || Math.abs(max) * 0.02 || 1;
|
|
36792
|
-
const low = min - span * 0.1;
|
|
36793
|
-
const high = max + span * 0.1;
|
|
36794
|
-
const step = niceStep((high - low) / 3);
|
|
36795
|
-
const start = min >= 0 ? Math.max(0, Math.floor(low / step) * step) : Math.floor(low / step) * step;
|
|
36796
|
-
const ticks = [];
|
|
36797
|
-
for (let index = 0; index <= MAX_TICKS; index++) {
|
|
36798
|
-
const tick = Number((start + index * step).toPrecision(15));
|
|
36799
|
-
if (ticks.length > 0 && tick <= ticks[ticks.length - 1]) break;
|
|
36800
|
-
ticks.push(tick);
|
|
36801
|
-
if (tick >= high) break;
|
|
36802
|
-
}
|
|
36803
|
-
return ticks.length >= 2 ? ticks : void 0;
|
|
36804
|
-
}
|
|
36805
|
-
function buildChartConfig(dataKeys, colors) {
|
|
36868
|
+
function buildChartConfig(dataKeys, labels, colors) {
|
|
36806
36869
|
const config = {};
|
|
36807
36870
|
dataKeys.forEach((key3, i) => {
|
|
36808
36871
|
const custom = colors?.[key3];
|
|
36809
36872
|
config[key3] = {
|
|
36810
|
-
label: key3
|
|
36873
|
+
label: labels[key3],
|
|
36811
36874
|
color: isSafeCssColor(custom) ? custom : paletteColor(i)
|
|
36812
36875
|
};
|
|
36813
36876
|
});
|
|
36814
36877
|
return config;
|
|
36815
36878
|
}
|
|
36816
|
-
function lastValueIndex(points, key3) {
|
|
36817
|
-
for (let index = points.length - 1; index >= 0; index--) {
|
|
36818
|
-
if (typeof points[index][key3] === "number") return index;
|
|
36819
|
-
}
|
|
36820
|
-
return -1;
|
|
36821
|
-
}
|
|
36822
36879
|
function usePrefersReducedMotion() {
|
|
36823
36880
|
const [reduced, setReduced] = React2.useState(false);
|
|
36824
36881
|
React2.useEffect(() => {
|
|
@@ -36831,33 +36888,13 @@ function usePrefersReducedMotion() {
|
|
|
36831
36888
|
}, []);
|
|
36832
36889
|
return reduced;
|
|
36833
36890
|
}
|
|
36834
|
-
function buildTrend(values, format, formatters) {
|
|
36835
|
-
if (values.length < 2) return void 0;
|
|
36836
|
-
const first = values[0];
|
|
36837
|
-
const last = values[values.length - 1];
|
|
36838
|
-
const difference = last - first;
|
|
36839
|
-
const direction = difference > 0 ? "up" : difference < 0 ? "down" : "flat";
|
|
36840
|
-
const sign = direction === "up" ? "+" : direction === "down" ? MINUS : "";
|
|
36841
|
-
const percent = format !== "percent" && first !== 0 ? ` (${sign}${new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }).format(
|
|
36842
|
-
Math.abs(difference / Math.abs(first) * 100)
|
|
36843
|
-
)}%)` : "";
|
|
36844
|
-
return {
|
|
36845
|
-
value: formatters.value(last),
|
|
36846
|
-
change: `${sign}${formatters.change(difference)}${percent}`,
|
|
36847
|
-
direction
|
|
36848
|
-
};
|
|
36849
|
-
}
|
|
36850
36891
|
var TREND_CLASS = {
|
|
36851
36892
|
up: "text-emerald-600 dark:text-emerald-400",
|
|
36852
36893
|
down: "text-red-600 dark:text-red-400",
|
|
36853
36894
|
flat: "text-muted-foreground"
|
|
36854
36895
|
};
|
|
36855
36896
|
var TREND_ARROW = { up: "\u25B2", down: "\u25BC", flat: "" };
|
|
36856
|
-
function ChartHeader({
|
|
36857
|
-
title,
|
|
36858
|
-
trend,
|
|
36859
|
-
range
|
|
36860
|
-
}) {
|
|
36897
|
+
function ChartHeader({ title, trend }) {
|
|
36861
36898
|
if (!trend) {
|
|
36862
36899
|
return title ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mb-3 text-sm font-medium", children: title }) : null;
|
|
36863
36900
|
}
|
|
@@ -36869,7 +36906,7 @@ function ChartHeader({
|
|
|
36869
36906
|
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] }),
|
|
36870
36907
|
trend.change
|
|
36871
36908
|
] }),
|
|
36872
|
-
range && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-muted-foreground", children: range })
|
|
36909
|
+
trend.range && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-muted-foreground", children: trend.range })
|
|
36873
36910
|
] })
|
|
36874
36911
|
] });
|
|
36875
36912
|
}
|
|
@@ -36885,34 +36922,13 @@ function ChartCard({ data }) {
|
|
|
36885
36922
|
if ("error" in data) {
|
|
36886
36923
|
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." }) }) });
|
|
36887
36924
|
}
|
|
36888
|
-
const {
|
|
36889
|
-
|
|
36890
|
-
|
|
36891
|
-
|
|
36892
|
-
dataKeys,
|
|
36893
|
-
xAxisKey,
|
|
36894
|
-
colors,
|
|
36895
|
-
valueFormat,
|
|
36896
|
-
currency
|
|
36897
|
-
} = data;
|
|
36898
|
-
const chartConfig = buildChartConfig(dataKeys, colors);
|
|
36925
|
+
const { chartType, title, data: chartData, dataKeys, xAxisKey, colors } = data;
|
|
36926
|
+
const model = buildChartModel(data);
|
|
36927
|
+
const { plottedKeys, yTicks, yDomain, formatters, trend, isTrendChart } = model;
|
|
36928
|
+
const chartConfig = buildChartConfig(dataKeys, model.seriesLabels, colors);
|
|
36899
36929
|
const seriesColor = (key3) => chartConfig[key3]?.color;
|
|
36900
|
-
const isTrendChart = chartType === "line" || chartType === "area";
|
|
36901
|
-
const plottedKeys = chartType === "pie" ? dataKeys.slice(0, 1) : dataKeys;
|
|
36902
|
-
const values = seriesValues(chartData, plottedKeys);
|
|
36903
|
-
const yTicks = isTrendChart ? niceTicks(values) : void 0;
|
|
36904
|
-
const yDomain = yTicks ? [yTicks[0], yTicks[yTicks.length - 1]] : void 0;
|
|
36905
|
-
const formatters = buildFormatters(valueFormat, currency, yTicks);
|
|
36906
|
-
const trend = isTrendChart && dataKeys.length === 1 ? buildTrend(values, valueFormat, formatters) : void 0;
|
|
36907
|
-
const trendRows = trend ? chartData.filter((point) => typeof point[dataKeys[0]] === "number") : [];
|
|
36908
|
-
const range = trend && xAxisKey ? [trendRows[0], trendRows[trendRows.length - 1]].map((point) => cellText(point[xAxisKey])).filter(Boolean).join(" \u2013 ") : void 0;
|
|
36909
|
-
const headerTitle = title ?? (trend ? chartConfig[dataKeys[0]]?.label : void 0);
|
|
36910
|
-
const tickSamples = [...yDomain ?? [], ...values].map((value) => formatters.tick(value));
|
|
36911
|
-
const longestTick = tickSamples.reduce((max, label) => Math.max(max, label.length), 0);
|
|
36912
36930
|
const animate = !reducedMotion;
|
|
36913
|
-
const showDots
|
|
36914
|
-
const curve = showDots ? "linear" : "monotone";
|
|
36915
|
-
const hasNegative = values.some((value) => value < 0);
|
|
36931
|
+
const { showDots, curve, hasNegative, endIndexes } = model;
|
|
36916
36932
|
const margin = { top: 8, right: 8, bottom: 0, left: 0 };
|
|
36917
36933
|
const xAxis = xAxisKey && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36918
36934
|
import_recharts.XAxis,
|
|
@@ -36937,7 +36953,7 @@ function ChartCard({ data }) {
|
|
|
36937
36953
|
tickFormatter: formatters.tick,
|
|
36938
36954
|
domain: yDomain,
|
|
36939
36955
|
allowDataOverflow: false,
|
|
36940
|
-
width: Math.min(120, Math.max(36,
|
|
36956
|
+
width: Math.min(120, Math.max(36, model.longestTickLength * 7 + 12))
|
|
36941
36957
|
}
|
|
36942
36958
|
);
|
|
36943
36959
|
const tooltip = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -36960,9 +36976,8 @@ function ChartCard({ data }) {
|
|
|
36960
36976
|
stroke: SURFACE,
|
|
36961
36977
|
strokeWidth: 2
|
|
36962
36978
|
});
|
|
36963
|
-
const lineDot = (key3) => showDots ? marker(key3, 4) : (props) => props.index ===
|
|
36964
|
-
const
|
|
36965
|
-
const tableColumns = labelKey ? [labelKey, ...plottedKeys] : plottedKeys;
|
|
36979
|
+
const lineDot = (key3) => showDots ? marker(key3, 4) : (props) => props.index === endIndexes[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}`);
|
|
36980
|
+
const tableColumns = model.labelKey ? [model.labelKey, ...plottedKeys] : plottedKeys;
|
|
36966
36981
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36967
36982
|
"div",
|
|
36968
36983
|
{
|
|
@@ -36971,10 +36986,10 @@ function ChartCard({ data }) {
|
|
|
36971
36986
|
role: "figure",
|
|
36972
36987
|
"aria-label": [title, `${chartType} chart`].filter(Boolean).join(", "),
|
|
36973
36988
|
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: [
|
|
36974
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartHeader, { title:
|
|
36989
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartHeader, { title: model.title, trend }),
|
|
36975
36990
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("table", { style: VISUALLY_HIDDEN, children: [
|
|
36976
36991
|
/* @__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)) }) }),
|
|
36977
|
-
/* @__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:
|
|
36992
|
+
/* @__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: chartCellText(point[column]) }, column)) }, row)) })
|
|
36978
36993
|
] }),
|
|
36979
36994
|
ready ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
36980
36995
|
ChartContainer,
|
|
@@ -37090,7 +37105,7 @@ function ChartCard({ data }) {
|
|
|
37090
37105
|
x: box.cx,
|
|
37091
37106
|
y: box.cy - 6,
|
|
37092
37107
|
className: "fill-foreground text-lg font-semibold",
|
|
37093
|
-
children: formatters.value(
|
|
37108
|
+
children: formatters.value(model.total)
|
|
37094
37109
|
}
|
|
37095
37110
|
),
|
|
37096
37111
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tspan", { x: box.cx, y: box.cy + 14, className: "fill-muted-foreground", children: "Total" })
|
|
@@ -37223,30 +37238,60 @@ async function authenticateICloud() {
|
|
|
37223
37238
|
ensureAuthElements();
|
|
37224
37239
|
return container.setUpAuth();
|
|
37225
37240
|
}
|
|
37226
|
-
async function requestICloudSignIn(
|
|
37227
|
-
|
|
37228
|
-
|
|
37229
|
-
|
|
37230
|
-
|
|
37231
|
-
|
|
37232
|
-
|
|
37233
|
-
|
|
37234
|
-
|
|
37235
|
-
const
|
|
37236
|
-
|
|
37237
|
-
|
|
37238
|
-
|
|
37239
|
-
|
|
37240
|
-
|
|
37241
|
-
|
|
37242
|
-
|
|
37243
|
-
|
|
37244
|
-
|
|
37245
|
-
|
|
37246
|
-
|
|
37241
|
+
async function requestICloudSignIn({
|
|
37242
|
+
signal
|
|
37243
|
+
} = {}) {
|
|
37244
|
+
if (signal?.aborted) {
|
|
37245
|
+
throw new Error("Sign-in was cancelled");
|
|
37246
|
+
}
|
|
37247
|
+
let cancellationError;
|
|
37248
|
+
let timer;
|
|
37249
|
+
let onAbort;
|
|
37250
|
+
const cancellation = new Promise((_resolve, reject) => {
|
|
37251
|
+
const cancel = (error) => {
|
|
37252
|
+
cancellationError = error;
|
|
37253
|
+
reject(error);
|
|
37254
|
+
};
|
|
37255
|
+
onAbort = () => cancel(new Error("Sign-in was cancelled"));
|
|
37256
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
37257
|
+
timer = setTimeout(() => cancel(new Error("iCloud sign-in timed out")), 6e4);
|
|
37258
|
+
});
|
|
37259
|
+
const throwIfCancelled = () => {
|
|
37260
|
+
if (cancellationError) throw cancellationError;
|
|
37261
|
+
};
|
|
37262
|
+
const signInRequest = async () => {
|
|
37263
|
+
const container = await getContainer();
|
|
37264
|
+
throwIfCancelled();
|
|
37265
|
+
const { signIn } = ensureAuthElements();
|
|
37266
|
+
const existingUser = await container.setUpAuth();
|
|
37267
|
+
throwIfCancelled();
|
|
37268
|
+
if (existingUser) {
|
|
37269
|
+
return existingUser;
|
|
37270
|
+
}
|
|
37271
|
+
getLogger().debug("[CloudKit] Sign-in container innerHTML:", signIn.innerHTML);
|
|
37272
|
+
getLogger().debug("[CloudKit] Sign-in container children:", signIn.children.length);
|
|
37273
|
+
const appleButton = signIn.querySelector(
|
|
37274
|
+
"a, button, [role='button'], div[id*='apple']"
|
|
37275
|
+
);
|
|
37276
|
+
getLogger().debug("[CloudKit] Found button element:", appleButton);
|
|
37277
|
+
if (appleButton) {
|
|
37278
|
+
getLogger().debug("[CloudKit] Clicking button...");
|
|
37279
|
+
appleButton.click();
|
|
37280
|
+
} else {
|
|
37281
|
+
const anyClickable = signIn.firstElementChild;
|
|
37282
|
+
if (anyClickable) {
|
|
37283
|
+
getLogger().debug("[CloudKit] Clicking first child element:", anyClickable);
|
|
37284
|
+
anyClickable.click();
|
|
37285
|
+
}
|
|
37247
37286
|
}
|
|
37287
|
+
return container.whenUserSignsIn();
|
|
37288
|
+
};
|
|
37289
|
+
try {
|
|
37290
|
+
return await Promise.race([signInRequest(), cancellation]);
|
|
37291
|
+
} finally {
|
|
37292
|
+
clearTimeout(timer);
|
|
37293
|
+
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
37248
37294
|
}
|
|
37249
|
-
return container.whenUserSignsIn();
|
|
37250
37295
|
}
|
|
37251
37296
|
async function uploadFileToICloud(filename, content, backupRevision) {
|
|
37252
37297
|
const container = await getContainer();
|