@carto/ps-react-ui 6.3.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 (46) 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/scale-Bhx8HKEB.js +29 -0
  6. package/dist/scale-Bhx8HKEB.js.map +1 -0
  7. package/dist/types/widgets/actions/index.d.ts +1 -1
  8. package/dist/types/widgets/actions/relative-data/index.d.ts +1 -0
  9. package/dist/types/widgets/actions/relative-data/labels.d.ts +3 -0
  10. package/dist/types/widgets/actions/relative-data/relative-data.d.ts +16 -2
  11. package/dist/types/widgets/actions/relative-data/scale.d.ts +26 -0
  12. package/dist/types/widgets/actions/relative-data/style.d.ts +12 -0
  13. package/dist/types/widgets/category/category.d.ts +2 -1
  14. package/dist/types/widgets/index.d.ts +1 -1
  15. package/dist/widgets/actions.js +1 -1
  16. package/dist/widgets/bar.js +80 -79
  17. package/dist/widgets/bar.js.map +1 -1
  18. package/dist/widgets/category.js +1 -1
  19. package/dist/widgets/histogram.js +104 -103
  20. package/dist/widgets/histogram.js.map +1 -1
  21. package/dist/widgets/scatterplot.js +116 -115
  22. package/dist/widgets/scatterplot.js.map +1 -1
  23. package/dist/widgets/timeseries.js +86 -85
  24. package/dist/widgets/timeseries.js.map +1 -1
  25. package/dist/widgets.js +2 -2
  26. package/dist/widgets.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/widgets/actions/index.ts +1 -0
  29. package/src/widgets/actions/relative-data/index.ts +1 -0
  30. package/src/widgets/actions/relative-data/labels.ts +6 -0
  31. package/src/widgets/actions/relative-data/relative-data.test.tsx +78 -1
  32. package/src/widgets/actions/relative-data/relative-data.tsx +137 -20
  33. package/src/widgets/actions/relative-data/scale.ts +48 -0
  34. package/src/widgets/actions/relative-data/style.ts +10 -0
  35. package/src/widgets/bar/options.test.ts +16 -0
  36. package/src/widgets/bar/options.ts +6 -2
  37. package/src/widgets/category/category.relative-data.test.tsx +51 -63
  38. package/src/widgets/category/category.tsx +25 -11
  39. package/src/widgets/histogram/options.ts +6 -2
  40. package/src/widgets/index.ts +1 -0
  41. package/src/widgets/scatterplot/options.test.ts +12 -0
  42. package/src/widgets/scatterplot/options.ts +18 -4
  43. package/src/widgets/timeseries/options.ts +6 -2
  44. package/dist/actions-CkxKe8-J.js +0 -1160
  45. package/dist/actions-CkxKe8-J.js.map +0 -1
  46. package/dist/category-DULnoxvk.js.map +0 -1
