@automattic/charts 0.57.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -2
- package/README.md +7 -54
- package/dist/index.cjs +9607 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +32 -49
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +1612 -33
- package/dist/index.d.ts +1612 -33
- package/dist/index.js +9640 -54
- package/dist/index.js.map +1 -1
- package/package.json +9 -126
- package/src/charts/bar-chart/bar-chart.module.scss +0 -5
- package/src/charts/bar-chart/bar-chart.tsx +142 -149
- package/src/charts/bar-chart/test/bar-chart.test.tsx +48 -31
- package/src/charts/leaderboard-chart/leaderboard-chart.tsx +54 -74
- package/src/charts/leaderboard-chart/test/leaderboard-chart.test.tsx +4 -5
- package/src/charts/leaderboard-chart/types.ts +1 -11
- package/src/charts/line-chart/line-chart.module.scss +0 -5
- package/src/charts/line-chart/line-chart.tsx +202 -193
- package/src/charts/line-chart/private/line-chart-annotations-overlay.tsx +1 -2
- package/src/charts/line-chart/test/line-chart.test.tsx +49 -27
- package/src/charts/line-chart/types.ts +0 -1
- package/src/charts/pie-chart/pie-chart.module.scss +2 -10
- package/src/charts/pie-chart/pie-chart.tsx +212 -212
- package/src/charts/pie-chart/test/composition-api.test.tsx +44 -3
- package/src/charts/pie-chart/test/pie-chart.test.tsx +51 -44
- package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +2 -8
- package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx +166 -168
- package/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx +58 -30
- package/src/charts/private/chart-composition/index.ts +2 -0
- package/src/charts/private/chart-composition/render-legend-slot.ts +22 -0
- package/src/charts/private/chart-composition/test/render-legend-slot.test.tsx +60 -0
- package/src/charts/private/chart-composition/test/use-chart-children.test.tsx +91 -0
- package/src/charts/private/chart-composition/use-chart-children.ts +34 -2
- package/src/charts/private/chart-layout/chart-layout.module.scss +7 -0
- package/src/charts/private/chart-layout/chart-layout.tsx +106 -0
- package/src/charts/private/chart-layout/index.ts +2 -0
- package/src/charts/private/chart-layout/test/chart-layout.test.tsx +167 -0
- package/src/charts/private/single-chart-context/single-chart-context.tsx +2 -2
- package/src/charts/private/svg-empty-state/index.ts +1 -0
- package/src/charts/private/svg-empty-state/svg-empty-state.module.scss +7 -0
- package/src/charts/private/svg-empty-state/svg-empty-state.tsx +40 -0
- package/src/components/legend/hooks/test/use-chart-legend-items.test.tsx +12 -8
- package/src/components/legend/hooks/use-chart-legend-items.ts +12 -13
- package/src/components/legend/index.ts +1 -8
- package/src/components/legend/legend.tsx +33 -8
- package/src/components/legend/private/base-legend.module.scss +19 -37
- package/src/components/legend/private/base-legend.tsx +0 -2
- package/src/components/legend/test/legend.test.tsx +93 -1
- package/src/components/legend/types.ts +7 -34
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-data-with-percentages.ts +24 -0
- package/src/hooks/use-interactive-legend-data.ts +18 -15
- package/src/index.ts +66 -9
- package/src/providers/chart-context/global-charts-provider.tsx +7 -1
- package/src/providers/chart-context/hooks/use-chart-registration.ts +2 -1
- package/src/providers/chart-context/types.ts +2 -2
- package/src/types.ts +110 -45
- package/src/utils/date-parsing.ts +10 -1
- package/src/utils/test/date-parsing.test.ts +12 -0
- package/src/utils/test/resolve-css-var.test.ts +4 -2
- package/tsup.config.ts +1 -1
- package/dist/base-tooltip-DOq93wjU.d.cts +0 -38
- package/dist/base-tooltip-DOq93wjU.d.ts +0 -38
- package/dist/charts/bar-chart/index.cjs +0 -15
- package/dist/charts/bar-chart/index.cjs.map +0 -1
- package/dist/charts/bar-chart/index.css +0 -153
- package/dist/charts/bar-chart/index.css.map +0 -1
- package/dist/charts/bar-chart/index.d.cts +0 -37
- package/dist/charts/bar-chart/index.d.ts +0 -37
- package/dist/charts/bar-chart/index.js +0 -15
- package/dist/charts/bar-chart/index.js.map +0 -1
- package/dist/charts/bar-list-chart/index.cjs +0 -16
- package/dist/charts/bar-list-chart/index.cjs.map +0 -1
- package/dist/charts/bar-list-chart/index.css +0 -153
- package/dist/charts/bar-list-chart/index.css.map +0 -1
- package/dist/charts/bar-list-chart/index.d.cts +0 -92
- package/dist/charts/bar-list-chart/index.d.ts +0 -92
- package/dist/charts/bar-list-chart/index.js +0 -16
- package/dist/charts/bar-list-chart/index.js.map +0 -1
- package/dist/charts/conversion-funnel-chart/index.cjs +0 -11
- package/dist/charts/conversion-funnel-chart/index.cjs.map +0 -1
- package/dist/charts/conversion-funnel-chart/index.css +0 -251
- package/dist/charts/conversion-funnel-chart/index.css.map +0 -1
- package/dist/charts/conversion-funnel-chart/index.d.cts +0 -97
- package/dist/charts/conversion-funnel-chart/index.d.ts +0 -97
- package/dist/charts/conversion-funnel-chart/index.js +0 -11
- package/dist/charts/conversion-funnel-chart/index.js.map +0 -1
- package/dist/charts/geo-chart/index.cjs +0 -13
- package/dist/charts/geo-chart/index.cjs.map +0 -1
- package/dist/charts/geo-chart/index.css +0 -117
- package/dist/charts/geo-chart/index.css.map +0 -1
- package/dist/charts/geo-chart/index.d.cts +0 -67
- package/dist/charts/geo-chart/index.d.ts +0 -67
- package/dist/charts/geo-chart/index.js +0 -13
- package/dist/charts/geo-chart/index.js.map +0 -1
- package/dist/charts/leaderboard-chart/index.cjs +0 -20
- package/dist/charts/leaderboard-chart/index.cjs.map +0 -1
- package/dist/charts/leaderboard-chart/index.css +0 -172
- package/dist/charts/leaderboard-chart/index.css.map +0 -1
- package/dist/charts/leaderboard-chart/index.d.cts +0 -46
- package/dist/charts/leaderboard-chart/index.d.ts +0 -46
- package/dist/charts/leaderboard-chart/index.js +0 -20
- package/dist/charts/leaderboard-chart/index.js.map +0 -1
- package/dist/charts/line-chart/index.cjs +0 -15
- package/dist/charts/line-chart/index.cjs.map +0 -1
- package/dist/charts/line-chart/index.css +0 -225
- package/dist/charts/line-chart/index.css.map +0 -1
- package/dist/charts/line-chart/index.d.cts +0 -99
- package/dist/charts/line-chart/index.d.ts +0 -99
- package/dist/charts/line-chart/index.js +0 -15
- package/dist/charts/line-chart/index.js.map +0 -1
- package/dist/charts/pie-chart/index.cjs +0 -18
- package/dist/charts/pie-chart/index.cjs.map +0 -1
- package/dist/charts/pie-chart/index.css +0 -143
- package/dist/charts/pie-chart/index.css.map +0 -1
- package/dist/charts/pie-chart/index.d.cts +0 -97
- package/dist/charts/pie-chart/index.d.ts +0 -97
- package/dist/charts/pie-chart/index.js +0 -18
- package/dist/charts/pie-chart/index.js.map +0 -1
- package/dist/charts/pie-semi-circle-chart/index.cjs +0 -17
- package/dist/charts/pie-semi-circle-chart/index.cjs.map +0 -1
- package/dist/charts/pie-semi-circle-chart/index.css +0 -144
- package/dist/charts/pie-semi-circle-chart/index.css.map +0 -1
- package/dist/charts/pie-semi-circle-chart/index.d.cts +0 -94
- package/dist/charts/pie-semi-circle-chart/index.d.ts +0 -94
- package/dist/charts/pie-semi-circle-chart/index.js +0 -17
- package/dist/charts/pie-semi-circle-chart/index.js.map +0 -1
- package/dist/charts/sparkline/index.cjs +0 -16
- package/dist/charts/sparkline/index.cjs.map +0 -1
- package/dist/charts/sparkline/index.css +0 -242
- package/dist/charts/sparkline/index.css.map +0 -1
- package/dist/charts/sparkline/index.d.cts +0 -113
- package/dist/charts/sparkline/index.d.ts +0 -113
- package/dist/charts/sparkline/index.js +0 -16
- package/dist/charts/sparkline/index.js.map +0 -1
- package/dist/chunk-2A34OA5O.cjs +0 -51
- package/dist/chunk-2A34OA5O.cjs.map +0 -1
- package/dist/chunk-2NCY7R4G.js +0 -3897
- package/dist/chunk-2NCY7R4G.js.map +0 -1
- package/dist/chunk-32DH6JDF.js +0 -1263
- package/dist/chunk-32DH6JDF.js.map +0 -1
- package/dist/chunk-4OPFE4RM.js +0 -614
- package/dist/chunk-4OPFE4RM.js.map +0 -1
- package/dist/chunk-6CCZL2JJ.js +0 -63
- package/dist/chunk-6CCZL2JJ.js.map +0 -1
- package/dist/chunk-77OKCVQN.cjs +0 -421
- package/dist/chunk-77OKCVQN.cjs.map +0 -1
- package/dist/chunk-7FQX4ALL.cjs +0 -219
- package/dist/chunk-7FQX4ALL.cjs.map +0 -1
- package/dist/chunk-ASLARV7L.cjs +0 -81
- package/dist/chunk-ASLARV7L.cjs.map +0 -1
- package/dist/chunk-BCX5THDQ.js +0 -403
- package/dist/chunk-BCX5THDQ.js.map +0 -1
- package/dist/chunk-BPYKWMI7.js +0 -194
- package/dist/chunk-BPYKWMI7.js.map +0 -1
- package/dist/chunk-CZGYJKG6.js +0 -421
- package/dist/chunk-CZGYJKG6.js.map +0 -1
- package/dist/chunk-D2UH4CFE.cjs +0 -120
- package/dist/chunk-D2UH4CFE.cjs.map +0 -1
- package/dist/chunk-DAU3HNEG.js +0 -344
- package/dist/chunk-DAU3HNEG.js.map +0 -1
- package/dist/chunk-H2V4JMSA.js +0 -219
- package/dist/chunk-H2V4JMSA.js.map +0 -1
- package/dist/chunk-I2276W3I.cjs +0 -66
- package/dist/chunk-I2276W3I.cjs.map +0 -1
- package/dist/chunk-I35UYJJR.cjs +0 -468
- package/dist/chunk-I35UYJJR.cjs.map +0 -1
- package/dist/chunk-IU4DYUAV.js +0 -120
- package/dist/chunk-IU4DYUAV.js.map +0 -1
- package/dist/chunk-KXRWNFQJ.js +0 -51
- package/dist/chunk-KXRWNFQJ.js.map +0 -1
- package/dist/chunk-OP6PHB2U.js +0 -81
- package/dist/chunk-OP6PHB2U.js.map +0 -1
- package/dist/chunk-PXLEMUGJ.js +0 -165
- package/dist/chunk-PXLEMUGJ.js.map +0 -1
- package/dist/chunk-RCY6XLGU.cjs +0 -63
- package/dist/chunk-RCY6XLGU.cjs.map +0 -1
- package/dist/chunk-RHHVEJHJ.cjs +0 -1263
- package/dist/chunk-RHHVEJHJ.cjs.map +0 -1
- package/dist/chunk-TO3OQBXG.cjs +0 -165
- package/dist/chunk-TO3OQBXG.cjs.map +0 -1
- package/dist/chunk-V36ERY7Y.js +0 -375
- package/dist/chunk-V36ERY7Y.js.map +0 -1
- package/dist/chunk-VJM5XCB4.cjs +0 -614
- package/dist/chunk-VJM5XCB4.cjs.map +0 -1
- package/dist/chunk-VTS3PNMS.cjs +0 -344
- package/dist/chunk-VTS3PNMS.cjs.map +0 -1
- package/dist/chunk-WLODYNLB.js +0 -1067
- package/dist/chunk-WLODYNLB.js.map +0 -1
- package/dist/chunk-XKRJL2QT.cjs +0 -375
- package/dist/chunk-XKRJL2QT.cjs.map +0 -1
- package/dist/chunk-XWYZIFZW.js +0 -66
- package/dist/chunk-XWYZIFZW.js.map +0 -1
- package/dist/chunk-Y3NNQMAX.cjs +0 -194
- package/dist/chunk-Y3NNQMAX.cjs.map +0 -1
- package/dist/chunk-YE2T52VZ.cjs +0 -1067
- package/dist/chunk-YE2T52VZ.cjs.map +0 -1
- package/dist/chunk-Z26M4V2M.js +0 -468
- package/dist/chunk-Z26M4V2M.js.map +0 -1
- package/dist/chunk-Z45KX47P.cjs +0 -3897
- package/dist/chunk-Z45KX47P.cjs.map +0 -1
- package/dist/chunk-ZH4F5RMG.cjs +0 -403
- package/dist/chunk-ZH4F5RMG.cjs.map +0 -1
- package/dist/components/legend/index.cjs +0 -11
- package/dist/components/legend/index.cjs.map +0 -1
- package/dist/components/legend/index.css +0 -103
- package/dist/components/legend/index.css.map +0 -1
- package/dist/components/legend/index.d.cts +0 -37
- package/dist/components/legend/index.d.ts +0 -37
- package/dist/components/legend/index.js +0 -11
- package/dist/components/legend/index.js.map +0 -1
- package/dist/components/tooltip/index.cjs +0 -12
- package/dist/components/tooltip/index.cjs.map +0 -1
- package/dist/components/tooltip/index.css +0 -13
- package/dist/components/tooltip/index.css.map +0 -1
- package/dist/components/tooltip/index.d.cts +0 -71
- package/dist/components/tooltip/index.d.ts +0 -71
- package/dist/components/tooltip/index.js +0 -12
- package/dist/components/tooltip/index.js.map +0 -1
- package/dist/components/trend-indicator/index.cjs +0 -8
- package/dist/components/trend-indicator/index.cjs.map +0 -1
- package/dist/components/trend-indicator/index.css +0 -27
- package/dist/components/trend-indicator/index.css.map +0 -1
- package/dist/components/trend-indicator/index.d.cts +0 -44
- package/dist/components/trend-indicator/index.d.ts +0 -44
- package/dist/components/trend-indicator/index.js +0 -8
- package/dist/components/trend-indicator/index.js.map +0 -1
- package/dist/format-metric-value-MXm5DtQ_.d.cts +0 -24
- package/dist/format-metric-value-MXm5DtQ_.d.ts +0 -24
- package/dist/hooks/index.cjs +0 -31
- package/dist/hooks/index.cjs.map +0 -1
- package/dist/hooks/index.css +0 -103
- package/dist/hooks/index.css.map +0 -1
- package/dist/hooks/index.d.cts +0 -272
- package/dist/hooks/index.d.ts +0 -272
- package/dist/hooks/index.js +0 -31
- package/dist/hooks/index.js.map +0 -1
- package/dist/leaderboard-chart-BKYYXcg2.d.ts +0 -83
- package/dist/leaderboard-chart-DR7CGb0L.d.cts +0 -83
- package/dist/legend-C2grwnWk.d.cts +0 -9
- package/dist/legend-Cj0xM5dU.d.ts +0 -9
- package/dist/providers/index.cjs +0 -21
- package/dist/providers/index.cjs.map +0 -1
- package/dist/providers/index.css +0 -103
- package/dist/providers/index.css.map +0 -1
- package/dist/providers/index.d.cts +0 -28
- package/dist/providers/index.d.ts +0 -28
- package/dist/providers/index.js +0 -21
- package/dist/providers/index.js.map +0 -1
- package/dist/themes-BmVGrYnF.d.ts +0 -67
- package/dist/themes-CyjKm-P_.d.cts +0 -67
- package/dist/types-CuUEszrM.d.ts +0 -19
- package/dist/types-DZordNiO.d.cts +0 -505
- package/dist/types-DZordNiO.d.ts +0 -505
- package/dist/types-I67mddpr.d.cts +0 -78
- package/dist/types-I67mddpr.d.ts +0 -78
- package/dist/types-KtOPPzPX.d.cts +0 -19
- package/dist/utils/index.cjs +0 -44
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.d.cts +0 -226
- package/dist/utils/index.d.ts +0 -226
- package/dist/utils/index.js +0 -44
- package/dist/utils/index.js.map +0 -1
- package/dist/with-responsive-CNfhzAUu.d.cts +0 -18
- package/dist/with-responsive-CNfhzAUu.d.ts +0 -18
- package/src/hooks/use-has-legend-child.ts +0 -22
package/dist/chunk-32DH6JDF.js
DELETED
|
@@ -1,1263 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatPercentage,
|
|
3
|
-
getColorDistance,
|
|
4
|
-
getItemShapeStyles,
|
|
5
|
-
getLongestTickWidth,
|
|
6
|
-
getSeriesLineStyles,
|
|
7
|
-
mergeThemes,
|
|
8
|
-
normalizeColorToHex,
|
|
9
|
-
parseAsLocalDate,
|
|
10
|
-
resolveCssVariable
|
|
11
|
-
} from "./chunk-DAU3HNEG.js";
|
|
12
|
-
|
|
13
|
-
// src/hooks/use-deep-memo.ts
|
|
14
|
-
import isEqual from "fast-deep-equal";
|
|
15
|
-
import { useRef } from "react";
|
|
16
|
-
var useDeepMemo = (value) => {
|
|
17
|
-
const ref = useRef(value);
|
|
18
|
-
if (!isEqual(ref.current, value)) {
|
|
19
|
-
ref.current = value;
|
|
20
|
-
}
|
|
21
|
-
return ref.current;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// src/hooks/use-chart-mouse-handler.ts
|
|
25
|
-
import { localPoint } from "@visx/event";
|
|
26
|
-
import { useTooltip } from "@visx/tooltip";
|
|
27
|
-
import { useCallback } from "react";
|
|
28
|
-
var useChartMouseHandler = ({
|
|
29
|
-
withTooltips,
|
|
30
|
-
offsetX = 0,
|
|
31
|
-
offsetY = -10
|
|
32
|
-
}) => {
|
|
33
|
-
const { tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip } = useTooltip();
|
|
34
|
-
const onMouseMove = useCallback(
|
|
35
|
-
(event, data) => {
|
|
36
|
-
if (!withTooltips) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const coords = localPoint(event);
|
|
40
|
-
if (!coords) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
showTooltip({
|
|
44
|
-
tooltipData: data,
|
|
45
|
-
tooltipLeft: coords.x + offsetX,
|
|
46
|
-
tooltipTop: coords.y + offsetY
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
[withTooltips, showTooltip, offsetX, offsetY]
|
|
50
|
-
);
|
|
51
|
-
const onMouseLeave = useCallback(() => {
|
|
52
|
-
if (!withTooltips) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
hideTooltip();
|
|
56
|
-
}, [withTooltips, hideTooltip]);
|
|
57
|
-
return {
|
|
58
|
-
onMouseMove,
|
|
59
|
-
onMouseLeave,
|
|
60
|
-
tooltipOpen,
|
|
61
|
-
tooltipData: tooltipData || null,
|
|
62
|
-
tooltipLeft,
|
|
63
|
-
tooltipTop
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/hooks/use-xychart-theme.ts
|
|
68
|
-
import { buildChartTheme } from "@visx/xychart";
|
|
69
|
-
import { useMemo as useMemo3 } from "react";
|
|
70
|
-
|
|
71
|
-
// src/providers/chart-context/global-charts-provider.tsx
|
|
72
|
-
import { hsl as d3Hsl2 } from "@visx/vendor/d3-color";
|
|
73
|
-
import { createContext, useCallback as useCallback2, useMemo, useState, useEffect as useEffect2, useLayoutEffect, useRef as useRef2 } from "react";
|
|
74
|
-
|
|
75
|
-
// src/hooks/use-tooltip-portal-relocator.ts
|
|
76
|
-
import { useEffect } from "react";
|
|
77
|
-
|
|
78
|
-
// src/hooks/use-tooltip-portal-relocator.module.scss
|
|
79
|
-
var use_tooltip_portal_relocator_module_default = {
|
|
80
|
-
"relocatedPortal": "a8ccharts-jCw5dQ"
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/hooks/use-tooltip-portal-relocator.ts
|
|
84
|
-
function isVisxPortalNode(node) {
|
|
85
|
-
return node instanceof HTMLDivElement && node.parentElement === document.body && !node.id && !node.className && node.querySelector(".visx-tooltip") !== null;
|
|
86
|
-
}
|
|
87
|
-
var patchRefCount = 0;
|
|
88
|
-
var origRemoveChild = null;
|
|
89
|
-
var patchedRemoveChild = null;
|
|
90
|
-
var relocatedNodes = /* @__PURE__ */ new WeakSet();
|
|
91
|
-
function installRemoveChildPatch() {
|
|
92
|
-
if (patchRefCount++ > 0) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
origRemoveChild = document.body.removeChild;
|
|
96
|
-
patchedRemoveChild = function(child) {
|
|
97
|
-
if (relocatedNodes.has(child) && child.parentNode !== this) {
|
|
98
|
-
relocatedNodes.delete(child);
|
|
99
|
-
child.parentNode?.removeChild(child);
|
|
100
|
-
return child;
|
|
101
|
-
}
|
|
102
|
-
return origRemoveChild.call(this, child);
|
|
103
|
-
};
|
|
104
|
-
document.body.removeChild = patchedRemoveChild;
|
|
105
|
-
}
|
|
106
|
-
function uninstallRemoveChildPatch() {
|
|
107
|
-
if (--patchRefCount > 0) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (document.body.removeChild === patchedRemoveChild) {
|
|
111
|
-
document.body.removeChild = origRemoveChild;
|
|
112
|
-
}
|
|
113
|
-
origRemoveChild = null;
|
|
114
|
-
patchedRemoveChild = null;
|
|
115
|
-
}
|
|
116
|
-
function useTooltipPortalRelocator(containerRef) {
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
const container = containerRef?.current;
|
|
119
|
-
if (!container) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const instanceNodes = /* @__PURE__ */ new Set();
|
|
123
|
-
const relocateNode = (node) => {
|
|
124
|
-
if (!isVisxPortalNode(node)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
node.style.opacity = "0";
|
|
128
|
-
node.classList.add(use_tooltip_portal_relocator_module_default.relocatedPortal);
|
|
129
|
-
const { activeElement } = node.ownerDocument;
|
|
130
|
-
const focusedElement = activeElement instanceof HTMLElement && node.contains(activeElement) ? activeElement : null;
|
|
131
|
-
container.insertBefore(node, container.firstChild);
|
|
132
|
-
relocatedNodes.add(node);
|
|
133
|
-
instanceNodes.add(node);
|
|
134
|
-
if (focusedElement) {
|
|
135
|
-
focusedElement.focus();
|
|
136
|
-
}
|
|
137
|
-
requestAnimationFrame(() => {
|
|
138
|
-
requestAnimationFrame(() => {
|
|
139
|
-
node.style.opacity = "";
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
installRemoveChildPatch();
|
|
144
|
-
for (const child of Array.from(document.body.children)) {
|
|
145
|
-
relocateNode(child);
|
|
146
|
-
}
|
|
147
|
-
const observer = new MutationObserver((mutations) => {
|
|
148
|
-
for (const mutation of mutations) {
|
|
149
|
-
for (const node of mutation.addedNodes) {
|
|
150
|
-
relocateNode(node);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
observer.observe(document.body, { childList: true });
|
|
155
|
-
return () => {
|
|
156
|
-
observer.disconnect();
|
|
157
|
-
for (const node of instanceNodes) {
|
|
158
|
-
if (node instanceof HTMLElement) {
|
|
159
|
-
node.classList.remove(use_tooltip_portal_relocator_module_default.relocatedPortal);
|
|
160
|
-
}
|
|
161
|
-
if (node.parentNode === container) {
|
|
162
|
-
document.body.appendChild(node);
|
|
163
|
-
}
|
|
164
|
-
relocatedNodes.delete(node);
|
|
165
|
-
}
|
|
166
|
-
instanceNodes.clear();
|
|
167
|
-
uninstallRemoveChildPatch();
|
|
168
|
-
};
|
|
169
|
-
}, [containerRef]);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// src/providers/chart-context/private/get-chart-color.ts
|
|
173
|
-
import { hsl as d3Hsl } from "@visx/vendor/d3-color";
|
|
174
|
-
var GOLDEN_RATIO = 0.618033988749;
|
|
175
|
-
var MIN_COLOR_DISTANCE = 25;
|
|
176
|
-
var MAX_COLOR_GENERATION_ATTEMPTS = 50;
|
|
177
|
-
var VARIATION_ATTEMPT_OFFSET = 0.1;
|
|
178
|
-
var BASE_SATURATION = 45;
|
|
179
|
-
var SATURATION_VARIATION_STEPS = 3;
|
|
180
|
-
var SATURATION_INCREMENT = 10;
|
|
181
|
-
var BASE_LIGHTNESS = 35;
|
|
182
|
-
var LIGHTNESS_VARIATION_STEPS = 4;
|
|
183
|
-
var LIGHTNESS_INCREMENT = 8;
|
|
184
|
-
var MIN_HUE_RANGE_DEGREES = 60;
|
|
185
|
-
var HUE_RANGE_EXPANSION_FACTOR = 1.3;
|
|
186
|
-
var HUE_WRAP_THRESHOLD_DEGREES = 180;
|
|
187
|
-
var FULL_HUE_ROTATION_DEGREES = 360;
|
|
188
|
-
var SINGLE_COLOR_HUE_RANGE_FACTOR = 0.33;
|
|
189
|
-
var getChartColor = (index, colorCache) => {
|
|
190
|
-
const {
|
|
191
|
-
colors,
|
|
192
|
-
hues,
|
|
193
|
-
existingHslColors,
|
|
194
|
-
minHue: cachedMinHue,
|
|
195
|
-
maxHue: cachedMaxHue
|
|
196
|
-
} = colorCache;
|
|
197
|
-
if (index < colors.length) {
|
|
198
|
-
return colors[index];
|
|
199
|
-
}
|
|
200
|
-
let minHue = cachedMinHue;
|
|
201
|
-
let maxHue = cachedMaxHue;
|
|
202
|
-
for (let attempt = 0; attempt < MAX_COLOR_GENERATION_ATTEMPTS; attempt++) {
|
|
203
|
-
let hue = (index - colors.length + attempt * VARIATION_ATTEMPT_OFFSET) * GOLDEN_RATIO * FULL_HUE_ROTATION_DEGREES % FULL_HUE_ROTATION_DEGREES;
|
|
204
|
-
if (hues.length > 0) {
|
|
205
|
-
let hueRange = maxHue - minHue;
|
|
206
|
-
if (hues.length === 1) {
|
|
207
|
-
hueRange = FULL_HUE_ROTATION_DEGREES * SINGLE_COLOR_HUE_RANGE_FACTOR;
|
|
208
|
-
} else if (hueRange > HUE_WRAP_THRESHOLD_DEGREES) {
|
|
209
|
-
const altMinHue = Math.min(...hues.filter((h) => h > HUE_WRAP_THRESHOLD_DEGREES));
|
|
210
|
-
const altMaxHue = Math.max(...hues.filter((h) => h < HUE_WRAP_THRESHOLD_DEGREES)) + FULL_HUE_ROTATION_DEGREES;
|
|
211
|
-
const altRange = altMaxHue - altMinHue;
|
|
212
|
-
if (altRange < hueRange) {
|
|
213
|
-
minHue = altMinHue;
|
|
214
|
-
maxHue = altMaxHue;
|
|
215
|
-
hueRange = altRange;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
const expandedRange = Math.max(
|
|
219
|
-
hueRange * HUE_RANGE_EXPANSION_FACTOR,
|
|
220
|
-
MIN_HUE_RANGE_DEGREES
|
|
221
|
-
);
|
|
222
|
-
const rangeCenter = (minHue + maxHue) / 2;
|
|
223
|
-
const expandedMin = rangeCenter - expandedRange / 2;
|
|
224
|
-
hue = expandedMin + hue / FULL_HUE_ROTATION_DEGREES * expandedRange;
|
|
225
|
-
hue = (hue % FULL_HUE_ROTATION_DEGREES + FULL_HUE_ROTATION_DEGREES) % FULL_HUE_ROTATION_DEGREES;
|
|
226
|
-
}
|
|
227
|
-
const saturation = BASE_SATURATION + (index + attempt) % SATURATION_VARIATION_STEPS * SATURATION_INCREMENT;
|
|
228
|
-
const lightness = BASE_LIGHTNESS + (index + attempt) % LIGHTNESS_VARIATION_STEPS * LIGHTNESS_INCREMENT;
|
|
229
|
-
const candidateHsl = [hue, saturation, lightness];
|
|
230
|
-
let isSufficientlyDifferent = true;
|
|
231
|
-
for (const existingHsl of existingHslColors) {
|
|
232
|
-
if (getColorDistance(candidateHsl, existingHsl) < MIN_COLOR_DISTANCE) {
|
|
233
|
-
isSufficientlyDifferent = false;
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (isSufficientlyDifferent) {
|
|
238
|
-
return d3Hsl(Math.round(hue), saturation / 100, lightness / 100).formatHex();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const fallbackHue = (index - colors.length) * GOLDEN_RATIO * FULL_HUE_ROTATION_DEGREES % FULL_HUE_ROTATION_DEGREES;
|
|
242
|
-
const fallbackSaturation = BASE_SATURATION + index % SATURATION_VARIATION_STEPS * SATURATION_INCREMENT;
|
|
243
|
-
const fallbackLightness = BASE_LIGHTNESS + index % LIGHTNESS_VARIATION_STEPS * LIGHTNESS_INCREMENT;
|
|
244
|
-
return d3Hsl(
|
|
245
|
-
Math.round(fallbackHue),
|
|
246
|
-
fallbackSaturation / 100,
|
|
247
|
-
fallbackLightness / 100
|
|
248
|
-
).formatHex();
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// src/providers/chart-context/themes.ts
|
|
252
|
-
var defaultTheme = {
|
|
253
|
-
backgroundColor: "#FFFFFF",
|
|
254
|
-
// chart background color
|
|
255
|
-
labelBackgroundColor: "transparent",
|
|
256
|
-
// label background color (transparent by default)
|
|
257
|
-
labelTextColor: "#FFFFFF",
|
|
258
|
-
// label text color (white to match original behavior)
|
|
259
|
-
colors: ["#98C8DF", "#006DAB", "#A6DC80", "#1F9828", "#FF8C8F"],
|
|
260
|
-
gridStyles: {
|
|
261
|
-
stroke: "#DCDCDE",
|
|
262
|
-
strokeWidth: 1
|
|
263
|
-
},
|
|
264
|
-
tickLength: 4,
|
|
265
|
-
gridColor: "",
|
|
266
|
-
gridColorDark: "",
|
|
267
|
-
xTickLineStyles: { stroke: "black" },
|
|
268
|
-
xAxisLineStyles: { stroke: "#DCDCDE", strokeWidth: 1 },
|
|
269
|
-
legend: {
|
|
270
|
-
labelStyles: {
|
|
271
|
-
color: "var(--jp-gray-80, #2c3338)"
|
|
272
|
-
},
|
|
273
|
-
containerStyles: {},
|
|
274
|
-
shapeStyles: []
|
|
275
|
-
},
|
|
276
|
-
seriesLineStyles: [],
|
|
277
|
-
glyphs: [],
|
|
278
|
-
svgLabelSmall: { fill: "var(--jp-gray-80, #2c3338)" },
|
|
279
|
-
annotationStyles: {
|
|
280
|
-
label: {
|
|
281
|
-
anchorLineStroke: "var(--jp-gray-80, #2c3338)",
|
|
282
|
-
backgroundFill: "#fff"
|
|
283
|
-
},
|
|
284
|
-
connector: {
|
|
285
|
-
stroke: "var(--jp-gray-80, #2c3338)"
|
|
286
|
-
},
|
|
287
|
-
circleSubject: {
|
|
288
|
-
stroke: "transparent",
|
|
289
|
-
fill: "var(--jp-gray-80, #2c3338)",
|
|
290
|
-
radius: 5
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
geoChart: {
|
|
294
|
-
featureFillColor: "var(--jp-gray-0, #f6f7f7)"
|
|
295
|
-
},
|
|
296
|
-
leaderboardChart: {
|
|
297
|
-
rowGap: 12,
|
|
298
|
-
columnGap: 4,
|
|
299
|
-
labelSpacing: 1.5,
|
|
300
|
-
deltaColors: ["#FF8C8F", "#757575", "#1F9828"]
|
|
301
|
-
// [negative, neutral, positive]
|
|
302
|
-
},
|
|
303
|
-
conversionFunnelChart: {
|
|
304
|
-
backgroundColor: "#F3F4F6",
|
|
305
|
-
positiveChangeColor: "#1F9828",
|
|
306
|
-
negativeChangeColor: "#FF8C8F"
|
|
307
|
-
},
|
|
308
|
-
lineChart: {
|
|
309
|
-
lineStyles: {
|
|
310
|
-
comparison: {
|
|
311
|
-
strokeDasharray: "4 4",
|
|
312
|
-
strokeLinecap: "square"
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
sparkline: {
|
|
317
|
-
margin: { top: 2, right: 2, bottom: 2, left: 2 },
|
|
318
|
-
strokeWidth: 1.5
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
// src/providers/chart-context/global-charts-provider.tsx
|
|
323
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
324
|
-
var GlobalChartsContext = /* @__PURE__ */ createContext(null);
|
|
325
|
-
var GlobalChartsProvider = ({
|
|
326
|
-
children,
|
|
327
|
-
theme,
|
|
328
|
-
portalContainer
|
|
329
|
-
}) => {
|
|
330
|
-
const [charts, setCharts] = useState(() => /* @__PURE__ */ new Map());
|
|
331
|
-
const [hiddenSeries, setHiddenSeries] = useState(() => /* @__PURE__ */ new Map());
|
|
332
|
-
const wrapperRef = useRef2(null);
|
|
333
|
-
useTooltipPortalRelocator(portalContainer ?? wrapperRef);
|
|
334
|
-
const providerTheme = useMemo(() => {
|
|
335
|
-
return theme ? mergeThemes(defaultTheme, theme) : defaultTheme;
|
|
336
|
-
}, [theme]);
|
|
337
|
-
const [colorCache, setColorCache] = useState(() => ({
|
|
338
|
-
colors: [],
|
|
339
|
-
hues: [],
|
|
340
|
-
existingHslColors: [],
|
|
341
|
-
minHue: 360,
|
|
342
|
-
maxHue: 0
|
|
343
|
-
}));
|
|
344
|
-
useLayoutEffect(() => {
|
|
345
|
-
const {
|
|
346
|
-
colors
|
|
347
|
-
} = providerTheme;
|
|
348
|
-
const resolvedColors = [];
|
|
349
|
-
const hues = [];
|
|
350
|
-
const existingHslColors = [];
|
|
351
|
-
let minHue = 360;
|
|
352
|
-
let maxHue = 0;
|
|
353
|
-
if (Array.isArray(colors)) {
|
|
354
|
-
for (const color of colors) {
|
|
355
|
-
if (color && typeof color === "string") {
|
|
356
|
-
let colorValue = color;
|
|
357
|
-
if (color.startsWith("--") || color.startsWith("var(")) {
|
|
358
|
-
const resolved = resolveCssVariable(color, wrapperRef.current);
|
|
359
|
-
if (resolved === null || resolved === "") {
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
colorValue = resolved;
|
|
363
|
-
}
|
|
364
|
-
if (colorValue.startsWith("#")) {
|
|
365
|
-
resolvedColors.push(colorValue);
|
|
366
|
-
const hslColor = d3Hsl2(colorValue);
|
|
367
|
-
if (!isNaN(hslColor.h)) {
|
|
368
|
-
const hslTuple = [hslColor.h, hslColor.s * 100, hslColor.l * 100];
|
|
369
|
-
hues.push(hslTuple[0]);
|
|
370
|
-
existingHslColors.push(hslTuple);
|
|
371
|
-
minHue = Math.min(minHue, hslTuple[0]);
|
|
372
|
-
maxHue = Math.max(maxHue, hslTuple[0]);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
setColorCache({
|
|
379
|
-
colors: resolvedColors,
|
|
380
|
-
hues,
|
|
381
|
-
existingHslColors,
|
|
382
|
-
minHue,
|
|
383
|
-
maxHue
|
|
384
|
-
});
|
|
385
|
-
}, [providerTheme]);
|
|
386
|
-
const [groupToColorMap, setGroupToColorMap] = useState(() => /* @__PURE__ */ new Map());
|
|
387
|
-
useEffect2(() => {
|
|
388
|
-
setGroupToColorMap(/* @__PURE__ */ new Map());
|
|
389
|
-
}, [providerTheme.colors]);
|
|
390
|
-
const registerChart = useCallback2((id, data) => {
|
|
391
|
-
setCharts((prev) => new Map(prev).set(id, data));
|
|
392
|
-
}, []);
|
|
393
|
-
const unregisterChart = useCallback2((id) => {
|
|
394
|
-
setCharts((prev) => {
|
|
395
|
-
const newMap = new Map(prev);
|
|
396
|
-
newMap.delete(id);
|
|
397
|
-
return newMap;
|
|
398
|
-
});
|
|
399
|
-
}, []);
|
|
400
|
-
const getChartData = useCallback2((id) => {
|
|
401
|
-
return charts.get(id);
|
|
402
|
-
}, [charts]);
|
|
403
|
-
const resolveColor = useCallback2(({
|
|
404
|
-
group,
|
|
405
|
-
index,
|
|
406
|
-
overrideColor
|
|
407
|
-
}) => {
|
|
408
|
-
if (overrideColor) {
|
|
409
|
-
return normalizeColorToHex(overrideColor, wrapperRef.current, resolveCssVariable);
|
|
410
|
-
}
|
|
411
|
-
if (group) {
|
|
412
|
-
const existing = groupToColorMap.get(group);
|
|
413
|
-
if (existing) {
|
|
414
|
-
return existing;
|
|
415
|
-
}
|
|
416
|
-
const assignedCount = groupToColorMap.size;
|
|
417
|
-
const color = getChartColor(assignedCount, colorCache);
|
|
418
|
-
groupToColorMap.set(group, color);
|
|
419
|
-
return color;
|
|
420
|
-
}
|
|
421
|
-
return getChartColor(index, colorCache);
|
|
422
|
-
}, [colorCache, groupToColorMap]);
|
|
423
|
-
const getElementStyles = useCallback2(({
|
|
424
|
-
data,
|
|
425
|
-
index,
|
|
426
|
-
overrideColor,
|
|
427
|
-
legendShape
|
|
428
|
-
}) => {
|
|
429
|
-
const isSeriesData = data && typeof data === "object" && "data" in data && "options" in data;
|
|
430
|
-
const isPointPercentageData = data && typeof data === "object" && "percentage" in data;
|
|
431
|
-
return {
|
|
432
|
-
color: resolveColor({
|
|
433
|
-
group: data?.group,
|
|
434
|
-
index,
|
|
435
|
-
overrideColor: overrideColor || isSeriesData && data?.options?.stroke || isPointPercentageData && data?.color
|
|
436
|
-
}),
|
|
437
|
-
lineStyles: isSeriesData ? getSeriesLineStyles(data, index, providerTheme) : {},
|
|
438
|
-
glyph: providerTheme.glyphs?.[index],
|
|
439
|
-
shapeStyles: isSeriesData ? getItemShapeStyles(data, index, providerTheme, legendShape) : {}
|
|
440
|
-
};
|
|
441
|
-
}, [providerTheme, resolveColor]);
|
|
442
|
-
const toggleSeriesVisibility = useCallback2((chartId, seriesLabel) => {
|
|
443
|
-
setHiddenSeries((prev) => {
|
|
444
|
-
const newMap = new Map(prev);
|
|
445
|
-
const chartHidden = newMap.get(chartId) || /* @__PURE__ */ new Set();
|
|
446
|
-
const newSet = new Set(chartHidden);
|
|
447
|
-
if (newSet.has(seriesLabel)) {
|
|
448
|
-
newSet.delete(seriesLabel);
|
|
449
|
-
} else {
|
|
450
|
-
newSet.add(seriesLabel);
|
|
451
|
-
}
|
|
452
|
-
if (newSet.size === 0) {
|
|
453
|
-
newMap.delete(chartId);
|
|
454
|
-
} else {
|
|
455
|
-
newMap.set(chartId, newSet);
|
|
456
|
-
}
|
|
457
|
-
return newMap;
|
|
458
|
-
});
|
|
459
|
-
}, []);
|
|
460
|
-
const isSeriesVisible = useCallback2((chartId, seriesLabel) => {
|
|
461
|
-
const chartHidden = hiddenSeries.get(chartId);
|
|
462
|
-
return !chartHidden || !chartHidden.has(seriesLabel);
|
|
463
|
-
}, [hiddenSeries]);
|
|
464
|
-
const getHiddenSeries = useCallback2((chartId) => {
|
|
465
|
-
const set = hiddenSeries.get(chartId);
|
|
466
|
-
return set ? new Set(set) : /* @__PURE__ */ new Set();
|
|
467
|
-
}, [hiddenSeries]);
|
|
468
|
-
const value = useMemo(() => ({
|
|
469
|
-
charts,
|
|
470
|
-
registerChart,
|
|
471
|
-
unregisterChart,
|
|
472
|
-
getChartData,
|
|
473
|
-
theme: providerTheme,
|
|
474
|
-
getElementStyles,
|
|
475
|
-
toggleSeriesVisibility,
|
|
476
|
-
isSeriesVisible,
|
|
477
|
-
getHiddenSeries
|
|
478
|
-
}), [charts, registerChart, unregisterChart, getChartData, providerTheme, getElementStyles, toggleSeriesVisibility, isSeriesVisible, getHiddenSeries]);
|
|
479
|
-
return /* @__PURE__ */ _jsx(GlobalChartsContext.Provider, {
|
|
480
|
-
value,
|
|
481
|
-
children: /* @__PURE__ */ _jsx("div", {
|
|
482
|
-
ref: wrapperRef,
|
|
483
|
-
style: {
|
|
484
|
-
display: "contents"
|
|
485
|
-
},
|
|
486
|
-
children
|
|
487
|
-
})
|
|
488
|
-
});
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
// src/providers/chart-context/hooks/use-global-charts-context.ts
|
|
492
|
-
import { useContext } from "react";
|
|
493
|
-
var useGlobalChartsContext = () => {
|
|
494
|
-
const context = useContext(GlobalChartsContext);
|
|
495
|
-
if (!context) {
|
|
496
|
-
throw new Error("useGlobalChartsContext must be used within a GlobalChartsProvider");
|
|
497
|
-
}
|
|
498
|
-
return context;
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
// src/providers/chart-context/hooks/use-chart-id.ts
|
|
502
|
-
import { useId } from "react";
|
|
503
|
-
var useChartId = (providedId) => {
|
|
504
|
-
const generatedId = useId();
|
|
505
|
-
return providedId || generatedId;
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
// src/providers/chart-context/hooks/use-chart-registration.ts
|
|
509
|
-
import { useEffect as useEffect3, useMemo as useMemo2 } from "react";
|
|
510
|
-
var useChartRegistration = ({
|
|
511
|
-
chartId,
|
|
512
|
-
legendItems,
|
|
513
|
-
chartType,
|
|
514
|
-
isDataValid,
|
|
515
|
-
metadata
|
|
516
|
-
}) => {
|
|
517
|
-
const { registerChart, unregisterChart } = useGlobalChartsContext();
|
|
518
|
-
const stableLegendItems = useDeepMemo(legendItems);
|
|
519
|
-
const memoizedMetadata = useMemo2(() => metadata, [metadata]);
|
|
520
|
-
useEffect3(() => {
|
|
521
|
-
if (isDataValid) {
|
|
522
|
-
registerChart(chartId, {
|
|
523
|
-
legendItems: stableLegendItems,
|
|
524
|
-
chartType,
|
|
525
|
-
metadata: memoizedMetadata
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
return () => {
|
|
529
|
-
unregisterChart(chartId);
|
|
530
|
-
};
|
|
531
|
-
}, [
|
|
532
|
-
chartId,
|
|
533
|
-
stableLegendItems,
|
|
534
|
-
chartType,
|
|
535
|
-
memoizedMetadata,
|
|
536
|
-
isDataValid
|
|
537
|
-
// Removed registerChart and unregisterChart from dependencies
|
|
538
|
-
// They are stable functions created with useCallback and empty deps
|
|
539
|
-
]);
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
// src/providers/chart-context/hooks/use-global-charts-theme.ts
|
|
543
|
-
import { useContext as useContext2 } from "react";
|
|
544
|
-
var useGlobalChartsTheme = () => {
|
|
545
|
-
const context = useContext2(GlobalChartsContext);
|
|
546
|
-
const globalTheme = context?.theme;
|
|
547
|
-
return globalTheme ?? defaultTheme;
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
// src/hooks/use-xychart-theme.ts
|
|
551
|
-
var useXYChartTheme = (data) => {
|
|
552
|
-
const theme = useGlobalChartsTheme();
|
|
553
|
-
return useMemo3(() => {
|
|
554
|
-
const seriesColors = (data ?? []).map((series) => series.options?.stroke).filter((color) => Boolean(color));
|
|
555
|
-
return buildChartTheme({
|
|
556
|
-
...theme,
|
|
557
|
-
colors: [...seriesColors, ...theme.colors ?? []]
|
|
558
|
-
});
|
|
559
|
-
}, [theme, data]);
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
// src/hooks/use-chart-data-transform.ts
|
|
563
|
-
import { useMemo as useMemo4 } from "react";
|
|
564
|
-
var useChartDataTransform = (data) => {
|
|
565
|
-
return useMemo4(() => {
|
|
566
|
-
const firstPoint = data?.[0]?.data?.[0];
|
|
567
|
-
const hasDateProperties = firstPoint && ("date" in firstPoint || "dateString" in firstPoint);
|
|
568
|
-
if (!hasDateProperties) {
|
|
569
|
-
return data;
|
|
570
|
-
}
|
|
571
|
-
return data.map((series) => ({
|
|
572
|
-
...series,
|
|
573
|
-
data: series.data.map((point) => {
|
|
574
|
-
let date;
|
|
575
|
-
if ("date" in point && point.date) {
|
|
576
|
-
date = point.date;
|
|
577
|
-
} else if ("dateString" in point && point.dateString) {
|
|
578
|
-
date = parseAsLocalDate(point.dateString);
|
|
579
|
-
}
|
|
580
|
-
return {
|
|
581
|
-
...point,
|
|
582
|
-
date
|
|
583
|
-
};
|
|
584
|
-
}).sort((a, b) => {
|
|
585
|
-
if (!a.date || !b.date) return 0;
|
|
586
|
-
return a.date.getTime() - b.date.getTime();
|
|
587
|
-
})
|
|
588
|
-
}));
|
|
589
|
-
}, [data]);
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
// src/hooks/use-chart-margin.tsx
|
|
593
|
-
import { createScale, getTicks } from "@visx/scale";
|
|
594
|
-
import { useMemo as useMemo5 } from "react";
|
|
595
|
-
var DEFAULT_MARGIN_TOP = 10;
|
|
596
|
-
var DEFAULT_MARGIN_RIGHT = 20;
|
|
597
|
-
var DEFAULT_MARGIN_BOTTOM = 20;
|
|
598
|
-
var DEFAULT_MARGIN_LEFT = 20;
|
|
599
|
-
var DEFAULT_BOTTOM_FOR_TOP_AXIS = 10;
|
|
600
|
-
var DEFAULT_FONT_SIZE = 12;
|
|
601
|
-
var DEFAULT_TICK_LENGTH = 8;
|
|
602
|
-
var DEFAULT_Y_TICK_WIDTH = 40;
|
|
603
|
-
var resolveFontSize = (val) => {
|
|
604
|
-
if (typeof val === "number" && !isNaN(val)) {
|
|
605
|
-
return val;
|
|
606
|
-
}
|
|
607
|
-
if (typeof val === "string") {
|
|
608
|
-
const parsed = parseFloat(val);
|
|
609
|
-
return isNaN(parsed) ? void 0 : parsed;
|
|
610
|
-
}
|
|
611
|
-
return void 0;
|
|
612
|
-
};
|
|
613
|
-
var getXAxisLabelMetrics = (theme, orientation) => {
|
|
614
|
-
const xAxisStyles = orientation === "top" ? theme.axisStyles?.x?.top : theme.axisStyles?.x?.bottom;
|
|
615
|
-
const fontSize = resolveFontSize(xAxisStyles?.axisLabel?.fontSize) || resolveFontSize(theme.svgLabelSmall?.fontSize) || DEFAULT_FONT_SIZE;
|
|
616
|
-
const tickLength = xAxisStyles?.tickLength ?? DEFAULT_TICK_LENGTH;
|
|
617
|
-
return {
|
|
618
|
-
fontSize,
|
|
619
|
-
tickLength
|
|
620
|
-
};
|
|
621
|
-
};
|
|
622
|
-
var useChartMargin = (height, options, data, theme, horizontal = false) => {
|
|
623
|
-
const yTicks = useMemo5(() => {
|
|
624
|
-
const allDataPoints = data.flatMap((series) => series.data);
|
|
625
|
-
if (horizontal) {
|
|
626
|
-
return allDataPoints.map((d) => d.label || options.axis?.y?.tickFormat(d.date.getTime(), 0, []));
|
|
627
|
-
}
|
|
628
|
-
const minY = Math.min(...allDataPoints.map((d) => d.value));
|
|
629
|
-
const maxY = Math.max(...allDataPoints.map((d) => d.value));
|
|
630
|
-
const yScale = createScale({
|
|
631
|
-
...options.yScale,
|
|
632
|
-
domain: [minY, maxY],
|
|
633
|
-
range: [height, 0]
|
|
634
|
-
});
|
|
635
|
-
return getTicks(yScale, options.axis?.y?.numTicks);
|
|
636
|
-
}, [options, data, height, horizontal]);
|
|
637
|
-
return useMemo5(() => {
|
|
638
|
-
const defaultMargin = {
|
|
639
|
-
top: DEFAULT_MARGIN_TOP,
|
|
640
|
-
right: DEFAULT_MARGIN_RIGHT,
|
|
641
|
-
bottom: DEFAULT_MARGIN_BOTTOM,
|
|
642
|
-
left: DEFAULT_MARGIN_LEFT
|
|
643
|
-
};
|
|
644
|
-
const yAxisOrientation = options.axis?.y?.orientation;
|
|
645
|
-
const yAxisStyles = yAxisOrientation === "right" ? theme.axisStyles.y.right : theme.axisStyles.y.left;
|
|
646
|
-
const yTickWidth = getLongestTickWidth(yTicks, options.axis?.y?.tickFormat, yAxisStyles.axisLabel);
|
|
647
|
-
const yMarginValue = (yTickWidth ?? DEFAULT_Y_TICK_WIDTH) + (yAxisStyles?.tickLength ?? 0);
|
|
648
|
-
if (yAxisOrientation === "right") {
|
|
649
|
-
defaultMargin.right = yMarginValue;
|
|
650
|
-
} else {
|
|
651
|
-
defaultMargin.left = yMarginValue;
|
|
652
|
-
}
|
|
653
|
-
const xOrientation = options.axis?.x?.orientation === "top" ? "top" : "bottom";
|
|
654
|
-
const {
|
|
655
|
-
fontSize,
|
|
656
|
-
tickLength
|
|
657
|
-
} = getXAxisLabelMetrics(theme, xOrientation);
|
|
658
|
-
const computedXMargin = fontSize + tickLength;
|
|
659
|
-
if (xOrientation === "top") {
|
|
660
|
-
defaultMargin.top = Math.max(defaultMargin.top, computedXMargin);
|
|
661
|
-
defaultMargin.bottom = DEFAULT_BOTTOM_FOR_TOP_AXIS;
|
|
662
|
-
} else {
|
|
663
|
-
defaultMargin.bottom = Math.max(defaultMargin.bottom, computedXMargin);
|
|
664
|
-
}
|
|
665
|
-
return defaultMargin;
|
|
666
|
-
}, [options, theme, yTicks]);
|
|
667
|
-
};
|
|
668
|
-
|
|
669
|
-
// src/hooks/use-element-size.ts
|
|
670
|
-
import { useState as useState2, useCallback as useCallback3, useRef as useRef3 } from "react";
|
|
671
|
-
function useElementSize({
|
|
672
|
-
initialWidth = 0,
|
|
673
|
-
initialHeight = 0
|
|
674
|
-
} = {}) {
|
|
675
|
-
const [width, setWidth] = useState2(initialWidth);
|
|
676
|
-
const [height, setHeight] = useState2(initialHeight);
|
|
677
|
-
const observerRef = useRef3(null);
|
|
678
|
-
const refCallback = useCallback3((node) => {
|
|
679
|
-
if (observerRef.current) {
|
|
680
|
-
observerRef.current.disconnect();
|
|
681
|
-
observerRef.current = null;
|
|
682
|
-
}
|
|
683
|
-
if (node) {
|
|
684
|
-
const handleResize = () => {
|
|
685
|
-
const rect = node.getBoundingClientRect();
|
|
686
|
-
setWidth(rect.width || 0);
|
|
687
|
-
setHeight(rect.height || 0);
|
|
688
|
-
};
|
|
689
|
-
handleResize();
|
|
690
|
-
const resizeObserver = new ResizeObserver(handleResize);
|
|
691
|
-
resizeObserver.observe(node);
|
|
692
|
-
observerRef.current = resizeObserver;
|
|
693
|
-
}
|
|
694
|
-
}, []);
|
|
695
|
-
return [refCallback, width, height];
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
// src/hooks/use-has-legend-child.ts
|
|
699
|
-
import { Children, isValidElement, useMemo as useMemo8 } from "react";
|
|
700
|
-
|
|
701
|
-
// src/components/legend/legend.tsx
|
|
702
|
-
import { useContext as useContext5, useMemo as useMemo6, forwardRef as forwardRef2 } from "react";
|
|
703
|
-
|
|
704
|
-
// src/charts/private/single-chart-context/single-chart-context.tsx
|
|
705
|
-
import { createContext as createContext2 } from "react";
|
|
706
|
-
var ChartInstanceContext = /* @__PURE__ */ createContext2(null);
|
|
707
|
-
var SingleChartContext = ChartInstanceContext;
|
|
708
|
-
|
|
709
|
-
// src/charts/private/single-chart-context/use-single-chart-context.ts
|
|
710
|
-
import { useContext as useContext3 } from "react";
|
|
711
|
-
var useChartInstanceContext = () => {
|
|
712
|
-
const context = useContext3(ChartInstanceContext);
|
|
713
|
-
if (!context) {
|
|
714
|
-
throw new Error("useChartInstanceContext must be used within a Chart component");
|
|
715
|
-
}
|
|
716
|
-
return context;
|
|
717
|
-
};
|
|
718
|
-
var useSingleChartContext = useChartInstanceContext;
|
|
719
|
-
|
|
720
|
-
// src/components/legend/private/base-legend.tsx
|
|
721
|
-
import { Group } from "@visx/group";
|
|
722
|
-
import { LegendItem, LegendLabel, LegendOrdinal, LegendShape } from "@visx/legend";
|
|
723
|
-
import { scaleOrdinal } from "@visx/scale";
|
|
724
|
-
import clsx from "clsx";
|
|
725
|
-
import { forwardRef, useCallback as useCallback4, useContext as useContext4 } from "react";
|
|
726
|
-
|
|
727
|
-
// src/components/legend/utils/value-or-identity.ts
|
|
728
|
-
function valueOrIdentity(_) {
|
|
729
|
-
if (_ && typeof _ === "object" && "value" in _ && typeof _.value !== "undefined")
|
|
730
|
-
return _.value;
|
|
731
|
-
return _;
|
|
732
|
-
}
|
|
733
|
-
function valueOrIdentityString(_) {
|
|
734
|
-
return String(valueOrIdentity(_));
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
// src/components/legend/utils/label-transform-factory.ts
|
|
738
|
-
function labelTransformFactory({
|
|
739
|
-
scale,
|
|
740
|
-
labelFormat
|
|
741
|
-
}) {
|
|
742
|
-
return (d, i) => ({
|
|
743
|
-
datum: d,
|
|
744
|
-
index: i,
|
|
745
|
-
text: `${labelFormat(d, i)}`,
|
|
746
|
-
value: scale(d)
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
// src/components/legend/private/base-legend.module.scss
|
|
751
|
-
var base_legend_module_default = {
|
|
752
|
-
"legend--horizontal": "a8ccharts-AELBvX",
|
|
753
|
-
"legend--vertical": "a8ccharts-fX8uQe",
|
|
754
|
-
"legend--alignment-start": "a8ccharts-DEe0wg",
|
|
755
|
-
"legend--alignment-center": "a8ccharts-WBKF9I",
|
|
756
|
-
"legend--alignment-end": "a8ccharts-JfwMng",
|
|
757
|
-
"legend--position-top": "a8ccharts-8Y73Kh",
|
|
758
|
-
"legend--position-bottom": "a8ccharts-TVM-IY",
|
|
759
|
-
"legend-item": "a8ccharts-Vflwq8",
|
|
760
|
-
"legend-item--interactive": "a8ccharts-qGsavM",
|
|
761
|
-
"legend-item--inactive": "a8ccharts-ZtDY-Q",
|
|
762
|
-
"legend-item-label": "a8ccharts-2H65Kr",
|
|
763
|
-
"legend-item-text--wrap": "a8ccharts-faSDBI",
|
|
764
|
-
"legend-item-text--ellipsis": "a8ccharts-FISUIO",
|
|
765
|
-
"legend-item-value": "a8ccharts-DTZlT-"
|
|
766
|
-
};
|
|
767
|
-
|
|
768
|
-
// src/components/legend/private/base-legend.tsx
|
|
769
|
-
import { jsx as _jsx2, jsxs as _jsxs } from "react/jsx-runtime";
|
|
770
|
-
var orientationToFlexDirection = {
|
|
771
|
-
horizontal: "row",
|
|
772
|
-
vertical: "column"
|
|
773
|
-
};
|
|
774
|
-
var LegendText = ({
|
|
775
|
-
text,
|
|
776
|
-
textOverflow,
|
|
777
|
-
maxWidth
|
|
778
|
-
}) => {
|
|
779
|
-
const isEllipsis = maxWidth != null && textOverflow === "ellipsis";
|
|
780
|
-
const [textRef, isTruncated] = useTextTruncation(Boolean(isEllipsis));
|
|
781
|
-
return /* @__PURE__ */ _jsx2("span", {
|
|
782
|
-
ref: textRef,
|
|
783
|
-
className: clsx(base_legend_module_default["legend-item-text"], maxWidth != null && base_legend_module_default[`legend-item-text--${textOverflow}`]),
|
|
784
|
-
style: {
|
|
785
|
-
...maxWidth != null && {
|
|
786
|
-
maxWidth,
|
|
787
|
-
minWidth: 0
|
|
788
|
-
}
|
|
789
|
-
},
|
|
790
|
-
title: isEllipsis && isTruncated ? text : void 0,
|
|
791
|
-
children: text
|
|
792
|
-
});
|
|
793
|
-
};
|
|
794
|
-
var BaseLegend = /* @__PURE__ */ forwardRef(({
|
|
795
|
-
items,
|
|
796
|
-
className,
|
|
797
|
-
orientation = "horizontal",
|
|
798
|
-
position = "bottom",
|
|
799
|
-
alignment = "center",
|
|
800
|
-
shape = "rect",
|
|
801
|
-
fill = valueOrIdentityString,
|
|
802
|
-
size = valueOrIdentityString,
|
|
803
|
-
labelFormat = valueOrIdentity,
|
|
804
|
-
labelTransform = labelTransformFactory,
|
|
805
|
-
itemStyles,
|
|
806
|
-
itemClassName,
|
|
807
|
-
labelStyles,
|
|
808
|
-
labelClassName,
|
|
809
|
-
shapeStyles,
|
|
810
|
-
render,
|
|
811
|
-
interactive = false,
|
|
812
|
-
chartId
|
|
813
|
-
}, ref) => {
|
|
814
|
-
const {
|
|
815
|
-
margin: itemMargin = "0",
|
|
816
|
-
flexDirection: itemDirection = "row"
|
|
817
|
-
} = itemStyles ?? {};
|
|
818
|
-
const {
|
|
819
|
-
justifyContent: labelJustifyContent = "flex-start",
|
|
820
|
-
flex: labelFlex = "0 0 auto",
|
|
821
|
-
margin: labelMargin = "0 4px",
|
|
822
|
-
maxWidth,
|
|
823
|
-
textOverflow = "wrap"
|
|
824
|
-
} = labelStyles ?? {};
|
|
825
|
-
const {
|
|
826
|
-
width: shapeWidth = 16,
|
|
827
|
-
height: shapeHeight = 16,
|
|
828
|
-
margin: shapeMargin = "2px 4px 2px 0"
|
|
829
|
-
} = shapeStyles ?? {};
|
|
830
|
-
const theme = useGlobalChartsTheme();
|
|
831
|
-
const context = useContext4(GlobalChartsContext);
|
|
832
|
-
const legendScale = scaleOrdinal({
|
|
833
|
-
domain: items.map((item) => item.label),
|
|
834
|
-
range: items.map((item) => item.color)
|
|
835
|
-
});
|
|
836
|
-
const domain = legendScale.domain();
|
|
837
|
-
const getShapeStyle = useCallback4(({
|
|
838
|
-
index
|
|
839
|
-
}) => items[index]?.shapeStyle, [items]);
|
|
840
|
-
const handleLegendClick = useCallback4((seriesLabel) => {
|
|
841
|
-
if (interactive && chartId && context) {
|
|
842
|
-
context.toggleSeriesVisibility(chartId, seriesLabel);
|
|
843
|
-
}
|
|
844
|
-
}, [interactive, chartId, context]);
|
|
845
|
-
const isSeriesVisible = useCallback4((seriesLabel) => {
|
|
846
|
-
if (!interactive || !chartId || !context) {
|
|
847
|
-
return true;
|
|
848
|
-
}
|
|
849
|
-
return context.isSeriesVisible(chartId, seriesLabel);
|
|
850
|
-
}, [interactive, chartId, context]);
|
|
851
|
-
const createClickHandler = useCallback4((labelText) => {
|
|
852
|
-
if (!interactive) {
|
|
853
|
-
return void 0;
|
|
854
|
-
}
|
|
855
|
-
return () => handleLegendClick(labelText);
|
|
856
|
-
}, [interactive, handleLegendClick]);
|
|
857
|
-
const createKeyDownHandler = useCallback4((labelText) => {
|
|
858
|
-
if (!interactive) {
|
|
859
|
-
return void 0;
|
|
860
|
-
}
|
|
861
|
-
return (event) => {
|
|
862
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
863
|
-
event.preventDefault();
|
|
864
|
-
handleLegendClick(labelText);
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
}, [interactive, handleLegendClick]);
|
|
868
|
-
return render ? render(items) : /* @__PURE__ */ _jsx2(LegendOrdinal, {
|
|
869
|
-
scale: legendScale,
|
|
870
|
-
labelFormat,
|
|
871
|
-
labelTransform,
|
|
872
|
-
children: (labels) => /* @__PURE__ */ _jsx2("div", {
|
|
873
|
-
ref,
|
|
874
|
-
role: "list",
|
|
875
|
-
className: clsx(base_legend_module_default.legend, base_legend_module_default[`legend--${orientation}`], base_legend_module_default[`legend--alignment-${alignment}`], base_legend_module_default[`legend--position-${position}`], className),
|
|
876
|
-
style: {
|
|
877
|
-
flexDirection: orientationToFlexDirection[orientation],
|
|
878
|
-
...theme.legend?.containerStyles
|
|
879
|
-
},
|
|
880
|
-
children: labels.map((label, i) => {
|
|
881
|
-
const visible = isSeriesVisible(label.text);
|
|
882
|
-
const handleClick = createClickHandler(label.text);
|
|
883
|
-
const handleKeyDown = createKeyDownHandler(label.text);
|
|
884
|
-
const matchedItem = items[i];
|
|
885
|
-
return /* @__PURE__ */ _jsxs(LegendItem, {
|
|
886
|
-
className: clsx("visx-legend-item", base_legend_module_default["legend-item"], interactive && base_legend_module_default["legend-item--interactive"], !visible && base_legend_module_default["legend-item--inactive"], itemClassName),
|
|
887
|
-
margin: itemMargin,
|
|
888
|
-
flexDirection: orientation === "vertical" && alignment === "end" ? "row-reverse" : itemDirection,
|
|
889
|
-
onClick: handleClick,
|
|
890
|
-
onKeyDown: handleKeyDown,
|
|
891
|
-
role: interactive ? "button" : void 0,
|
|
892
|
-
tabIndex: interactive ? 0 : void 0,
|
|
893
|
-
"aria-pressed": interactive ? visible : void 0,
|
|
894
|
-
"aria-label": interactive ? `${label.text}: ${visible ? "visible" : "hidden"}. Toggle visibility.` : void 0,
|
|
895
|
-
children: [items[i]?.renderGlyph ? /* @__PURE__ */ _jsx2("svg", {
|
|
896
|
-
width: items[i]?.glyphSize * 2,
|
|
897
|
-
height: items[i]?.glyphSize * 2,
|
|
898
|
-
children: /* @__PURE__ */ _jsx2(Group, {
|
|
899
|
-
children: items[i]?.renderGlyph({
|
|
900
|
-
key: `legend-glyph-${label.text}`,
|
|
901
|
-
datum: {},
|
|
902
|
-
index: i,
|
|
903
|
-
color: fill(label),
|
|
904
|
-
size: items[i]?.glyphSize,
|
|
905
|
-
x: items[i]?.glyphSize,
|
|
906
|
-
y: items[i]?.glyphSize
|
|
907
|
-
})
|
|
908
|
-
})
|
|
909
|
-
}) : /* @__PURE__ */ _jsx2(LegendShape, {
|
|
910
|
-
shape,
|
|
911
|
-
height: shapeHeight,
|
|
912
|
-
width: shapeWidth,
|
|
913
|
-
margin: shapeMargin,
|
|
914
|
-
item: domain[i],
|
|
915
|
-
itemIndex: i,
|
|
916
|
-
label,
|
|
917
|
-
fill,
|
|
918
|
-
size,
|
|
919
|
-
shapeStyle: getShapeStyle
|
|
920
|
-
}), /* @__PURE__ */ _jsxs(LegendLabel, {
|
|
921
|
-
className: clsx("visx-legend-label", base_legend_module_default["legend-item-label"], labelClassName),
|
|
922
|
-
style: {
|
|
923
|
-
justifyContent: labelJustifyContent,
|
|
924
|
-
flex: labelFlex,
|
|
925
|
-
margin: labelMargin,
|
|
926
|
-
...theme.legend?.labelStyles
|
|
927
|
-
},
|
|
928
|
-
children: [/* @__PURE__ */ _jsx2(LegendText, {
|
|
929
|
-
text: label.text,
|
|
930
|
-
textOverflow,
|
|
931
|
-
maxWidth
|
|
932
|
-
}), matchedItem?.value != null && matchedItem.value !== "" && /* @__PURE__ */ _jsxs("span", {
|
|
933
|
-
className: base_legend_module_default["legend-item-value"],
|
|
934
|
-
children: ["\xA0", matchedItem.value]
|
|
935
|
-
})]
|
|
936
|
-
})]
|
|
937
|
-
}, `legend-${label.text}-${i}`);
|
|
938
|
-
})
|
|
939
|
-
})
|
|
940
|
-
});
|
|
941
|
-
});
|
|
942
|
-
|
|
943
|
-
// src/components/legend/legend.tsx
|
|
944
|
-
import { jsx as _jsx3 } from "react/jsx-runtime";
|
|
945
|
-
var Legend = /* @__PURE__ */ forwardRef2(({
|
|
946
|
-
chartId,
|
|
947
|
-
items,
|
|
948
|
-
...props
|
|
949
|
-
}, ref) => {
|
|
950
|
-
const context = useContext5(GlobalChartsContext);
|
|
951
|
-
const singleChartContext = useContext5(SingleChartContext);
|
|
952
|
-
const contextChartId = chartId ?? singleChartContext?.chartId;
|
|
953
|
-
const contextItems = useMemo6(() => {
|
|
954
|
-
return contextChartId && context ? context.getChartData(contextChartId)?.legendItems : void 0;
|
|
955
|
-
}, [contextChartId, context]);
|
|
956
|
-
const legendItems = items || contextItems;
|
|
957
|
-
if (!legendItems) {
|
|
958
|
-
return null;
|
|
959
|
-
}
|
|
960
|
-
return /* @__PURE__ */ _jsx3(BaseLegend, {
|
|
961
|
-
ref,
|
|
962
|
-
items: legendItems,
|
|
963
|
-
...props,
|
|
964
|
-
chartId: contextChartId
|
|
965
|
-
});
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
// src/components/legend/hooks/use-chart-legend-items.ts
|
|
969
|
-
import { formatNumber } from "@automattic/number-formatters";
|
|
970
|
-
import { useMemo as useMemo7 } from "react";
|
|
971
|
-
function formatPointValue(point, showValues, legendValueDisplay = "percentage") {
|
|
972
|
-
if (!showValues || legendValueDisplay === "none") {
|
|
973
|
-
return "";
|
|
974
|
-
}
|
|
975
|
-
if ("percentage" in point) {
|
|
976
|
-
const percentagePoint = point;
|
|
977
|
-
switch (legendValueDisplay) {
|
|
978
|
-
case "percentage":
|
|
979
|
-
return formatPercentage(percentagePoint.percentage);
|
|
980
|
-
case "value":
|
|
981
|
-
return formatNumber(percentagePoint.value);
|
|
982
|
-
case "valueDisplay":
|
|
983
|
-
return percentagePoint.valueDisplay || formatNumber(percentagePoint.value);
|
|
984
|
-
default:
|
|
985
|
-
return "";
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
if ("value" in point) {
|
|
989
|
-
return point.value !== null ? formatNumber(point.value) : "";
|
|
990
|
-
}
|
|
991
|
-
return "";
|
|
992
|
-
}
|
|
993
|
-
function applyGlyphToLegendItem(baseItem, withGlyph, glyph, renderGlyph, glyphSize) {
|
|
994
|
-
if (withGlyph) {
|
|
995
|
-
const glyphToUse = glyph || renderGlyph;
|
|
996
|
-
if (glyphToUse) {
|
|
997
|
-
return {
|
|
998
|
-
...baseItem,
|
|
999
|
-
glyphSize,
|
|
1000
|
-
renderGlyph: glyphToUse
|
|
1001
|
-
};
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
return baseItem;
|
|
1005
|
-
}
|
|
1006
|
-
function processSeriesData(seriesData, getElementStyles, showValues, withGlyph, glyphSize, renderGlyph, legendShape) {
|
|
1007
|
-
const mapper = (series, index) => {
|
|
1008
|
-
const { color, glyph, shapeStyles } = getElementStyles({
|
|
1009
|
-
data: series,
|
|
1010
|
-
index,
|
|
1011
|
-
legendShape
|
|
1012
|
-
});
|
|
1013
|
-
const baseItem = {
|
|
1014
|
-
label: series.label,
|
|
1015
|
-
value: showValues ? series.data?.length?.toString() || "0" : "",
|
|
1016
|
-
color,
|
|
1017
|
-
shapeStyle: shapeStyles
|
|
1018
|
-
};
|
|
1019
|
-
return applyGlyphToLegendItem(baseItem, withGlyph, glyph, renderGlyph, glyphSize);
|
|
1020
|
-
};
|
|
1021
|
-
return seriesData.map(mapper);
|
|
1022
|
-
}
|
|
1023
|
-
function processPointData(pointData, getElementStyles, showValues, legendValueDisplay, withGlyph, glyphSize, renderGlyph, legendShape) {
|
|
1024
|
-
const mapper = (point, index) => {
|
|
1025
|
-
const { color, glyph, shapeStyles } = getElementStyles({
|
|
1026
|
-
data: point,
|
|
1027
|
-
index,
|
|
1028
|
-
legendShape
|
|
1029
|
-
});
|
|
1030
|
-
const baseItem = {
|
|
1031
|
-
label: point.label,
|
|
1032
|
-
value: formatPointValue(point, showValues, legendValueDisplay),
|
|
1033
|
-
color,
|
|
1034
|
-
shapeStyle: shapeStyles
|
|
1035
|
-
};
|
|
1036
|
-
return applyGlyphToLegendItem(baseItem, withGlyph, glyph, renderGlyph, glyphSize);
|
|
1037
|
-
};
|
|
1038
|
-
return pointData.map(mapper);
|
|
1039
|
-
}
|
|
1040
|
-
function useChartLegendItems(data, options = {}, legendShape) {
|
|
1041
|
-
const {
|
|
1042
|
-
showValues = false,
|
|
1043
|
-
legendValueDisplay = "percentage",
|
|
1044
|
-
withGlyph = false,
|
|
1045
|
-
glyphSize = 8,
|
|
1046
|
-
renderGlyph
|
|
1047
|
-
} = options;
|
|
1048
|
-
const { getElementStyles } = useGlobalChartsContext();
|
|
1049
|
-
return useMemo7(() => {
|
|
1050
|
-
if (!data || !Array.isArray(data) || data.length === 0) {
|
|
1051
|
-
return [];
|
|
1052
|
-
}
|
|
1053
|
-
if ("data" in data[0]) {
|
|
1054
|
-
return processSeriesData(
|
|
1055
|
-
data,
|
|
1056
|
-
getElementStyles,
|
|
1057
|
-
showValues,
|
|
1058
|
-
withGlyph,
|
|
1059
|
-
glyphSize,
|
|
1060
|
-
renderGlyph,
|
|
1061
|
-
legendShape
|
|
1062
|
-
);
|
|
1063
|
-
}
|
|
1064
|
-
return processPointData(
|
|
1065
|
-
data,
|
|
1066
|
-
getElementStyles,
|
|
1067
|
-
showValues,
|
|
1068
|
-
legendValueDisplay,
|
|
1069
|
-
withGlyph,
|
|
1070
|
-
glyphSize,
|
|
1071
|
-
renderGlyph,
|
|
1072
|
-
legendShape
|
|
1073
|
-
);
|
|
1074
|
-
}, [
|
|
1075
|
-
data,
|
|
1076
|
-
getElementStyles,
|
|
1077
|
-
showValues,
|
|
1078
|
-
legendValueDisplay,
|
|
1079
|
-
withGlyph,
|
|
1080
|
-
glyphSize,
|
|
1081
|
-
renderGlyph,
|
|
1082
|
-
legendShape
|
|
1083
|
-
]);
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
// src/hooks/use-has-legend-child.ts
|
|
1087
|
-
function useHasLegendChild(children) {
|
|
1088
|
-
return useMemo8(() => {
|
|
1089
|
-
let found = false;
|
|
1090
|
-
Children.forEach(children, (child) => {
|
|
1091
|
-
if (isValidElement(child) && child.type === Legend) {
|
|
1092
|
-
found = true;
|
|
1093
|
-
}
|
|
1094
|
-
});
|
|
1095
|
-
return found;
|
|
1096
|
-
}, [children]);
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
// src/hooks/use-text-truncation.ts
|
|
1100
|
-
import { useCallback as useCallback5, useRef as useRef4, useState as useState3 } from "react";
|
|
1101
|
-
function useTextTruncation(enabled = true) {
|
|
1102
|
-
const [isTruncated, setIsTruncated] = useState3(false);
|
|
1103
|
-
const observerRef = useRef4(null);
|
|
1104
|
-
const refCallback = useCallback5(
|
|
1105
|
-
(node) => {
|
|
1106
|
-
if (observerRef.current) {
|
|
1107
|
-
observerRef.current.disconnect();
|
|
1108
|
-
observerRef.current = null;
|
|
1109
|
-
}
|
|
1110
|
-
if (node && enabled) {
|
|
1111
|
-
const checkTruncation = () => {
|
|
1112
|
-
const truncated = node.scrollWidth > node.clientWidth;
|
|
1113
|
-
setIsTruncated(truncated);
|
|
1114
|
-
};
|
|
1115
|
-
checkTruncation();
|
|
1116
|
-
const resizeObserver = new ResizeObserver(checkTruncation);
|
|
1117
|
-
resizeObserver.observe(node);
|
|
1118
|
-
observerRef.current = resizeObserver;
|
|
1119
|
-
} else {
|
|
1120
|
-
setIsTruncated(false);
|
|
1121
|
-
}
|
|
1122
|
-
},
|
|
1123
|
-
[enabled]
|
|
1124
|
-
);
|
|
1125
|
-
return [refCallback, isTruncated];
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
// src/hooks/use-zero-value-display.ts
|
|
1129
|
-
import { useMemo as useMemo9 } from "react";
|
|
1130
|
-
var MIN_PIXEL_SIZE = 3;
|
|
1131
|
-
var ZERO_PIXEL_SIZE = MIN_PIXEL_SIZE - 1;
|
|
1132
|
-
var useZeroValueDisplay = (data, options = { enabled: false }) => {
|
|
1133
|
-
const { enabled, valueAxisLength } = options;
|
|
1134
|
-
return useMemo9(() => {
|
|
1135
|
-
if (!enabled || !valueAxisLength || valueAxisLength <= 0) return data;
|
|
1136
|
-
let maxAbsoluteValue = 0;
|
|
1137
|
-
for (const series of data) {
|
|
1138
|
-
for (const point of series.data) {
|
|
1139
|
-
if (point.value !== null && point.value !== 0) {
|
|
1140
|
-
maxAbsoluteValue = Math.max(maxAbsoluteValue, Math.abs(point.value));
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
if (maxAbsoluteValue === 0) return data;
|
|
1145
|
-
const minNonZeroValue = Math.min(
|
|
1146
|
-
MIN_PIXEL_SIZE / valueAxisLength * maxAbsoluteValue,
|
|
1147
|
-
maxAbsoluteValue
|
|
1148
|
-
);
|
|
1149
|
-
const zeroVisualValue = Math.min(
|
|
1150
|
-
ZERO_PIXEL_SIZE / valueAxisLength * maxAbsoluteValue,
|
|
1151
|
-
maxAbsoluteValue
|
|
1152
|
-
);
|
|
1153
|
-
return data.map((series) => ({
|
|
1154
|
-
...series,
|
|
1155
|
-
data: series.data.map((point) => {
|
|
1156
|
-
if (point.value === 0) {
|
|
1157
|
-
return {
|
|
1158
|
-
...point,
|
|
1159
|
-
visualValue: zeroVisualValue
|
|
1160
|
-
};
|
|
1161
|
-
}
|
|
1162
|
-
if (point.value === null) {
|
|
1163
|
-
return point;
|
|
1164
|
-
}
|
|
1165
|
-
const absValue = Math.abs(point.value);
|
|
1166
|
-
if (absValue < minNonZeroValue) {
|
|
1167
|
-
return {
|
|
1168
|
-
...point,
|
|
1169
|
-
visualValue: Math.sign(point.value) * minNonZeroValue
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
return point;
|
|
1173
|
-
})
|
|
1174
|
-
}));
|
|
1175
|
-
}, [data, enabled, valueAxisLength]);
|
|
1176
|
-
};
|
|
1177
|
-
|
|
1178
|
-
// src/hooks/use-interactive-legend-data.ts
|
|
1179
|
-
import { useMemo as useMemo10 } from "react";
|
|
1180
|
-
var useInteractiveLegendData = ({
|
|
1181
|
-
data,
|
|
1182
|
-
chartId,
|
|
1183
|
-
legendInteractive,
|
|
1184
|
-
isSeriesVisible
|
|
1185
|
-
}) => {
|
|
1186
|
-
const visibleData = useMemo10(() => {
|
|
1187
|
-
if (!chartId || !legendInteractive) {
|
|
1188
|
-
return data;
|
|
1189
|
-
}
|
|
1190
|
-
const filtered = data.filter((segment) => isSeriesVisible(chartId, segment.label));
|
|
1191
|
-
if (filtered.length === 0) {
|
|
1192
|
-
return [];
|
|
1193
|
-
}
|
|
1194
|
-
const totalValue = filtered.reduce((sum, segment) => sum + segment.value, 0);
|
|
1195
|
-
return filtered.map((segment) => ({
|
|
1196
|
-
...segment,
|
|
1197
|
-
percentage: totalValue > 0 ? segment.value / totalValue * 100 : 0
|
|
1198
|
-
}));
|
|
1199
|
-
}, [data, chartId, isSeriesVisible, legendInteractive]);
|
|
1200
|
-
const allSegmentsHidden = useMemo10(() => {
|
|
1201
|
-
return legendInteractive && visibleData.length === 0;
|
|
1202
|
-
}, [legendInteractive, visibleData]);
|
|
1203
|
-
const legendData = useMemo10(() => {
|
|
1204
|
-
if (!legendInteractive || !chartId) {
|
|
1205
|
-
return data;
|
|
1206
|
-
}
|
|
1207
|
-
return data.map((segment) => {
|
|
1208
|
-
const isVisible = isSeriesVisible(chartId, segment.label);
|
|
1209
|
-
if (!isVisible) {
|
|
1210
|
-
return segment;
|
|
1211
|
-
}
|
|
1212
|
-
const recalculated = visibleData.find((d) => d.label === segment.label);
|
|
1213
|
-
return recalculated || segment;
|
|
1214
|
-
});
|
|
1215
|
-
}, [data, visibleData, legendInteractive, chartId, isSeriesVisible]);
|
|
1216
|
-
return { visibleData, allSegmentsHidden, legendData };
|
|
1217
|
-
};
|
|
1218
|
-
|
|
1219
|
-
// src/hooks/use-prefers-reduced-motion.ts
|
|
1220
|
-
import { useState as useState4, useEffect as useEffect4 } from "react";
|
|
1221
|
-
var QUERY = "(prefers-reduced-motion: no-preference)";
|
|
1222
|
-
var getInitialState = () => !window.matchMedia(QUERY).matches;
|
|
1223
|
-
function usePrefersReducedMotion() {
|
|
1224
|
-
const [prefersReducedMotion, setPrefersReducedMotion] = useState4(getInitialState);
|
|
1225
|
-
useEffect4(() => {
|
|
1226
|
-
const mediaQueryList = window.matchMedia(QUERY);
|
|
1227
|
-
const listener = (event) => {
|
|
1228
|
-
setPrefersReducedMotion(!event.matches);
|
|
1229
|
-
};
|
|
1230
|
-
mediaQueryList.addEventListener("change", listener);
|
|
1231
|
-
return () => {
|
|
1232
|
-
mediaQueryList.removeEventListener("change", listener);
|
|
1233
|
-
};
|
|
1234
|
-
}, []);
|
|
1235
|
-
return prefersReducedMotion;
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
export {
|
|
1239
|
-
SingleChartContext,
|
|
1240
|
-
useSingleChartContext,
|
|
1241
|
-
useTooltipPortalRelocator,
|
|
1242
|
-
defaultTheme,
|
|
1243
|
-
GlobalChartsContext,
|
|
1244
|
-
GlobalChartsProvider,
|
|
1245
|
-
useGlobalChartsContext,
|
|
1246
|
-
useChartId,
|
|
1247
|
-
useDeepMemo,
|
|
1248
|
-
useChartMouseHandler,
|
|
1249
|
-
useXYChartTheme,
|
|
1250
|
-
useChartDataTransform,
|
|
1251
|
-
useChartMargin,
|
|
1252
|
-
useElementSize,
|
|
1253
|
-
useHasLegendChild,
|
|
1254
|
-
useTextTruncation,
|
|
1255
|
-
useZeroValueDisplay,
|
|
1256
|
-
useInteractiveLegendData,
|
|
1257
|
-
usePrefersReducedMotion,
|
|
1258
|
-
useChartRegistration,
|
|
1259
|
-
useGlobalChartsTheme,
|
|
1260
|
-
Legend,
|
|
1261
|
-
useChartLegendItems
|
|
1262
|
-
};
|
|
1263
|
-
//# sourceMappingURL=chunk-32DH6JDF.js.map
|