@carto/ps-react-ui 6.2.0 → 6.4.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 (91) hide show
  1. package/dist/actions-DyWNwvLu.js +1272 -0
  2. package/dist/actions-DyWNwvLu.js.map +1 -0
  3. package/dist/{category-DULnoxvk.js → category-BHBd5Pcc.js} +262 -245
  4. package/dist/category-BHBd5Pcc.js.map +1 -0
  5. package/dist/{option-builders-DQivvvbb.js → item-color-B7xkIpDZ.js} +26 -9
  6. package/dist/item-color-B7xkIpDZ.js.map +1 -0
  7. package/dist/scale-Bhx8HKEB.js +29 -0
  8. package/dist/scale-Bhx8HKEB.js.map +1 -0
  9. package/dist/types/widgets/actions/index.d.ts +1 -1
  10. package/dist/types/widgets/actions/relative-data/index.d.ts +1 -0
  11. package/dist/types/widgets/actions/relative-data/labels.d.ts +3 -0
  12. package/dist/types/widgets/actions/relative-data/relative-data.d.ts +16 -2
  13. package/dist/types/widgets/actions/relative-data/scale.d.ts +26 -0
  14. package/dist/types/widgets/actions/relative-data/style.d.ts +12 -0
  15. package/dist/types/widgets/bar/types.d.ts +6 -0
  16. package/dist/types/widgets/category/category.d.ts +2 -1
  17. package/dist/types/widgets/histogram/bins.d.ts +7 -0
  18. package/dist/types/widgets/histogram/download.d.ts +2 -2
  19. package/dist/types/widgets/histogram/index.d.ts +2 -1
  20. package/dist/types/widgets/histogram/options.d.ts +1 -1
  21. package/dist/types/widgets/histogram/transforms.d.ts +5 -4
  22. package/dist/types/widgets/histogram/types.d.ts +22 -5
  23. package/dist/types/widgets/index.d.ts +2 -2
  24. package/dist/types/widgets/pie/types.d.ts +6 -0
  25. package/dist/types/widgets/scatterplot/download.d.ts +2 -2
  26. package/dist/types/widgets/scatterplot/index.d.ts +2 -1
  27. package/dist/types/widgets/scatterplot/points.d.ts +7 -0
  28. package/dist/types/widgets/scatterplot/transforms.d.ts +4 -3
  29. package/dist/types/widgets/scatterplot/types.d.ts +21 -2
  30. package/dist/types/widgets/timeseries/types.d.ts +6 -0
  31. package/dist/types/widgets/utils/item-color.d.ts +26 -0
  32. package/dist/widgets/actions.js +1 -1
  33. package/dist/widgets/bar.js +87 -78
  34. package/dist/widgets/bar.js.map +1 -1
  35. package/dist/widgets/category.js +1 -1
  36. package/dist/widgets/histogram.js +129 -97
  37. package/dist/widgets/histogram.js.map +1 -1
  38. package/dist/widgets/pie.js +108 -89
  39. package/dist/widgets/pie.js.map +1 -1
  40. package/dist/widgets/scatterplot.js +147 -107
  41. package/dist/widgets/scatterplot.js.map +1 -1
  42. package/dist/widgets/timeseries.js +92 -83
  43. package/dist/widgets/timeseries.js.map +1 -1
  44. package/dist/widgets.js +2 -2
  45. package/dist/widgets.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/widgets/actions/fullscreen/fullscreen-store.test.tsx +77 -13
  48. package/src/widgets/actions/fullscreen/fullscreen.tsx +48 -5
  49. package/src/widgets/actions/index.ts +1 -0
  50. package/src/widgets/actions/relative-data/index.ts +1 -0
  51. package/src/widgets/actions/relative-data/labels.ts +6 -0
  52. package/src/widgets/actions/relative-data/relative-data.test.tsx +78 -1
  53. package/src/widgets/actions/relative-data/relative-data.tsx +137 -20
  54. package/src/widgets/actions/relative-data/scale.ts +48 -0
  55. package/src/widgets/actions/relative-data/style.ts +10 -0
  56. package/src/widgets/bar/options.test.ts +122 -0
  57. package/src/widgets/bar/options.ts +31 -16
  58. package/src/widgets/bar/types.ts +6 -0
  59. package/src/widgets/category/category.relative-data.test.tsx +51 -63
  60. package/src/widgets/category/category.tsx +25 -11
  61. package/src/widgets/histogram/bins.ts +22 -0
  62. package/src/widgets/histogram/download.test.ts +10 -0
  63. package/src/widgets/histogram/download.ts +7 -3
  64. package/src/widgets/histogram/index.ts +3 -0
  65. package/src/widgets/histogram/options.test.ts +62 -0
  66. package/src/widgets/histogram/options.ts +44 -19
  67. package/src/widgets/histogram/transforms.test.ts +21 -7
  68. package/src/widgets/histogram/transforms.ts +26 -12
  69. package/src/widgets/histogram/types.ts +25 -5
  70. package/src/widgets/index.ts +7 -1
  71. package/src/widgets/pie/options.test.ts +91 -0
  72. package/src/widgets/pie/options.ts +50 -20
  73. package/src/widgets/pie/types.ts +6 -0
  74. package/src/widgets/scatterplot/download.test.ts +9 -0
  75. package/src/widgets/scatterplot/download.ts +5 -3
  76. package/src/widgets/scatterplot/index.ts +3 -0
  77. package/src/widgets/scatterplot/options.test.ts +90 -0
  78. package/src/widgets/scatterplot/options.ts +53 -15
  79. package/src/widgets/scatterplot/points.ts +35 -0
  80. package/src/widgets/scatterplot/transforms.test.ts +19 -0
  81. package/src/widgets/scatterplot/transforms.ts +23 -18
  82. package/src/widgets/scatterplot/types.ts +25 -2
  83. package/src/widgets/timeseries/options.test.ts +65 -0
  84. package/src/widgets/timeseries/options.ts +37 -16
  85. package/src/widgets/timeseries/types.ts +6 -0
  86. package/src/widgets/utils/item-color.test.ts +74 -0
  87. package/src/widgets/utils/item-color.ts +55 -0
  88. package/dist/actions-CueYrfVr.js +0 -1150
  89. package/dist/actions-CueYrfVr.js.map +0 -1
  90. package/dist/category-DULnoxvk.js.map +0 -1
  91. package/dist/option-builders-DQivvvbb.js.map +0 -1
