@carto/ps-react-ui 4.11.1 → 4.11.2

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.
@@ -209,7 +209,14 @@ export function createHistogramOptionFactory(
209
209
  // pick that up.
210
210
  const liveFormatter = ctx?.formatter
211
211
 
212
- const { niceMinVal, niceMaxVal } = computeHistogramNiceBounds(seriesArr)
212
+ // Closure shared between the yAxis min/max callbacks and the label
213
+ // formatter, so only the rounded extents are labelled (matches v1 +
214
+ // bar). Delegating the extent to ECharts (rather than precomputing
215
+ // scalars from the raw counts) keeps stacked bins inside the plot:
216
+ // when StackToggle marks the series, ECharts feeds the *post-stack*
217
+ // extent to these callbacks, so `niceNum` rounds the stacked total.
218
+ let niceMin = 0
219
+ let niceMax = 1
213
220
 
214
221
  // Zoom slider layout: when ZoomToggle has installed `dataZoom`, push
215
222
  // the slider above the legend (if any) and reserve room in the grid.
@@ -270,12 +277,18 @@ export function createHistogramOptionFactory(
270
277
  ...(dataZoomLayout ? { dataZoom: dataZoomLayout } : {}),
271
278
  yAxis: {
272
279
  ...baseYAxis,
273
- min: niceMinVal,
274
- max: niceMaxVal,
280
+ min: (extent: { min: number }) => {
281
+ niceMin = extent.min < 0 ? niceNum(extent.min) : 0
282
+ return niceMin
283
+ },
284
+ max: (extent: { min: number; max: number }) => {
285
+ niceMax = extent.max <= 0 ? 1 : niceNum(extent.max)
286
+ return niceMax
287
+ },
275
288
  axisLabel: {
276
289
  ...((baseYAxis as { axisLabel?: object }).axisLabel ?? {}),
277
290
  formatter: (value: number) => {
278
- if (value !== niceMaxVal && value !== niceMinVal) return ''
291
+ if (value !== niceMax && value !== niceMin) return ''
279
292
  if (value === 0) return ''
280
293
  return liveFormatter ? liveFormatter(value) : String(value)
281
294
  },
@@ -315,23 +328,6 @@ function buildHistogramTooltipFormatter(
315
328
  })
316
329
  }
317
330
 
318
- function computeHistogramNiceBounds(seriesArr: HistogramWidgetData): {
319
- niceMinVal: number
320
- niceMaxVal: number
321
- } {
322
- let max = -Infinity
323
- for (const counts of seriesArr) {
324
- for (const v of counts) {
325
- if (typeof v !== 'number' || !Number.isFinite(v)) continue
326
- if (v > max) max = v
327
- }
328
- }
329
- return {
330
- niceMinVal: 0,
331
- niceMaxVal: max <= 0 ? 1 : niceNum(max),
332
- }
333
- }
334
-
335
331
  function formatNumber(n: number): string {
336
332
  if (Number.isInteger(n)) return String(n)
337
333
  return Number(n.toFixed(2)).toString()
@@ -260,13 +260,18 @@ describe('createTimeseriesOptionFactory', () => {
260
260
  { formatter: fmt },
261
261
  ) as {
262
262
  yAxis: {
263
- min: number
264
- max: number
263
+ min: (extent: { min: number }) => number
264
+ max: (extent: { min: number; max: number }) => number
265
265
  axisLabel: { formatter: (v: number) => string }
266
266
  }
267
267
  }
268
- expect(out.yAxis.min).toBe(0)
269
- expect(out.yAxis.max).toBe(100)
268
+ // Bounds are callbacks now: ECharts supplies the (post-stack) extent and
269
+ // we round it with niceNum. Invoke them as ECharts would before reading
270
+ // the label formatter (which keys off the closure-cached extents).
271
+ expect(typeof out.yAxis.min).toBe('function')
272
+ expect(typeof out.yAxis.max).toBe('function')
273
+ expect(out.yAxis.min({ min: 0 })).toBe(0)
274
+ expect(out.yAxis.max({ min: 0, max: 100 })).toBe(100)
270
275
  expect(out.yAxis.axisLabel.formatter(100)).toBe('100%')
271
276
  expect(out.yAxis.axisLabel.formatter(50)).toBe('')
272
277
  expect(out.yAxis.axisLabel.formatter(0)).toBe('')
@@ -207,7 +207,14 @@ export function createTimeseriesOptionFactory(
207
207
  // not relativizable — so the merge branch reads the closure-time value.
208
208
  const liveFormatter = ctx?.formatter
209
209
 
210
- const { niceMinVal, niceMaxVal } = computeTimeseriesNiceBounds(seriesArr)
210
+ // Closure shared between the yAxis min/max callbacks and the label
211
+ // formatter, so only the rounded extents are labelled (matches v1 +
212
+ // bar). Delegating the extent to ECharts (rather than precomputing
213
+ // scalars from the raw data) keeps stacked lines inside the plot: when
214
+ // StackToggle marks the series, ECharts feeds the *post-stack* extent
215
+ // to these callbacks, so `niceNum` rounds the stacked total.
216
+ let niceMin = 0
217
+ let niceMax = 1
211
218
 
212
219
  // Zoom slider layout: when ZoomToggle has installed `dataZoom`, push the
213
220
  // slider above the legend (if any) and reserve room in the grid below.
@@ -278,12 +285,18 @@ export function createTimeseriesOptionFactory(
278
285
  ...(dataZoomLayout ? { dataZoom: dataZoomLayout } : {}),
279
286
  yAxis: {
280
287
  ...baseYAxis,
281
- min: niceMinVal,
282
- max: niceMaxVal,
288
+ min: (extent: { min: number }) => {
289
+ niceMin = extent.min < 0 ? niceNum(extent.min) : 0
290
+ return niceMin
291
+ },
292
+ max: (extent: { min: number; max: number }) => {
293
+ niceMax = extent.max <= 0 ? 1 : niceNum(extent.max)
294
+ return niceMax
295
+ },
283
296
  axisLabel: {
284
297
  ...((baseYAxis as { axisLabel?: object }).axisLabel ?? {}),
285
298
  formatter: (value: number) => {
286
- if (value !== niceMaxVal && value !== niceMinVal) return ''
299
+ if (value !== niceMax && value !== niceMin) return ''
287
300
  if (value === 0) return ''
288
301
  return liveFormatter ? liveFormatter(value) : String(value)
289
302
  },
@@ -328,21 +341,3 @@ function buildTimeseriesTooltipFormatter(
328
341
  return { name: String(name), seriesName, marker, value: formattedValue }
329
342
  })
330
343
  }
331
-
332
- function computeTimeseriesNiceBounds(seriesArr: TimeseriesWidgetData): {
333
- niceMinVal: number
334
- niceMaxVal: number
335
- } {
336
- let min = 0
337
- let max = -Infinity
338
- for (const series of seriesArr) {
339
- for (const d of series) {
340
- if (typeof d?.value !== 'number' || !Number.isFinite(d.value)) continue
341
- if (d.value < min) min = d.value
342
- if (d.value > max) max = d.value
343
- }
344
- }
345
- const niceMinVal = min < 0 ? niceNum(min) : 0
346
- const niceMaxVal = max <= 0 ? 1 : niceNum(max)
347
- return { niceMinVal, niceMaxVal }
348
- }
@@ -1,176 +0,0 @@
1
- import { jsx as j } from "react/jsx-runtime";
2
- import { c as k } from "react/compiler-runtime";
3
- import { useRef as M, useEffectEvent as w, useEffect as T } from "react";
4
- import { u as N, a as D, m as L } from "./widget-store-registry-_W4Z4xp-.js";
5
- import { u as U } from "./widget-context-DTGO0Yta.js";
6
- import "zustand";
7
- import { Box as P } from "@mui/material";
8
- import * as C from "echarts";
9
- const z = /* @__PURE__ */ new Map();
10
- let g = null;
11
- function K() {
12
- return typeof ResizeObserver > "u" ? null : (g ??= new ResizeObserver((r) => {
13
- for (const e of r)
14
- z.get(e.target)?.();
15
- }), g);
16
- }
17
- const W = () => {
18
- };
19
- function $(r, e) {
20
- const t = K();
21
- return t ? (z.set(r, e), t.observe(r), () => {
22
- z.delete(r), g && (g.unobserve(r), z.size === 0 && (g.disconnect(), g = null));
23
- }) : W;
24
- }
25
- function se() {
26
- g && g.disconnect(), z.clear(), g = null;
27
- }
28
- const B = {
29
- root: {
30
- width: "100%",
31
- minHeight: 0
32
- }
33
- }, G = {
34
- renderer: "svg",
35
- height: 304
36
- };
37
- function H(r) {
38
- const e = k(21), {
39
- option: t,
40
- replaceMerge: s,
41
- onEvents: c,
42
- init: a,
43
- onInstance: b,
44
- className: x,
45
- sx: y
46
- } = r, h = M(null), i = M(null), l = M(null), A = M(null);
47
- let v;
48
- e[0] !== b ? (v = (n) => {
49
- b?.(n);
50
- }, e[0] = b, e[1] = v) : v = e[1];
51
- const f = w(v);
52
- let E;
53
- e[2] !== a || e[3] !== f ? (E = () => {
54
- if (!h.current)
55
- return;
56
- const n = C.init(h.current, null, {
57
- ...G,
58
- ...a
59
- });
60
- return i.current = n, f(n), () => {
61
- f(null), n.dispose(), i.current = null;
62
- };
63
- }, e[2] = a, e[3] = f, e[4] = E) : E = e[4];
64
- let u;
65
- e[5] !== a ? (u = [a], e[5] = a, e[6] = u) : u = e[6], T(E, u);
66
- let F, d;
67
- e[7] !== t || e[8] !== s ? (F = () => {
68
- const n = J(t), I = q(t), S = new Set(s ?? []);
69
- n !== l.current && S.add("series"), I !== A.current && S.add("dataset"), l.current = n, A.current = I, i.current?.setOption(t, {
70
- notMerge: !1,
71
- lazyUpdate: !0,
72
- replaceMerge: S.size > 0 ? Array.from(S) : void 0
73
- });
74
- }, d = [t, s], e[7] = t, e[8] = s, e[9] = F, e[10] = d) : (F = e[9], d = e[10]), T(F, d);
75
- let _, m;
76
- e[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (_ = () => {
77
- const n = h.current;
78
- if (n)
79
- return $(n, () => {
80
- i.current?.resize();
81
- });
82
- }, m = [], e[11] = _, e[12] = m) : (_ = e[11], m = e[12]), T(_, m);
83
- let O, p;
84
- e[13] !== c ? (O = () => {
85
- const n = i.current;
86
- if (!(!n || !c)) {
87
- for (const [I, S] of Object.entries(c))
88
- n.on(I, S);
89
- return () => {
90
- for (const [I, S] of Object.entries(c))
91
- n.off(I, S);
92
- };
93
- }
94
- }, p = [c], e[13] = c, e[14] = O, e[15] = p) : (O = e[14], p = e[15]), T(O, p);
95
- let o;
96
- e[16] !== y ? (o = {
97
- ...B.root,
98
- ...y
99
- }, e[16] = y, e[17] = o) : o = e[17];
100
- let R;
101
- return e[18] !== x || e[19] !== o ? (R = /* @__PURE__ */ j(P, { ref: h, className: x, sx: o }), e[18] = x, e[19] = o, e[20] = R) : R = e[20], R;
102
- }
103
- function J(r) {
104
- const e = r.series;
105
- return Array.isArray(e) ? e.map((t) => {
106
- if (t == null || typeof t != "object") return String(t);
107
- const s = t;
108
- return [
109
- s.type,
110
- s.datasetIndex,
111
- s.name,
112
- s.stack,
113
- // `encode` is small; stringify is cheap and stable for plain objects.
114
- JSON.stringify(s.encode ?? null)
115
- ].join("|");
116
- }).join("||") : e ? "1" : "";
117
- }
118
- function q(r) {
119
- const e = r.dataset;
120
- return Array.isArray(e) ? String(e.length) : e ? "1" : "";
121
- }
122
- const Q = ["toolbox"], V = (r) => ({
123
- data: r.data,
124
- configTransforms: r.configTransforms,
125
- formatter: r.formatter,
126
- labelFormatter: r.labelFormatter
127
- });
128
- function oe(r) {
129
- const e = k(22), {
130
- optionFactory: t,
131
- onEvents: s,
132
- init: c,
133
- className: a
134
- } = r, b = U(), x = N(b, V);
135
- let y;
136
- e[0] !== b ? (y = (o) => L(b, o), e[0] = b, e[1] = y) : y = e[1];
137
- const h = y, {
138
- data: i,
139
- configTransforms: l,
140
- formatter: A,
141
- labelFormatter: v
142
- } = x;
143
- let f;
144
- e[2] !== t ? (f = t(void 0, void 0), e[2] = t, e[3] = f) : f = e[3];
145
- const E = f;
146
- let u;
147
- e[4] !== l || e[5] !== E ? (u = D(E, l), e[4] = l, e[5] = E, e[6] = u) : u = e[6];
148
- const F = u;
149
- let d;
150
- if (e[7] !== l) {
151
- const o = new Set(Q);
152
- for (const R of l)
153
- if (R.enabled && R.replaceMergeKeys?.length)
154
- for (const n of R.replaceMergeKeys)
155
- o.add(n);
156
- d = Array.from(o).sort(), e[7] = l, e[8] = d;
157
- } else
158
- d = e[8];
159
- const _ = d;
160
- let m;
161
- e[9] !== t || e[10] !== i || e[11] !== A || e[12] !== v || e[13] !== F ? (m = t(F, i, {
162
- formatter: A,
163
- labelFormatter: v
164
- }), e[9] = t, e[10] = i, e[11] = A, e[12] = v, e[13] = F, e[14] = m) : m = e[14];
165
- const O = m;
166
- let p;
167
- return e[15] !== a || e[16] !== c || e[17] !== s || e[18] !== h || e[19] !== O || e[20] !== _ ? (p = /* @__PURE__ */ j(H, { option: O, replaceMerge: _, onEvents: s, init: c, onInstance: h, className: a }), e[15] = a, e[16] = c, e[17] = s, e[18] = h, e[19] = O, e[20] = _, e[21] = p) : p = e[21], p;
168
- }
169
- export {
170
- G as D,
171
- oe as E,
172
- se as _,
173
- H as a,
174
- $ as o
175
- };
176
- //# sourceMappingURL=echart-CU0KmClP.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"echart-CU0KmClP.js","sources":["../src/widgets-v2/echart/shared-resize-observer.ts","../src/widgets-v2/echart/style.ts","../src/widgets-v2/echart/echart-ui.tsx","../src/widgets-v2/echart/echart.tsx"],"sourcesContent":["type ResizeCallback = () => void\n\nconst callbacks = new Map<Element, ResizeCallback>()\nlet observer: ResizeObserver | null = null\n\n/**\n * Returns the singleton ResizeObserver, lazily constructing it on first use.\n * Returns `null` when `ResizeObserver` is not available in the global scope\n * (SSR, very old browsers, or tests that intentionally remove it).\n */\nfunction getObserver(): ResizeObserver | null {\n if (typeof ResizeObserver === 'undefined') return null\n observer ??= new ResizeObserver((entries) => {\n for (const entry of entries) {\n const callback = callbacks.get(entry.target)\n callback?.()\n }\n })\n return observer\n}\n\nconst NOOP_CLEANUP = (): void => undefined\n\nexport function observeResize(\n element: Element,\n callback: ResizeCallback,\n): () => void {\n const ro = getObserver()\n // Gracefully degrade when no ResizeObserver is available — consumers\n // still see one initial measure() pass via their own effect; we just\n // skip the subsequent resize-driven re-measures.\n if (!ro) return NOOP_CLEANUP\n callbacks.set(element, callback)\n ro.observe(element)\n return () => {\n callbacks.delete(element)\n if (observer) {\n observer.unobserve(element)\n // Disconnect the singleton once the last subscriber leaves so the\n // observer doesn't outlive its consumers in SSR teardown / micro-\n // frontend unmount scenarios. A subsequent observeResize() will\n // lazily re-create it via getObserver().\n if (callbacks.size === 0) {\n observer.disconnect()\n observer = null\n }\n }\n }\n}\n\n/** @internal — for tests only. */\nexport function __resetSharedResizeObserver(): void {\n if (observer) observer.disconnect()\n callbacks.clear()\n observer = null\n}\n","import type { SxProps, Theme } from '@mui/material'\n\nexport const styles = {\n root: {\n width: '100%',\n minHeight: 0,\n },\n} satisfies Record<string, SxProps<Theme>>\n","import { useEffect, useEffectEvent, useRef } from 'react'\nimport { Box, type SxProps, type Theme } from '@mui/material'\nimport * as echarts from 'echarts'\nimport { observeResize } from './shared-resize-observer'\nimport { styles } from './style'\n\nexport const DEFAULT_INIT_OPTS = {\n renderer: 'svg',\n height: 304,\n} satisfies echarts.EChartsInitOpts\n\nexport type EchartsEventHandler = (event: unknown) => void\n\nexport interface EchartUIProps {\n option: echarts.EChartsOption\n /**\n * Keys to merge as arrays (replace by index) instead of by id. The middleware\n * memoizes this content-stably, so identical sets don't re-trigger setOption.\n */\n replaceMerge?: readonly string[]\n /**\n * Opaque ECharts event passthrough — handlers fire untransformed.\n *\n * **Must be referentially stable** (memoize it with `useMemo` /\n * `useCallback`, or hoist to module scope). The binding effect depends on\n * the `onEvents` object identity; an inline `{ click: handler }` literal\n * recreates the object on every render and causes every listener to be\n * detached and re-attached each commit.\n */\n onEvents?: Record<string, EchartsEventHandler>\n /**\n * Init options forwarded to echarts.init. Captured at mount only — to change\n * `renderer` or `height` after mount, unmount and remount the chart.\n * Defaults: `{ renderer: 'svg', height: 304 }`.\n */\n init?: echarts.EChartsInitOpts\n /**\n * Optional callback fired once after the ECharts instance is created\n * (`onInstance(chart)`) and once when it's about to be disposed\n * (`onInstance(null)`). Used by `Widget.Echart` to publish the live\n * instance to the per-widget registry so other actions (e.g.\n * `ZoomToggle`'s disable handler) can reach it without DOM lookups.\n * No need to memoize — the bridge wraps it in `useEffectEvent` so an\n * unstable reference does not re-init the chart.\n */\n onInstance?: (chart: echarts.ECharts | null) => void\n className?: string\n sx?: SxProps<Theme>\n}\n\nexport function EchartUI({\n option,\n replaceMerge,\n onEvents,\n init,\n onInstance,\n className,\n sx,\n}: EchartUIProps) {\n const containerRef = useRef<HTMLDivElement>(null)\n const chartRef = useRef<echarts.ECharts | null>(null)\n\n // Structural fingerprint of the last applied series / dataset arrays.\n // Used to decide whether the next `setOption` should *replace* those\n // components (when their shape changed) or *merge* them (when only\n // styling-level fields differ — e.g. a new `itemStyle.color` callback\n // from a selection update). Replacing wipes ECharts' per-series runtime\n // state (hover, animation cache, brush areas), so we want to do it only\n // when the structure actually moved.\n const seriesFingerprintRef = useRef<string | null>(null)\n const datasetFingerprintRef = useRef<string | null>(null)\n\n // Stable notify wrapper — always reads the latest `onInstance` prop\n // without forcing the init effect below to re-run when the parent\n // passes a fresh function reference. The init effect now only fires\n // when `init` actually changes (documented as mount-only anyway).\n const notifyInstance = useEffectEvent(\n (chart: echarts.ECharts | null): void => {\n onInstance?.(chart)\n },\n )\n\n // Init / dispose. `init` is captured once at mount.\n useEffect(() => {\n if (!containerRef.current) return undefined\n const chart = echarts.init(containerRef.current, null, {\n ...DEFAULT_INIT_OPTS,\n ...init,\n })\n chartRef.current = chart\n notifyInstance(chart)\n return () => {\n // Notify observers *before* disposal so any queued imperative\n // dispatches (e.g. ZoomToggle's `setOption` cleanup) see the\n // instance disappear before its DOM is torn down.\n notifyInstance(null)\n chart.dispose()\n chartRef.current = null\n }\n }, [init])\n\n // Apply option / replaceMerge changes via merge mode (no remount required).\n useEffect(() => {\n const seriesFp = computeSeriesFingerprint(option)\n const datasetFp = computeDatasetFingerprint(option)\n const augmented = new Set<string>(replaceMerge ?? [])\n if (seriesFp !== seriesFingerprintRef.current) augmented.add('series')\n if (datasetFp !== datasetFingerprintRef.current) augmented.add('dataset')\n seriesFingerprintRef.current = seriesFp\n datasetFingerprintRef.current = datasetFp\n chartRef.current?.setOption(option, {\n notMerge: false,\n lazyUpdate: true,\n replaceMerge: augmented.size > 0 ? Array.from(augmented) : undefined,\n })\n }, [option, replaceMerge])\n\n // Resize via shared singleton observer.\n useEffect(() => {\n const node = containerRef.current\n if (!node) return undefined\n return observeResize(node, () => {\n chartRef.current?.resize()\n })\n }, [])\n\n // Bind / unbind opaque event handlers.\n useEffect(() => {\n const chart = chartRef.current\n if (!chart || !onEvents) return undefined\n for (const [event, handler] of Object.entries(onEvents)) {\n chart.on(event, handler)\n }\n return () => {\n for (const [event, handler] of Object.entries(onEvents)) {\n chart.off(event, handler)\n }\n }\n }, [onEvents])\n\n return (\n <Box\n ref={containerRef}\n className={className}\n sx={{ ...styles.root, ...sx }}\n />\n )\n}\n\n/**\n * Cheap structural digest of the option's `series` array — covers the fields\n * that actually demand a `replaceMerge` (length, type, datasetIndex, name,\n * stack, encode). Excludes runtime-style fields like `itemStyle` (callbacks\n * have unstable identity but don't change structure).\n */\nfunction computeSeriesFingerprint(option: echarts.EChartsOption): string {\n const series = option.series\n if (!Array.isArray(series)) return series ? '1' : ''\n return series\n .map((s) => {\n if (s == null || typeof s !== 'object') return String(s)\n const o = s as Record<string, unknown>\n return [\n o.type,\n o.datasetIndex,\n o.name,\n o.stack,\n // `encode` is small; stringify is cheap and stable for plain objects.\n JSON.stringify(o.encode ?? null),\n ].join('|')\n })\n .join('||')\n}\n\n/**\n * Structural digest of the option's `dataset` array — count is the only\n * thing that needs `replaceMerge` here. Row-level changes are picked up by\n * ECharts' default merge.\n */\nfunction computeDatasetFingerprint(option: echarts.EChartsOption): string {\n const dataset = option.dataset\n if (!Array.isArray(dataset)) return dataset ? '1' : ''\n return String(dataset.length)\n}\n","import { useCallback, useMemo } from 'react'\nimport type * as echarts from 'echarts'\nimport {\n applyTransforms,\n setEchartInstance,\n useWidgetId,\n useWidgetShallow,\n type Transform,\n} from '../stores'\nimport { EchartUI, type EchartsEventHandler } from './echart-ui'\n\n/**\n * Default ECharts `replaceMerge` keys for every widget. `dataZoom` and\n * `brush` are omitted so ZoomToggle / BrushToggle's user-driven runtime\n * state (slider range, brushed areas in `multiple` mode) survives unrelated\n * re-renders. `series` and `dataset` are also omitted: EchartUI fingerprints\n * them per-render and adds them to `replaceMerge` only when their shape\n * actually changes, keeping ECharts' per-series runtime state alive when\n * only callback-style fields differ.\n *\n * Lives in this module (not the generic store) because it's an ECharts\n * concept. Module-private — callers should not need it.\n */\nconst DEFAULT_REPLACE_MERGE: readonly string[] = ['toolbox']\n\n/**\n * Reactive context passed to every {@link OptionFactory} call so the\n * factory can rebuild render-time pieces (axis label / tooltip formatters)\n * from the live store. Drives RelativeData / consumer-formatter changes\n * through to the chart without rebuilding the structural option.\n */\nexport interface OptionFactoryContext {\n formatter?: (value: number) => string\n labelFormatter?: (value: string | number) => string | number\n}\n\n/**\n * The per-widget option factory — a single callable that owns BOTH phases\n * of option construction:\n *\n * - **Structural phase** — when `option == null`, return the theme-aware\n * structural option (tooltip / legend / color palette / series\n * template, optionally merged with a consumer-supplied `optionsOverride`).\n * No data is read. `<Widget.Echart>` calls the factory with\n * `(undefined, undefined)` synchronously during render to derive the\n * structural base; `configTransforms` (Stack/Zoom/Brush) then mutate it\n * in the same render pass.\n * - **Merge phase** — when `option` is defined, fuse `data` into the\n * post-configTransforms option at fusion time. `<Widget.Echart>` calls\n * the factory with `(transformed, data, ctx)` on every render.\n *\n * The two phases share a closure (the factory creator captures `theme`,\n * `formatter`, `labelFormatter`, `seriesNames`, `selection`, `optionsOverride`,\n * …), so structural and merge agree on the same widget configuration.\n *\n * The third arg `ctx` carries the **live** store-side formatters at the\n * call site — distinct from the closure-time formatters because actions\n * like RelativeData can install a percent formatter on the store after\n * the factory was constructed. The merge phase reads from `ctx`; the\n * structural phase typically uses the closure-time values.\n */\nexport type OptionFactory = (\n option: echarts.EChartsOption | undefined,\n data: unknown,\n ctx?: OptionFactoryContext,\n) => echarts.EChartsOption\n\nexport interface EchartProps {\n /**\n * The per-widget {@link OptionFactory}. Required — `<Widget.Echart>`\n * derives the structural option from it (so configTransforms have a base\n * to mutate) and fuses `state.data` into the post-pipeline option at\n * render time. Wrap the factory creator in `useMemo` so its identity is\n * stable across renders.\n */\n optionFactory: OptionFactory\n onEvents?: Record<string, EchartsEventHandler>\n init?: echarts.EChartsInitOpts\n className?: string\n}\n\ninterface EchartSlice {\n data: unknown\n configTransforms: readonly Transform[]\n formatter?: (value: number) => string\n labelFormatter?: (value: string | number) => string | number\n}\n\nconst echartSelector = (s: {\n data: unknown\n configTransforms: readonly Transform[]\n formatter?: (value: number) => string\n labelFormatter?: (value: string | number) => string | number\n}): EchartSlice => ({\n data: s.data,\n configTransforms: s.configTransforms,\n formatter: s.formatter,\n labelFormatter: s.labelFormatter,\n})\n\n/**\n * Stateful Echart bridge — owns the entire ECharts coupling. The whole\n * option pipeline lives here, not in the store:\n *\n * 1. **Structural** — `optionFactory(undefined, undefined)` produces the\n * theme-aware base. Memoized on the factory identity, so the consumer's\n * `useMemo` ID gates the rebuild.\n * 2. **Transformed** — `applyTransforms(structural, configTransforms)`\n * applies any registered configTransforms (Stack/Zoom/Brush) over the\n * structural base. Memoized on `[structural, configTransforms]`.\n * 3. **`replaceMerge`** — derived from the enabled configTransforms'\n * `replaceMergeKeys`, deduped and sorted, seeded with\n * {@link DEFAULT_REPLACE_MERGE}. Memoized on `[configTransforms]` so\n * ECharts sees a stable array reference across non-transform changes.\n * 4. **Merge** — `optionFactory(transformed, data, ctx)` fuses post-\n * pipeline data into the option. Reactive `ctx` carries the live store\n * formatters so RelativeData's percent formatter flows through without\n * a structural rebuild.\n *\n * The `<Widget.Provider>` doesn't know about the factory at all: it stays\n * a renderer-agnostic shell. The `ProviderProps` surface has no ECharts\n * coupling, so non-Echart widgets don't transitively import the type.\n */\nexport function Echart({\n optionFactory,\n onEvents,\n init,\n className,\n}: EchartProps) {\n const id = useWidgetId()\n const slice = useWidgetShallow(id, echartSelector)\n\n // Publish the live ECharts instance to the per-id registry so actions\n // (e.g. `ZoomToggle`'s disable handler) can reach it imperatively. The\n // callback identity is stable across renders (only `id` is in deps), so\n // EchartUI's init effect doesn't see a fresh `onInstance` and re-init.\n const onInstance = useCallback(\n (chart: echarts.ECharts | null) => setEchartInstance(id, chart),\n [id],\n )\n\n // Destructure so React Compiler sees specific deps instead of inferring\n // the whole `slice` object. `useWidgetShallow` already shallow-compares\n // the slice, so per-field deps drive each memo exactly when its inputs\n // change.\n const {\n data: sliceData,\n configTransforms,\n formatter: sliceFormatter,\n labelFormatter: sliceLabelFormatter,\n } = slice\n\n const structural = useMemo(\n () => optionFactory(undefined, undefined),\n [optionFactory],\n )\n\n const transformed = useMemo(\n () =>\n applyTransforms(structural, configTransforms) as echarts.EChartsOption,\n [structural, configTransforms],\n )\n\n const replaceMerge = useMemo(() => {\n const keys = new Set<string>(DEFAULT_REPLACE_MERGE)\n for (const xf of configTransforms) {\n if (xf.enabled && xf.replaceMergeKeys?.length) {\n for (const k of xf.replaceMergeKeys) keys.add(k)\n }\n }\n return Array.from(keys).sort()\n }, [configTransforms])\n\n const option = useMemo(\n () =>\n optionFactory(transformed, sliceData, {\n formatter: sliceFormatter,\n labelFormatter: sliceLabelFormatter,\n }),\n [\n optionFactory,\n transformed,\n sliceData,\n sliceFormatter,\n sliceLabelFormatter,\n ],\n )\n\n return (\n <EchartUI\n option={option}\n replaceMerge={replaceMerge}\n onEvents={onEvents}\n init={init}\n onInstance={onInstance}\n className={className}\n />\n )\n}\n"],"names":["callbacks","Map","observer","getObserver","ResizeObserver","entries","entry","callback","get","target","NOOP_CLEANUP","observeResize","element","ro","set","observe","delete","unobserve","size","disconnect","__resetSharedResizeObserver","clear","styles","root","width","minHeight","DEFAULT_INIT_OPTS","renderer","height","EchartUI","t0","$","_c","option","replaceMerge","onEvents","init","onInstance","className","sx","containerRef","useRef","chartRef","seriesFingerprintRef","datasetFingerprintRef","t1","chart","notifyInstance","useEffectEvent","t2","current","chart_0","echarts","dispose","t3","useEffect","t4","t5","seriesFp","computeSeriesFingerprint","datasetFp","computeDatasetFingerprint","augmented","Set","add","setOption","notMerge","lazyUpdate","Array","from","undefined","t6","t7","Symbol","for","node","resize","t8","t9","chart_1","event","handler","Object","on","event_0","handler_0","off","t10","t11","Box","series","isArray","map","s","String","o","type","datasetIndex","name","stack","JSON","stringify","encode","join","dataset","length","DEFAULT_REPLACE_MERGE","echartSelector","data","configTransforms","formatter","labelFormatter","Echart","optionFactory","id","useWidgetId","slice","useWidgetShallow","setEchartInstance","sliceData","sliceFormatter","sliceLabelFormatter","structural","applyTransforms","transformed","keys","xf","enabled","replaceMergeKeys","k","sort"],"mappings":";;;;;;;;AAEA,MAAMA,wBAAgBC,IAAAA;AACtB,IAAIC,IAAkC;AAOtC,SAASC,IAAqC;AAC5C,SAAI,OAAOC,iBAAmB,MAAoB,QAClDF,MAAa,IAAIE,eAAgBC,CAAAA,MAAY;AAC3C,eAAWC,KAASD;AAElBE,MADiBP,EAAUQ,IAAIF,EAAMG,MAAM,IAC3CF;AAAAA,EAEJ,CAAC,GACML;AACT;AAEA,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