@automattic/charts 0.58.0 → 0.59.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 +20 -0
- package/README.md +7 -54
- package/dist/index.cjs +9606 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +20 -25
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +1612 -33
- package/dist/index.d.ts +1612 -33
- package/dist/index.js +9640 -56
- package/dist/index.js.map +1 -1
- package/package.json +8 -125
- package/src/charts/bar-chart/bar-chart.module.scss +0 -5
- package/src/charts/bar-chart/bar-chart.tsx +131 -137
- package/src/charts/leaderboard-chart/leaderboard-chart.tsx +23 -40
- package/src/charts/line-chart/line-chart.module.scss +0 -5
- package/src/charts/line-chart/line-chart.tsx +190 -183
- package/src/charts/line-chart/private/line-chart-annotations-overlay.tsx +1 -2
- package/src/charts/pie-chart/pie-chart.module.scss +2 -10
- package/src/charts/pie-chart/pie-chart.tsx +198 -199
- package/src/charts/pie-chart/test/composition-api.test.tsx +3 -3
- package/src/charts/pie-chart/test/pie-chart.test.tsx +42 -35
- package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +2 -8
- package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +155 -155
- package/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx +25 -25
- package/src/charts/private/chart-layout/chart-layout.module.scss +7 -0
- package/src/charts/private/chart-layout/chart-layout.tsx +106 -0
- package/src/charts/private/chart-layout/index.ts +2 -0
- package/src/charts/private/chart-layout/test/chart-layout.test.tsx +167 -0
- package/src/charts/private/single-chart-context/single-chart-context.tsx +2 -2
- package/src/charts/private/svg-empty-state/index.ts +1 -0
- package/src/charts/private/svg-empty-state/svg-empty-state.module.scss +7 -0
- package/src/charts/private/svg-empty-state/svg-empty-state.tsx +40 -0
- package/src/components/legend/hooks/test/use-chart-legend-items.test.tsx +12 -8
- package/src/components/legend/hooks/use-chart-legend-items.ts +12 -13
- package/src/components/legend/legend.tsx +33 -8
- package/src/components/legend/test/legend.test.tsx +93 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-data-with-percentages.ts +24 -0
- package/src/hooks/use-interactive-legend-data.ts +18 -15
- package/src/index.ts +65 -2
- package/src/providers/chart-context/global-charts-provider.tsx +7 -1
- package/src/providers/chart-context/hooks/use-chart-registration.ts +2 -1
- package/src/providers/chart-context/types.ts +2 -2
- package/src/types.ts +27 -7
- package/src/utils/test/resolve-css-var.test.ts +2 -0
- package/dist/base-tooltip-DOq93wjU.d.cts +0 -38
- package/dist/base-tooltip-DOq93wjU.d.ts +0 -38
- package/dist/charts/bar-chart/index.cjs +0 -17
- package/dist/charts/bar-chart/index.cjs.map +0 -1
- package/dist/charts/bar-chart/index.css +0 -141
- package/dist/charts/bar-chart/index.css.map +0 -1
- package/dist/charts/bar-chart/index.d.cts +0 -36
- package/dist/charts/bar-chart/index.d.ts +0 -36
- package/dist/charts/bar-chart/index.js +0 -17
- package/dist/charts/bar-chart/index.js.map +0 -1
- package/dist/charts/bar-list-chart/index.cjs +0 -18
- package/dist/charts/bar-list-chart/index.cjs.map +0 -1
- package/dist/charts/bar-list-chart/index.css +0 -141
- package/dist/charts/bar-list-chart/index.css.map +0 -1
- package/dist/charts/bar-list-chart/index.d.cts +0 -92
- package/dist/charts/bar-list-chart/index.d.ts +0 -92
- package/dist/charts/bar-list-chart/index.js +0 -18
- package/dist/charts/bar-list-chart/index.js.map +0 -1
- package/dist/charts/conversion-funnel-chart/index.cjs +0 -11
- package/dist/charts/conversion-funnel-chart/index.cjs.map +0 -1
- package/dist/charts/conversion-funnel-chart/index.css +0 -157
- package/dist/charts/conversion-funnel-chart/index.css.map +0 -1
- package/dist/charts/conversion-funnel-chart/index.d.cts +0 -97
- package/dist/charts/conversion-funnel-chart/index.d.ts +0 -97
- package/dist/charts/conversion-funnel-chart/index.js +0 -11
- package/dist/charts/conversion-funnel-chart/index.js.map +0 -1
- package/dist/charts/geo-chart/index.cjs +0 -13
- package/dist/charts/geo-chart/index.cjs.map +0 -1
- package/dist/charts/geo-chart/index.css +0 -23
- package/dist/charts/geo-chart/index.css.map +0 -1
- package/dist/charts/geo-chart/index.d.cts +0 -67
- package/dist/charts/geo-chart/index.d.ts +0 -67
- package/dist/charts/geo-chart/index.js +0 -13
- package/dist/charts/geo-chart/index.js.map +0 -1
- package/dist/charts/leaderboard-chart/index.cjs +0 -21
- package/dist/charts/leaderboard-chart/index.cjs.map +0 -1
- package/dist/charts/leaderboard-chart/index.css +0 -160
- package/dist/charts/leaderboard-chart/index.css.map +0 -1
- package/dist/charts/leaderboard-chart/index.d.cts +0 -46
- package/dist/charts/leaderboard-chart/index.d.ts +0 -46
- package/dist/charts/leaderboard-chart/index.js +0 -21
- package/dist/charts/leaderboard-chart/index.js.map +0 -1
- package/dist/charts/line-chart/index.cjs +0 -17
- package/dist/charts/line-chart/index.cjs.map +0 -1
- package/dist/charts/line-chart/index.css +0 -213
- package/dist/charts/line-chart/index.css.map +0 -1
- package/dist/charts/line-chart/index.d.cts +0 -98
- package/dist/charts/line-chart/index.d.ts +0 -98
- package/dist/charts/line-chart/index.js +0 -17
- package/dist/charts/line-chart/index.js.map +0 -1
- package/dist/charts/pie-chart/index.cjs +0 -19
- package/dist/charts/pie-chart/index.cjs.map +0 -1
- package/dist/charts/pie-chart/index.css +0 -131
- package/dist/charts/pie-chart/index.css.map +0 -1
- package/dist/charts/pie-chart/index.d.cts +0 -91
- package/dist/charts/pie-chart/index.d.ts +0 -91
- package/dist/charts/pie-chart/index.js +0 -19
- package/dist/charts/pie-chart/index.js.map +0 -1
- package/dist/charts/pie-semi-circle-chart/index.cjs +0 -18
- package/dist/charts/pie-semi-circle-chart/index.cjs.map +0 -1
- package/dist/charts/pie-semi-circle-chart/index.css +0 -132
- package/dist/charts/pie-semi-circle-chart/index.css.map +0 -1
- package/dist/charts/pie-semi-circle-chart/index.d.cts +0 -88
- package/dist/charts/pie-semi-circle-chart/index.d.ts +0 -88
- package/dist/charts/pie-semi-circle-chart/index.js +0 -18
- package/dist/charts/pie-semi-circle-chart/index.js.map +0 -1
- package/dist/charts/sparkline/index.cjs +0 -18
- package/dist/charts/sparkline/index.cjs.map +0 -1
- package/dist/charts/sparkline/index.css +0 -230
- package/dist/charts/sparkline/index.css.map +0 -1
- package/dist/charts/sparkline/index.d.cts +0 -113
- package/dist/charts/sparkline/index.d.ts +0 -113
- package/dist/charts/sparkline/index.js +0 -18
- package/dist/charts/sparkline/index.js.map +0 -1
- package/dist/chunk-2A34OA5O.cjs +0 -51
- package/dist/chunk-2A34OA5O.cjs.map +0 -1
- package/dist/chunk-2I67QUIV.js +0 -895
- package/dist/chunk-2I67QUIV.js.map +0 -1
- package/dist/chunk-2ICEEQOC.js +0 -1071
- package/dist/chunk-2ICEEQOC.js.map +0 -1
- package/dist/chunk-4B7BL2DD.js +0 -120
- package/dist/chunk-4B7BL2DD.js.map +0 -1
- package/dist/chunk-4OXMTKAL.js +0 -401
- package/dist/chunk-4OXMTKAL.js.map +0 -1
- package/dist/chunk-ASLARV7L.cjs +0 -81
- package/dist/chunk-ASLARV7L.cjs.map +0 -1
- package/dist/chunk-B6NLZFRW.js +0 -617
- package/dist/chunk-B6NLZFRW.js.map +0 -1
- package/dist/chunk-BBAUQOW6.cjs +0 -120
- package/dist/chunk-BBAUQOW6.cjs.map +0 -1
- package/dist/chunk-BPYKWMI7.js +0 -194
- package/dist/chunk-BPYKWMI7.js.map +0 -1
- package/dist/chunk-CMMHCTBX.cjs +0 -373
- package/dist/chunk-CMMHCTBX.cjs.map +0 -1
- package/dist/chunk-CPPXJATQ.cjs +0 -1071
- package/dist/chunk-CPPXJATQ.cjs.map +0 -1
- package/dist/chunk-DKU775VC.js +0 -219
- package/dist/chunk-DKU775VC.js.map +0 -1
- package/dist/chunk-GRA7Y2ZG.cjs +0 -401
- package/dist/chunk-GRA7Y2ZG.cjs.map +0 -1
- package/dist/chunk-I2276W3I.cjs +0 -66
- package/dist/chunk-I2276W3I.cjs.map +0 -1
- package/dist/chunk-JJIMABHT.js +0 -351
- package/dist/chunk-JJIMABHT.js.map +0 -1
- package/dist/chunk-KJHWXOCZ.js +0 -421
- package/dist/chunk-KJHWXOCZ.js.map +0 -1
- package/dist/chunk-KRWGSOJ2.js +0 -91
- package/dist/chunk-KRWGSOJ2.js.map +0 -1
- package/dist/chunk-KXRWNFQJ.js +0 -51
- package/dist/chunk-KXRWNFQJ.js.map +0 -1
- package/dist/chunk-LTFH7SEG.js +0 -373
- package/dist/chunk-LTFH7SEG.js.map +0 -1
- package/dist/chunk-MUNOKLLE.js +0 -165
- package/dist/chunk-MUNOKLLE.js.map +0 -1
- package/dist/chunk-MXGLYWVP.cjs +0 -351
- package/dist/chunk-MXGLYWVP.cjs.map +0 -1
- package/dist/chunk-OP6PHB2U.js +0 -81
- package/dist/chunk-OP6PHB2U.js.map +0 -1
- package/dist/chunk-OYC34VTO.cjs +0 -3957
- package/dist/chunk-OYC34VTO.cjs.map +0 -1
- package/dist/chunk-PQL5I3F6.cjs +0 -421
- package/dist/chunk-PQL5I3F6.cjs.map +0 -1
- package/dist/chunk-REZTQ4PH.cjs +0 -488
- package/dist/chunk-REZTQ4PH.cjs.map +0 -1
- package/dist/chunk-TZRUHQOH.cjs +0 -91
- package/dist/chunk-TZRUHQOH.cjs.map +0 -1
- package/dist/chunk-UTYVIOWZ.js +0 -3957
- package/dist/chunk-UTYVIOWZ.js.map +0 -1
- package/dist/chunk-W2LDIX26.cjs +0 -165
- package/dist/chunk-W2LDIX26.cjs.map +0 -1
- package/dist/chunk-WSG64BVN.cjs +0 -219
- package/dist/chunk-WSG64BVN.cjs.map +0 -1
- package/dist/chunk-WTQYGUNF.js +0 -400
- package/dist/chunk-WTQYGUNF.js.map +0 -1
- package/dist/chunk-WYK7EL5R.cjs +0 -895
- package/dist/chunk-WYK7EL5R.cjs.map +0 -1
- package/dist/chunk-XC4KHJYX.cjs +0 -617
- package/dist/chunk-XC4KHJYX.cjs.map +0 -1
- package/dist/chunk-XVBH5XHE.cjs +0 -400
- package/dist/chunk-XVBH5XHE.cjs.map +0 -1
- package/dist/chunk-XWYZIFZW.js +0 -66
- package/dist/chunk-XWYZIFZW.js.map +0 -1
- package/dist/chunk-Y3NNQMAX.cjs +0 -194
- package/dist/chunk-Y3NNQMAX.cjs.map +0 -1
- package/dist/chunk-YAFQVVDI.js +0 -488
- package/dist/chunk-YAFQVVDI.js.map +0 -1
- package/dist/components/legend/index.cjs +0 -12
- package/dist/components/legend/index.cjs.map +0 -1
- package/dist/components/legend/index.css +0 -91
- package/dist/components/legend/index.css.map +0 -1
- package/dist/components/legend/index.d.cts +0 -37
- package/dist/components/legend/index.d.ts +0 -37
- package/dist/components/legend/index.js +0 -12
- package/dist/components/legend/index.js.map +0 -1
- package/dist/components/tooltip/index.cjs +0 -12
- package/dist/components/tooltip/index.cjs.map +0 -1
- package/dist/components/tooltip/index.css +0 -13
- package/dist/components/tooltip/index.css.map +0 -1
- package/dist/components/tooltip/index.d.cts +0 -71
- package/dist/components/tooltip/index.d.ts +0 -71
- package/dist/components/tooltip/index.js +0 -12
- package/dist/components/tooltip/index.js.map +0 -1
- package/dist/components/trend-indicator/index.cjs +0 -8
- package/dist/components/trend-indicator/index.cjs.map +0 -1
- package/dist/components/trend-indicator/index.css +0 -27
- package/dist/components/trend-indicator/index.css.map +0 -1
- package/dist/components/trend-indicator/index.d.cts +0 -44
- package/dist/components/trend-indicator/index.d.ts +0 -44
- package/dist/components/trend-indicator/index.js +0 -8
- package/dist/components/trend-indicator/index.js.map +0 -1
- package/dist/format-metric-value-MXm5DtQ_.d.cts +0 -24
- package/dist/format-metric-value-MXm5DtQ_.d.ts +0 -24
- package/dist/hooks/index.cjs +0 -29
- package/dist/hooks/index.cjs.map +0 -1
- package/dist/hooks/index.css +0 -9
- package/dist/hooks/index.css.map +0 -1
- package/dist/hooks/index.d.cts +0 -264
- package/dist/hooks/index.d.ts +0 -264
- package/dist/hooks/index.js +0 -29
- package/dist/hooks/index.js.map +0 -1
- package/dist/leaderboard-chart-BSbg0ufV.d.cts +0 -79
- package/dist/leaderboard-chart-odEYxxEC.d.ts +0 -79
- package/dist/legend-DFkosEvC.d.cts +0 -9
- package/dist/legend-DLswHhOk.d.ts +0 -9
- package/dist/providers/index.cjs +0 -21
- package/dist/providers/index.cjs.map +0 -1
- package/dist/providers/index.css +0 -9
- package/dist/providers/index.css.map +0 -1
- package/dist/providers/index.d.cts +0 -28
- package/dist/providers/index.d.ts +0 -28
- package/dist/providers/index.js +0 -21
- package/dist/providers/index.js.map +0 -1
- package/dist/themes-D0qc5JaW.d.cts +0 -67
- package/dist/themes-itO4Ht5g.d.ts +0 -67
- package/dist/types-B5f6XQ7Q.d.cts +0 -19
- package/dist/types-BsHooDbM.d.ts +0 -19
- package/dist/types-BuSrRM4p.d.ts +0 -49
- package/dist/types-ChOUI9-N.d.cts +0 -545
- package/dist/types-ChOUI9-N.d.ts +0 -545
- package/dist/types-Dfw9VOKI.d.cts +0 -49
- package/dist/utils/index.cjs +0 -44
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.d.cts +0 -226
- package/dist/utils/index.d.ts +0 -226
- package/dist/utils/index.js +0 -44
- package/dist/utils/index.js.map +0 -1
- package/dist/with-responsive-CNfhzAUu.d.cts +0 -18
- package/dist/with-responsive-CNfhzAUu.d.ts +0 -18
package/dist/index.d.cts
CHANGED
|
@@ -1,35 +1,1614 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { CSSProperties, ReactNode, PointerEvent, ComponentProps, FC, ComponentType, SVGProps, PropsWithChildren } from 'react';
|
|
3
|
+
import { LegendOrdinal } from '@visx/legend';
|
|
4
|
+
import { CircleSubjectProps } from '@visx/annotation/lib/components/CircleSubject';
|
|
5
|
+
import { ConnectorProps } from '@visx/annotation/lib/components/Connector';
|
|
6
|
+
import { LabelProps } from '@visx/annotation/lib/components/Label';
|
|
7
|
+
import { LineSubjectProps } from '@visx/annotation/lib/components/LineSubject';
|
|
8
|
+
import { Orientation, TickFormatter, AxisScale, AxisRendererProps } from '@visx/axis';
|
|
9
|
+
import { LegendShape } from '@visx/legend/lib/types';
|
|
10
|
+
import { ScaleInput, ScaleType } from '@visx/scale';
|
|
11
|
+
import { TextProps } from '@visx/text/lib/Text';
|
|
12
|
+
import { LineStyles, EventHandlerParams, GridStyles, GlyphProps } from '@visx/xychart';
|
|
7
13
|
export { EventHandlerParams, GridStyles, LineStyles } from '@visx/xychart';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export { B as BaseLegendItem } from './types-Dfw9VOKI.cjs';
|
|
11
|
-
export { LineChart, LineChartUnresponsive } from './charts/line-chart/index.cjs';
|
|
12
|
-
export { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
13
|
-
export { PieChart, PieChartProps, PieChartRenderTooltipParams, PieChartUnresponsive } from './charts/pie-chart/index.cjs';
|
|
14
|
-
export { PieSemiCircleChart, PieSemiCircleChartProps, PieSemiCircleChartRenderTooltipParams, PieSemiCircleChartUnresponsive } from './charts/pie-semi-circle-chart/index.cjs';
|
|
15
|
-
export { Sparkline, SparklineUnresponsive } from './charts/sparkline/index.cjs';
|
|
16
|
-
export { B as BaseTooltip } from './base-tooltip-DOq93wjU.cjs';
|
|
17
|
-
export { TrendDirection, TrendIndicator, TrendIndicatorProps } from './components/trend-indicator/index.cjs';
|
|
18
|
-
export { G as GlobalChartsContext, a as GlobalChartsProvider, a as ThemeProvider, d as defaultTheme, u as useGlobalChartsContext, b as useGlobalChartsTheme } from './themes-D0qc5JaW.cjs';
|
|
14
|
+
import { GapSize } from '@wordpress/theme';
|
|
15
|
+
import { GoogleDataTableColumn, GoogleDataTableRow } from 'react-google-charts';
|
|
19
16
|
export { GoogleDataTableColumn, GoogleDataTableColumnRoleType, GoogleDataTableRow } from 'react-google-charts';
|
|
20
|
-
import '
|
|
21
|
-
|
|
22
|
-
import 'react/jsx-runtime';
|
|
23
|
-
import '@visx/text';
|
|
24
|
-
import '@visx/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
import { RenderTooltipParams, TooltipProps as TooltipProps$1 } from '@visx/xychart/lib/components/Tooltip';
|
|
18
|
+
export { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
19
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
20
|
+
import { TextProps as TextProps$1 } from '@visx/text';
|
|
21
|
+
import { PieArcDatum } from '@visx/shape/lib/shapes/Pie';
|
|
22
|
+
|
|
23
|
+
type ValueOf<T> = T[keyof T];
|
|
24
|
+
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
25
|
+
type ChartType = 'bar' | 'conversion-funnel' | 'leaderboard' | 'line' | 'pie' | 'pie-semi-circle';
|
|
26
|
+
type OrientationType = ValueOf<typeof Orientation>;
|
|
27
|
+
type AnnotationStyles = {
|
|
28
|
+
circleSubject?: Omit<CircleSubjectProps, 'x' | 'y'> & {
|
|
29
|
+
fill?: string;
|
|
30
|
+
};
|
|
31
|
+
lineSubject?: Omit<LineSubjectProps, 'x' | 'y'>;
|
|
32
|
+
connector?: Omit<ConnectorProps, 'x' | 'y' | 'dx' | 'dy'>;
|
|
33
|
+
label?: Omit<LabelProps, 'title' | 'subtitle' | 'x' | 'y'> & {
|
|
34
|
+
x?: number | 'start' | 'end';
|
|
35
|
+
y?: number | 'start' | 'end';
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
type DataPoint = {
|
|
39
|
+
label: string;
|
|
40
|
+
value: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Data format for GeoChart - uses Google Charts native data format for maximum flexibility.
|
|
44
|
+
* First element is the header row, subsequent elements are data rows.
|
|
45
|
+
*
|
|
46
|
+
* Country identifiers can be either full country names or ISO 3166-1 alpha-2 codes (e.g., 'United States' or 'US').
|
|
47
|
+
* Full names are recommended for better readability in tooltips.
|
|
48
|
+
*
|
|
49
|
+
* @example Basic usage with country names:
|
|
50
|
+
* [['Country', 'Value'], ['United States', 100], ['Canada', 50], ['United Kingdom', 75]]
|
|
51
|
+
*
|
|
52
|
+
* @example With custom HTML tooltips:
|
|
53
|
+
* [
|
|
54
|
+
* ['Country', 'Value', { type: 'string', role: 'tooltip', p: { html: true } }],
|
|
55
|
+
* ['United States', 100, '<b>United States</b><br/>100 visitors'],
|
|
56
|
+
* ['Canada', 50, '<b>Canada</b><br/>50 visitors']
|
|
57
|
+
* ]
|
|
58
|
+
*
|
|
59
|
+
* @example With formatted values (v = value, f = formatted):
|
|
60
|
+
* [
|
|
61
|
+
* ['Country', 'Value'],
|
|
62
|
+
* ['United States', { v: 100, f: '100 visitors' }],
|
|
63
|
+
* ['Canada', { v: 50, f: '50 visitors' }]
|
|
64
|
+
* ]
|
|
65
|
+
*
|
|
66
|
+
* @example With multiple columns:
|
|
67
|
+
* [
|
|
68
|
+
* ['Country', 'Population', 'Area'],
|
|
69
|
+
* ['United States', 331000000, 9834000],
|
|
70
|
+
* ['Canada', 38000000, 9985000]
|
|
71
|
+
* ]
|
|
72
|
+
*/
|
|
73
|
+
type GeoData = [GoogleDataTableColumn[], ...GoogleDataTableRow[]];
|
|
74
|
+
type DataPointDate = {
|
|
75
|
+
date?: Date;
|
|
76
|
+
/**
|
|
77
|
+
* Supported Formats:
|
|
78
|
+
* - YYYY-MM-DD (local)
|
|
79
|
+
* - YYYY-MM-DD HH:mm:ss (local)
|
|
80
|
+
* - YYYY-MM-DD HH:mm (local)
|
|
81
|
+
* - YYYY-MM-DDTHH:mm:ss (local)
|
|
82
|
+
* - YYYY-MM-DDTHH:mm:ss.SSS (local)
|
|
83
|
+
* - YYYY-MM-DDTHH:mm (local)
|
|
84
|
+
* - YYYY-MM-DDTHH:mm:ssZ (UTC → local)
|
|
85
|
+
* - YYYY-MM-DDTHH:mm:ss±HH:mm (offset → local)
|
|
86
|
+
*/
|
|
87
|
+
dateString?: string;
|
|
88
|
+
value: number | null;
|
|
89
|
+
label?: string;
|
|
90
|
+
};
|
|
91
|
+
type LeaderboardEntry = {
|
|
92
|
+
/**
|
|
93
|
+
* Unique internal key (e.g., 'key-direct')
|
|
94
|
+
*/
|
|
95
|
+
id: string;
|
|
96
|
+
/**
|
|
97
|
+
* Human-readable name (e.g., 'Direct') or a JSX element (e.g., <h4>Direct</h4>)
|
|
98
|
+
*/
|
|
99
|
+
label: string | JSX.Element;
|
|
100
|
+
/**
|
|
101
|
+
* Value of the entry
|
|
102
|
+
*/
|
|
103
|
+
currentValue: number;
|
|
104
|
+
/**
|
|
105
|
+
* Value of the entry in the previous period
|
|
106
|
+
*/
|
|
107
|
+
previousValue: number;
|
|
108
|
+
/**
|
|
109
|
+
* Width of current bar, as % of the current value
|
|
110
|
+
*/
|
|
111
|
+
currentShare: number;
|
|
112
|
+
/**
|
|
113
|
+
* Width of previous bar, as % of the current value
|
|
114
|
+
*/
|
|
115
|
+
previousShare: number;
|
|
116
|
+
/**
|
|
117
|
+
* Delta of the entry
|
|
118
|
+
*/
|
|
119
|
+
delta: number;
|
|
120
|
+
/**
|
|
121
|
+
* Optional color for the entry's image/icon
|
|
122
|
+
*/
|
|
123
|
+
imageColor?: string;
|
|
124
|
+
};
|
|
125
|
+
type GradientStop = {
|
|
126
|
+
offset: string;
|
|
127
|
+
color?: string;
|
|
128
|
+
opacity?: number;
|
|
129
|
+
};
|
|
130
|
+
type SeriesDataOptions = {
|
|
131
|
+
gradient?: {
|
|
132
|
+
from: string;
|
|
133
|
+
to: string;
|
|
134
|
+
fromOpacity?: number;
|
|
135
|
+
toOpacity?: number;
|
|
136
|
+
stops?: GradientStop[];
|
|
137
|
+
};
|
|
138
|
+
stroke?: string;
|
|
139
|
+
seriesLineStyle?: LineStyles;
|
|
140
|
+
legendShapeStyle?: CSSProperties;
|
|
141
|
+
type?: 'comparison';
|
|
142
|
+
};
|
|
143
|
+
type SeriesData = {
|
|
144
|
+
group?: string;
|
|
145
|
+
label: string;
|
|
146
|
+
data: DataPointDate[] | DataPoint[];
|
|
147
|
+
options?: SeriesDataOptions;
|
|
148
|
+
};
|
|
149
|
+
type MultipleDataPointsDate = {
|
|
150
|
+
label: string;
|
|
151
|
+
data: DataPointDate[];
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Input data point for percentage-based charts (pie, donut, semi-circle).
|
|
155
|
+
* Provide values; percentages will be calculated automatically.
|
|
156
|
+
*/
|
|
157
|
+
type DataPointPercentage = {
|
|
158
|
+
/**
|
|
159
|
+
* Label for the data point
|
|
160
|
+
*/
|
|
161
|
+
label: string;
|
|
162
|
+
/**
|
|
163
|
+
* Numerical value used for slice sizing.
|
|
164
|
+
* Percentages are calculated automatically from values.
|
|
165
|
+
*/
|
|
166
|
+
value: number;
|
|
167
|
+
/**
|
|
168
|
+
* Formatted value for display (e.g., "30K" instead of 30000)
|
|
169
|
+
*/
|
|
170
|
+
valueDisplay?: string;
|
|
171
|
+
/**
|
|
172
|
+
* Color code for the segment, by default colours are taken from the theme but this property can overrides it
|
|
173
|
+
*/
|
|
174
|
+
color?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Group for the data point, used to match color with groups on other charts
|
|
177
|
+
*/
|
|
178
|
+
group?: string;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Internal type with calculated percentage.
|
|
182
|
+
* Used internally after percentage calculation from values.
|
|
183
|
+
*/
|
|
184
|
+
type DataPointPercentageCalculated = DataPointPercentage & {
|
|
185
|
+
/**
|
|
186
|
+
* Calculated percentage (0-100) based on value relative to total
|
|
187
|
+
*/
|
|
188
|
+
percentage: number;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Base theme configuration for chart components with optional properties
|
|
192
|
+
*/
|
|
193
|
+
type ChartTheme = {
|
|
194
|
+
/** Background color for chart components */
|
|
195
|
+
backgroundColor: string;
|
|
196
|
+
/** Background color for labels */
|
|
197
|
+
labelBackgroundColor?: string;
|
|
198
|
+
/** Text color for labels */
|
|
199
|
+
labelTextColor?: string;
|
|
200
|
+
/** Array of colors used for data visualization */
|
|
201
|
+
colors: string[];
|
|
202
|
+
/** Optional CSS styles for grid lines */
|
|
203
|
+
gridStyles?: GridStyles;
|
|
204
|
+
/** Length of axis ticks in pixels */
|
|
205
|
+
tickLength: number;
|
|
206
|
+
/** Color of the grid lines */
|
|
207
|
+
gridColor: string;
|
|
208
|
+
/** Color of the grid lines in dark mode */
|
|
209
|
+
gridColorDark: string;
|
|
210
|
+
/** Styles for x-axis tick lines */
|
|
211
|
+
xTickLineStyles?: LineStyles;
|
|
212
|
+
/** Styles for x-axis line */
|
|
213
|
+
xAxisLineStyles?: LineStyles;
|
|
214
|
+
/** Styles for series lines */
|
|
215
|
+
seriesLineStyles?: LineStyles[];
|
|
216
|
+
/** Array of render functions for glyphs */
|
|
217
|
+
glyphs?: Array<(<Datum extends object>(props: GlyphProps<Datum>) => ReactNode)>;
|
|
218
|
+
/** Legend specific settings */
|
|
219
|
+
legend?: {
|
|
220
|
+
/** Styles for legend shapes */
|
|
221
|
+
shapeStyles?: Record<string, unknown>[];
|
|
222
|
+
/** Styles for legend labels */
|
|
223
|
+
labelStyles?: CSSProperties;
|
|
224
|
+
/** Styles for legend container */
|
|
225
|
+
containerStyles?: CSSProperties;
|
|
226
|
+
};
|
|
227
|
+
/** Styles for small SVG text (eg. axis tick labels), passed through to the XYChart theme. */
|
|
228
|
+
svgLabelSmall?: TextProps;
|
|
229
|
+
annotationStyles?: AnnotationStyles;
|
|
230
|
+
/** GeoChart specific settings */
|
|
231
|
+
geoChart?: {
|
|
232
|
+
/** Default fill color for a geo chart feature (e.g. country) with no data */
|
|
233
|
+
featureFillColor?: string;
|
|
234
|
+
};
|
|
235
|
+
/** LeaderboardChart specific settings */
|
|
236
|
+
leaderboardChart?: {
|
|
237
|
+
/** Gap between rows in the leaderboard grid */
|
|
238
|
+
rowGap?: number;
|
|
239
|
+
/** Gap between columns in the leaderboard grid */
|
|
240
|
+
columnGap?: number;
|
|
241
|
+
/** Spacing between label and progress bars */
|
|
242
|
+
labelSpacing?: number;
|
|
243
|
+
/** Primary color for current period bars */
|
|
244
|
+
primaryColor?: string;
|
|
245
|
+
/** Secondary color for comparison period bars */
|
|
246
|
+
secondaryColor?: string;
|
|
247
|
+
/** Delta colors: [negative, neutral, positive] */
|
|
248
|
+
deltaColors?: [string, string, string];
|
|
249
|
+
};
|
|
250
|
+
/** ConversionFunnelChart specific settings */
|
|
251
|
+
conversionFunnelChart?: {
|
|
252
|
+
/** Primary color for funnel bars */
|
|
253
|
+
primaryColor?: string;
|
|
254
|
+
/** Background color for chart container */
|
|
255
|
+
backgroundColor?: string;
|
|
256
|
+
/** Color for positive change indicators */
|
|
257
|
+
positiveChangeColor?: string;
|
|
258
|
+
/** Color for negative change indicators */
|
|
259
|
+
negativeChangeColor?: string;
|
|
260
|
+
};
|
|
261
|
+
lineChart?: {
|
|
262
|
+
lineStyles?: Partial<Record<NonNullable<SeriesDataOptions['type']>, LineStyles>>;
|
|
263
|
+
};
|
|
264
|
+
/** Sparkline specific settings */
|
|
265
|
+
sparkline?: {
|
|
266
|
+
/** Margin around the sparkline chart */
|
|
267
|
+
margin?: {
|
|
268
|
+
top?: number;
|
|
269
|
+
right?: number;
|
|
270
|
+
bottom?: number;
|
|
271
|
+
left?: number;
|
|
272
|
+
};
|
|
273
|
+
/** Stroke width for the sparkline line */
|
|
274
|
+
strokeWidth?: number;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Theme configuration with all properties guaranteed to be defined.
|
|
279
|
+
* Useful for merged themes where defaults are provided for all optional properties.
|
|
280
|
+
*/
|
|
281
|
+
type CompleteChartTheme = Required<ChartTheme> & {
|
|
282
|
+
leaderboardChart: Omit<Required<NonNullable<ChartTheme['leaderboardChart']>>, 'primaryColor' | 'secondaryColor'> & Pick<NonNullable<ChartTheme['leaderboardChart']>, 'primaryColor' | 'secondaryColor'>;
|
|
283
|
+
conversionFunnelChart: Omit<Required<NonNullable<ChartTheme['conversionFunnelChart']>>, 'primaryColor'> & Pick<NonNullable<ChartTheme['conversionFunnelChart']>, 'primaryColor'>;
|
|
284
|
+
lineChart: {
|
|
285
|
+
lineStyles: Record<NonNullable<SeriesDataOptions['type']>, LineStyles>;
|
|
286
|
+
};
|
|
287
|
+
legend: Required<NonNullable<ChartTheme['legend']>>;
|
|
288
|
+
sparkline: Required<NonNullable<ChartTheme['sparkline']>> & {
|
|
289
|
+
margin: Required<NonNullable<ChartTheme['sparkline']>['margin']>;
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
type AxisOptions = {
|
|
293
|
+
orientation?: OrientationType;
|
|
294
|
+
numTicks?: number;
|
|
295
|
+
axisClassName?: string;
|
|
296
|
+
axisLineClassName?: string;
|
|
297
|
+
labelClassName?: string;
|
|
298
|
+
tickClassName?: string;
|
|
299
|
+
tickFormat?: TickFormatter<ScaleInput<AxisScale>>;
|
|
300
|
+
/**
|
|
301
|
+
* Whether to display this axis. Defaults to true.
|
|
302
|
+
*/
|
|
303
|
+
display?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* For more control over rendering or to add event handlers to datum, pass a function as children.
|
|
306
|
+
*/
|
|
307
|
+
children?: (renderProps: AxisRendererProps<AxisScale>) => ReactNode;
|
|
308
|
+
/**
|
|
309
|
+
* Controls tick label overflow (bar charts only):
|
|
310
|
+
*
|
|
311
|
+
* - 'ellipsis': Truncate with ellipsis and fit to available space. Labels show full text
|
|
312
|
+
* on hover via native tooltip. Note: A minimum width (20px) is enforced for readability.
|
|
313
|
+
* On very dense charts (bandwidth < 20px), adjacent labels may overlap. To mitigate, use `numTicks`
|
|
314
|
+
* to reduce labels or `tickFormat` to abbreviate text.
|
|
315
|
+
* - undefined: No truncation; labels may overlap.
|
|
316
|
+
*
|
|
317
|
+
* Default: No truncation; labels may overlap.
|
|
318
|
+
*/
|
|
319
|
+
labelOverflow?: 'ellipsis';
|
|
320
|
+
};
|
|
321
|
+
type ScaleOptions = {
|
|
322
|
+
type?: ScaleType;
|
|
323
|
+
zero?: boolean;
|
|
324
|
+
domain?: [number, number];
|
|
325
|
+
range?: [number, number];
|
|
326
|
+
/**
|
|
327
|
+
* For band scale, shortcut for setting `paddingInner` and `paddingOuter` to the same value.
|
|
328
|
+
*
|
|
329
|
+
* For point scale, the outer padding (spacing) at the ends of the range.
|
|
330
|
+
* This is similar to band scale's `paddingOuter`.
|
|
331
|
+
*
|
|
332
|
+
*/
|
|
333
|
+
padding?: number;
|
|
334
|
+
/**
|
|
335
|
+
* The inner padding (spacing) within each band step of band scales, as a fraction of the step size. This value must lie in the range [0,1].
|
|
336
|
+
*
|
|
337
|
+
*/
|
|
338
|
+
paddingInner?: number;
|
|
339
|
+
/**
|
|
340
|
+
* The outer padding (spacing) at the ends of the range of band and point scales,
|
|
341
|
+
* as a fraction of the step size. This value must lie in the range [0,1].
|
|
342
|
+
*
|
|
343
|
+
*/
|
|
344
|
+
paddingOuter?: number;
|
|
345
|
+
};
|
|
346
|
+
type LegendItemStyles = {
|
|
347
|
+
/** Margin around each legend item. */
|
|
348
|
+
margin?: CSSProperties['margin'];
|
|
349
|
+
/** Flex direction for items within each legend entry. */
|
|
350
|
+
flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse';
|
|
351
|
+
};
|
|
352
|
+
type LegendLabelStyles = Pick<CSSProperties, 'justifyContent' | 'flex' | 'margin'> & {
|
|
353
|
+
/**
|
|
354
|
+
* Maximum width for legend label text as a CSS value (e.g. '200px', '50%', '10rem').
|
|
355
|
+
* When set, text overflow behavior is controlled by textOverflow.
|
|
356
|
+
*/
|
|
357
|
+
maxWidth?: string;
|
|
358
|
+
/**
|
|
359
|
+
* Controls how text behaves when it exceeds maxWidth.
|
|
360
|
+
* - 'ellipsis': Truncate with ellipsis (ideal for widgets/small devices)
|
|
361
|
+
* - 'wrap': Wrap text to multiple lines (default, ideal for larger displays)
|
|
362
|
+
*/
|
|
363
|
+
textOverflow?: 'ellipsis' | 'wrap';
|
|
364
|
+
};
|
|
365
|
+
type LegendShapeStyles = {
|
|
366
|
+
/** Width of the legend shape in pixels. */
|
|
367
|
+
width?: number;
|
|
368
|
+
/** Height of the legend shape in pixels. */
|
|
369
|
+
height?: number;
|
|
370
|
+
/** Margin around the legend shape. */
|
|
371
|
+
margin?: CSSProperties['margin'];
|
|
372
|
+
};
|
|
373
|
+
/** Position of the legend relative to chart content. */
|
|
374
|
+
type LegendPosition = 'top' | 'bottom';
|
|
375
|
+
/**
|
|
376
|
+
* Configuration object for chart legend appearance and behavior.
|
|
377
|
+
* Consolidates all legend styling and layout props into a single structured object.
|
|
378
|
+
*/
|
|
379
|
+
type ChartLegendConfig<T = DataPoint | DataPointDate | LeaderboardEntry> = {
|
|
380
|
+
/**
|
|
381
|
+
* Layout direction of legend items.
|
|
382
|
+
*/
|
|
383
|
+
orientation?: 'horizontal' | 'vertical';
|
|
384
|
+
/**
|
|
385
|
+
* Position of the legend relative to the chart.
|
|
386
|
+
* TODO: Add 'left' | 'right' positioning support in future implementation
|
|
387
|
+
*/
|
|
388
|
+
position?: LegendPosition;
|
|
389
|
+
/**
|
|
390
|
+
* Alignment of the legend within its position.
|
|
391
|
+
*/
|
|
392
|
+
alignment?: 'start' | 'center' | 'end';
|
|
393
|
+
/**
|
|
394
|
+
* Shape of the legend marker icon.
|
|
395
|
+
*/
|
|
396
|
+
shape?: LegendShape<T, number>;
|
|
397
|
+
/**
|
|
398
|
+
* Enable interactive legend items that can toggle series visibility.
|
|
399
|
+
* Supported for all chart types that render series.
|
|
400
|
+
* Requires chartId and GlobalChartsProvider.
|
|
401
|
+
* For pie charts, percentages are recalculated so visible segments total 100%.
|
|
402
|
+
*/
|
|
403
|
+
interactive?: boolean;
|
|
404
|
+
/**
|
|
405
|
+
* Additional CSS class name for individual legend items.
|
|
406
|
+
*/
|
|
407
|
+
itemClassName?: string;
|
|
408
|
+
/**
|
|
409
|
+
* CSS styles for each legend item (margin, flexDirection).
|
|
410
|
+
*/
|
|
411
|
+
itemStyles?: LegendItemStyles;
|
|
412
|
+
/**
|
|
413
|
+
* CSS styles for legend labels (maxWidth, textOverflow, justifyContent, flex, margin).
|
|
414
|
+
*/
|
|
415
|
+
labelStyles?: LegendLabelStyles;
|
|
416
|
+
/**
|
|
417
|
+
* Styles for legend shapes (width, height, margin).
|
|
418
|
+
*/
|
|
419
|
+
shapeStyles?: LegendShapeStyles;
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* Base properties shared across all chart components
|
|
423
|
+
*/
|
|
424
|
+
type BaseChartProps<T = DataPoint | DataPointDate | LeaderboardEntry> = {
|
|
425
|
+
/**
|
|
426
|
+
* Array of data points to display in the chart
|
|
427
|
+
*/
|
|
428
|
+
data: T extends DataPoint | DataPointDate | LeaderboardEntry ? T[] : T;
|
|
429
|
+
/**
|
|
430
|
+
* Optional unique identifier for the chart (auto-generated if not provided)
|
|
431
|
+
*/
|
|
432
|
+
chartId?: string;
|
|
433
|
+
/**
|
|
434
|
+
* Additional CSS class name for the chart container
|
|
435
|
+
*/
|
|
436
|
+
className?: string;
|
|
437
|
+
/**
|
|
438
|
+
* Width of the chart container in pixels. When omitted, the chart fills its parent's width.
|
|
439
|
+
*/
|
|
440
|
+
width?: number;
|
|
441
|
+
/**
|
|
442
|
+
* Height of the chart container in pixels. When omitted, the chart fills its parent's height.
|
|
443
|
+
*/
|
|
444
|
+
height?: number;
|
|
445
|
+
/**
|
|
446
|
+
* Maximum diameter of the pie in pixels (pie and donut charts only).
|
|
447
|
+
* The pie will shrink if the container is smaller than this value.
|
|
448
|
+
* When omitted, the pie fills the available space.
|
|
449
|
+
*/
|
|
450
|
+
size?: number;
|
|
451
|
+
/**
|
|
452
|
+
* Chart margins
|
|
453
|
+
*/
|
|
454
|
+
margin?: {
|
|
455
|
+
top?: number;
|
|
456
|
+
right?: number;
|
|
457
|
+
bottom?: number;
|
|
458
|
+
left?: number;
|
|
459
|
+
};
|
|
460
|
+
/**
|
|
461
|
+
* Callback function for pointer down event
|
|
462
|
+
*/
|
|
463
|
+
onPointerDown?: (event: EventHandlerParams<DataPoint | DataPointDate>) => void;
|
|
464
|
+
/**
|
|
465
|
+
* Callback function for pointer up event
|
|
466
|
+
*/
|
|
467
|
+
onPointerUp?: (event: EventHandlerParams<DataPoint | DataPointDate>) => void;
|
|
468
|
+
/**
|
|
469
|
+
* Callback function for pointer move event
|
|
470
|
+
*/
|
|
471
|
+
onPointerMove?: (event: EventHandlerParams<DataPoint | DataPointDate>) => void;
|
|
472
|
+
/**
|
|
473
|
+
* Callback function for pointer out event
|
|
474
|
+
*/
|
|
475
|
+
onPointerOut?: (event: PointerEvent<Element>) => void;
|
|
476
|
+
/**
|
|
477
|
+
* Whether to show tooltips on hover. False by default.
|
|
478
|
+
*/
|
|
479
|
+
withTooltips?: boolean;
|
|
480
|
+
/**
|
|
481
|
+
* Whether to show legend
|
|
482
|
+
*/
|
|
483
|
+
showLegend?: boolean;
|
|
484
|
+
/**
|
|
485
|
+
* Legend configuration object for controlling legend appearance and behavior.
|
|
486
|
+
* Includes orientation, position, alignment, shape, styling, and interactivity options.
|
|
487
|
+
*/
|
|
488
|
+
legend?: ChartLegendConfig<T>;
|
|
489
|
+
/**
|
|
490
|
+
* Grid visibility. x is default when orientation is vertical. y is default when orientation is horizontal.
|
|
491
|
+
*/
|
|
492
|
+
gridVisibility?: 'x' | 'y' | 'xy' | 'none';
|
|
493
|
+
/**
|
|
494
|
+
* Whether to show chart animation on initial render or not
|
|
495
|
+
*/
|
|
496
|
+
animation?: boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Gap between chart elements (SVG, legend, children).
|
|
499
|
+
* Uses WordPress design system tokens.
|
|
500
|
+
* @default 'md'
|
|
501
|
+
*/
|
|
502
|
+
gap?: GapSize;
|
|
503
|
+
/**
|
|
504
|
+
* More options for the chart.
|
|
505
|
+
*/
|
|
506
|
+
options?: {
|
|
507
|
+
yScale?: ScaleOptions;
|
|
508
|
+
xScale?: ScaleOptions;
|
|
509
|
+
axis?: {
|
|
510
|
+
x?: AxisOptions;
|
|
511
|
+
y?: AxisOptions;
|
|
512
|
+
};
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* Properties for grid components
|
|
517
|
+
*/
|
|
518
|
+
type GridProps = {
|
|
519
|
+
/**
|
|
520
|
+
* Width of the grid in pixels
|
|
521
|
+
*/
|
|
522
|
+
width: number;
|
|
523
|
+
/**
|
|
524
|
+
* Height of the grid in pixels
|
|
525
|
+
*/
|
|
526
|
+
height: number;
|
|
527
|
+
/**
|
|
528
|
+
* Grid visibility. x is default.
|
|
529
|
+
*/
|
|
530
|
+
gridVisibility?: 'x' | 'y' | 'xy' | 'none';
|
|
531
|
+
/**
|
|
532
|
+
* X-axis scale for the grid
|
|
533
|
+
* TODO: Fix any type after resolving visx scale type issues
|
|
534
|
+
*/
|
|
535
|
+
xScale: any;
|
|
536
|
+
/**
|
|
537
|
+
* Y-axis scale for the grid
|
|
538
|
+
* TODO: Fix any type after resolving visx scale type issues
|
|
539
|
+
*/
|
|
540
|
+
yScale: any;
|
|
541
|
+
/**
|
|
542
|
+
* Top offset for the grid
|
|
543
|
+
*/
|
|
544
|
+
top?: number;
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
type VisxLegendProps = Pick<ComponentProps<typeof LegendOrdinal>, 'className' | 'shape' | 'fill' | 'size' | 'labelFormat' | 'labelTransform'>;
|
|
548
|
+
type BaseLegendProps = VisxLegendProps & {
|
|
549
|
+
items: BaseLegendItem[];
|
|
550
|
+
orientation?: 'horizontal' | 'vertical';
|
|
551
|
+
position?: LegendPosition;
|
|
552
|
+
alignment?: 'start' | 'center' | 'end';
|
|
553
|
+
/** Additional CSS class name for legend items. */
|
|
554
|
+
itemClassName?: string;
|
|
555
|
+
/** CSS styles for each legend item (margin, flexDirection). */
|
|
556
|
+
itemStyles?: LegendItemStyles;
|
|
557
|
+
/** Additional CSS class name for legend labels. */
|
|
558
|
+
labelClassName?: string;
|
|
559
|
+
/** CSS styles for legend labels (justifyContent, flex, margin). */
|
|
560
|
+
labelStyles?: LegendLabelStyles;
|
|
561
|
+
/** Styles for legend shapes (width, height, margin). */
|
|
562
|
+
shapeStyles?: LegendShapeStyles;
|
|
563
|
+
/**
|
|
564
|
+
* Function for rendering a custom legend layout.
|
|
565
|
+
*/
|
|
566
|
+
render?: (items: BaseLegendItem[]) => ReactNode;
|
|
567
|
+
/**
|
|
568
|
+
* Enable interactive legend items that can toggle series visibility.
|
|
569
|
+
* Requires GlobalChartsProvider and chartId to be set.
|
|
570
|
+
*/
|
|
571
|
+
interactive?: boolean;
|
|
572
|
+
/**
|
|
573
|
+
* Chart ID for series visibility tracking when interactive mode is enabled.
|
|
574
|
+
*/
|
|
575
|
+
chartId?: string;
|
|
576
|
+
};
|
|
577
|
+
type LegendProps = Omit<BaseLegendProps, 'items'> & {
|
|
578
|
+
items?: BaseLegendItem[];
|
|
579
|
+
chartId?: string;
|
|
580
|
+
};
|
|
581
|
+
type BaseLegendItem = {
|
|
582
|
+
label: string;
|
|
583
|
+
value?: number | string;
|
|
584
|
+
color: string;
|
|
585
|
+
glyphSize?: number;
|
|
586
|
+
renderGlyph?: <Datum extends object>(props: GlyphProps<Datum>) => ReactNode;
|
|
587
|
+
shapeStyle?: CSSProperties & LineStyles;
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
declare const Legend: react.ForwardRefExoticComponent<Omit<BaseLegendProps, "items"> & {
|
|
591
|
+
items?: BaseLegendItem[];
|
|
592
|
+
chartId?: string;
|
|
593
|
+
} & react.RefAttributes<HTMLDivElement>>;
|
|
594
|
+
|
|
595
|
+
type LegendValueDisplay = 'percentage' | 'value' | 'valueDisplay' | 'none';
|
|
596
|
+
interface ChartLegendOptions {
|
|
597
|
+
withGlyph?: boolean;
|
|
598
|
+
glyphSize?: number;
|
|
599
|
+
renderGlyph?: <Datum extends object>(props: GlyphProps<Datum>) => ReactNode;
|
|
600
|
+
showValues?: boolean;
|
|
601
|
+
legendValueDisplay?: LegendValueDisplay;
|
|
602
|
+
legendShape?: LegendShape<SeriesData[], number>;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Hook to transform chart data into legend items
|
|
606
|
+
* @param data - The chart data to transform
|
|
607
|
+
* @param options - Configuration options for legend generation
|
|
608
|
+
* @param legendShape - The shape type for legend items (string literal or React component)
|
|
609
|
+
* @return Array of legend items ready for display
|
|
610
|
+
*/
|
|
611
|
+
declare function useChartLegendItems<T extends SeriesData[] | DataPointDate[] | DataPointPercentageCalculated[]>(data: T, options?: ChartLegendOptions, legendShape?: LegendShape<SeriesData[], number>): BaseLegendItem[];
|
|
612
|
+
|
|
613
|
+
type ResponsiveConfig = {
|
|
614
|
+
/**
|
|
615
|
+
* The maximum width of the chart. Defaults to 1200.
|
|
616
|
+
*/
|
|
617
|
+
maxWidth?: number;
|
|
618
|
+
/**
|
|
619
|
+
* The aspect ratio of the chart (height = width * aspectRatio).
|
|
620
|
+
* When provided, height is calculated from width.
|
|
621
|
+
* When omitted, the chart fills the parent container's height.
|
|
622
|
+
*/
|
|
623
|
+
aspectRatio?: number;
|
|
624
|
+
/**
|
|
625
|
+
* Child render updates upon resize are delayed until debounceTime milliseconds after the last resize event is observed.
|
|
626
|
+
*/
|
|
627
|
+
resizeDebounceTime?: number;
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
interface BarChartProps extends BaseChartProps<SeriesData[]> {
|
|
631
|
+
renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
|
|
632
|
+
orientation?: 'horizontal' | 'vertical';
|
|
633
|
+
withPatterns?: boolean;
|
|
634
|
+
showZeroValues?: boolean;
|
|
635
|
+
children?: ReactNode;
|
|
636
|
+
}
|
|
637
|
+
type BarChartBaseProps = Optional<BarChartProps, 'width' | 'height' | 'size'>;
|
|
638
|
+
interface BarChartSubComponents {
|
|
639
|
+
Legend: ComponentType<React.ComponentProps<typeof Legend>>;
|
|
640
|
+
}
|
|
641
|
+
type BarChartComponent = FC<BarChartBaseProps> & BarChartSubComponents;
|
|
642
|
+
type BarChartResponsiveComponent = FC<BarChartBaseProps & ResponsiveConfig> & BarChartSubComponents;
|
|
643
|
+
declare const BarChart: BarChartComponent;
|
|
644
|
+
declare const BarChartResponsive: BarChartResponsiveComponent;
|
|
645
|
+
|
|
646
|
+
interface BarListChartProps extends Exclude<BarChartProps, 'orientation' | 'size' | 'gridVisibility'> {
|
|
647
|
+
options?: {
|
|
648
|
+
/**
|
|
649
|
+
* Scale for the y axis. Exclude the type property.
|
|
650
|
+
*/
|
|
651
|
+
yScale: Omit<ScaleOptions, 'type'>;
|
|
652
|
+
/**
|
|
653
|
+
* Scale for the x axis. Exclude the type property.
|
|
654
|
+
*/
|
|
655
|
+
xScale: Omit<ScaleOptions, 'type'>;
|
|
656
|
+
/**
|
|
657
|
+
* Formatter for the label.
|
|
658
|
+
*/
|
|
659
|
+
labelFormatter?: (value: string) => string;
|
|
660
|
+
/**
|
|
661
|
+
* Formatter for the value.
|
|
662
|
+
*/
|
|
663
|
+
valueFormatter?: (value: number) => string;
|
|
664
|
+
/**
|
|
665
|
+
* y offset of the label and value. Default is based on the number of series, automatically computed.
|
|
666
|
+
*/
|
|
667
|
+
yOffset?: number;
|
|
668
|
+
/**
|
|
669
|
+
* x position of the label.
|
|
670
|
+
*/
|
|
671
|
+
labelPosition?: number;
|
|
672
|
+
/**
|
|
673
|
+
* x position of the value.
|
|
674
|
+
*/
|
|
675
|
+
valuePosition?: number;
|
|
676
|
+
/**
|
|
677
|
+
* Custom render function for the label.
|
|
678
|
+
*/
|
|
679
|
+
labelComponent?: ComponentType<RenderLabelProps>;
|
|
680
|
+
/**
|
|
681
|
+
* Custom render function for the value.
|
|
682
|
+
*/
|
|
683
|
+
valueComponent?: ComponentType<RenderValueProps>;
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
interface RenderLabelProps {
|
|
687
|
+
textProps: TextProps$1;
|
|
688
|
+
x: number;
|
|
689
|
+
y: number;
|
|
690
|
+
label: string;
|
|
691
|
+
formatter: (value: string) => string;
|
|
692
|
+
}
|
|
693
|
+
interface RenderValueProps {
|
|
694
|
+
textProps: TextProps$1;
|
|
695
|
+
x: number;
|
|
696
|
+
y: number;
|
|
697
|
+
value: number;
|
|
698
|
+
/**
|
|
699
|
+
* Original data
|
|
700
|
+
*/
|
|
701
|
+
data: SeriesData[];
|
|
702
|
+
/**
|
|
703
|
+
* Index of the data point
|
|
704
|
+
*/
|
|
705
|
+
index: number;
|
|
706
|
+
formatter: (value: number) => string;
|
|
707
|
+
}
|
|
708
|
+
declare const BarListChart: FC<BarListChartProps>;
|
|
709
|
+
declare const BarListChartResponsive: ({ resizeDebounceTime, maxWidth, aspectRatio, size, width, height, ...chartProps }: Omit<BarListChartProps, "width" | "height" | "size"> & {
|
|
710
|
+
width?: number;
|
|
711
|
+
height?: number;
|
|
712
|
+
size?: number;
|
|
713
|
+
} & ResponsiveConfig) => react_jsx_runtime.JSX.Element;
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Represents a single step in the conversion funnel
|
|
717
|
+
*/
|
|
718
|
+
interface FunnelStep {
|
|
719
|
+
/** Step identifier */
|
|
720
|
+
id: string;
|
|
721
|
+
/** Display label for the step */
|
|
722
|
+
label: string;
|
|
723
|
+
/** Conversion rate as percentage (0-100) */
|
|
724
|
+
rate: number;
|
|
725
|
+
/** Absolute count (optional, for tooltip/details) */
|
|
726
|
+
count?: number;
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Render prop for customizing step labels
|
|
730
|
+
*/
|
|
731
|
+
interface StepLabelRenderProps {
|
|
732
|
+
step: FunnelStep;
|
|
733
|
+
index: number;
|
|
734
|
+
className?: string;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Render prop for customizing step rates
|
|
738
|
+
*/
|
|
739
|
+
interface StepRateRenderProps {
|
|
740
|
+
step: FunnelStep;
|
|
741
|
+
index: number;
|
|
742
|
+
className?: string;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Render prop for customizing the entire main metric section
|
|
746
|
+
*/
|
|
747
|
+
interface MainMetricRenderProps {
|
|
748
|
+
mainRate: number;
|
|
749
|
+
changeIndicator?: string;
|
|
750
|
+
className?: string;
|
|
751
|
+
changeColor?: string;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Render prop for customizing tooltip content
|
|
755
|
+
*/
|
|
756
|
+
interface TooltipRenderProps {
|
|
757
|
+
step: FunnelStep;
|
|
758
|
+
index: number;
|
|
759
|
+
top: number;
|
|
760
|
+
left: number;
|
|
761
|
+
className?: string;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Props for the ConversionFunnelChart component
|
|
765
|
+
*/
|
|
766
|
+
interface ConversionFunnelChartProps extends Pick<BaseChartProps, 'className' | 'chartId' | 'animation'> {
|
|
767
|
+
/** Main conversion rate to highlight */
|
|
768
|
+
mainRate: number;
|
|
769
|
+
/** Change indicator (e.g., +2%, -1.5%) */
|
|
770
|
+
changeIndicator?: string;
|
|
771
|
+
/** Array of funnel steps */
|
|
772
|
+
steps: FunnelStep[];
|
|
773
|
+
/** Whether the chart is in loading state */
|
|
774
|
+
loading?: boolean;
|
|
775
|
+
/** Height of the chart container. Accepts a number (pixels) or CSS string (e.g., "400px", "100%"). Falls back to style.height if set, otherwise defaults to "100%". */
|
|
776
|
+
height?: string | number;
|
|
777
|
+
/** Custom styling */
|
|
778
|
+
style?: React.CSSProperties;
|
|
779
|
+
/** Custom render function for step labels */
|
|
780
|
+
renderStepLabel?: (props: StepLabelRenderProps) => React.ReactNode;
|
|
781
|
+
/** Custom render function for step rates */
|
|
782
|
+
renderStepRate?: (props: StepRateRenderProps) => React.ReactNode;
|
|
783
|
+
/** Custom render function for the entire main metric section */
|
|
784
|
+
renderMainMetric?: (props: MainMetricRenderProps) => React.ReactNode;
|
|
785
|
+
/** Custom render function for tooltip content */
|
|
786
|
+
renderTooltip?: (props: TooltipRenderProps) => React.ReactNode;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* ConversionFunnelChart component with provider wrapper
|
|
791
|
+
*
|
|
792
|
+
* @param props - Component props
|
|
793
|
+
* @return JSX element representing the conversion funnel chart
|
|
794
|
+
*/
|
|
795
|
+
declare const ConversionFunnelChartWithProvider: FC<ConversionFunnelChartProps>;
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Region to display on the map.
|
|
799
|
+
* Use 'world' for global view or any ISO 3166-1 alpha-2 country code
|
|
800
|
+
* (e.g., 'US' for United States, 'CA' for Canada).
|
|
801
|
+
*/
|
|
802
|
+
type GeoRegion = 'world' | (string & {});
|
|
803
|
+
/**
|
|
804
|
+
* Resolution level for the map.
|
|
805
|
+
* - 'countries': Country-level (default for 'world')
|
|
806
|
+
* - 'provinces': State/province level (use with specific region like 'US')
|
|
807
|
+
* - 'metros': Metropolitan areas (US only)
|
|
808
|
+
*/
|
|
809
|
+
type GeoResolution = 'countries' | 'provinces' | 'metros';
|
|
810
|
+
interface GeoChartProps extends Pick<BaseChartProps, 'className' | 'chartId' | 'width' | 'height'> {
|
|
811
|
+
/**
|
|
812
|
+
* Data in Google Charts native format for maximum flexibility.
|
|
813
|
+
* First row contains column headers, subsequent rows contain data.
|
|
814
|
+
*
|
|
815
|
+
* Country identifiers can be either full country names or ISO 3166-1 alpha-2 codes
|
|
816
|
+
* (e.g., 'United States' or 'US').
|
|
817
|
+
*/
|
|
818
|
+
data: GeoData;
|
|
819
|
+
/**
|
|
820
|
+
* Region to display. Use 'world' for global view, 'US' for United States,
|
|
821
|
+
* or any ISO 3166-1 alpha-2 country code.
|
|
822
|
+
* @default 'world'
|
|
823
|
+
*/
|
|
824
|
+
region?: GeoRegion;
|
|
825
|
+
/**
|
|
826
|
+
* Resolution level for the map.
|
|
827
|
+
* - 'countries': Country-level (default for 'world')
|
|
828
|
+
* - 'provinces': State/province level (use with specific region like 'US')
|
|
829
|
+
* - 'metros': Metropolitan areas (US only)
|
|
830
|
+
* @default 'countries'
|
|
831
|
+
*/
|
|
832
|
+
resolution?: GeoResolution;
|
|
833
|
+
/**
|
|
834
|
+
* Optional render function for the loading placeholder.
|
|
835
|
+
* Called while Google Charts is loading.
|
|
836
|
+
*/
|
|
837
|
+
renderPlaceholder?: () => React.ReactNode;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
declare const GeoChartWithProvider: FC<GeoChartProps>;
|
|
841
|
+
declare const GeoChartResponsive: ({ resizeDebounceTime, maxWidth, aspectRatio, size, width, height, ...chartProps }: Omit<GeoChartProps, "width" | "height" | "size"> & {
|
|
842
|
+
width?: number;
|
|
843
|
+
height?: number;
|
|
844
|
+
size?: number;
|
|
845
|
+
} & ResponsiveConfig) => react_jsx_runtime.JSX.Element;
|
|
846
|
+
|
|
847
|
+
interface LeaderboardChartProps extends Pick<BaseChartProps<LeaderboardEntry>, 'className' | 'data' | 'showLegend' | 'legend' | 'chartId' | 'width' | 'height' | 'size' | 'gap' | 'animation'> {
|
|
848
|
+
/**
|
|
849
|
+
* Whether to show comparison data
|
|
850
|
+
*/
|
|
851
|
+
withComparison?: boolean;
|
|
852
|
+
/**
|
|
853
|
+
* Whether to overlay the label on top of bar
|
|
854
|
+
*/
|
|
855
|
+
withOverlayLabel?: boolean;
|
|
856
|
+
/**
|
|
857
|
+
* Primary color for current period bars
|
|
858
|
+
*/
|
|
859
|
+
primaryColor?: string;
|
|
860
|
+
/**
|
|
861
|
+
* Secondary color for comparison period bars
|
|
862
|
+
*/
|
|
863
|
+
secondaryColor?: string;
|
|
864
|
+
/**
|
|
865
|
+
* Formatter for values
|
|
866
|
+
*/
|
|
867
|
+
valueFormatter?: (value: number) => string;
|
|
868
|
+
/**
|
|
869
|
+
* Formatter for delta values
|
|
870
|
+
*/
|
|
871
|
+
deltaFormatter?: (value: number) => string;
|
|
872
|
+
/**
|
|
873
|
+
* Whether the chart is in loading state
|
|
874
|
+
*/
|
|
875
|
+
loading?: boolean;
|
|
876
|
+
/**
|
|
877
|
+
* Custom styling for the chart container
|
|
878
|
+
*/
|
|
879
|
+
style?: React.CSSProperties & {
|
|
880
|
+
'--a8c--charts--leaderboard--bar--border-radius'?: string;
|
|
881
|
+
};
|
|
882
|
+
/**
|
|
883
|
+
* Custom labels for legend items
|
|
884
|
+
*/
|
|
885
|
+
legendLabels?: {
|
|
886
|
+
/**
|
|
887
|
+
* Label for primary period data
|
|
888
|
+
*/
|
|
889
|
+
primary?: string;
|
|
890
|
+
/**
|
|
891
|
+
* Label for comparison period data (only used when withComparison is true)
|
|
892
|
+
*/
|
|
893
|
+
comparison?: string;
|
|
894
|
+
};
|
|
895
|
+
/**
|
|
896
|
+
* Child components for composition API
|
|
897
|
+
*/
|
|
898
|
+
children?: ReactNode;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
declare const LeaderboardChart: FC<LeaderboardChartProps> & {
|
|
902
|
+
Legend: react.ForwardRefExoticComponent<Omit<BaseLegendProps, "items"> & {
|
|
903
|
+
items?: BaseLegendItem[];
|
|
904
|
+
chartId?: string;
|
|
905
|
+
} & react.RefAttributes<HTMLDivElement>>;
|
|
906
|
+
};
|
|
907
|
+
declare const LeaderboardChartResponsive: (({ resizeDebounceTime, maxWidth, aspectRatio, size, width, height, ...chartProps }: Omit<LeaderboardChartProps, "width" | "height" | "size"> & {
|
|
908
|
+
width?: number;
|
|
909
|
+
height?: number;
|
|
910
|
+
size?: number;
|
|
911
|
+
} & ResponsiveConfig) => react_jsx_runtime.JSX.Element) & {
|
|
912
|
+
Legend: react.ForwardRefExoticComponent<Omit<BaseLegendProps, "items"> & {
|
|
913
|
+
items?: BaseLegendItem[];
|
|
914
|
+
chartId?: string;
|
|
915
|
+
} & react.RefAttributes<HTMLDivElement>>;
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* @file Date parsing utilities using date-fns for local timezone handling
|
|
920
|
+
*
|
|
921
|
+
* This module provides utilities for parsing various date string formats and converting
|
|
922
|
+
* them to local timezone dates using the battle-tested date-fns library. For formats
|
|
923
|
+
* without timezone info, they're treated as local. For formats with timezone info,
|
|
924
|
+
* they're converted to the equivalent local time.
|
|
925
|
+
*
|
|
926
|
+
* Note: And specifically it prevents format `YYYY-MM-DD` being parsed as UTC date.
|
|
927
|
+
*
|
|
928
|
+
* Key Features:
|
|
929
|
+
* - All parsed dates are in local timezone
|
|
930
|
+
* - Converts timezone-aware strings to local equivalent
|
|
931
|
+
* - Robust input validation and error handling using date-fns
|
|
932
|
+
* - TypeScript type safety
|
|
933
|
+
* - Much smaller codebase than custom parsing
|
|
934
|
+
*
|
|
935
|
+
* Supported Formats:
|
|
936
|
+
* - YYYY-MM-DD (treated as local)
|
|
937
|
+
* - YYYY-MM-DD HH:mm:ss (treated as local)
|
|
938
|
+
* - YYYY-MM-DD HH:mm (treated as local)
|
|
939
|
+
* - YYYY-MM-DDTHH:mm:ss (treated as local)
|
|
940
|
+
* - YYYY-MM-DDTHH:mm:ss.SSS (treated as local)
|
|
941
|
+
* - YYYY-MM-DDTHH:mm (treated as local)
|
|
942
|
+
* - YYYY-MM-DDTHH:mm:ssZ (converted to local)
|
|
943
|
+
* - YYYY-MM-DDTHH:mm:ss±HH:mm (converted to local)
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* ```typescript
|
|
947
|
+
* parseAsLocalDate("2025-01-01"); // Local timezone
|
|
948
|
+
* parseAsLocalDate("2025-01-01 14:30:00"); // Local timezone
|
|
949
|
+
* parseAsLocalDate("2025-01-01 14:30"); // Local timezone
|
|
950
|
+
* parseAsLocalDate("2025-01-01T14:30:45.123"); // Local timezone
|
|
951
|
+
* parseAsLocalDate("2025-01-01T14:30:00Z"); // UTC 14:30 → Local equivalent
|
|
952
|
+
* parseAsLocalDate("2025-01-01T14:30:00+05:00"); // +05:00 14:30 → Local equivalent
|
|
953
|
+
* ```
|
|
954
|
+
*/
|
|
955
|
+
/**
|
|
956
|
+
* Parses any supported date string format and returns a local timezone date
|
|
957
|
+
*
|
|
958
|
+
* Uses date-fns for robust parsing and validation. For strings without timezone
|
|
959
|
+
* info, treats as local timezone. For strings with timezone info, converts to
|
|
960
|
+
* local timezone equivalent.
|
|
961
|
+
*
|
|
962
|
+
* Supports:
|
|
963
|
+
* - YYYY-MM-DD (local)
|
|
964
|
+
* - YYYY-MM-DD HH:mm:ss (local)
|
|
965
|
+
* - YYYY-MM-DD HH:mm (local)
|
|
966
|
+
* - YYYY-MM-DDTHH:mm:ss (local)
|
|
967
|
+
* - YYYY-MM-DDTHH:mm:ss.SSS (local)
|
|
968
|
+
* - YYYY-MM-DDTHH:mm (local)
|
|
969
|
+
* - YYYY-MM-DDTHH:mm:ssZ (UTC → local)
|
|
970
|
+
* - YYYY-MM-DDTHH:mm:ss±HH:mm (offset → local)
|
|
971
|
+
* @param {string} dateString - The date string to parse into a local timezone date
|
|
972
|
+
* @return {Date} A Date object representing the parsed date in local timezone, or an invalid Date if parsing fails
|
|
973
|
+
*/
|
|
974
|
+
declare const parseAsLocalDate: (dateString: string) => Date;
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Types for formatMetricValue
|
|
978
|
+
*/
|
|
979
|
+
type MetricValueType = 'number' | 'average' | 'currency';
|
|
980
|
+
type FormatMetricValueOptions = {
|
|
981
|
+
decimals?: number;
|
|
982
|
+
useMultipliers?: boolean;
|
|
983
|
+
signDisplay?: Intl.NumberFormatOptions['signDisplay'];
|
|
984
|
+
};
|
|
985
|
+
/**
|
|
986
|
+
* Format a numeric metric value based on type, precision and scale.
|
|
987
|
+
* Supports currency, number and percentage, using `@automattic/number-formatters`.
|
|
988
|
+
*
|
|
989
|
+
* @param value - The value to format
|
|
990
|
+
* @param type - The type of formatting to apply
|
|
991
|
+
* @param options - Formatting options
|
|
992
|
+
* @param options.decimals - Number of decimal places to show
|
|
993
|
+
* @param options.useMultipliers - Whether to use K, M, B suffixes for large numbers
|
|
994
|
+
* @param options.signDisplay - Controls when to display the sign (auto, always, never, exceptZero)
|
|
995
|
+
* @return Formatted string
|
|
996
|
+
*/
|
|
997
|
+
declare const formatMetricValue: (value: string | number, type?: MetricValueType, { decimals, useMultipliers, signDisplay }?: FormatMetricValueOptions) => string;
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Format a percentage value with smart decimal handling.
|
|
1001
|
+
* Uses `@automattic/number-formatters` for consistent formatting.
|
|
1002
|
+
* Removes unnecessary trailing zeros and caps at 2 decimal places.
|
|
1003
|
+
*
|
|
1004
|
+
* @param value - The percentage value (0-100 range)
|
|
1005
|
+
* @return Formatted percentage string (e.g., "30%", "30.1%", "30.25%")
|
|
1006
|
+
*/
|
|
1007
|
+
declare const formatPercentage: (value: number) => string;
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Merges chart themes with proper precedence.
|
|
1011
|
+
* The second theme (override) takes precedence over the first theme (base).
|
|
1012
|
+
*
|
|
1013
|
+
* @param baseTheme - Base theme object
|
|
1014
|
+
* @param overrideTheme - Theme to override base with (takes precedence)
|
|
1015
|
+
* @return Merged theme with overrideTheme values taking precedence
|
|
1016
|
+
*/
|
|
1017
|
+
declare function mergeThemes(baseTheme: CompleteChartTheme, overrideTheme: Partial<ChartTheme>): CompleteChartTheme;
|
|
1018
|
+
declare function mergeThemes(baseTheme: ChartTheme, overrideTheme: Partial<ChartTheme>): ChartTheme;
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Check if a value is a valid 6-digit hex color
|
|
1022
|
+
* @param hex - The value to check
|
|
1023
|
+
* @return true if valid hex color format (e.g., '#ff0000')
|
|
1024
|
+
*/
|
|
1025
|
+
declare const isValidHexColor: (hex: unknown) => hex is string;
|
|
1026
|
+
/**
|
|
1027
|
+
* Validate hex color format, throwing descriptive errors if invalid
|
|
1028
|
+
* @param hex - The hex color string to validate
|
|
1029
|
+
* @throws {Error} if hex string is malformed
|
|
1030
|
+
*/
|
|
1031
|
+
declare const validateHexColor: (hex: unknown) => void;
|
|
1032
|
+
/**
|
|
1033
|
+
* Convert hex color to rgba with specified opacity.
|
|
1034
|
+
* This is genuinely reusable across chart components.
|
|
1035
|
+
* @param hex - The hex color string (e.g., '#ff0000')
|
|
1036
|
+
* @param alpha - The opacity value. Values outside the [0, 1] range will be clamped by the underlying d3 color library.
|
|
1037
|
+
* @return The rgba color string (e.g., 'rgba(255, 0, 0, 0.5)')
|
|
1038
|
+
* @throws {Error} if hex string is malformed or alpha is not a valid number
|
|
1039
|
+
*/
|
|
1040
|
+
declare const hexToRgba: (hex: string, alpha: number) => string;
|
|
1041
|
+
/**
|
|
1042
|
+
* Calculate the perceptual distance between two HSL colors
|
|
1043
|
+
* @param hsl1 - first color in HSL format [h, s, l]
|
|
1044
|
+
* @param hsl2 - second color in HSL format [h, s, l]
|
|
1045
|
+
* @return distance value (0-100+, lower means more similar)
|
|
1046
|
+
*/
|
|
1047
|
+
declare const getColorDistance: (hsl1: [number, number, number], hsl2: [number, number, number]) => number;
|
|
1048
|
+
/**
|
|
1049
|
+
* Parse an HSL string like 'hsl(120, 50%, 50%)' into an HSL tuple.
|
|
1050
|
+
*
|
|
1051
|
+
* @param hslString - HSL color string
|
|
1052
|
+
* @return HSL tuple [h, s, l] or null if invalid
|
|
1053
|
+
*/
|
|
1054
|
+
declare const parseHslString: (hslString: string) => [number, number, number] | null;
|
|
1055
|
+
/**
|
|
1056
|
+
* Parse an RGB string like 'rgb(255, 0, 0)' into a hex color.
|
|
1057
|
+
*
|
|
1058
|
+
* @param rgbString - RGB color string
|
|
1059
|
+
* @return hex color string or null if invalid
|
|
1060
|
+
*/
|
|
1061
|
+
declare const parseRgbString: (rgbString: string) => string | null;
|
|
1062
|
+
/**
|
|
1063
|
+
* Normalize any CSS color value to a hex color string.
|
|
1064
|
+
* Handles hex colors, HSL strings, RGB strings, and CSS variables.
|
|
1065
|
+
*
|
|
1066
|
+
* @param color - Any CSS color value
|
|
1067
|
+
* @param element - Optional DOM element for resolving CSS variables
|
|
1068
|
+
* @param resolveCss - Function to resolve CSS variables (injected for testability)
|
|
1069
|
+
* @return hex color string, or the original value if conversion fails
|
|
1070
|
+
*/
|
|
1071
|
+
declare const normalizeColorToHex: (color: string, element?: HTMLElement | null, resolveCss?: (value: string, el?: HTMLElement | null) => string | null) => string;
|
|
1072
|
+
/**
|
|
1073
|
+
* Lighten a hex color by blending it with white.
|
|
1074
|
+
* Useful for creating color gradients or lighter variants.
|
|
1075
|
+
*
|
|
1076
|
+
* @param hex - Hex color string (e.g., '#98C8DF')
|
|
1077
|
+
* @param blend - Blend amount with white (0 = original color, 1 = white)
|
|
1078
|
+
* @return Lightened hex color string (e.g., '#cce4ef')
|
|
1079
|
+
* @throws {Error} if hex string is malformed
|
|
1080
|
+
*/
|
|
1081
|
+
declare const lightenHexColor: (hex: string, blend: number) => string;
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Hook to create legend items from leaderboard data
|
|
1085
|
+
* @param root0 - Configuration object
|
|
1086
|
+
* @param root0.data - Array of leaderboard entries
|
|
1087
|
+
* @param root0.primaryColor - Primary color override
|
|
1088
|
+
* @param root0.secondaryColor - Secondary color override
|
|
1089
|
+
* @param root0.withComparison - Whether comparison data is shown
|
|
1090
|
+
* @param root0.withOverlayLabel - Whether to overlay the label on top of the bar
|
|
1091
|
+
* @param root0.legendLabels - Custom labels for legend items
|
|
1092
|
+
* @param root0.legendLabels.primary - Label for primary period data
|
|
1093
|
+
* @param root0.legendLabels.comparison - Label for comparison period data
|
|
1094
|
+
* @return Array of legend items for the leaderboard chart
|
|
1095
|
+
*/
|
|
1096
|
+
declare function useLeaderboardLegendItems({ data, primaryColor, secondaryColor, withComparison, withOverlayLabel, legendLabels, }: {
|
|
1097
|
+
data: LeaderboardEntry[];
|
|
1098
|
+
primaryColor?: string;
|
|
1099
|
+
secondaryColor?: string;
|
|
1100
|
+
withComparison: boolean;
|
|
1101
|
+
withOverlayLabel: boolean;
|
|
1102
|
+
legendLabels?: {
|
|
1103
|
+
primary?: string;
|
|
1104
|
+
comparison?: string;
|
|
1105
|
+
};
|
|
1106
|
+
}): BaseLegendItem[];
|
|
1107
|
+
|
|
1108
|
+
interface ChartInstanceRef {
|
|
1109
|
+
getScales: () => {
|
|
1110
|
+
xScale: unknown;
|
|
1111
|
+
yScale: unknown;
|
|
1112
|
+
} | null;
|
|
1113
|
+
getChartDimensions: () => {
|
|
1114
|
+
width: number;
|
|
1115
|
+
height: number;
|
|
1116
|
+
margin: {
|
|
1117
|
+
top?: number;
|
|
1118
|
+
right?: number;
|
|
1119
|
+
bottom?: number;
|
|
1120
|
+
left?: number;
|
|
1121
|
+
};
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
type SingleChartRef = ChartInstanceRef;
|
|
1125
|
+
|
|
1126
|
+
interface LineChartAnnotationsProps {
|
|
1127
|
+
children?: ReactNode;
|
|
1128
|
+
}
|
|
1129
|
+
declare const LineChartAnnotationsOverlay: FC<LineChartAnnotationsProps>;
|
|
1130
|
+
|
|
1131
|
+
type LineChartAnnotationProps = {
|
|
1132
|
+
datum: DataPointDate;
|
|
1133
|
+
title: string;
|
|
1134
|
+
subtitle?: string;
|
|
1135
|
+
subjectType?: 'circle' | 'line-vertical' | 'line-horizontal';
|
|
1136
|
+
styles?: AnnotationStyles;
|
|
1137
|
+
testId?: string;
|
|
1138
|
+
renderLabel?: FC<{
|
|
1139
|
+
title: string;
|
|
1140
|
+
subtitle?: string;
|
|
1141
|
+
}>;
|
|
1142
|
+
renderLabelPopover?: FC<{
|
|
1143
|
+
title: string;
|
|
1144
|
+
subtitle?: string;
|
|
1145
|
+
}>;
|
|
1146
|
+
};
|
|
1147
|
+
type CurveType = 'smooth' | 'linear' | 'monotone';
|
|
1148
|
+
type RenderLineGlyphProps<Datum extends object> = GlyphProps<Datum> & {
|
|
1149
|
+
glyphStyle?: SVGProps<SVGCircleElement>;
|
|
1150
|
+
position?: 'start' | 'end';
|
|
1151
|
+
};
|
|
1152
|
+
interface LineChartProps extends BaseChartProps<SeriesData[]> {
|
|
1153
|
+
withGradientFill: boolean;
|
|
1154
|
+
smoothing?: boolean;
|
|
1155
|
+
curveType?: CurveType;
|
|
1156
|
+
renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
|
|
1157
|
+
withStartGlyphs?: boolean;
|
|
1158
|
+
withEndGlyphs?: boolean;
|
|
1159
|
+
renderGlyph?: <Datum extends object>(props: GlyphProps<Datum>) => ReactNode;
|
|
1160
|
+
glyphStyle?: SVGProps<SVGCircleElement>;
|
|
1161
|
+
withLegendGlyph?: boolean;
|
|
1162
|
+
withTooltipCrosshairs?: {
|
|
1163
|
+
showVertical?: boolean;
|
|
1164
|
+
showHorizontal?: boolean;
|
|
1165
|
+
};
|
|
1166
|
+
children?: ReactNode;
|
|
1167
|
+
}
|
|
1168
|
+
type TooltipDatum = {
|
|
1169
|
+
key: string;
|
|
1170
|
+
value: number;
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1173
|
+
declare const LineChartAnnotation: FC<LineChartAnnotationProps>;
|
|
1174
|
+
|
|
1175
|
+
type LineChartAnnotationComponents = {
|
|
1176
|
+
AnnotationsOverlay: typeof LineChartAnnotationsOverlay;
|
|
1177
|
+
Annotation: typeof LineChartAnnotation;
|
|
1178
|
+
Legend: typeof Legend;
|
|
1179
|
+
};
|
|
1180
|
+
type LineChartBaseProps = Optional<LineChartProps, 'width' | 'height' | 'size'>;
|
|
1181
|
+
type LineChartComponent = React.ForwardRefExoticComponent<LineChartBaseProps & React.RefAttributes<SingleChartRef>> & LineChartAnnotationComponents;
|
|
1182
|
+
type LineChartResponsiveComponent = React.ForwardRefExoticComponent<LineChartBaseProps & ResponsiveConfig & React.RefAttributes<SingleChartRef>> & LineChartAnnotationComponents;
|
|
1183
|
+
declare const LineChart: LineChartComponent;
|
|
1184
|
+
declare const LineChartResponsive: LineChartResponsiveComponent;
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* Base interface for chart subcomponents in the composition API
|
|
1188
|
+
*/
|
|
1189
|
+
interface BaseChartSubComponents {
|
|
1190
|
+
Legend: ComponentType<React.ComponentProps<typeof Legend>>;
|
|
1191
|
+
SVG: FC<PropsWithChildren>;
|
|
1192
|
+
HTML: FC<PropsWithChildren>;
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Type helper for creating chart components with composition API
|
|
1196
|
+
* @template TProps - The props type for the chart component
|
|
1197
|
+
* @template TSubComponents - Additional subcomponents beyond the base ones
|
|
1198
|
+
*/
|
|
1199
|
+
type ChartComponentWithComposition<TProps, TSubComponents extends BaseChartSubComponents = BaseChartSubComponents> = FC<TProps> & TSubComponents;
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* Parameters passed to the renderTooltip function for pie charts.
|
|
1203
|
+
*/
|
|
1204
|
+
type PieChartRenderTooltipParams = {
|
|
1205
|
+
/**
|
|
1206
|
+
* The data point being hovered, including label, value, and calculated percentage.
|
|
1207
|
+
*/
|
|
1208
|
+
tooltipData: DataPointPercentageCalculated;
|
|
1209
|
+
};
|
|
1210
|
+
interface PieChartProps extends BaseChartProps<DataPointPercentage[]> {
|
|
1211
|
+
/**
|
|
1212
|
+
* Inner radius in pixels. If > 0, creates a donut chart. Defaults to 0.
|
|
1213
|
+
*/
|
|
1214
|
+
innerRadius?: number;
|
|
1215
|
+
/**
|
|
1216
|
+
* Add padding to the chart
|
|
1217
|
+
*/
|
|
1218
|
+
padding?: number;
|
|
1219
|
+
/**
|
|
1220
|
+
* Thickness of the pie chart.
|
|
1221
|
+
* A value between 0 and 1, where 0 means no thickness
|
|
1222
|
+
* and 1 means the maximum thickness.
|
|
1223
|
+
*/
|
|
1224
|
+
thickness?: number;
|
|
1225
|
+
/**
|
|
1226
|
+
* Scale of the gap between groups in the pie chart
|
|
1227
|
+
* A value between 0 and 1, where 0 means no gap.
|
|
1228
|
+
*/
|
|
1229
|
+
gapScale?: number;
|
|
1230
|
+
/**
|
|
1231
|
+
* Scale of the corner radius for the pie chart segments.
|
|
1232
|
+
* A value between 0 and 1, where 0 means no corner radius.
|
|
1233
|
+
*/
|
|
1234
|
+
cornerScale?: number;
|
|
1235
|
+
/**
|
|
1236
|
+
* Whether to show labels on pie segments. Defaults to true.
|
|
1237
|
+
*/
|
|
1238
|
+
showLabels?: boolean;
|
|
1239
|
+
/**
|
|
1240
|
+
* What type of value to display in the legend when showValues is true.
|
|
1241
|
+
* - 'percentage': Shows percentage values (e.g., "23%") [default]
|
|
1242
|
+
* - 'value': Shows raw numeric values (e.g., "30000")
|
|
1243
|
+
* - 'valueDisplay': Shows formatted values (e.g., "30K")
|
|
1244
|
+
* - 'none': Shows no values, only labels
|
|
1245
|
+
*/
|
|
1246
|
+
legendValueDisplay?: LegendValueDisplay;
|
|
1247
|
+
/**
|
|
1248
|
+
* Use the children prop to render additional elements on the chart.
|
|
1249
|
+
*/
|
|
1250
|
+
children?: ReactNode;
|
|
1251
|
+
/**
|
|
1252
|
+
* Horizontal offset for tooltip positioning in pixels (default: 0)
|
|
1253
|
+
*/
|
|
1254
|
+
tooltipOffsetX?: number;
|
|
1255
|
+
/**
|
|
1256
|
+
* Vertical offset for tooltip positioning in pixels (default: -15)
|
|
1257
|
+
*/
|
|
1258
|
+
tooltipOffsetY?: number;
|
|
1259
|
+
/**
|
|
1260
|
+
* Custom render function for tooltip content.
|
|
1261
|
+
* When provided, replaces the default BaseTooltip with custom content.
|
|
1262
|
+
*/
|
|
1263
|
+
renderTooltip?: (params: PieChartRenderTooltipParams) => ReactNode;
|
|
1264
|
+
}
|
|
1265
|
+
type PieChartBaseProps = Optional<PieChartProps, 'size'>;
|
|
1266
|
+
type PieChartComponent = ChartComponentWithComposition<PieChartBaseProps>;
|
|
1267
|
+
type PieChartResponsiveComponent = ChartComponentWithComposition<PieChartBaseProps & ResponsiveConfig>;
|
|
1268
|
+
declare const PieChart: PieChartComponent;
|
|
1269
|
+
declare const PieChartResponsive: PieChartResponsiveComponent;
|
|
1270
|
+
|
|
1271
|
+
/**
|
|
1272
|
+
* Parameters passed to the renderTooltip function for semi-circle charts.
|
|
1273
|
+
*/
|
|
1274
|
+
type PieSemiCircleChartRenderTooltipParams = {
|
|
1275
|
+
/**
|
|
1276
|
+
* The data point being hovered, including label, value, and calculated percentage.
|
|
1277
|
+
*/
|
|
1278
|
+
tooltipData: DataPointPercentageCalculated;
|
|
1279
|
+
};
|
|
1280
|
+
interface PieSemiCircleChartProps extends BaseChartProps<DataPointPercentage[]> {
|
|
1281
|
+
/**
|
|
1282
|
+
* Explicit width of the chart container in pixels.
|
|
1283
|
+
* When omitted, the chart fills its parent container's width.
|
|
1284
|
+
* The chart always maintains a 2:1 width-to-height ratio, constrained by available space.
|
|
1285
|
+
*/
|
|
1286
|
+
width?: number;
|
|
1287
|
+
/**
|
|
1288
|
+
* Thickness of the pie chart. A value between 0 and 1
|
|
1289
|
+
*/
|
|
1290
|
+
thickness?: number;
|
|
1291
|
+
/**
|
|
1292
|
+
* Direction of chart rendering
|
|
1293
|
+
* true for clockwise, false for counter-clockwise
|
|
1294
|
+
*/
|
|
1295
|
+
clockwise?: boolean;
|
|
1296
|
+
/**
|
|
1297
|
+
* Label text to display above the chart
|
|
1298
|
+
*/
|
|
1299
|
+
label?: string;
|
|
1300
|
+
/**
|
|
1301
|
+
* Note text to display below the label
|
|
1302
|
+
*/
|
|
1303
|
+
note?: string;
|
|
1304
|
+
/**
|
|
1305
|
+
* Use the children prop to render additional elements on the chart.
|
|
1306
|
+
*/
|
|
1307
|
+
children?: ReactNode;
|
|
1308
|
+
/**
|
|
1309
|
+
* What type of value to display in the legend when showValues is true.
|
|
1310
|
+
* - 'percentage': Shows percentage values (e.g., "23%") [default]
|
|
1311
|
+
* - 'value': Shows raw numeric values (e.g., "30000")
|
|
1312
|
+
* - 'valueDisplay': Shows formatted values (e.g., "30K")
|
|
1313
|
+
* - 'none': Shows no values, only labels
|
|
1314
|
+
*/
|
|
1315
|
+
legendValueDisplay?: LegendValueDisplay;
|
|
1316
|
+
/**
|
|
1317
|
+
* Horizontal offset for tooltip positioning in pixels (default: 0)
|
|
1318
|
+
*/
|
|
1319
|
+
tooltipOffsetX?: number;
|
|
1320
|
+
/**
|
|
1321
|
+
* Vertical offset for tooltip positioning in pixels (default: -15)
|
|
1322
|
+
*/
|
|
1323
|
+
tooltipOffsetY?: number;
|
|
1324
|
+
/**
|
|
1325
|
+
* Custom render function for tooltip content.
|
|
1326
|
+
* When provided, replaces the default BaseTooltip with custom content.
|
|
1327
|
+
*/
|
|
1328
|
+
renderTooltip?: (params: PieSemiCircleChartRenderTooltipParams) => ReactNode;
|
|
1329
|
+
}
|
|
1330
|
+
type PieSemiCircleChartBaseProps = Optional<PieSemiCircleChartProps, 'width'>;
|
|
1331
|
+
type PieSemiCircleChartComponent = ChartComponentWithComposition<PieSemiCircleChartBaseProps>;
|
|
1332
|
+
type PieSemiCircleChartResponsiveComponent = ChartComponentWithComposition<PieSemiCircleChartBaseProps & ResponsiveConfig>;
|
|
1333
|
+
type ArcData = PieArcDatum<DataPointPercentageCalculated>;
|
|
1334
|
+
declare const PieSemiCircleChart: PieSemiCircleChartComponent;
|
|
1335
|
+
declare const PieSemiCircleChartResponsive: PieSemiCircleChartResponsiveComponent;
|
|
1336
|
+
|
|
1337
|
+
type SparklineDataPoint = number;
|
|
1338
|
+
type GradientConfig = {
|
|
1339
|
+
/**
|
|
1340
|
+
* Start color for gradient (defaults to color prop)
|
|
1341
|
+
*/
|
|
1342
|
+
from?: string;
|
|
1343
|
+
/**
|
|
1344
|
+
* End color for gradient (defaults to theme backgroundColor)
|
|
1345
|
+
*/
|
|
1346
|
+
to?: string;
|
|
1347
|
+
/**
|
|
1348
|
+
* Start opacity (0-1)
|
|
1349
|
+
* @default 0.5
|
|
1350
|
+
*/
|
|
1351
|
+
fromOpacity?: number;
|
|
1352
|
+
/**
|
|
1353
|
+
* End opacity (0-1)
|
|
1354
|
+
* @default 0.0
|
|
1355
|
+
*/
|
|
1356
|
+
toOpacity?: number;
|
|
1357
|
+
};
|
|
1358
|
+
interface SparklineProps {
|
|
1359
|
+
/**
|
|
1360
|
+
* Array of numeric values to plot
|
|
1361
|
+
* @example [10, 25, 15, 30, 22, 35]
|
|
1362
|
+
*/
|
|
1363
|
+
data: SparklineDataPoint[];
|
|
1364
|
+
/**
|
|
1365
|
+
* Width of the sparkline in pixels
|
|
1366
|
+
* @default 100
|
|
1367
|
+
*/
|
|
1368
|
+
width?: number;
|
|
1369
|
+
/**
|
|
1370
|
+
* Height of the sparkline in pixels
|
|
1371
|
+
* @default 40
|
|
1372
|
+
*/
|
|
1373
|
+
height?: number;
|
|
1374
|
+
/**
|
|
1375
|
+
* Size (used by responsive variant, equivalent to width for square charts)
|
|
1376
|
+
*/
|
|
1377
|
+
size?: number;
|
|
1378
|
+
/**
|
|
1379
|
+
* Color for the line stroke (hex or CSS color)
|
|
1380
|
+
* @default Theme color (first color in theme.colors array)
|
|
1381
|
+
*/
|
|
1382
|
+
color?: string;
|
|
1383
|
+
/**
|
|
1384
|
+
* Line stroke width in pixels
|
|
1385
|
+
* @default 1
|
|
1386
|
+
*/
|
|
1387
|
+
strokeWidth?: number;
|
|
1388
|
+
/**
|
|
1389
|
+
* Whether to render the gradient fill beneath the line
|
|
1390
|
+
* @default true
|
|
1391
|
+
*/
|
|
1392
|
+
withGradientFill?: boolean;
|
|
1393
|
+
/**
|
|
1394
|
+
* Gradient configuration for area fill
|
|
1395
|
+
* If not provided, uses color prop with default opacity values
|
|
1396
|
+
*/
|
|
1397
|
+
gradient?: GradientConfig;
|
|
1398
|
+
/**
|
|
1399
|
+
* Additional CSS class name
|
|
1400
|
+
*/
|
|
1401
|
+
className?: string;
|
|
1402
|
+
/**
|
|
1403
|
+
* Chart ID for unique gradient/element identification
|
|
1404
|
+
*/
|
|
1405
|
+
chartId?: string;
|
|
1406
|
+
/**
|
|
1407
|
+
* Margin around the chart
|
|
1408
|
+
* @default { top: 2, right: 2, bottom: 2, left: 2 }
|
|
1409
|
+
*/
|
|
1410
|
+
margin?: {
|
|
1411
|
+
top?: number;
|
|
1412
|
+
right?: number;
|
|
1413
|
+
bottom?: number;
|
|
1414
|
+
left?: number;
|
|
1415
|
+
};
|
|
1416
|
+
/**
|
|
1417
|
+
* Enable entry animation on initial render
|
|
1418
|
+
* Creates a rising effect where the line scales up from the bottom.
|
|
1419
|
+
* Automatically respects user's prefers-reduced-motion system setting.
|
|
1420
|
+
* @default false
|
|
1421
|
+
*/
|
|
1422
|
+
animation?: boolean;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
/**
|
|
1426
|
+
* Sparkline - A minimal line chart for inline data visualization.
|
|
1427
|
+
*
|
|
1428
|
+
* Sparklines are compact charts designed to be embedded inline with text or
|
|
1429
|
+
* displayed in small spaces like table cells or dashboards. They show trends
|
|
1430
|
+
* without axes, labels, or other chart chrome.
|
|
1431
|
+
*
|
|
1432
|
+
* This component is built on top of LineChart with preconfigured settings
|
|
1433
|
+
* for minimal display (no axes, grid, tooltips, or legend).
|
|
1434
|
+
*/
|
|
1435
|
+
declare const SparklineUnresponsive: react.ForwardRefExoticComponent<SparklineProps & react.RefAttributes<HTMLDivElement>>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Responsive Sparkline chart component
|
|
1438
|
+
*/
|
|
1439
|
+
declare const Sparkline: ({ resizeDebounceTime, maxWidth, aspectRatio, size, width, height, ...chartProps }: Omit<SparklineProps, "width" | "height" | "size"> & {
|
|
1440
|
+
width?: number;
|
|
1441
|
+
height?: number;
|
|
1442
|
+
size?: number;
|
|
1443
|
+
} & ResponsiveConfig) => react_jsx_runtime.JSX.Element;
|
|
1444
|
+
|
|
1445
|
+
type TooltipData = {
|
|
1446
|
+
label: string;
|
|
1447
|
+
value: number;
|
|
1448
|
+
valueDisplay?: string;
|
|
1449
|
+
};
|
|
1450
|
+
type TooltipComponentProps = {
|
|
1451
|
+
data: TooltipData;
|
|
1452
|
+
className?: string;
|
|
1453
|
+
};
|
|
1454
|
+
type TooltipCommonProps = {
|
|
1455
|
+
top: number;
|
|
1456
|
+
left: number;
|
|
1457
|
+
style?: CSSProperties;
|
|
1458
|
+
className?: string;
|
|
1459
|
+
/**
|
|
1460
|
+
* Whether to render the tooltip container div. When false, only renders the content.
|
|
1461
|
+
* Useful when the tooltip is rendered inside a portal or custom container.
|
|
1462
|
+
* @default true
|
|
1463
|
+
*/
|
|
1464
|
+
renderContainer?: boolean;
|
|
1465
|
+
};
|
|
1466
|
+
type DefaultDataTooltip = {
|
|
1467
|
+
data: TooltipData;
|
|
1468
|
+
component?: ComponentType<TooltipComponentProps>;
|
|
1469
|
+
children?: never;
|
|
1470
|
+
};
|
|
1471
|
+
type CustomTooltip = {
|
|
1472
|
+
children: ReactNode;
|
|
1473
|
+
data?: never;
|
|
1474
|
+
component?: never;
|
|
1475
|
+
};
|
|
1476
|
+
type BaseTooltipProps = TooltipCommonProps & (DefaultDataTooltip | CustomTooltip);
|
|
1477
|
+
declare const BaseTooltip: ({ data, top, left, component: Component, children, className, style, renderContainer, }: BaseTooltipProps) => string | number | true | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
|
|
1478
|
+
|
|
1479
|
+
type FlattenedTooltipData = {
|
|
1480
|
+
datum: DataPointDate;
|
|
1481
|
+
seriesLabel: string;
|
|
1482
|
+
seriesIndex: number;
|
|
1483
|
+
dataPointIndex: number;
|
|
1484
|
+
};
|
|
1485
|
+
interface AccessibleTooltipProps extends Omit<TooltipProps$1<DataPointDate>, 'renderTooltip'> {
|
|
1486
|
+
renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
|
|
1487
|
+
selectedIndex?: number | undefined;
|
|
1488
|
+
tooltipRef?: (element: HTMLDivElement | null) => void;
|
|
1489
|
+
keyboardFocusedClassName?: string;
|
|
1490
|
+
/**
|
|
1491
|
+
* Flattened tooltip data prepared by parent component
|
|
1492
|
+
* Each index corresponds to one tooltip to show
|
|
1493
|
+
*/
|
|
1494
|
+
tooltipData?: FlattenedTooltipData[];
|
|
1495
|
+
/**
|
|
1496
|
+
* For line charts: series data to show all series at selected data point
|
|
1497
|
+
* When provided, shows all series instead of individual tooltips
|
|
1498
|
+
*/
|
|
1499
|
+
series?: SeriesData[];
|
|
1500
|
+
/**
|
|
1501
|
+
* Whether to combine tooltip information from multiple series into a single tooltip. This is useful for line charts.
|
|
1502
|
+
* Or to show individual tooltips for each series. This is useful for bar charts.
|
|
1503
|
+
*/
|
|
1504
|
+
mode?: 'individual' | 'group';
|
|
1505
|
+
}
|
|
1506
|
+
declare const AccessibleTooltip: React.FC<AccessibleTooltipProps>;
|
|
1507
|
+
|
|
1508
|
+
type TooltipProps = {
|
|
1509
|
+
data: {
|
|
1510
|
+
label: string;
|
|
1511
|
+
value: number;
|
|
1512
|
+
};
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
/**
|
|
1516
|
+
* The direction of the trend
|
|
1517
|
+
*/
|
|
1518
|
+
type TrendDirection = 'up' | 'down' | 'neutral';
|
|
1519
|
+
/**
|
|
1520
|
+
* Props for the TrendIndicator component
|
|
1521
|
+
*/
|
|
1522
|
+
type TrendIndicatorProps = {
|
|
1523
|
+
/**
|
|
1524
|
+
* The direction of the trend (up, down, or neutral)
|
|
1525
|
+
*/
|
|
1526
|
+
direction: TrendDirection;
|
|
1527
|
+
/**
|
|
1528
|
+
* The value to display (e.g., "14%", "+$500", "2.5k")
|
|
1529
|
+
*/
|
|
1530
|
+
value: string | number;
|
|
1531
|
+
/**
|
|
1532
|
+
* Additional CSS class name
|
|
1533
|
+
*/
|
|
1534
|
+
className?: string;
|
|
1535
|
+
/**
|
|
1536
|
+
* Inline styles
|
|
1537
|
+
*/
|
|
1538
|
+
style?: CSSProperties;
|
|
1539
|
+
/**
|
|
1540
|
+
* Whether to show the directional icon
|
|
1541
|
+
* @default true
|
|
1542
|
+
*/
|
|
1543
|
+
showIcon?: boolean;
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
/**
|
|
1547
|
+
* TrendIndicator displays a directional trend with a value.
|
|
1548
|
+
* Used to show percentage changes or growth metrics.
|
|
1549
|
+
*
|
|
1550
|
+
* @param {TrendIndicatorProps} props - Component props
|
|
1551
|
+
* @return {JSX.Element} The rendered trend indicator
|
|
1552
|
+
*/
|
|
1553
|
+
declare function TrendIndicator({ direction, value, className, style, showIcon, }: TrendIndicatorProps): react_jsx_runtime.JSX.Element;
|
|
1554
|
+
|
|
1555
|
+
interface ChartRegistration {
|
|
1556
|
+
legendItems: BaseLegendItem[];
|
|
1557
|
+
chartType: ChartType;
|
|
1558
|
+
metadata?: Record<string, unknown>;
|
|
1559
|
+
}
|
|
1560
|
+
type GetElementStylesParams = {
|
|
1561
|
+
index: number;
|
|
1562
|
+
data?: SeriesData | DataPointPercentage;
|
|
1563
|
+
overrideColor?: string;
|
|
1564
|
+
legendShape?: LegendShape<SeriesData[], number>;
|
|
1565
|
+
};
|
|
1566
|
+
type ElementStyles = {
|
|
1567
|
+
color: string;
|
|
1568
|
+
lineStyles: LineStyles;
|
|
1569
|
+
glyph: <Datum extends object>(props: GlyphProps<Datum>) => ReactNode;
|
|
1570
|
+
shapeStyles: CSSProperties & LineStyles;
|
|
1571
|
+
};
|
|
1572
|
+
interface GlobalChartsContextValue {
|
|
1573
|
+
charts: Map<string, ChartRegistration>;
|
|
1574
|
+
registerChart: (id: string, data: ChartRegistration) => void;
|
|
1575
|
+
unregisterChart: (id: string) => void;
|
|
1576
|
+
getChartData: (id: string) => ChartRegistration | undefined;
|
|
1577
|
+
theme: CompleteChartTheme;
|
|
1578
|
+
getElementStyles: (params: GetElementStylesParams) => ElementStyles;
|
|
1579
|
+
toggleSeriesVisibility: (chartId: string, seriesLabel: string) => void;
|
|
1580
|
+
isSeriesVisible: (chartId: string, seriesLabel: string) => boolean;
|
|
1581
|
+
getHiddenSeries: (chartId: string) => Set<string>;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
declare const GlobalChartsContext: react.Context<GlobalChartsContextValue>;
|
|
1585
|
+
interface GlobalChartsProviderProps {
|
|
1586
|
+
children: ReactNode;
|
|
1587
|
+
theme?: Partial<ChartTheme>;
|
|
1588
|
+
/**
|
|
1589
|
+
* Optional ref to an element that chart tooltip portals should be relocated into.
|
|
1590
|
+
* When provided, visx tooltip portals (normally appended to document.body) will be
|
|
1591
|
+
* moved into this container so they participate in the same effective CSS stacking context.
|
|
1592
|
+
* The element referenced here, or one of its ancestors, should establish the desired
|
|
1593
|
+
* stacking context (for example by using `position` and `z-index`) so that tooltips
|
|
1594
|
+
* appear above the relevant chart content.
|
|
1595
|
+
*/
|
|
1596
|
+
portalContainer?: React.RefObject<HTMLElement | null>;
|
|
1597
|
+
}
|
|
1598
|
+
declare const GlobalChartsProvider: FC<GlobalChartsProviderProps>;
|
|
1599
|
+
|
|
1600
|
+
declare const useGlobalChartsContext: () => GlobalChartsContextValue;
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* Hook to get the global chart theme from GlobalChartsProvider
|
|
1604
|
+
*
|
|
1605
|
+
* @return The global chart theme
|
|
1606
|
+
*/
|
|
1607
|
+
declare const useGlobalChartsTheme: () => CompleteChartTheme;
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* Default theme configuration
|
|
1611
|
+
*/
|
|
1612
|
+
declare const defaultTheme: CompleteChartTheme;
|
|
1613
|
+
|
|
1614
|
+
export { AccessibleTooltip, type AnnotationStyles, type ArcData, 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 ChartLegendConfig, type ChartLegendOptions, type ChartTheme, type CompleteChartTheme, ConversionFunnelChartWithProvider as ConversionFunnelChart, type ConversionFunnelChartProps, type CurveType, type DataPoint, type DataPointDate, type DataPointPercentage, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, type GradientConfig, type GradientStop, type GridProps, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, 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 RenderValueProps, type ScaleOptions, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, GlobalChartsProvider as ThemeProvider, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };
|