pxengine 0.1.145 → 0.1.146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +32 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +32 -2
- package/dist/index.mjs.map +1 -1
- package/dist/registry.json +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24318,6 +24318,17 @@ function highchartsType(type) {
|
|
|
24318
24318
|
if (type === "donut") return "pie";
|
|
24319
24319
|
return type;
|
|
24320
24320
|
}
|
|
24321
|
+
var DOWNSAMPLE_THRESHOLD = 800;
|
|
24322
|
+
function downsampleSeriesData(data, threshold = DOWNSAMPLE_THRESHOLD) {
|
|
24323
|
+
if (!Array.isArray(data) || data.length <= threshold) return data;
|
|
24324
|
+
if (data.every((p) => typeof p === "number")) return data;
|
|
24325
|
+
const stride = Math.ceil(data.length / threshold);
|
|
24326
|
+
const out = [];
|
|
24327
|
+
for (let i = 0; i < data.length; i += stride) out.push(data[i]);
|
|
24328
|
+
const last = data[data.length - 1];
|
|
24329
|
+
if (out[out.length - 1] !== last) out.push(last);
|
|
24330
|
+
return out;
|
|
24331
|
+
}
|
|
24321
24332
|
function buildAxis(axis, fallbackCategories) {
|
|
24322
24333
|
const cfg = {};
|
|
24323
24334
|
if (!axis) {
|
|
@@ -24349,7 +24360,7 @@ function buildChartOptions(config, palette) {
|
|
|
24349
24360
|
subtitle: { text: config.subtitle ?? void 0 },
|
|
24350
24361
|
series: safeSeries.map((s, i) => ({
|
|
24351
24362
|
name: s.name,
|
|
24352
|
-
data: s.data,
|
|
24363
|
+
data: downsampleSeriesData(s.data),
|
|
24353
24364
|
...s.type && { type: highchartsType(s.type) },
|
|
24354
24365
|
...s.stack && { stack: s.stack },
|
|
24355
24366
|
...typeof s.yAxis === "number" && { yAxis: s.yAxis },
|
|
@@ -24568,6 +24579,14 @@ function loadHighcharts() {
|
|
|
24568
24579
|
});
|
|
24569
24580
|
return hcLoadPromise;
|
|
24570
24581
|
}
|
|
24582
|
+
function structuralKey(config) {
|
|
24583
|
+
const type = config?.chart?.type;
|
|
24584
|
+
const xAxis = config?.xAxis;
|
|
24585
|
+
const yAxis = config?.yAxis;
|
|
24586
|
+
const xType = Array.isArray(xAxis) ? xAxis.map((a) => a?.type).join(",") : xAxis?.type;
|
|
24587
|
+
const yCount = Array.isArray(yAxis) ? yAxis.length : yAxis ? 1 : 0;
|
|
24588
|
+
return `${type}|${xType}|${yCount}`;
|
|
24589
|
+
}
|
|
24571
24590
|
function buildTheme(height) {
|
|
24572
24591
|
const colors = [1, 2, 3, 4, 5, 6, 7, 8].map((i) => getCSSVar(`--chart-${i}`)).filter(Boolean);
|
|
24573
24592
|
return {
|
|
@@ -24636,6 +24655,7 @@ function AnalyticsChart({
|
|
|
24636
24655
|
const [fetchError, setFetchError] = (0, import_react99.useState)(null);
|
|
24637
24656
|
const containerRef = (0, import_react99.useRef)(null);
|
|
24638
24657
|
const chartRef = (0, import_react99.useRef)(null);
|
|
24658
|
+
const structuralKeyRef = (0, import_react99.useRef)(null);
|
|
24639
24659
|
const declarative = (0, import_react99.useMemo)(
|
|
24640
24660
|
() => resolveDeclarativeConfig({
|
|
24641
24661
|
chartConfig,
|
|
@@ -24705,8 +24725,17 @@ function AnalyticsChart({
|
|
|
24705
24725
|
if (!mounted || !activeConfig || !containerRef.current) return;
|
|
24706
24726
|
const container = containerRef.current;
|
|
24707
24727
|
let cancelled = false;
|
|
24728
|
+
const nextConfig = normalizeConfig(stripNulls(activeConfig));
|
|
24729
|
+
const nextKey = structuralKey(nextConfig);
|
|
24708
24730
|
loadHighcharts().then((HC) => {
|
|
24709
24731
|
if (cancelled || !container) return;
|
|
24732
|
+
if (chartRef.current && structuralKeyRef.current === nextKey) {
|
|
24733
|
+
try {
|
|
24734
|
+
chartRef.current.update(nextConfig, true, true);
|
|
24735
|
+
return;
|
|
24736
|
+
} catch {
|
|
24737
|
+
}
|
|
24738
|
+
}
|
|
24710
24739
|
if (chartRef.current) {
|
|
24711
24740
|
try {
|
|
24712
24741
|
chartRef.current.destroy();
|
|
@@ -24715,7 +24744,8 @@ function AnalyticsChart({
|
|
|
24715
24744
|
chartRef.current = null;
|
|
24716
24745
|
}
|
|
24717
24746
|
HC.setOptions(buildTheme(height));
|
|
24718
|
-
chartRef.current = HC.chart(container,
|
|
24747
|
+
chartRef.current = HC.chart(container, nextConfig);
|
|
24748
|
+
structuralKeyRef.current = nextKey;
|
|
24719
24749
|
});
|
|
24720
24750
|
return () => {
|
|
24721
24751
|
cancelled = true;
|