@automattic/charts 1.11.0 → 2.0.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 (39) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/TOKENS.md +19 -1
  3. package/dist/index.cjs +2196 -2711
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.css +23 -43
  6. package/dist/index.d.cts +72 -6
  7. package/dist/index.d.ts +72 -6
  8. package/dist/index.js +278 -792
  9. package/dist/index.js.map +1 -1
  10. package/package.json +5 -4
  11. package/src/charts/area-chart/area-chart.tsx +31 -10
  12. package/src/charts/area-chart/test/area-chart.test.tsx +102 -0
  13. package/src/charts/area-chart/types.ts +20 -6
  14. package/src/charts/bar-chart/bar-chart.tsx +33 -9
  15. package/src/charts/bar-chart/test/bar-chart.test.tsx +117 -0
  16. package/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +7 -7
  17. package/src/charts/line-chart/line-chart.module.scss +3 -3
  18. package/src/charts/line-chart/line-chart.tsx +43 -7
  19. package/src/charts/line-chart/test/line-chart.test.tsx +234 -5
  20. package/src/charts/line-chart/types.ts +14 -0
  21. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +1 -1
  22. package/src/charts/private/test/time-axis.test.ts +182 -0
  23. package/src/charts/private/time-axis.ts +84 -5
  24. package/src/charts/private/x-zoom/index.ts +1 -0
  25. package/src/charts/private/{test → x-zoom/test}/x-zoom.test.tsx +92 -4
  26. package/src/charts/private/x-zoom/x-zoom.module.scss +35 -0
  27. package/src/charts/private/{x-zoom.tsx → x-zoom/x-zoom.tsx} +44 -27
  28. package/src/components/legend/hooks/test/use-chart-legend-items.test.tsx +152 -0
  29. package/src/components/legend/hooks/use-chart-legend-items.ts +118 -16
  30. package/src/components/legend/private/base-legend.module.scss +1 -1
  31. package/src/components/legend/private/base-legend.tsx +21 -9
  32. package/src/components/legend/test/legend-config-types.test.tsx +32 -0
  33. package/src/components/legend/test/legend.test.tsx +121 -1
  34. package/src/components/legend/types.ts +6 -0
  35. package/src/components/tooltip/base-tooltip.module.scss +1 -1
  36. package/src/components/trend-indicator/trend-indicator.module.scss +1 -1
  37. package/src/index.ts +2 -0
  38. package/src/types.ts +31 -0
  39. package/src/charts/private/x-zoom.module.scss +0 -50
package/dist/index.css CHANGED
@@ -49,7 +49,7 @@
49
49
  }
50
50
 
51
51
  .a8ccharts-04TogW-legend-item-value {
52
- font-weight: var(--wpds-typography-font-weight-medium, 499);
52
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
53
53
  flex-shrink: 0;
54
54
  }
55
55
  .a8ccharts--zY0xG-tooltip {
@@ -58,7 +58,7 @@
58
58
  color: #fff;
59
59
  border-radius: var(--wpds-border-radius-md, 4px);
60
60
  font-size: var(--wpds-typography-font-size-md, 13px);
61
- box-shadow: var(--wpds-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005);
61
+ box-shadow: var(--a8c-charts-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005);
62
62
  pointer-events: none;
63
63
  position: absolute;
64
64
  transform: translate(-50%, -100%);
@@ -99,45 +99,25 @@
99
99
  min-width: 0;
100
100
  min-height: 0;
101
101
  }
