@carto/ps-react-ui 4.11.3 → 4.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/chat.js +962 -733
  2. package/dist/chat.js.map +1 -1
  3. package/dist/csv-item-hH_Gt7ur.js +32 -0
  4. package/dist/csv-item-hH_Gt7ur.js.map +1 -0
  5. package/dist/{echart-BMPpj7n_.js → echart-Bdvbfx9s.js} +2 -2
  6. package/dist/echart-Bdvbfx9s.js.map +1 -0
  7. package/dist/{option-builders-F-c9ELi1.js → option-builders-DPeoyQaM.js} +41 -33
  8. package/dist/option-builders-DPeoyQaM.js.map +1 -0
  9. package/dist/png-item-9dNbB37T.js +57 -0
  10. package/dist/png-item-9dNbB37T.js.map +1 -0
  11. package/dist/table-B3ZWWhJt.js +383 -0
  12. package/dist/table-B3ZWWhJt.js.map +1 -0
  13. package/dist/types/chat/containers/chat-footer.d.ts +1 -1
  14. package/dist/types/chat/containers/styles.d.ts +79 -12
  15. package/dist/types/chat/index.d.ts +1 -1
  16. package/dist/types/chat/types.d.ts +21 -0
  17. package/dist/types/chat/use-typewriter.d.ts +5 -3
  18. package/dist/types/widgets/utils/chart-config/index.d.ts +1 -1
  19. package/dist/types/widgets-v2/actions/download/constants.d.ts +12 -0
  20. package/dist/types/widgets-v2/actions/download/csv-item.d.ts +38 -0
  21. package/dist/types/widgets-v2/actions/download/icons.d.ts +6 -0
  22. package/dist/types/widgets-v2/actions/download/index.d.ts +3 -1
  23. package/dist/types/widgets-v2/actions/index.d.ts +1 -1
  24. package/dist/types/widgets-v2/pie/skeleton.d.ts +9 -0
  25. package/dist/widgets/bar.js +1 -1
  26. package/dist/widgets/histogram.js +1 -1
  27. package/dist/widgets/pie.js +1 -1
  28. package/dist/widgets/scatterplot.js +5 -5
  29. package/dist/widgets/timeseries.js +1 -1
  30. package/dist/widgets/utils.js +1 -1
  31. package/dist/widgets-v2/actions.js +40 -36
  32. package/dist/widgets-v2/actions.js.map +1 -1
  33. package/dist/widgets-v2/bar.js +69 -76
  34. package/dist/widgets-v2/bar.js.map +1 -1
  35. package/dist/widgets-v2/category.js +50 -55
  36. package/dist/widgets-v2/category.js.map +1 -1
  37. package/dist/widgets-v2/echart.js +1 -1
  38. package/dist/widgets-v2/formula.js +37 -43
  39. package/dist/widgets-v2/formula.js.map +1 -1
  40. package/dist/widgets-v2/histogram.js +141 -147
  41. package/dist/widgets-v2/histogram.js.map +1 -1
  42. package/dist/widgets-v2/markdown.js +18 -17
  43. package/dist/widgets-v2/markdown.js.map +1 -1
  44. package/dist/widgets-v2/pie.js +174 -126
  45. package/dist/widgets-v2/pie.js.map +1 -1
  46. package/dist/widgets-v2/scatterplot.js +156 -166
  47. package/dist/widgets-v2/scatterplot.js.map +1 -1
  48. package/dist/widgets-v2/spread.js +36 -41
  49. package/dist/widgets-v2/spread.js.map +1 -1
  50. package/dist/widgets-v2/table.js +46 -55
  51. package/dist/widgets-v2/table.js.map +1 -1
  52. package/dist/widgets-v2/timeseries.js +83 -89
  53. package/dist/widgets-v2/timeseries.js.map +1 -1
  54. package/dist/widgets-v2.js +3 -3
  55. package/package.json +1 -1
  56. package/src/chat/bubbles/styles.ts +5 -1
  57. package/src/chat/containers/chat-content.tsx +4 -1
  58. package/src/chat/containers/chat-footer.test.tsx +59 -0
  59. package/src/chat/containers/chat-footer.tsx +124 -36
  60. package/src/chat/containers/styles.ts +107 -16
  61. package/src/chat/feedback/styles.ts +11 -4
  62. package/src/chat/index.ts +1 -0
  63. package/src/chat/types.ts +22 -0
  64. package/src/chat/use-typewriter.ts +32 -24
  65. package/src/widgets/utils/chart-config/index.ts +1 -0
  66. package/src/widgets/utils/chart-config/option-builders.test.ts +34 -0
  67. package/src/widgets/utils/chart-config/option-builders.ts +21 -0
  68. package/src/widgets-v2/actions/download/constants.ts +14 -0
  69. package/src/widgets-v2/actions/download/csv-item.test.tsx +77 -0
  70. package/src/widgets-v2/actions/download/csv-item.tsx +71 -0
  71. package/src/widgets-v2/actions/download/icons.tsx +10 -1
  72. package/src/widgets-v2/actions/download/index.ts +3 -1
  73. package/src/widgets-v2/actions/download/png-item.tsx +2 -1
  74. package/src/widgets-v2/actions/index.ts +5 -0
  75. package/src/widgets-v2/bar/download.tsx +16 -22
  76. package/src/widgets-v2/bar/options.ts +3 -2
  77. package/src/widgets-v2/category/download.test.ts +9 -0
  78. package/src/widgets-v2/category/download.ts +16 -20
  79. package/src/widgets-v2/echart/edge-label-clamp.ts +7 -4
  80. package/src/widgets-v2/formula/download.tsx +23 -29
  81. package/src/widgets-v2/histogram/download.ts +22 -26
  82. package/src/widgets-v2/histogram/options.ts +3 -2
  83. package/src/widgets-v2/markdown/{download.ts → download.tsx} +5 -2
  84. package/src/widgets-v2/pie/download.ts +16 -20
  85. package/src/widgets-v2/pie/skeleton.test.tsx +6 -3
  86. package/src/widgets-v2/pie/skeleton.tsx +69 -7
  87. package/src/widgets-v2/scatterplot/download.ts +16 -20
  88. package/src/widgets-v2/scatterplot/options.ts +3 -6
  89. package/src/widgets-v2/spread/download.ts +23 -27
  90. package/src/widgets-v2/table/download.test.ts +10 -0
  91. package/src/widgets-v2/table/download.ts +11 -15
  92. package/src/widgets-v2/table/helpers.test.ts +19 -0
  93. package/src/widgets-v2/table/helpers.ts +7 -12
  94. package/src/widgets-v2/timeseries/download.ts +36 -40
  95. package/src/widgets-v2/timeseries/options.ts +3 -2
  96. package/dist/echart-BMPpj7n_.js.map +0 -1
  97. package/dist/option-builders-F-c9ELi1.js.map +0 -1
  98. package/dist/png-item-BE9uEqlD.js +0 -45
  99. package/dist/png-item-BE9uEqlD.js.map +0 -1
  100. package/dist/table-C9IMbTr0.js +0 -385
  101. package/dist/table-C9IMbTr0.js.map +0 -1
  102. package/dist/types/chat/feedback/styles.d.ts +0 -211
  103. package/dist/types/widgets/utils/chart-config/option-builders.d.ts +0 -124
