@automattic/charts 1.6.0 → 1.7.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 (33) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +2 -2
  3. package/dist/index.cjs +22 -9
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.css +6 -3
  6. package/dist/index.d.cts +103 -30
  7. package/dist/index.d.ts +106 -33
  8. package/dist/index.js +22 -9
  9. package/dist/index.js.map +1 -1
  10. package/package.json +22 -21
  11. package/src/charts/area-chart/types.ts +1 -1
  12. package/src/charts/bar-chart/bar-chart.tsx +1 -1
  13. package/src/charts/geo-chart/geo-chart.tsx +3 -1
  14. package/src/charts/leaderboard-chart/leaderboard-chart.module.scss +27 -14
  15. package/src/charts/leaderboard-chart/leaderboard-chart.tsx +7 -4
  16. package/src/charts/leaderboard-chart/test/leaderboard-chart.test.tsx +51 -4
  17. package/src/charts/line-chart/line-chart.tsx +1 -1
  18. package/src/charts/line-chart/private/line-chart-annotation-label-popover.tsx +18 -2
  19. package/src/charts/line-chart/private/line-chart-annotation.tsx +1 -1
  20. package/src/charts/line-chart/types.ts +1 -1
  21. package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +2 -2
  22. package/src/charts/private/chart-layout/chart-layout.tsx +1 -2
  23. package/src/charts/private/x-zoom.tsx +2 -2
  24. package/src/components/legend/hooks/use-chart-legend-items.ts +6 -2
  25. package/src/components/legend/legend.tsx +1 -2
  26. package/src/components/legend/utils/label-transform-factory.ts +1 -1
  27. package/src/components/tooltip/accessible-tooltip.tsx +2 -6
  28. package/src/index.ts +6 -5
  29. package/src/providers/chart-context/themes.ts +1 -1
  30. package/src/providers/chart-context/types.ts +7 -2
  31. package/src/types.ts +104 -11
  32. package/src/utils/get-styles.ts +1 -2
  33. package/src/visx/types.ts +30 -1
package/src/types.ts CHANGED
@@ -1,20 +1,102 @@
1
- import type { CircleSubjectProps } from '@visx/annotation/lib/components/CircleSubject';
2
- import type { ConnectorProps } from '@visx/annotation/lib/components/Connector';
3
- import type { LabelProps } from '@visx/annotation/lib/components/Label';
4
- import type { LineSubjectProps } from '@visx/annotation/lib/components/LineSubject';
1
+ import type {
2
+ CircleSubjectProps,
3
+ ConnectorProps,
4
+ LabelProps,
5
+ LineSubjectProps,
6
+ } from '@visx/annotation';
5
7
  import type { AxisScale, Orientation, TickFormatter, AxisRendererProps } from '@visx/axis';
6
- import type { LegendShape } from '@visx/legend/lib/types';
7
8
  import type { ScaleInput, ScaleType } from '@visx/scale';
8
- import type { TextProps } from '@visx/text/lib/Text';
9
+ import type { TextProps } from '@visx/text';
9
10
  import type { EventHandlerParams, GlyphProps, GridStyles, LineStyles } from '@visx/xychart';
10
- import type { GapSize } from '@wordpress/theme';
11
- import type { CSSProperties, MouseEvent, PointerEvent, ReactNode } from 'react';
12
- import type { GoogleDataTableColumn, GoogleDataTableRow } from 'react-google-charts';
11
+ import type {
12
+ ComponentClass,
13
+ CSSProperties,
14
+ FC,
15
+ MouseEvent,
16
+ PointerEvent,
17
+ ReactElement,
18
+ ReactNode,
19
+ } from 'react';
13
20
 
14
21
  type ValueOf< T > = T[ keyof T ];
15
22
 
16
23
  export type Optional< T, K extends keyof T > = Pick< Partial< T >, K > & Omit< T, K >;
17
24
 
25
+ /**
26
+ * Mirrors the WordPress Design System gap token scale used by the WordPress UI Stack.
27
+ */
28
+ export type GapSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl';
29
+
30
+ export type LegendShapeLabel< Data, Output, ExtraAttributes = object > = {
31
+ datum: Data;
32
+ index: number;
33
+ text: string;
34
+ value?: Output;
35
+ } & ExtraAttributes;
36
+
37
+ export type LegendShapeRenderProps< Data, Output > = {
38
+ width?: string | number;
39
+ height?: string | number;
40
+ label: LegendShapeLabel< Data, Output >;
41
+ item: Data;
42
+ itemIndex: number;
43
+ fill?: string;
44
+ size?: string | number;
45
+ style?: CSSProperties;
46
+ };
47
+
48
+ export type LegendShape< Data, Output > =
49
+ | 'rect'
50
+ | 'circle'
51
+ | 'line'
52
+ | FC< LegendShapeRenderProps< Data, Output > >
53
+ | ComponentClass< LegendShapeRenderProps< Data, Output > >;
54
+
55
+ export type GoogleDataTableColumnType =
56
+ | 'string'
57
+ | 'number'
58
+ | 'boolean'
59
+ | 'date'
60
+ | 'datetime'
61
+ | 'timeofday';
62
+
63
+ export enum GoogleDataTableColumnRoleType {
64
+ annotation = 'annotation',
65
+ annotationText = 'annotationText',
66
+ certainty = 'certainty',
67
+ emphasis = 'emphasis',
68
+ interval = 'interval',
69
+ scope = 'scope',
70
+ style = 'style',
71
+ tooltip = 'tooltip',
72
+ domain = 'domain',
73
+ }
74
+
75
+ export type GoogleDataTableColumn =
76
+ | {
77
+ type: GoogleDataTableColumnType;
78
+ label?: string;
79
+ role?: GoogleDataTableColumnRoleType;
80
+ pattern?: string;
81
+ p?: Record< string, unknown >;
82
+ id?: string;
83
+ }
84
+ | string;
85
+
86
+ export type GoogleDataTableCell =
87
+ | {
88
+ v?: unknown;
89
+ f?: string;
90
+ p?: Record< string, unknown >;
91
+ }
92
+ | string
93
+ | number
94
+ | boolean
95
+ | Date
96
+ | null;
97
+
98
+ export type GoogleDataTableRow = GoogleDataTableCell[];
99
+
18
100
  export type ChartType =
