@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
|
@@ -72,13 +72,96 @@ var _xychart = require('@visx/xychart');
|
|
|
72
72
|
var _d3color = require('@visx/vendor/d3-color');
|
|
73
73
|
|
|
74
74
|
|
|
75
|
+
// src/hooks/use-tooltip-portal-relocator.ts
|
|
75
76
|
|
|
76
77
|
|
|
78
|
+
// src/hooks/use-tooltip-portal-relocator.module.scss
|
|
79
|
+
var use_tooltip_portal_relocator_module_default = {
|
|
80
|
+
"relocatedPortal": "a8ccharts-jCw5dQ"
|
|
81
|
+
};
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
_optionalChain([child, 'access', _2 => _2.parentNode, 'optionalAccess', _3 => _3.removeChild, 'call', _4 => _4(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
|
+
_react.useEffect.call(void 0, () => {
|
|
118
|
+
const container = _optionalChain([containerRef, 'optionalAccess', _5 => _5.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.classList.add(use_tooltip_portal_relocator_module_default.relocatedPortal);
|
|
128
|
+
const { activeElement } = node.ownerDocument;
|
|
129
|
+
const focusedElement = activeElement instanceof HTMLElement && node.contains(activeElement) ? activeElement : null;
|
|
130
|
+
container.insertBefore(node, container.firstChild);
|
|
131
|
+
relocatedNodes.add(node);
|
|
132
|
+
instanceNodes.add(node);
|
|
133
|
+
if (focusedElement) {
|
|
134
|
+
focusedElement.focus();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
installRemoveChildPatch();
|
|
138
|
+
for (const child of Array.from(document.body.children)) {
|
|
139
|
+
relocateNode(child);
|
|
140
|
+
}
|
|
141
|
+
const observer = new MutationObserver((mutations) => {
|
|
142
|
+
for (const mutation of mutations) {
|
|
143
|
+
for (const node of mutation.addedNodes) {
|
|
144
|
+
relocateNode(node);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
observer.observe(document.body, { childList: true });
|
|
149
|
+
return () => {
|
|
150
|
+
observer.disconnect();
|
|
151
|
+
for (const node of instanceNodes) {
|
|
152
|
+
if (node instanceof HTMLElement) {
|
|
153
|
+
node.classList.remove(use_tooltip_portal_relocator_module_default.relocatedPortal);
|
|
154
|
+
}
|
|
155
|
+
if (node.parentNode === container) {
|
|
156
|
+
document.body.appendChild(node);
|
|
157
|
+
}
|
|
158
|
+
relocatedNodes.delete(node);
|
|
159
|
+
}
|
|
160
|
+
instanceNodes.clear();
|
|
161
|
+
uninstallRemoveChildPatch();
|
|
162
|
+
};
|
|
163
|
+
}, [containerRef]);
|
|
164
|
+
}
|
|
82
165
|
|
|
83
166
|
// src/providers/chart-context/private/get-chart-color.ts
|
|
84
167
|
|
|
@@ -230,13 +313,16 @@ var defaultTheme = {
|
|
|
230
313
|
|
|
231
314
|
// src/providers/chart-context/global-charts-provider.tsx
|
|
232
315
|
var _jsxruntime = require('react/jsx-runtime');
|
|
233
|
-
var GlobalChartsContext = _react.createContext.call(void 0, null);
|
|
234
|
-
var GlobalChartsProvider = ({
|
|
316
|
+
var GlobalChartsContext = /* @__PURE__ */ _react.createContext.call(void 0, null);
|
|
317
|
+
var GlobalChartsProvider = ({
|
|
318
|
+
children,
|
|
319
|
+
theme,
|
|
320
|
+
portalContainer
|
|
321
|
+
}) => {
|
|
235
322
|
const [charts, setCharts] = _react.useState.call(void 0, () => /* @__PURE__ */ new Map());
|
|
236
|
-
const [hiddenSeries, setHiddenSeries] = _react.useState.call(void 0,
|
|
237
|
-
() => /* @__PURE__ */ new Map()
|
|
238
|
-
);
|
|
323
|
+
const [hiddenSeries, setHiddenSeries] = _react.useState.call(void 0, () => /* @__PURE__ */ new Map());
|
|
239
324
|
const wrapperRef = _react.useRef.call(void 0, null);
|
|
325
|
+
useTooltipPortalRelocator(_nullishCoalesce(portalContainer, () => ( wrapperRef)));
|
|
240
326
|
const providerTheme = _react.useMemo.call(void 0, () => {
|
|
241
327
|
return theme ? _chunkZVGEDXDPcjs.mergeThemes.call(void 0, defaultTheme, theme) : defaultTheme;
|
|
242
328
|
}, [theme]);
|
|
@@ -248,7 +334,9 @@ var GlobalChartsProvider = ({ children, theme }) => {
|
|
|
248
334
|
maxHue: 0
|
|
249
335
|
}));
|
|
250
336
|
_react.useLayoutEffect.call(void 0, () => {
|
|
251
|
-
const {
|
|
337
|
+
const {
|
|
338
|
+
colors
|
|
339
|
+
} = providerTheme;
|
|
252
340
|
const resolvedColors = [];
|
|
253
341
|
const hues = [];
|
|
254
342
|
const existingHslColors = [];
|
|
@@ -269,11 +357,7 @@ var GlobalChartsProvider = ({ children, theme }) => {
|
|
|
269
357
|
resolvedColors.push(colorValue);
|
|
270
358
|
const hslColor = _d3color.hsl.call(void 0, colorValue);
|
|
271
359
|
if (!isNaN(hslColor.h)) {
|
|
272
|
-
const hslTuple = [
|
|
273
|
-
hslColor.h,
|
|
274
|
-
hslColor.s * 100,
|
|
275
|
-
hslColor.l * 100
|
|
276
|
-
];
|
|
360
|
+
const hslTuple = [hslColor.h, hslColor.s * 100, hslColor.l * 100];
|
|
277
361
|
hues.push(hslTuple[0]);
|
|
278
362
|
existingHslColors.push(hslTuple);
|
|
279
363
|
minHue = Math.min(minHue, hslTuple[0]);
|
|
@@ -291,9 +375,7 @@ var GlobalChartsProvider = ({ children, theme }) => {
|
|
|
291
375
|
maxHue
|
|
292
376
|
});
|
|
293
377
|
}, [providerTheme]);
|
|
294
|
-
const [groupToColorMap, setGroupToColorMap] = _react.useState.call(void 0,
|
|
295
|
-
() => /* @__PURE__ */ new Map()
|
|
296
|
-
);
|
|
378
|
+
const [groupToColorMap, setGroupToColorMap] = _react.useState.call(void 0, () => /* @__PURE__ */ new Map());
|
|
297
379
|
_react.useEffect.call(void 0, () => {
|
|
298
380
|
setGroupToColorMap(/* @__PURE__ */ new Map());
|
|
299
381
|
}, [providerTheme.colors]);
|
|
@@ -307,52 +389,48 @@ var GlobalChartsProvider = ({ children, theme }) => {
|
|
|
307
389
|
return newMap;
|
|
308
390
|
});
|
|
309
391
|
}, []);
|
|
310
|
-
const getChartData = _react.useCallback.call(void 0,
|
|
311
|
-
(id)
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (group) {
|
|
326
|
-
const existing = groupToColorMap.get(group);
|
|
327
|
-
if (existing) {
|
|
328
|
-
return existing;
|
|
329
|
-
}
|
|
330
|
-
const assignedCount = groupToColorMap.size;
|
|
331
|
-
const color = getChartColor(assignedCount, colorCache);
|
|
332
|
-
groupToColorMap.set(group, color);
|
|
333
|
-
return color;
|
|
392
|
+
const getChartData = _react.useCallback.call(void 0, (id) => {
|
|
393
|
+
return charts.get(id);
|
|
394
|
+
}, [charts]);
|
|
395
|
+
const resolveColor = _react.useCallback.call(void 0, ({
|
|
396
|
+
group,
|
|
397
|
+
index,
|
|
398
|
+
overrideColor
|
|
399
|
+
}) => {
|
|
400
|
+
if (overrideColor) {
|
|
401
|
+
return _chunkZVGEDXDPcjs.normalizeColorToHex.call(void 0, overrideColor, wrapperRef.current, _chunkZVGEDXDPcjs.resolveCssVariable);
|
|
402
|
+
}
|
|
403
|
+
if (group) {
|
|
404
|
+
const existing = groupToColorMap.get(group);
|
|
405
|
+
if (existing) {
|
|
406
|
+
return existing;
|
|
334
407
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
408
|
+
const assignedCount = groupToColorMap.size;
|
|
409
|
+
const color = getChartColor(assignedCount, colorCache);
|
|
410
|
+
groupToColorMap.set(group, color);
|
|
411
|
+
return color;
|
|
412
|
+
}
|
|
413
|
+
return getChartColor(index, colorCache);
|
|
414
|
+
}, [colorCache, groupToColorMap]);
|
|
415
|
+
const getElementStyles = _react.useCallback.call(void 0, ({
|
|
416
|
+
data,
|
|
417
|
+
index,
|
|
418
|
+
overrideColor,
|
|
419
|
+
legendShape
|
|
420
|
+
}) => {
|
|
421
|
+
const isSeriesData = data && typeof data === "object" && "data" in data && "options" in data;
|
|
422
|
+
const isPointPercentageData = data && typeof data === "object" && "percentage" in data;
|
|
423
|
+
return {
|
|
424
|
+
color: resolveColor({
|
|
425
|
+
group: _optionalChain([data, 'optionalAccess', _6 => _6.group]),
|
|
426
|
+
index,
|
|
427
|
+
overrideColor: overrideColor || isSeriesData && _optionalChain([data, 'optionalAccess', _7 => _7.options, 'optionalAccess', _8 => _8.stroke]) || isPointPercentageData && _optionalChain([data, 'optionalAccess', _9 => _9.color])
|
|
428
|
+
}),
|
|
429
|
+
lineStyles: isSeriesData ? _chunkZVGEDXDPcjs.getSeriesLineStyles.call(void 0, data, index, providerTheme) : {},
|
|
430
|
+
glyph: _optionalChain([providerTheme, 'access', _10 => _10.glyphs, 'optionalAccess', _11 => _11[index]]),
|
|
431
|
+
shapeStyles: isSeriesData ? _chunkZVGEDXDPcjs.getItemShapeStyles.call(void 0, data, index, providerTheme, legendShape) : {}
|
|
432
|
+
};
|
|
433
|
+
}, [providerTheme, resolveColor]);
|
|
356
434
|
const toggleSeriesVisibility = _react.useCallback.call(void 0, (chartId, seriesLabel) => {
|
|
357
435
|
setHiddenSeries((prev) => {
|
|
358
436
|
const newMap = new Map(prev);
|
|
@@ -371,45 +449,35 @@ var GlobalChartsProvider = ({ children, theme }) => {
|
|
|
371
449
|
return newMap;
|
|
372
450
|
});
|
|
373
451
|
}, []);
|
|
374
|
-
const isSeriesVisible = _react.useCallback.call(void 0,
|
|
375
|
-
(chartId
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
unregisterChart,
|
|
404
|
-
getChartData,
|
|
405
|
-
providerTheme,
|
|
406
|
-
getElementStyles,
|
|
407
|
-
toggleSeriesVisibility,
|
|
408
|
-
isSeriesVisible,
|
|
409
|
-
getHiddenSeries
|
|
410
|
-
]
|
|
411
|
-
);
|
|
412
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GlobalChartsContext.Provider, { value, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ref: wrapperRef, style: { display: "contents" }, children }) });
|
|
452
|
+
const isSeriesVisible = _react.useCallback.call(void 0, (chartId, seriesLabel) => {
|
|
453
|
+
const chartHidden = hiddenSeries.get(chartId);
|
|
454
|
+
return !chartHidden || !chartHidden.has(seriesLabel);
|
|
455
|
+
}, [hiddenSeries]);
|
|
456
|
+
const getHiddenSeries = _react.useCallback.call(void 0, (chartId) => {
|
|
457
|
+
const set = hiddenSeries.get(chartId);
|
|
458
|
+
return set ? new Set(set) : /* @__PURE__ */ new Set();
|
|
459
|
+
}, [hiddenSeries]);
|
|
460
|
+
const value = _react.useMemo.call(void 0, () => ({
|
|
461
|
+
charts,
|
|
462
|
+
registerChart,
|
|
463
|
+
unregisterChart,
|
|
464
|
+
getChartData,
|
|
465
|
+
theme: providerTheme,
|
|
466
|
+
getElementStyles,
|
|
467
|
+
toggleSeriesVisibility,
|
|
468
|
+
isSeriesVisible,
|
|
469
|
+
getHiddenSeries
|
|
470
|
+
}), [charts, registerChart, unregisterChart, getChartData, providerTheme, getElementStyles, toggleSeriesVisibility, isSeriesVisible, getHiddenSeries]);
|
|
471
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GlobalChartsContext.Provider, {
|
|
472
|
+
value,
|
|
473
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
|
|
474
|
+
ref: wrapperRef,
|
|
475
|
+
style: {
|
|
476
|
+
display: "contents"
|
|
477
|
+
},
|
|
478
|
+
children
|
|
479
|
+
})
|
|
480
|
+
});
|
|
413
481
|
};
|
|
414
482
|
|
|
415
483
|
// src/providers/chart-context/hooks/use-global-charts-context.ts
|
|
@@ -467,7 +535,7 @@ var useChartRegistration = ({
|
|
|
467
535
|
|
|
468
536
|
var useGlobalChartsTheme = () => {
|
|
469
537
|
const context = _react.useContext.call(void 0, GlobalChartsContext);
|
|
470
|
-
const globalTheme = _optionalChain([context, 'optionalAccess',
|
|
538
|
+
const globalTheme = _optionalChain([context, 'optionalAccess', _12 => _12.theme]);
|
|
471
539
|
return _nullishCoalesce(globalTheme, () => ( defaultTheme));
|
|
472
540
|
};
|
|
473
541
|
|
|
@@ -475,7 +543,7 @@ var useGlobalChartsTheme = () => {
|
|
|
475
543
|
var useXYChartTheme = (data) => {
|
|
476
544
|
const theme = useGlobalChartsTheme();
|
|
477
545
|
return _react.useMemo.call(void 0, () => {
|
|
478
|
-
const seriesColors = (_nullishCoalesce(data, () => ( []))).map((series) => _optionalChain([series, 'access',
|
|
546
|
+
const seriesColors = (_nullishCoalesce(data, () => ( []))).map((series) => _optionalChain([series, 'access', _13 => _13.options, 'optionalAccess', _14 => _14.stroke])).filter((color) => Boolean(color));
|
|
479
547
|
return _xychart.buildChartTheme.call(void 0, {
|
|
480
548
|
...theme,
|
|
481
549
|
colors: [...seriesColors, ..._nullishCoalesce(theme.colors, () => ( []))]
|
|
@@ -487,7 +555,7 @@ var useXYChartTheme = (data) => {
|
|
|
487
555
|
|
|
488
556
|
var useChartDataTransform = (data) => {
|
|
489
557
|
return _react.useMemo.call(void 0, () => {
|
|
490
|
-
const firstPoint = _optionalChain([data, 'optionalAccess',
|
|
558
|
+
const firstPoint = _optionalChain([data, 'optionalAccess', _15 => _15[0], 'optionalAccess', _16 => _16.data, 'optionalAccess', _17 => _17[0]]);
|
|
491
559
|
const hasDateProperties = firstPoint && ("date" in firstPoint || "dateString" in firstPoint);
|
|
492
560
|
if (!hasDateProperties) {
|
|
493
561
|
return data;
|
|
@@ -516,13 +584,38 @@ var useChartDataTransform = (data) => {
|
|
|
516
584
|
// src/hooks/use-chart-margin.tsx
|
|
517
585
|
var _scale = require('@visx/scale');
|
|
518
586
|
|
|
587
|
+
var DEFAULT_MARGIN_TOP = 10;
|
|
588
|
+
var DEFAULT_MARGIN_RIGHT = 20;
|
|
589
|
+
var DEFAULT_MARGIN_BOTTOM = 20;
|
|
590
|
+
var DEFAULT_MARGIN_LEFT = 20;
|
|
591
|
+
var DEFAULT_BOTTOM_FOR_TOP_AXIS = 10;
|
|
592
|
+
var DEFAULT_FONT_SIZE = 12;
|
|
593
|
+
var DEFAULT_TICK_LENGTH = 8;
|
|
594
|
+
var DEFAULT_Y_TICK_WIDTH = 40;
|
|
595
|
+
var resolveFontSize = (val) => {
|
|
596
|
+
if (typeof val === "number" && !isNaN(val)) {
|
|
597
|
+
return val;
|
|
598
|
+
}
|
|
599
|
+
if (typeof val === "string") {
|
|
600
|
+
const parsed = parseFloat(val);
|
|
601
|
+
return isNaN(parsed) ? void 0 : parsed;
|
|
602
|
+
}
|
|
603
|
+
return void 0;
|
|
604
|
+
};
|
|
605
|
+
var getXAxisLabelMetrics = (theme, orientation) => {
|
|
606
|
+
const xAxisStyles = orientation === "top" ? _optionalChain([theme, 'access', _18 => _18.axisStyles, 'optionalAccess', _19 => _19.x, 'optionalAccess', _20 => _20.top]) : _optionalChain([theme, 'access', _21 => _21.axisStyles, 'optionalAccess', _22 => _22.x, 'optionalAccess', _23 => _23.bottom]);
|
|
607
|
+
const fontSize = resolveFontSize(_optionalChain([xAxisStyles, 'optionalAccess', _24 => _24.axisLabel, 'optionalAccess', _25 => _25.fontSize])) || resolveFontSize(_optionalChain([theme, 'access', _26 => _26.svgLabelSmall, 'optionalAccess', _27 => _27.fontSize])) || DEFAULT_FONT_SIZE;
|
|
608
|
+
const tickLength = _nullishCoalesce(_optionalChain([xAxisStyles, 'optionalAccess', _28 => _28.tickLength]), () => ( DEFAULT_TICK_LENGTH));
|
|
609
|
+
return {
|
|
610
|
+
fontSize,
|
|
611
|
+
tickLength
|
|
612
|
+
};
|
|
613
|
+
};
|
|
519
614
|
var useChartMargin = (height, options, data, theme, horizontal = false) => {
|
|
520
615
|
const yTicks = _react.useMemo.call(void 0, () => {
|
|
521
616
|
const allDataPoints = data.flatMap((series) => series.data);
|
|
522
617
|
if (horizontal) {
|
|
523
|
-
return allDataPoints.map(
|
|
524
|
-
(d) => d.label || _optionalChain([options, 'access', _14 => _14.axis, 'optionalAccess', _15 => _15.y, 'optionalAccess', _16 => _16.tickFormat, 'call', _17 => _17(d.date.getTime(), 0, [])])
|
|
525
|
-
);
|
|
618
|
+
return allDataPoints.map((d) => d.label || _optionalChain([options, 'access', _29 => _29.axis, 'optionalAccess', _30 => _30.y, 'optionalAccess', _31 => _31.tickFormat, 'call', _32 => _32(d.date.getTime(), 0, [])]));
|
|
526
619
|
}
|
|
527
620
|
const minY = Math.min(...allDataPoints.map((d) => d.value));
|
|
528
621
|
const maxY = Math.max(...allDataPoints.map((d) => d.value));
|
|
@@ -531,27 +624,35 @@ var useChartMargin = (height, options, data, theme, horizontal = false) => {
|
|
|
531
624
|
domain: [minY, maxY],
|
|
532
625
|
range: [height, 0]
|
|
533
626
|
});
|
|
534
|
-
return _scale.getTicks.call(void 0, yScale, _optionalChain([options, 'access',
|
|
627
|
+
return _scale.getTicks.call(void 0, yScale, _optionalChain([options, 'access', _33 => _33.axis, 'optionalAccess', _34 => _34.y, 'optionalAccess', _35 => _35.numTicks]));
|
|
535
628
|
}, [options, data, height, horizontal]);
|
|
536
629
|
return _react.useMemo.call(void 0, () => {
|
|
537
|
-
const defaultMargin = {
|
|
538
|
-
|
|
539
|
-
|
|
630
|
+
const defaultMargin = {
|
|
631
|
+
top: DEFAULT_MARGIN_TOP,
|
|
632
|
+
right: DEFAULT_MARGIN_RIGHT,
|
|
633
|
+
bottom: DEFAULT_MARGIN_BOTTOM,
|
|
634
|
+
left: DEFAULT_MARGIN_LEFT
|
|
635
|
+
};
|
|
636
|
+
const yAxisOrientation = _optionalChain([options, 'access', _36 => _36.axis, 'optionalAccess', _37 => _37.y, 'optionalAccess', _38 => _38.orientation]);
|
|
540
637
|
const yAxisStyles = yAxisOrientation === "right" ? theme.axisStyles.y.right : theme.axisStyles.y.left;
|
|
541
|
-
const yTickWidth = _chunkZVGEDXDPcjs.getLongestTickWidth.call(void 0,
|
|
542
|
-
|
|
543
|
-
_optionalChain([options, 'access', _24 => _24.axis, 'optionalAccess', _25 => _25.y, 'optionalAccess', _26 => _26.tickFormat]),
|
|
544
|
-
yAxisStyles.axisLabel
|
|
545
|
-
);
|
|
546
|
-
const yMarginValue = (_nullishCoalesce(yTickWidth, () => ( defaultTickWidth))) + (_nullishCoalesce(_optionalChain([yAxisStyles, 'optionalAccess', _27 => _27.tickLength]), () => ( 0)));
|
|
638
|
+
const yTickWidth = _chunkZVGEDXDPcjs.getLongestTickWidth.call(void 0, yTicks, _optionalChain([options, 'access', _39 => _39.axis, 'optionalAccess', _40 => _40.y, 'optionalAccess', _41 => _41.tickFormat]), yAxisStyles.axisLabel);
|
|
639
|
+
const yMarginValue = (_nullishCoalesce(yTickWidth, () => ( DEFAULT_Y_TICK_WIDTH))) + (_nullishCoalesce(_optionalChain([yAxisStyles, 'optionalAccess', _42 => _42.tickLength]), () => ( 0)));
|
|
547
640
|
if (yAxisOrientation === "right") {
|
|
548
641
|
defaultMargin.right = yMarginValue;
|
|
549
642
|
} else {
|
|
550
643
|
defaultMargin.left = yMarginValue;
|
|
551
644
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
645
|
+
const xOrientation = _optionalChain([options, 'access', _43 => _43.axis, 'optionalAccess', _44 => _44.x, 'optionalAccess', _45 => _45.orientation]) === "top" ? "top" : "bottom";
|
|
646
|
+
const {
|
|
647
|
+
fontSize,
|
|
648
|
+
tickLength
|
|
649
|
+
} = getXAxisLabelMetrics(theme, xOrientation);
|
|
650
|
+
const computedXMargin = fontSize + tickLength;
|
|
651
|
+
if (xOrientation === "top") {
|
|
652
|
+
defaultMargin.top = Math.max(defaultMargin.top, computedXMargin);
|
|
653
|
+
defaultMargin.bottom = DEFAULT_BOTTOM_FOR_TOP_AXIS;
|
|
654
|
+
} else {
|
|
655
|
+
defaultMargin.bottom = Math.max(defaultMargin.bottom, computedXMargin);
|
|
555
656
|
}
|
|
556
657
|
return defaultMargin;
|
|
557
658
|
}, [options, theme, yTicks]);
|
|
@@ -590,7 +691,7 @@ function useElementHeight({
|
|
|
590
691
|
|
|
591
692
|
// src/charts/private/single-chart-context/single-chart-context.tsx
|
|
592
693
|
|
|
593
|
-
var ChartInstanceContext = _react.createContext.call(void 0, null);
|
|
694
|
+
var ChartInstanceContext = /* @__PURE__ */ _react.createContext.call(void 0, null);
|
|
594
695
|
var SingleChartContext = ChartInstanceContext;
|
|
595
696
|
|
|
596
697
|
// src/charts/private/single-chart-context/use-single-chart-context.ts
|
|
@@ -611,10 +712,6 @@ var _legend = require('@visx/legend');
|
|
|
611
712
|
var _clsx = require('clsx'); var _clsx2 = _interopRequireDefault(_clsx);
|
|
612
713
|
|
|
613
714
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
715
|
// src/components/legend/utils/value-or-identity.ts
|
|
619
716
|
function valueOrIdentity(_) {
|
|
620
717
|
if (_ && typeof _ === "object" && "value" in _ && typeof _.value !== "undefined")
|
|
@@ -669,241 +766,186 @@ var LegendText = ({
|
|
|
669
766
|
}) => {
|
|
670
767
|
const isEllipsis = maxWidth != null && textOverflow === "ellipsis";
|
|
671
768
|
const [textRef, isTruncated] = useTextTruncation(Boolean(isEllipsis));
|
|
672
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
673
|
-
|
|
674
|
-
{
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
},
|
|
686
|
-
title: isEllipsis && isTruncated ? text : void 0,
|
|
687
|
-
children: text
|
|
688
|
-
}
|
|
689
|
-
);
|
|
769
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", {
|
|
770
|
+
ref: textRef,
|
|
771
|
+
className: _clsx2.default.call(void 0, base_legend_module_default["legend-item-text"], maxWidth != null && base_legend_module_default[`legend-item-text--${textOverflow}`]),
|
|
772
|
+
style: {
|
|
773
|
+
...maxWidth != null && {
|
|
774
|
+
maxWidth,
|
|
775
|
+
minWidth: 0
|
|
776
|
+
}
|
|
777
|
+
},
|
|
778
|
+
title: isEllipsis && isTruncated ? text : void 0,
|
|
779
|
+
children: text
|
|
780
|
+
});
|
|
690
781
|
};
|
|
691
|
-
var BaseLegend = _react.forwardRef.call(void 0,
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
)
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
);
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
)
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
782
|
+
var BaseLegend = /* @__PURE__ */ _react.forwardRef.call(void 0, ({
|
|
783
|
+
items,
|
|
784
|
+
className,
|
|
785
|
+
orientation = "horizontal",
|
|
786
|
+
position = "bottom",
|
|
787
|
+
alignment = "center",
|
|
788
|
+
maxWidth,
|
|
789
|
+
textOverflow = "wrap",
|
|
790
|
+
shape = "rect",
|
|
791
|
+
fill = valueOrIdentityString,
|
|
792
|
+
size = valueOrIdentityString,
|
|
793
|
+
labelFormat = valueOrIdentity,
|
|
794
|
+
labelTransform = labelTransformFactory,
|
|
795
|
+
shapeWidth = 16,
|
|
796
|
+
shapeHeight = 16,
|
|
797
|
+
shapeMargin = "2px 4px 2px 0",
|
|
798
|
+
labelAlign = "left",
|
|
799
|
+
labelFlex = "0 0 auto",
|
|
800
|
+
// Use natural width instead of expanding to fill space
|
|
801
|
+
labelMargin = "0 4px",
|
|
802
|
+
itemMargin = "0",
|
|
803
|
+
itemDirection = "row",
|
|
804
|
+
legendLabelProps,
|
|
805
|
+
legendItemClassName,
|
|
806
|
+
render,
|
|
807
|
+
interactive = false,
|
|
808
|
+
chartId,
|
|
809
|
+
...legendItemProps
|
|
810
|
+
}, ref) => {
|
|
811
|
+
const theme = useGlobalChartsTheme();
|
|
812
|
+
const context = _react.useContext.call(void 0, GlobalChartsContext);
|
|
813
|
+
const legendScale = _scale.scaleOrdinal.call(void 0, {
|
|
814
|
+
domain: items.map((item) => item.label),
|
|
815
|
+
range: items.map((item) => item.color)
|
|
816
|
+
});
|
|
817
|
+
const domain = legendScale.domain();
|
|
818
|
+
const getShapeStyle = _react.useCallback.call(void 0, ({
|
|
819
|
+
index
|
|
820
|
+
}) => _optionalChain([items, 'access', _46 => _46[index], 'optionalAccess', _47 => _47.shapeStyle]), [items]);
|
|
821
|
+
const handleLegendClick = _react.useCallback.call(void 0, (seriesLabel) => {
|
|
822
|
+
if (interactive && chartId && context) {
|
|
823
|
+
context.toggleSeriesVisibility(chartId, seriesLabel);
|
|
824
|
+
}
|
|
825
|
+
}, [interactive, chartId, context]);
|
|
826
|
+
const isSeriesVisible = _react.useCallback.call(void 0, (seriesLabel) => {
|
|
827
|
+
if (!interactive || !chartId || !context) {
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
830
|
+
return context.isSeriesVisible(chartId, seriesLabel);
|
|
831
|
+
}, [interactive, chartId, context]);
|
|
832
|
+
const createClickHandler = _react.useCallback.call(void 0, (labelText) => {
|
|
833
|
+
if (!interactive) {
|
|
834
|
+
return void 0;
|
|
835
|
+
}
|
|
836
|
+
return () => handleLegendClick(labelText);
|
|
837
|
+
}, [interactive, handleLegendClick]);
|
|
838
|
+
const createKeyDownHandler = _react.useCallback.call(void 0, (labelText) => {
|
|
839
|
+
if (!interactive) {
|
|
840
|
+
return void 0;
|
|
841
|
+
}
|
|
842
|
+
return (event) => {
|
|
843
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
844
|
+
event.preventDefault();
|
|
845
|
+
handleLegendClick(labelText);
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
}, [interactive, handleLegendClick]);
|
|
849
|
+
return render ? render(items) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _legend.LegendOrdinal, {
|
|
850
|
+
scale: legendScale,
|
|
851
|
+
labelFormat,
|
|
852
|
+
labelTransform,
|
|
853
|
+
children: (labels) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
|
|
854
|
+
ref,
|
|
855
|
+
role: "list",
|
|
856
|
+
className: _clsx2.default.call(void 0, 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),
|
|
857
|
+
style: {
|
|
858
|
+
flexDirection: orientationToFlexDirection[orientation],
|
|
859
|
+
...theme.legendContainerStyles
|
|
769
860
|
},
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
861
|
+
children: labels.map((label, i) => {
|
|
862
|
+
const visible = isSeriesVisible(label.text);
|
|
863
|
+
const handleClick = createClickHandler(label.text);
|
|
864
|
+
const handleKeyDown = createKeyDownHandler(label.text);
|
|
865
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _legend.LegendItem, {
|
|
866
|
+
className: _clsx2.default.call(void 0, "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"], legendItemClassName),
|
|
867
|
+
margin: itemMargin,
|
|
868
|
+
flexDirection: orientation === "vertical" && alignment === "end" ? "row-reverse" : itemDirection,
|
|
869
|
+
onClick: handleClick,
|
|
870
|
+
onKeyDown: handleKeyDown,
|
|
871
|
+
role: interactive ? "button" : void 0,
|
|
872
|
+
tabIndex: interactive ? 0 : void 0,
|
|
873
|
+
"aria-pressed": interactive ? visible : void 0,
|
|
874
|
+
"aria-label": interactive ? `${label.text}: ${visible ? "visible" : "hidden"}. Toggle visibility.` : void 0,
|
|
875
|
+
...legendItemProps,
|
|
876
|
+
children: [_optionalChain([items, 'access', _48 => _48[i], 'optionalAccess', _49 => _49.renderGlyph]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", {
|
|
877
|
+
width: _optionalChain([items, 'access', _50 => _50[i], 'optionalAccess', _51 => _51.glyphSize]) * 2,
|
|
878
|
+
height: _optionalChain([items, 'access', _52 => _52[i], 'optionalAccess', _53 => _53.glyphSize]) * 2,
|
|
879
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _group.Group, {
|
|
880
|
+
children: _optionalChain([items, 'access', _54 => _54[i], 'optionalAccess', _55 => _55.renderGlyph, 'call', _56 => _56({
|
|
881
|
+
key: `legend-glyph-${label.text}`,
|
|
882
|
+
datum: {},
|
|
883
|
+
index: i,
|
|
884
|
+
color: fill(label),
|
|
885
|
+
size: _optionalChain([items, 'access', _57 => _57[i], 'optionalAccess', _58 => _58.glyphSize]),
|
|
886
|
+
x: _optionalChain([items, 'access', _59 => _59[i], 'optionalAccess', _60 => _60.glyphSize]),
|
|
887
|
+
y: _optionalChain([items, 'access', _61 => _61[i], 'optionalAccess', _62 => _62.glyphSize])
|
|
888
|
+
})])
|
|
889
|
+
})
|
|
890
|
+
}) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _legend.LegendShape, {
|
|
891
|
+
shape,
|
|
892
|
+
height: shapeHeight,
|
|
893
|
+
width: shapeWidth,
|
|
894
|
+
margin: shapeMargin,
|
|
895
|
+
item: domain[i],
|
|
896
|
+
itemIndex: i,
|
|
897
|
+
label,
|
|
898
|
+
fill,
|
|
899
|
+
size,
|
|
900
|
+
shapeStyle: getShapeStyle
|
|
901
|
+
}), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _legend.LegendLabel, {
|
|
902
|
+
className: _clsx2.default.call(void 0, "visx-legend-label", base_legend_module_default["legend-item-label"]),
|
|
791
903
|
style: {
|
|
792
|
-
|
|
793
|
-
|
|
904
|
+
justifyContent: labelAlign,
|
|
905
|
+
flex: labelFlex,
|
|
906
|
+
margin: labelMargin,
|
|
907
|
+
...theme.legendLabelStyles
|
|
794
908
|
},
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
margin: itemMargin,
|
|
811
|
-
flexDirection: orientation === "vertical" && alignment === "end" ? "row-reverse" : itemDirection,
|
|
812
|
-
onClick: handleClick,
|
|
813
|
-
onKeyDown: handleKeyDown,
|
|
814
|
-
role: interactive ? "button" : void 0,
|
|
815
|
-
tabIndex: interactive ? 0 : void 0,
|
|
816
|
-
"aria-pressed": interactive ? visible : void 0,
|
|
817
|
-
"aria-label": interactive ? `${label.text}: ${visible ? "visible" : "hidden"}. Toggle visibility.` : void 0,
|
|
818
|
-
...legendItemProps,
|
|
819
|
-
children: [
|
|
820
|
-
_optionalChain([items, 'access', _33 => _33[i], 'optionalAccess', _34 => _34.renderGlyph]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
821
|
-
"svg",
|
|
822
|
-
{
|
|
823
|
-
width: _optionalChain([items, 'access', _35 => _35[i], 'optionalAccess', _36 => _36.glyphSize]) * 2,
|
|
824
|
-
height: _optionalChain([items, 'access', _37 => _37[i], 'optionalAccess', _38 => _38.glyphSize]) * 2,
|
|
825
|
-
"data-testid": "legend-glyph",
|
|
826
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _group.Group, { children: _optionalChain([items, 'access', _39 => _39[i], 'optionalAccess', _40 => _40.renderGlyph, 'call', _41 => _41({
|
|
827
|
-
key: `legend-glyph-${label.text}`,
|
|
828
|
-
datum: {},
|
|
829
|
-
index: i,
|
|
830
|
-
color: fill(label),
|
|
831
|
-
size: _optionalChain([items, 'access', _42 => _42[i], 'optionalAccess', _43 => _43.glyphSize]),
|
|
832
|
-
x: _optionalChain([items, 'access', _44 => _44[i], 'optionalAccess', _45 => _45.glyphSize]),
|
|
833
|
-
y: _optionalChain([items, 'access', _46 => _46[i], 'optionalAccess', _47 => _47.glyphSize])
|
|
834
|
-
})]) })
|
|
835
|
-
}
|
|
836
|
-
) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
837
|
-
_legend.LegendShape,
|
|
838
|
-
{
|
|
839
|
-
shape,
|
|
840
|
-
height: shapeHeight,
|
|
841
|
-
width: shapeWidth,
|
|
842
|
-
margin: shapeMargin,
|
|
843
|
-
item: domain[i],
|
|
844
|
-
itemIndex: i,
|
|
845
|
-
label,
|
|
846
|
-
fill,
|
|
847
|
-
size,
|
|
848
|
-
shapeStyle: getShapeStyle
|
|
849
|
-
}
|
|
850
|
-
),
|
|
851
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
852
|
-
_legend.LegendLabel,
|
|
853
|
-
{
|
|
854
|
-
className: _clsx2.default.call(void 0, "visx-legend-label", base_legend_module_default["legend-item-label"]),
|
|
855
|
-
style: {
|
|
856
|
-
justifyContent: labelAlign,
|
|
857
|
-
flex: labelFlex,
|
|
858
|
-
margin: labelMargin,
|
|
859
|
-
...theme.legendLabelStyles
|
|
860
|
-
},
|
|
861
|
-
...legendLabelProps,
|
|
862
|
-
children: [
|
|
863
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
864
|
-
LegendText,
|
|
865
|
-
{
|
|
866
|
-
text: label.text,
|
|
867
|
-
textOverflow,
|
|
868
|
-
maxWidth
|
|
869
|
-
}
|
|
870
|
-
),
|
|
871
|
-
_optionalChain([items, 'access', _48 => _48.find, 'call', _49 => _49((item) => item.label === label.text), 'optionalAccess', _50 => _50.value]) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: base_legend_module_default["legend-item-value"], children: [
|
|
872
|
-
"\xA0",
|
|
873
|
-
_optionalChain([items, 'access', _51 => _51.find, 'call', _52 => _52((item) => item.label === label.text), 'optionalAccess', _53 => _53.value])
|
|
874
|
-
] })
|
|
875
|
-
]
|
|
876
|
-
}
|
|
877
|
-
)
|
|
878
|
-
]
|
|
879
|
-
},
|
|
880
|
-
`legend-${label.text}-${i}`
|
|
881
|
-
);
|
|
882
|
-
})
|
|
883
|
-
}
|
|
884
|
-
)
|
|
885
|
-
}
|
|
886
|
-
);
|
|
887
|
-
}
|
|
888
|
-
);
|
|
909
|
+
...legendLabelProps,
|
|
910
|
+
children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, LegendText, {
|
|
911
|
+
text: label.text,
|
|
912
|
+
textOverflow,
|
|
913
|
+
maxWidth
|
|
914
|
+
}), _optionalChain([items, 'access', _63 => _63.find, 'call', _64 => _64((item) => item.label === label.text), 'optionalAccess', _65 => _65.value]) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", {
|
|
915
|
+
className: base_legend_module_default["legend-item-value"],
|
|
916
|
+
children: ["\xA0", _optionalChain([items, 'access', _66 => _66.find, 'call', _67 => _67((item) => item.label === label.text), 'optionalAccess', _68 => _68.value])]
|
|
917
|
+
})]
|
|
918
|
+
})]
|
|
919
|
+
}, `legend-${label.text}-${i}`);
|
|
920
|
+
})
|
|
921
|
+
})
|
|
922
|
+
});
|
|
923
|
+
});
|
|
889
924
|
|
|
890
925
|
// src/components/legend/legend.tsx
|
|
891
926
|
|
|
892
|
-
var Legend = _react.forwardRef.call(void 0,
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
927
|
+
var Legend = /* @__PURE__ */ _react.forwardRef.call(void 0, ({
|
|
928
|
+
chartId,
|
|
929
|
+
items,
|
|
930
|
+
...props
|
|
931
|
+
}, ref) => {
|
|
932
|
+
const context = _react.useContext.call(void 0, GlobalChartsContext);
|
|
933
|
+
const singleChartContext = _react.useContext.call(void 0, SingleChartContext);
|
|
934
|
+
const contextChartId = _nullishCoalesce(chartId, () => ( _optionalChain([singleChartContext, 'optionalAccess', _69 => _69.chartId])));
|
|
935
|
+
const contextItems = _react.useMemo.call(void 0, () => {
|
|
936
|
+
return contextChartId && context ? _optionalChain([context, 'access', _70 => _70.getChartData, 'call', _71 => _71(contextChartId), 'optionalAccess', _72 => _72.legendItems]) : void 0;
|
|
937
|
+
}, [contextChartId, context]);
|
|
938
|
+
const legendItems = items || contextItems;
|
|
939
|
+
if (!legendItems) {
|
|
940
|
+
return null;
|
|
905
941
|
}
|
|
906
|
-
|
|
942
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BaseLegend, {
|
|
943
|
+
ref,
|
|
944
|
+
items: legendItems,
|
|
945
|
+
...props,
|
|
946
|
+
chartId: contextChartId
|
|
947
|
+
});
|
|
948
|
+
});
|
|
907
949
|
|
|
908
950
|
// src/components/legend/hooks/use-chart-legend-items.ts
|
|
909
951
|
var _numberformatters = require('@automattic/number-formatters');
|
|
@@ -952,7 +994,7 @@ function processSeriesData(seriesData, getElementStyles, showValues, withGlyph,
|
|
|
952
994
|
});
|
|
953
995
|
const baseItem = {
|
|
954
996
|
label: series.label,
|
|
955
|
-
value: showValues ? _optionalChain([series, 'access',
|
|
997
|
+
value: showValues ? _optionalChain([series, 'access', _73 => _73.data, 'optionalAccess', _74 => _74.length, 'optionalAccess', _75 => _75.toString, 'call', _76 => _76()]) || "0" : "",
|
|
956
998
|
color,
|
|
957
999
|
shapeStyle: shapeStyles
|
|
958
1000
|
};
|
|
@@ -1185,5 +1227,6 @@ function usePrefersReducedMotion() {
|
|
|
1185
1227
|
|
|
1186
1228
|
|
|
1187
1229
|
|
|
1188
|
-
|
|
1189
|
-
|
|
1230
|
+
|
|
1231
|
+
exports.SingleChartContext = SingleChartContext; exports.useSingleChartContext = useSingleChartContext; exports.useTooltipPortalRelocator = useTooltipPortalRelocator; exports.defaultTheme = defaultTheme; exports.GlobalChartsContext = GlobalChartsContext; exports.GlobalChartsProvider = GlobalChartsProvider; exports.useGlobalChartsContext = useGlobalChartsContext; exports.useChartId = useChartId; exports.useDeepMemo = useDeepMemo; exports.useChartMouseHandler = useChartMouseHandler; exports.useXYChartTheme = useXYChartTheme; exports.useChartDataTransform = useChartDataTransform; exports.useChartMargin = useChartMargin; exports.useElementHeight = useElementHeight; exports.useHasLegendChild = useHasLegendChild; exports.useTextTruncation = useTextTruncation; exports.useZeroValueDisplay = useZeroValueDisplay; exports.useInteractiveLegendData = useInteractiveLegendData; exports.usePrefersReducedMotion = usePrefersReducedMotion; exports.useChartRegistration = useChartRegistration; exports.useGlobalChartsTheme = useGlobalChartsTheme; exports.Legend = Legend; exports.useChartLegendItems = useChartLegendItems;
|
|
1232
|
+
//# sourceMappingURL=chunk-EJJO2QNB.cjs.map
|