@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
|
@@ -4,17 +4,23 @@ import { LinearGradient } from '@visx/gradient';
|
|
|
4
4
|
import { scaleTime } from '@visx/scale';
|
|
5
5
|
import { XYChart, AreaSeries, Grid, Axis, DataContext } from '@visx/xychart';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
|
-
import { Stack } from '@wordpress/ui';
|
|
8
7
|
import clsx from 'clsx';
|
|
9
8
|
import { differenceInHours, differenceInYears } from 'date-fns';
|
|
10
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
useMemo,
|
|
11
|
+
useContext,
|
|
12
|
+
forwardRef,
|
|
13
|
+
useImperativeHandle,
|
|
14
|
+
useState,
|
|
15
|
+
useRef,
|
|
16
|
+
useCallback,
|
|
17
|
+
} from 'react';
|
|
11
18
|
import { Legend, useChartLegendItems } from '../../components/legend';
|
|
12
19
|
import { AccessibleTooltip, useKeyboardNavigation } from '../../components/tooltip';
|
|
13
20
|
import {
|
|
14
21
|
useXYChartTheme,
|
|
15
22
|
useChartDataTransform,
|
|
16
23
|
useChartMargin,
|
|
17
|
-
useElementSize,
|
|
18
24
|
usePrefersReducedMotion,
|
|
19
25
|
} from '../../hooks';
|
|
20
26
|
import {
|
|
@@ -26,9 +32,11 @@ import {
|
|
|
26
32
|
useGlobalChartsTheme,
|
|
27
33
|
} from '../../providers';
|
|
28
34
|
import { attachSubComponents } from '../../utils';
|
|
29
|
-
import { useChartChildren
|
|
35
|
+
import { useChartChildren } from '../private/chart-composition';
|
|
36
|
+
import { ChartLayout } from '../private/chart-layout';
|
|
30
37
|
import { DefaultGlyph } from '../private/default-glyph';
|
|
31
38
|
import { SingleChartContext, type SingleChartRef } from '../private/single-chart-context';
|
|
39
|
+
import { SvgEmptyState } from '../private/svg-empty-state';
|
|
32
40
|
import { withResponsive } from '../private/with-responsive';
|
|
33
41
|
import styles from './line-chart.module.scss';
|
|
34
42
|
import { LineChartAnnotation, LineChartAnnotationsOverlay, LineChartGlyph } from './private';
|
|
@@ -285,7 +293,6 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
|
|
|
285
293
|
const providerTheme = useGlobalChartsTheme();
|
|
286
294
|
const theme = useXYChartTheme( data );
|
|
287
295
|
const chartId = useChartId( providedChartId );
|
|
288
|
-
const [ svgWrapperRef, , svgWrapperHeight ] = useElementSize< HTMLDivElement >();
|
|
289
296
|
const chartRef = useRef< HTMLDivElement >( null );
|
|
290
297
|
const [ selectedIndex, setSelectedIndex ] = useState< number | undefined >( undefined );
|
|
291
298
|
const [ isNavigating, setIsNavigating ] = useState( false );
|
|
@@ -293,14 +300,17 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
|
|
|
293
300
|
|
|
294
301
|
// Process children for composition API (Legend, etc.)
|
|
295
302
|
const { legendChildren, nonLegendChildren } = useChartChildren( children, 'LineChart' );
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
//
|
|
299
|
-
//
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
303
|
+
const [ measuredChartHeight, setMeasuredChartHeight ] = useState< number | undefined >();
|
|
304
|
+
|
|
305
|
+
// Callback for ChartLayout to notify us when the measured content height changes.
|
|
306
|
+
// We compute chartHeight the same way the render prop does so the context stays in sync.
|
|
307
|
+
const handleContentHeightChange = useCallback(
|
|
308
|
+
( contentHeight: number ) => {
|
|
309
|
+
const chartHeight = contentHeight > 0 ? contentHeight : height;
|
|
310
|
+
setMeasuredChartHeight( chartHeight );
|
|
311
|
+
},
|
|
312
|
+
[ height ]
|
|
313
|
+
);
|
|
304
314
|
|
|
305
315
|
// Forward the external ref to the internal ref
|
|
306
316
|
useImperativeHandle(
|
|
@@ -472,11 +482,13 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
|
|
|
472
482
|
chartId,
|
|
473
483
|
chartRef: internalChartRef,
|
|
474
484
|
chartWidth: width,
|
|
475
|
-
chartHeight,
|
|
485
|
+
chartHeight: measuredChartHeight || 0,
|
|
476
486
|
} }
|
|
477
487
|
>
|
|
478
|
-
<
|
|
479
|
-
|
|
488
|
+
<ChartLayout
|
|
489
|
+
legendPosition={ legendPosition }
|
|
490
|
+
legendElement={ legendElement }
|
|
491
|
+
legendChildren={ legendChildren }
|
|
480
492
|
gap={ gap }
|
|
481
493
|
className={ clsx(
|
|
482
494
|
'line-chart',
|
|
@@ -484,181 +496,176 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
|
|
|
484
496
|
{ [ styles[ 'line-chart--animated' ] ]: animation && ! prefersReducedMotion },
|
|
485
497
|
className
|
|
486
498
|
) }
|
|
499
|
+
style={ { width, height } }
|
|
487
500
|
data-testid="line-chart"
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
height,
|
|
491
|
-
visibility: isWaitingForMeasurement ? 'hidden' : 'visible',
|
|
492
|
-
} }
|
|
501
|
+
trailingContent={ nonLegendChildren }
|
|
502
|
+
onContentHeightChange={ handleContentHeightChange }
|
|
493
503
|
>
|
|
494
|
-
{
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
>
|
|
526
|
-
{ gridVisibility !== 'none' && <Grid columns={ false } numTicks={ 4 } /> }
|
|
527
|
-
{ chartOptions.axis.x.display && <Axis { ...chartOptions.axis.x } /> }
|
|
528
|
-
{ chartOptions.axis.y.display && <Axis { ...chartOptions.axis.y } /> }
|
|
529
|
-
|
|
530
|
-
{ allSeriesHidden ? (
|
|
531
|
-
<text
|
|
532
|
-
x={ width / 2 }
|
|
533
|
-
y={ chartHeight / 2 }
|
|
534
|
-
textAnchor="middle"
|
|
535
|
-
fill={ providerTheme.gridStyles?.stroke || '#ccc' }
|
|
536
|
-
fontSize="14"
|
|
537
|
-
fontFamily="-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif"
|
|
504
|
+
{ ( { contentHeight } ) => {
|
|
505
|
+
// Use the measured height, falling back to the passed height if provided.
|
|
506
|
+
const chartHeight = contentHeight > 0 ? contentHeight : height;
|
|
507
|
+
|
|
508
|
+
return (
|
|
509
|
+
<div
|
|
510
|
+
role="grid"
|
|
511
|
+
aria-label={ __( 'Line chart', 'jetpack-charts' ) }
|
|
512
|
+
tabIndex={ 0 }
|
|
513
|
+
onKeyDown={ onChartKeyDown }
|
|
514
|
+
onFocus={ onChartFocus }
|
|
515
|
+
onBlur={ onChartBlur }
|
|
516
|
+
>
|
|
517
|
+
{ chartHeight > 0 && (
|
|
518
|
+
<div ref={ chartRef }>
|
|
519
|
+
<XYChart
|
|
520
|
+
theme={ theme }
|
|
521
|
+
width={ width }
|
|
522
|
+
height={ chartHeight }
|
|
523
|
+
margin={ {
|
|
524
|
+
...defaultMargin,
|
|
525
|
+
...margin,
|
|
526
|
+
} }
|
|
527
|
+
// xScale and yScale could be set in Axis as well, but they are `scale` props there.
|
|
528
|
+
xScale={ chartOptions.xScale }
|
|
529
|
+
yScale={ chartOptions.yScale }
|
|
530
|
+
onPointerDown={ onPointerDown }
|
|
531
|
+
onPointerUp={ onPointerUp }
|
|
532
|
+
onPointerMove={ onPointerMove }
|
|
533
|
+
onPointerOut={ onPointerOut }
|
|
534
|
+
pointerEventsDataKey="nearest"
|
|
538
535
|
>
|
|
539
|
-
{
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
536
|
+
{ gridVisibility !== 'none' && <Grid columns={ false } numTicks={ 4 } /> }
|
|
537
|
+
{ chartOptions.axis.x.display && <Axis { ...chartOptions.axis.x } /> }
|
|
538
|
+
{ chartOptions.axis.y.display && <Axis { ...chartOptions.axis.y } /> }
|
|
539
|
+
|
|
540
|
+
{ allSeriesHidden ? (
|
|
541
|
+
<SvgEmptyState
|
|
542
|
+
x={ width / 2 }
|
|
543
|
+
y={ chartHeight / 2 }
|
|
544
|
+
width={ width }
|
|
545
|
+
height={ chartHeight }
|
|
546
|
+
>
|
|
547
|
+
{ __(
|
|
548
|
+
'All series are hidden. Click legend items to show data.',
|
|
549
|
+
'jetpack-charts'
|
|
550
|
+
) }
|
|
551
|
+
</SvgEmptyState>
|
|
552
|
+
) : null }
|
|
553
|
+
|
|
554
|
+
{ seriesWithVisibility.map( ( { series: seriesData, index, isVisible } ) => {
|
|
555
|
+
// Skip rendering invisible series
|
|
556
|
+
if ( ! isVisible ) {
|
|
557
|
+
return null;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const { color, lineStyles, glyph } = getElementStyles( {
|
|
561
|
+
data: seriesData,
|
|
562
|
+
index,
|
|
563
|
+
} );
|
|
564
|
+
|
|
565
|
+
const lineProps = {
|
|
566
|
+
stroke: color,
|
|
567
|
+
...lineStyles,
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
return (
|
|
571
|
+
<g key={ seriesData?.label || index }>
|
|
572
|
+
{ withGradientFill && (
|
|
573
|
+
<LinearGradient
|
|
574
|
+
id={ `area-gradient-${ chartId }-${ index + 1 }` }
|
|
575
|
+
from={ color }
|
|
576
|
+
fromOpacity={ 0.4 }
|
|
577
|
+
toOpacity={ 0.1 }
|
|
578
|
+
to={ providerTheme.backgroundColor }
|
|
579
|
+
{ ...seriesData.options?.gradient }
|
|
580
|
+
data-testid="line-gradient"
|
|
581
|
+
>
|
|
582
|
+
{ seriesData.options?.gradient?.stops?.map( ( stop, stopIndex ) => (
|
|
583
|
+
<stop
|
|
584
|
+
key={ `${ stop.offset }-${ stop.color || color }` }
|
|
585
|
+
offset={ stop.offset }
|
|
586
|
+
stopColor={ stop.color || color }
|
|
587
|
+
stopOpacity={ stop.opacity ?? 1 }
|
|
588
|
+
data-testid={ `line-gradient-stop-${ chartId }-${ index }-${ stopIndex }` }
|
|
589
|
+
/>
|
|
590
|
+
) ) }
|
|
591
|
+
</LinearGradient>
|
|
592
|
+
) }
|
|
593
|
+
<AreaSeries
|
|
594
|
+
key={ seriesData?.label }
|
|
595
|
+
dataKey={ seriesData?.label }
|
|
596
|
+
data={ seriesData.data as DataPointDate[] }
|
|
597
|
+
{ ...accessors }
|
|
598
|
+
fill={
|
|
599
|
+
withGradientFill
|
|
600
|
+
? `url(#area-gradient-${ chartId }-${ index + 1 })`
|
|
601
|
+
: 'transparent'
|
|
602
|
+
}
|
|
603
|
+
renderLine={ true }
|
|
604
|
+
curve={ getCurveType( curveType, smoothing ) }
|
|
605
|
+
lineProps={ lineProps }
|
|
606
|
+
/>
|
|
607
|
+
|
|
608
|
+
{ withStartGlyphs && (
|
|
609
|
+
<LineChartGlyph
|
|
610
|
+
index={ index }
|
|
611
|
+
data={ seriesData }
|
|
612
|
+
color={ color }
|
|
613
|
+
renderGlyph={ glyph ?? renderGlyph }
|
|
614
|
+
accessors={ accessors }
|
|
615
|
+
glyphStyle={ glyphStyle }
|
|
616
|
+
position="start"
|
|
581
617
|
/>
|
|
582
|
-
)
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
618
|
+
) }
|
|
619
|
+
|
|
620
|
+
{ withEndGlyphs && (
|
|
621
|
+
<LineChartGlyph
|
|
622
|
+
index={ index }
|
|
623
|
+
data={ seriesData }
|
|
624
|
+
color={ color }
|
|
625
|
+
renderGlyph={ glyph ?? renderGlyph }
|
|
626
|
+
accessors={ accessors }
|
|
627
|
+
glyphStyle={ glyphStyle }
|
|
628
|
+
position="end"
|
|
629
|
+
/>
|
|
630
|
+
) }
|
|
631
|
+
</g>
|
|
632
|
+
);
|
|
633
|
+
} ) }
|
|
634
|
+
|
|
635
|
+
{ withTooltips && (
|
|
636
|
+
<AccessibleTooltip
|
|
637
|
+
detectBounds
|
|
638
|
+
snapTooltipToDatumX
|
|
639
|
+
snapTooltipToDatumY
|
|
640
|
+
showSeriesGlyphs
|
|
641
|
+
renderTooltip={ renderTooltip }
|
|
642
|
+
renderGlyph={ tooltipRenderGlyph }
|
|
643
|
+
glyphStyle={ glyphStyle }
|
|
644
|
+
showVerticalCrosshair={ withTooltipCrosshairs?.showVertical }
|
|
645
|
+
showHorizontalCrosshair={ withTooltipCrosshairs?.showHorizontal }
|
|
646
|
+
selectedIndex={ selectedIndex }
|
|
647
|
+
tooltipRef={ tooltipRef }
|
|
648
|
+
keyboardFocusedClassName={
|
|
649
|
+
styles[ 'line-chart__tooltip--keyboard-focused' ]
|
|
594
650
|
}
|
|
595
|
-
|
|
596
|
-
curve={ getCurveType( curveType, smoothing ) }
|
|
597
|
-
lineProps={ lineProps }
|
|
651
|
+
series={ dataSorted }
|
|
598
652
|
/>
|
|
653
|
+
) }
|
|
599
654
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
) }
|
|
611
|
-
|
|
612
|
-
{ withEndGlyphs && (
|
|
613
|
-
<LineChartGlyph
|
|
614
|
-
index={ index }
|
|
615
|
-
data={ seriesData }
|
|
616
|
-
color={ color }
|
|
617
|
-
renderGlyph={ glyph ?? renderGlyph }
|
|
618
|
-
accessors={ accessors }
|
|
619
|
-
glyphStyle={ glyphStyle }
|
|
620
|
-
position="end"
|
|
621
|
-
/>
|
|
622
|
-
) }
|
|
623
|
-
</g>
|
|
624
|
-
);
|
|
625
|
-
} ) }
|
|
626
|
-
|
|
627
|
-
{ withTooltips && (
|
|
628
|
-
<AccessibleTooltip
|
|
629
|
-
detectBounds
|
|
630
|
-
snapTooltipToDatumX
|
|
631
|
-
snapTooltipToDatumY
|
|
632
|
-
showSeriesGlyphs
|
|
633
|
-
renderTooltip={ renderTooltip }
|
|
634
|
-
renderGlyph={ tooltipRenderGlyph }
|
|
635
|
-
glyphStyle={ glyphStyle }
|
|
636
|
-
showVerticalCrosshair={ withTooltipCrosshairs?.showVertical }
|
|
637
|
-
showHorizontalCrosshair={ withTooltipCrosshairs?.showHorizontal }
|
|
638
|
-
selectedIndex={ selectedIndex }
|
|
639
|
-
tooltipRef={ tooltipRef }
|
|
640
|
-
keyboardFocusedClassName={ styles[ 'line-chart__tooltip--keyboard-focused' ] }
|
|
641
|
-
series={ dataSorted }
|
|
642
|
-
/>
|
|
643
|
-
) }
|
|
644
|
-
|
|
645
|
-
{ /* Component to expose scale data via ref */ }
|
|
646
|
-
<LineChartScalesRef
|
|
647
|
-
chartRef={ internalChartRef }
|
|
648
|
-
width={ width }
|
|
649
|
-
height={ height }
|
|
650
|
-
margin={ margin }
|
|
651
|
-
/>
|
|
652
|
-
</XYChart>
|
|
655
|
+
{ /* Component to expose scale data via ref */ }
|
|
656
|
+
<LineChartScalesRef
|
|
657
|
+
chartRef={ internalChartRef }
|
|
658
|
+
width={ width }
|
|
659
|
+
height={ height }
|
|
660
|
+
margin={ margin }
|
|
661
|
+
/>
|
|
662
|
+
</XYChart>
|
|
663
|
+
</div>
|
|
664
|
+
) }
|
|
653
665
|
</div>
|
|
654
|
-
)
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
{ legendPosition === 'bottom' && legendElement }
|
|
658
|
-
{ renderLegendSlot( legendChildren, 'bottom' ) }
|
|
659
|
-
|
|
660
|
-
{ nonLegendChildren }
|
|
661
|
-
</Stack>
|
|
666
|
+
);
|
|
667
|
+
} }
|
|
668
|
+
</ChartLayout>
|
|
662
669
|
</SingleChartContext.Provider>
|
|
663
670
|
);
|
|
664
671
|
}
|
|
@@ -99,8 +99,7 @@ const LineChartAnnotationsOverlay: FC< LineChartAnnotationsProps > = ( { childre
|
|
|
99
99
|
};
|
|
100
100
|
}, [ getScalesData, chartWidth, chartHeight ] );
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
if ( ! chartRef || ! children ) {
|
|
102
|
+
if ( ! chartRef || ! children || ! chartWidth || ! chartHeight ) {
|
|
104
103
|
return null;
|
|
105
104
|
}
|
|
106
105
|
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
.pie-chart {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
2
|
overflow: hidden;
|
|
5
|
-
align-items: center;
|
|
6
3
|
|
|
7
4
|
// Fill parent when no explicit width/height provided
|
|
8
5
|
&--responsive {
|
|
@@ -10,13 +7,8 @@
|
|
|
10
7
|
width: 100%;
|
|
11
8
|
}
|
|
12
9
|
|
|
13
|
-
&
|
|
14
|
-
flex: 1;
|
|
15
|
-
min-height: 0; // Required for flex shrinking
|
|
16
|
-
min-width: 0; // Required for flex shrinking
|
|
10
|
+
&__centering {
|
|
17
11
|
width: 100%;
|
|
18
|
-
|
|
19
|
-
align-items: center;
|
|
20
|
-
justify-content: center;
|
|
12
|
+
height: 100%;
|
|
21
13
|
}
|
|
22
14
|
}
|