19
101
  | 'area'
20
102
  | 'bar'
@@ -101,7 +183,7 @@ export type LeaderboardEntry = {
101
183
  /**
102
184
  * Human-readable name (e.g., 'Direct') or a JSX element (e.g., <h4>Direct</h4>)
103
185
  */
104
- label: string | JSX.Element;
186
+ label: string | ReactElement;
105
187
 
106
188
  /**
107
189
  * Value of the entry
@@ -146,6 +228,17 @@ export type LeaderboardEntry = {
146
228
  * never both, since interactive elements cannot be nested in HTML.
147
229
  */
148
230
  onClick?: ( event: MouseEvent< HTMLButtonElement > ) => void;
231
+
232
+ /**
233
+ * Optional accessible name for the interactive row's `<button>`. Only applies
234
+ * when `onClick` is set — without it the row renders as a Fragment with no
235
+ * element to receive `aria-label`. By default the button derives its name from
236
+ * its rendered content (label text plus the formatted value), which is the
237
+ * right outcome for plain-text labels. Set this when the `label` is JSX whose
238
+ * text content does not yield a clean name on its own — e.g. an image-only
239
+ * label — to give assistive tech a deterministic, human-readable name.
240
+ */
241
+ ariaLabel?: string;
149
242
  };
150
243
 
151
244
  export type GradientStop = {
@@ -273,7 +366,7 @@ export type ChartTheme = {
273
366
  /** Gap between columns in the leaderboard grid */
274
367
  columnGap?: number;
275
368
  /** Spacing between label and progress bars */
276
- labelSpacing?: number;
369
+ labelSpacing?: GapSize;
277
370
  /** Primary color for current period bars */
278
371
  primaryColor?: string;
279
372
  /** Secondary color for comparison period bars */
@@ -1,5 +1,4 @@
1
- import type { ChartTheme, SeriesData } from '../types';
2
- import type { LegendShape } from '@visx/legend/lib/types';
1
+ import type { ChartTheme, LegendShape, SeriesData } from '../types';
3
2
  import type { LineStyles } from '@visx/xychart';
4
3
 
5
4
  /**
package/src/visx/types.ts CHANGED
@@ -1,2 +1,31 @@
1
- export type { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
1
+ import type { PickD3Scale } from '@visx/scale';
2
+ import type { TooltipProps as VisxTooltipProps, UseTooltipPortalOptions } from '@visx/tooltip';
3
+ import type { GlyphProps, TooltipContextType } from '@visx/xychart';
4
+ import type { ReactNode, SVGProps } from 'react';
5
+
6
+ export type RenderTooltipParams< Datum extends object > = TooltipContextType< Datum > & {
7
+ colorScale?: PickD3Scale< 'ordinal', string, string >;
8
+ };
9
+
10
+ export interface RenderTooltipGlyphProps< Datum extends object > extends GlyphProps< Datum > {
11
+ glyphStyle?: SVGProps< SVGCircleElement >;
12
+ isNearestDatum: boolean;
13
+ }
14
+
15
+ export type XyChartTooltipProps< Datum extends object > = {
16
+ renderTooltip: ( params: RenderTooltipParams< Datum > ) => ReactNode;
17
+ renderGlyph?: ( params: RenderTooltipGlyphProps< Datum > ) => ReactNode;
18
+ snapTooltipToDatumX?: boolean;
19
+ snapTooltipToDatumY?: boolean;
20
+ showVerticalCrosshair?: boolean;
21
+ showHorizontalCrosshair?: boolean;
22
+ showDatumGlyph?: boolean;
23
+ showSeriesGlyphs?: boolean;
24
+ verticalCrosshairStyle?: SVGProps< SVGLineElement >;
25
+ horizontalCrosshairStyle?: SVGProps< SVGLineElement >;
26
+ glyphStyle?: SVGProps< SVGCircleElement >;
27
+ resizeObserverPolyfill?: UseTooltipPortalOptions[ 'polyfill' ];
28
+ } & Omit< VisxTooltipProps, 'left' | 'top' | 'children' > &
29
+ Pick< UseTooltipPortalOptions, 'debounce' | 'detectBounds' | 'scroll' | 'zIndex' >;
30
+
2
31
  export type { LineStyles, GridStyles } from '@visx/xychart';