@@ -1,6 +1,6 @@
1
1
  import {
2
+ buildCsvDownloadItem,
2
3
  buildPngDownloadItem,
3
- downloadToCSV,
4
4
  type DownloadItem,
5
5
  } from '../actions/download'
6
6
  import type { ScatterplotWidgetData } from './types'
@@ -30,25 +30,21 @@ export function createScatterplotDownloadConfig(args: {
30
30
  }),
31
31
  )
32
32
  }
33
- items.push({
34
- id: 'csv',
35
- label: 'Download as CSV',
36
- resolve: () => {
37
- const data = args.getData()
38
- const rows: unknown[][] = [['series', 'x', 'y']]
39
- for (const [i, series] of data.entries()) {
40
- const seriesName = args.seriesNames?.[i] ?? `series_${i + 1}`
41
- for (const [x, y] of series) {
42
- rows.push([seriesName, x, y])
33
+ items.push(
34
+ buildCsvDownloadItem({
35
+ filename: args.filename,
36
+ getRows: () => {
37
+ const data = args.getData()
38
+ const rows: unknown[][] = [['series', 'x', 'y']]
39
+ for (const [i, series] of data.entries()) {
40
+ const seriesName = args.seriesNames?.[i] ?? `series_${i + 1}`
41
+ for (const [x, y] of series) {
42
+ rows.push([seriesName, x, y])
43
+ }
43
44
  }
44
- }
45
- const handle = downloadToCSV(rows)
46
- return Promise.resolve({
47
- url: handle.url,
48
- filename: `${args.filename}.csv`,
49
- revoke: handle.revoke,
50
- })
51
- },
52
- })
45
+ return rows
46
+ },
47
+ }),
48
+ )
53
49
  return items
54
50
  }
@@ -2,6 +2,7 @@ import type { EChartsOption } from 'echarts'
2
2
  import * as echarts from 'echarts'
3
3
  import type { CallbackDataParams } from 'echarts/types/dist/shared'
