@automattic/charts 3.1.0 → 3.2.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.
- package/CHANGELOG.md +17 -0
- package/TOKENS.md +51 -12
- package/dist/index.cjs +307 -213
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +7 -1
- package/dist/index.d.cts +223 -127
- package/dist/index.d.ts +223 -127
- package/dist/index.js +306 -212
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/charts/area-chart/area-chart.tsx +2 -2
- package/src/charts/area-chart/test/area-chart.test.tsx +45 -0
- package/src/charts/bar-chart/bar-chart.tsx +36 -10
- package/src/charts/bar-chart/private/use-bar-chart-options.ts +19 -12
- package/src/charts/bar-chart/test/bar-chart-pointer-events.test.tsx +67 -0
- package/src/charts/bar-chart/test/bar-chart.test.tsx +101 -0
- package/src/charts/bar-list-chart/bar-list-chart.tsx +40 -2
- package/src/charts/bar-list-chart/test/bar-list-chart.test.tsx +38 -0
- package/src/charts/line-chart/line-chart.tsx +18 -3
- package/src/charts/line-chart/test/line-chart.test.tsx +98 -0
- package/src/charts/sparkline/sparkline.tsx +9 -3
- package/src/charts/sparkline/types.ts +1 -1
- package/src/components/tooltip/accessible-tooltip.tsx +32 -2
- package/src/components/tooltip/test/accessible-tooltip.test.tsx +68 -0
- package/src/hooks/test/use-xychart-theme-provider-override.test.tsx +4 -4
- package/src/hooks/test/use-xychart-theme-style-reads.test.tsx +17 -10
- package/src/hooks/test/use-xychart-theme.test.tsx +50 -5
- package/src/hooks/use-xychart-theme.ts +14 -20
- package/src/providers/chart-context/global-charts-provider.tsx +44 -33
- package/src/providers/chart-context/private/series-palette.ts +45 -0
- package/src/providers/chart-context/private/theme-override-vars.ts +46 -2
- package/src/providers/chart-context/private/with-catalog-pointers.ts +45 -2
- package/src/providers/chart-context/test/sparse-theme.test.ts +16 -2
- package/src/providers/chart-context/test/theme-override-vars.test.ts +65 -0
- package/src/providers/chart-context/test/use-global-charts-theme.test.tsx +8 -1
- package/src/providers/chart-context/test/with-catalog-pointers.test.ts +57 -0
- package/src/providers/chart-context/themes.ts +8 -3
- package/src/styles/chart-scope.scss +52 -24
- package/src/styles/test/chart-scope.test.ts +22 -9
- package/src/types.ts +148 -31
- package/src/utils/get-styles.ts +7 -1
package/src/types.ts
CHANGED
|
@@ -108,13 +108,31 @@ export type ChartType =
|
|
|
108
108
|
|
|
109
109
|
export type OrientationType = ValueOf< typeof Orientation >;
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Annotation styling.
|
|
113
|
+
*
|
|
114
|
+
* Each color member is deprecated on its own rather than the field it sits in: `radius`, `stroke` widths and the label geometry alongside them have no catalog role behind them and still apply.
|
|
115
|
+
*/
|
|
111
116
|
export type AnnotationStyles = {
|
|
112
|
-
circleSubject?: Omit< CircleSubjectProps, 'x' | 'y' > & {
|
|
117
|
+
circleSubject?: Omit< CircleSubjectProps, 'x' | 'y' | 'fill' > & {
|
|
118
|
+
/** @deprecated Set the `--a8c-charts-color-annotation` custom property inside the provider tree instead. See `TOKENS.md`. */
|
|
119
|
+
fill?: string;
|
|
120
|
+
};
|
|
113
121
|
lineSubject?: Omit< LineSubjectProps, 'x' | 'y' >;
|
|
114
|
-
connector?: Omit< ConnectorProps, 'x' | 'y' | 'dx' | 'dy'
|
|
115
|
-
|
|
122
|
+
connector?: Omit< ConnectorProps, 'x' | 'y' | 'dx' | 'dy' | 'stroke' > & {
|
|
123
|
+
/** @deprecated Set the `--a8c-charts-color-annotation` custom property inside the provider tree instead. See `TOKENS.md`. */
|
|
124
|
+
stroke?: ConnectorProps[ 'stroke' ];
|
|
125
|
+
};
|
|
126
|
+
label?: Omit<
|
|
127
|
+
LabelProps,
|
|
128
|
+
'title' | 'subtitle' | 'x' | 'y' | 'anchorLineStroke' | 'backgroundFill'
|
|
129
|
+
> & {
|
|
116
130
|
x?: number | 'start' | 'end';
|
|
117
131
|
y?: number | 'start' | 'end';
|
|
132
|
+
/** @deprecated Set the `--a8c-charts-color-annotation` custom property inside the provider tree instead. See `TOKENS.md`. */
|
|
133
|
+
anchorLineStroke?: LabelProps[ 'anchorLineStroke' ];
|
|
134
|
+
/** @deprecated Set the `--a8c-charts-color-surface` custom property inside the provider tree instead. See `TOKENS.md`. */
|
|
135
|
+
backgroundFill?: LabelProps[ 'backgroundFill' ];
|
|
118
136
|
};
|
|
119
137
|
};
|
|
120
138
|
|
|
@@ -305,7 +323,7 @@ export type DataPointPercentage = {
|
|
|
305
323
|
*/
|
|
306
324
|
valueDisplay?: string;
|
|
307
325
|
/**
|
|
308
|
-
* Color code for the segment, by default
|
|
326
|
+
* Color code for the segment, by default colors are taken from the theme but this property can overrides it
|
|
309
327
|
*/
|
|
310
328
|
color?: string;
|
|
311
329
|
/**
|
|
@@ -329,26 +347,67 @@ export type DataPointPercentageCalculated = DataPointPercentage & {
|
|
|
329
347
|
* Base theme configuration for chart components with optional properties
|
|
330
348
|
*/
|
|
331
349
|
export type ChartTheme = {
|
|
332
|
-
/**
|
|
333
|
-
|
|
334
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Background color for chart components.
|
|
352
|
+
*
|
|
353
|
+
* Still resolved in JS — gradient stops, the glyph stroke and `GeoChart`'s Google Charts config each need a concrete string — but that is about where the value is *consumed*, not where it is *set*. `withCatalogPointers` parks a consumer's value in the catalog role and restores the pointer, so the field is only ever a carrier for `--a8c-charts-color-background`, and setting the role directly does the same job.
|
|
354
|
+
*
|
|
355
|
+
* Optional so the deprecation is actionable: a consumer writing a full theme literal can now stop setting it. `CompleteChartTheme` is `Required< ChartTheme >`, so `defaultTheme` must still carry one.
|
|
356
|
+
*
|
|
357
|
+
* @deprecated Set the `--a8c-charts-color-background` custom property inside the provider tree instead. See `TOKENS.md`.
|
|
358
|
+
*/
|
|
359
|
+
backgroundColor?: string;
|
|
360
|
+
/**
|
|
361
|
+
* Background color for labels.
|
|
362
|
+
*
|
|
363
|
+
* @deprecated Set the `--a8c-charts-color-label-background` custom property inside the provider tree instead. See `TOKENS.md`.
|
|
364
|
+
*/
|
|
335
365
|
labelBackgroundColor?: string;
|
|
336
|
-
/**
|
|
366
|
+
/**
|
|
367
|
+
* Text color for labels.
|
|
368
|
+
*
|
|
369
|
+
* @deprecated Set the `--a8c-charts-color-label-on-fill` custom property inside the provider tree instead. See `TOKENS.md`.
|
|
370
|
+
*/
|
|
337
371
|
labelTextColor?: string;
|
|
338
|
-
/**
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
372
|
+
/**
|
|
373
|
+
* Series palette seeds. Entry N publishes `--a8c-charts-color-series-{N+1}`; entries past the fifth are ignored.
|
|
374
|
+
*
|
|
375
|
+
* Optional so the deprecation is actionable: a consumer writing a full theme literal can now stop setting it. `CompleteChartTheme` is `Required< ChartTheme >`, so `defaultTheme` must still carry one.
|
|
376
|
+
*
|
|
377
|
+
* @deprecated Set the `--a8c-charts-color-series-1` … `-5` custom properties inside the provider tree instead, or `options.stroke` on a series for a single one. See `TOKENS.md`.
|
|
378
|
+
*/
|
|
379
|
+
colors?: string[];
|
|
380
|
+
/**
|
|
381
|
+
* Optional CSS styles for grid lines.
|
|
382
|
+
*
|
|
383
|
+
* `stroke` is deprecated on its own, not the whole field: `strokeWidth` has no CSS role behind it and still applies. The same shape is used for the other fields whose color moved to CSS — annotating the field itself would strike through the half that stays.
|
|
384
|
+
*/
|
|
385
|
+
gridStyles?: Omit< GridStyles, 'stroke' > & {
|
|
386
|
+
/** @deprecated Set the `--a8c-charts-color-grid` custom property inside the provider tree instead. See `TOKENS.md`. */
|
|
387
|
+
stroke?: GridStyles[ 'stroke' ];
|
|
388
|
+
};
|
|
342
389
|
/** Length of axis ticks in pixels */
|
|
343
390
|
tickLength: number;
|
|
344
|
-
/**
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Set `--a8c-charts-color-grid` for the gridlines.
|
|
393
|
+
*
|
|
394
|
+
* @deprecated Do not drop this field without replacing it. Nothing in this package consults it, but `buildChartTheme` seeds `y.left/right.axisLine.stroke` and `y.*.tickLine.stroke` from it, and `defaultTheme`'s empty string is the only thing leaving the y axis unpainted — deleting the field hands those a black `#222` instead. CHARTS-263 replaces it with visx's own `yAxisLineStyles`/`yTickLineStyles` and a pair of catalog roles.
|
|
395
|
+
*/
|
|
396
|
+
gridColor?: string;
|
|
397
|
+
/**
|
|
398
|
+
* @deprecated Paints nothing, and unlike `gridColor` is safe to delete: `buildChartTheme` seeds `x.*.axisLine.stroke` from it, but spreads `xAxisLineStyles` over the top and `defaultTheme` always carries that stroke. Charts follow the host's theme through the catalog rather than a dark-mode field of their own.
|
|
399
|
+
*/
|
|
400
|
+
gridColorDark?: string;
|
|
348
401
|
/** Styles for x-axis tick lines */
|
|
349
|
-
xTickLineStyles?: LineStyles
|
|
402
|
+
xTickLineStyles?: Omit< LineStyles, 'stroke' > & {
|
|
403
|
+
/** @deprecated Set the `--a8c-charts-color-tick` custom property inside the provider tree instead. See `TOKENS.md`. */
|
|
404
|
+
stroke?: LineStyles[ 'stroke' ];
|
|
405
|
+
};
|
|
350
406
|
/** Styles for x-axis line */
|
|
351
|
-
xAxisLineStyles?: LineStyles
|
|
407
|
+
xAxisLineStyles?: Omit< LineStyles, 'stroke' > & {
|
|
408
|
+
/** @deprecated Set the `--a8c-charts-color-axis` custom property inside the provider tree instead. See `TOKENS.md`. */
|
|
409
|
+
stroke?: LineStyles[ 'stroke' ];
|
|
410
|
+
};
|
|
352
411
|
/** Styles for series lines */
|
|
353
412
|
seriesLineStyles?: LineStyles[];
|
|
354
413
|
/** Array of render functions for glyphs */
|
|
@@ -357,19 +416,37 @@ export type ChartTheme = {
|
|
|
357
416
|
legend?: {
|
|
358
417
|
/** Styles for legend shapes */
|
|
359
418
|
shapeStyles?: Record< string, unknown >[];
|
|
360
|
-
/**
|
|
361
|
-
|
|
419
|
+
/**
|
|
420
|
+
* Styles for legend labels.
|
|
421
|
+
*
|
|
422
|
+
* `color` is deprecated on its own, not the whole field: everything else a consumer sets here — font size, weight, spacing — has no catalog role behind it and still applies.
|
|
423
|
+
*/
|
|
424
|
+
labelStyles?: Omit< CSSProperties, 'color' > & {
|
|
425
|
+
/** @deprecated Set the `--a8c-charts-color-label` custom property inside the provider tree instead. See `TOKENS.md`. */
|
|
426
|
+
color?: CSSProperties[ 'color' ];
|
|
427
|
+
};
|
|
362
428
|
/** Styles for legend container */
|
|
363
429
|
containerStyles?: CSSProperties;
|
|
364
430
|
};
|
|
365
|
-
/**
|
|
366
|
-
|
|
431
|
+
/**
|
|
432
|
+
* Styles for small SVG text (eg. axis tick labels), passed through to the XYChart theme.
|
|
433
|
+
*
|
|
434
|
+
* `fontFamily: 'inherit'` is load-bearing here — it overrides the font stack `buildChartTheme` injects inline on SVG `<text>` — so only `fill` is deprecated.
|
|
435
|
+
*/
|
|
436
|
+
svgLabelSmall?: Omit< TextProps, 'fill' > & {
|
|
437
|
+
/** @deprecated Set the `--a8c-charts-color-label-axis` custom property inside the provider tree instead, or `--a8c-charts-color-label` to move every label at once. See `TOKENS.md`. */
|
|
438
|
+
fill?: TextProps[ 'fill' ];
|
|
439
|
+
};
|
|
367
440
|
/** Styles for large SVG text (eg. axis titles), passed through to the XYChart theme. */
|
|
368
441
|
svgLabelBig?: TextProps;
|
|
369
442
|
annotationStyles?: AnnotationStyles;
|
|
370
443
|
/** GeoChart specific settings */
|
|
371
444
|
geoChart?: {
|
|
372
|
-
/**
|
|
445
|
+
/**
|
|
446
|
+
* Default fill color for a geo chart feature (e.g. country) with no data.
|
|
447
|
+
*
|
|
448
|
+
* @deprecated Set the `--a8c-charts-color-surface-secondary` custom property inside the provider tree instead. Google Charts still takes a resolved hex, but the value is read from the role. See `TOKENS.md`.
|
|
449
|
+
*/
|
|
373
450
|
featureFillColor?: string;
|
|
374
451
|
};
|
|
375
452
|
/** LeaderboardChart specific settings */
|
|
@@ -380,22 +457,50 @@ export type ChartTheme = {
|
|
|
380
457
|
columnGap?: number;
|
|
381
458
|
/** Spacing between label and progress bars */
|
|
382
459
|
labelSpacing?: GapSize;
|
|
383
|
-
/**
|
|
460
|
+
/**
|
|
461
|
+
* Primary color for current period bars.
|
|
462
|
+
*
|
|
463
|
+
* @deprecated Use the `primaryColor` prop on `LeaderboardChart` for one chart, or set `--a8c-charts-color-series-1` to move the palette this falls back to. See `TOKENS.md`.
|
|
464
|
+
*/
|
|
384
465
|
primaryColor?: string;
|
|
385
|
-
/**
|
|
466
|
+
/**
|
|
467
|
+
* Secondary color for comparison period bars.
|
|
468
|
+
*
|
|
469
|
+
* @deprecated Use the `secondaryColor` prop on `LeaderboardChart` for one chart, or set `--a8c-charts-color-series-2` to move the palette this falls back to. See `TOKENS.md`.
|
|
470
|
+
*/
|
|
386
471
|
secondaryColor?: string;
|
|
387
|
-
/**
|
|
472
|
+
/**
|
|
473
|
+
* Delta colors: [negative, neutral, positive].
|
|
474
|
+
*
|
|
475
|
+
* @deprecated Set the `--a8c-charts-color-trend-down`, `-trend-neutral` and `-trend-up` custom properties inside the provider tree instead. See `TOKENS.md`.
|
|
476
|
+
*/
|
|
388
477
|
deltaColors?: [ string, string, string ];
|
|
389
478
|
};
|
|
390
479
|
/** ConversionFunnelChart specific settings */
|
|
391
480
|
conversionFunnelChart?: {
|
|
392
|
-
/**
|
|
481
|
+
/**
|
|
482
|
+
* Primary color for funnel bars.
|
|
483
|
+
*
|
|
484
|
+
* @deprecated Set `--a8c-charts-color-series-1` to move the palette this falls back to. See `TOKENS.md`.
|
|
485
|
+
*/
|
|
393
486
|
primaryColor?: string;
|
|
394
|
-
/**
|
|
487
|
+
/**
|
|
488
|
+
* Background color for chart container.
|
|
489
|
+
*
|
|
490
|
+
* @deprecated Set the `--a8c-charts-color-surface-secondary` custom property inside the provider tree instead. See `TOKENS.md`.
|
|
491
|
+
*/
|
|
395
492
|
backgroundColor?: string;
|
|
396
|
-
/**
|
|
493
|
+
/**
|
|
494
|
+
* Color for positive change indicators.
|
|
495
|
+
*
|
|
496
|
+
* @deprecated Set the `--a8c-charts-color-trend-up` custom property inside the provider tree instead. See `TOKENS.md`.
|
|
497
|
+
*/
|
|
397
498
|
positiveChangeColor?: string;
|
|
398
|
-
/**
|
|
499
|
+
/**
|
|
500
|
+
* Color for negative change indicators.
|
|
501
|
+
*
|
|
502
|
+
* @deprecated Set the `--a8c-charts-color-trend-down` custom property inside the provider tree instead. See `TOKENS.md`.
|
|
503
|
+
*/
|
|
399
504
|
negativeChangeColor?: string;
|
|
400
505
|
};
|
|
401
506
|
lineChart?: {
|
|
@@ -424,6 +529,8 @@ export type ChartTheme = {
|
|
|
424
529
|
/**
|
|
425
530
|
* Color the cell scale interpolates toward at the highest value (prop > this >
|
|
426
531
|
* palette `colors[0]`), fed to CSS `color-mix`. Omit to use the palette color.
|
|
532
|
+
*
|
|
533
|
+
* @deprecated Use the `primaryColor` prop on `HeatmapChart` for one chart, or set `--a8c-charts-color-series-1` to move the palette this falls back to. See `TOKENS.md`.
|
|
427
534
|
*/
|
|
428
535
|
primaryColor?: string;
|
|
429
536
|
/** Gap in px between cells in compact mode */
|
|
@@ -626,7 +733,7 @@ export type ChartLegendConfig< T = DataPoint | DataPointDate | LeaderboardEntry
|
|
|
626
733
|
/**
|
|
627
734
|
* Legend config for charts built from `SeriesData` (line, bar, area). Adds `collapseGroups` on top
|
|
628
735
|
* of the shared config. It is intentionally absent from the base `ChartLegendConfig` so point-based
|
|
629
|
-
* charts (pie, semi-circle pie) — whose data points carry `group` only to coordinate
|
|
736
|
+
* charts (pie, semi-circle pie) — whose data points carry `group` only to coordinate colors — can't
|
|
630
737
|
* set it.
|
|
631
738
|
*/
|
|
632
739
|
export type SeriesChartLegendConfig = ChartLegendConfig< SeriesData[] > & {
|
|
@@ -706,6 +813,16 @@ export type BaseChartProps< T = DataPoint | DataPointDate | LeaderboardEntry > =
|
|
|
706
813
|
* Callback function for pointer out event
|
|
707
814
|
*/
|
|
708
815
|
onPointerOut?: ( event: PointerEvent< Element > ) => void;
|
|
816
|
+
/**
|
|
817
|
+
* Callback for Enter or Space on the point keyboard navigation has selected:
|
|
818
|
+
* the keyboard counterpart of a click. `index` is the point's position in its
|
|
819
|
+
* series and `key` the series label.
|
|
820
|
+
*/
|
|
821
|
+
onDatumActivate?: ( params: {
|
|
822
|
+
datum: DataPoint | DataPointDate;
|
|
823
|
+
index: number;
|
|
824
|
+
key: string;
|
|
825
|
+
} ) => void;
|
|
709
826
|
/**
|
|
710
827
|
* Whether to show tooltips on hover. False by default.
|
|
711
828
|
*/
|
package/src/utils/get-styles.ts
CHANGED
|
@@ -50,9 +50,15 @@ export function getSeriesBarStyles(
|
|
|
50
50
|
/**
|
|
51
51
|
* Utility function to get stroke color for a series
|
|
52
52
|
*
|
|
53
|
+
* `themeColors` must already be resolved. `useGlobalChartsTheme().colors` is not: its entries are
|
|
54
|
+
* the palette's `var()` chains, which an SVG presentation attribute cannot resolve. Prefer
|
|
55
|
+
* `getElementStyles( { data, index } ).color` from
|
|
56
|
+
* `useGlobalChartsContext()`, which resolves at the chart's scope element and generates past the
|
|
57
|
+
* seeds.
|
|
58
|
+
*
|
|
53
59
|
* @param {SeriesData} seriesData - The series data containing styling options
|
|
54
60
|
* @param {number} index - The index of the series in the data array
|
|
55
|
-
* @param {string[]} themeColors -
|
|
61
|
+
* @param {string[]} themeColors - The resolved series palette
|
|
56
62
|
* @return {string} The stroke color for the series
|
|
57
63
|
*/
|
|
58
64
|
export function getSeriesStroke(
|