@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.
- package/CHANGELOG.md +9 -0
- package/README.md +2 -2
- package/dist/index.cjs +22 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +6 -3
- package/dist/index.d.cts +103 -30
- package/dist/index.d.ts +106 -33
- package/dist/index.js +22 -9
- package/dist/index.js.map +1 -1
- package/package.json +22 -21
- package/src/charts/area-chart/types.ts +1 -1
- package/src/charts/bar-chart/bar-chart.tsx +1 -1
- package/src/charts/geo-chart/geo-chart.tsx +3 -1
- package/src/charts/leaderboard-chart/leaderboard-chart.module.scss +27 -14
- package/src/charts/leaderboard-chart/leaderboard-chart.tsx +7 -4
- package/src/charts/leaderboard-chart/test/leaderboard-chart.test.tsx +51 -4
- package/src/charts/line-chart/line-chart.tsx +1 -1
- package/src/charts/line-chart/private/line-chart-annotation-label-popover.tsx +18 -2
- package/src/charts/line-chart/private/line-chart-annotation.tsx +1 -1
- package/src/charts/line-chart/types.ts +1 -1
- package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +2 -2
- package/src/charts/private/chart-layout/chart-layout.tsx +1 -2
- package/src/charts/private/x-zoom.tsx +2 -2
- package/src/components/legend/hooks/use-chart-legend-items.ts +6 -2
- package/src/components/legend/legend.tsx +1 -2
- package/src/components/legend/utils/label-transform-factory.ts +1 -1
- package/src/components/tooltip/accessible-tooltip.tsx +2 -6
- package/src/index.ts +6 -5
- package/src/providers/chart-context/themes.ts +1 -1
- package/src/providers/chart-context/types.ts +7 -2
- package/src/types.ts +104 -11
- package/src/utils/get-styles.ts +1 -2
- package/src/visx/types.ts +30 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/charts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Display charts within Automattic products.",
|
|
5
5
|
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/charts/#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -65,23 +65,23 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@automattic/number-formatters": "^1.2.4",
|
|
67
67
|
"@babel/runtime": "7.29.7",
|
|
68
|
-
"@react-spring/web": "
|
|
69
|
-
"@visx/annotation": "^
|
|
70
|
-
"@visx/axis": "^
|
|
71
|
-
"@visx/curve": "^
|
|
72
|
-
"@visx/event": "^
|
|
73
|
-
"@visx/gradient": "^
|
|
74
|
-
"@visx/grid": "^
|
|
75
|
-
"@visx/group": "^
|
|
76
|
-
"@visx/legend": "^
|
|
77
|
-
"@visx/pattern": "^
|
|
78
|
-
"@visx/responsive": "^
|
|
79
|
-
"@visx/scale": "^
|
|
80
|
-
"@visx/shape": "^
|
|
81
|
-
"@visx/text": "^
|
|
82
|
-
"@visx/tooltip": "^
|
|
83
|
-
"@visx/vendor": "^
|
|
84
|
-
"@visx/xychart": "^
|
|
68
|
+
"@react-spring/web": "10.1.1",
|
|
69
|
+
"@visx/annotation": "^4.0.0",
|
|
70
|
+
"@visx/axis": "^4.0.0",
|
|
71
|
+
"@visx/curve": "^4.0.0",
|
|
72
|
+
"@visx/event": "^4.0.0",
|
|
73
|
+
"@visx/gradient": "^4.0.0",
|
|
74
|
+
"@visx/grid": "^4.0.0",
|
|
75
|
+
"@visx/group": "^4.0.0",
|
|
76
|
+
"@visx/legend": "^4.0.0",
|
|
77
|
+
"@visx/pattern": "^4.0.0",
|
|
78
|
+
"@visx/responsive": "^4.0.0",
|
|
79
|
+
"@visx/scale": "^4.0.0",
|
|
80
|
+
"@visx/shape": "^4.0.0",
|
|
81
|
+
"@visx/text": "^4.0.0",
|
|
82
|
+
"@visx/tooltip": "^4.0.0",
|
|
83
|
+
"@visx/vendor": "^4.0.0",
|
|
84
|
+
"@visx/xychart": "^4.0.0",
|
|
85
85
|
"@wordpress/i18n": "^6.0.0",
|
|
86
86
|
"@wordpress/icons": "^13.0.0",
|
|
87
87
|
"@wordpress/theme": "0.15.1",
|
|
@@ -96,6 +96,7 @@
|
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@automattic/jetpack-webpack-config": "workspace:*",
|
|
99
|
+
"@babel/core": "^7.29.7",
|
|
99
100
|
"@storybook/addon-docs": "10.3.6",
|
|
100
101
|
"@storybook/react": "10.3.6",
|
|
101
102
|
"@testing-library/dom": "^10.0.0",
|
|
@@ -107,7 +108,7 @@
|
|
|
107
108
|
"@types/react": "18.3.28",
|
|
108
109
|
"@types/react-dom": "18.3.7",
|
|
109
110
|
"@typescript/native-preview": "7.0.0-dev.20260225.1",
|
|
110
|
-
"@visx/glyph": "
|
|
111
|
+
"@visx/glyph": "4.0.0",
|
|
111
112
|
"@wordpress/components": "35.0.1",
|
|
112
113
|
"@wordpress/element": "8.0.1",
|
|
113
114
|
"@wordpress/private-apis": "1.48.1",
|
|
@@ -124,8 +125,8 @@
|
|
|
124
125
|
"typescript": "5.9.3"
|
|
125
126
|
},
|
|
126
127
|
"peerDependencies": {
|
|
127
|
-
"react": "^
|
|
128
|
-
"react-dom": "^
|
|
128
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
129
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
129
130
|
},
|
|
130
131
|
"engines": {
|
|
131
132
|
"node": ">=20.11.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BaseChartProps, DataPointDate, SeriesData } from '../../types';
|
|
2
|
+
import type { RenderTooltipParams } from '../../visx/types';
|
|
2
3
|
import type { CurveType } from '../line-chart/types';
|
|
3
|
-
import type { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
4
4
|
import type { ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
export interface AreaChartProps extends BaseChartProps< SeriesData[] > {
|
|
@@ -29,8 +29,8 @@ import { withResponsive } from '../private/with-responsive';
|
|
|
29
29
|
import styles from './bar-chart.module.scss';
|
|
30
30
|
import { useBarChartOptions } from './private';
|
|
31
31
|
import type { BaseChartProps, DataPointDate, SeriesData, Optional } from '../../types';
|
|
32
|
+
import type { RenderTooltipParams } from '../../visx/types';
|
|
32
33
|
import type { ResponsiveConfig } from '../private/with-responsive';
|
|
33
|
-
import type { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
34
34
|
import type { FC, ReactNode, ComponentType } from 'react';
|
|
35
35
|
|
|
36
36
|
export interface BarChartProps extends BaseChartProps< SeriesData[] > {
|
|
@@ -5,7 +5,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
5
5
|
import { Stack } from '@wordpress/ui';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import { FC, useContext, useMemo } from 'react';
|
|
8
|
-
import { Chart
|
|
8
|
+
import { Chart } from 'react-google-charts';
|
|
9
9
|
/**
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
@@ -20,6 +20,8 @@ import { GeoChartProps } from './types';
|
|
|
20
20
|
const DEFAULT_FEATURE_FILL_COLOR = '#ffffff';
|
|
21
21
|
const DEFAULT_BACKGROUND_COLOR = '#ffffff';
|
|
22
22
|
|
|
23
|
+
type GoogleChartOptions = Record< string, unknown >;
|
|
24
|
+
|
|
23
25
|
/**
|
|
24
26
|
* Renders a geographical chart using Google Charts GeoChart to visualize data.
|
|
25
27
|
*
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
&.is-overlay {
|
|
32
32
|
grid-template: "overlap" 1fr / 1fr;
|
|
33
33
|
|
|
34
|
-
/* contains a single cell
|
|
34
|
+
/* contains a single cell called 'overlap' */
|
|
35
35
|
|
|
36
36
|
>* {
|
|
37
37
|
grid-area: overlap;
|
|
@@ -85,6 +85,8 @@
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
.interactiveRow {
|
|
88
|
+
--focus-ring-width: var(--wpds-border-width-focus, var(--wp-admin-border-width-focus, 2px));
|
|
89
|
+
|
|
88
90
|
display: grid;
|
|
89
91
|
grid-column: 1 / -1;
|
|
90
92
|
grid-template-columns: subgrid;
|
|
@@ -92,10 +94,13 @@
|
|
|
92
94
|
position: relative;
|
|
93
95
|
|
|
94
96
|
// Native button reset.
|
|
97
|
+
box-sizing: border-box;
|
|
95
98
|
appearance: none;
|
|
96
99
|
width: 100%;
|
|
97
100
|
margin: 0;
|
|
98
|
-
|
|
101
|
+
// Reserve a ring's worth of space on every edge so the inset focus outline
|
|
102
|
+
// hugs the row without the bar painting over it (see :focus-visible below).
|
|
103
|
+
padding: var(--focus-ring-width);
|
|
99
104
|
border: 0;
|
|
100
105
|
background: none;
|
|
101
106
|
color: inherit;
|
|
@@ -103,14 +108,15 @@
|
|
|
103
108
|
text-align: inherit;
|
|
104
109
|
cursor: pointer;
|
|
105
110
|
|
|
106
|
-
// On hover/focus the bar dims and its inline-end edge pulls back
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
111
|
+
// On hover/focus the bar dims and its inline-end edge pulls back while the
|
|
112
|
+
// value/delta slides toward the inline start to clear room for the chevron
|
|
113
|
+
// revealed at the inline-end edge. The value always slides the full inset
|
|
114
|
+
// (it must clear the chevron), but the bar pulls back in proportion to its
|
|
115
|
+
// length (see getBarWidth in leaderboard-chart.tsx): the full-length bar —
|
|
116
|
+
// the one that reaches the value — pulls back the whole inset to keep its
|
|
117
|
+
// gap, while shorter bars move proportionally less, down to ~0. The bar is
|
|
118
|
+
// a grid item aligned to the inline start, so its inset mirrors in RTL; the
|
|
119
|
+
// value slide is given an RTL override below. No row background.
|
|
114
120
|
.bar {
|
|
115
121
|
transition: opacity 0.15s ease, width 0.15s ease;
|
|
116
122
|
}
|
|
@@ -122,8 +128,8 @@
|
|
|
122
128
|
&:hover,
|
|
123
129
|
&:focus-visible {
|
|
124
130
|
|
|
125
|
-
// Fixed reserve for the chevron —
|
|
126
|
-
// (see leaderboard-chart.tsx)
|
|
131
|
+
// Fixed reserve for the chevron — the value slides by it in full, and the
|
|
132
|
+
// bar width inset (see leaderboard-chart.tsx) scales it by the bar's share.
|
|
127
133
|
--a8c--charts--leaderboard--bar--hover-inset: var(--wpds-dimension-gap-2xl, 32px);
|
|
128
134
|
|
|
129
135
|
.bar {
|
|
@@ -146,8 +152,15 @@
|
|
|
146
152
|
}
|
|
147
153
|
|
|
148
154
|
&:focus-visible {
|
|
149
|
-
|
|
150
|
-
outline
|
|
155
|
+
border-radius: var(--wpds-border-radius-sm, 2px);
|
|
156
|
+
outline:
|
|
157
|
+
var(--focus-ring-width) solid
|
|
158
|
+
var(--wpds-color-stroke-focus-brand, var(--wp-admin-theme-color, #3858e9));
|
|
159
|
+
// Inset by its own width so the outer edge hugs the row boundary: the
|
|
160
|
+
// outline then sits in the row's padding (also a ring width), clear of the
|
|
161
|
+
// bar, and stays inside the overflow:auto container that would clip an
|
|
162
|
+
// outset ring.
|
|
163
|
+
outline-offset: calc(-1 * var(--focus-ring-width));
|
|
151
164
|
}
|
|
152
165
|
}
|
|
153
166
|
|
|
@@ -54,16 +54,18 @@ const defaultDeltaFormatter = ( value: number ): string => {
|
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Build a bar's width. A hover-inset CSS variable (0 by default) is subtracted
|
|
57
|
-
*
|
|
58
|
-
*
|
|
57
|
+
* on hover, scaled by the bar's share so the pull-back is proportional to its
|
|
58
|
+
* length: the full-length (100%) bar — the one that reaches the value — pulls
|
|
59
|
+
* back the whole inset to keep its gap with the value, while shorter bars pull
|
|
60
|
+
* back proportionally less, down to ~0 for a very short bar.
|
|
59
61
|
*
|
|
60
62
|
* @param share - The bar's share of the row width, as a percentage.
|
|
61
63
|
* @return A CSS width value.
|
|
62
64
|
*/
|
|
63
65
|
const getBarWidth = ( share: number ): string =>
|
|
64
|
-
`calc(${ share }% - var(--a8c--charts--leaderboard--bar--hover-inset, 0px))`;
|
|
66
|
+
`calc(${ share }% - var(--a8c--charts--leaderboard--bar--hover-inset, 0px) * ${ share } / 100)`;
|
|
65
67
|
|
|
66
|
-
const BarLabel = ( { label }: { label:
|
|
68
|
+
const BarLabel = ( { label }: { label: LeaderboardEntry[ 'label' ] } ) => (
|
|
67
69
|
<>{ typeof label === 'string' ? <Text className={ styles.label }>{ label }</Text> : label }</>
|
|
68
70
|
);
|
|
69
71
|
|
|
@@ -376,6 +378,7 @@ const LeaderboardChartInternal: FC< LeaderboardChartProps > = ( {
|
|
|
376
378
|
type="button"
|
|
377
379
|
className={ styles.interactiveRow }
|
|
378
380
|
onClick={ entry.onClick }
|
|
381
|
+
aria-label={ entry.ariaLabel }
|
|
379
382
|
>
|
|
380
383
|
{ rowCells }
|
|
381
384
|
<Icon className={ styles.chevron } icon={ chevronRight } size={ 24 } />
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { render, screen
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
2
3
|
import LeaderboardChart from '../leaderboard-chart';
|
|
3
4
|
import type { LeaderboardEntry } from '../../../types';
|
|
4
5
|
|
|
@@ -375,20 +376,66 @@ describe( 'LeaderboardChart', () => {
|
|
|
375
376
|
expect( screen.getByRole( 'button' ).tagName ).toBe( 'BUTTON' );
|
|
376
377
|
} );
|
|
377
378
|
|
|
378
|
-
it( 'calls onClick when the row is clicked', () => {
|
|
379
|
+
it( 'calls onClick when the row is clicked', async () => {
|
|
380
|
+
const user = userEvent.setup();
|
|
379
381
|
const onClick = jest.fn();
|
|
380
382
|
render( <LeaderboardChart data={ [ { ...mockData[ 0 ], onClick } ] } /> );
|
|
381
|
-
|
|
382
|
-
fireEvent.click( screen.getByRole( 'button' ) );
|
|
383
|
+
await user.click( screen.getByRole( 'button' ) );
|
|
383
384
|
expect( onClick ).toHaveBeenCalledTimes( 1 );
|
|
384
385
|
} );
|
|
385
386
|
|
|
387
|
+
it( 'activates onClick via the keyboard (Enter and Space)', async () => {
|
|
388
|
+
const user = userEvent.setup();
|
|
389
|
+
const onClick = jest.fn();
|
|
390
|
+
render( <LeaderboardChart data={ [ { ...mockData[ 0 ], onClick } ] } /> );
|
|
391
|
+
|
|
392
|
+
await user.tab();
|
|
393
|
+
expect( screen.getByRole( 'button' ) ).toHaveFocus();
|
|
394
|
+
|
|
395
|
+
await user.keyboard( '[Enter]' );
|
|
396
|
+
await user.keyboard( '[Space]' );
|
|
397
|
+
expect( onClick ).toHaveBeenCalledTimes( 2 );
|
|
398
|
+
} );
|
|
399
|
+
|
|
386
400
|
it( 'gives the interactive row an accessible name from the label and value', () => {
|
|
387
401
|
render( <LeaderboardChart data={ [ { ...mockData[ 0 ], onClick: jest.fn() } ] } /> );
|
|
388
402
|
// mockData[0] label is 'Direct', currentValue 12500 → '12.5K'
|
|
389
403
|
expect( screen.getByRole( 'button' ) ).toHaveAccessibleName( /Direct.*12\.5K/ );
|
|
390
404
|
} );
|
|
391
405
|
|
|
406
|
+
it( 'derives the accessible name from an image label via its alt text', () => {
|
|
407
|
+
render(
|
|
408
|
+
<LeaderboardChart
|
|
409
|
+
data={ [
|
|
410
|
+
{
|
|
411
|
+
...mockData[ 0 ],
|
|
412
|
+
label: <img src="https://example.com/flag.svg" alt="United States" />,
|
|
413
|
+
onClick: jest.fn(),
|
|
414
|
+
},
|
|
415
|
+
] }
|
|
416
|
+
/>
|
|
417
|
+
);
|
|
418
|
+
expect( screen.getByRole( 'button' ) ).toHaveAccessibleName( /United States.*12\.5K/ );
|
|
419
|
+
} );
|
|
420
|
+
|
|
421
|
+
it( 'uses ariaLabel as the accessible name when provided', () => {
|
|
422
|
+
render(
|
|
423
|
+
<LeaderboardChart
|
|
424
|
+
data={ [
|
|
425
|
+
{
|
|
426
|
+
...mockData[ 0 ],
|
|
427
|
+
label: <img src="https://example.com/flag.svg" alt="" />,
|
|
428
|
+
ariaLabel: 'United States: 12.5K visitors',
|
|
429
|
+
onClick: jest.fn(),
|
|
430
|
+
},
|
|
431
|
+
] }
|
|
432
|
+
/>
|
|
433
|
+
);
|
|
434
|
+
expect( screen.getByRole( 'button' ) ).toHaveAccessibleName(
|
|
435
|
+
'United States: 12.5K visitors'
|
|
436
|
+
);
|
|
437
|
+
} );
|
|
438
|
+
|
|
392
439
|
it( 'does not render a button for entries without onClick', () => {
|
|
393
440
|
render( <LeaderboardChart data={ [ mockData[ 0 ] ] } /> );
|
|
394
441
|
expect( screen.queryByRole( 'button' ) ).not.toBeInTheDocument();
|
|
@@ -42,10 +42,10 @@ import styles from './line-chart.module.scss';
|
|
|
42
42
|
import { LineChartAnnotation, LineChartAnnotationsOverlay, LineChartGlyph } from './private';
|
|
43
43
|
import type { RenderLineGlyphProps, LineChartProps, TooltipDatum } from './types';
|
|
44
44
|
import type { DataPoint, DataPointDate, SeriesData, Optional } from '../../types';
|
|
45
|
+
import type { RenderTooltipParams } from '../../visx/types';
|
|
45
46
|
import type { ResponsiveConfig } from '../private/with-responsive';
|
|
46
47
|
import type { TickFormatter } from '@visx/axis';
|
|
47
48
|
import type { GlyphProps } from '@visx/xychart';
|
|
48
|
-
import type { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
49
49
|
import type { FC, Ref } from 'react';
|
|
50
50
|
|
|
51
51
|
const defaultRenderGlyph = < Datum extends object >( props: RenderLineGlyphProps< Datum > ) => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { __ } from '@wordpress/i18n';
|
|
2
|
-
import { Icon, close } from '@wordpress/icons';
|
|
3
2
|
import { Stack } from '@wordpress/ui';
|
|
4
3
|
import clsx from 'clsx';
|
|
5
4
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
@@ -10,6 +9,23 @@ import type { FC } from 'react';
|
|
|
10
9
|
|
|
11
10
|
export const POPOVER_BUTTON_SIZE = 44;
|
|
12
11
|
|
|
12
|
+
const CloseIcon = () => (
|
|
13
|
+
<svg
|
|
14
|
+
width="16"
|
|
15
|
+
height="16"
|
|
16
|
+
viewBox="0 0 24 24"
|
|
17
|
+
fill="none"
|
|
18
|
+
stroke="currentColor"
|
|
19
|
+
strokeWidth="2"
|
|
20
|
+
strokeLinecap="round"
|
|
21
|
+
strokeLinejoin="round"
|
|
22
|
+
aria-hidden="true"
|
|
23
|
+
focusable="false"
|
|
24
|
+
>
|
|
25
|
+
<path d="M6 6l12 12M18 6L6 18" />
|
|
26
|
+
</svg>
|
|
27
|
+
);
|
|
28
|
+
|
|
13
29
|
interface LineChartAnnotationLabelWithPopoverProps {
|
|
14
30
|
title: string;
|
|
15
31
|
subtitle?: string;
|
|
@@ -101,7 +117,7 @@ const LineChartAnnotationLabelWithPopover: FC< LineChartAnnotationLabelWithPopov
|
|
|
101
117
|
className={ styles[ 'line-chart__annotation-label-popover-close-button' ] }
|
|
102
118
|
aria-label={ __( 'Close', 'jetpack-charts' ) }
|
|
103
119
|
>
|
|
104
|
-
<
|
|
120
|
+
<CloseIcon />
|
|
105
121
|
</button>
|
|
106
122
|
</Stack>
|
|
107
123
|
</div>
|
|
@@ -15,7 +15,7 @@ import LineChartAnnotationLabelWithPopover, {
|
|
|
15
15
|
POPOVER_BUTTON_SIZE,
|
|
16
16
|
} from './line-chart-annotation-label-popover';
|
|
17
17
|
import type { LineChartAnnotationProps } from '../types';
|
|
18
|
-
import type { LabelProps } from '@visx/annotation
|
|
18
|
+
import type { LabelProps } from '@visx/annotation';
|
|
19
19
|
import type { TextProps } from '@visx/text';
|
|
20
20
|
import type { FC } from 'react';
|
|
21
21
|
|
|
@@ -5,8 +5,8 @@ import type {
|
|
|
5
5
|
AnnotationStyles,
|
|
6
6
|
DataPoint,
|
|
7
7
|
} from '../../types';
|
|
8
|
+
import type { RenderTooltipParams } from '../../visx/types';
|
|
8
9
|
import type { GlyphProps } from '@visx/xychart';
|
|
9
|
-
import type { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
10
10
|
import type { ReactNode, SVGProps, FC } from 'react';
|
|
11
11
|
|
|
12
12
|
export type LineChartAnnotationProps = {
|
|
@@ -37,7 +37,7 @@ import type {
|
|
|
37
37
|
} from '../../types';
|
|
38
38
|
import type { ChartComponentWithComposition } from '../private/chart-composition';
|
|
39
39
|
import type { ResponsiveConfig } from '../private/with-responsive';
|
|
40
|
-
import type {
|
|
40
|
+
import type { PieProvidedProps } from '@visx/shape';
|
|
41
41
|
import type { FC, MouseEvent, ReactNode } from 'react';
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -135,7 +135,7 @@ type PieSemiCircleChartResponsiveComponent = ChartComponentWithComposition<
|
|
|
135
135
|
PieSemiCircleChartBaseProps & ResponsiveConfig
|
|
136
136
|
>;
|
|
137
137
|
|
|
138
|
-
export type ArcData =
|
|
138
|
+
export type ArcData = PieProvidedProps< DataPointPercentageCalculated >[ 'arcs' ][ number ];
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Validates the semi-circle pie chart data
|
|
@@ -3,9 +3,8 @@ import { useEffect } from 'react';
|
|
|
3
3
|
import { useElementSize } from '../../../hooks';
|
|
4
4
|
import { renderLegendSlot } from '../chart-composition';
|
|
5
5
|
import styles from './chart-layout.module.scss';
|
|
6
|
-
import type { LegendPosition } from '../../../types';
|
|
6
|
+
import type { GapSize, LegendPosition } from '../../../types';
|
|
7
7
|
import type { LegendChild } from '../chart-composition/use-chart-children';
|
|
8
|
-
import type { GapSize } from '@wordpress/theme';
|
|
9
8
|
import type { CSSProperties, ReactNode } from 'react';
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -5,7 +5,7 @@ import styles from './x-zoom.module.scss';
|
|
|
5
5
|
import type { SingleChartRef } from './single-chart-context';
|
|
6
6
|
import type { AxisScale } from '@visx/axis';
|
|
7
7
|
import type { EventHandlerParams } from '@visx/xychart';
|
|
8
|
-
import type {
|
|
8
|
+
import type { ReactNode, RefObject } from 'react';
|
|
9
9
|
|
|
10
10
|
const MIN_DRAG_PIXELS = 6;
|
|
11
11
|
|
|
@@ -37,7 +37,7 @@ export function useXZoom< T extends Date | number = Date >( {
|
|
|
37
37
|
userHandlers,
|
|
38
38
|
}: {
|
|
39
39
|
enabled: boolean;
|
|
40
|
-
chartRef:
|
|
40
|
+
chartRef: RefObject< SingleChartRef | null >;
|
|
41
41
|
userHandlers?: {
|
|
42
42
|
onPointerDown?: PointerHandler;
|
|
43
43
|
onPointerMove?: PointerHandler;
|
|
@@ -6,9 +6,13 @@ import {
|
|
|
6
6
|
type ElementStyles,
|
|
7
7
|
} from '../../../providers';
|
|
8
8
|
import { formatPercentage } from '../../../utils';
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
SeriesData,
|
|
11
|
+
DataPointDate,
|
|
12
|
+
DataPointPercentageCalculated,
|
|
13
|
+
LegendShape,
|
|
14
|
+
} from '../../../types';
|
|
10
15
|
import type { BaseLegendItem } from '../types';
|
|
11
|
-
import type { LegendShape } from '@visx/legend/lib/types';
|
|
12
16
|
import type { GlyphProps } from '@visx/xychart';
|
|
13
17
|
import type { ReactNode } from 'react';
|
|
14
18
|
|
|
@@ -3,8 +3,7 @@ import { SingleChartContext } from '../../charts/private/single-chart-context';
|
|
|
3
3
|
import { GlobalChartsContext } from '../../providers';
|
|
4
4
|
import { BaseLegend } from './private';
|
|
5
5
|
import type { LegendProps } from './types';
|
|
6
|
-
import type { ChartType } from '../../types';
|
|
7
|
-
import type { LegendShape } from '@visx/legend/lib/types';
|
|
6
|
+
import type { ChartType, LegendShape } from '../../types';
|
|
8
7
|
|
|
9
8
|
const defaultShapeByChartType: Partial<
|
|
10
9
|
Record< ChartType, Extract< LegendShape< unknown, unknown >, string > >
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { Tooltip, TooltipContext } from '@visx/xychart';
|
|
2
2
|
import { useContext, useEffect, useCallback, useMemo } from 'react';
|
|
3
3
|
import type { SeriesData, DataPointDate } from '../../types';
|
|
4
|
-
import type {
|
|
5
|
-
TooltipProps as BaseTooltipProps,
|
|
6
|
-
RenderTooltipParams,
|
|
7
|
-
} from '@visx/xychart/lib/components/Tooltip';
|
|
4
|
+
import type { RenderTooltipParams, XyChartTooltipProps } from '../../visx/types';
|
|
8
5
|
import type { ReactNode } from 'react';
|
|
9
6
|
|
|
10
7
|
// Type for flattened tooltip data used in individual mode
|
|
@@ -17,7 +14,7 @@ export type FlattenedTooltipData = {
|
|
|
17
14
|
|
|
18
15
|
// Enhanced tooltip with keyboard navigation and accessibility
|
|
19
16
|
interface AccessibleTooltipProps
|
|
20
|
-
extends Omit<
|
|
17
|
+
extends Omit< XyChartTooltipProps< DataPointDate >, 'renderTooltip' > {
|
|
21
18
|
renderTooltip?: ( params: RenderTooltipParams< DataPointDate > ) => ReactNode;
|
|
22
19
|
selectedIndex?: number | undefined;
|
|
23
20
|
tooltipRef?: ( element: HTMLDivElement | null ) => void;
|
|
@@ -242,4 +239,3 @@ export const useKeyboardNavigation = ( {
|
|
|
242
239
|
|
|
243
240
|
// Re-export the base Tooltip for backwards compatibility
|
|
244
241
|
export { Tooltip };
|
|
245
|
-
export type { BaseTooltipProps };
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,12 @@ export type {
|
|
|
54
54
|
ChartLegendConfig,
|
|
55
55
|
BaseChartProps,
|
|
56
56
|
GridProps,
|
|
57
|
+
GoogleDataTableColumn,
|
|
58
|
+
GoogleDataTableColumnRoleType,
|
|
59
|
+
GoogleDataTableRow,
|
|
60
|
+
LegendShape,
|
|
61
|
+
LegendShapeLabel,
|
|
62
|
+
LegendShapeRenderProps,
|
|
57
63
|
} from './types';
|
|
58
64
|
export type * from './visx/types';
|
|
59
65
|
export type { PieChartProps, PieChartRenderTooltipParams } from './charts/pie-chart';
|
|
@@ -65,11 +71,6 @@ export type { GeoChartProps, GeoRegion, GeoResolution } from './charts/geo-chart
|
|
|
65
71
|
export type { LegendValueDisplay, BaseLegendItem } from './components/legend';
|
|
66
72
|
export type { TrendIndicatorProps, TrendDirection } from './components/trend-indicator';
|
|
67
73
|
export type { LineStyles, GridStyles, EventHandlerParams } from '@visx/xychart';
|
|
68
|
-
export type {
|
|
69
|
-
GoogleDataTableColumn,
|
|
70
|
-
GoogleDataTableRow,
|
|
71
|
-
GoogleDataTableColumnRoleType,
|
|
72
|
-
} from 'react-google-charts';
|
|
73
74
|
|
|
74
75
|
// Re-exports from removed individual entry points
|
|
75
76
|
export { useLeaderboardLegendItems } from './charts/leaderboard-chart/hooks';
|
|
@@ -53,7 +53,7 @@ const defaultTheme: CompleteChartTheme = {
|
|
|
53
53
|
leaderboardChart: {
|
|
54
54
|
rowGap: 12,
|
|
55
55
|
columnGap: 4,
|
|
56
|
-
labelSpacing:
|
|
56
|
+
labelSpacing: 'xs',
|
|
57
57
|
deltaColors: [ '#FF8C8F', '#757575', '#1F9828' ], // [negative, neutral, positive]
|
|
58
58
|
},
|
|
59
59
|
conversionFunnelChart: {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
import type { BaseLegendItem } from '../../components/legend';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
ChartType,
|
|
5
|
+
CompleteChartTheme,
|
|
6
|
+
DataPointPercentage,
|
|
7
|
+
LegendShape,
|
|
8
|
+
SeriesData,
|
|
9
|
+
} from '../../types';
|
|
5
10
|
import type { GlyphProps, LineStyles } from '@visx/xychart';
|
|
6
11
|
|
|
7
12
|
export interface ChartRegistration {
|