@@ -155,6 +155,7 @@ export type {
155
155
  ZoomToggleProps,
156
156
  BrushToggleProps,
157
157
  RelativeDataProps,
158
+ RelativeScale,
158
159
  DownloadProps,
159
160
  DownloadItem,
160
161
  DownloadContext,
@@ -213,6 +213,18 @@ describe('createScatterplotOptionFactory', () => {
213
213
  expect(out.yAxis.min).toBe(0)
214
214
  })
215
215
 
216
+ it("pins the y ends a config transform set (RelativeData 'total')", () => {
217
+ const merge = createScatterplotOptionFactory({ theme })
218
+ const out = merge({ yAxis: { min: -100, max: 100 } }, [
219
+ [
220
+ [1, 47],
221
+ [2, 3],
222
+ ],
223
+ ]) as { yAxis: { min: number; max: number } }
224
+ expect(out.yAxis.max).toBe(100)
225
+ expect(out.yAxis.min).toBe(0)
226
+ })
227
+
216
228
  it('always emits itemStyle.color as a callback (passthrough when no selection)', () => {
217
229
  const merge = createScatterplotOptionFactory({ theme })
218
230
  const out = merge({}, [[[1, 2]]]) as {
@@ -21,6 +21,7 @@ import type {
21
21
  ScatterplotItem,
22
22
  ScatterplotWidgetData,
23
23
  } from './types'
24
+ import { fixedAxisBounds } from '../actions/relative-data/scale'
24
25
 
25
26
  /**
26
27
  * Builds the **structural** ECharts option for a scatterplot widget — both
@@ -189,8 +190,12 @@ export function createScatterplotOptionFactory(
189
190
 
190
191
  const reactiveFormatter = ctx?.formatter
191
192
 
192
- const { niceMinX, niceMaxX, niceMinY, niceMaxY } =
193
- computeScatterBounds(seriesArr)
193
+ const { niceMinX, niceMaxX, niceMinY, niceMaxY } = computeScatterBounds(
194
+ seriesArr,
195
+ // A config transform (RelativeData's `'total'` scale) may pin the
196
+ // y ends; each applies only on the side the data reaches.
197
+ fixedAxisBounds(baseYAxis),
198
+ )
194
199
 
195
200
  // Dim non-selected points via `series.itemStyle.color`. The selection
196
201
  // key is `${seriesIndex}:${dataIndex}`; we read those off the params
@@ -410,6 +415,7 @@ function buildScatterTooltipFormatter(
410
415
 
411
416
  function computeScatterBounds(
412
417
  seriesArr: ScatterplotWidgetData<ScatterplotItem>,
418
+ fixedY: { min?: number; max?: number } = {},
413
419
  ): {
414
420
  niceMinX: number
415
421
  niceMaxX: number
@@ -439,8 +445,16 @@ function computeScatterBounds(
439
445
  // negative mins, and floor max=0 to 1 so the chart always has range.
440
446
  // Scatter can have free coordinates so we apply this per-axis.
441
447
  const niceMaxX = Number.isFinite(maxX) ? (maxX <= 0 ? 1 : niceNum(maxX)) : 1
442
- const niceMaxY = Number.isFinite(maxY) ? (maxY <= 0 ? 1 : niceNum(maxY)) : 1
448
+ const niceMaxY = Number.isFinite(maxY)
449
+ ? maxY <= 0
450
+ ? 1
451
+ : (fixedY.max ?? niceNum(maxY))
452
+ : 1
443
453
  const niceMinX = Number.isFinite(minX) ? (minX < 0 ? niceNum(minX) : 0) : 0
444
- const niceMinY = Number.isFinite(minY) ? (minY < 0 ? niceNum(minY) : 0) : 0
454
+ const niceMinY = Number.isFinite(minY)
455
+ ? minY < 0
456
+ ? (fixedY.min ?? niceNum(minY))
457
+ : 0
458
+ : 0
445
459
  return { niceMinX, niceMaxX, niceMinY, niceMaxY }
446
460
  }
@@ -20,6 +20,7 @@ import type {
20
20
  TimeseriesOptionsInput,
21
21
  TimeseriesWidgetData,
22
22
  } from './types'
23
+ import { fixedAxisBounds } from '../actions/relative-data/scale'
23
24
 
24
25
  /**
25
26
  * Builds the **structural** ECharts option for a timeseries widget —
@@ -188,6 +189,7 @@ export function createTimeseriesOptionFactory(
188
189
  typeof option.yAxis === 'object' && !Array.isArray(option.yAxis)
189
190
  ? option.yAxis
190
191
  : {}
192
+ const fixedY = fixedAxisBounds(baseYAxis)
191
193
  const baseGrid =
192
194
  typeof option.grid === 'object' && !Array.isArray(option.grid)
193
195
  ? option.grid
@@ -302,12 +304,14 @@ export function createTimeseriesOptionFactory(
302
304
  ...(dataZoomLayout ? { dataZoom: dataZoomLayout } : {}),
303
305
  yAxis: {
304
306
  ...baseYAxis,
307
+ // A config transform (RelativeData's `'total'` scale) may pin the
308
+ // ends; each applies only on the side the data reaches.
305
309
  min: (extent: { min: number }) => {
306
- niceMin = extent.min < 0 ? niceNum(extent.min) : 0
310
+ niceMin = extent.min < 0 ? (fixedY.min ?? niceNum(extent.min)) : 0
307
311
  return niceMin
308
312
  },
309
313
  max: (extent: { min: number; max: number }) => {
310
- niceMax = extent.max <= 0 ? 1 : niceNum(extent.max)
314
+ niceMax = extent.max <= 0 ? 1 : (fixedY.max ?? niceNum(extent.max))
311
315
  return niceMax
312
316
  },
313
317
  axisLabel: {