4
4
  import {
5
+ buildAxisLabelStyle,
5
6
  buildGridConfig,
6
7
  buildLegendConfig,
7
8
  createTooltipFormatter,
@@ -80,9 +81,7 @@ export function scatterplotOptions({
80
81
  axisLine: { show: false },
81
82
  axisTick: { show: false },
82
83
  axisLabel: {
83
- fontSize: theme.typography.overlineDelicate?.fontSize,
84
- fontFamily: theme.typography.overlineDelicate?.fontFamily,
85
- color: theme.palette.black?.[60],
84
+ ...buildAxisLabelStyle(theme),
86
85
  margin: parseInt(theme.spacing(1)),
87
86
  hideOverlap: true,
88
87
  showMinLabel: true,
@@ -99,9 +98,7 @@ export function scatterplotOptions({
99
98
  axisLine: { show: false },
100
99
  axisTick: { show: false },
101
100
  axisLabel: {
102
- fontSize: theme.typography.overlineDelicate?.fontSize,
103
- fontFamily: theme.typography.overlineDelicate?.fontFamily,
104
- color: theme.palette.black?.[60],
101
+ ...buildAxisLabelStyle(theme),
105
102
  margin: parseInt(theme.spacing(1)),
106
103
  hideOverlap: true,
107
104
  showMinLabel: true,
@@ -1,6 +1,6 @@
1
1
  import {
2
+ buildCsvDownloadItem,
2
3
  buildPngDownloadItem,
3
- downloadToCSV,
4
4
  type DownloadItem,
5
5
  } from '../actions/download'
6
6
  import type { SpreadWidgetData } from './types'
@@ -29,31 +29,27 @@ export function createSpreadDownloadConfig(args: {
29
29
  }),
30
30
  )
31
31
  }
32
- items.push({
33
- id: 'csv',
34
- label: 'Download as CSV',
35
- resolve: () => {
36
- const data = args.getData()
37
- const rows: unknown[][] = [
38
- ['series', 'prefix', 'min', 'max', 'suffix', 'note'],
39
- ]
40
- for (const item of data) {
41
- rows.push([
42
- item.series?.name ?? '',
43
- item.prefix ?? '',
44
- item.min,
45
- item.max,
46
- item.suffix ?? '',
47
- item.note ?? '',
48
- ])
49
- }
50
- const handle = downloadToCSV(rows)
51
- return Promise.resolve({
52
- url: handle.url,
53
- filename: `${args.filename}.csv`,
54
- revoke: handle.revoke,
55
- })
56
- },
57
- })
32
+ items.push(
33
+ buildCsvDownloadItem({
34
+ filename: args.filename,
35
+ getRows: () => {
36
+ const data = args.getData()
37
+ const rows: unknown[][] = [
38
+ ['series', 'prefix', 'min', 'max', 'suffix', 'note'],
39
+ ]
40
+ for (const item of data) {
41
+ rows.push([
42
+ item.series?.name ?? '',
43
+ item.prefix ?? '',
44
+ item.min,
45
+ item.max,
46
+ item.suffix ?? '',
47
+ item.note ?? '',
48
+ ])
49
+ }
50
+ return rows
51
+ },
52
+ }),
53
+ )
58
54
  return items
59
55
  }
@@ -61,6 +61,16 @@ describe('createTableDownloadConfig', () => {
61
61
  expect(csvText).toBe('Name,Score\nAlpha,10\nBeta,20')
62
62
  })
63
63
 
64
+ it('CSV guards formula-injection cells end-to-end', async () => {
65
+ const items = createTableDownloadConfig({
66
+ filename: 't',
67
+ getData: () => [{ id: 1, name: '=HYPERLINK("x")', score: 1 }],
68
+ columns,
69
+ })
70
+ await items.find((i) => i.id === 'csv')!.resolve()
71
+ expect(csvText).toBe('Name,Score\n"\'=HYPERLINK(""x"")",1')
72
+ })
73
+
64
74
  it('CSV calls getData() at click time (not at config creation)', async () => {
65
75
  let snapshot: TableWidgetData = data
66
76
  const items = createTableDownloadConfig({
@@ -1,4 +1,8 @@
1
- import { buildPngDownloadItem, type DownloadItem } from '../actions/download'
1
+ import {
2
+ buildCsvDownloadItem,
3
+ buildPngDownloadItem,
4
+ type DownloadItem,
5
+ } from '../actions/download'
2
6
  import { tableDataToCsv } from './helpers'
3
7
  import type { TableColumn, TableWidgetData } from './types'
4
8
 
@@ -29,19 +33,11 @@ export function createTableDownloadConfig(opts: {
29
33
  }),
30
34
  )
31
35
  }
32
- items.push({
33
- id: 'csv',
34
- label: 'Download as CSV',
35
- resolve: () => {
36
- const csv = tableDataToCsv(opts.getData(), opts.columns)
37
- const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' })
38
- const url = URL.createObjectURL(blob)
39
- return Promise.resolve({
40
- url,
41
- filename: `${opts.filename}.csv`,
42
- revoke: () => URL.revokeObjectURL(url),
43
- })
44
- },
45
- })
36
+ items.push(
37
+ buildCsvDownloadItem({
38
+ filename: opts.filename,
39
+ getCsv: () => tableDataToCsv(opts.getData(), opts.columns),
40
+ }),
41
+ )
46
42
  return items
47
43
  }
@@ -211,4 +211,23 @@ describe('tableDataToCsv', () => {
211
211
  expect(csv).toContain('"[""x"",""y""]"')
212
212
  expect(csv).toContain('"{""z"":1}"')
213
213
  })
214
+
215
+ it('guards against formula injection by prefixing leading =,+,-,@', () => {
216
+ const csv = tableDataToCsv(
217
+ [
218
+ { id: 1, name: '=SUM(A1)', score: '+1' },
219
+ { id: 2, name: '-2', score: '@cmd' },
220
+ ],
221
+ cols,
222
+ )
223
+ const lines = csv.split('\n')
224
+ expect(lines[1]).toBe("'=SUM(A1),'+1")
225
+ expect(lines[2]).toBe("'-2,'@cmd")
226
+ })
227
+
228
+ it('still wraps a formula cell that also contains a comma', () => {
229
+ const csv = tableDataToCsv([{ id: 1, name: '=A1,B2', score: 1 }], cols)
230
+ // Prefixed against injection, then quoted for the embedded comma.
231
+ expect(csv.split('\n')[1]).toBe('"\'=A1,B2",1')
232
+ })
214
233
  })
@@ -1,3 +1,4 @@
1
+ import { toCsvString } from '../actions/download'
1
2
  import type {
2
3
  TableColumn,
3
4
  TableRow,
@@ -102,20 +103,14 @@ export function tableDataToCsv(
102
103
  data: TableWidgetData,
103
104
  columns: readonly TableColumn[],
104
105
  ): string {
105
- const head = columns.map((c) => csvEscape(stringifyHeader(c.label))).join(',')
106
- const lines = [head]
106
+ // Pre-stringify with the table's own header/cell rules, then delegate the
107
+ // CSV assembly (quoting + spreadsheet formula-injection guard) to the shared
108
+ // `toCsvString` so escaping stays identical to every other widget's export.
109
+ const rows: string[][] = [columns.map((c) => stringifyHeader(c.label))]
107
110
  for (const row of data) {
108
- const cells = columns.map((c) => csvEscape(stringifyCell(row[c.id])))
109
- lines.push(cells.join(','))
111
+ rows.push(columns.map((c) => stringifyCell(row[c.id])))
110
112
  }
111
- return lines.join('\n')
112
- }
113
-
114
- function csvEscape(value: string): string {
115
- if (/[",\n\r]/.test(value)) {
116
- return `"${value.replace(/"/g, '""')}"`
117
- }
118
- return value
113
+ return toCsvString(rows)
119
114
  }
120
115
 
121
116
  function stringifyHeader(label: unknown): string {
@@ -1,6 +1,6 @@
1
1
  import {
2
+ buildCsvDownloadItem,
2
3
  buildPngDownloadItem,
3
- downloadToCSV,
4
4
  type DownloadItem,
5
5
  } from '../actions/download'
6
6
  import type { TimeseriesWidgetData } from './types'
@@ -31,51 +31,47 @@ export function createTimeseriesDownloadConfig(args: {
31
31
  }),
32
32
  )
33
33
  }
34
- items.push({
35
- id: 'csv',
36
- label: 'Download as CSV',
37
- resolve: () => {
38
- const data = args.getData()
39
- const seriesCount = data.length
34
+ items.push(
35
+ buildCsvDownloadItem({
36
+ filename: args.filename,
37
+ getRows: () => {
38
+ const data = args.getData()
39
+ const seriesCount = data.length
40
40
 
41
- // Collect every unique time, preserving insertion order.
42
- const timeKeys: (Date | number | string)[] = []
43
- const seenKeys = new Set<string>()
44
- for (const series of data) {
45
- for (const point of series) {
46
- const key = String(point.name)
47
- if (!seenKeys.has(key)) {
48
- seenKeys.add(key)
49
- timeKeys.push(point.name)
41
+ // Collect every unique time, preserving insertion order.
42
+ const timeKeys: (Date | number | string)[] = []
43
+ const seenKeys = new Set<string>()
44
+ for (const series of data) {
45
+ for (const point of series) {
46
+ const key = String(point.name)
47
+ if (!seenKeys.has(key)) {
48
+ seenKeys.add(key)
49
+ timeKeys.push(point.name)
50
+ }
50
51
  }
51
52
  }
52
- }
53
53
 
54
- // Build a quick lookup per series for O(rows × series) emit.
55
- const lookups = data.map(
56
- (series) => new Map(series.map((p) => [String(p.name), p.value])),
57
- )
54
+ // Build a quick lookup per series for O(rows × series) emit.
55
+ const lookups = data.map(
56
+ (series) => new Map(series.map((p) => [String(p.name), p.value])),
57
+ )
58
58
 
59
- const header: unknown[] = ['time']
60
- for (let i = 0; i < seriesCount; i++) {
61
- header.push(args.seriesNames?.[i] ?? `series_${i + 1}`)
62
- }
63
- const rows: unknown[][] = [header]
64
- for (const key of timeKeys) {
65
- const row: unknown[] = [formatTime(key)]
66
- const lookupKey = String(key)
67
- for (const lookup of lookups) row.push(lookup.get(lookupKey) ?? '')
68
- rows.push(row)
69
- }
59
+ const header: unknown[] = ['time']
60
+ for (let i = 0; i < seriesCount; i++) {
61
+ header.push(args.seriesNames?.[i] ?? `series_${i + 1}`)
62
+ }
63
+ const rows: unknown[][] = [header]
64
+ for (const key of timeKeys) {
65
+ const row: unknown[] = [formatTime(key)]
66
+ const lookupKey = String(key)
67
+ for (const lookup of lookups) row.push(lookup.get(lookupKey) ?? '')
68
+ rows.push(row)
69
+ }
70
70
 
71
- const handle = downloadToCSV(rows)
72
- return Promise.resolve({
73
- url: handle.url,
74
- filename: `${args.filename}.csv`,
75
- revoke: handle.revoke,
76
- })
77
- },
78
- })
71
+ return rows
72
+ },
73
+ }),
74
+ )
79
75
  return items
80
76
  }
81
77
 
@@ -2,6 +2,7 @@ import type { EChartsOption } from 'echarts'
2
2
  import * as echarts from 'echarts'
3
3
  import type { CallbackDataParams } from 'echarts/types/dist/shared'
4
4
  import {
5
+ buildAxisLabelStyle,
5
6
  buildGridConfig,
6
7
  buildLegendConfig,
7
8
  createTooltipFormatter,
@@ -89,6 +90,7 @@ export function timeseriesOptions({
89
90
  axisLine: { show: false },
90
91
  axisTick: { show: false },
91
92
  axisLabel: {
93
+ ...buildAxisLabelStyle(theme),
92
94
  padding: [parseInt(theme.spacing(0.5)), 0, 0, 0],
93
95
  margin: 0,
94
96
  hideOverlap: true,
@@ -114,8 +116,7 @@ export function timeseriesOptions({
114
116
  lineStyle: { color: theme.palette.black?.[4] ?? theme.palette.divider },
115
117
  },
116
118
  axisLabel: {
117
- fontSize: theme.typography.overlineDelicate?.fontSize,
118
- fontFamily: theme.typography.overlineDelicate?.fontFamily,
119
+ ...buildAxisLabelStyle(theme),
119
120
  margin: parseInt(theme.spacing(1)),
120
121
  show: true,
121
122
  showMaxLabel: true,
@@ -1 +0,0 @@
1
- {"version":3,"file":"echart-BMPpj7n_.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// Bias toward anchoring when borderline: clipping is worse than a hair of\n// off-centering, and the reconstructed font may differ slightly from what\n// ECharts actually renders.\nconst SAFETY_MARGIN_PX = 2\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 return () => {\n chart.off('finished', onFinished)\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","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","Object","event_0","handler_0","t10","t11","Box","map","s","o","name","stack","JSON","stringify","join","DEFAULT_REPLACE_MERGE","echartSelector","data","configTransforms","labelFormatter","Echart","optionFactory","id","useWidgetId","slice","useWidgetShallow","setEchartInstance","sliceData","sliceFormatter","sliceLabelFormatter","structural","applyTransforms","transformed","keys","xf","enabled","replaceMergeKeys","k","sort"],"mappings":";;;;;;;;AAyBO,MAAMA,IAA0B;AAAA,EACrCC,eAAe;AAAA,EACfC,eAAe;AACjB,GAKMC,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,SAASG,EAAWC,GAAkD;AACpE,QAAMC,IAAON,EACXK,EAAOE,KACT;AACA,SAAOD,KAAQ,OAAOA,KAAS,WAAWA,IAAOE;AACnD;AAEA,SAASC,EAAYJ,GAAgC;AACnD,QAAMK,IAAKL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,IAAA3B,EAAA,CAAA;AAPhC,QAAAE,IAOEyB;AACoB,MAAAC;AAAA,EAAA5B,EAAA,CAAA,MAAAqE,KAAArE,EAAA,EAAA,MAAA2E,KAAA3E,EAAA,EAAA,MAAA4E,KAAA5E,EAAA,EAAA,MAAA6E,KAAA7E,UAAAgF,KAIlBpD,IAAAyC,EAAcW,GAAaL,GAAW;AAAA,IAAA7H,WACzB8H;AAAAA,IAAcT,gBACTU;AAAAA,EAAAA,CACjB,GAAC7E,OAAAqE,GAAArE,QAAA2E,GAAA3E,QAAA4E,GAAA5E,QAAA6E,GAAA7E,QAAAgF,GAAAhF,QAAA4B,KAAAA,IAAA5B,EAAA,EAAA;AALN,QAAA1E,IAEIsG;AAWH,MAAAU;AAAA,SAAAtC,UAAAM,KAAAN,EAAA,EAAA,MAAAI,KAAAJ,EAAA,EAAA,MAAAG,KAAAH,EAAA,EAAA,MAAAK,KAAAL,UAAA1E,KAAA0E,EAAA,EAAA,MAAAE,KAGCoC,sBAACxC,IAAA,EACSxE,QAAAA,GACM4E,cAAAA,GACJC,UAAAA,GACJC,MAAAA,GACMC,YAAAA,GACDC,WAAAA,GAAS,GACpBN,QAAAM,GAAAN,QAAAI,GAAAJ,QAAAG,GAAAH,QAAAK,GAAAL,QAAA1E,GAAA0E,QAAAE,GAAAF,QAAAsC,KAAAA,IAAAtC,EAAA,EAAA,GAPFsC;AAOE;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"option-builders-F-c9ELi1.js","sources":["../src/widgets/utils/chart-config/option-builders.ts"],"sourcesContent":["import type { Theme } from '@mui/material'\nimport type { LegendComponentOption } from 'echarts'\nimport type {\n CallbackDataParams,\n TopLevelFormatterParams,\n} from 'echarts/types/dist/shared'\n\n/**\n * Shared EChart configuration builders for chart widgets\n */\n\n/**\n * Rounds a value up to the nearest \"nice\" number.\n * A nice number is a multiple of 10^floor(log10(value)).\n *\n * Examples: 547 → 600, 200 → 200, 1200 → 2000, 18 → 20, 5 → 5, -547 → -500\n */\nexport function niceNum(value: number): number {\n if (value === 0) return 0\n const absValue = Math.abs(value)\n const base = Math.pow(10, Math.floor(Math.log10(absValue)))\n const rounded = Math.ceil(absValue / base) * base\n return value < 0 ? -rounded : rounded\n}\n\n/**\n * Builds standard legend configuration for chart widgets\n *\n * @param params - Legend configuration parameters\n * @param params.hasLegend - Whether to show the legend\n * @param params.labelFormatter - Optional formatter for legend item names\n * @returns Legend configuration object\n */\nexport function buildLegendConfig({\n hasLegend,\n labelFormatter,\n}: {\n hasLegend: boolean\n labelFormatter?: (value: string | number) => string | number\n}): LegendComponentOption {\n return {\n show: hasLegend,\n icon: 'circle' as const,\n left: 0,\n bottom: 0,\n orient: 'horizontal',\n type: 'scroll',\n ...(labelFormatter && {\n formatter: (name: string) => String(labelFormatter(name)),\n }),\n }\n}\n\n/**\n * Builds standard grid configuration with legend-aware spacing\n *\n * @param hasLegend - Whether the chart has a legend\n * @param theme - MUI theme for spacing\n * @param additionalConfig - Additional grid configuration to merge\n * @returns Grid configuration object\n */\nexport function buildGridConfig(hasLegend: boolean, theme: Theme) {\n return {\n ...(!hasLegend && { bottom: parseInt(theme.spacing(3)) }),\n ...(hasLegend && { bottom: parseInt(theme.spacing(7)) }),\n }\n}\n\n/**\n * Creates a tooltip position calculator that handles overflow\n * Used by bar, histogram, and scatterplot widgets\n *\n * @param theme - MUI theme for spacing\n * @returns Tooltip position function\n */\nexport function createTooltipPositioner(theme: Theme) {\n return function (\n point: [number, number],\n _params: unknown,\n _dom: unknown,\n _rect: unknown,\n size: { contentSize: [number, number]; viewSize: [number, number] },\n ) {\n const position = { top: parseInt(theme.spacing(0.5)) } as Record<\n string,\n number\n >\n\n // Position tooltip left or right based on available space\n if (size.contentSize[0] < size.viewSize[0] - point[0]) {\n position.left = point[0]\n } else {\n position.right = size.viewSize[0] - point[0]\n }\n\n return position\n }\n}\n\n/**\n * Creates an axis label formatter for ECharts\n * Used to format numeric axis labels with a widget formatter\n *\n * @param formatter - Optional formatter function from widget config\n * @returns Axis label formatter function or undefined\n */\nexport function createAxisLabelFormatter(\n formatter?: (value: number) => string,\n) {\n if (!formatter) return undefined\n return (value: number) => formatter(value)\n}\n\n/**\n * Applies labelFormatter to xAxis configuration\n * Applies to any xAxis regardless of axis type (category, value, etc.)\n *\n * @param xAxis - Existing xAxis configuration\n * @param labelFormatter - Optional labelFormatter function from widget config\n * @returns Updated xAxis configuration\n */\nexport function applyXAxisFormatter(\n xAxis: unknown,\n formatter?: (value: string | number) => string | number,\n) {\n const xAxisIsObject = xAxis && !Array.isArray(xAxis)\n const xAxisTyped = xAxis as { type?: string; axisLabel?: unknown }\n\n const axisFormatter =\n formatter && xAxisIsObject\n ? (value: string | number) => String(formatter(value))\n : undefined\n\n return {\n ...xAxisTyped,\n axisLabel: {\n ...(typeof xAxisTyped.axisLabel === 'object' && xAxisTyped.axisLabel\n ? xAxisTyped.axisLabel\n : {}),\n formatter: axisFormatter,\n },\n }\n}\n\n/**\n * Applies formatter to yAxis configuration\n * Only applies to single axis objects (not arrays) with type 'value'\n *\n * @param yAxis - Existing yAxis configuration\n * @param formatter - Optional formatter function from widget config\n * @returns Updated yAxis configuration or undefined if no changes needed\n */\nexport function applyYAxisFormatter(\n yAxis: unknown,\n formatter?: (value: number) => string,\n) {\n let axisFormatter = createAxisLabelFormatter(formatter)\n\n const yAxisIsObject = yAxis && !Array.isArray(yAxis)\n const yAxisTyped = yAxis as { type?: string; axisLabel?: unknown }\n\n if (!yAxisIsObject || yAxisTyped.type !== 'value') {\n axisFormatter = undefined\n }\n\n return {\n ...yAxisTyped,\n axisLabel: {\n ...(typeof yAxisTyped.axisLabel === 'object' && yAxisTyped.axisLabel\n ? yAxisTyped.axisLabel\n : {}),\n formatter: axisFormatter,\n },\n }\n}\n\n/**\n * Creates a tooltip formatter for ECharts\n * Formats numeric values in tooltip using widget formatter\n * Handles both axis trigger (array) and item trigger (object) modes\n *\n * @param formatter - Optional formatter function from widget config\n * @returns Tooltip formatter function or undefined\n */\nexport function createTooltipFormatter(\n callback: (\n item: CallbackDataParams,\n items: CallbackDataParams[],\n ) => {\n name: string\n seriesName: string\n marker: string\n value: string | number\n },\n) {\n return (params: TopLevelFormatterParams) => {\n // Handle both array (axis trigger) and object (item trigger)\n const items = Array.isArray(params) ? params : [params]\n\n const tooltip = (name: string, callback: string) =>\n `<div style=\"margin: 0px 0 0;line-height:1;\">${name ? `<div style=\"font-size:11px;color:#FFFFFF;font-weight:400;line-height:1; margin-bottom: 10px\">${name}</div>` : ''}<div style=\"margin: 0;line-height:1;\">${callback}</div><div style=\"clear:both\"></div></div>`\n\n const values = items.map((item) => {\n const { name, seriesName, marker, value } = callback(item, items)\n return {\n name,\n seriesName,\n marker,\n value,\n }\n })\n\n const name = values[0]?.name ?? ''\n // Show margin if name exists or there are multiple items\n const showMargin = name || items.length > 1\n const marginStyle = showMargin\n ? 'margin: 10px 0 0;line-height:1;'\n : 'margin: 0;line-height:1;'\n\n const formattedValues = values.map(\n ({ seriesName, marker, value }) =>\n `<div style=\"${marginStyle}\"><div style=\"margin: 0px 0 0;line-height:1;\">${marker}${seriesName ? `<span style=\"font-size:11px;color:#FFFFFF;font-weight:400;margin-left:2px;margin-right:10px\">${seriesName}</span>` : ''}<span style=\"float:right;margin-left:10px;font-size:11px;color:#FFFFFF;font-weight:900\">${value}</span></div></div>`,\n )\n\n return tooltip(name, formattedValues.join(''))\n }\n}\n\n/**\n * Builds a series `label` config that applies formatter to the data value\n * extracted from a dataset row using ECharts encode/dimensionNames.\n *\n * Does not set `show` — labels remain hidden by default per ECharts defaults.\n *\n * @param formatter - Optional numeric value formatter\n * @param encodeKey - The encode dimension key to extract ('y' for vertical charts, 'x' for horizontal)\n */\nexport function buildSeriesLabelConfig(\n formatter?: (value: number) => string,\n encodeKey = 'y',\n): { label: { formatter: (params: CallbackDataParams) => string } } | object {\n if (!formatter) return {}\n\n return {\n label: {\n formatter: (params: CallbackDataParams) => {\n const encodeIndex = params.encode?.[encodeKey]?.[0]\n if (encodeIndex === undefined) return ''\n const dimName = params.dimensionNames?.[encodeIndex]\n const row = params.value as Record<string, string | number>\n const value = dimName ? row[dimName] : undefined\n return typeof value === 'number'\n ? formatter(value)\n : String(value ?? '')\n },\n },\n }\n}\n\n/**\n * Builds a series `label` config that applies formatter to a raw numeric value.\n * Used by histogram where series data is number[] (not datasets).\n *\n * Does not set `show` — labels remain hidden by default per ECharts defaults.\n *\n * @param formatter - Optional numeric value formatter\n */\nexport function buildHistogramSeriesLabelConfig(\n formatter?: (value: number) => string,\n): { label: { formatter: (params: CallbackDataParams) => string } } | object {\n if (!formatter) return {}\n\n return {\n label: {\n formatter: (params: CallbackDataParams) => {\n const value = params.value as number\n return typeof value === 'number'\n ? formatter(value)\n : String(value ?? '')\n },\n },\n }\n}\n"],"names":["niceNum","value","absValue","Math","abs","base","pow","floor","log10","rounded","ceil","buildLegendConfig","hasLegend","labelFormatter","show","icon","left","bottom","orient","type","formatter","name","String","buildGridConfig","theme","parseInt","spacing","createTooltipPositioner","point","_params","_dom","_rect","size","position","top","contentSize","viewSize","right","createAxisLabelFormatter","applyXAxisFormatter","xAxis","xAxisIsObject","Array","isArray","xAxisTyped","axisFormatter","undefined","axisLabel","applyYAxisFormatter","yAxis","yAxisIsObject","yAxisTyped","createTooltipFormatter","callback","params","items","tooltip","values","map","item","seriesName","marker","marginStyle","length","formattedValues","join","buildSeriesLabelConfig","encodeKey","label","encodeIndex","encode","dimName","dimensionNames","row","buildHistogramSeriesLabelConfig"],"mappings":"AAiBO,SAASA,EAAQC,GAAuB;AAC7C,MAAIA,MAAU,EAAG,QAAO;AACxB,QAAMC,IAAWC,KAAKC,IAAIH,CAAK,GACzBI,IAAOF,KAAKG,IAAI,IAAIH,KAAKI,MAAMJ,KAAKK,MAAMN,CAAQ,CAAC,CAAC,GACpDO,IAAUN,KAAKO,KAAKR,IAAWG,CAAI,IAAIA;AAC7C,SAAOJ,IAAQ,IAAI,CAACQ,IAAUA;AAChC;AAUO,SAASE,EAAkB;AAAA,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AAA,IAAAA,MACrB,eAAe6D,CAAW,iDAAiDD,CAAM,GAAGD,IAAa,gGAAgGA,CAAU,YAAY,EAAE,2FAA2F3D,CAAK,qBAC7T;AAEA,WAAOuD,EAAQnC,GAAM2C,EAAgBC,KAAK,EAAE,CAAC;AAAA,EAC/C;AACF;AAWO,SAASC,EACd9C,GACA+C,IAAY,KAC+D;AAC3E,SAAK/C,IAEE;AAAA,IACLgD,OAAO;AAAA,MACLhD,WAAWA,CAACkC,MAA+B;AACzC,cAAMe,IAAcf,EAAOgB,SAASH,CAAS,IAAI,CAAC;AAClD,YAAIE,MAAgBvB,OAAW,QAAO;AACtC,cAAMyB,IAAUjB,EAAOkB,iBAAiBH,CAAW,GAC7CI,IAAMnB,EAAOrD,OACbA,IAAQsE,IAAUE,EAAIF,CAAO,IAAIzB;AACvC,eAAO,OAAO7C,KAAU,WACpBmB,EAAUnB,CAAK,IACfqB,OAAOrB,KAAS,EAAE;AAAA,MACxB;AAAA,IAAA;AAAA,EACF,IAdqB,CAAA;AAgBzB;AAUO,SAASyE,EACdtD,GAC2E;AAC3E,SAAKA,IAEE;AAAA,IACLgD,OAAO;AAAA,MACLhD,WAAWA,CAACkC,MAA+B;AACzC,cAAMrD,IAAQqD,EAAOrD;AACrB,eAAO,OAAOA,KAAU,WACpBmB,EAAUnB,CAAK,IACfqB,OAAOrB,KAAS,EAAE;AAAA,MACxB;AAAA,IAAA;AAAA,EACF,IAVqB,CAAA;AAYzB;"}
@@ -1,45 +0,0 @@
1
- import { jsx as n } from "react/jsx-runtime";
2
- import { d as a } from "./exports-Cx-f6m6U.js";
3
- import { c as r } from "react/compiler-runtime";
4
- import { SvgIcon as i } from "@mui/material";
5
- import { ImageOutlined as c } from "@mui/icons-material";
6
- function m(o) {
7
- const e = r(2);
8
- let l;
9
- return e[0] !== o ? (l = /* @__PURE__ */ n(c, { ...o }), e[0] = o, e[1] = l) : l = e[1], l;
10
- }
11
- function s(o) {
12
- const e = r(3);
13
- let l;
14
- e[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (l = /* @__PURE__ */ n("path", { fill: "currentColor", d: "M4.313 11.25h2.25v-1.125H4.688v-2.25h1.875V6.75h-2.25a.726.726 0 0 0-.535.216.726.726 0 0 0-.216.534v3c0 .213.072.39.216.534a.726.726 0 0 0 .534.216Zm2.925 0h2.25c.212 0 .39-.072.534-.216a.726.726 0 0 0 .216-.534V9.375a.931.931 0 0 0-.216-.59.658.658 0 0 0-.534-.273H8.363v-.637h1.875V6.75h-2.25a.726.726 0 0 0-.535.216.726.726 0 0 0-.216.534v1.125c0 .213.072.403.216.572a.675.675 0 0 0 .534.253h1.126v.675H7.238v1.125Zm4.95 0h1.124l1.313-4.5H13.5l-.75 2.588L12 6.75h-1.125l1.313 4.5ZM3 15c-.413 0-.766-.147-1.06-.44a1.445 1.445 0 0 1-.44-1.06v-9c0-.412.147-.766.44-1.06C2.235 3.148 2.588 3 3 3h12c.412 0 .766.147 1.06.44.293.294.44.648.44 1.06v9c0 .412-.147.766-.44 1.06-.294.293-.647.44-1.06.44H3Zm0-1.5h12v-9H3v9Z" }), e[0] = l) : l = e[0];
15
- let t;
16
- return e[1] !== o ? (t = /* @__PURE__ */ n(i, { viewBox: "0 0 18 18", ...o, children: l }), e[1] = o, e[2] = t) : t = e[2], t;
17
- }
18
- function b(o) {
19
- return {
20
- id: "png",
21
- label: o.label ?? "PNG",
22
- icon: /* @__PURE__ */ n(m, { fontSize: "small" }),
23
- resolve: async () => {
24
- const e = o.getCaptureEl();
25
- if (!e)
26
- throw new Error("[widgets-v2] No PNG capture element available");
27
- const l = await a({
28
- element: e,
29
- pixelRatio: o.pixelRatio,
30
- backgroundColor: o.backgroundColor
31
- });
32
- return {
33
- url: l.url,
34
- filename: `${o.filename}.png`,
35
- revoke: l.revoke
36
- };
37
- }
38
- };
39
- }
40
- export {
41
- s as C,
42
- m as P,
43
- b
44
- };
45
- //# sourceMappingURL=png-item-BE9uEqlD.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"png-item-BE9uEqlD.js","sources":["../src/widgets-v2/actions/download/icons.tsx","../src/widgets-v2/actions/download/png-item.tsx"],"sourcesContent":["import { SvgIcon, type SvgIconProps } from '@mui/material'\nimport { ImageOutlined } from '@mui/icons-material'\n\n/**\n * Generic \"image\" glyph used for the PNG download item. Wraps MUI's\n * `ImageOutlined` so callers can swap it via the per-widget download\n * config's `icon` override without pulling MUI directly.\n */\nexport function PNGIcon(props: SvgIconProps) {\n return <ImageOutlined {...props} />\n}\n\n/**\n * \"CSV\" rectangle with the letters spelled inside — matches v1 visual and is\n * easier to recognise in a download menu than a generic table glyph.\n */\nexport function CSVIcon(props: SvgIconProps) {\n return (\n <SvgIcon viewBox='0 0 18 18' {...props}>\n <path\n fill='currentColor'\n d='M4.313 11.25h2.25v-1.125H4.688v-2.25h1.875V6.75h-2.25a.726.726 0 0 0-.535.216.726.726 0 0 0-.216.534v3c0 .213.072.39.216.534a.726.726 0 0 0 .534.216Zm2.925 0h2.25c.212 0 .39-.072.534-.216a.726.726 0 0 0 .216-.534V9.375a.931.931 0 0 0-.216-.59.658.658 0 0 0-.534-.273H8.363v-.637h1.875V6.75h-2.25a.726.726 0 0 0-.535.216.726.726 0 0 0-.216.534v1.125c0 .213.072.403.216.572a.675.675 0 0 0 .534.253h1.126v.675H7.238v1.125Zm4.95 0h1.124l1.313-4.5H13.5l-.75 2.588L12 6.75h-1.125l1.313 4.5ZM3 15c-.413 0-.766-.147-1.06-.44a1.445 1.445 0 0 1-.44-1.06v-9c0-.412.147-.766.44-1.06C2.235 3.148 2.588 3 3 3h12c.412 0 .766.147 1.06.44.293.294.44.648.44 1.06v9c0 .412-.147.766-.44 1.06-.294.293-.647.44-1.06.44H3Zm0-1.5h12v-9H3v9Z'\n />\n </SvgIcon>\n )\n}\n","import { downloadDOMToPNG } from './exports'\nimport { PNGIcon } from './icons'\nimport type { DownloadItem } from './types'\n\nexport interface BuildPngDownloadItemArgs {\n /** Base filename (without extension). The item appends `.png`. */\n filename: string\n /**\n * Reads the capture element to rasterise. Called at click time so the\n * download config doesn't capture a stale reference. Wire it to\n * `() => getCaptureEl(id)` from `widgets-v2/stores`.\n */\n getCaptureEl: () => HTMLElement | null\n /** html2canvas `scale`. Default 2. */\n pixelRatio?: number\n /** html2canvas `backgroundColor`. Default transparent (`null`). */\n backgroundColor?: string | null\n /** Override the menu label. Default `'PNG'`. */\n label?: string\n}\n\n/**\n * Builds the standard PNG `DownloadItem` used by every per-widget download\n * config. Centralised so the menu label, icon, error message, and filename\n * suffix stay consistent across widgets without each `create*DownloadConfig`\n * re-deriving the same shape.\n */\nexport function buildPngDownloadItem(\n args: BuildPngDownloadItemArgs,\n): DownloadItem {\n return {\n id: 'png',\n label: args.label ?? 'PNG',\n icon: <PNGIcon fontSize='small' />,\n resolve: async () => {\n const el = args.getCaptureEl()\n if (!el) {\n throw new Error('[widgets-v2] No PNG capture element available')\n }\n const handle = await downloadDOMToPNG({\n element: el,\n pixelRatio: args.pixelRatio,\n backgroundColor: args.backgroundColor,\n })\n return {\n url: handle.url,\n filename: `${args.filename}.png`,\n revoke: handle.revoke,\n }\n },\n }\n}\n"],"names":["PNGIcon","props","$","_c","t0","jsx","ImageOutlined","CSVIcon","Symbol","for","t1","SvgIcon","buildPngDownloadItem","args","id","label","icon","resolve","el","getCaptureEl","Error","handle","downloadDOMToPNG","element","pixelRatio","backgroundColor","url","filename","revoke"],"mappings":";;;;;AAQO,SAAAA,EAAAC,GAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AAAA,MAAAC;AAAA,SAAAF,SAAAD,KACEG,IAAA,gBAAAC,EAACC,GAAA,EAAa,GAAKL,EAAAA,CAAK,GAAIC,OAAAD,GAAAC,OAAAE,KAAAA,IAAAF,EAAA,CAAA,GAA5BE;AAA4B;AAO9B,SAAAG,EAAAN,GAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AAAA,MAAAC;AAAA,EAAAF,EAAA,CAAA,MAAAM,uBAAAC,IAA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