102
- .a8ccharts-y6bXNq-x-zoom__selection {
103
- fill: #3858e929;
104
- stroke: #3858e9a6;
102
+ .a8ccharts-ur9dWW-x-zoom__selection {
103
+ fill: var(--a8c-charts-color-zoom-selection, var(--wpds-color-background-interactive-brand-strong, #3858e9));
104
+ fill-opacity: .16;
105
+ stroke: var(--a8c-charts-color-zoom-selection-stroke, var(--wpds-color-stroke-interactive-brand, #3858e9));
106
+ stroke-opacity: .65;
105
107
  stroke-width: var(--wpds-border-width-xs, 1px);
106
108
  pointer-events: none;
107
109
  }
108
110
 
109
- .a8ccharts-y6bXNq-x-zoom__reset {
111
+ .a8ccharts-ur9dWW-x-zoom__reset {
110
112
  top: var(--wpds-dimension-gap-sm, 8px);
111
113
  right: var(--wpds-dimension-gap-sm, 8px);
112
114
  z-index: 2;
113
- width: 28px;
114
- height: 28px;
115
- color: var(--wpds-color-foreground-content-neutral, #1e1e1e);
116
- border: var(--wpds-border-width-xs, 1px) solid #00000029;
117
- border-radius: var(--wpds-border-radius-md, 4px);
118
- cursor: pointer;
119
- box-shadow: var(--wpds-elevation-xs, 0 1px 1px 0 #00000008, 0 1px 2px 0 #00000005, 0 3px 3px 0 #00000005, 0 4px 4px 0 #00000003);
120
- background: #ffffffeb;
121
- justify-content: center;
122
- align-items: center;
123
- padding: 0;
124
- display: inline-flex;
115
+ box-shadow: var(--a8c-charts-elevation-xs, 0 1px 1px 0 #00000008, 0 1px 2px 0 #00000005, 0 3px 3px 0 #00000005, 0 4px 4px 0 #00000003);
125
116
  position: absolute;
126
117
  }
127
118
 
128
- .a8ccharts-y6bXNq-x-zoom__reset:hover {
129
- background: #fff;
130
- }
131
-
132
- .a8ccharts-y6bXNq-x-zoom__reset:focus-visible {
133
- outline: 2px solid var(--a8c-charts-color-focus, var(--wpds-color-stroke-focus, #3858e9));
134
- outline-offset: 1px;
135
- }
136
-
137
- .a8ccharts-y6bXNq-x-zoom__reset-icon {
138
- flex-shrink: 0;
139
- width: 16px;
140
- height: 16px;
119
+ .a8ccharts-ur9dWW-x-zoom__reset:not(:hover, :active, :focus) {
120
+ background-color: var(--a8c-charts-color-background, var(--wpds-color-background-surface-neutral-strong, #fff));
141
121
  }
142
122
  .a8ccharts-inuQka-line-chart {
143
123
  position: relative;
@@ -160,7 +140,7 @@
160
140
  }
161
141
 
162
142
  .a8ccharts-inuQka-line-chart__tooltip-date {
163
- font-weight: var(--wpds-typography-font-weight-medium, 499);
143
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
164
144
  padding-bottom: var(--wpds-dimension-padding-md, 12px);
165
145
  }
166
146
 
@@ -169,7 +149,7 @@
169
149
  }
170
150
 
171
151
  .a8ccharts-inuQka-line-chart__tooltip-label {
172
- font-weight: var(--wpds-typography-font-weight-medium, 499);
152
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
173
153
  padding-right: var(--wpds-dimension-padding-lg, 16px);
174
154
  }
175
155
 
@@ -200,7 +180,7 @@
200
180
  border-radius: var(--wpds-border-radius-md, 4px);
201
181
  min-width: 125px;
202
182
  font-size: var(--wpds-typography-font-size-md, 13px);
203
- box-shadow: var(--wpds-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005);
183
+ box-shadow: var(--a8c-charts-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005);
204
184
  margin: var(--wpds-dimension-gap-sm, 8px);
205
185
  visibility: hidden;
206
186
  border: none;
@@ -304,7 +284,7 @@
304
284
  text-overflow: ellipsis;
305
285
  font-size: var(--wpds-typography-font-size-xl, 18px);
306
286
  font-style: normal;
307
- font-weight: var(--wpds-typography-font-weight-medium, 499);
287
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
308
288
  line-height: var(--wpds-typography-line-height-sm, 20px);
309
289
  margin: 0;
310
290
  overflow: hidden;
@@ -314,7 +294,7 @@
314
294
  text-overflow: ellipsis;
315
295
  font-size: var(--wpds-typography-font-size-md, 13px);
316
296
  font-style: normal;
317
- font-weight: var(--wpds-typography-font-weight-medium, 499);
297
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
318
298
  line-height: var(--wpds-typography-line-height-sm, 20px);
319
299
  margin: 0;
320
300
  overflow: hidden;
@@ -343,7 +323,7 @@
343
323
  .a8ccharts-mGEVca-step-label {
344
324
  color: var(--a8c-charts-color-label-secondary, var(--wpds-color-foreground-content-neutral-weak, #707070));
345
325
  font-size: var(--wpds-typography-font-size-sm, 12px);
346
- font-weight: var(--wpds-typography-font-weight-regular, 400);
326
+ font-weight: var(--wpds-typography-font-weight-default, 400);
347
327
  line-height: var(--wpds-typography-line-height-xs, 16px);
348
328
  white-space: nowrap;
349
329
  text-overflow: ellipsis;
@@ -353,7 +333,7 @@
353
333
  .a8ccharts-mGEVca-step-rate {
354
334
  color: var(--a8c-charts-color-label, var(--wpds-color-foreground-content-neutral, #1e1e1e));
355
335
  font-size: var(--wpds-typography-font-size-md, 13px);
356
- font-weight: var(--wpds-typography-font-weight-medium, 499);
336
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
357
337
  line-height: var(--wpds-typography-line-height-xs, 16px);
358
338
  }
359
339
 
@@ -387,14 +367,14 @@
387
367
  background: var(--a8c-charts-color-background, var(--wpds-color-background-surface-neutral-strong, #fff));
388
368
  border-radius: var(--wpds-border-radius-md, 4px) !important;
389
369
  padding: var(--wpds-dimension-padding-md, 12px) !important;
390
- box-shadow: var(--wpds-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005) !important;
370
+ box-shadow: var(--a8c-charts-elevation-sm, 0 1px 2px 0 #0000000d, 0 2px 3px 0 #0000000a, 0 6px 6px 0 #00000008, 0 8px 8px 0 #00000005) !important;
391
371
  }
392
372
 
393
373
  .a8ccharts-mGEVca-tooltip-title {
394
374
  color: var(--a8c-charts-color-label, var(--wpds-color-foreground-content-neutral, #1e1e1e));
395
375
  font-size: var(--wpds-typography-font-size-sm, 12px);
396
376
  font-style: normal;
397
- font-weight: var(--wpds-typography-font-weight-regular, 400);
377
+ font-weight: var(--wpds-typography-font-weight-default, 400);
398
378
  line-height: var(--wpds-typography-line-height-xs, 16px);
399
379
  }
400
380
 
@@ -402,7 +382,7 @@
402
382
  color: var(--a8c-charts-color-label, var(--wpds-color-foreground-content-neutral, #1e1e1e));
403
383
  font-size: var(--wpds-typography-font-size-md, 13px);
404
384
  font-style: normal;
405
- font-weight: var(--wpds-typography-font-weight-medium, 499);
385
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
406
386
  line-height: var(--wpds-typography-line-height-sm, 20px);
407
387
  }
408
388
 
@@ -709,7 +689,7 @@
709
689
  }
710
690
 
711
691
  .a8ccharts-YtTOxW-pie-semi-circle-chart .a8ccharts-YtTOxW-label {
712
- font-weight: var(--wpds-typography-font-weight-medium, 499);
692
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
713
693
  font-size: var(--wpds-typography-font-size-lg, 16px);
714
694
  }
715
695
 
@@ -736,7 +716,7 @@
736
716
  }
737
717
  .a8ccharts-zR7F7G-trend-indicator {
738
718
  font-size: var(--wpds-typography-font-size-md, 13px);
739
- font-weight: var(--wpds-typography-font-weight-medium, 499);
719
+ font-weight: var(--wpds-typography-font-weight-emphasis, 499);
740
720
  align-items: center;
741
721
  gap: .125em;
742
722
  line-height: 1;
package/dist/index.d.cts CHANGED
@@ -347,6 +347,11 @@ type CompleteChartTheme = Required<ChartTheme> & {
347
347
  };
348
348
  heatmapChart: Omit<Required<NonNullable<ChartTheme['heatmapChart']>>, 'primaryColor'> & Pick<NonNullable<ChartTheme['heatmapChart']>, 'primaryColor'>;
349
349
  };
350
+ /**
351
+ * Bucket resolution of time-series data, as known by the caller (e.g. a
352
+ * granularity selector), for consumers that don't need to infer it.
353
+ */
354
+ type TickResolution = 'hour' | 'day' | 'week' | 'month' | 'year';
350
355
  type AxisOptions = {
351
356
  orientation?: OrientationType;
352
357
  numTicks?: number;
@@ -360,6 +365,15 @@ type AxisOptions = {
360
365
  labelClassName?: string;
361
366
  tickClassName?: string;
362
367
  tickFormat?: TickFormatter<ScaleInput<AxisScale>>;
368
+ /**
369
+ * Bucket resolution of the data on a time x-axis. When set, the automatic
370
+ * tick formatter derives tick formats from it directly instead of
371
+ * inferring the resolution from point spacing. The overall time span still
372
+ * constrains the choice — e.g. hourly buckets spanning more than a week
373
+ * get date ticks, since hour ticks would be unreadable at that span.
374
+ * Ignored when `tickFormat` is set.
375
+ */
376
+ tickResolution?: TickResolution;
363
377
  /**
364
378
  * Whether to display this axis. Defaults to true.
365
379
  */
@@ -481,6 +495,21 @@ type ChartLegendConfig<T = DataPoint | DataPointDate | LeaderboardEntry> = {
481
495
  */
482
496
  shapeStyles?: LegendShapeStyles;
483
497
  };
498
+ /**
499
+ * Legend config for charts built from `SeriesData` (line, bar, area). Adds `collapseGroups` on top
500
+ * of the shared config. It is intentionally absent from the base `ChartLegendConfig` so point-based
501
+ * charts (pie, semi-circle pie) — whose data points carry `group` only to coordinate colours — can't
502
+ * set it.
503
+ */
504
+ type SeriesChartLegendConfig = ChartLegendConfig<SeriesData[]> & {
505
+ /**
506
+ * Collapse series that share a `group` into a single legend item, labelled by the group's
507
+ * primary series (its first non-comparison member). Off by default, so every series keeps its
508
+ * own item. Combines with `interactive`: a collapsed item toggles every series in its group, an
509
+ * uncollapsed one toggles only its own.
510
+ */
511
+ collapseGroups?: boolean;
512
+ };
484
513
  /**
485
514
  * Base properties shared across all chart components
486
515
  */
@@ -644,6 +673,12 @@ type BaseLegendItem = {
644
673
  glyphSize?: number;
645
674
  renderGlyph?: <Datum extends object>(props: GlyphProps<Datum>) => ReactNode;
646
675
  shapeStyle?: CSSProperties & LineStyles$1;
676
+ /**
677
+ * The series labels this legend item controls. For a grouped item this is every series
678
+ * sharing the group (primary first); for a single series it is just its own label. Used by
679
+ * the interactive legend to toggle a whole group's visibility from one item.
680
+ */
681
+ seriesLabels?: string[];
647
682
  };
648
683
  //#endregion
649
684
  //#region src/components/legend/legend.d.ts
@@ -661,6 +696,11 @@ interface ChartLegendOptions {
661
696
  showValues?: boolean;
662
697
  legendValueDisplay?: LegendValueDisplay;
663
698
  legendShape?: LegendShape<SeriesData[], number>;
699
+ /**
700
+ * Collapse series that share a `group` into a single legend item, labelled by the group's
701
+ * primary series. Off by default, so every series gets its own item.
702
+ */
703
+ collapseGroups?: boolean;
664
704
  }
665
705
  /**
666
706
  * Hook to transform chart data into legend items
@@ -736,6 +776,10 @@ type RenderLineGlyphProps<Datum extends object> = GlyphProps<Datum> & {
736
776
  position?: 'start' | 'end';
737
777
  };
738
778
  interface LineChartProps extends BaseChartProps<SeriesData[]> {
779
+ /**
780
+ * Legend configuration. Supports `collapseGroups` on top of the shared options.
781
+ */
782
+ legend?: SeriesChartLegendConfig;
739
783
  withGradientFill: boolean;
740
784
  smoothing?: boolean;
741
785
  curveType?: CurveType;
@@ -755,6 +799,15 @@ interface LineChartProps extends BaseChartProps<SeriesData[]> {
755
799
  * button appears in the top-right of the chart while zoomed.
756
800
  */
757
801
  zoomable?: boolean;
802
+ /**
803
+ * Whether the Y axis rescales to fit only the visible series when series are
804
+ * hidden or shown through the interactive legend.
805
+ * Defaults to `true` (the pre-existing behaviour). Set to `false` to pin the Y
806
+ * axis to the full data extent so hiding series does not move the chart's
807
+ * baseline — useful for comparison charts. Matches `AreaChart`.
808
+ * @default true
809
+ */
810
+ rescaleYOnVisibilityChange?: boolean;
758
811
  children?: ReactNode;
759
812
  }
760
813
  type TooltipDatum = {
@@ -764,6 +817,10 @@ type TooltipDatum = {
764
817
  //#endregion
765
818
  //#region src/charts/area-chart/types.d.ts
766
819
  interface AreaChartProps extends BaseChartProps<SeriesData[]> {
820
+ /**
821
+ * Legend configuration. Supports `collapseGroups` on top of the shared options.
822
+ */
823
+ legend?: SeriesChartLegendConfig;
767
824
  /**
768
825
  * Whether series should be stacked on top of each other.
769
826
  * When false, series are rendered as overlapping filled areas.
@@ -814,13 +871,18 @@ interface AreaChartProps extends BaseChartProps<SeriesData[]> {
814
871
  */
815
872
  zoomable?: boolean;
816
873
  /**
817
- * When using an interactive legend, controls whether the Y axis rescales
818
- * to fit only the visible series. Defaults to `true`, matching the
819
- * intuitive default for LineChart and BarChart. Set to `false` to pin
820
- * the Y axis to the full data extent so toggling legend items off does
821
- * not move the chart's baseline.
874
+ * Whether the Y axis rescales to fit only the visible series when series are
875
+ * hidden or shown through the interactive legend.
876
+ * Defaults to `true`, matching LineChart. Set to `false` to pin the Y axis to
877
+ * the full data extent so hiding series does not move the chart's baseline.
822
878
  * @default true
823
879
  */
880
+ rescaleYOnVisibilityChange?: boolean;
881
+ /**
882
+ * @deprecated Use `rescaleYOnVisibilityChange`. The behaviour keys off series
883
+ * visibility changing, not specifically a legend toggle. Still honoured when
884
+ * `rescaleYOnVisibilityChange` is not set.
885
+ */
824
886
  rescaleYOnLegendToggle?: boolean;
825
887
  children?: ReactNode;
826
888
  }
@@ -859,6 +921,10 @@ declare const AreaChartResponsive: AreaChartResponsiveComponent;
859
921
  //#endregion
860
922
  //#region src/charts/bar-chart/bar-chart.d.ts
861
923
  interface BarChartProps extends BaseChartProps<SeriesData[]> {
924
+ /**
925
+ * Legend configuration. Supports `collapseGroups` on top of the shared options.
926
+ */
927
+ legend?: SeriesChartLegendConfig;
862
928
  renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
863
929
  orientation?: 'horizontal' | 'vertical';
864
930
  withPatterns?: boolean;
@@ -2008,5 +2074,5 @@ declare const useGlobalChartsTheme: () => CompleteChartTheme;
2008
2074
  */
2009
2075
  declare const defaultTheme: CompleteChartTheme;
2010
2076
  //#endregion
2011
- export { AccessibleTooltip, type AnnotationStyles, type ArcData, AreaChartResponsive as AreaChart, type AreaChartProps, AreaChart as AreaChartUnresponsive, type AxisOptions, BarChartResponsive as BarChart, type BarChartProps, BarChart as BarChartUnresponsive, BarListChartResponsive as BarListChart, type BarListChartProps, BarListChart as BarListChartUnresponsive, type BaseChartProps, type BaseLegendItem, type BaseLegendProps, BaseTooltip, type BaseTooltipProps, type CalendarHeatmapResult, type ChartLegendConfig, type ChartLegendOptions, type ChartTheme, type CompleteChartTheme, ConversionFunnelChartWithProvider as ConversionFunnelChart, type ConversionFunnelChartProps, type CurveType, type DataPoint, type DataPointDate, type DataPointPercentage, type EventHandlerParams, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartError, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, GlobalChartsProvider as ThemeProvider, type GoogleDataTableColumn, type GoogleDataTableColumnRoleType, type GoogleDataTableRow, type GradientConfig, type GradientStop, type GridProps, type GridStyles, type HeatmapCell, HeatmapChartResponsive as HeatmapChart, type HeatmapChartProps, HeatmapChart as HeatmapChartUnresponsive, type HeatmapColumn, type HeatmapTooltipData, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShape, type LegendShapeLabel, type LegendShapeRenderProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, type LineStyles, type MainMetricRenderProps, type MetricValueType, type MultipleDataPointsDate, type Optional, type OrientationType, PieChartResponsive as PieChart, type PieChartProps, type PieChartRenderTooltipParams, PieChart as PieChartUnresponsive, PieSemiCircleChartResponsive as PieSemiCircleChart, type PieSemiCircleChartProps, type PieSemiCircleChartRenderTooltipParams, PieSemiCircleChart as PieSemiCircleChartUnresponsive, type RenderLabelProps, type RenderLineGlyphProps, type RenderTooltipGlyphProps, type RenderTooltipParams, type RenderValueProps, type ScaleOptions, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, type XyChartTooltipProps, buildCalendarHeatmapData, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, mixHexColors, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, prefersLightText, relativeLuminance, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };
2077
+ export { AccessibleTooltip, type AnnotationStyles, type ArcData, AreaChartResponsive as AreaChart, type AreaChartProps, AreaChart as AreaChartUnresponsive, type AxisOptions, BarChartResponsive as BarChart, type BarChartProps, BarChart as BarChartUnresponsive, BarListChartResponsive as BarListChart, type BarListChartProps, BarListChart as BarListChartUnresponsive, type BaseChartProps, type BaseLegendItem, type BaseLegendProps, BaseTooltip, type BaseTooltipProps, type CalendarHeatmapResult, type ChartLegendConfig, type ChartLegendOptions, type ChartTheme, type CompleteChartTheme, ConversionFunnelChartWithProvider as ConversionFunnelChart, type ConversionFunnelChartProps, type CurveType, type DataPoint, type DataPointDate, type DataPointPercentage, type EventHandlerParams, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartError, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, GlobalChartsProvider as ThemeProvider, type GoogleDataTableColumn, type GoogleDataTableColumnRoleType, type GoogleDataTableRow, type GradientConfig, type GradientStop, type GridProps, type GridStyles, type HeatmapCell, HeatmapChartResponsive as HeatmapChart, type HeatmapChartProps, HeatmapChart as HeatmapChartUnresponsive, type HeatmapColumn, type HeatmapTooltipData, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShape, type LegendShapeLabel, type LegendShapeRenderProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, type LineStyles, type MainMetricRenderProps, type MetricValueType, type MultipleDataPointsDate, type Optional, type OrientationType, PieChartResponsive as PieChart, type PieChartProps, type PieChartRenderTooltipParams, PieChart as PieChartUnresponsive, PieSemiCircleChartResponsive as PieSemiCircleChart, type PieSemiCircleChartProps, type PieSemiCircleChartRenderTooltipParams, PieSemiCircleChart as PieSemiCircleChartUnresponsive, type RenderLabelProps, type RenderLineGlyphProps, type RenderTooltipGlyphProps, type RenderTooltipParams, type RenderValueProps, type ScaleOptions, type SeriesChartLegendConfig, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, type TickResolution, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, type XyChartTooltipProps, buildCalendarHeatmapData, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, mixHexColors, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, prefersLightText, relativeLuminance, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };
2012
2078
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -347,6 +347,11 @@ type CompleteChartTheme = Required<ChartTheme> & {
347
347
  };
348
348
  heatmapChart: Omit<Required<NonNullable<ChartTheme['heatmapChart']>>, 'primaryColor'> & Pick<NonNullable<ChartTheme['heatmapChart']>, 'primaryColor'>;
349
349
  };
350
+ /**
351
+ * Bucket resolution of time-series data, as known by the caller (e.g. a
352
+ * granularity selector), for consumers that don't need to infer it.
353
+ */
354
+ type TickResolution = 'hour' | 'day' | 'week' | 'month' | 'year';
350
355
  type AxisOptions = {
351
356
  orientation?: OrientationType;
352
357
  numTicks?: number;
@@ -360,6 +365,15 @@ type AxisOptions = {
360
365
  labelClassName?: string;
361
366
  tickClassName?: string;
362
367
  tickFormat?: TickFormatter<ScaleInput<AxisScale>>;
368
+ /**
369
+ * Bucket resolution of the data on a time x-axis. When set, the automatic
370
+ * tick formatter derives tick formats from it directly instead of
371
+ * inferring the resolution from point spacing. The overall time span still
372
+ * constrains the choice — e.g. hourly buckets spanning more than a week
373
+ * get date ticks, since hour ticks would be unreadable at that span.
374
+ * Ignored when `tickFormat` is set.
375
+ */
376
+ tickResolution?: TickResolution;
363
377
  /**
364
378
  * Whether to display this axis. Defaults to true.
365
379
  */
@@ -481,6 +495,21 @@ type ChartLegendConfig<T = DataPoint | DataPointDate | LeaderboardEntry> = {
481
495
  */
482
496
  shapeStyles?: LegendShapeStyles;
483
497
  };
498
+ /**
499
+ * Legend config for charts built from `SeriesData` (line, bar, area). Adds `collapseGroups` on top
500
+ * of the shared config. It is intentionally absent from the base `ChartLegendConfig` so point-based
501
+ * charts (pie, semi-circle pie) — whose data points carry `group` only to coordinate colours — can't
502
+ * set it.
503
+ */
504
+ type SeriesChartLegendConfig = ChartLegendConfig<SeriesData[]> & {
505
+ /**
506
+ * Collapse series that share a `group` into a single legend item, labelled by the group's
507
+ * primary series (its first non-comparison member). Off by default, so every series keeps its
508
+ * own item. Combines with `interactive`: a collapsed item toggles every series in its group, an
509
+ * uncollapsed one toggles only its own.
510
+ */
511
+ collapseGroups?: boolean;
512
+ };
484
513
  /**
485
514
  * Base properties shared across all chart components
486
515
  */
@@ -644,6 +673,12 @@ type BaseLegendItem = {
644
673
  glyphSize?: number;
645
674
  renderGlyph?: <Datum extends object>(props: GlyphProps<Datum>) => ReactNode;
646
675
  shapeStyle?: CSSProperties & LineStyles$1;
676
+ /**
677
+ * The series labels this legend item controls. For a grouped item this is every series
678
+ * sharing the group (primary first); for a single series it is just its own label. Used by
679
+ * the interactive legend to toggle a whole group's visibility from one item.
680
+ */
681
+ seriesLabels?: string[];
647
682
  };
648
683
  //#endregion
649
684
  //#region src/components/legend/legend.d.ts
@@ -661,6 +696,11 @@ interface ChartLegendOptions {
661
696
  showValues?: boolean;
662
697
  legendValueDisplay?: LegendValueDisplay;
663
698
  legendShape?: LegendShape<SeriesData[], number>;
699
+ /**
700
+ * Collapse series that share a `group` into a single legend item, labelled by the group's
701
+ * primary series. Off by default, so every series gets its own item.
702
+ */
703
+ collapseGroups?: boolean;
664
704
  }
665
705
  /**
666
706
  * Hook to transform chart data into legend items
@@ -736,6 +776,10 @@ type RenderLineGlyphProps<Datum extends object> = GlyphProps<Datum> & {
736
776
  position?: 'start' | 'end';
737
777
  };
738
778
  interface LineChartProps extends BaseChartProps<SeriesData[]> {
779
+ /**
780
+ * Legend configuration. Supports `collapseGroups` on top of the shared options.
781
+ */
782
+ legend?: SeriesChartLegendConfig;
739
783
  withGradientFill: boolean;
740
784
  smoothing?: boolean;
741
785
  curveType?: CurveType;
@@ -755,6 +799,15 @@ interface LineChartProps extends BaseChartProps<SeriesData[]> {
755
799
  * button appears in the top-right of the chart while zoomed.
756
800
  */
757
801
  zoomable?: boolean;
802
+ /**
803
+ * Whether the Y axis rescales to fit only the visible series when series are
804
+ * hidden or shown through the interactive legend.
805
+ * Defaults to `true` (the pre-existing behaviour). Set to `false` to pin the Y
806
+ * axis to the full data extent so hiding series does not move the chart's
807
+ * baseline — useful for comparison charts. Matches `AreaChart`.
808
+ * @default true
809
+ */
810
+ rescaleYOnVisibilityChange?: boolean;
758
811
  children?: ReactNode;
759
812
  }
760
813
  type TooltipDatum = {
@@ -764,6 +817,10 @@ type TooltipDatum = {
764
817
  //#endregion
765
818
  //#region src/charts/area-chart/types.d.ts
766
819
  interface AreaChartProps extends BaseChartProps<SeriesData[]> {
820
+ /**
821
+ * Legend configuration. Supports `collapseGroups` on top of the shared options.
822
+ */
823
+ legend?: SeriesChartLegendConfig;
767
824
  /**
768
825
  * Whether series should be stacked on top of each other.
769
826
  * When false, series are rendered as overlapping filled areas.
@@ -814,13 +871,18 @@ interface AreaChartProps extends BaseChartProps<SeriesData[]> {
814
871
  */
815
872
  zoomable?: boolean;
816
873
  /**
817
- * When using an interactive legend, controls whether the Y axis rescales
818
- * to fit only the visible series. Defaults to `true`, matching the
819
- * intuitive default for LineChart and BarChart. Set to `false` to pin
820
- * the Y axis to the full data extent so toggling legend items off does
821
- * not move the chart's baseline.
874
+ * Whether the Y axis rescales to fit only the visible series when series are
875
+ * hidden or shown through the interactive legend.
876
+ * Defaults to `true`, matching LineChart. Set to `false` to pin the Y axis to
877
+ * the full data extent so hiding series does not move the chart's baseline.
822
878
  * @default true
823
879
  */
880
+ rescaleYOnVisibilityChange?: boolean;
881
+ /**
882
+ * @deprecated Use `rescaleYOnVisibilityChange`. The behaviour keys off series
883
+ * visibility changing, not specifically a legend toggle. Still honoured when
884
+ * `rescaleYOnVisibilityChange` is not set.
885
+ */
824
886
  rescaleYOnLegendToggle?: boolean;
825
887
  children?: ReactNode;
826
888
  }
@@ -859,6 +921,10 @@ declare const AreaChartResponsive: AreaChartResponsiveComponent;
859
921
  //#endregion
860
922
  //#region src/charts/bar-chart/bar-chart.d.ts
861
923
  interface BarChartProps extends BaseChartProps<SeriesData[]> {
924
+ /**
925
+ * Legend configuration. Supports `collapseGroups` on top of the shared options.
926
+ */
927
+ legend?: SeriesChartLegendConfig;
862
928
  renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
863
929
  orientation?: 'horizontal' | 'vertical';
864
930
  withPatterns?: boolean;
@@ -2008,5 +2074,5 @@ declare const useGlobalChartsTheme: () => CompleteChartTheme;
2008
2074
  */
2009
2075
  declare const defaultTheme: CompleteChartTheme;
2010
2076
  //#endregion
2011
- export { AccessibleTooltip, type AnnotationStyles, type ArcData, AreaChartResponsive as AreaChart, type AreaChartProps, AreaChart as AreaChartUnresponsive, type AxisOptions, BarChartResponsive as BarChart, type BarChartProps, BarChart as BarChartUnresponsive, BarListChartResponsive as BarListChart, type BarListChartProps, BarListChart as BarListChartUnresponsive, type BaseChartProps, type BaseLegendItem, type BaseLegendProps, BaseTooltip, type BaseTooltipProps, type CalendarHeatmapResult, type ChartLegendConfig, type ChartLegendOptions, type ChartTheme, type CompleteChartTheme, ConversionFunnelChartWithProvider as ConversionFunnelChart, type ConversionFunnelChartProps, type CurveType, type DataPoint, type DataPointDate, type DataPointPercentage, type EventHandlerParams, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartError, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, GlobalChartsProvider as ThemeProvider, type GoogleDataTableColumn, type GoogleDataTableColumnRoleType, type GoogleDataTableRow, type GradientConfig, type GradientStop, type GridProps, type GridStyles, type HeatmapCell, HeatmapChartResponsive as HeatmapChart, type HeatmapChartProps, HeatmapChart as HeatmapChartUnresponsive, type HeatmapColumn, type HeatmapTooltipData, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShape, type LegendShapeLabel, type LegendShapeRenderProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, type LineStyles, type MainMetricRenderProps, type MetricValueType, type MultipleDataPointsDate, type Optional, type OrientationType, PieChartResponsive as PieChart, type PieChartProps, type PieChartRenderTooltipParams, PieChart as PieChartUnresponsive, PieSemiCircleChartResponsive as PieSemiCircleChart, type PieSemiCircleChartProps, type PieSemiCircleChartRenderTooltipParams, PieSemiCircleChart as PieSemiCircleChartUnresponsive, type RenderLabelProps, type RenderLineGlyphProps, type RenderTooltipGlyphProps, type RenderTooltipParams, type RenderValueProps, type ScaleOptions, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, type XyChartTooltipProps, buildCalendarHeatmapData, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, mixHexColors, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, prefersLightText, relativeLuminance, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };
2077
+ export { AccessibleTooltip, type AnnotationStyles, type ArcData, AreaChartResponsive as AreaChart, type AreaChartProps, AreaChart as AreaChartUnresponsive, type AxisOptions, BarChartResponsive as BarChart, type BarChartProps, BarChart as BarChartUnresponsive, BarListChartResponsive as BarListChart, type BarListChartProps, BarListChart as BarListChartUnresponsive, type BaseChartProps, type BaseLegendItem, type BaseLegendProps, BaseTooltip, type BaseTooltipProps, type CalendarHeatmapResult, type ChartLegendConfig, type ChartLegendOptions, type ChartTheme, type CompleteChartTheme, ConversionFunnelChartWithProvider as ConversionFunnelChart, type ConversionFunnelChartProps, type CurveType, type DataPoint, type DataPointDate, type DataPointPercentage, type EventHandlerParams, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartError, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, GlobalChartsProvider as ThemeProvider, type GoogleDataTableColumn, type GoogleDataTableColumnRoleType, type GoogleDataTableRow, type GradientConfig, type GradientStop, type GridProps, type GridStyles, type HeatmapCell, HeatmapChartResponsive as HeatmapChart, type HeatmapChartProps, HeatmapChart as HeatmapChartUnresponsive, type HeatmapColumn, type HeatmapTooltipData, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShape, type LegendShapeLabel, type LegendShapeRenderProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, type LineStyles, type MainMetricRenderProps, type MetricValueType, type MultipleDataPointsDate, type Optional, type OrientationType, PieChartResponsive as PieChart, type PieChartProps, type PieChartRenderTooltipParams, PieChart as PieChartUnresponsive, PieSemiCircleChartResponsive as PieSemiCircleChart, type PieSemiCircleChartProps, type PieSemiCircleChartRenderTooltipParams, PieSemiCircleChart as PieSemiCircleChartUnresponsive, type RenderLabelProps, type RenderLineGlyphProps, type RenderTooltipGlyphProps, type RenderTooltipParams, type RenderValueProps, type ScaleOptions, type SeriesChartLegendConfig, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, type TickResolution, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, type XyChartTooltipProps, buildCalendarHeatmapData, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, mixHexColors, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, prefersLightText, relativeLuminance, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };
2012
2078
  //# sourceMappingURL=index.d.ts.map