@automattic/charts 0.53.4 → 0.54.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 +5 -0
- package/dist/charts/bar-chart/index.cjs +2 -2
- package/dist/charts/bar-chart/index.d.cts +1 -1
- package/dist/charts/bar-chart/index.d.ts +1 -1
- package/dist/charts/bar-chart/index.js +1 -1
- package/dist/charts/bar-list-chart/index.cjs +3 -3
- package/dist/charts/bar-list-chart/index.d.cts +1 -1
- package/dist/charts/bar-list-chart/index.d.ts +1 -1
- package/dist/charts/bar-list-chart/index.js +2 -2
- package/dist/charts/conversion-funnel-chart/index.d.cts +1 -1
- package/dist/charts/conversion-funnel-chart/index.d.ts +1 -1
- package/dist/charts/geo-chart/index.d.cts +1 -1
- package/dist/charts/geo-chart/index.d.ts +1 -1
- package/dist/charts/leaderboard-chart/index.d.cts +2 -2
- package/dist/charts/leaderboard-chart/index.d.ts +2 -2
- package/dist/charts/line-chart/index.d.cts +1 -1
- package/dist/charts/line-chart/index.d.ts +1 -1
- package/dist/charts/pie-chart/index.d.cts +1 -1
- package/dist/charts/pie-chart/index.d.ts +1 -1
- package/dist/charts/pie-semi-circle-chart/index.d.cts +1 -1
- package/dist/charts/pie-semi-circle-chart/index.d.ts +1 -1
- package/dist/{chunk-KORG7ITC.js → chunk-2NRSBKV2.js} +2 -2
- package/dist/{chunk-DDV5726Q.cjs → chunk-3OONWZ4Z.cjs} +84 -4
- package/dist/chunk-3OONWZ4Z.cjs.map +1 -0
- package/dist/{chunk-FVWTBK44.cjs → chunk-EGGRTD4V.cjs} +3 -3
- package/dist/{chunk-FVWTBK44.cjs.map → chunk-EGGRTD4V.cjs.map} +1 -1
- package/dist/{chunk-KBORJZKC.js → chunk-PU2UO4EG.js} +108 -28
- package/dist/chunk-PU2UO4EG.js.map +1 -0
- package/dist/components/legend/index.d.cts +1 -1
- package/dist/components/legend/index.d.ts +1 -1
- package/dist/components/tooltip/index.d.cts +1 -1
- package/dist/components/tooltip/index.d.ts +1 -1
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/{leaderboard-chart-DPi2ueOg.d.ts → leaderboard-chart-BOgMT2BT.d.ts} +1 -1
- package/dist/{leaderboard-chart-CN80sJmQ.d.cts → leaderboard-chart-Df6kkqtI.d.cts} +1 -1
- package/dist/providers/index.d.cts +2 -2
- package/dist/providers/index.d.ts +2 -2
- package/dist/{themes-Dzg0wE3B.d.cts → themes-BTFVRiJ8.d.cts} +1 -1
- package/dist/{themes-AriuFXQ2.d.ts → themes-GEPvLhum.d.ts} +1 -1
- package/dist/{types-D1lTxRyg.d.cts → types-B1_Q_Lhh.d.cts} +12 -0
- package/dist/{types-D1lTxRyg.d.ts → types-B1_Q_Lhh.d.ts} +12 -0
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/charts/bar-chart/private/index.ts +1 -0
- package/src/charts/bar-chart/private/truncated-tick-component.tsx +157 -0
- package/src/charts/bar-chart/private/use-bar-chart-options.ts +8 -2
- package/src/charts/bar-chart/test/bar-chart.test.tsx +141 -0
- package/src/charts/line-chart/test/line-chart-annotation-label-popover.test.tsx +4 -2
- package/src/providers/chart-context/test/chart-context.test.tsx +0 -13
- package/src/types.ts +12 -0
- package/src/utils/test/resolve-css-var.ssr.test.ts +17 -0
- package/src/utils/test/resolve-css-var.test.ts +0 -24
- package/dist/chunk-DDV5726Q.cjs.map +0 -1
- package/dist/chunk-KBORJZKC.js.map +0 -1
- /package/dist/{chunk-KORG7ITC.js.map → chunk-2NRSBKV2.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.54.0] - 2026-01-21
|
|
9
|
+
### Added
|
|
10
|
+
- Add labelOverflow ellipsis option to truncate long axis labels for bar chart. [#46656]
|
|
11
|
+
|
|
8
12
|
## [0.53.4] - 2026-01-19
|
|
9
13
|
### Changed
|
|
10
14
|
- Update package dependencies. [#46647]
|
|
@@ -632,6 +636,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
632
636
|
- Fixed lints following ESLint rule changes for TS [#40584]
|
|
633
637
|
- Fixing a bug in Chart storybook data. [#40640]
|
|
634
638
|
|
|
639
|
+
[0.54.0]: https://github.com/Automattic/charts/compare/v0.53.4...v0.54.0
|
|
635
640
|
[0.53.4]: https://github.com/Automattic/charts/compare/v0.53.3...v0.53.4
|
|
636
641
|
[0.53.3]: https://github.com/Automattic/charts/compare/v0.53.2...v0.53.3
|
|
637
642
|
[0.53.2]: https://github.com/Automattic/charts/compare/v0.53.1...v0.53.2
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk3OONWZ4Zcjs = require('../../chunk-3OONWZ4Z.cjs');
|
|
5
5
|
require('../../chunk-ZPJHWKEK.cjs');
|
|
6
6
|
require('../../chunk-7HROSZRS.cjs');
|
|
7
7
|
require('../../chunk-MUUSZ7J5.cjs');
|
|
@@ -11,5 +11,5 @@ require('../../chunk-EMMSS5I5.cjs');
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.BarChart =
|
|
14
|
+
exports.BarChart = _chunk3OONWZ4Zcjs.BarChartResponsive; exports.BarChartUnresponsive = _chunk3OONWZ4Zcjs.BarChart;
|
|
15
15
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { L as Legend } from '../../legend-C9ahiwOt.cjs';
|
|
2
|
-
import { O as Optional, B as BaseChartProps, d as SeriesData, b as DataPointDate } from '../../types-
|
|
2
|
+
import { O as Optional, B as BaseChartProps, d as SeriesData, b as DataPointDate } from '../../types-B1_Q_Lhh.cjs';
|
|
3
3
|
import { FC, ReactNode, ComponentType } from 'react';
|
|
4
4
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.cjs';
|
|
5
5
|
import { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { L as Legend } from '../../legend-jjMmhSg3.js';
|
|
2
|
-
import { O as Optional, B as BaseChartProps, d as SeriesData, b as DataPointDate } from '../../types-
|
|
2
|
+
import { O as Optional, B as BaseChartProps, d as SeriesData, b as DataPointDate } from '../../types-B1_Q_Lhh.js';
|
|
3
3
|
import { FC, ReactNode, ComponentType } from 'react';
|
|
4
4
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.js';
|
|
5
5
|
import { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../../chunk-
|
|
4
|
+
var _chunkEGGRTD4Vcjs = require('../../chunk-EGGRTD4V.cjs');
|
|
5
|
+
require('../../chunk-3OONWZ4Z.cjs');
|
|
6
6
|
require('../../chunk-ZPJHWKEK.cjs');
|
|
7
7
|
require('../../chunk-7HROSZRS.cjs');
|
|
8
8
|
require('../../chunk-MUUSZ7J5.cjs');
|
|
@@ -12,5 +12,5 @@ require('../../chunk-EMMSS5I5.cjs');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
exports.BarListChart =
|
|
15
|
+
exports.BarListChart = _chunkEGGRTD4Vcjs.BarListChartResponsive; exports.BarListChartUnresponsive = _chunkEGGRTD4Vcjs.BarListChart;
|
|
16
16
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.cjs';
|
|
3
3
|
import { TextProps } from '@visx/text';
|
|
4
4
|
import { BarChartProps } from '../bar-chart/index.cjs';
|
|
5
|
-
import { g as ScaleOptions, d as SeriesData } from '../../types-
|
|
5
|
+
import { g as ScaleOptions, d as SeriesData } from '../../types-B1_Q_Lhh.cjs';
|
|
6
6
|
import { ComponentType, FC } from 'react';
|
|
7
7
|
import '../../legend-C9ahiwOt.cjs';
|
|
8
8
|
import '../../types-C05PdDJa.cjs';
|
|
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.js';
|
|
3
3
|
import { TextProps } from '@visx/text';
|
|
4
4
|
import { BarChartProps } from '../bar-chart/index.js';
|
|
5
|
-
import { g as ScaleOptions, d as SeriesData } from '../../types-
|
|
5
|
+
import { g as ScaleOptions, d as SeriesData } from '../../types-B1_Q_Lhh.js';
|
|
6
6
|
import { ComponentType, FC } from 'react';
|
|
7
7
|
import '../../legend-jjMmhSg3.js';
|
|
8
8
|
import '../../types-C05PdDJa.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BarListChart,
|
|
3
3
|
BarListChartResponsive
|
|
4
|
-
} from "../../chunk-
|
|
5
|
-
import "../../chunk-
|
|
4
|
+
} from "../../chunk-2NRSBKV2.js";
|
|
5
|
+
import "../../chunk-PU2UO4EG.js";
|
|
6
6
|
import "../../chunk-ALDWCNLH.js";
|
|
7
7
|
import "../../chunk-5XI443YP.js";
|
|
8
8
|
import "../../chunk-NONODB3K.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { B as BaseChartProps } from '../../types-
|
|
2
|
+
import { B as BaseChartProps } from '../../types-B1_Q_Lhh.cjs';
|
|
3
3
|
import '@visx/annotation/lib/components/CircleSubject';
|
|
4
4
|
import '@visx/annotation/lib/components/Connector';
|
|
5
5
|
import '@visx/annotation/lib/components/Label';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { B as BaseChartProps } from '../../types-
|
|
2
|
+
import { B as BaseChartProps } from '../../types-B1_Q_Lhh.js';
|
|
3
3
|
import '@visx/annotation/lib/components/CircleSubject';
|
|
4
4
|
import '@visx/annotation/lib/components/Connector';
|
|
5
5
|
import '@visx/annotation/lib/components/Label';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.cjs';
|
|
3
3
|
import { FC } from 'react';
|
|
4
|
-
import { B as BaseChartProps, G as GeoData } from '../../types-
|
|
4
|
+
import { B as BaseChartProps, G as GeoData } from '../../types-B1_Q_Lhh.cjs';
|
|
5
5
|
import '@visx/annotation/lib/components/CircleSubject';
|
|
6
6
|
import '@visx/annotation/lib/components/Connector';
|
|
7
7
|
import '@visx/annotation/lib/components/Label';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.js';
|
|
3
3
|
import { FC } from 'react';
|
|
4
|
-
import { B as BaseChartProps, G as GeoData } from '../../types-
|
|
4
|
+
import { B as BaseChartProps, G as GeoData } from '../../types-B1_Q_Lhh.js';
|
|
5
5
|
import '@visx/annotation/lib/components/CircleSubject';
|
|
6
6
|
import '@visx/annotation/lib/components/Connector';
|
|
7
7
|
import '@visx/annotation/lib/components/Label';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { L as LeaderboardChart, b as LeaderboardChartProps, a as LeaderboardChartUnresponsive } from '../../leaderboard-chart-
|
|
2
|
-
import { L as LeaderboardEntry } from '../../types-
|
|
1
|
+
export { L as LeaderboardChart, b as LeaderboardChartProps, a as LeaderboardChartUnresponsive } from '../../leaderboard-chart-Df6kkqtI.cjs';
|
|
2
|
+
import { L as LeaderboardEntry } from '../../types-B1_Q_Lhh.cjs';
|
|
3
3
|
export { M as MetricValueType, f as formatMetricValue } from '../../format-metric-value-MXm5DtQ_.cjs';
|
|
4
4
|
import { B as BaseLegendItem } from '../../types-C05PdDJa.cjs';
|
|
5
5
|
import 'react/jsx-runtime';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { L as LeaderboardChart, b as LeaderboardChartProps, a as LeaderboardChartUnresponsive } from '../../leaderboard-chart-
|
|
2
|
-
import { L as LeaderboardEntry } from '../../types-
|
|
1
|
+
export { L as LeaderboardChart, b as LeaderboardChartProps, a as LeaderboardChartUnresponsive } from '../../leaderboard-chart-BOgMT2BT.js';
|
|
2
|
+
import { L as LeaderboardEntry } from '../../types-B1_Q_Lhh.js';
|
|
3
3
|
export { M as MetricValueType, f as formatMetricValue } from '../../format-metric-value-MXm5DtQ_.js';
|
|
4
4
|
import { B as BaseLegendItem } from '../../types-C05PdDJa.js';
|
|
5
5
|
import 'react/jsx-runtime';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { L as Legend } from '../../legend-C9ahiwOt.cjs';
|
|
2
|
-
import { B as BaseChartProps, d as SeriesData, b as DataPointDate, A as AnnotationStyles, O as Optional } from '../../types-
|
|
2
|
+
import { B as BaseChartProps, d as SeriesData, b as DataPointDate, A as AnnotationStyles, O as Optional } from '../../types-B1_Q_Lhh.cjs';
|
|
3
3
|
import { FC, ReactNode, SVGProps } from 'react';
|
|
4
4
|
import { GlyphProps } from '@visx/xychart';
|
|
5
5
|
import { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { L as Legend } from '../../legend-jjMmhSg3.js';
|
|
2
|
-
import { B as BaseChartProps, d as SeriesData, b as DataPointDate, A as AnnotationStyles, O as Optional } from '../../types-
|
|
2
|
+
import { B as BaseChartProps, d as SeriesData, b as DataPointDate, A as AnnotationStyles, O as Optional } from '../../types-B1_Q_Lhh.js';
|
|
3
3
|
import { FC, ReactNode, SVGProps } from 'react';
|
|
4
4
|
import { GlyphProps } from '@visx/xychart';
|
|
5
5
|
import { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.cjs';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { LegendValueDisplay } from '../../components/legend/index.cjs';
|
|
4
|
-
import { O as Optional, B as BaseChartProps, e as DataPointPercentage } from '../../types-
|
|
4
|
+
import { O as Optional, B as BaseChartProps, e as DataPointPercentage } from '../../types-B1_Q_Lhh.cjs';
|
|
5
5
|
import { C as ChartComponentWithComposition } from '../../types-BBwg4Evw.cjs';
|
|
6
6
|
import '../../legend-C9ahiwOt.cjs';
|
|
7
7
|
import '../../types-C05PdDJa.cjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.js';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { LegendValueDisplay } from '../../components/legend/index.js';
|
|
4
|
-
import { O as Optional, B as BaseChartProps, e as DataPointPercentage } from '../../types-
|
|
4
|
+
import { O as Optional, B as BaseChartProps, e as DataPointPercentage } from '../../types-B1_Q_Lhh.js';
|
|
5
5
|
import { C as ChartComponentWithComposition } from '../../types-DQNnq5Fr.js';
|
|
6
6
|
import '../../legend-jjMmhSg3.js';
|
|
7
7
|
import '../../types-C05PdDJa.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { LegendValueDisplay } from '../../components/legend/index.cjs';
|
|
3
|
-
import { O as Optional, B as BaseChartProps, e as DataPointPercentage } from '../../types-
|
|
3
|
+
import { O as Optional, B as BaseChartProps, e as DataPointPercentage } from '../../types-B1_Q_Lhh.cjs';
|
|
4
4
|
import { C as ChartComponentWithComposition } from '../../types-BBwg4Evw.cjs';
|
|
5
5
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.cjs';
|
|
6
6
|
import { PieArcDatum } from '@visx/shape/lib/shapes/Pie';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { LegendValueDisplay } from '../../components/legend/index.js';
|
|
3
|
-
import { O as Optional, B as BaseChartProps, e as DataPointPercentage } from '../../types-
|
|
3
|
+
import { O as Optional, B as BaseChartProps, e as DataPointPercentage } from '../../types-B1_Q_Lhh.js';
|
|
4
4
|
import { C as ChartComponentWithComposition } from '../../types-DQNnq5Fr.js';
|
|
5
5
|
import { R as ResponsiveConfig } from '../../with-responsive-Cp2qnQPo.js';
|
|
6
6
|
import { PieArcDatum } from '@visx/shape/lib/shapes/Pie';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BarChartResponsive
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PU2UO4EG.js";
|
|
4
4
|
import {
|
|
5
5
|
withResponsive
|
|
6
6
|
} from "./chunk-NONODB3K.js";
|
|
@@ -193,4 +193,4 @@ export {
|
|
|
193
193
|
BarListChart,
|
|
194
194
|
BarListChartResponsive
|
|
195
195
|
};
|
|
196
|
-
//# sourceMappingURL=chunk-
|
|
196
|
+
//# sourceMappingURL=chunk-2NRSBKV2.js.map
|
|
@@ -26,6 +26,7 @@ var _chunkMUUSZ7J5cjs = require('./chunk-MUUSZ7J5.cjs');
|
|
|
26
26
|
var _chunkWKN6C4ZEcjs = require('./chunk-WKN6C4ZE.cjs');
|
|
27
27
|
|
|
28
28
|
|
|
29
|
+
|
|
29
30
|
var _chunkZVGEDXDPcjs = require('./chunk-ZVGEDXDP.cjs');
|
|
30
31
|
|
|
31
32
|
// src/charts/bar-chart/bar-chart.tsx
|
|
@@ -50,6 +51,81 @@ var bar_chart_module_default = {
|
|
|
50
51
|
// src/charts/bar-chart/private/use-bar-chart-options.ts
|
|
51
52
|
|
|
52
53
|
|
|
54
|
+
|
|
55
|
+
// src/charts/bar-chart/private/truncated-tick-component.tsx
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
59
|
+
var getScaleBandwidth = (scale) => {
|
|
60
|
+
return scale && "bandwidth" in scale ? _nullishCoalesce(scale.bandwidth(), () => ( 0)) : 0;
|
|
61
|
+
};
|
|
62
|
+
var MIN_TICK_LABEL_WIDTH = 20;
|
|
63
|
+
var TruncatedTickComponent = ({
|
|
64
|
+
x,
|
|
65
|
+
y,
|
|
66
|
+
formattedValue,
|
|
67
|
+
axis,
|
|
68
|
+
textAnchor,
|
|
69
|
+
fill,
|
|
70
|
+
dy,
|
|
71
|
+
...textProps
|
|
72
|
+
}) => {
|
|
73
|
+
const { xScale, yScale } = _react.useContext.call(void 0, _xychart.DataContext) || {};
|
|
74
|
+
const scale = axis === "x" ? xScale : yScale;
|
|
75
|
+
const bandwidth = getScaleBandwidth(scale);
|
|
76
|
+
const maxWidth = Math.max(bandwidth, MIN_TICK_LABEL_WIDTH);
|
|
77
|
+
let textAlign = "center";
|
|
78
|
+
if (textAnchor === "start") {
|
|
79
|
+
textAlign = "left";
|
|
80
|
+
} else if (textAnchor === "end") {
|
|
81
|
+
textAlign = "right";
|
|
82
|
+
} else if (textAnchor === "middle") {
|
|
83
|
+
textAlign = "center";
|
|
84
|
+
}
|
|
85
|
+
let xOffset = 0;
|
|
86
|
+
if (textAlign === "center") {
|
|
87
|
+
xOffset = -maxWidth / 2;
|
|
88
|
+
} else if (textAlign === "right") {
|
|
89
|
+
xOffset = -maxWidth;
|
|
90
|
+
}
|
|
91
|
+
const { fontSize, fontFamily, fontWeight, fontStyle, letterSpacing, opacity } = textProps;
|
|
92
|
+
const textStyles = {
|
|
93
|
+
/**
|
|
94
|
+
* SVG <text> elements are vertically aligned to the baseline by default, but HTML <div> elements inside <foreignObject>
|
|
95
|
+
* are positioned relative to the top-left corner. To visually align the tick label like SVG text,
|
|
96
|
+
* we shift the div up by 100% of its height and adjust by twice the SVG dy value (from visx) to approximate original placement.
|
|
97
|
+
*/
|
|
98
|
+
transform: `translateY(calc(-100% + ${_nullishCoalesce(dy, () => ( "0"))} * 2))`,
|
|
99
|
+
// Safari doesn't work well with foreignObject positioning. Use position: fixed as a workaround.
|
|
100
|
+
..._chunkZVGEDXDPcjs.isSafari.call(void 0, ) ? { position: "fixed" } : {},
|
|
101
|
+
// Apply compatible SVG text styles
|
|
102
|
+
fontSize,
|
|
103
|
+
fontFamily,
|
|
104
|
+
fontWeight,
|
|
105
|
+
fontStyle,
|
|
106
|
+
letterSpacing,
|
|
107
|
+
opacity,
|
|
108
|
+
// Convert svg text styles to CSS styles for the div
|
|
109
|
+
color: _nullishCoalesce(fill, () => ( "inherit")),
|
|
110
|
+
textAlign,
|
|
111
|
+
// Ensure text is truncated with ellipsis, remains on one line, and shows the full value in a tooltip on hover.
|
|
112
|
+
// The surrounding div uses CSS to handle overflow, and the 'title' attribute is set for accessibility.
|
|
113
|
+
width: maxWidth,
|
|
114
|
+
overflow: "hidden",
|
|
115
|
+
textOverflow: "ellipsis",
|
|
116
|
+
whiteSpace: "nowrap",
|
|
117
|
+
cursor: "default",
|
|
118
|
+
pointerEvents: "auto"
|
|
119
|
+
};
|
|
120
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "foreignObject", { x: x + xOffset, y, width: maxWidth, height: 0, overflow: "visible", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { style: textStyles, title: formattedValue, children: formattedValue }) });
|
|
121
|
+
};
|
|
122
|
+
var createTruncatedTickComponent = (axis) => (props) => {
|
|
123
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TruncatedTickComponent, { ...props, axis });
|
|
124
|
+
};
|
|
125
|
+
var TruncatedXTickComponent = createTruncatedTickComponent("x");
|
|
126
|
+
var TruncatedYTickComponent = createTruncatedTickComponent("y");
|
|
127
|
+
|
|
128
|
+
// src/charts/bar-chart/private/use-bar-chart-options.ts
|
|
53
129
|
var formatDateTick = (timestamp) => {
|
|
54
130
|
const date = new Date(timestamp);
|
|
55
131
|
return date.toLocaleDateString(void 0, {
|
|
@@ -117,6 +193,8 @@ function useBarChartOptions(data, horizontal, options = {}) {
|
|
|
117
193
|
const xScale = { ...baseXScale, ...options.xScale || {} };
|
|
118
194
|
const yScale = { ...baseYScale, ...options.yScale || {} };
|
|
119
195
|
const providedToolTipLabelFormatter = horizontal ? _optionalChain([options, 'access', _9 => _9.axis, 'optionalAccess', _10 => _10.y, 'optionalAccess', _11 => _11.tickFormat]) : _optionalChain([options, 'access', _12 => _12.axis, 'optionalAccess', _13 => _13.x, 'optionalAccess', _14 => _14.tickFormat]);
|
|
196
|
+
const { labelOverflow: xLabelOverflow, ...xAxisOptions } = _optionalChain([options, 'access', _15 => _15.axis, 'optionalAccess', _16 => _16.x]) || {};
|
|
197
|
+
const { labelOverflow: yLabelOverflow, ...yAxisOptions } = _optionalChain([options, 'access', _17 => _17.axis, 'optionalAccess', _18 => _18.y]) || {};
|
|
120
198
|
return {
|
|
121
199
|
gridVisibility,
|
|
122
200
|
xScale,
|
|
@@ -130,13 +208,15 @@ function useBarChartOptions(data, horizontal, options = {}) {
|
|
|
130
208
|
orientation: "bottom",
|
|
131
209
|
numTicks: 4,
|
|
132
210
|
tickFormat: xTickFormat,
|
|
133
|
-
...
|
|
211
|
+
...xLabelOverflow === "ellipsis" ? { tickComponent: TruncatedXTickComponent } : {},
|
|
212
|
+
...xAxisOptions
|
|
134
213
|
},
|
|
135
214
|
y: {
|
|
136
215
|
orientation: "left",
|
|
137
216
|
numTicks: 4,
|
|
138
217
|
tickFormat: yTickFormat,
|
|
139
|
-
...
|
|
218
|
+
...yLabelOverflow === "ellipsis" ? { tickComponent: TruncatedYTickComponent } : {},
|
|
219
|
+
...yAxisOptions
|
|
140
220
|
}
|
|
141
221
|
},
|
|
142
222
|
barGroup: {
|
|
@@ -150,7 +230,7 @@ function useBarChartOptions(data, horizontal, options = {}) {
|
|
|
150
230
|
}
|
|
151
231
|
|
|
152
232
|
// src/charts/bar-chart/bar-chart.tsx
|
|
153
|
-
|
|
233
|
+
|
|
154
234
|
var validateData = (data) => {
|
|
155
235
|
if (!_optionalChain([data, 'optionalAccess', _19 => _19.length])) return "No data available";
|
|
156
236
|
const hasInvalidData = data.some(
|
|
@@ -505,4 +585,4 @@ var BarChartResponsive = _chunkZVGEDXDPcjs.attachSubComponents.call(void 0,
|
|
|
505
585
|
|
|
506
586
|
|
|
507
587
|
exports.BarChart = BarChart; exports.BarChartResponsive = BarChartResponsive;
|
|
508
|
-
//# sourceMappingURL=chunk-
|
|
588
|
+
//# sourceMappingURL=chunk-3OONWZ4Z.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-3OONWZ4Z.cjs","../src/charts/bar-chart/bar-chart.tsx","../src/charts/bar-chart/bar-chart.module.scss","../src/charts/bar-chart/private/use-bar-chart-options.ts","../src/charts/bar-chart/private/truncated-tick-component.tsx"],"names":["jsx","useMemo"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;AC/BA,iEAA6B;AAC7B,wCAA4E;AAC5E,wCAAyD;AACzD,uCAAmB;AACnB,wEAAiB;AACjB,8BAAmE;ADiCnE;AACA;AEvC8D,IAAO,yBAA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;AAAA,oBAAA;AACN,kBAAA;AAAA,gBAAA;AAAA,cAAA;AAEF,YAAA;AAGCA,YAAAA;AAAC,cAAA;AAAA,cAAA;AACc,gBAAA;AACH,gBAAA;AACC,gBAAA;AACD,gBAAA;AACI,gBAAA;AACf,gBAAA;AACwC,gBAAA;AAChC,gBAAA;AACF,gBAAA;AACN,gBAAA;AACc,gBAAA;AAAA,cAAA;AACf,YAAA;AAGC,YAAA;AAAA,UAAA;AAAA,QAAA;AACH,MAAA;AAAA,IAAA;AACD,EAAA;AAEF;AAE2D;AACF,EAAA;AAGjC,EAAA;AACgB,IAAA;AACvC,EAAA;AAKE,EAAA;AAGH;AAEmC;AAGyB;AAC3D,EAAA;AACC;AAGyB;AAC4B,EAAA;AACtD,EAAA;AACC,IAAA;AACD,EAAA;AACD;AD2FuE;AACA;AACA;AACA;AACA","file":"/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-3OONWZ4Z.cjs","sourcesContent":[null,"import { formatNumber } from '@automattic/number-formatters';\nimport { PatternLines, PatternCircles, PatternWaves, PatternHexagons } from '@visx/pattern';\nimport { Axis, BarSeries, BarGroup, Grid, XYChart } from '@visx/xychart';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { useCallback, useContext, useState, useRef, useMemo } from 'react';\nimport { Legend, useChartLegendItems } from '../../components/legend';\nimport { AccessibleTooltip, useKeyboardNavigation } from '../../components/tooltip';\nimport {\n\tuseXYChartTheme,\n\tuseChartDataTransform,\n\tuseZeroValueDisplay,\n\tuseChartMargin,\n\tuseElementHeight,\n\tusePrefersReducedMotion,\n} from '../../hooks';\nimport {\n\tGlobalChartsProvider,\n\tuseChartId,\n\tuseChartRegistration,\n\tuseGlobalChartsContext,\n\tuseGlobalChartsTheme,\n\tGlobalChartsContext,\n} from '../../providers';\nimport { attachSubComponents } from '../../utils';\nimport { SingleChartContext } from '../private/single-chart-context';\nimport { withResponsive } from '../private/with-responsive';\nimport styles from './bar-chart.module.scss';\nimport { useBarChartOptions } from './private';\nimport type { BaseChartProps, DataPointDate, SeriesData, Optional } from '../../types';\nimport type { ResponsiveConfig } from '../private/with-responsive';\nimport type { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';\nimport type { FC, ReactNode, ComponentType } from 'react';\n\nexport interface BarChartProps extends BaseChartProps< SeriesData[] > {\n\trenderTooltip?: ( params: RenderTooltipParams< DataPointDate > ) => ReactNode;\n\torientation?: 'horizontal' | 'vertical';\n\twithPatterns?: boolean;\n\tshowZeroValues?: boolean;\n\tlegendInteractive?: boolean;\n\tchildren?: ReactNode;\n}\n\n// Base props type with optional responsive properties\ntype BarChartBaseProps = Optional< BarChartProps, 'width' | 'height' | 'size' >;\n\n// Composition API types\ninterface BarChartSubComponents {\n\tLegend: ComponentType< React.ComponentProps< typeof Legend > >;\n}\n\ntype BarChartComponent = FC< BarChartBaseProps > & BarChartSubComponents;\ntype BarChartResponsiveComponent = FC< BarChartBaseProps & ResponsiveConfig > &\n\tBarChartSubComponents;\n\n// Validation function similar to LineChart\nconst validateData = ( data: SeriesData[] ) => {\n\tif ( ! data?.length ) return 'No data available';\n\n\tconst hasInvalidData = data.some( series =>\n\t\tseries.data.some(\n\t\t\tpoint =>\n\t\t\t\tisNaN( point.value as number ) ||\n\t\t\t\tpoint.value === null ||\n\t\t\t\tpoint.value === undefined ||\n\t\t\t\t( ! point.label &&\n\t\t\t\t\t( ! ( 'date' in point && point.date ) || isNaN( point.date.getTime() ) ) )\n\t\t)\n\t);\n\n\tif ( hasInvalidData ) return 'Invalid data';\n\treturn null;\n};\n\nconst getPatternId = ( chartId: string, index: number ) => `bar-pattern-${ chartId }-${ index }`;\n\nconst BarChartInternal: FC< BarChartProps > = ( {\n\tdata,\n\tchartId: providedChartId,\n\twidth,\n\theight = 400,\n\tclassName,\n\tmargin,\n\twithTooltips = false,\n\tshowLegend = false,\n\tlegendOrientation = 'horizontal',\n\tlegendPosition = 'bottom',\n\tlegendAlignment = 'center',\n\tlegendMaxWidth,\n\tlegendTextOverflow = 'wrap',\n\tlegendItemClassName,\n\tlegendShape = 'rect',\n\tgridVisibility: gridVisibilityProp,\n\trenderTooltip,\n\toptions = {},\n\torientation = 'vertical',\n\twithPatterns = false,\n\tshowZeroValues = false,\n\tlegendInteractive = false,\n\tanimation,\n\tchildren,\n} ) => {\n\tconst horizontal = orientation === 'horizontal';\n\tconst chartId = useChartId( providedChartId );\n\tconst theme = useXYChartTheme( data );\n\n\tconst dataSorted = useChartDataTransform( data );\n\n\t// Transform data to add a small value for zero bars to make them visible\n\tconst dataWithVisibleZeros = useZeroValueDisplay( dataSorted, {\n\t\tenabled: showZeroValues,\n\t} );\n\n\t// Create legend items using the reusable hook\n\tconst legendItems = useChartLegendItems( dataSorted );\n\tconst chartOptions = useBarChartOptions( dataWithVisibleZeros, horizontal, options );\n\tconst defaultMargin = useChartMargin( height, chartOptions, dataSorted, theme, horizontal );\n\tconst [ legendRef, legendHeight ] = useElementHeight< HTMLDivElement >();\n\tconst chartRef = useRef< HTMLDivElement >( null );\n\tconst [ selectedIndex, setSelectedIndex ] = useState< number | undefined >( undefined );\n\tconst [ isNavigating, setIsNavigating ] = useState( false );\n\n\tconst totalPoints =\n\t\tMath.max( 0, ...data.map( series => series.data?.length || 0 ) ) * data.length;\n\n\t// Use the keyboard navigation hook\n\tconst { tooltipRef, onChartFocus, onChartBlur, onChartKeyDown } = useKeyboardNavigation( {\n\t\tselectedIndex,\n\t\tsetSelectedIndex,\n\t\tisNavigating,\n\t\tsetIsNavigating,\n\t\tchartRef,\n\t\ttotalPoints,\n\t} );\n\n\tconst { getElementStyles, isSeriesVisible } = useGlobalChartsContext();\n\tconst providerTheme = useGlobalChartsTheme();\n\n\t// Add visibility information to series when using interactive legends\n\tconst seriesWithVisibility = useMemo( () => {\n\t\tif ( ! chartId || ! legendInteractive ) {\n\t\t\treturn dataWithVisibleZeros.map( ( series, index ) => ( {\n\t\t\t\tseries,\n\t\t\t\tindex,\n\t\t\t\tisVisible: true,\n\t\t\t} ) );\n\t\t}\n\t\treturn dataWithVisibleZeros.map( ( series, index ) => ( {\n\t\t\tseries,\n\t\t\tindex,\n\t\t\tisVisible: isSeriesVisible( chartId, series.label ),\n\t\t} ) );\n\t}, [ dataWithVisibleZeros, chartId, isSeriesVisible, legendInteractive ] );\n\n\t// Check if all series are hidden\n\tconst allSeriesHidden = useMemo( () => {\n\t\treturn seriesWithVisibility.every( ( { isVisible } ) => ! isVisible );\n\t}, [ seriesWithVisibility ] );\n\n\tconst getBarBackground = useCallback(\n\t\t( index: number ) => () =>\n\t\t\twithPatterns\n\t\t\t\t? `url(#${ getPatternId( chartId, index ) })`\n\t\t\t\t: getElementStyles( { data: dataSorted[ index ], index } ).color,\n\t\t[ withPatterns, getElementStyles, dataSorted, chartId ]\n\t);\n\n\tconst renderDefaultTooltip = useCallback(\n\t\t( { tooltipData }: RenderTooltipParams< DataPointDate > ) => {\n\t\t\tconst nearestDatum = tooltipData?.nearestDatum?.datum;\n\t\t\tif ( ! nearestDatum ) return null;\n\n\t\t\treturn (\n\t\t\t\t<div className={ styles[ 'bar-chart__tooltip' ] }>\n\t\t\t\t\t<div className={ styles[ 'bar-chart__tooltip-header' ] }>\n\t\t\t\t\t\t{ tooltipData?.nearestDatum?.key }\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className={ styles[ 'bar-chart__tooltip-row' ] }>\n\t\t\t\t\t\t<span className={ styles[ 'bar-chart__tooltip-label' ] }>\n\t\t\t\t\t\t\t{ chartOptions.tooltip.labelFormatter(\n\t\t\t\t\t\t\t\tnearestDatum.label || ( nearestDatum.date ? nearestDatum.date.getTime() : 0 ),\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t[]\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t:\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span className={ styles[ 'bar-chart__tooltip-value' ] }>\n\t\t\t\t\t\t\t{ formatNumber( nearestDatum.value as number ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t);\n\t\t},\n\t\t[ chartOptions.tooltip ]\n\t);\n\n\tconst renderPattern = useCallback(\n\t\t( index: number, color: string ) => {\n\t\t\tconst patternType = index % 4;\n\t\t\tconst id = getPatternId( chartId, index );\n\t\t\tconst commonProps = {\n\t\t\t\tid,\n\t\t\t\tstroke: 'white',\n\t\t\t\tstrokeWidth: 1,\n\t\t\t\tbackground: color,\n\t\t\t};\n\n\t\t\tswitch ( patternType ) {\n\t\t\t\tcase 0:\n\t\t\t\tdefault:\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<PatternLines\n\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\t{ ...commonProps }\n\t\t\t\t\t\t\twidth={ 5 }\n\t\t\t\t\t\t\theight={ 5 }\n\t\t\t\t\t\t\torientation={ [ 'diagonal' ] }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\tcase 1:\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<PatternCircles key={ id } { ...commonProps } width={ 6 } height={ 6 } fill=\"white\" />\n\t\t\t\t\t);\n\t\t\t\tcase 2:\n\t\t\t\t\treturn <PatternWaves key={ id } { ...commonProps } width={ 4 } height={ 4 } />;\n\t\t\t\tcase 3:\n\t\t\t\t\treturn <PatternHexagons key={ id } { ...commonProps } size={ 8 } height={ 3 } />;\n\t\t\t}\n\t\t},\n\t\t[ chartId ]\n\t);\n\n\tconst createPatternBorderStyle = useCallback(\n\t\t( index: number, color: string ) => {\n\t\t\tconst patternId = getPatternId( chartId, index );\n\t\t\treturn `\n\t\t\t.visx-bar[fill=\"url(#${ patternId })\"] {\n\t\t\t\tstroke: ${ color };\n\t\t\t\tstroke-width: 1;\n\t\t\t\t}\n\t\t\t`;\n\t\t},\n\t\t[ chartId ]\n\t);\n\n\tconst createKeyboardHighlightStyle = useCallback( () => {\n\t\tif ( selectedIndex === undefined ) return '';\n\n\t\t// Calculate which bar should be highlighted based on selectedIndex\n\t\t// Pattern: [series1[0], series2[0], series3[0], series1[1], series2[1], series3[1], ...]\n\t\tconst maxDataPoints = Math.max( ...data.map( s => s.data.length ) );\n\t\tconst dataPointIndex = Math.floor( selectedIndex / data.length );\n\t\tconst seriesIndex = selectedIndex % data.length;\n\n\t\t// Only highlight if we're within valid bounds\n\t\tif ( dataPointIndex >= maxDataPoints || seriesIndex >= data.length ) {\n\t\t\treturn '';\n\t\t}\n\n\t\tconst seriesData = data[ seriesIndex ];\n\t\tif ( dataPointIndex >= seriesData.data.length ) {\n\t\t\treturn '';\n\t\t}\n\n\t\t// Based on the DOM structure analysis:\n\t\t// - All bars are in a single .visx-bar-group\n\t\t// - Bars are ordered as: [series1[0], series1[1], series2[0], series2[1], ...]\n\t\t// - So we need to calculate the actual bar index in the DOM\n\t\tconst actualBarIndex = seriesIndex * maxDataPoints + dataPointIndex;\n\n\t\t// Use a CSS class selector instead of ID since useId() generates invalid CSS ID characters\n\t\tconst generatedStyles = `\n\t\t\t.bar-chart[data-chart-id=\"bar-chart-${ chartId }\"] .visx-bar-group .visx-bar:nth-child(${\n\t\t\t\tactualBarIndex + 1\n\t\t\t}) {\n\t\t\t\tstroke: #005fcc;\n\t\t\t\tstroke-width: 2px;\n\t\t\t}\n\t\t`;\n\n\t\treturn generatedStyles;\n\t}, [ selectedIndex, data, chartId ] );\n\n\t// Validate data first\n\tconst error = validateData( dataSorted );\n\tconst isDataValid = ! error;\n\n\t// Memoize metadata to prevent unnecessary re-registration\n\tconst chartMetadata = useMemo(\n\t\t() => ( {\n\t\t\torientation,\n\t\t\twithPatterns,\n\t\t} ),\n\t\t[ orientation, withPatterns ]\n\t);\n\n\t// Register chart with context only if data is valid\n\tuseChartRegistration( {\n\t\tchartId,\n\t\tlegendItems,\n\t\tchartType: 'bar',\n\t\tisDataValid,\n\t\tmetadata: chartMetadata,\n\t} );\n\n\tconst prefersReducedMotion = usePrefersReducedMotion();\n\n\tif ( error ) {\n\t\treturn <div className={ clsx( 'bar-chart', styles[ 'bar-chart' ] ) }>{ error }</div>;\n\t}\n\n\tconst gridVisibility = gridVisibilityProp ?? chartOptions.gridVisibility;\n\tconst highlightedBarStyle = createKeyboardHighlightStyle();\n\n\treturn (\n\t\t<SingleChartContext.Provider\n\t\t\tvalue={ {\n\t\t\t\tchartId,\n\t\t\t\tchartWidth: width,\n\t\t\t\tchartHeight: height - ( showLegend ? legendHeight : 0 ),\n\t\t\t} }\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'bar-chart',\n\t\t\t\t\tstyles[ 'bar-chart' ],\n\t\t\t\t\t{\n\t\t\t\t\t\t[ styles[ `bar-chart--animated${ horizontal ? '-horizontal' : '' }` ] ]:\n\t\t\t\t\t\t\tanimation && ! prefersReducedMotion,\n\t\t\t\t\t\t[ styles[ 'bar-chart--legend-top' ] ]: showLegend && legendPosition === 'top',\n\t\t\t\t\t},\n\t\t\t\t\tclassName\n\t\t\t\t) }\n\t\t\t\tdata-testid=\"bar-chart\"\n\t\t\t\trole=\"grid\"\n\t\t\t\taria-label={ __( 'Bar chart', 'jetpack-charts' ) }\n\t\t\t\tstyle={ {\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t} }\n\t\t\t\ttabIndex={ 0 }\n\t\t\t\tonKeyDown={ onChartKeyDown }\n\t\t\t\tonFocus={ onChartFocus }\n\t\t\t\tonBlur={ onChartBlur }\n\t\t\t\tref={ chartRef }\n\t\t\t\tdata-chart-id={ `bar-chart-${ chartId }` } // Unique ID for the chart\n\t\t\t>\n\t\t\t\t<XYChart\n\t\t\t\t\ttheme={ theme }\n\t\t\t\t\twidth={ width }\n\t\t\t\t\theight={ height - ( showLegend ? legendHeight : 0 ) }\n\t\t\t\t\tmargin={ {\n\t\t\t\t\t\t...defaultMargin,\n\t\t\t\t\t\t...margin,\n\t\t\t\t\t\t...( showLegend && legendPosition === 'top'\n\t\t\t\t\t\t\t? { top: ( defaultMargin.top || 0 ) + legendHeight }\n\t\t\t\t\t\t\t: {} ),\n\t\t\t\t\t} }\n\t\t\t\t\txScale={ chartOptions.xScale }\n\t\t\t\t\tyScale={ chartOptions.yScale }\n\t\t\t\t\thorizontal={ horizontal }\n\t\t\t\t\tpointerEventsDataKey=\"nearest\"\n\t\t\t\t>\n\t\t\t\t\t<Grid\n\t\t\t\t\t\tcolumns={ gridVisibility.includes( 'y' ) }\n\t\t\t\t\t\trows={ gridVisibility.includes( 'x' ) }\n\t\t\t\t\t\tnumTicks={ 4 }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ withPatterns && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<defs data-testid=\"bar-chart-patterns\">\n\t\t\t\t\t\t\t\t{ dataSorted.map( ( seriesData, index ) =>\n\t\t\t\t\t\t\t\t\trenderPattern( index, getElementStyles( { data: seriesData, index } ).color )\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</defs>\n\t\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t\t{ dataSorted.map( ( seriesData, index ) =>\n\t\t\t\t\t\t\t\t\tcreatePatternBorderStyle(\n\t\t\t\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\t\t\t\tgetElementStyles( { data: seriesData, index } ).color\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</style>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ highlightedBarStyle && <style>{ highlightedBarStyle }</style> }\n\n\t\t\t\t\t{ allSeriesHidden ? (\n\t\t\t\t\t\t<text\n\t\t\t\t\t\t\tx={ width / 2 }\n\t\t\t\t\t\t\ty={ ( height - ( showLegend ? legendHeight : 0 ) ) / 2 }\n\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\tfill={ providerTheme.gridStyles?.stroke || '#ccc' }\n\t\t\t\t\t\t\tfontSize=\"14\"\n\t\t\t\t\t\t\tfontFamily=\"-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'All series are hidden. Click legend items to show data.', 'jetpack-charts' ) }\n\t\t\t\t\t\t</text>\n\t\t\t\t\t) : null }\n\n\t\t\t\t\t<BarGroup padding={ chartOptions.barGroup.padding }>\n\t\t\t\t\t\t{ seriesWithVisibility.map( ( { series: seriesData, index, isVisible } ) => {\n\t\t\t\t\t\t\t// Skip rendering invisible series\n\t\t\t\t\t\t\tif ( ! isVisible ) {\n\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<BarSeries\n\t\t\t\t\t\t\t\t\tkey={ seriesData?.label }\n\t\t\t\t\t\t\t\t\tdataKey={ seriesData?.label }\n\t\t\t\t\t\t\t\t\tdata={ seriesData.data as DataPointDate[] }\n\t\t\t\t\t\t\t\t\tyAccessor={ chartOptions.accessors.yAccessor }\n\t\t\t\t\t\t\t\t\txAccessor={ chartOptions.accessors.xAccessor }\n\t\t\t\t\t\t\t\t\tcolorAccessor={ getBarBackground( index ) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</BarGroup>\n\n\t\t\t\t\t<Axis { ...chartOptions.axis.x } />\n\t\t\t\t\t<Axis { ...chartOptions.axis.y } />\n\n\t\t\t\t\t{ withTooltips && (\n\t\t\t\t\t\t<AccessibleTooltip\n\t\t\t\t\t\t\tdetectBounds\n\t\t\t\t\t\t\tsnapTooltipToDatumX\n\t\t\t\t\t\t\tsnapTooltipToDatumY\n\t\t\t\t\t\t\trenderTooltip={ renderTooltip || renderDefaultTooltip }\n\t\t\t\t\t\t\tselectedIndex={ selectedIndex }\n\t\t\t\t\t\t\ttooltipRef={ tooltipRef }\n\t\t\t\t\t\t\tkeyboardFocusedClassName={ styles[ 'bar-chart__tooltip--keyboard-focused' ] }\n\t\t\t\t\t\t\tseries={ data }\n\t\t\t\t\t\t\tmode=\"individual\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</XYChart>\n\n\t\t\t\t{ showLegend && (\n\t\t\t\t\t<Legend\n\t\t\t\t\t\torientation={ legendOrientation }\n\t\t\t\t\t\tposition={ legendPosition }\n\t\t\t\t\t\talignment={ legendAlignment }\n\t\t\t\t\t\tmaxWidth={ legendMaxWidth }\n\t\t\t\t\t\ttextOverflow={ legendTextOverflow }\n\t\t\t\t\t\tlegendItemClassName={ legendItemClassName }\n\t\t\t\t\t\tclassName={ styles[ 'bar-chart__legend' ] }\n\t\t\t\t\t\tshape={ legendShape }\n\t\t\t\t\t\tref={ legendRef }\n\t\t\t\t\t\tchartId={ chartId }\n\t\t\t\t\t\tinteractive={ legendInteractive }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</SingleChartContext.Provider>\n\t);\n};\n\nconst BarChartWithProvider: FC< BarChartProps > = props => {\n\tconst existingContext = useContext( GlobalChartsContext );\n\n\t// If we're already in a GlobalChartsProvider context, don't create a new one\n\tif ( existingContext ) {\n\t\treturn <BarChartInternal { ...props } />;\n\t}\n\n\t// Otherwise, create our own GlobalChartsProvider\n\treturn (\n\t\t<GlobalChartsProvider>\n\t\t\t<BarChartInternal { ...props } />\n\t\t</GlobalChartsProvider>\n\t);\n};\n\nBarChartWithProvider.displayName = 'BarChart';\n\n// Create BarChart with composition API\nconst BarChart = attachSubComponents( BarChartWithProvider, {\n\tLegend: Legend,\n} ) as BarChartComponent;\n\n// Create responsive BarChart with composition API\nconst BarChartResponsive = attachSubComponents(\n\twithResponsive< BarChartProps >( BarChartWithProvider ),\n\t{\n\t\tLegend: Legend,\n\t}\n) as BarChartResponsiveComponent;\n\nexport { BarChartResponsive as default, BarChart as BarChartUnresponsive };\n","import 'css-chunk:src/charts/bar-chart/bar-chart.module.scss';export default {\n \"bar-chart\": \"a8ccharts-3gflnB\",\n \"bar-chart--legend-top\": \"a8ccharts-8Vnz-c\",\n \"bar-chart-legend\": \"a8ccharts-XhI9HR\",\n \"bar-chart--animated\": \"a8ccharts-98W-yu\",\n \"rise\": \"a8ccharts-z6AsiQ\",\n \"bar-chart--animated-horizontal\": \"a8ccharts-HFA3FF\",\n \"stretch\": \"a8ccharts-DQp37O\"\n};","import { formatNumberCompact } from '@automattic/number-formatters';\nimport { useMemo } from 'react';\nimport { TruncatedXTickComponent, TruncatedYTickComponent } from './truncated-tick-component';\nimport type { EnhancedDataPoint } from '../../../hooks/use-zero-value-display';\nimport type { DataPointDate, BaseChartProps, SeriesData } from '../../../types';\nimport type { TickFormatter } from '@visx/axis';\n\nconst formatDateTick = ( timestamp: number ) => {\n\tconst date = new Date( timestamp );\n\treturn date.toLocaleDateString( undefined, {\n\t\tmonth: 'short',\n\t\tday: 'numeric',\n\t} );\n};\n\n/**\n * Get the group padding of a scale.\n *\n * @param scale - The scale to get the group padding of.\n * @return The group padding of the scale.\n */\nconst getGroupPadding = ( scale: Record< string, unknown > ): number => {\n\treturn typeof scale.paddingInner === 'number' ? ( scale.paddingInner as number ) : 0;\n};\n\n/**\n * Returns the merged options for the bar chart, including axis and scale configuration based on the orientation.\n *\n * @param data - The data to be displayed in the chart.\n * @param horizontal - Whether the chart is horizontal or vertical.\n * @param options - The options for the chart.\n * @return The merged options for the chart.\n */\nexport function useBarChartOptions(\n\tdata: SeriesData[],\n\thorizontal: boolean,\n\toptions: BaseChartProps[ 'options' ] = {}\n) {\n\tconst defaultOptions = useMemo( () => {\n\t\tconst bandScale = {\n\t\t\ttype: 'band' as const,\n\t\t\tpadding: 0.2,\n\t\t\tpaddingInner: 0.1,\n\t\t};\n\t\tconst linearScale = {\n\t\t\ttype: 'linear' as const,\n\t\t\tnice: true,\n\t\t\tzero: false,\n\t\t};\n\n\t\tconst labelFormatter = data?.[ 0 ]?.data?.[ 0 ]?.label\n\t\t\t? ( label: string ) => label\n\t\t\t: formatDateTick;\n\t\tconst valueFormatter = formatNumberCompact as TickFormatter< unknown >;\n\n\t\tconst labelAccessor = ( d: DataPointDate ) => d?.label || d?.date;\n\t\tconst valueAccessor = ( d: DataPointDate | EnhancedDataPoint ) => {\n\t\t\t// Use visualValue for bar rendering if available (for zero values), otherwise use value\n\t\t\tconst enhancedPoint = d as EnhancedDataPoint;\n\t\t\treturn enhancedPoint?.visualValue !== undefined ? enhancedPoint.visualValue : d?.value;\n\t\t};\n\n\t\treturn {\n\t\t\tvertical: {\n\t\t\t\txTickFormat: labelFormatter,\n\t\t\t\tyTickFormat: valueFormatter,\n\t\t\t\ttooltipLabelFormatter: labelFormatter,\n\t\t\t\txAccessor: labelAccessor,\n\t\t\t\tyAccessor: valueAccessor,\n\t\t\t\tgridVisibility: 'x',\n\t\t\t\txScale: bandScale,\n\t\t\t\tyScale: linearScale,\n\t\t\t},\n\t\t\thorizontal: {\n\t\t\t\txTickFormat: valueFormatter,\n\t\t\t\tyTickFormat: labelFormatter,\n\t\t\t\ttooltipLabelFormatter: labelFormatter,\n\t\t\t\txAccessor: valueAccessor,\n\t\t\t\tyAccessor: labelAccessor,\n\t\t\t\tgridVisibility: 'y',\n\t\t\t\txScale: linearScale,\n\t\t\t\tyScale: bandScale,\n\t\t\t},\n\t\t};\n\t}, [ data ] );\n\n\treturn useMemo( () => {\n\t\tconst orientationKey = horizontal ? 'horizontal' : 'vertical';\n\t\tconst {\n\t\t\txTickFormat,\n\t\t\tyTickFormat,\n\t\t\ttooltipLabelFormatter: defaultTooltipLabelFormatter,\n\t\t\txAccessor,\n\t\t\tyAccessor,\n\t\t\tgridVisibility,\n\t\t\txScale: baseXScale,\n\t\t\tyScale: baseYScale,\n\t\t} = defaultOptions[ orientationKey ];\n\n\t\tconst xScale = { ...baseXScale, ...( options.xScale || {} ) };\n\t\tconst yScale = { ...baseYScale, ...( options.yScale || {} ) };\n\t\tconst providedToolTipLabelFormatter = horizontal\n\t\t\t? options.axis?.y?.tickFormat\n\t\t\t: options.axis?.x?.tickFormat;\n\n\t\tconst { labelOverflow: xLabelOverflow, ...xAxisOptions } = options.axis?.x || {};\n\t\tconst { labelOverflow: yLabelOverflow, ...yAxisOptions } = options.axis?.y || {};\n\n\t\treturn {\n\t\t\tgridVisibility,\n\t\t\txScale,\n\t\t\tyScale,\n\t\t\taccessors: {\n\t\t\t\txAccessor,\n\t\t\t\tyAccessor,\n\t\t\t},\n\t\t\taxis: {\n\t\t\t\tx: {\n\t\t\t\t\torientation: 'bottom' as const,\n\t\t\t\t\tnumTicks: 4,\n\t\t\t\t\ttickFormat: xTickFormat,\n\t\t\t\t\t...( xLabelOverflow === 'ellipsis' ? { tickComponent: TruncatedXTickComponent } : {} ),\n\t\t\t\t\t...xAxisOptions,\n\t\t\t\t},\n\t\t\t\ty: {\n\t\t\t\t\torientation: 'left' as const,\n\t\t\t\t\tnumTicks: 4,\n\t\t\t\t\ttickFormat: yTickFormat,\n\t\t\t\t\t...( yLabelOverflow === 'ellipsis' ? { tickComponent: TruncatedYTickComponent } : {} ),\n\t\t\t\t\t...yAxisOptions,\n\t\t\t\t},\n\t\t\t},\n\t\t\tbarGroup: {\n\t\t\t\tpadding: getGroupPadding( horizontal ? yScale : xScale ),\n\t\t\t},\n\t\t\ttooltip: {\n\t\t\t\tlabelFormatter: providedToolTipLabelFormatter || defaultTooltipLabelFormatter,\n\t\t\t},\n\t\t};\n\t}, [ defaultOptions, options, horizontal ] );\n}\n","import { DataContext } from '@visx/xychart';\nimport { useContext } from 'react';\nimport { isSafari } from '../../../utils';\nimport type { AxisScale, TickRendererProps } from '@visx/axis';\nimport type { FC, CSSProperties } from 'react';\n\n/**\n * Get the bandwidth of a scale\n *\n * @param scale - The scale to get the bandwidth of\n * @return The bandwidth of the scale\n */\nconst getScaleBandwidth = < Scale extends AxisScale >( scale?: Scale ) => {\n\treturn scale && 'bandwidth' in scale ? scale.bandwidth() ?? 0 : 0;\n};\ninterface TruncatedTickComponentProps extends TickRendererProps {\n\t/** Which axis this tick belongs to */\n\taxis: 'x' | 'y';\n}\n\n/**\n * Minimum width in pixels for tick labels when scale bandwidth is very small.\n * Prevents labels from collapsing to unreadable widths on dense charts.\n *\n * Trade-off: When bandwidth is less than this minimum (e.g., many bars in a narrow chart),\n * adjacent labels may overlap since each label uses this minimum width regardless of\n * available space. This prioritizes label readability over preventing overlap.\n *\n * For very dense charts where overlap occurs, consider:\n * - Using `numTicks` option to reduce the number of displayed labels\n * - Using `tickFormat` to abbreviate label text\n * - Increasing chart width or reducing data points\n */\nconst MIN_TICK_LABEL_WIDTH = 20;\n\n/**\n * A tick component that renders labels with text truncation (ellipsis) when they exceed\n * the available bandwidth. Shows the full text on hover via native title attribute.\n *\n * Uses foreignObject to embed HTML within SVG, enabling CSS text-overflow: ellipsis.\n * Inherits text styles from tickLabelProps passed by visx Axis component.\n *\n * Note: A minimum label width (MIN_TICK_LABEL_WIDTH) is enforced to keep labels readable.\n * On very dense charts where bandwidth < 20px, this may cause label overlap.\n * See MIN_TICK_LABEL_WIDTH documentation for mitigation strategies.\n *\n * @param props - The props for the truncated tick component\n * @param props.x - The x position of the tick\n * @param props.y - The y position of the tick\n * @param props.formattedValue - The formatted value of the tick\n * @param props.axis - The axis this tick belongs to\n * @param props.textAnchor - The text anchor of the tick\n * @param props.fill - The fill color of the tick\n * @param props.dy - The dy offset of the tick\n *\n * @return The truncated tick component\n */\nexport const TruncatedTickComponent: FC< TruncatedTickComponentProps > = ( {\n\tx,\n\ty,\n\tformattedValue,\n\taxis,\n\ttextAnchor,\n\tfill,\n\tdy,\n\t...textProps\n} ) => {\n\t// Get max width of the tick label\n\tconst { xScale, yScale } = useContext( DataContext ) || {};\n\tconst scale = axis === 'x' ? xScale : yScale;\n\tconst bandwidth = getScaleBandwidth( scale );\n\tconst maxWidth = Math.max( bandwidth, MIN_TICK_LABEL_WIDTH );\n\n\t// Map SVG textAnchor to CSS textAlign\n\tlet textAlign: 'left' | 'right' | 'center' = 'center';\n\tif ( textAnchor === 'start' ) {\n\t\ttextAlign = 'left';\n\t} else if ( textAnchor === 'end' ) {\n\t\ttextAlign = 'right';\n\t} else if ( textAnchor === 'middle' ) {\n\t\ttextAlign = 'center';\n\t}\n\n\t// Calculate x offset based on text alignment\n\tlet xOffset = 0;\n\tif ( textAlign === 'center' ) {\n\t\txOffset = -maxWidth / 2;\n\t} else if ( textAlign === 'right' ) {\n\t\txOffset = -maxWidth;\n\t}\n\n\t// Extract compatible style properties from SVG text props\n\tconst { fontSize, fontFamily, fontWeight, fontStyle, letterSpacing, opacity } = textProps as {\n\t\tfontSize?: CSSProperties[ 'fontSize' ];\n\t\tfontFamily?: CSSProperties[ 'fontFamily' ];\n\t\tfontWeight?: CSSProperties[ 'fontWeight' ];\n\t\tfontStyle?: CSSProperties[ 'fontStyle' ];\n\t\tletterSpacing?: CSSProperties[ 'letterSpacing' ];\n\t\topacity?: CSSProperties[ 'opacity' ];\n\t};\n\n\tconst textStyles: CSSProperties = {\n\t\t/**\n\t\t * SVG <text> elements are vertically aligned to the baseline by default, but HTML <div> elements inside <foreignObject>\n\t\t * are positioned relative to the top-left corner. To visually align the tick label like SVG text,\n\t\t * we shift the div up by 100% of its height and adjust by twice the SVG dy value (from visx) to approximate original placement.\n\t\t */\n\t\ttransform: `translateY(calc(-100% + ${ dy ?? '0' } * 2))`,\n\t\t// Safari doesn't work well with foreignObject positioning. Use position: fixed as a workaround.\n\t\t...( isSafari() ? { position: 'fixed' as const } : {} ),\n\t\t// Apply compatible SVG text styles\n\t\tfontSize,\n\t\tfontFamily,\n\t\tfontWeight,\n\t\tfontStyle,\n\t\tletterSpacing,\n\t\topacity,\n\t\t// Convert svg text styles to CSS styles for the div\n\t\tcolor: fill ?? 'inherit',\n\t\ttextAlign,\n\t\t// Ensure text is truncated with ellipsis, remains on one line, and shows the full value in a tooltip on hover.\n\t\t// The surrounding div uses CSS to handle overflow, and the 'title' attribute is set for accessibility.\n\t\twidth: maxWidth,\n\t\toverflow: 'hidden',\n\t\ttextOverflow: 'ellipsis',\n\t\twhiteSpace: 'nowrap',\n\t\tcursor: 'default',\n\t\tpointerEvents: 'auto',\n\t};\n\n\treturn (\n\t\t<foreignObject x={ x + xOffset } y={ y } width={ maxWidth } height={ 0 } overflow=\"visible\">\n\t\t\t<div style={ textStyles } title={ formattedValue }>\n\t\t\t\t{ formattedValue }\n\t\t\t</div>\n\t\t</foreignObject>\n\t);\n};\n\n/**\n * Factory function to create a truncated tick component for a specific axis.\n * Returns a component that can be passed to visx's tickComponent prop.\n *\n * @param axis - The axis this tick component is for ('x' or 'y')\n * @return A tick component function compatible with visx's TickRendererProps\n */\nconst createTruncatedTickComponent = ( axis: 'x' | 'y' ) => ( props: TickRendererProps ) => {\n\treturn <TruncatedTickComponent { ...props } axis={ axis } />;\n};\n\n/**\n * Pre-created tick components for x and y axes.\n * These functions are created once at module initialization and reused,\n * avoiding repeated factory calls when configuring axes.\n */\nexport const TruncatedXTickComponent = createTruncatedTickComponent( 'x' );\nexport const TruncatedYTickComponent = createTruncatedTickComponent( 'y' );\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk3OONWZ4Zcjs = require('./chunk-3OONWZ4Z.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkMUUSZ7J5cjs = require('./chunk-MUUSZ7J5.cjs');
|
|
@@ -142,7 +142,7 @@ var BarListChartInternal = ({
|
|
|
142
142
|
};
|
|
143
143
|
}, [options, width, data, height]);
|
|
144
144
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
145
|
-
|
|
145
|
+
_chunk3OONWZ4Zcjs.BarChartResponsive,
|
|
146
146
|
{
|
|
147
147
|
orientation: "horizontal",
|
|
148
148
|
gridVisibility: "none",
|
|
@@ -193,4 +193,4 @@ var BarListChartResponsive = _chunkMUUSZ7J5cjs.withResponsive.call(void 0, BarLi
|
|
|
193
193
|
|
|
194
194
|
|
|
195
195
|
exports.BarListChart = BarListChart; exports.BarListChartResponsive = BarListChartResponsive;
|
|
196
|
-
//# sourceMappingURL=chunk-
|
|
196
|
+
//# sourceMappingURL=chunk-EGGRTD4V.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-FVWTBK44.cjs","../src/charts/bar-list-chart/bar-list-chart.tsx"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACXA,iEAAoC;AACpC,oCAAsB;AACtB,oCAAuC;AACvC,kCAAqC;AACrC,8BAAoC;AA0FlC,+CAAA;AARF,IAAM,kBAAA,EAAoB,CAA6B,KAAA,EAAA,GAAmB;AAEzE,EAAA,MAAM,EAAA,EAAI,KAAA;AACV,EAAA,OAAO,EAAA,GAAK,YAAA,GAAe,EAAA,mCAAI,CAAA,2BAAG,SAAA,mBAAU,GAAA,UAAK,IAAA,EAAI,CAAA;AACtD,CAAA;AAEA,IAAM,sBAAA,EAAwB,CAAE,EAAE,SAAA,EAAW,CAAA,EAAG,CAAA,EAAG,KAAA,EAAO,UAAU,CAAA,EAAA,GAAO;AAC1E,EAAA,uBACC,6BAAA,UAAC,EAAA,EAAO,GAAG,SAAA,EAAY,UAAA,EAAW,OAAA,EAAQ,CAAA,EAA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C7B,cAAA,EAAiB,YAAA,CAAa,cAAA;AAAA,gBAC9B,cAAA,EAAiB,YAAA,CAAa,cAAA;AAAA,gBAC9B,cAAA,EAAiB,OAAA,CAAQ,cAAA;AAAA,gBACzB,cAAA,EAAiB,OAAA,CAAQ;AAAA,cAAA;AAAA,YAC1B;AAAA,UAEF,CAAA;AAAA,UACA,CAAA,EAAG;AAAA,YACF,QAAA,EAAU,CAAA,EAAA,GAAM;AAAA,UACjB;AAAA,QACD,CAAA;AAAA,QACA,MAAA,EAAQ,YAAA,CAAa,MAAA;AAAA,QACrB,MAAA,EAAQ,YAAA,CAAa;AAAA,MACtB,CAAA;AAAA,MACE,GAAG;AAAA,IAAA;AAAA,EACN,CAAA;AAEF,CAAA;AAEA,IAAM,aAAA,EAAwC,CAAA,KAAA,EAAA,GAAS;AACtD,EAAA,MAAM,gBAAA,EAAkB,+BAAA,qCAAgC,CAAA;AAGxD,EAAA,GAAA,CAAK,eAAA,EAAkB;AACtB,IAAA,uBAAO,6BAAA,oBAAC,EAAA,EAAuB,GAAG,MAAA,CAAQ,CAAA;AAAA,EAC3C;AAGA,EAAA,uBACC,6BAAA,sCAAC,EAAA,EACA,QAAA,kBAAA,6BAAA,oBAAC,EAAA,EAAuB,GAAG,MAAA,CAAQ,EAAA,CACpC,CAAA;AAEF,CAAA;AAEA,YAAA,CAAa,YAAA,EAAc,cAAA;AAE3B,IAAM,uBAAA,EAAyB,8CAAA,YAAkD,CAAA;AD3HjF;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-FVWTBK44.cjs","sourcesContent":[null,"import { formatNumberCompact } from '@automattic/number-formatters';\nimport { Group } from '@visx/group';\nimport { createScale, scaleBand } from '@visx/scale';\nimport { Text, type TextProps } from '@visx/text';\nimport { useContext, useMemo } from 'react';\nimport { GlobalChartsContext, GlobalChartsProvider } from '../../providers';\nimport { BarChart } from '../bar-chart';\nimport { withResponsive } from '../private/with-responsive';\nimport type { SeriesData } from '../..';\nimport type { ScaleOptions } from '../../types';\nimport type { BarChartProps } from '../bar-chart/bar-chart';\nimport type { AxisRendererProps, AxisScale } from '@visx/axis';\nimport type { AnyD3Scale } from '@visx/scale';\nimport type { ComponentType, FC } from 'react';\n\nexport interface BarListChartProps\n\textends Exclude< BarChartProps, 'orientation' | 'size' | 'gridVisibility' > {\n\toptions?: {\n\t\t/**\n\t\t * Scale for the y axis. Exclude the type property.\n\t\t */\n\t\tyScale: Omit< ScaleOptions, 'type' >;\n\t\t/**\n\t\t * Scale for the x axis. Exclude the type property.\n\t\t */\n\t\txScale: Omit< ScaleOptions, 'type' >;\n\t\t/**\n\t\t * Formatter for the label.\n\t\t */\n\t\tlabelFormatter?: ( value: string ) => string;\n\t\t/**\n\t\t * Formatter for the value.\n\t\t */\n\t\tvalueFormatter?: ( value: number ) => string;\n\t\t/**\n\t\t * y offset of the label and value. Default is based on the number of series, automatically computed.\n\t\t */\n\t\tyOffset?: number;\n\t\t/**\n\t\t * x position of the label.\n\t\t */\n\t\tlabelPosition?: number;\n\t\t/**\n\t\t * x position of the value.\n\t\t */\n\t\tvaluePosition?: number;\n\t\t/**\n\t\t * Custom render function for the label.\n\t\t */\n\t\tlabelComponent?: ComponentType< RenderLabelProps >;\n\t\t/**\n\t\t * Custom render function for the value.\n\t\t */\n\t\tvalueComponent?: ComponentType< RenderValueProps >;\n\t};\n}\n\nexport interface RenderLabelProps {\n\ttextProps: TextProps;\n\tx: number;\n\ty: number;\n\tlabel: string;\n\tformatter: ( value: string ) => string;\n}\n\nexport interface RenderValueProps {\n\ttextProps: TextProps;\n\tx: number;\n\ty: number;\n\tvalue: number;\n\t/**\n\t * Original data\n\t */\n\tdata: SeriesData[];\n\t/**\n\t * Index of the data point\n\t */\n\tindex: number;\n\tformatter: ( value: number ) => string;\n}\n\n/**\n * Get the bandwidth of a scale\n * @param scale - The scale to get the bandwidth of\n * @return The bandwidth of the scale\n */\nconst getScaleBandwidth = < Scale extends AxisScale >( scale?: Scale ) => {\n\t// Broaden type before using 'xxx' in s as typeguard.\n\tconst s = scale as AxisScale;\n\treturn s && 'bandwidth' in s ? s?.bandwidth() ?? 0 : 0;\n};\n\nconst DefaultLabelComponent = ( { textProps, x, y, label, formatter } ) => {\n\treturn (\n\t\t<Text { ...textProps } textAnchor=\"start\" x={ x } y={ y }>\n\t\t\t{ formatter( label ) }\n\t\t</Text>\n\t);\n};\n\nconst DefaultValueComponent = ( { textProps, x, y, value, formatter }: RenderValueProps ) => {\n\treturn (\n\t\t<Text { ...textProps } textAnchor=\"end\" x={ x } y={ y } fontWeight={ 500 }>\n\t\t\t{ formatter( value ) }\n\t\t</Text>\n\t);\n};\n\nconst AxisRenderer = ( {\n\tticks,\n\ttickLabelProps,\n\tyOffset,\n\tlabelPosition,\n\tvaluePosition,\n\tdata,\n\tlabelFormatter,\n\tvalueFormatter,\n\tLabelComponent = DefaultLabelComponent,\n\tValueComponent = DefaultValueComponent,\n}: AxisRendererProps< AnyD3Scale > & {\n\tyOffset: number;\n\tlabelPosition: number;\n\tvaluePosition: number;\n\tdata: SeriesData[];\n\tlabelFormatter?: ( value: string ) => string;\n\tvalueFormatter?: ( value: number ) => string;\n\tLabelComponent?: ComponentType< RenderLabelProps >;\n\tValueComponent?: ComponentType< RenderValueProps >;\n} ) => {\n\tif ( ticks.length === 0 ) {\n\t\treturn null;\n\t}\n\n\t// compute the max tick label size to compute label offset\n\tconst allTickLabelProps = ticks.map( ( { value, index } ) =>\n\t\ttypeof tickLabelProps === 'function' ? tickLabelProps( value, index, ticks ) : {}\n\t);\n\n\treturn ticks.map( ( { from, formattedValue }, index ) => {\n\t\tconst textProps = allTickLabelProps[ index ] ?? {};\n\t\t// No need to pass textAnchor and dx. It will be handled by the component.\n\t\tdelete textProps.textAnchor;\n\t\tdelete textProps.dx;\n\n\t\tconst sum = data.reduce(\n\t\t\t( acc, { data: seriesData } ) => acc + ( seriesData[ index ]?.value ?? 0 ),\n\t\t\t0\n\t\t);\n\t\tconst y = from.y + yOffset;\n\n\t\treturn (\n\t\t\t<Group key={ index }>\n\t\t\t\t<LabelComponent\n\t\t\t\t\ttextProps={ textProps }\n\t\t\t\t\tx={ labelPosition }\n\t\t\t\t\ty={ y }\n\t\t\t\t\tlabel={ formattedValue }\n\t\t\t\t\tformatter={ labelFormatter }\n\t\t\t\t/>\n\t\t\t\t<ValueComponent\n\t\t\t\t\ttextProps={ textProps }\n\t\t\t\t\tx={ valuePosition }\n\t\t\t\t\ty={ y }\n\t\t\t\t\tvalue={ sum }\n\t\t\t\t\tformatter={ valueFormatter }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tindex={ index }\n\t\t\t\t/>\n\t\t\t</Group>\n\t\t);\n\t} );\n};\n\n/**\n * Calculate the default y offset for the bar list chart.\n * @param data - The data to calculate the default y offset for.\n * @param yScaleConfig - The y scale configuration.\n * @param height - The height of the chart.\n * @param isMultiSeries - Whether the chart is a multi series chart.\n * @return The default y offset.\n */\nconst getDefaultYOffset = (\n\tdata: SeriesData[],\n\tyScaleConfig: Omit< ScaleOptions, 'type' >,\n\theight: number,\n\tisMultiSeries: boolean\n) => {\n\tif ( ! isMultiSeries ) {\n\t\treturn 0;\n\t}\n\n\tconst dataKeys = data.map( ( { label } ) => label );\n\n\tconst yScale = createScale< string >( {\n\t\ttype: 'band' as const,\n\t\trange: [ 0, height ],\n\t\tdomain: dataKeys,\n\t\t...yScaleConfig,\n\t} );\n\n\tconst groupScale = scaleBand< string >( {\n\t\tdomain: dataKeys,\n\t\trange: [ 0, getScaleBandwidth( yScale ) ],\n\t\tpadding: yScaleConfig.paddingInner,\n\t} );\n\n\tconst GAP_BETWEEN_BARS = 6;\n\tconst barThickness = getScaleBandwidth( groupScale );\n\n\t// Use negative value to move the label up.\n\treturn -( barThickness + GAP_BETWEEN_BARS );\n};\n\nconst BarListChartInternal: FC< BarListChartProps > = ( {\n\tdata,\n\twidth,\n\theight,\n\toptions = {},\n\tmargin = {\n\t\tleft: 0,\n\t\tright: 20,\n\t\tbottom: 0,\n\t\ttop: 0,\n\t},\n\t...rest\n} ) => {\n\tconst chartOptions = useMemo( () => {\n\t\tconst isMultiSeries = data.length > 1;\n\n\t\tconst defaultYScale = {\n\t\t\t// For multi series, set default padding larger to look better.\n\t\t\tpaddingInner: isMultiSeries ? 0.3 : 0.1,\n\t\t\tpadding: isMultiSeries ? 0.3 : 0.1,\n\t\t};\n\t\tconst defaultXScale = {\n\t\t\t// Always begin at zero since the x axis is hidden.\n\t\t\tzero: true,\n\t\t};\n\t\tconst yScale = {\n\t\t\t...defaultYScale,\n\t\t\t...( options.yScale ?? {} ),\n\t\t};\n\t\tconst xScale = {\n\t\t\t...defaultXScale,\n\t\t\t...( options.xScale ?? {} ),\n\t\t};\n\n\t\treturn {\n\t\t\tyScale,\n\t\t\txScale,\n\t\t\tlabelPosition: options.labelPosition ?? ( isMultiSeries ? 0 : 10 ),\n\t\t\tvalueFormatter: options.valueFormatter ?? ( value => formatNumberCompact( value ) ),\n\t\t\tlabelFormatter: options.labelFormatter ?? ( value => String( value ) ),\n\t\t\tvaluePosition: options.valuePosition ?? width,\n\t\t\tyOffset: options.yOffset ?? getDefaultYOffset( data, yScale, height, isMultiSeries ),\n\t\t};\n\t}, [ options, width, data, height ] );\n\n\treturn (\n\t\t<BarChart\n\t\t\torientation=\"horizontal\"\n\t\t\tgridVisibility={ 'none' }\n\t\t\tdata={ data }\n\t\t\twidth={ width }\n\t\t\theight={ height }\n\t\t\tmargin={ margin }\n\t\t\toptions={ {\n\t\t\t\taxis: {\n\t\t\t\t\ty: {\n\t\t\t\t\t\tchildren: ( renderProps: AxisRendererProps< AnyD3Scale > ) => (\n\t\t\t\t\t\t\t<AxisRenderer\n\t\t\t\t\t\t\t\t{ ...renderProps }\n\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\tyOffset={ chartOptions.yOffset }\n\t\t\t\t\t\t\t\tlabelPosition={ chartOptions.labelPosition }\n\t\t\t\t\t\t\t\tvaluePosition={ chartOptions.valuePosition }\n\t\t\t\t\t\t\t\tlabelFormatter={ chartOptions.labelFormatter }\n\t\t\t\t\t\t\t\tvalueFormatter={ chartOptions.valueFormatter }\n\t\t\t\t\t\t\t\tLabelComponent={ options.labelComponent }\n\t\t\t\t\t\t\t\tValueComponent={ options.valueComponent }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\tx: {\n\t\t\t\t\t\tchildren: () => null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\txScale: chartOptions.xScale,\n\t\t\t\tyScale: chartOptions.yScale,\n\t\t\t} }\n\t\t\t{ ...rest }\n\t\t/>\n\t);\n};\n\nconst BarListChart: FC< BarListChartProps > = props => {\n\tconst existingContext = useContext( GlobalChartsContext );\n\n\t// If we're already in a GlobalChartsProvider context, render the core component directly\n\tif ( existingContext ) {\n\t\treturn <BarListChartInternal { ...props } />;\n\t}\n\n\t// Otherwise, wrap with our own GlobalChartsProvider\n\treturn (\n\t\t<GlobalChartsProvider>\n\t\t\t<BarListChartInternal { ...props } />\n\t\t</GlobalChartsProvider>\n\t);\n};\n\nBarListChart.displayName = 'BarListChart';\n\nconst BarListChartResponsive = withResponsive< BarListChartProps >( BarListChart );\n\nexport { BarListChartResponsive as default, BarListChart as BarListChartUnresponsive };\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-EGGRTD4V.cjs","../src/charts/bar-list-chart/bar-list-chart.tsx"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACXA,iEAAoC;AACpC,oCAAsB;AACtB,oCAAuC;AACvC,kCAAqC;AACrC,8BAAoC;AA0FlC,+CAAA;AARF,IAAM,kBAAA,EAAoB,CAA6B,KAAA,EAAA,GAAmB;AAEzE,EAAA,MAAM,EAAA,EAAI,KAAA;AAC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;AD3HjF;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-EGGRTD4V.cjs","sourcesContent":[null,"import { formatNumberCompact } from '@automattic/number-formatters';\nimport { Group } from '@visx/group';\nimport { createScale, scaleBand } from '@visx/scale';\nimport { Text, type TextProps } from '@visx/text';\nimport { useContext, useMemo } from 'react';\nimport { GlobalChartsContext, GlobalChartsProvider } from '../../providers';\nimport { BarChart } from '../bar-chart';\nimport { withResponsive } from '../private/with-responsive';\nimport type { SeriesData } from '../..';\nimport type { ScaleOptions } from '../../types';\nimport type { BarChartProps } from '../bar-chart/bar-chart';\nimport type { AxisRendererProps, AxisScale } from '@visx/axis';\nimport type { AnyD3Scale } from '@visx/scale';\nimport type { ComponentType, FC } from 'react';\n\nexport interface BarListChartProps\n\textends Exclude< BarChartProps, 'orientation' | 'size' | 'gridVisibility' > {\n\toptions?: {\n\t\t/**\n\t\t * Scale for the y axis. Exclude the type property.\n\t\t */\n\t\tyScale: Omit< ScaleOptions, 'type' >;\n\t\t/**\n\t\t * Scale for the x axis. Exclude the type property.\n\t\t */\n\t\txScale: Omit< ScaleOptions, 'type' >;\n\t\t/**\n\t\t * Formatter for the label.\n\t\t */\n\t\tlabelFormatter?: ( value: string ) => string;\n\t\t/**\n\t\t * Formatter for the value.\n\t\t */\n\t\tvalueFormatter?: ( value: number ) => string;\n\t\t/**\n\t\t * y offset of the label and value. Default is based on the number of series, automatically computed.\n\t\t */\n\t\tyOffset?: number;\n\t\t/**\n\t\t * x position of the label.\n\t\t */\n\t\tlabelPosition?: number;\n\t\t/**\n\t\t * x position of the value.\n\t\t */\n\t\tvaluePosition?: number;\n\t\t/**\n\t\t * Custom render function for the label.\n\t\t */\n\t\tlabelComponent?: ComponentType< RenderLabelProps >;\n\t\t/**\n\t\t * Custom render function for the value.\n\t\t */\n\t\tvalueComponent?: ComponentType< RenderValueProps >;\n\t};\n}\n\nexport interface RenderLabelProps {\n\ttextProps: TextProps;\n\tx: number;\n\ty: number;\n\tlabel: string;\n\tformatter: ( value: string ) => string;\n}\n\nexport interface RenderValueProps {\n\ttextProps: TextProps;\n\tx: number;\n\ty: number;\n\tvalue: number;\n\t/**\n\t * Original data\n\t */\n\tdata: SeriesData[];\n\t/**\n\t * Index of the data point\n\t */\n\tindex: number;\n\tformatter: ( value: number ) => string;\n}\n\n/**\n * Get the bandwidth of a scale\n * @param scale - The scale to get the bandwidth of\n * @return The bandwidth of the scale\n */\nconst getScaleBandwidth = < Scale extends AxisScale >( scale?: Scale ) => {\n\t// Broaden type before using 'xxx' in s as typeguard.\n\tconst s = scale as AxisScale;\n\treturn s && 'bandwidth' in s ? s?.bandwidth() ?? 0 : 0;\n};\n\nconst DefaultLabelComponent = ( { textProps, x, y, label, formatter } ) => {\n\treturn (\n\t\t<Text { ...textProps } textAnchor=\"start\" x={ x } y={ y }>\n\t\t\t{ formatter( label ) }\n\t\t</Text>\n\t);\n};\n\nconst DefaultValueComponent = ( { textProps, x, y, value, formatter }: RenderValueProps ) => {\n\treturn (\n\t\t<Text { ...textProps } textAnchor=\"end\" x={ x } y={ y } fontWeight={ 500 }>\n\t\t\t{ formatter( value ) }\n\t\t</Text>\n\t);\n};\n\nconst AxisRenderer = ( {\n\tticks,\n\ttickLabelProps,\n\tyOffset,\n\tlabelPosition,\n\tvaluePosition,\n\tdata,\n\tlabelFormatter,\n\tvalueFormatter,\n\tLabelComponent = DefaultLabelComponent,\n\tValueComponent = DefaultValueComponent,\n}: AxisRendererProps< AnyD3Scale > & {\n\tyOffset: number;\n\tlabelPosition: number;\n\tvaluePosition: number;\n\tdata: SeriesData[];\n\tlabelFormatter?: ( value: string ) => string;\n\tvalueFormatter?: ( value: number ) => string;\n\tLabelComponent?: ComponentType< RenderLabelProps >;\n\tValueComponent?: ComponentType< RenderValueProps >;\n} ) => {\n\tif ( ticks.length === 0 ) {\n\t\treturn null;\n\t}\n\n\t// compute the max tick label size to compute label offset\n\tconst allTickLabelProps = ticks.map( ( { value, index } ) =>\n\t\ttypeof tickLabelProps === 'function' ? tickLabelProps( value, index, ticks ) : {}\n\t);\n\n\treturn ticks.map( ( { from, formattedValue }, index ) => {\n\t\tconst textProps = allTickLabelProps[ index ] ?? {};\n\t\t// No need to pass textAnchor and dx. It will be handled by the component.\n\t\tdelete textProps.textAnchor;\n\t\tdelete textProps.dx;\n\n\t\tconst sum = data.reduce(\n\t\t\t( acc, { data: seriesData } ) => acc + ( seriesData[ index ]?.value ?? 0 ),\n\t\t\t0\n\t\t);\n\t\tconst y = from.y + yOffset;\n\n\t\treturn (\n\t\t\t<Group key={ index }>\n\t\t\t\t<LabelComponent\n\t\t\t\t\ttextProps={ textProps }\n\t\t\t\t\tx={ labelPosition }\n\t\t\t\t\ty={ y }\n\t\t\t\t\tlabel={ formattedValue }\n\t\t\t\t\tformatter={ labelFormatter }\n\t\t\t\t/>\n\t\t\t\t<ValueComponent\n\t\t\t\t\ttextProps={ textProps }\n\t\t\t\t\tx={ valuePosition }\n\t\t\t\t\ty={ y }\n\t\t\t\t\tvalue={ sum }\n\t\t\t\t\tformatter={ valueFormatter }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tindex={ index }\n\t\t\t\t/>\n\t\t\t</Group>\n\t\t);\n\t} );\n};\n\n/**\n * Calculate the default y offset for the bar list chart.\n * @param data - The data to calculate the default y offset for.\n * @param yScaleConfig - The y scale configuration.\n * @param height - The height of the chart.\n * @param isMultiSeries - Whether the chart is a multi series chart.\n * @return The default y offset.\n */\nconst getDefaultYOffset = (\n\tdata: SeriesData[],\n\tyScaleConfig: Omit< ScaleOptions, 'type' >,\n\theight: number,\n\tisMultiSeries: boolean\n) => {\n\tif ( ! isMultiSeries ) {\n\t\treturn 0;\n\t}\n\n\tconst dataKeys = data.map( ( { label } ) => label );\n\n\tconst yScale = createScale< string >( {\n\t\ttype: 'band' as const,\n\t\trange: [ 0, height ],\n\t\tdomain: dataKeys,\n\t\t...yScaleConfig,\n\t} );\n\n\tconst groupScale = scaleBand< string >( {\n\t\tdomain: dataKeys,\n\t\trange: [ 0, getScaleBandwidth( yScale ) ],\n\t\tpadding: yScaleConfig.paddingInner,\n\t} );\n\n\tconst GAP_BETWEEN_BARS = 6;\n\tconst barThickness = getScaleBandwidth( groupScale );\n\n\t// Use negative value to move the label up.\n\treturn -( barThickness + GAP_BETWEEN_BARS );\n};\n\nconst BarListChartInternal: FC< BarListChartProps > = ( {\n\tdata,\n\twidth,\n\theight,\n\toptions = {},\n\tmargin = {\n\t\tleft: 0,\n\t\tright: 20,\n\t\tbottom: 0,\n\t\ttop: 0,\n\t},\n\t...rest\n} ) => {\n\tconst chartOptions = useMemo( () => {\n\t\tconst isMultiSeries = data.length > 1;\n\n\t\tconst defaultYScale = {\n\t\t\t// For multi series, set default padding larger to look better.\n\t\t\tpaddingInner: isMultiSeries ? 0.3 : 0.1,\n\t\t\tpadding: isMultiSeries ? 0.3 : 0.1,\n\t\t};\n\t\tconst defaultXScale = {\n\t\t\t// Always begin at zero since the x axis is hidden.\n\t\t\tzero: true,\n\t\t};\n\t\tconst yScale = {\n\t\t\t...defaultYScale,\n\t\t\t...( options.yScale ?? {} ),\n\t\t};\n\t\tconst xScale = {\n\t\t\t...defaultXScale,\n\t\t\t...( options.xScale ?? {} ),\n\t\t};\n\n\t\treturn {\n\t\t\tyScale,\n\t\t\txScale,\n\t\t\tlabelPosition: options.labelPosition ?? ( isMultiSeries ? 0 : 10 ),\n\t\t\tvalueFormatter: options.valueFormatter ?? ( value => formatNumberCompact( value ) ),\n\t\t\tlabelFormatter: options.labelFormatter ?? ( value => String( value ) ),\n\t\t\tvaluePosition: options.valuePosition ?? width,\n\t\t\tyOffset: options.yOffset ?? getDefaultYOffset( data, yScale, height, isMultiSeries ),\n\t\t};\n\t}, [ options, width, data, height ] );\n\n\treturn (\n\t\t<BarChart\n\t\t\torientation=\"horizontal\"\n\t\t\tgridVisibility={ 'none' }\n\t\t\tdata={ data }\n\t\t\twidth={ width }\n\t\t\theight={ height }\n\t\t\tmargin={ margin }\n\t\t\toptions={ {\n\t\t\t\taxis: {\n\t\t\t\t\ty: {\n\t\t\t\t\t\tchildren: ( renderProps: AxisRendererProps< AnyD3Scale > ) => (\n\t\t\t\t\t\t\t<AxisRenderer\n\t\t\t\t\t\t\t\t{ ...renderProps }\n\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\tyOffset={ chartOptions.yOffset }\n\t\t\t\t\t\t\t\tlabelPosition={ chartOptions.labelPosition }\n\t\t\t\t\t\t\t\tvaluePosition={ chartOptions.valuePosition }\n\t\t\t\t\t\t\t\tlabelFormatter={ chartOptions.labelFormatter }\n\t\t\t\t\t\t\t\tvalueFormatter={ chartOptions.valueFormatter }\n\t\t\t\t\t\t\t\tLabelComponent={ options.labelComponent }\n\t\t\t\t\t\t\t\tValueComponent={ options.valueComponent }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\tx: {\n\t\t\t\t\t\tchildren: () => null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\txScale: chartOptions.xScale,\n\t\t\t\tyScale: chartOptions.yScale,\n\t\t\t} }\n\t\t\t{ ...rest }\n\t\t/>\n\t);\n};\n\nconst BarListChart: FC< BarListChartProps > = props => {\n\tconst existingContext = useContext( GlobalChartsContext );\n\n\t// If we're already in a GlobalChartsProvider context, render the core component directly\n\tif ( existingContext ) {\n\t\treturn <BarListChartInternal { ...props } />;\n\t}\n\n\t// Otherwise, wrap with our own GlobalChartsProvider\n\treturn (\n\t\t<GlobalChartsProvider>\n\t\t\t<BarListChartInternal { ...props } />\n\t\t</GlobalChartsProvider>\n\t);\n};\n\nBarListChart.displayName = 'BarListChart';\n\nconst BarListChartResponsive = withResponsive< BarListChartProps >( BarListChart );\n\nexport { BarListChartResponsive as default, BarListChart as BarListChartUnresponsive };\n"]}
|