@@ -0,0 +1,74 @@
1
+ import { describe, it, expect, vi } from 'vitest'
2
+ import { createTheme } from '@mui/material'
3
+ import type { CallbackDataParams } from 'echarts/types/dist/shared'
4
+ import { createItemColorResolver } from './item-color'
5
+
6
+ const theme = createTheme({ palette: { primary: { main: '#1976d2' } } })
7
+ const params = (dataIndex: number) =>
8
+ ({ dataIndex, color: '#fallback' }) as unknown as CallbackDataParams
9
+ const fallback = (p: CallbackDataParams) => p.color as string
10
+
11
+ describe('createItemColorResolver', () => {
12
+ it('uses the datum colour first', () => {
13
+ const resolve = createItemColorResolver({
14
+ theme,
15
+ datums: [{ color: '#00ff00' }],
16
+ template: { itemStyle: { color: '#123456' } },
17
+ fallback,
18
+ })
19
+ expect(resolve(params(0))).toBe('#00ff00')
20
+ })
21
+
22
+ it('uses a string template itemStyle.color when the datum has none', () => {
23
+ const resolve = createItemColorResolver({
24
+ theme,
25
+ datums: [{}, 3],
26
+ template: { itemStyle: { color: '#123456' } },
27
+ fallback,
28
+ })
29
+ expect(resolve(params(0))).toBe('#123456')
30
+ expect(resolve(params(1))).toBe('#123456')
31
+ })
32
+
33
+ it('calls a function template itemStyle.color with the ECharts params', () => {
34
+ const color = vi.fn(() => '#abcdef')
35
+ const resolve = createItemColorResolver({
36
+ theme,
37
+ datums: [{}],
38
+ template: { itemStyle: { color } },
39
+ fallback,
40
+ })
41
+ const p = params(0)
42
+ expect(resolve(p)).toBe('#abcdef')
43
+ expect(color).toHaveBeenCalledWith(p)
44
+ })
45
+
46
+ it('falls back when neither datum nor template give a colour', () => {
47
+ const resolve = createItemColorResolver({
48
+ theme,
49
+ datums: [{ value: 1 }],
50
+ template: { itemStyle: { color: () => undefined } },
51
+ fallback,
52
+ })
53
+ expect(resolve(params(0))).toBe('#fallback')
54
+ expect(resolve(params(5))).toBe('#fallback')
55
+ const noTemplate = createItemColorResolver({
56
+ theme,
57
+ datums: [],
58
+ template: undefined,
59
+ fallback,
60
+ })
61
+ expect(noTemplate(params(0))).toBe('#fallback')
62
+ })
63
+
64
+ it('resolves theme palette paths on datum and template colours', () => {
65
+ const resolve = createItemColorResolver({
66
+ theme,
67
+ datums: [{ color: 'primary.main' }, {}],
68
+ template: { itemStyle: { color: () => 'primary.main' } },
69
+ fallback,
70
+ })
71
+ expect(resolve(params(0))).toBe('#1976d2')
72
+ expect(resolve(params(1))).toBe('#1976d2')
73
+ })
74
+ })
@@ -0,0 +1,55 @@
1
+ import type { Theme } from '@mui/material'
2
+ import type { CallbackDataParams } from 'echarts/types/dist/shared'
3
+ import { resolveThemeColor } from './resolve-theme-color'
4
+
5
+ /** ECharts `itemStyle.color` callback, as emitted by the chart widgets. */
6
+ export type ItemColorCallback = (params: CallbackDataParams) => string
7
+
8
+ /**
9
+ * Builds the callback that resolves the **base** colour of every item of one
10
+ * series, before any selection dimming. Priority:
11
+ *
12
+ * 1. the datum's own `color` (`datums[params.dataIndex].color`);
13
+ * 2. the consumer's `template.itemStyle.color` (from `optionsOverride`):
14
+ * a string is used as is, a function is called with the ECharts params;
15
+ * 3. `fallback` — the widget's default (series colour / palette).
16
+ *
17
+ * The datum is looked up by `params.dataIndex` in the widget's own data
18
+ * rather than read off `params.data`, so it works whatever the dataset row
19
+ * shape is (object rows, `[label, count]` tuples, `[x, y]` tuples).
20
+ *
21
+ * Datum and template colours go through {@link resolveThemeColor}, same as
22
+ * per-series colours, so palette paths such as `'primary.main'` work.
23
+ */
24
+ export function createItemColorResolver({
25
+ theme,
26
+ datums,
27
+ template,
28
+ fallback,
29
+ }: {
30
+ theme: Theme
31
+ datums: readonly unknown[]
32
+ template: unknown
33
+ fallback: ItemColorCallback
34
+ }): ItemColorCallback {
35
+ const templateColor = (template as { itemStyle?: { color?: unknown } })
36
+ ?.itemStyle?.color
37
+ return (params) => {
38
+ const datumColor = readColor(datums[params.dataIndex])
39
+ if (datumColor) return resolveThemeColor(theme, datumColor)!
40
+ const custom =
41
+ typeof templateColor === 'function'
42
+ ? (templateColor as (p: CallbackDataParams) => unknown)(params)
43
+ : templateColor
44
+ if (typeof custom === 'string' && custom !== '') {
45
+ return resolveThemeColor(theme, custom)!
46
+ }
47
+ return fallback(params)
48
+ }
49
+ }
50
+
51
+ function readColor(datum: unknown): string | undefined {
52
+ if (datum == null || typeof datum !== 'object') return undefined
53
+ const color = (datum as { color?: unknown }).color
54
+ return typeof color === 'string' && color !== '' ? color : undefined
55
+ }