@carto/ps-react-ui 4.17.3 → 4.18.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.
Files changed (74) hide show
  1. package/dist/category-Ct2BzADB.js +753 -0
  2. package/dist/category-Ct2BzADB.js.map +1 -0
  3. package/dist/change-column-Bhcxmp-r.js +1148 -0
  4. package/dist/change-column-Bhcxmp-r.js.map +1 -0
  5. package/dist/echart-B10dhEaM.js +262 -0
  6. package/dist/echart-B10dhEaM.js.map +1 -0
  7. package/dist/types/widgets-v2/actions/lock-selection/lock-selection.d.ts +15 -5
  8. package/dist/types/widgets-v2/category/components/category-legend.d.ts +18 -2
  9. package/dist/types/widgets-v2/category/components/category-row-stacked.d.ts +6 -1
  10. package/dist/types/widgets-v2/category/style.d.ts +8 -0
  11. package/dist/types/widgets-v2/echart/use-chart-selection.d.ts +10 -4
  12. package/dist/types/widgets-v2/histogram/index.d.ts +1 -1
  13. package/dist/types/widgets-v2/histogram/transforms.d.ts +11 -0
  14. package/dist/types/widgets-v2/histogram/types.d.ts +9 -0
  15. package/dist/types/widgets-v2/scatterplot/index.d.ts +1 -1
  16. package/dist/types/widgets-v2/scatterplot/transforms.d.ts +9 -0
  17. package/dist/types/widgets-v2/table/index.d.ts +1 -0
  18. package/dist/types/widgets-v2/table/transforms.d.ts +13 -0
  19. package/dist/types/widgets-v2/table/transforms.test.d.ts +1 -0
  20. package/dist/types/widgets-v2/timeseries/index.d.ts +1 -0
  21. package/dist/types/widgets-v2/timeseries/transforms.d.ts +10 -0
  22. package/dist/types/widgets-v2/timeseries/transforms.test.d.ts +1 -0
  23. package/dist/widgets-v2/actions.js +1 -1
  24. package/dist/widgets-v2/category.js +1 -1
  25. package/dist/widgets-v2/echart.js +1 -1
  26. package/dist/widgets-v2/echart.js.map +1 -1
  27. package/dist/widgets-v2/histogram.js +181 -158
  28. package/dist/widgets-v2/histogram.js.map +1 -1
  29. package/dist/widgets-v2/pie.js +155 -116
  30. package/dist/widgets-v2/pie.js.map +1 -1
  31. package/dist/widgets-v2/scatterplot.js +91 -85
  32. package/dist/widgets-v2/scatterplot.js.map +1 -1
  33. package/dist/widgets-v2/table.js +55 -45
  34. package/dist/widgets-v2/table.js.map +1 -1
  35. package/dist/widgets-v2/timeseries.js +96 -85
  36. package/dist/widgets-v2/timeseries.js.map +1 -1
  37. package/dist/widgets-v2.js +4 -4
  38. package/package.json +1 -1
  39. package/src/widgets-v2/actions/lock-selection/lock-selection.test.tsx +62 -0
  40. package/src/widgets-v2/actions/lock-selection/lock-selection.tsx +45 -13
  41. package/src/widgets-v2/category/category-ui.test.tsx +55 -0
  42. package/src/widgets-v2/category/category-ui.tsx +65 -6
  43. package/src/widgets-v2/category/components/category-legend.test.tsx +53 -2
  44. package/src/widgets-v2/category/components/category-legend.tsx +55 -12
  45. package/src/widgets-v2/category/components/category-row-stacked.test.tsx +7 -3
  46. package/src/widgets-v2/category/components/category-row-stacked.tsx +8 -3
  47. package/src/widgets-v2/category/style.ts +10 -2
  48. package/src/widgets-v2/echart/echart-ui.test.tsx +25 -0
  49. package/src/widgets-v2/echart/echart-ui.tsx +20 -0
  50. package/src/widgets-v2/echart/use-chart-selection.test.tsx +3 -1
  51. package/src/widgets-v2/echart/use-chart-selection.ts +10 -4
  52. package/src/widgets-v2/histogram/index.ts +4 -1
  53. package/src/widgets-v2/histogram/options.test.ts +86 -0
  54. package/src/widgets-v2/histogram/options.ts +50 -0
  55. package/src/widgets-v2/histogram/transforms.test.ts +36 -1
  56. package/src/widgets-v2/histogram/transforms.ts +23 -0
  57. package/src/widgets-v2/histogram/types.ts +9 -0
  58. package/src/widgets-v2/pie/options.test.ts +262 -0
  59. package/src/widgets-v2/pie/options.ts +80 -5
  60. package/src/widgets-v2/scatterplot/index.ts +4 -1
  61. package/src/widgets-v2/scatterplot/transforms.test.ts +38 -1
  62. package/src/widgets-v2/scatterplot/transforms.ts +23 -0
  63. package/src/widgets-v2/table/index.ts +1 -0
  64. package/src/widgets-v2/table/transforms.test.ts +40 -0
  65. package/src/widgets-v2/table/transforms.ts +26 -0
  66. package/src/widgets-v2/timeseries/index.ts +1 -0
  67. package/src/widgets-v2/timeseries/transforms.test.ts +49 -0
  68. package/src/widgets-v2/timeseries/transforms.ts +31 -0
  69. package/dist/category-CGS_eHr4.js +0 -719
  70. package/dist/category-CGS_eHr4.js.map +0 -1
  71. package/dist/change-column-CiVAjOUB.js +0 -1143
  72. package/dist/change-column-CiVAjOUB.js.map +0 -1
  73. package/dist/echart-Bdvbfx9s.js +0 -250
  74. package/dist/echart-Bdvbfx9s.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"echart-B10dhEaM.js","sources":["../src/widgets-v2/echart/edge-label-clamp.ts","../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":["import * as echarts from 'echarts'\nimport type { ECharts, EChartsOption } from 'echarts'\n\n/**\n * Render-time clamp that stops the first/last **category x-axis** labels from\n * clipping at the chart edges — *only when they actually overflow*.\n *\n * ECharts centers each category label on its tick; the first/last ticks sit at\n * the plot boundary, so a wide edge label spills past the chart and is cut off.\n * `grid.containLabel` does not contain this horizontal overflow and the v6\n * `outerBounds` shrink is unreliable, so we measure at render time and anchor\n * the overflowing edge label inward (`alignMinLabel: 'left'` /\n * `alignMaxLabel: 'right'`). Labels that fit stay centered.\n *\n * Lives in the generic bridge because the verdict needs the laid-out chart\n * (`convertToPixel`, `getWidth`); everything else is read from the `option`.\n * Auto-targets bar + histogram (category x-axis); pie's horizontal-bar fallback\n * (category *y*-axis), scatterplot (value) and timeseries (time) are skipped.\n */\n\nexport interface EdgeAlignment {\n alignMinLabel: 'left' | null\n alignMaxLabel: 'right' | null\n}\n\nexport const CENTERED: EdgeAlignment = {\n alignMinLabel: null,\n alignMaxLabel: null,\n}\n\n// Small cushion biasing toward anchoring when borderline: clipping is worse\n// than a hair of off-centering, and the measured width can differ slightly\n// from the final render (mainly when the web font isn't loaded yet at measure\n// time). Kept to 1px — a wider margin anchored labels that only just clear the\n// edge, and an anchored edge label can then be dropped by the axis\n// `hideOverlap`, leaving a gap. 1px guards measurement error without that.\nconst SAFETY_MARGIN_PX = 1\n\n/**\n * Pure overflow decision. Inputs are anchor-independent (tick centers and text\n * width don't depend on the label's current `text-anchor`), so feeding the\n * result back via `setOption` doesn't change them — the next pass yields the\n * same verdict, keeping the clamp loop-stable.\n */\nexport function decideEdgeAlignment(args: {\n firstLabel: string\n lastLabel: string\n font: string\n firstTickX: number\n lastTickX: number\n width: number\n}): EdgeAlignment {\n const halfFirst =\n echarts.format.getTextRect(args.firstLabel, args.font).width / 2\n const halfLast =\n echarts.format.getTextRect(args.lastLabel, args.font).width / 2\n return {\n alignMinLabel:\n halfFirst + SAFETY_MARGIN_PX > args.firstTickX ? 'left' : null,\n alignMaxLabel:\n halfLast + SAFETY_MARGIN_PX > args.width - args.lastTickX\n ? 'right'\n : null,\n }\n}\n\ninterface AxisLabel {\n formatter?: (value: string | number) => string | number\n fontSize?: number | string\n fontFamily?: string\n fontWeight?: number | string\n}\n\ninterface CategoryXAxis {\n type?: string\n axisLabel?: AxisLabel\n}\n\ninterface SeriesLike {\n encode?: { x?: string | number }\n datasetIndex?: number\n}\n\ntype Cell = string | number | null | undefined\n\nfunction firstOf<T>(value: T | T[] | undefined): T | undefined {\n if (Array.isArray(value)) return value[0]\n return value\n}\n\nfunction firstXAxis(option: EChartsOption): CategoryXAxis | undefined {\n const axis = firstOf(\n option.xAxis as CategoryXAxis | CategoryXAxis[] | undefined,\n )\n return axis && typeof axis === 'object' ? axis : undefined\n}\n\nfunction hasDataZoom(option: EChartsOption): boolean {\n const dz = option.dataZoom\n return Array.isArray(dz) ? dz.length > 0 : dz != null\n}\n\nfunction cellToText(value: Cell, fmt: AxisLabel['formatter']): string {\n if (typeof fmt === 'function') return String(fmt(value ?? ''))\n return value == null ? '' : String(value)\n}\n\n/**\n * Extracts the displayed first/last category strings and the label font from\n * the option, reading categories generically via `series[0].encode.x` into the\n * referenced dataset (`'name'` for bar, `0` for histogram). Returns `null` when\n * the option isn't a measurable category x-axis (fewer than 2 categories, no\n * dataset, etc.).\n */\nexport function resolveEdgeLabels(option: EChartsOption): {\n firstLabel: string\n lastLabel: string\n font: string\n count: number\n} | null {\n const xAxis = firstXAxis(option)\n if (!xAxis) return null\n if (xAxis.type !== 'category') return null\n\n const series0 = firstOf(\n option.series as SeriesLike | SeriesLike[] | undefined,\n )\n const encodeX = series0?.encode?.x\n if (encodeX == null) return null\n\n const datasetIndex = series0?.datasetIndex ?? 0\n const allDatasets = option.dataset as\n | { source?: unknown }\n | { source?: unknown }[]\n | undefined\n const dataset = Array.isArray(allDatasets)\n ? allDatasets[datasetIndex]\n : allDatasets\n const source = dataset?.source\n if (!Array.isArray(source) || source.length < 2) return null\n\n const rows = source as Record<string | number, Cell>[]\n const fmt = xAxis.axisLabel?.formatter\n const axisLabel = xAxis.axisLabel ?? {}\n const size =\n typeof axisLabel.fontSize === 'number'\n ? `${axisLabel.fontSize}px`\n : (axisLabel.fontSize ?? '12px')\n const family = axisLabel.fontFamily ?? 'sans-serif'\n const weight = axisLabel.fontWeight != null ? `${axisLabel.fontWeight} ` : ''\n\n return {\n firstLabel: cellToText(rows[0]?.[encodeX], fmt),\n lastLabel: cellToText(rows[rows.length - 1]?.[encodeX], fmt),\n font: `${weight}${size} ${family}`,\n count: source.length,\n }\n}\n\n/**\n * Measures the rendered chart and, when the edge labels would clip, applies\n * `alignMinLabel`/`alignMaxLabel` (or clears them) via an imperative merge\n * `setOption`. Returns the alignment now in effect so the caller can keep a\n * `prev` ref and skip redundant `setOption`s. Should be invoked from the\n * chart's `finished` event (layout is settled, so `convertToPixel` is valid).\n */\nexport function clampEdgeLabels(\n chart: ECharts,\n option: EChartsOption,\n prev: EdgeAlignment,\n): EdgeAlignment {\n const next = computeAlignment(chart, option)\n if (\n next.alignMinLabel === prev.alignMinLabel &&\n next.alignMaxLabel === prev.alignMaxLabel\n ) {\n return prev\n }\n chart.setOption({ xAxis: { axisLabel: { ...next } } } as EChartsOption, {\n lazyUpdate: true,\n })\n return next\n}\n\nfunction computeAlignment(\n chart: ECharts,\n option: EChartsOption,\n): EdgeAlignment {\n // Under dataZoom, convertToPixel on the absolute first/last index returns\n // off-plot pixels, so the overflow math is invalid — reset to centered.\n if (hasDataZoom(option)) return CENTERED\n\n const labels = resolveEdgeLabels(option)\n if (!labels) return CENTERED\n\n const firstTickX = chart.convertToPixel({ xAxisIndex: 0 }, 0)\n const lastTickX = chart.convertToPixel({ xAxisIndex: 0 }, labels.count - 1)\n const width = chart.getWidth()\n // Layout not measurable yet (defensive — `finished` normally fires after\n // layout). Fall back to centered; a later `finished` re-measures.\n if (\n typeof firstTickX !== 'number' ||\n typeof lastTickX !== 'number' ||\n !Number.isFinite(firstTickX) ||\n !Number.isFinite(lastTickX) ||\n !width\n ) {\n return CENTERED\n }\n\n return decideEdgeAlignment({\n firstLabel: labels.firstLabel,\n lastLabel: labels.lastLabel,\n font: labels.font,\n firstTickX,\n lastTickX,\n width,\n })\n}\n","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 {\n clampEdgeLabels,\n CENTERED,\n type EdgeAlignment,\n} from './edge-label-clamp'\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 // Latest applied option (read by the `finished` clamp listener, which is\n // bound once and must see the current option) + the edge-label alignment\n // currently applied to the chart (so the clamp skips redundant setOptions).\n const optionRef = useRef<echarts.EChartsOption>(option)\n const edgeAlignRef = useRef<EdgeAlignment>(CENTERED)\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 // Edge-label clamp: after each layout settles (option change OR resize both\n // end in a render → `finished`), measure the category x-axis edge labels\n // and anchor them inward only if they'd clip. `finished` (not rAF) so\n // `convertToPixel` sees the flushed `lazyUpdate` layout. Loop-safe: the\n // verdict is anchor-independent, so our own clamp setOption recomputes the\n // same result and the ref guard short-circuits.\n const onFinished = (): void => {\n edgeAlignRef.current = clampEdgeLabels(\n chart,\n optionRef.current,\n edgeAlignRef.current,\n )\n }\n chart.on('finished', onFinished)\n // Never let the legend end up with every item hidden — a user can click\n // series off one by one until the chart goes blank. `selected` on this\n // event is always the FULL name→boolean map (not just the clicked item),\n // so \"every value false\" reliably means \"nothing left visible\". Restore\n // all of them instead. `legendAllSelect` fires its own `legendselectall`\n // event, not `legendselectchanged`, so this can't re-trigger itself.\n // Always-on and independent of the consumer's `onEvents` — applies to\n // every ECharts widget in the library for free. A widget that disables\n // legend clicks entirely (e.g. Pie's `selectedMode: false`) never fires\n // `legendselectchanged`, so this is a no-op there.\n const onLegendSelectChanged = (params: unknown): void => {\n const { selected } = params as { selected?: Record<string, boolean> }\n if (!selected) return\n const names = Object.keys(selected)\n if (names.length > 0 && names.every((name) => !selected[name])) {\n chart.dispatchAction({ type: 'legendAllSelect' })\n }\n }\n chart.on('legendselectchanged', onLegendSelectChanged)\n return () => {\n chart.off('finished', onFinished)\n chart.off('legendselectchanged', onLegendSelectChanged)\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 // Expose the latest option to the `finished` clamp listener (bound once).\n optionRef.current = option\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":["CENTERED","alignMinLabel","alignMaxLabel","SAFETY_MARGIN_PX","decideEdgeAlignment","args","halfFirst","echarts","format","getTextRect","firstLabel","font","width","halfLast","lastLabel","firstTickX","lastTickX","firstOf","value","Array","isArray","firstXAxis","option","axis","xAxis","undefined","hasDataZoom","dz","dataZoom","length","cellToText","fmt","String","resolveEdgeLabels","type","series0","series","encodeX","encode","x","datasetIndex","allDatasets","dataset","source","rows","axisLabel","formatter","size","fontSize","family","fontFamily","weight","fontWeight","count","clampEdgeLabels","chart","prev","next","computeAlignment","setOption","lazyUpdate","labels","convertToPixel","xAxisIndex","getWidth","Number","isFinite","callbacks","Map","observer","getObserver","ResizeObserver","entries","entry","callback","get","target","NOOP_CLEANUP","observeResize","element","ro","set","observe","delete","unobserve","disconnect","__resetSharedResizeObserver","clear","styles","root","minHeight","DEFAULT_INIT_OPTS","renderer","height","EchartUI","t0","$","_c","replaceMerge","onEvents","init","onInstance","className","sx","containerRef","useRef","chartRef","seriesFingerprintRef","datasetFingerprintRef","optionRef","edgeAlignRef","t1","notifyInstance","useEffectEvent","t2","current","chart_0","onFinished","on","onLegendSelectChanged","params","selected","names","Object","keys","every","name","dispatchAction","off","dispose","t3","useEffect","t4","t5","seriesFp","computeSeriesFingerprint","datasetFp","computeDatasetFingerprint","augmented","Set","add","notMerge","from","t6","t7","Symbol","for","node","resize","t8","t9","chart_1","event","handler","event_0","handler_0","t10","t11","Box","map","s","o","stack","JSON","stringify","join","DEFAULT_REPLACE_MERGE","echartSelector","data","configTransforms","labelFormatter","Echart","optionFactory","id","useWidgetId","slice","useWidgetShallow","setEchartInstance","sliceData","sliceFormatter","sliceLabelFormatter","structural","applyTransforms","transformed","xf","enabled","replaceMergeKeys","k","sort"],"mappings":";;;;;;;;AAyBO,MAAMA,IAA0B;AAAA,EACrCC,eAAe;AAAA,EACfC,eAAe;AACjB,GAQMC,IAAmB;AAQlB,SAASC,EAAoBC,GAOlB;AAChB,QAAMC,IACJC,EAAQC,OAAOC,YAAYJ,EAAKK,YAAYL,EAAKM,IAAI,EAAEC,QAAQ,GAC3DC,IACJN,EAAQC,OAAOC,YAAYJ,EAAKS,WAAWT,EAAKM,IAAI,EAAEC,QAAQ;AAChE,SAAO;AAAA,IACLX,eACEK,IAAYH,IAAmBE,EAAKU,aAAa,SAAS;AAAA,IAC5Db,eACEW,IAAWV,IAAmBE,EAAKO,QAAQP,EAAKW,YAC5C,UACA;AAAA,EAAA;AAEV;AAqBA,SAASC,EAAWC,GAA2C;AAC7D,SAAIC,MAAMC,QAAQF,CAAK,IAAUA,EAAM,CAAC,IACjCA;AACT;AAEA,SAAS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,UAAAA,GACJC,MAAAA,GACMC,YAAAA,GACDC,WAAAA,GAAS,GACpBN,QAAAM,GAAAN,QAAAI,GAAAJ,QAAAG,GAAAH,QAAAK,GAAAL,QAAA1E,GAAA0E,QAAAE,GAAAF,QAAA+C,KAAAA,IAAA/C,EAAA,EAAA,GAPF+C;AAOE;"}
@@ -2,28 +2,38 @@ import { ComponentType } from 'react';
2
2
  import { SvgIconProps } from '@mui/material';
3
3
  import { LockSelectionLabels } from './labels';
4
4
  export type LockSelectionKey = string | number;
5
- export interface LockSelectionProps {
5
+ export interface LockSelectionProps<K extends LockSelectionKey = LockSelectionKey> {
6
6
  /**
7
7
  * Currently-selected items (destination-owned). On lock, this set is
8
8
  * snapshotted into `lockedItems` via `onLockChange`.
9
9
  */
10
- selection: readonly LockSelectionKey[];
10
+ selection: readonly K[];
11
11
  /**
12
12
  * Currently-locked items (destination-owned). When non-empty, the widget's
13
13
  * data is filtered to these items via the registered transform.
14
14
  */
15
- lockedItems: readonly LockSelectionKey[];
15
+ lockedItems: readonly K[];
16
16
  /**
17
17
  * Fires when the user toggles the lock. The destination is responsible for
18
18
  * persisting the new locked set (and re-feeding it via `lockedItems`).
19
19
  */
20
- onLockChange: (next: readonly LockSelectionKey[]) => void;
20
+ onLockChange: (next: readonly K[]) => void;
21
21
  labels?: Partial<LockSelectionLabels>;
22
22
  /** Lock icon (default: `LockIcon`). */
23
23
  lockIcon?: ComponentType<SvgIconProps>;
24
24
  /** Unlock icon (default: `LockOpenIcon`). */
25
25
  unlockIcon?: ComponentType<SvgIconProps>;
26
26
  iconProps?: SvgIconProps;
27
+ /**
28
+ * Data transform applied while locked. Defaults to {@link filterByLockedItems}
29
+ * (keeps only `{name, ...}` items whose `name` is in `lockedItems`, across a
30
+ * `X[][]` series shape — matches Bar/Pie/Category/Timeseries data). Widgets
31
+ * whose data shape or selection identity differs (bin index, composite
32
+ * point key, flat rows) pass their own — e.g. Histogram's
33
+ * `filterHistogramByLockedBins`, Scatterplot's
34
+ * `filterScatterplotByLockedPoints`, Table's `filterTableByLockedRows`.
35
+ */
36
+ filterFn?: (data: unknown, lockedItems: readonly K[]) => unknown;
27
37
  }
28
38
  /**
29
39
  * Action that pins the current selection so the widget's data filters down
@@ -33,4 +43,4 @@ export interface LockSelectionProps {
33
43
  *
34
44
  * The trigger is disabled when there is nothing to lock and nothing locked.
35
45
  */
36
- export declare function LockSelection({ selection, lockedItems, onLockChange, labels, lockIcon: LockSvg, unlockIcon: UnlockSvg, iconProps, }: LockSelectionProps): import("react/jsx-runtime").JSX.Element;
46
+ export declare function LockSelection<K extends LockSelectionKey = LockSelectionKey>({ selection, lockedItems, onLockChange, labels, lockIcon: LockSvg, unlockIcon: UnlockSvg, iconProps, filterFn, }: LockSelectionProps<K>): import("react/jsx-runtime").JSX.Element;
@@ -10,9 +10,25 @@ export interface CategoryLegendProps {
10
10
  * same source).
11
11
  */
12
12
  colorAt: (index: number) => string | undefined;
13
+ /**
14
+ * Series indices currently hidden from the chart. Renders dimmed.
15
+ * Optional — defaults to none hidden. Added after this component's first
16
+ * release; kept optional (not required) so it stays a non-breaking
17
+ * addition for any direct consumer of `CategoryLegend` (a public
18
+ * subpath export) that predates the hide feature.
19
+ */
20
+ hiddenSeries?: ReadonlySet<number>;
21
+ /**
22
+ * Fires with the series index when its legend item is clicked. Optional
23
+ * — omitting it renders a legend with no hide affordance (same
24
+ * reasoning as `hiddenSeries`).
25
+ */
26
+ onToggle?: (index: number) => void;
13
27
  }
14
28
  /**
15
29
  * Sticky color legend rendered below a multi-series Category list.
16
- * Per-series `color` overrides the matching `colorAt(i)` result.
30
+ * Per-series `color` overrides the matching `colorAt(i)` result. Clicking an
31
+ * item toggles that series' visibility in the rows above (mirrors ECharts'
32
+ * native legend click-to-hide).
17
33
  */
18
- export declare function CategoryLegend({ series, colorAt }: CategoryLegendProps): import("react/jsx-runtime").JSX.Element | null;
34
+ export declare function CategoryLegend({ series, colorAt, hiddenSeries, onToggle, }: CategoryLegendProps): import("react/jsx-runtime").JSX.Element | null;
@@ -8,7 +8,12 @@ export interface CategoryRowStackedProps {
8
8
  values: readonly number[];
9
9
  /** One color per series (palette + per-series overrides resolved upstream). */
10
10
  colors: readonly string[];
11
- /** Series names for the breakdown row. Missing entries fall back to `Series N`. */
11
+ /**
12
+ * Series names for the breakdown row, one per visible series, already
13
+ * resolved by the caller (unnamed series fall back to `Series N` using
14
+ * their ORIGINAL series index — this component has no notion of which
15
+ * series were hidden, so it must not recompute a positional fallback).
16
+ */
12
17
  seriesNames: readonly string[];
13
18
  formatter: (n: number) => string;
14
19
  selected: boolean;
@@ -140,6 +140,14 @@ export declare const styles: {
140
140
  display: string;
141
141
  alignItems: string;
142
142
  gap: number;
143
+ cursor: string;
144
+ };
145
+ legendItemHidden: {
146
+ display: string;
147
+ alignItems: string;
148
+ gap: number;
149
+ cursor: string;
150
+ opacity: number;
143
151
  };
144
152
  legendDot: {
145
153
  width: number;
@@ -2,7 +2,13 @@ import { CallbackDataParams } from 'echarts/types/dist/shared';
2
2
  import { EchartsEventHandler } from './echart-ui';
3
3
  export type SelectionKey = string | number;
4
4
  export interface UseChartSelectionOptions<K extends SelectionKey> {
5
- /** Controlled selection. `undefined` is treated the same as `[]`. */
5
+ /**
6
+ * Controlled selection. `undefined`/`null`/an explicit `[]` all mean "no
7
+ * selection interaction" — every current merger already treats an empty
8
+ * selection as "nothing excluded," so this hook collapses all three to
9
+ * `null` rather than promising per-merger `[]` semantics it doesn't
10
+ * implement.
11
+ */
6
12
  selection?: readonly K[];
7
13
  /** Receives the next selection. When omitted the wiring is a no-op. */
8
14
  onSelectionChange?: (next: readonly K[]) => void;
@@ -29,9 +35,9 @@ export interface ChartSelectionWiring<K extends SelectionKey> {
29
35
  */
30
36
  onEvents: Record<string, EchartsEventHandler>;
31
37
  /**
32
- * The current selection — `null` when the consumer didn't pass one or it's
33
- * empty. Mergers should treat `null` as "no dimming" and a non-null array
34
- * as "render only these as fully opaque, dim the rest".
38
+ * The current selection — `null` for "no selection interaction"
39
+ * (`undefined`/`null`/an explicit `[]`), or a non-empty array meaning
40
+ * "render only these as fully opaque, dim the rest".
35
41
  */
36
42
  selection: readonly K[] | null;
37
43
  }
@@ -1,5 +1,5 @@
1
1
  export { histogramOptions, createHistogramOptionFactory } from './options';
2
2
  export { HistogramSkeleton, type HistogramSkeletonProps } from './skeleton';
3
3
  export { createHistogramDownloadConfig } from './download';
4
- export { toRelativeHistogramData } from './transforms';
4
+ export { toRelativeHistogramData, filterHistogramByLockedBins, } from './transforms';
5
5
  export type { HistogramWidgetData, HistogramOptionsInput, HistogramOptionFactoryInput, HistogramEChartsOption, } from './types';
@@ -15,3 +15,14 @@
15
15
  * shape-check pattern as the default transform).
16
16
  */
17
17
  export declare const toRelativeHistogramData: (input: unknown) => unknown;
18
+ /**
19
+ * `LockSelection` filter for Histogram. Data is `number[][]` — a flat list
20
+ * of bin counts per series, positionally paired with `ticks` (bin `i` covers
21
+ * `[ticks[i], ticks[i+1])`). Unlike name-keyed widgets, locked-out bins can't
22
+ * be REMOVED — that would shift every later bin's index and desync it from
23
+ * its `ticks` range. Zeroing them out instead preserves array length/position,
24
+ * so locked bins just render as empty (height 0) rather than disappearing.
25
+ *
26
+ * `lockedItems` holds bin indices (numbers, from Histogram's `selection`).
27
+ */
28
+ export declare function filterHistogramByLockedBins(input: unknown, lockedItems: readonly (string | number)[]): unknown;
@@ -41,6 +41,15 @@ export interface HistogramOptionFactoryInput {
41
41
  * (`itemStyle.opacity: 0.15`). `null`/empty means no selection.
42
42
  */
43
43
  selection?: readonly number[] | null;
44
+ /**
45
+ * Locked bin indices (from `LockSelection`). The x-axis crops its visible
46
+ * window to `[min(lockedItems), max(lockedItems)]` so the chart actually
47
+ * zooms into the locked range instead of showing every bin label with
48
+ * zeroed-out bars outside it. `null`/empty means no crop. Histogram's
49
+ * selection is always a contiguous run (`use-widget-filters`'s BETWEEN
50
+ * envelope round-trip fills any gaps), so min/max fully describes it.
51
+ */
52
+ lockedItems?: readonly number[] | null;
44
53
  /**
45
54
  * Consumer-supplied partial option merged into the structural option at
46
55
  * structural-build time. Lets stories override pieces of the theme-aware
@@ -1,5 +1,5 @@
1
1
  export { scatterplotOptions, createScatterplotOptionFactory } from './options';
2
2
  export { ScatterplotSkeleton, type ScatterplotSkeletonProps } from './skeleton';
3
3
  export { createScatterplotDownloadConfig } from './download';
4
- export { toRelativeScatterplotData } from './transforms';
4
+ export { toRelativeScatterplotData, filterScatterplotByLockedPoints, } from './transforms';
5
5
  export type { ScatterplotDatum, ScatterplotWidgetData, ScatterplotOptionsInput, ScatterplotOptionFactoryInput, ScatterplotEChartsOption, } from './types';
@@ -15,3 +15,12 @@
15
15
  * untouched.
16
16
  */
17
17
  export declare const toRelativeScatterplotData: (input: unknown) => unknown;
18
+ /**
19
+ * `LockSelection` filter for Scatterplot. Data is `[number, number][][]` —
20
+ * points have no `name`, so selection (and locking) is keyed on a synthetic
21
+ * `${seriesIndex}:${dataIndex}` string (same format `useChartSelection`'s
22
+ * `keyFromClick`/`keysFromBrush` produce for this widget). Unlike Histogram,
23
+ * a point's position carries no external meaning (no `ticks` to desync from),
24
+ * so non-locked points are removed outright rather than zeroed.
25
+ */
26
+ export declare function filterScatterplotByLockedPoints(input: unknown, lockedItems: readonly (string | number)[]): unknown;
@@ -2,6 +2,7 @@ export { Table, type TableProps } from './table';
2
2
  export { TableUI, type TableUIProps } from './table-ui';
3
3
  export { TableSkeleton, type TableSkeletonProps } from './skeleton';
4
4
  export { createTableDownloadConfig } from './download';
5
+ export { filterTableByLockedRows } from './transforms';
5
6
  export { compareValues, sortRows, paginateRows, resolveColumns, deriveVisibleRows, tableDataToCsv, } from './helpers';
6
7
  export { DEFAULT_TABLE_LABELS, type TableLabels } from './labels';
7
8
  export { DEFAULT_TABLE_PAGE_SIZE, DEFAULT_TABLE_PAGE_SIZE_OPTIONS, type TableColumn, type TableRow, type TableWidgetData, type TableWidgetState, type TableSortDirection, type TableSortState, } from './types';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `LockSelection` filter for Table. Data is a FLAT `TableRow[]` (unlike every
3
+ * other widget's `X[][]` series shape) and row identity comes from
4
+ * `row[keyColumn]` (default `'id'`), not `name` — so `filterByLockedItems`
5
+ * doesn't apply here (its outer `.map` treats each row as a "series", and a
6
+ * plain row object isn't an array, so it would silently pass everything
7
+ * through unfiltered). Falls back to the row's index when the identity
8
+ * column is nullish, mirroring `TableUI`'s own `resolveRowId`.
9
+ *
10
+ * `keyColumn` isn't part of `LockSelection`'s generic `filterFn` signature —
11
+ * close over it: `filterFn={(data, locked) => filterTableByLockedRows(data, locked, keyColumn)}`.
12
+ */
13
+ export declare function filterTableByLockedRows(input: unknown, lockedItems: readonly (string | number)[], keyColumn?: string): unknown;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  export { timeseriesOptions, createTimeseriesOptionFactory } from './options';
2
2
  export { TimeseriesSkeleton } from './skeleton';
3
3
  export { createTimeseriesDownloadConfig } from './download';
4
+ export { filterTimeseriesByLockedItems } from './transforms';
4
5
  export type { TimeseriesDatum, TimeseriesWidgetData, TimeseriesOptionsInput, TimeseriesOptionFactoryInput, TimeseriesEChartsOption, } from './types';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `LockSelection` filter for Timeseries. Data is `{name, value}[][]` like
3
+ * Bar/Pie/Category, but `name` may arrive as `Date | number | string` (the
4
+ * time axis stores a `Date`). `lockedItems` is snapshotted from `selection`,
5
+ * whose keys are already normalized to `Date → ms` (see `options.ts`'s
6
+ * `normalizeName`) — so a raw `Date` name must be normalized the same way
7
+ * before the membership check, or every point would compare a `Date` object
8
+ * against a `number` and silently fail to match, filtering everything out.
9
+ */
10
+ export declare function filterTimeseriesByLockedItems(input: unknown, lockedItems: readonly (string | number)[]): unknown;
@@ -1,4 +1,4 @@
1
- import { B as L, C as o, D as e, a as A, b as E, c as r, d as t, e as S, f as _, g as T, h as l, i as D, j as d, F as n, L as c, R as O, S as g, k as B, l as C, m, n as F, Z as U, o as i, p as I, q as h, r as w, s as G, t as f, u as N, v as R } from "../change-column-CiVAjOUB.js";
1
+ import { B as L, C as o, D as e, a as A, b as E, c as r, d as t, e as S, f as _, g as T, h as l, i as D, j as d, F as n, L as c, R as O, S as g, k as B, l as C, m, n as F, Z as U, o as i, p as I, q as h, r as w, s as G, t as f, u as N, v as R } from "../change-column-Bhcxmp-r.js";
2
2
  import { Z as u, a as x, c as M } from "../transforms-Cdx4fkU5.js";
3
3
  import { d as b, a as p, t as v, b as H } from "../exports-Cx-f6m6U.js";
4
4
  import { C as W, D as V, M as y, P as K, b as j } from "../png-item-9dNbB37T.js";
@@ -1,4 +1,4 @@
1
- import { C as N, a as P, b as $, c as z, d as G, e as L, f as M } from "../category-CGS_eHr4.js";
1
+ import { C as N, a as P, b as $, c as z, d as G, e as L, f as M } from "../category-Ct2BzADB.js";
2
2
  import { jsx as m, jsxs as g } from "react/jsx-runtime";
3
3
  import { c as d } from "react/compiler-runtime";
4
4
  import { Box as c, Skeleton as p } from "@mui/material";
@@ -1,4 +1,4 @@
1
- import { D as T, E as z, a as D, _ as U, o as w } from "../echart-Bdvbfx9s.js";
1
+ import { D as T, E as z, a as D, _ as U, o as w } from "../echart-B10dhEaM.js";
2
2
  import { c as C } from "react/compiler-runtime";
3
3
  import { useRef as R } from "react";
4
4
  function F(x) {
@@ -1 +1 @@
1
- {"version":3,"file":"echart.js","sources":["../../src/widgets-v2/echart/use-chart-selection.ts"],"sourcesContent":["import { useCallback, useMemo, useRef } from 'react'\nimport type { CallbackDataParams } from 'echarts/types/dist/shared'\nimport type { EchartsEventHandler } from './echart-ui'\n\nexport type SelectionKey = string | number\n\nexport interface UseChartSelectionOptions<K extends SelectionKey> {\n /** Controlled selection. `undefined` is treated the same as `[]`. */\n selection?: readonly K[]\n /** Receives the next selection. When omitted the wiring is a no-op. */\n onSelectionChange?: (next: readonly K[]) => void\n /**\n * Pull a selection key out of an ECharts `click` event. Return `null` to\n * skip (e.g. a click on empty plot area). For Bar/Pie/Timeseries this is\n * usually `(p) => p.name`; for Histogram/Scatterplot it's the dataIndex.\n */\n keyFromClick: (params: CallbackDataParams) => K | null\n /**\n * Map a `brushSelected` payload's `selected[*]` entries (each carrying a\n * `seriesIndex` + `dataIndex[]`) into the full set of selection keys for\n * the brushed area. Called once per brush event.\n */\n keysFromBrush: (\n selected: readonly { seriesIndex: number; dataIndex: number[] }[],\n ) => K[]\n}\n\nexport interface ChartSelectionWiring<K extends SelectionKey> {\n /**\n * Pass straight to `<Widget.Echart onEvents={…}>`. Wires `click` and\n * `brushSelected` so the user's interactions reach `onSelectionChange`.\n */\n onEvents: Record<string, EchartsEventHandler>\n /**\n * The current selection — `null` when the consumer didn't pass one or it's\n * empty. Mergers should treat `null` as \"no dimming\" and a non-null array\n * as \"render only these as fully opaque, dim the rest\".\n */\n selection: readonly K[] | null\n}\n\n/**\n * Translate ECharts' click + brush events into a consumer-owned selection\n * with the expected dashboard semantics:\n *\n * - **Click toggles** — clicking an item adds it to the selection if\n * absent, removes it if present.\n * - **Brush replaces** — finishing a brush stroke overwrites the selection\n * with whatever the brush covered (drag-to-empty clears).\n *\n * Wire the returned `onEvents` into `<Widget.Echart>` and feed\n * `wiring.selection` to the widget's option factory so the merger can dim\n * non-selected rows at fusion time.\n */\nexport function useChartSelection<K extends SelectionKey>({\n selection,\n onSelectionChange,\n keyFromClick,\n keysFromBrush,\n}: UseChartSelectionOptions<K>): ChartSelectionWiring<K> {\n const handleClick = useCallback(\n (event: unknown) => {\n if (!onSelectionChange) return\n const params = event as CallbackDataParams\n const key = keyFromClick(params)\n if (key == null) return\n const current = selection ?? []\n const idx = current.indexOf(key)\n const next =\n idx === -1\n ? [...current, key]\n : [...current.slice(0, idx), ...current.slice(idx + 1)]\n onSelectionChange(next)\n },\n [selection, onSelectionChange, keyFromClick],\n )\n\n // ECharts fires `brushSelected` on every pointer-move while the user is\n // drawing a brush, but we only want to push to `onSelectionChange` once\n // the gesture ends. Cache the latest `brushSelected` payload here, then\n // commit on `brushEnd`.\n const latestBrushedRef = useRef<\n readonly { seriesIndex: number; dataIndex: number[] }[]\n >([])\n\n const handleBrushSelected = useCallback((event: unknown) => {\n const params = event as {\n batch?: {\n selected?: { seriesIndex: number; dataIndex: number[] }[]\n }[]\n }\n latestBrushedRef.current = params.batch?.[0]?.selected ?? []\n }, [])\n\n const handleBrushEnd = useCallback(() => {\n if (!onSelectionChange) return\n onSelectionChange(keysFromBrush(latestBrushedRef.current))\n }, [onSelectionChange, keysFromBrush])\n\n const onEvents = useMemo<Record<string, EchartsEventHandler>>(\n () => ({\n click: handleClick,\n brushSelected: handleBrushSelected,\n brushEnd: handleBrushEnd,\n }),\n [handleClick, handleBrushSelected, handleBrushEnd],\n )\n\n const wiringSelection = useMemo(\n () => (selection && selection.length > 0 ? selection : null),\n [selection],\n )\n\n return { onEvents, selection: wiringSelection }\n}\n"],"names":["useChartSelection","t0","$","_c","selection","onSelectionChange","keyFromClick","keysFromBrush","t1","event","key","current","idx","indexOf","next","slice","handleClick","t2","Symbol","for","latestBrushedRef","useRef","t3","event_0","params_0","params","batch","selected","handleBrushSelected","t4","handleBrushEnd","t5","click","brushSelected","brushEnd","onEvents","wiringSelection","length","t6"],"mappings":";;;AAsDO,SAAAA,EAAAC,GAAA;AAAA,QAAAC,IAAAC,EAAA,EAAA,GAAmD;AAAA,IAAAC,WAAAA;AAAAA,IAAAC,mBAAAA;AAAAA,IAAAC,cAAAA;AAAAA,IAAAC,eAAAA;AAAAA,EAAAA,IAAAN;AAK5B,MAAAO;AAAA,EAAAN,EAAA,CAAA,MAAAI,KAAAJ,SAAAG,KAAAH,EAAA,CAAA,MAAAE,KAE1BI,IAAAC,CAAAA,MAAA;AACE,QAAI,CAACJ;AAAiB;AAEtB,UAAAK,IAAYJ,EADGG,CACgB;AAC/B,QAAIC,KAAO;AAAI;AACf,UAAAC,IAAgBP,KAAA,CAAA,GAChBQ,IAAYD,EAAOE,QAASH,CAAG,GAC/BI,IACEF,MAAQ,KAAR,CAA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CjC,IAAA;AAER,MAAAkC;AAAA,SAAApC,EAAA,EAAA,MAAAiC,KAAAjC,UAAAkC,KAEME,IAAA;AAAA,IAAAH,UAAAA;AAAAA,IAAA/B,WAAuBgC;AAAAA,EAAAA,GAAiBlC,QAAAiC,GAAAjC,QAAAkC,GAAAlC,QAAAoC,KAAAA,IAAApC,EAAA,EAAA,GAAxCoC;AAAwC;"}
1
+ {"version":3,"file":"echart.js","sources":["../../src/widgets-v2/echart/use-chart-selection.ts"],"sourcesContent":["import { useCallback, useMemo, useRef } from 'react'\nimport type { CallbackDataParams } from 'echarts/types/dist/shared'\nimport type { EchartsEventHandler } from './echart-ui'\n\nexport type SelectionKey = string | number\n\nexport interface UseChartSelectionOptions<K extends SelectionKey> {\n /**\n * Controlled selection. `undefined`/`null`/an explicit `[]` all mean \"no\n * selection interaction\" — every current merger already treats an empty\n * selection as \"nothing excluded,\" so this hook collapses all three to\n * `null` rather than promising per-merger `[]` semantics it doesn't\n * implement.\n */\n selection?: readonly K[]\n /** Receives the next selection. When omitted the wiring is a no-op. */\n onSelectionChange?: (next: readonly K[]) => void\n /**\n * Pull a selection key out of an ECharts `click` event. Return `null` to\n * skip (e.g. a click on empty plot area). For Bar/Pie/Timeseries this is\n * usually `(p) => p.name`; for Histogram/Scatterplot it's the dataIndex.\n */\n keyFromClick: (params: CallbackDataParams) => K | null\n /**\n * Map a `brushSelected` payload's `selected[*]` entries (each carrying a\n * `seriesIndex` + `dataIndex[]`) into the full set of selection keys for\n * the brushed area. Called once per brush event.\n */\n keysFromBrush: (\n selected: readonly { seriesIndex: number; dataIndex: number[] }[],\n ) => K[]\n}\n\nexport interface ChartSelectionWiring<K extends SelectionKey> {\n /**\n * Pass straight to `<Widget.Echart onEvents={…}>`. Wires `click` and\n * `brushSelected` so the user's interactions reach `onSelectionChange`.\n */\n onEvents: Record<string, EchartsEventHandler>\n /**\n * The current selection — `null` for \"no selection interaction\"\n * (`undefined`/`null`/an explicit `[]`), or a non-empty array meaning\n * \"render only these as fully opaque, dim the rest\".\n */\n selection: readonly K[] | null\n}\n\n/**\n * Translate ECharts' click + brush events into a consumer-owned selection\n * with the expected dashboard semantics:\n *\n * - **Click toggles** — clicking an item adds it to the selection if\n * absent, removes it if present.\n * - **Brush replaces** — finishing a brush stroke overwrites the selection\n * with whatever the brush covered (drag-to-empty clears).\n *\n * Wire the returned `onEvents` into `<Widget.Echart>` and feed\n * `wiring.selection` to the widget's option factory so the merger can dim\n * non-selected rows at fusion time.\n */\nexport function useChartSelection<K extends SelectionKey>({\n selection,\n onSelectionChange,\n keyFromClick,\n keysFromBrush,\n}: UseChartSelectionOptions<K>): ChartSelectionWiring<K> {\n const handleClick = useCallback(\n (event: unknown) => {\n if (!onSelectionChange) return\n const params = event as CallbackDataParams\n const key = keyFromClick(params)\n if (key == null) return\n const current = selection ?? []\n const idx = current.indexOf(key)\n const next =\n idx === -1\n ? [...current, key]\n : [...current.slice(0, idx), ...current.slice(idx + 1)]\n onSelectionChange(next)\n },\n [selection, onSelectionChange, keyFromClick],\n )\n\n // ECharts fires `brushSelected` on every pointer-move while the user is\n // drawing a brush, but we only want to push to `onSelectionChange` once\n // the gesture ends. Cache the latest `brushSelected` payload here, then\n // commit on `brushEnd`.\n const latestBrushedRef = useRef<\n readonly { seriesIndex: number; dataIndex: number[] }[]\n >([])\n\n const handleBrushSelected = useCallback((event: unknown) => {\n const params = event as {\n batch?: {\n selected?: { seriesIndex: number; dataIndex: number[] }[]\n }[]\n }\n latestBrushedRef.current = params.batch?.[0]?.selected ?? []\n }, [])\n\n const handleBrushEnd = useCallback(() => {\n if (!onSelectionChange) return\n onSelectionChange(keysFromBrush(latestBrushedRef.current))\n }, [onSelectionChange, keysFromBrush])\n\n const onEvents = useMemo<Record<string, EchartsEventHandler>>(\n () => ({\n click: handleClick,\n brushSelected: handleBrushSelected,\n brushEnd: handleBrushEnd,\n }),\n [handleClick, handleBrushSelected, handleBrushEnd],\n )\n\n const wiringSelection = useMemo(\n () => (selection && selection.length > 0 ? selection : null),\n [selection],\n )\n\n return { onEvents, selection: wiringSelection }\n}\n"],"names":["useChartSelection","t0","$","_c","selection","onSelectionChange","keyFromClick","keysFromBrush","t1","event","key","current","idx","indexOf","next","slice","handleClick","t2","Symbol","for","latestBrushedRef","useRef","t3","event_0","params_0","params","batch","selected","handleBrushSelected","t4","handleBrushEnd","t5","click","brushSelected","brushEnd","onEvents","wiringSelection","length","t6"],"mappings":";;;AA4DO,SAAAA,EAAAC,GAAA;AAAA,QAAAC,IAAAC,EAAA,EAAA,GAAmD;AAAA,IAAAC,WAAAA;AAAAA,IAAAC,mBAAAA;AAAAA,IAAAC,cAAAA;AAAAA,IAAAC,eAAAA;AAAAA,EAAAA,IAAAN;AAK5B,MAAAO;AAAA,EAAAN,EAAA,CAAA,MAAAI,KAAAJ,SAAAG,KAAAH,EAAA,CAAA,MAAAE,KAE1BI,IAAAC,CAAAA,MAAA;AACE,QAAI,CAACJ;AAAiB;AAEtB,UAAAK,IAAYJ,EADGG,CACgB;AAC/B,QAAIC,KAAO;AAAI;AACf,UAAAC,IAAgBP,KAAA,CAAA,GAChBQ,IAAYD,EAAOE,QAASH,CAAG,GAC/BI,IACEF,MAAQ,KAAR,CAAA,GACQD,GAASD,CAAG,IADpB,IAEQC,EAAOI,MAAO,GAAGH,CAAG,GAAC,GAAKD,EAAOI,MAAOH,IAAM,CAAC,CAAC;AAC1DP,IAAAA,EAAkBS,CAAI;AAAA,EAAC,GACxBZ,OAAAI,GAAAJ,OAAAG,GAAAH,OAAAE,GAAAF,OAAAM,KAAAA,IAAAN,EAAA,CAAA;AAbH,QAAAc,IAAoBR;AAenB,MAAAS;AAAA,EAAAf,EAAA,CAAA,MAAAgB,uBAAAC,IAAA,2BAAA,KAQCF,IAAA,CAAA,GAAEf,OAAAe,KAAAA,IAAAf,EAAA,CAAA;AAFJ,QAAAkB,IAAyBC,EAEvBJ,CAAE;AAAC,MAAAK;AAAA,EAAApB,EAAA,CAAA,MAAAgB,uBAAAC,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