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.mjs CHANGED
@@ -23975,6 +23975,17 @@ function highchartsType(type) {
23975
23975
  if (type === "donut") return "pie";
23976
23976
  return type;
23977
23977
  }
23978
+ var DOWNSAMPLE_THRESHOLD = 800;
23979
+ function downsampleSeriesData(data, threshold = DOWNSAMPLE_THRESHOLD) {
23980
+ if (!Array.isArray(data) || data.length <= threshold) return data;
23981
+ if (data.every((p) => typeof p === "number")) return data;
23982
+ const stride = Math.ceil(data.length / threshold);
23983
+ const out = [];
23984
+ for (let i = 0; i < data.length; i += stride) out.push(data[i]);
23985
+ const last = data[data.length - 1];
23986
+ if (out[out.length - 1] !== last) out.push(last);
23987
+ return out;
23988
+ }
23978
23989
  function buildAxis(axis, fallbackCategories) {
23979
23990
  const cfg = {};
23980
23991
  if (!axis) {
@@ -24006,7 +24017,7 @@ function buildChartOptions(config, palette) {
24006
24017
  subtitle: { text: config.subtitle ?? void 0 },
24007
24018
  series: safeSeries.map((s, i) => ({
24008
24019
  name: s.name,
24009
- data: s.data,
24020
+ data: downsampleSeriesData(s.data),
24010
24021
  ...s.type && { type: highchartsType(s.type) },
24011
24022
  ...s.stack && { stack: s.stack },
24012
24023
  ...typeof s.yAxis === "number" && { yAxis: s.yAxis },
@@ -24225,6 +24236,14 @@ function loadHighcharts() {
24225
24236
  });
24226
24237
  return hcLoadPromise;
24227
24238
  }
24239
+ function structuralKey(config) {
24240
+ const type = config?.chart?.type;
24241
+ const xAxis = config?.xAxis;
24242
+ const yAxis = config?.yAxis;
24243
+ const xType = Array.isArray(xAxis) ? xAxis.map((a) => a?.type).join(",") : xAxis?.type;
24244
+ const yCount = Array.isArray(yAxis) ? yAxis.length : yAxis ? 1 : 0;
24245
+ return `${type}|${xType}|${yCount}`;
24246
+ }
24228
24247
  function buildTheme(height) {
24229
24248
  const colors = [1, 2, 3, 4, 5, 6, 7, 8].map((i) => getCSSVar(`--chart-${i}`)).filter(Boolean);
24230
24249
  return {
@@ -24293,6 +24312,7 @@ function AnalyticsChart({
24293
24312
  const [fetchError, setFetchError] = useState24(null);
24294
24313
  const containerRef = useRef16(null);
24295
24314
  const chartRef = useRef16(null);
24315
+ const structuralKeyRef = useRef16(null);
24296
24316
  const declarative = useMemo13(
24297
24317
  () => resolveDeclarativeConfig({
24298
24318
  chartConfig,
@@ -24362,8 +24382,17 @@ function AnalyticsChart({
24362
24382
  if (!mounted || !activeConfig || !containerRef.current) return;
24363
24383
  const container = containerRef.current;
24364
24384
  let cancelled = false;
24385
+ const nextConfig = normalizeConfig(stripNulls(activeConfig));
24386
+ const nextKey = structuralKey(nextConfig);
24365
24387
  loadHighcharts().then((HC) => {
24366
24388
  if (cancelled || !container) return;
24389
+ if (chartRef.current && structuralKeyRef.current === nextKey) {
24390
+ try {
24391
+ chartRef.current.update(nextConfig, true, true);
24392
+ return;
24393
+ } catch {
24394
+ }
24395
+ }
24367
24396
  if (chartRef.current) {
24368
24397
  try {
24369
24398
  chartRef.current.destroy();
@@ -24372,7 +24401,8 @@ function AnalyticsChart({
24372
24401
  chartRef.current = null;
24373
24402
  }
24374
24403
  HC.setOptions(buildTheme(height));
24375
- chartRef.current = HC.chart(container, normalizeConfig(stripNulls(activeConfig)));
24404
+ chartRef.current = HC.chart(container, nextConfig);
24405
+ structuralKeyRef.current = nextKey;
24376
24406
  });
24377
24407
  return () => {
24378
24408
  cancelled = true;