@automattic/charts 0.56.3 → 0.56.5
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 +14 -0
- package/dist/charts/bar-chart/index.cjs +5 -5
- package/dist/charts/bar-chart/index.css +12 -0
- package/dist/charts/bar-chart/index.css.map +1 -1
- package/dist/charts/bar-chart/index.js +4 -4
- package/dist/charts/bar-list-chart/index.cjs +6 -6
- package/dist/charts/bar-list-chart/index.css +12 -0
- package/dist/charts/bar-list-chart/index.css.map +1 -1
- package/dist/charts/bar-list-chart/index.js +5 -5
- package/dist/charts/conversion-funnel-chart/index.cjs +5 -3
- package/dist/charts/conversion-funnel-chart/index.cjs.map +1 -1
- package/dist/charts/conversion-funnel-chart/index.css +14 -1
- package/dist/charts/conversion-funnel-chart/index.css.map +1 -1
- package/dist/charts/conversion-funnel-chart/index.d.cts +2 -0
- package/dist/charts/conversion-funnel-chart/index.d.ts +2 -0
- package/dist/charts/conversion-funnel-chart/index.js +4 -2
- package/dist/charts/geo-chart/index.cjs +4 -4
- package/dist/charts/geo-chart/index.css +12 -0
- package/dist/charts/geo-chart/index.css.map +1 -1
- package/dist/charts/geo-chart/index.js +3 -3
- package/dist/charts/leaderboard-chart/index.cjs +5 -5
- package/dist/charts/leaderboard-chart/index.css +12 -0
- package/dist/charts/leaderboard-chart/index.css.map +1 -1
- package/dist/charts/leaderboard-chart/index.js +4 -4
- package/dist/charts/line-chart/index.cjs +5 -5
- package/dist/charts/line-chart/index.css +12 -0
- package/dist/charts/line-chart/index.css.map +1 -1
- package/dist/charts/line-chart/index.js +4 -4
- package/dist/charts/pie-chart/index.cjs +7 -7
- package/dist/charts/pie-chart/index.css +12 -0
- package/dist/charts/pie-chart/index.css.map +1 -1
- package/dist/charts/pie-chart/index.js +6 -6
- package/dist/charts/pie-semi-circle-chart/index.cjs +7 -7
- package/dist/charts/pie-semi-circle-chart/index.css +12 -0
- package/dist/charts/pie-semi-circle-chart/index.css.map +1 -1
- package/dist/charts/pie-semi-circle-chart/index.js +6 -6
- package/dist/charts/sparkline/index.cjs +6 -6
- package/dist/charts/sparkline/index.css +12 -0
- package/dist/charts/sparkline/index.css.map +1 -1
- package/dist/charts/sparkline/index.js +5 -5
- package/dist/{chunk-OTZT3MC2.cjs → chunk-2A34OA5O.cjs} +19 -20
- package/dist/chunk-2A34OA5O.cjs.map +1 -0
- package/dist/{chunk-H34CJSR6.js → chunk-32ESS4MV.js} +406 -363
- package/dist/chunk-32ESS4MV.js.map +1 -0
- package/dist/{chunk-CEZGL6YP.js → chunk-6CCZL2JJ.js} +15 -7
- package/dist/chunk-6CCZL2JJ.js.map +1 -0
- package/dist/{chunk-NW3RUYK2.cjs → chunk-7QDEU3KN.cjs} +15 -22
- package/dist/chunk-7QDEU3KN.cjs.map +1 -0
- package/dist/chunk-7TQSPLIN.js +351 -0
- package/dist/chunk-7TQSPLIN.js.map +1 -0
- package/dist/{chunk-T4J6TI55.js → chunk-AFWQR3SM.js} +102 -79
- package/dist/chunk-AFWQR3SM.js.map +1 -0
- package/dist/{chunk-5XI443YP.js → chunk-BPYKWMI7.js} +72 -64
- package/dist/chunk-BPYKWMI7.js.map +1 -0
- package/dist/{chunk-TNRKEBTA.js → chunk-DBY6C4O2.js} +148 -164
- package/dist/{chunk-TNRKEBTA.js.map → chunk-DBY6C4O2.js.map} +1 -1
- package/dist/chunk-DLSUC7RN.js +1065 -0
- package/dist/chunk-DLSUC7RN.js.map +1 -0
- package/dist/{chunk-TVV7ZI7C.cjs → chunk-EJJO2QNB.cjs} +399 -356
- package/dist/chunk-EJJO2QNB.cjs.map +1 -0
- package/dist/{chunk-ODF5O5PV.cjs → chunk-FIFSYVN6.cjs} +154 -170
- package/dist/chunk-FIFSYVN6.cjs.map +1 -0
- package/dist/chunk-FY325WQ4.cjs +1065 -0
- package/dist/chunk-FY325WQ4.cjs.map +1 -0
- package/dist/{chunk-SRXJLAKG.cjs → chunk-I2276W3I.cjs} +28 -37
- package/dist/chunk-I2276W3I.cjs.map +1 -0
- package/dist/{chunk-7UJPVCMB.cjs → chunk-IHESL7H5.cjs} +265 -262
- package/dist/chunk-IHESL7H5.cjs.map +1 -0
- package/dist/chunk-JL4ZKKZU.cjs +375 -0
- package/dist/chunk-JL4ZKKZU.cjs.map +1 -0
- package/dist/chunk-KHRPRH4V.js +165 -0
- package/dist/chunk-KHRPRH4V.js.map +1 -0
- package/dist/{chunk-A3AEEGKR.js → chunk-KXRWNFQJ.js} +20 -21
- package/dist/chunk-KXRWNFQJ.js.map +1 -0
- package/dist/{chunk-2VPPTJS2.js → chunk-KXSLMOW5.js} +256 -253
- package/dist/chunk-KXSLMOW5.js.map +1 -0
- package/dist/chunk-LT4YOIMM.js +375 -0
- package/dist/chunk-LT4YOIMM.js.map +1 -0
- package/dist/chunk-LTPJPIDP.cjs +165 -0
- package/dist/chunk-LTPJPIDP.cjs.map +1 -0
- package/dist/chunk-NGHXTIUE.cjs +120 -0
- package/dist/chunk-NGHXTIUE.cjs.map +1 -0
- package/dist/chunk-PCOI2GT5.js +120 -0
- package/dist/chunk-PCOI2GT5.js.map +1 -0
- package/dist/{chunk-YYQ4IK5V.cjs → chunk-Q6G3BGCL.cjs} +103 -80
- package/dist/chunk-Q6G3BGCL.cjs.map +1 -0
- package/dist/{chunk-HIWNB5PK.cjs → chunk-RCY6XLGU.cjs} +13 -5
- package/dist/chunk-RCY6XLGU.cjs.map +1 -0
- package/dist/chunk-TKPK4RFS.cjs +351 -0
- package/dist/chunk-TKPK4RFS.cjs.map +1 -0
- package/dist/{chunk-C33AQZEC.js → chunk-TYIH5LMV.js} +16 -23
- package/dist/chunk-TYIH5LMV.js.map +1 -0
- package/dist/chunk-X6GX4QUJ.js +421 -0
- package/dist/chunk-X6GX4QUJ.js.map +1 -0
- package/dist/chunk-XCXAWMJQ.cjs +421 -0
- package/dist/chunk-XCXAWMJQ.cjs.map +1 -0
- package/dist/chunk-XWYZIFZW.js +66 -0
- package/dist/chunk-XWYZIFZW.js.map +1 -0
- package/dist/{chunk-7HROSZRS.cjs → chunk-Y3NNQMAX.cjs} +70 -62
- package/dist/chunk-Y3NNQMAX.cjs.map +1 -0
- package/dist/components/legend/index.cjs +2 -2
- package/dist/components/legend/index.css +12 -0
- package/dist/components/legend/index.css.map +1 -1
- package/dist/components/legend/index.js +1 -1
- package/dist/components/tooltip/index.cjs +2 -2
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/trend-indicator/index.cjs +2 -2
- package/dist/components/trend-indicator/index.js +1 -1
- package/dist/hooks/index.cjs +4 -2
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.css +12 -0
- package/dist/hooks/index.css.map +1 -1
- package/dist/hooks/index.d.cts +28 -2
- package/dist/hooks/index.d.ts +28 -2
- package/dist/hooks/index.js +3 -1
- package/dist/index.cjs +18 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +14 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -17
- package/dist/providers/index.cjs +2 -2
- package/dist/providers/index.css +12 -0
- package/dist/providers/index.css.map +1 -1
- package/dist/providers/index.d.cts +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/{themes-DQs9rbN5.d.cts → themes-BDVaIfBz.d.cts} +9 -0
- package/dist/{themes-CRV5fVzJ.d.ts → themes-mcS8QNkQ.d.ts} +9 -0
- package/package.json +6 -2
- package/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +2 -1
- package/src/charts/conversion-funnel-chart/conversion-funnel-chart.tsx +16 -6
- package/src/charts/conversion-funnel-chart/test/conversion-funnel-chart.test.tsx +34 -0
- package/src/charts/conversion-funnel-chart/types.ts +2 -0
- package/src/charts/pie-chart/pie-chart.tsx +2 -3
- package/src/hooks/index.ts +1 -0
- package/src/hooks/test/use-chart-margin.test.tsx +44 -0
- package/src/hooks/test/use-tooltip-portal-relocator.test.ts +216 -0
- package/src/hooks/use-chart-margin.tsx +92 -6
- package/src/hooks/use-tooltip-portal-relocator.module.scss +10 -0
- package/src/hooks/use-tooltip-portal-relocator.ts +177 -0
- package/src/providers/chart-context/global-charts-provider.tsx +18 -1
- package/tsup.config.ts +11 -0
- package/dist/chunk-2VPPTJS2.js.map +0 -1
- package/dist/chunk-5XI443YP.js.map +0 -1
- package/dist/chunk-7HROSZRS.cjs.map +0 -1
- package/dist/chunk-7UJPVCMB.cjs.map +0 -1
- package/dist/chunk-A3AEEGKR.js.map +0 -1
- package/dist/chunk-C33AQZEC.js.map +0 -1
- package/dist/chunk-CEZGL6YP.js.map +0 -1
- package/dist/chunk-COOC2TVQ.js +0 -167
- package/dist/chunk-COOC2TVQ.js.map +0 -1
- package/dist/chunk-EJHLLXBV.js +0 -362
- package/dist/chunk-EJHLLXBV.js.map +0 -1
- package/dist/chunk-FWMJ2FR2.js +0 -121
- package/dist/chunk-FWMJ2FR2.js.map +0 -1
- package/dist/chunk-GRYNIPWH.cjs +0 -385
- package/dist/chunk-GRYNIPWH.cjs.map +0 -1
- package/dist/chunk-H34CJSR6.js.map +0 -1
- package/dist/chunk-HIWNB5PK.cjs.map +0 -1
- package/dist/chunk-IZWC33YN.cjs +0 -357
- package/dist/chunk-IZWC33YN.cjs.map +0 -1
- package/dist/chunk-KOF32DBL.cjs +0 -1058
- package/dist/chunk-KOF32DBL.cjs.map +0 -1
- package/dist/chunk-LHWRZMF7.cjs +0 -362
- package/dist/chunk-LHWRZMF7.cjs.map +0 -1
- package/dist/chunk-MFRS2PEY.cjs +0 -121
- package/dist/chunk-MFRS2PEY.cjs.map +0 -1
- package/dist/chunk-MMDLXS6O.js +0 -75
- package/dist/chunk-MMDLXS6O.js.map +0 -1
- package/dist/chunk-NW3RUYK2.cjs.map +0 -1
- package/dist/chunk-ODF5O5PV.cjs.map +0 -1
- package/dist/chunk-OTZT3MC2.cjs.map +0 -1
- package/dist/chunk-SBRMWDWM.js +0 -357
- package/dist/chunk-SBRMWDWM.js.map +0 -1
- package/dist/chunk-SRXJLAKG.cjs.map +0 -1
- package/dist/chunk-T4J6TI55.js.map +0 -1
- package/dist/chunk-TVV7ZI7C.cjs.map +0 -1
- package/dist/chunk-XVMXWV3C.cjs +0 -167
- package/dist/chunk-XVMXWV3C.cjs.map +0 -1
- package/dist/chunk-YYQ4IK5V.cjs.map +0 -1
- package/dist/chunk-ZDNCF642.js +0 -1058
- package/dist/chunk-ZDNCF642.js.map +0 -1
- package/dist/chunk-ZWBUEHKF.js +0 -385
- package/dist/chunk-ZWBUEHKF.js.map +0 -1
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import {
|
|
2
|
+
radial_wipe_animation_default
|
|
3
|
+
} from "./chunk-KXRWNFQJ.js";
|
|
4
|
+
import {
|
|
5
|
+
ChartHTML,
|
|
6
|
+
ChartSVG,
|
|
7
|
+
useChartChildren
|
|
8
|
+
} from "./chunk-6CCZL2JJ.js";
|
|
9
|
+
import {
|
|
10
|
+
BaseTooltip
|
|
11
|
+
} from "./chunk-BPYKWMI7.js";
|
|
12
|
+
import {
|
|
13
|
+
withResponsive
|
|
14
|
+
} from "./chunk-TYIH5LMV.js";
|
|
15
|
+
import {
|
|
16
|
+
GlobalChartsContext,
|
|
17
|
+
GlobalChartsProvider,
|
|
18
|
+
Legend,
|
|
19
|
+
SingleChartContext,
|
|
20
|
+
useChartId,
|
|
21
|
+
useChartLegendItems,
|
|
22
|
+
useChartRegistration,
|
|
23
|
+
useElementHeight,
|
|
24
|
+
useGlobalChartsContext,
|
|
25
|
+
useInteractiveLegendData,
|
|
26
|
+
usePrefersReducedMotion
|
|
27
|
+
} from "./chunk-32ESS4MV.js";
|
|
28
|
+
import {
|
|
29
|
+
attachSubComponents
|
|
30
|
+
} from "./chunk-TE63Y5PX.js";
|
|
31
|
+
|
|
32
|
+
// src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx
|
|
33
|
+
import { Group } from "@visx/group";
|
|
34
|
+
import { Pie } from "@visx/shape";
|
|
35
|
+
import { Text } from "@visx/text";
|
|
36
|
+
import { useTooltip, useTooltipInPortal } from "@visx/tooltip";
|
|
37
|
+
import { __ } from "@wordpress/i18n";
|
|
38
|
+
import clsx from "clsx";
|
|
39
|
+
import { useCallback, useContext, useMemo } from "react";
|
|
40
|
+
|
|
41
|
+
// src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss
|
|
42
|
+
var pie_semi_circle_chart_module_default = {
|
|
43
|
+
"pie-semi-circle-chart": "a8ccharts-8tyaQj",
|
|
44
|
+
"pie-semi-circle-chart--legend-top": "a8ccharts-M1lF7A",
|
|
45
|
+
"label": "a8ccharts-EKZS3j",
|
|
46
|
+
"note": "a8ccharts-v85A8-"
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx
|
|
50
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
51
|
+
var renderDefaultPieSemiCircleTooltip = ({
|
|
52
|
+
tooltipData
|
|
53
|
+
}) => {
|
|
54
|
+
return /* @__PURE__ */ _jsx(BaseTooltip, {
|
|
55
|
+
data: tooltipData,
|
|
56
|
+
top: 0,
|
|
57
|
+
left: 0,
|
|
58
|
+
renderContainer: false
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
var PAD_ANGLE = 0.03;
|
|
62
|
+
var validateData = (data) => {
|
|
63
|
+
if (!data.length) {
|
|
64
|
+
return {
|
|
65
|
+
isValid: false,
|
|
66
|
+
message: "No data available"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const hasNegativeValues = data.some((item) => item.percentage < 0 || item.value < 0);
|
|
70
|
+
if (hasNegativeValues) {
|
|
71
|
+
return {
|
|
72
|
+
isValid: false,
|
|
73
|
+
message: "Invalid data: Negative values are not allowed"
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const totalPercentage = data.reduce((sum, item) => sum + item.percentage, 0);
|
|
77
|
+
if (totalPercentage <= 0) {
|
|
78
|
+
return {
|
|
79
|
+
isValid: false,
|
|
80
|
+
message: "Invalid percentage total: Must be greater than 0"
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
isValid: true,
|
|
85
|
+
message: ""
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var PieSemiCircleChartInternal = ({
|
|
89
|
+
data,
|
|
90
|
+
chartId: providedChartId,
|
|
91
|
+
width = 400,
|
|
92
|
+
thickness = 0.4,
|
|
93
|
+
clockwise = true,
|
|
94
|
+
withTooltips = false,
|
|
95
|
+
showLegend = false,
|
|
96
|
+
legendOrientation = "horizontal",
|
|
97
|
+
legendPosition = "bottom",
|
|
98
|
+
legendAlignment = "center",
|
|
99
|
+
legendMaxWidth,
|
|
100
|
+
legendTextOverflow = "wrap",
|
|
101
|
+
legendItemClassName,
|
|
102
|
+
legendShape = "circle",
|
|
103
|
+
legendValueDisplay = "percentage",
|
|
104
|
+
legendInteractive = false,
|
|
105
|
+
label,
|
|
106
|
+
animation,
|
|
107
|
+
note,
|
|
108
|
+
className,
|
|
109
|
+
children,
|
|
110
|
+
tooltipOffsetX = 0,
|
|
111
|
+
tooltipOffsetY = -15,
|
|
112
|
+
renderTooltip = renderDefaultPieSemiCircleTooltip
|
|
113
|
+
}) => {
|
|
114
|
+
const chartId = useChartId(providedChartId);
|
|
115
|
+
const [legendRef, legendHeight] = useElementHeight();
|
|
116
|
+
const {
|
|
117
|
+
tooltipOpen,
|
|
118
|
+
tooltipLeft,
|
|
119
|
+
tooltipTop,
|
|
120
|
+
tooltipData,
|
|
121
|
+
hideTooltip,
|
|
122
|
+
showTooltip
|
|
123
|
+
} = useTooltip();
|
|
124
|
+
const {
|
|
125
|
+
containerRef,
|
|
126
|
+
TooltipInPortal,
|
|
127
|
+
containerBounds
|
|
128
|
+
} = useTooltipInPortal({
|
|
129
|
+
detectBounds: true,
|
|
130
|
+
scroll: true,
|
|
131
|
+
debounce: 0
|
|
132
|
+
});
|
|
133
|
+
const handleMouseMove = useCallback((event, arc) => {
|
|
134
|
+
if (containerBounds.width === 0 || containerBounds.height === 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
showTooltip({
|
|
138
|
+
tooltipData: arc.data,
|
|
139
|
+
tooltipLeft: event.clientX - containerBounds.left + tooltipOffsetX,
|
|
140
|
+
tooltipTop: event.clientY - containerBounds.top + tooltipOffsetY
|
|
141
|
+
});
|
|
142
|
+
}, [containerBounds.width, containerBounds.height, containerBounds.left, containerBounds.top, showTooltip, tooltipOffsetX, tooltipOffsetY]);
|
|
143
|
+
const handleMouseLeave = useCallback(() => {
|
|
144
|
+
hideTooltip();
|
|
145
|
+
}, [hideTooltip]);
|
|
146
|
+
const handleArcMouseMove = useCallback((arc) => (event) => {
|
|
147
|
+
handleMouseMove(event, arc);
|
|
148
|
+
}, [handleMouseMove]);
|
|
149
|
+
const {
|
|
150
|
+
isValid,
|
|
151
|
+
message
|
|
152
|
+
} = validateData(data);
|
|
153
|
+
const {
|
|
154
|
+
getElementStyles,
|
|
155
|
+
isSeriesVisible
|
|
156
|
+
} = useGlobalChartsContext();
|
|
157
|
+
const {
|
|
158
|
+
visibleData,
|
|
159
|
+
allSegmentsHidden,
|
|
160
|
+
legendData
|
|
161
|
+
} = useInteractiveLegendData({
|
|
162
|
+
data,
|
|
163
|
+
chartId,
|
|
164
|
+
legendInteractive,
|
|
165
|
+
isSeriesVisible
|
|
166
|
+
});
|
|
167
|
+
const accessors = useMemo(() => ({
|
|
168
|
+
value: (d) => d.value,
|
|
169
|
+
sort: (a, b) => b.value - a.value,
|
|
170
|
+
fill: (d) => getElementStyles({
|
|
171
|
+
data: d,
|
|
172
|
+
index: d.index
|
|
173
|
+
}).color
|
|
174
|
+
}), [getElementStyles]);
|
|
175
|
+
const legendOptions = useMemo(() => ({
|
|
176
|
+
showValues: true,
|
|
177
|
+
legendValueDisplay
|
|
178
|
+
}), [legendValueDisplay]);
|
|
179
|
+
const legendItems = useChartLegendItems(legendData, legendOptions);
|
|
180
|
+
const {
|
|
181
|
+
svgChildren,
|
|
182
|
+
htmlChildren,
|
|
183
|
+
otherChildren
|
|
184
|
+
} = useChartChildren(children, "PieSemiCircleChart");
|
|
185
|
+
const chartMetadata = useMemo(() => ({
|
|
186
|
+
thickness,
|
|
187
|
+
clockwise
|
|
188
|
+
}), [thickness, clockwise]);
|
|
189
|
+
useChartRegistration({
|
|
190
|
+
chartId,
|
|
191
|
+
legendItems,
|
|
192
|
+
chartType: "pie-semi-circle",
|
|
193
|
+
isDataValid: isValid,
|
|
194
|
+
metadata: chartMetadata
|
|
195
|
+
});
|
|
196
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
197
|
+
if (!isValid) {
|
|
198
|
+
return /* @__PURE__ */ _jsx("div", {
|
|
199
|
+
className: pie_semi_circle_chart_module_default["pie-semi-circle-chart"],
|
|
200
|
+
children: /* @__PURE__ */ _jsx("svg", {
|
|
201
|
+
width,
|
|
202
|
+
height: width / 2,
|
|
203
|
+
children: /* @__PURE__ */ _jsx("text", {
|
|
204
|
+
x: "50%",
|
|
205
|
+
y: "50%",
|
|
206
|
+
textAnchor: "middle",
|
|
207
|
+
className: pie_semi_circle_chart_module_default.error,
|
|
208
|
+
children: message
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const height = width / 2;
|
|
214
|
+
const chartHeight = height - (showLegend && legendPosition === "top" ? legendHeight : 0);
|
|
215
|
+
const radius = Math.min(width / 2, chartHeight);
|
|
216
|
+
const innerRadius = radius * (1 - thickness);
|
|
217
|
+
const dataWithIndex = visibleData.map((d) => {
|
|
218
|
+
const originalIndex = data.findIndex((item) => item.label === d.label);
|
|
219
|
+
return {
|
|
220
|
+
...d,
|
|
221
|
+
index: originalIndex >= 0 ? originalIndex : 0
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
const startAngle = clockwise ? -Math.PI / 2 : Math.PI / 2;
|
|
225
|
+
const endAngle = clockwise ? Math.PI / 2 : -Math.PI / 2;
|
|
226
|
+
return /* @__PURE__ */ _jsx(SingleChartContext.Provider, {
|
|
227
|
+
value: {
|
|
228
|
+
chartId,
|
|
229
|
+
chartWidth: width,
|
|
230
|
+
chartHeight: radius
|
|
231
|
+
},
|
|
232
|
+
children: /* @__PURE__ */ _jsxs("div", {
|
|
233
|
+
ref: containerRef,
|
|
234
|
+
className: clsx("pie-semi-circle-chart", pie_semi_circle_chart_module_default["pie-semi-circle-chart"], {
|
|
235
|
+
[pie_semi_circle_chart_module_default["pie-semi-circle-chart--legend-top"]]: showLegend && legendPosition === "top"
|
|
236
|
+
}, className),
|
|
237
|
+
children: [/* @__PURE__ */ _jsxs("svg", {
|
|
238
|
+
width,
|
|
239
|
+
height: radius,
|
|
240
|
+
viewBox: `0 0 ${width} ${chartHeight}`,
|
|
241
|
+
children: [/* @__PURE__ */ _jsx("defs", {
|
|
242
|
+
children: /* @__PURE__ */ _jsx(radial_wipe_animation_default, {
|
|
243
|
+
id: `radial-wipe-${chartId}`,
|
|
244
|
+
radius,
|
|
245
|
+
innerRadius,
|
|
246
|
+
startAngle: "-180deg",
|
|
247
|
+
wipePercentage: 50
|
|
248
|
+
})
|
|
249
|
+
}), /* @__PURE__ */ _jsx(Group, {
|
|
250
|
+
top: chartHeight,
|
|
251
|
+
left: width / 2,
|
|
252
|
+
mask: animation && !prefersReducedMotion ? `url(#radial-wipe-${chartId})` : null,
|
|
253
|
+
children: allSegmentsHidden ? /* @__PURE__ */ _jsx("text", {
|
|
254
|
+
textAnchor: "middle",
|
|
255
|
+
y: -radius / 2,
|
|
256
|
+
fill: "#ccc",
|
|
257
|
+
fontSize: "14",
|
|
258
|
+
fontFamily: "-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif",
|
|
259
|
+
children: __("All segments are hidden. Click legend items to show data.", "jetpack-charts")
|
|
260
|
+
}) : /* @__PURE__ */ _jsxs(_Fragment, {
|
|
261
|
+
children: [/* @__PURE__ */ _jsx(Pie, {
|
|
262
|
+
data: dataWithIndex,
|
|
263
|
+
pieValue: accessors.value,
|
|
264
|
+
outerRadius: radius,
|
|
265
|
+
innerRadius,
|
|
266
|
+
cornerRadius: 3,
|
|
267
|
+
padAngle: PAD_ANGLE,
|
|
268
|
+
startAngle,
|
|
269
|
+
endAngle,
|
|
270
|
+
pieSort: accessors.sort,
|
|
271
|
+
children: (pie) => {
|
|
272
|
+
return pie.arcs.map((arc) => /* @__PURE__ */ _jsx("g", {
|
|
273
|
+
onMouseMove: withTooltips ? handleArcMouseMove(arc) : void 0,
|
|
274
|
+
onMouseLeave: withTooltips ? handleMouseLeave : void 0,
|
|
275
|
+
children: /* @__PURE__ */ _jsx("path", {
|
|
276
|
+
d: pie.path(arc) || "",
|
|
277
|
+
fill: accessors.fill(arc.data)
|
|
278
|
+
})
|
|
279
|
+
}, arc.data.label));
|
|
280
|
+
}
|
|
281
|
+
}), /* @__PURE__ */ _jsxs(Group, {
|
|
282
|
+
children: [/* @__PURE__ */ _jsx(Text, {
|
|
283
|
+
textAnchor: "middle",
|
|
284
|
+
verticalAnchor: "start",
|
|
285
|
+
y: -40,
|
|
286
|
+
className: pie_semi_circle_chart_module_default.label,
|
|
287
|
+
children: label
|
|
288
|
+
}), /* @__PURE__ */ _jsx(Text, {
|
|
289
|
+
textAnchor: "middle",
|
|
290
|
+
verticalAnchor: "start",
|
|
291
|
+
y: -20,
|
|
292
|
+
className: pie_semi_circle_chart_module_default.note,
|
|
293
|
+
children: note
|
|
294
|
+
})]
|
|
295
|
+
}), !allSegmentsHidden && svgChildren]
|
|
296
|
+
})
|
|
297
|
+
})]
|
|
298
|
+
}), withTooltips && tooltipOpen && tooltipData && /* @__PURE__ */ _jsx(TooltipInPortal, {
|
|
299
|
+
top: tooltipTop || 0,
|
|
300
|
+
left: tooltipLeft || 0,
|
|
301
|
+
children: /* @__PURE__ */ _jsx("div", {
|
|
302
|
+
role: "tooltip",
|
|
303
|
+
children: renderTooltip({
|
|
304
|
+
tooltipData
|
|
305
|
+
})
|
|
306
|
+
})
|
|
307
|
+
}), showLegend && /* @__PURE__ */ _jsx(Legend, {
|
|
308
|
+
orientation: legendOrientation,
|
|
309
|
+
position: legendPosition,
|
|
310
|
+
alignment: legendAlignment,
|
|
311
|
+
maxWidth: legendMaxWidth,
|
|
312
|
+
textOverflow: legendTextOverflow,
|
|
313
|
+
legendItemClassName,
|
|
314
|
+
shape: legendShape,
|
|
315
|
+
ref: legendRef,
|
|
316
|
+
chartId,
|
|
317
|
+
interactive: legendInteractive
|
|
318
|
+
}), htmlChildren, otherChildren]
|
|
319
|
+
})
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
var PieSemiCircleChartWithProvider = (props) => {
|
|
323
|
+
const existingContext = useContext(GlobalChartsContext);
|
|
324
|
+
if (existingContext) {
|
|
325
|
+
return /* @__PURE__ */ _jsx(PieSemiCircleChartInternal, {
|
|
326
|
+
...props
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
return /* @__PURE__ */ _jsx(GlobalChartsProvider, {
|
|
330
|
+
children: /* @__PURE__ */ _jsx(PieSemiCircleChartInternal, {
|
|
331
|
+
...props
|
|
332
|
+
})
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
PieSemiCircleChartWithProvider.displayName = "PieSemiCircleChart";
|
|
336
|
+
var PieSemiCircleChart = attachSubComponents(PieSemiCircleChartWithProvider, {
|
|
337
|
+
Legend,
|
|
338
|
+
SVG: ChartSVG,
|
|
339
|
+
HTML: ChartHTML
|
|
340
|
+
});
|
|
341
|
+
var PieSemiCircleChartResponsive = attachSubComponents(withResponsive(PieSemiCircleChartWithProvider), {
|
|
342
|
+
Legend,
|
|
343
|
+
SVG: ChartSVG,
|
|
344
|
+
HTML: ChartHTML
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
export {
|
|
348
|
+
PieSemiCircleChart,
|
|
349
|
+
PieSemiCircleChartResponsive
|
|
350
|
+
};
|
|
351
|
+
//# sourceMappingURL=chunk-7TQSPLIN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx","../src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss"],"sourcesContent":["import { Group } from '@visx/group';\nimport { Pie } from '@visx/shape';\nimport { Text } from '@visx/text';\nimport { useTooltip, useTooltipInPortal } from '@visx/tooltip';\nimport { __ } from '@wordpress/i18n';\nimport clsx from 'clsx';\nimport { useCallback, useContext, useMemo } from 'react';\nimport { Legend, useChartLegendItems } from '../../components/legend';\nimport { BaseTooltip } from '../../components/tooltip';\nimport { useElementHeight, useInteractiveLegendData, usePrefersReducedMotion } from '../../hooks';\nimport { GlobalChartsProvider, useChartId, useChartRegistration, useGlobalChartsContext, GlobalChartsContext } from '../../providers';\nimport { attachSubComponents } from '../../utils';\nimport { ChartSVG, ChartHTML, useChartChildren } from '../private/chart-composition';\nimport { RadialWipeAnimation } from '../private/radial-wipe-animation';\nimport { SingleChartContext } from '../private/single-chart-context';\nimport { withResponsive } from '../private/with-responsive';\nimport styles from './pie-semi-circle-chart.module.scss';\n\n/**\n * Parameters passed to the renderTooltip function for semi-circle charts.\n */\nimport { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\n/**\n * Default tooltip renderer for semi-circle pie charts.\n * Renders a BaseTooltip with the hovered segment's data.\n *\n * @param {PieSemiCircleChartRenderTooltipParams} params - The tooltip parameters containing the hovered data point\n * @return {ReactNode} The rendered tooltip content\n */\nconst renderDefaultPieSemiCircleTooltip = ({\n tooltipData\n}) => {\n return /*#__PURE__*/_jsx(BaseTooltip, {\n data: tooltipData,\n top: 0,\n left: 0,\n renderContainer: false\n });\n};\nconst PAD_ANGLE = 0.03; // Padding between segments\n\n// Base props type with optional responsive properties\n\n// Composition API types\n\n/**\n * Validates the semi-circle pie chart data\n * @param data - The data to validate\n * @return Object containing validation result and error message\n */\nconst validateData = data => {\n if (!data.length) {\n return {\n isValid: false,\n message: 'No data available'\n };\n }\n\n // Check for negative values\n const hasNegativeValues = data.some(item => item.percentage < 0 || item.value < 0);\n if (hasNegativeValues) {\n return {\n isValid: false,\n message: 'Invalid data: Negative values are not allowed'\n };\n }\n\n // Validate total percentage is greater than 0\n const totalPercentage = data.reduce((sum, item) => sum + item.percentage, 0);\n if (totalPercentage <= 0) {\n return {\n isValid: false,\n message: 'Invalid percentage total: Must be greater than 0'\n };\n }\n return {\n isValid: true,\n message: ''\n };\n};\nconst PieSemiCircleChartInternal = ({\n data,\n chartId: providedChartId,\n width = 400,\n thickness = 0.4,\n clockwise = true,\n withTooltips = false,\n showLegend = false,\n legendOrientation = 'horizontal',\n legendPosition = 'bottom',\n legendAlignment = 'center',\n legendMaxWidth,\n legendTextOverflow = 'wrap',\n legendItemClassName,\n legendShape = 'circle',\n legendValueDisplay = 'percentage',\n legendInteractive = false,\n label,\n animation,\n note,\n className,\n children,\n tooltipOffsetX = 0,\n tooltipOffsetY = -15,\n renderTooltip = renderDefaultPieSemiCircleTooltip\n}) => {\n const chartId = useChartId(providedChartId);\n const [legendRef, legendHeight] = useElementHeight();\n const {\n tooltipOpen,\n tooltipLeft,\n tooltipTop,\n tooltipData,\n hideTooltip,\n showTooltip\n } = useTooltip();\n\n // Set up portal tooltip for better z-index handling\n // We get containerBounds to cancel out stale offsets in the position calculation\n const {\n containerRef,\n TooltipInPortal,\n containerBounds\n } = useTooltipInPortal({\n detectBounds: true,\n scroll: true,\n debounce: 0\n });\n const handleMouseMove = useCallback((event, arc) => {\n // Don't show tooltip until container bounds are measured\n if (containerBounds.width === 0 || containerBounds.height === 0) {\n return;\n }\n\n // Use clientX/Y and subtract containerBounds to cancel out any stale offset.\n // TooltipInPortal calculates: tooltipLeft + containerBounds.left + scrollX\n // By passing (clientX - containerBounds.left), we get:\n // (clientX - containerBounds.left) + containerBounds.left + scrollX = clientX + scrollX\n // This gives correct page coordinates regardless of stale bounds.\n showTooltip({\n tooltipData: arc.data,\n tooltipLeft: event.clientX - containerBounds.left + tooltipOffsetX,\n tooltipTop: event.clientY - containerBounds.top + tooltipOffsetY\n });\n }, [containerBounds.width, containerBounds.height, containerBounds.left, containerBounds.top, showTooltip, tooltipOffsetX, tooltipOffsetY]);\n const handleMouseLeave = useCallback(() => {\n hideTooltip();\n }, [hideTooltip]);\n const handleArcMouseMove = useCallback(arc => event => {\n handleMouseMove(event, arc);\n }, [handleMouseMove]);\n\n // Validate data first to get validation result\n const {\n isValid,\n message\n } = validateData(data);\n const {\n getElementStyles,\n isSeriesVisible\n } = useGlobalChartsContext();\n\n // Filter and recalculate data for interactive legends\n const {\n visibleData,\n allSegmentsHidden,\n legendData\n } = useInteractiveLegendData({\n data,\n chartId,\n legendInteractive,\n isSeriesVisible\n });\n\n // Define accessors with useMemo to avoid changing dependencies\n const accessors = useMemo(() => ({\n value: d => d.value,\n sort: (a, b) => b.value - a.value,\n fill: d => getElementStyles({\n data: d,\n index: d.index\n }).color\n }), [getElementStyles]);\n\n // Memoize legend options to prevent unnecessary re-calculations\n const legendOptions = useMemo(() => ({\n showValues: true,\n legendValueDisplay\n }), [legendValueDisplay]);\n\n // Create legend items using legendData (has recalculated percentages for visible items)\n const legendItems = useChartLegendItems(legendData, legendOptions);\n\n // Process children to extract compound components\n const {\n svgChildren,\n htmlChildren,\n otherChildren\n } = useChartChildren(children, 'PieSemiCircleChart');\n\n // Memoize metadata to prevent unnecessary re-registration\n const chartMetadata = useMemo(() => ({\n thickness,\n clockwise\n }), [thickness, clockwise]);\n\n // Register chart with context only if data is valid\n useChartRegistration({\n chartId,\n legendItems,\n chartType: 'pie-semi-circle',\n isDataValid: isValid,\n metadata: chartMetadata\n });\n const prefersReducedMotion = usePrefersReducedMotion();\n if (!isValid) {\n return /*#__PURE__*/_jsx(\"div\", {\n className: styles['pie-semi-circle-chart'],\n children: /*#__PURE__*/_jsx(\"svg\", {\n width: width,\n height: width / 2,\n children: /*#__PURE__*/_jsx(\"text\", {\n x: \"50%\",\n y: \"50%\",\n textAnchor: \"middle\",\n className: styles.error,\n children: message\n })\n })\n });\n }\n\n // Calculate chart dimensions\n // TODO: we might want to accept height as a prop in the future, because the height of container might not always be enough.\n const height = width / 2;\n // The chart only takes the height minus the legend height.\n const chartHeight = height - (showLegend && legendPosition === 'top' ? legendHeight : 0);\n const radius = Math.min(width / 2, chartHeight);\n const innerRadius = radius * (1 - thickness);\n\n // Map data with index for color assignment\n // When interactive, we need to find the original index to maintain consistent colors\n const dataWithIndex = visibleData.map(d => {\n const originalIndex = data.findIndex(item => item.label === d.label);\n return {\n ...d,\n index: originalIndex >= 0 ? originalIndex : 0\n };\n });\n\n // Configure pie angles based on clockwise direction\n const startAngle = clockwise ? -Math.PI / 2 : Math.PI / 2;\n const endAngle = clockwise ? Math.PI / 2 : -Math.PI / 2;\n return /*#__PURE__*/_jsx(SingleChartContext.Provider, {\n value: {\n chartId,\n chartWidth: width,\n chartHeight: radius\n },\n children: /*#__PURE__*/_jsxs(\"div\", {\n ref: containerRef,\n className: clsx('pie-semi-circle-chart', styles['pie-semi-circle-chart'], {\n [styles['pie-semi-circle-chart--legend-top']]: showLegend && legendPosition === 'top'\n }, className),\n children: [/*#__PURE__*/_jsxs(\"svg\", {\n width: width,\n height: radius,\n viewBox: `0 0 ${width} ${chartHeight}`,\n children: [/*#__PURE__*/_jsx(\"defs\", {\n children: /*#__PURE__*/_jsx(RadialWipeAnimation, {\n id: `radial-wipe-${chartId}`,\n radius: radius,\n innerRadius: innerRadius,\n startAngle: \"-180deg\",\n wipePercentage: 50\n })\n }), /*#__PURE__*/_jsx(Group, {\n top: chartHeight,\n left: width / 2,\n mask: animation && !prefersReducedMotion ? `url(#radial-wipe-${chartId})` : null,\n children: allSegmentsHidden ? /*#__PURE__*/_jsx(\"text\", {\n textAnchor: \"middle\",\n y: -radius / 2,\n fill: \"#ccc\",\n fontSize: \"14\",\n fontFamily: \"-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif\",\n children: __('All segments are hidden. Click legend items to show data.', 'jetpack-charts')\n }) : /*#__PURE__*/_jsxs(_Fragment, {\n children: [/*#__PURE__*/_jsx(Pie, {\n data: dataWithIndex,\n pieValue: accessors.value,\n outerRadius: radius,\n innerRadius: innerRadius,\n cornerRadius: 3,\n padAngle: PAD_ANGLE,\n startAngle: startAngle,\n endAngle: endAngle,\n pieSort: accessors.sort,\n children: pie => {\n return pie.arcs.map(arc => /*#__PURE__*/_jsx(\"g\", {\n onMouseMove: withTooltips ? handleArcMouseMove(arc) : undefined,\n onMouseLeave: withTooltips ? handleMouseLeave : undefined,\n children: /*#__PURE__*/_jsx(\"path\", {\n d: pie.path(arc) || '',\n fill: accessors.fill(arc.data)\n })\n }, arc.data.label));\n }\n }), /*#__PURE__*/_jsxs(Group, {\n children: [/*#__PURE__*/_jsx(Text, {\n textAnchor: \"middle\",\n verticalAnchor: \"start\",\n y: -40 // Position above the chart with space for note\n ,\n className: styles.label,\n children: label\n }), /*#__PURE__*/_jsx(Text, {\n textAnchor: \"middle\",\n verticalAnchor: \"start\",\n y: -20 // Position between label and chart\n ,\n className: styles.note,\n children: note\n })]\n }), !allSegmentsHidden && svgChildren]\n })\n })]\n }), withTooltips && tooltipOpen && tooltipData && /*#__PURE__*/_jsx(TooltipInPortal, {\n top: tooltipTop || 0,\n left: tooltipLeft || 0,\n children: /*#__PURE__*/_jsx(\"div\", {\n role: \"tooltip\",\n children: renderTooltip({\n tooltipData\n })\n })\n }), showLegend && /*#__PURE__*/_jsx(Legend, {\n orientation: legendOrientation,\n position: legendPosition,\n alignment: legendAlignment,\n maxWidth: legendMaxWidth,\n textOverflow: legendTextOverflow,\n legendItemClassName: legendItemClassName,\n shape: legendShape,\n ref: legendRef,\n chartId: chartId,\n interactive: legendInteractive\n }), htmlChildren, otherChildren]\n })\n });\n};\nconst PieSemiCircleChartWithProvider = props => {\n const existingContext = useContext(GlobalChartsContext);\n\n // If we're already in a GlobalChartsProvider context, don't create a new one\n if (existingContext) {\n return /*#__PURE__*/_jsx(PieSemiCircleChartInternal, {\n ...props\n });\n }\n\n // Otherwise, create our own GlobalChartsProvider\n return /*#__PURE__*/_jsx(GlobalChartsProvider, {\n children: /*#__PURE__*/_jsx(PieSemiCircleChartInternal, {\n ...props\n })\n });\n};\nPieSemiCircleChartWithProvider.displayName = 'PieSemiCircleChart';\n\n// Create PieSemiCircleChart with composition API\nconst PieSemiCircleChart = attachSubComponents(PieSemiCircleChartWithProvider, {\n Legend: Legend,\n SVG: ChartSVG,\n HTML: ChartHTML\n});\n\n// Create responsive PieSemiCircleChart with composition API\nconst PieSemiCircleChartResponsive = attachSubComponents(withResponsive(PieSemiCircleChartWithProvider), {\n Legend: Legend,\n SVG: ChartSVG,\n HTML: ChartHTML\n});\nexport { PieSemiCircleChartResponsive as default, PieSemiCircleChart as PieSemiCircleChartUnresponsive };","import 'css-chunk:src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss';export default {\n \"pie-semi-circle-chart\": \"a8ccharts-8tyaQj\",\n \"pie-semi-circle-chart--legend-top\": \"a8ccharts-M1lF7A\",\n \"label\": \"a8ccharts-EKZS3j\",\n \"note\": \"a8ccharts-v85A8-\"\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,WAAW;AACpB,SAAS,YAAY;AACrB,SAAS,YAAY,0BAA0B;AAC/C,SAAS,UAAU;AACnB,OAAO,UAAU;AACjB,SAAS,aAAa,YAAY,eAAe;;;ACNqC,IAAO,uCAAQ;AAAA,EACnG,yBAAyB;AAAA,EACzB,qCAAqC;AAAA,EACrC,SAAS;AAAA,EACT,QAAQ;AACV;;;ADgBA,SAAS,OAAO,MAAM,QAAQ,OAAO,YAAY,iBAAiB;AAQlE,IAAM,oCAAoC,CAAC;AAAA,EACzC;AACF,MAAM;AACJ,SAAoB,qBAAK,aAAa;AAAA,IACpC,MAAM;AA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AAS;AAC9C,QAAM,kBAAkB,WAAW,mBAAmB;AAGtD,MAAI,iBAAiB;AACnB,WAAoB,qBAAK,4BAA4B;AAAA,MACnD,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAGA,SAAoB,qBAAK,sBAAsB;AAAA,IAC7C,UAAuB,qBAAK,4BAA4B;AAAA,MACtD,GAAG;AAAA,IACL,CAAC;AAAA,EACH,CAAC;AACH;AACA,+BAA+B,cAAc;AAG7C,IAAM,qBAAqB,oBAAoB,gCAAgC;AAAA,EAC7E;AAAA,EACA,KAAK;AAAA,EACL,MAAM;AACR,CAAC;AAGD,IAAM,+BAA+B,oBAAoB,eAAe,8BAA8B,GAAG;AAAA,EACvG;AAAA,EACA,KAAK;AAAA,EACL,MAAM;AACR,CAAC;","names":[]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BarChart
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KXSLMOW5.js";
|
|
4
4
|
import {
|
|
5
5
|
withResponsive
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TYIH5LMV.js";
|
|
7
7
|
import {
|
|
8
8
|
GlobalChartsContext,
|
|
9
9
|
GlobalChartsProvider
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-32ESS4MV.js";
|
|
11
11
|
|
|
12
12
|
// src/charts/bar-list-chart/bar-list-chart.tsx
|
|
13
13
|
import { formatNumberCompact } from "@automattic/number-formatters";
|
|
@@ -15,16 +15,41 @@ import { Group } from "@visx/group";
|
|
|
15
15
|
import { createScale, scaleBand } from "@visx/scale";
|
|
16
16
|
import { Text } from "@visx/text";
|
|
17
17
|
import { useContext, useMemo } from "react";
|
|
18
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
19
|
var getScaleBandwidth = (scale) => {
|
|
20
20
|
const s = scale;
|
|
21
21
|
return s && "bandwidth" in s ? s?.bandwidth() ?? 0 : 0;
|
|
22
22
|
};
|
|
23
|
-
var DefaultLabelComponent = ({
|
|
24
|
-
|
|
23
|
+
var DefaultLabelComponent = ({
|
|
24
|
+
textProps,
|
|
25
|
+
x,
|
|
26
|
+
y,
|
|
27
|
+
label,
|
|
28
|
+
formatter
|
|
29
|
+
}) => {
|
|
30
|
+
return /* @__PURE__ */ _jsx(Text, {
|
|
31
|
+
...textProps,
|
|
32
|
+
textAnchor: "start",
|
|
33
|
+
x,
|
|
34
|
+
y,
|
|
35
|
+
children: formatter(label)
|
|
36
|
+
});
|
|
25
37
|
};
|
|
26
|
-
var DefaultValueComponent = ({
|
|
27
|
-
|
|
38
|
+
var DefaultValueComponent = ({
|
|
39
|
+
textProps,
|
|
40
|
+
x,
|
|
41
|
+
y,
|
|
42
|
+
value,
|
|
43
|
+
formatter
|
|
44
|
+
}) => {
|
|
45
|
+
return /* @__PURE__ */ _jsx(Text, {
|
|
46
|
+
...textProps,
|
|
47
|
+
textAnchor: "end",
|
|
48
|
+
x,
|
|
49
|
+
y,
|
|
50
|
+
fontWeight: 500,
|
|
51
|
+
children: formatter(value)
|
|
52
|
+
});
|
|
28
53
|
};
|
|
29
54
|
var AxisRenderer = ({
|
|
30
55
|
ticks,
|
|
@@ -41,49 +66,47 @@ var AxisRenderer = ({
|
|
|
41
66
|
if (ticks.length === 0) {
|
|
42
67
|
return null;
|
|
43
68
|
}
|
|
44
|
-
const allTickLabelProps = ticks.map(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
69
|
+
const allTickLabelProps = ticks.map(({
|
|
70
|
+
value,
|
|
71
|
+
index
|
|
72
|
+
}) => typeof tickLabelProps === "function" ? tickLabelProps(value, index, ticks) : {});
|
|
73
|
+
return ticks.map(({
|
|
74
|
+
from,
|
|
75
|
+
formattedValue
|
|
76
|
+
}, index) => {
|
|
48
77
|
const textProps = allTickLabelProps[index] ?? {};
|
|
49
78
|
delete textProps.textAnchor;
|
|
50
79
|
delete textProps.dx;
|
|
51
|
-
const sum = data.reduce(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
80
|
+
const sum = data.reduce((acc, {
|
|
81
|
+
data: seriesData
|
|
82
|
+
}) => acc + (seriesData[index]?.value ?? 0), 0);
|
|
55
83
|
const y = from.y + yOffset;
|
|
56
|
-
return /* @__PURE__ */
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
value: sum,
|
|
74
|
-
formatter: valueFormatter,
|
|
75
|
-
data,
|
|
76
|
-
index
|
|
77
|
-
}
|
|
78
|
-
)
|
|
79
|
-
] }, index);
|
|
84
|
+
return /* @__PURE__ */ _jsxs(Group, {
|
|
85
|
+
children: [/* @__PURE__ */ _jsx(LabelComponent, {
|
|
86
|
+
textProps,
|
|
87
|
+
x: labelPosition,
|
|
88
|
+
y,
|
|
89
|
+
label: formattedValue,
|
|
90
|
+
formatter: labelFormatter
|
|
91
|
+
}), /* @__PURE__ */ _jsx(ValueComponent, {
|
|
92
|
+
textProps,
|
|
93
|
+
x: valuePosition,
|
|
94
|
+
y,
|
|
95
|
+
value: sum,
|
|
96
|
+
formatter: valueFormatter,
|
|
97
|
+
data,
|
|
98
|
+
index
|
|
99
|
+
})]
|
|
100
|
+
}, index);
|
|
80
101
|
});
|
|
81
102
|
};
|
|
82
103
|
var getDefaultYOffset = (data, yScaleConfig, height, isMultiSeries) => {
|
|
83
104
|
if (!isMultiSeries) {
|
|
84
105
|
return 0;
|
|
85
106
|
}
|
|
86
|
-
const dataKeys = data.map(({
|
|
107
|
+
const dataKeys = data.map(({
|
|
108
|
+
label
|
|
109
|
+
}) => label);
|
|
87
110
|
const yScale = createScale({
|
|
88
111
|
type: "band",
|
|
89
112
|
range: [0, height],
|
|
@@ -141,50 +164,50 @@ var BarListChartInternal = ({
|
|
|
141
164
|
yOffset: options.yOffset ?? getDefaultYOffset(data, yScale, height, isMultiSeries)
|
|
142
165
|
};
|
|
143
166
|
}, [options, width, data, height]);
|
|
144
|
-
return /* @__PURE__ */
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
valueFormatter: chartOptions.valueFormatter,
|
|
166
|
-
LabelComponent: options.labelComponent,
|
|
167
|
-
ValueComponent: options.valueComponent
|
|
168
|
-
}
|
|
169
|
-
)
|
|
170
|
-
},
|
|
171
|
-
x: {
|
|
172
|
-
children: () => null
|
|
173
|
-
}
|
|
167
|
+
return /* @__PURE__ */ _jsx(BarChart, {
|
|
168
|
+
orientation: "horizontal",
|
|
169
|
+
gridVisibility: "none",
|
|
170
|
+
data,
|
|
171
|
+
width,
|
|
172
|
+
height,
|
|
173
|
+
margin,
|
|
174
|
+
options: {
|
|
175
|
+
axis: {
|
|
176
|
+
y: {
|
|
177
|
+
children: (renderProps) => /* @__PURE__ */ _jsx(AxisRenderer, {
|
|
178
|
+
...renderProps,
|
|
179
|
+
data,
|
|
180
|
+
yOffset: chartOptions.yOffset,
|
|
181
|
+
labelPosition: chartOptions.labelPosition,
|
|
182
|
+
valuePosition: chartOptions.valuePosition,
|
|
183
|
+
labelFormatter: chartOptions.labelFormatter,
|
|
184
|
+
valueFormatter: chartOptions.valueFormatter,
|
|
185
|
+
LabelComponent: options.labelComponent,
|
|
186
|
+
ValueComponent: options.valueComponent
|
|
187
|
+
})
|
|
174
188
|
},
|
|
175
|
-
|
|
176
|
-
|
|
189
|
+
x: {
|
|
190
|
+
children: () => null
|
|
191
|
+
}
|
|
177
192
|
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
193
|
+
xScale: chartOptions.xScale,
|
|
194
|
+
yScale: chartOptions.yScale
|
|
195
|
+
},
|
|
196
|
+
...rest
|
|
197
|
+
});
|
|
181
198
|
};
|
|
182
199
|
var BarListChart = (props) => {
|
|
183
200
|
const existingContext = useContext(GlobalChartsContext);
|
|
184
201
|
if (existingContext) {
|
|
185
|
-
return /* @__PURE__ */
|
|
202
|
+
return /* @__PURE__ */ _jsx(BarListChartInternal, {
|
|
203
|
+
...props
|
|
204
|
+
});
|
|
186
205
|
}
|
|
187
|
-
return /* @__PURE__ */
|
|
206
|
+
return /* @__PURE__ */ _jsx(GlobalChartsProvider, {
|
|
207
|
+
children: /* @__PURE__ */ _jsx(BarListChartInternal, {
|
|
208
|
+
...props
|
|
209
|
+
})
|
|
210
|
+
});
|
|
188
211
|
};
|
|
189
212
|
BarListChart.displayName = "BarListChart";
|
|
190
213
|
var BarListChartResponsive = withResponsive(BarListChart);
|
|
@@ -193,4 +216,4 @@ export {
|
|
|
193
216
|
BarListChart,
|
|
194
217
|
BarListChartResponsive
|
|
195
218
|
};
|
|
196
|
-
//# sourceMappingURL=chunk-
|
|
219
|
+
//# sourceMappingURL=chunk-AFWQR3SM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/charts/bar-list-chart/bar-list-chart.tsx"],"sourcesContent":["import { formatNumberCompact } from '@automattic/number-formatters';\nimport { Group } from '@visx/group';\nimport { createScale, scaleBand } from '@visx/scale';\nimport { Text } from '@visx/text';\nimport { useContext, useMemo } from 'react';\nimport { GlobalChartsContext, GlobalChartsProvider } from '../../providers';\nimport { BarChartUnresponsive } from '../bar-chart';\nimport { withResponsive } from '../private/with-responsive';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\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 => {\n // Broaden type before using 'xxx' in s as typeguard.\n const s = scale;\n return s && 'bandwidth' in s ? s?.bandwidth() ?? 0 : 0;\n};\nconst DefaultLabelComponent = ({\n textProps,\n x,\n y,\n label,\n formatter\n}) => {\n return /*#__PURE__*/_jsx(Text, {\n ...textProps,\n textAnchor: \"start\",\n x: x,\n y: y,\n children: formatter(label)\n });\n};\nconst DefaultValueComponent = ({\n textProps,\n x,\n y,\n value,\n formatter\n}) => {\n return /*#__PURE__*/_jsx(Text, {\n ...textProps,\n textAnchor: \"end\",\n x: x,\n y: y,\n fontWeight: 500,\n children: formatter(value)\n });\n};\nconst AxisRenderer = ({\n ticks,\n tickLabelProps,\n yOffset,\n labelPosition,\n valuePosition,\n data,\n labelFormatter,\n valueFormatter,\n LabelComponent = DefaultLabelComponent,\n ValueComponent = DefaultValueComponent\n}) => {\n if (ticks.length === 0) {\n return null;\n }\n\n // compute the max tick label size to compute label offset\n const allTickLabelProps = ticks.map(({\n value,\n index\n }) => typeof tickLabelProps === 'function' ? tickLabelProps(value, index, ticks) : {});\n return ticks.map(({\n from,\n formattedValue\n }, index) => {\n const textProps = allTickLabelProps[index] ?? {};\n // No need to pass textAnchor and dx. It will be handled by the component.\n delete textProps.textAnchor;\n delete textProps.dx;\n const sum = data.reduce((acc, {\n data: seriesData\n }) => acc + (seriesData[index]?.value ?? 0), 0);\n const y = from.y + yOffset;\n return /*#__PURE__*/_jsxs(Group, {\n children: [/*#__PURE__*/_jsx(LabelComponent, {\n textProps: textProps,\n x: labelPosition,\n y: y,\n label: formattedValue,\n formatter: labelFormatter\n }), /*#__PURE__*/_jsx(ValueComponent, {\n textProps: textProps,\n x: valuePosition,\n y: y,\n value: sum,\n formatter: valueFormatter,\n data: data,\n index: index\n })]\n }, index);\n });\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 = (data, yScaleConfig, height, isMultiSeries) => {\n if (!isMultiSeries) {\n return 0;\n }\n const dataKeys = data.map(({\n label\n }) => label);\n const yScale = createScale({\n type: 'band',\n range: [0, height],\n domain: dataKeys,\n ...yScaleConfig\n });\n const groupScale = scaleBand({\n domain: dataKeys,\n range: [0, getScaleBandwidth(yScale)],\n padding: yScaleConfig.paddingInner\n });\n const GAP_BETWEEN_BARS = 6;\n const barThickness = getScaleBandwidth(groupScale);\n\n // Use negative value to move the label up.\n return -(barThickness + GAP_BETWEEN_BARS);\n};\nconst BarListChartInternal = ({\n data,\n width,\n height,\n options = {},\n margin = {\n left: 0,\n right: 20,\n bottom: 0,\n top: 0\n },\n ...rest\n}) => {\n const chartOptions = useMemo(() => {\n const isMultiSeries = data.length > 1;\n const defaultYScale = {\n // For multi series, set default padding larger to look better.\n paddingInner: isMultiSeries ? 0.3 : 0.1,\n padding: isMultiSeries ? 0.3 : 0.1\n };\n const defaultXScale = {\n // Always begin at zero since the x axis is hidden.\n zero: true\n };\n const yScale = {\n ...defaultYScale,\n ...(options.yScale ?? {})\n };\n const xScale = {\n ...defaultXScale,\n ...(options.xScale ?? {})\n };\n return {\n yScale,\n xScale,\n labelPosition: options.labelPosition ?? (isMultiSeries ? 0 : 10),\n valueFormatter: options.valueFormatter ?? (value => formatNumberCompact(value)),\n labelFormatter: options.labelFormatter ?? (value => String(value)),\n valuePosition: options.valuePosition ?? width,\n yOffset: options.yOffset ?? getDefaultYOffset(data, yScale, height, isMultiSeries)\n };\n }, [options, width, data, height]);\n return /*#__PURE__*/_jsx(BarChartUnresponsive, {\n orientation: \"horizontal\",\n gridVisibility: 'none',\n data: data,\n width: width,\n height: height,\n margin: margin,\n options: {\n axis: {\n y: {\n children: renderProps => /*#__PURE__*/_jsx(AxisRenderer, {\n ...renderProps,\n data: data,\n yOffset: chartOptions.yOffset,\n labelPosition: chartOptions.labelPosition,\n valuePosition: chartOptions.valuePosition,\n labelFormatter: chartOptions.labelFormatter,\n valueFormatter: chartOptions.valueFormatter,\n LabelComponent: options.labelComponent,\n ValueComponent: options.valueComponent\n })\n },\n x: {\n children: () => null\n }\n },\n xScale: chartOptions.xScale,\n yScale: chartOptions.yScale\n },\n ...rest\n });\n};\nconst BarListChart = props => {\n const existingContext = useContext(GlobalChartsContext);\n\n // If we're already in a GlobalChartsProvider context, render the core component directly\n if (existingContext) {\n return /*#__PURE__*/_jsx(BarListChartInternal, {\n ...props\n });\n }\n\n // Otherwise, wrap with our own GlobalChartsProvider\n return /*#__PURE__*/_jsx(GlobalChartsProvider, {\n children: /*#__PURE__*/_jsx(BarListChartInternal, {\n ...props\n })\n });\n};\nBarListChart.displayName = 'BarListChart';\nconst BarListChartResponsive = withResponsive(BarListChart);\nexport { BarListChartResponsive as default, BarListChart as BarListChartUnresponsive };"],"mappings":";;;;;;;;;;;;AAAA,SAAS,2BAA2B;AACpC,SAAS,aAAa;AACtB,SAAS,aAAa,iBAAiB;AACvC,SAAS,YAAY;AACrB,SAAS,YAAY,eAAe;AAIpC,SAAS,OAAO,MAAM,QAAQ,aAAa;AAM3C,IAAM,oBAAoB,WAAS;AAEjC,QAAM,IAAI;AACV,SAAO,KAAK,eAAe,IAAI,GAAG,UAAU,KAAK,IAAI;AACvD;AACA,IAAM,wBAAwB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,SAAoB,qBAAK,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,UAAU,UAAU,KAAK;AAAA,EAC3B,CAAC;AACH;AACA,IAAM,wBAAwB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,SAAoB,qBAAK,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH,YAAY;AAAA,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