@automattic/charts 1.3.1 → 1.4.1
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 +15 -0
- package/dist/index.cjs +158 -209
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +0 -9
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +11 -10
- package/dist/index.d.ts +11 -10
- package/dist/index.js +125 -176
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/charts/area-chart/area-chart.tsx +124 -54
- package/src/charts/area-chart/test/area-chart.test.tsx +203 -0
- package/src/hooks/index.ts +0 -1
- package/src/hooks/test/use-chart-margin.test.tsx +21 -0
- package/src/hooks/use-chart-margin.tsx +4 -0
- package/src/providers/chart-context/global-charts-provider.tsx +1 -18
- package/src/style.css +10 -0
- package/src/types.ts +10 -0
- package/tsup.config.ts +3 -2
- package/AGENTS.md +0 -78
- package/src/hooks/test/use-tooltip-portal-relocator.test.ts +0 -216
- package/src/hooks/use-tooltip-portal-relocator.module.scss +0 -7
- package/src/hooks/use-tooltip-portal-relocator.ts +0 -188
package/dist/index.js
CHANGED
|
@@ -467,7 +467,7 @@ var require_es6 = __commonJS({
|
|
|
467
467
|
|
|
468
468
|
// src/charts/area-chart/area-chart.tsx
|
|
469
469
|
import { formatNumberCompact as formatNumberCompact3 } from "@automattic/number-formatters";
|
|
470
|
-
import { XYChart as XYChart2,
|
|
470
|
+
import { XYChart as XYChart2, AnimatedAreaSeries, AnimatedAreaStack, Grid as Grid2, Axis as Axis2 } from "@visx/xychart";
|
|
471
471
|
import { __ as __4 } from "@wordpress/i18n";
|
|
472
472
|
import clsx5 from "clsx";
|
|
473
473
|
import { useMemo as useMemo16, useContext as useContext13, forwardRef as forwardRef5, useImperativeHandle as useImperativeHandle4, useState as useState10, useRef as useRef10, useCallback as useCallback9 } from "react";
|
|
@@ -493,104 +493,7 @@ var useSingleChartContext = useChartInstanceContext;
|
|
|
493
493
|
|
|
494
494
|
// src/providers/chart-context/global-charts-provider.tsx
|
|
495
495
|
import { hsl as d3Hsl3 } from "@visx/vendor/d3-color";
|
|
496
|
-
import { createContext as createContext2, useCallback, useMemo, useState, useEffect
|
|
497
|
-
|
|
498
|
-
// src/hooks/use-tooltip-portal-relocator.ts
|
|
499
|
-
import { useEffect } from "react";
|
|
500
|
-
|
|
501
|
-
// src/hooks/use-tooltip-portal-relocator.module.scss
|
|
502
|
-
var use_tooltip_portal_relocator_module_default = {
|
|
503
|
-
"relocatedPortal": "a8ccharts-jCw5dQ"
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
// src/hooks/use-tooltip-portal-relocator.ts
|
|
507
|
-
function isVisxPortalNode(node2) {
|
|
508
|
-
return node2 instanceof HTMLDivElement && node2.parentElement === document.body && !node2.id && !node2.className && node2.querySelector(".visx-tooltip") !== null;
|
|
509
|
-
}
|
|
510
|
-
var patchRefCount = 0;
|
|
511
|
-
var origRemoveChild = null;
|
|
512
|
-
var patchedRemoveChild = null;
|
|
513
|
-
var relocatedNodes = /* @__PURE__ */ new WeakSet();
|
|
514
|
-
function installRemoveChildPatch() {
|
|
515
|
-
if (patchRefCount++ > 0) {
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
origRemoveChild = document.body.removeChild;
|
|
519
|
-
patchedRemoveChild = function(child) {
|
|
520
|
-
if (relocatedNodes.has(child) && child.parentNode !== this) {
|
|
521
|
-
relocatedNodes.delete(child);
|
|
522
|
-
child.parentNode?.removeChild(child);
|
|
523
|
-
return child;
|
|
524
|
-
}
|
|
525
|
-
return origRemoveChild.call(this, child);
|
|
526
|
-
};
|
|
527
|
-
document.body.removeChild = patchedRemoveChild;
|
|
528
|
-
}
|
|
529
|
-
function uninstallRemoveChildPatch() {
|
|
530
|
-
if (--patchRefCount > 0) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
if (document.body.removeChild === patchedRemoveChild) {
|
|
534
|
-
document.body.removeChild = origRemoveChild;
|
|
535
|
-
}
|
|
536
|
-
origRemoveChild = null;
|
|
537
|
-
patchedRemoveChild = null;
|
|
538
|
-
}
|
|
539
|
-
function useTooltipPortalRelocator(containerRef) {
|
|
540
|
-
useEffect(() => {
|
|
541
|
-
const container = containerRef?.current;
|
|
542
|
-
if (!container) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
const instanceNodes = /* @__PURE__ */ new Set();
|
|
546
|
-
const relocateNode = (node2) => {
|
|
547
|
-
if (!isVisxPortalNode(node2)) {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
node2.style.opacity = "0";
|
|
551
|
-
node2.classList.add(use_tooltip_portal_relocator_module_default.relocatedPortal);
|
|
552
|
-
const { activeElement } = node2.ownerDocument;
|
|
553
|
-
const focusedElement = activeElement instanceof HTMLElement && node2.contains(activeElement) ? activeElement : null;
|
|
554
|
-
container.insertBefore(node2, container.firstChild);
|
|
555
|
-
relocatedNodes.add(node2);
|
|
556
|
-
instanceNodes.add(node2);
|
|
557
|
-
if (focusedElement) {
|
|
558
|
-
focusedElement.focus();
|
|
559
|
-
}
|
|
560
|
-
requestAnimationFrame(() => {
|
|
561
|
-
requestAnimationFrame(() => {
|
|
562
|
-
node2.style.opacity = "";
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
};
|
|
566
|
-
installRemoveChildPatch();
|
|
567
|
-
for (const child of Array.from(document.body.children)) {
|
|
568
|
-
relocateNode(child);
|
|
569
|
-
}
|
|
570
|
-
const observer = new MutationObserver((mutations) => {
|
|
571
|
-
for (const mutation of mutations) {
|
|
572
|
-
for (const node2 of mutation.addedNodes) {
|
|
573
|
-
relocateNode(node2);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
observer.observe(document.body, { childList: true });
|
|
578
|
-
return () => {
|
|
579
|
-
observer.disconnect();
|
|
580
|
-
for (const node2 of instanceNodes) {
|
|
581
|
-
if (node2 instanceof HTMLElement) {
|
|
582
|
-
node2.classList.remove(use_tooltip_portal_relocator_module_default.relocatedPortal);
|
|
583
|
-
}
|
|
584
|
-
if (node2.parentNode === container) {
|
|
585
|
-
document.body.appendChild(node2);
|
|
586
|
-
}
|
|
587
|
-
relocatedNodes.delete(node2);
|
|
588
|
-
}
|
|
589
|
-
instanceNodes.clear();
|
|
590
|
-
uninstallRemoveChildPatch();
|
|
591
|
-
};
|
|
592
|
-
}, [containerRef]);
|
|
593
|
-
}
|
|
496
|
+
import { createContext as createContext2, useCallback, useMemo, useState, useEffect, useLayoutEffect, useRef } from "react";
|
|
594
497
|
|
|
595
498
|
// src/utils/create-composition.ts
|
|
596
499
|
function attachSubComponents(Chart2, subComponents) {
|
|
@@ -1096,13 +999,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
1096
999
|
var GlobalChartsContext = /* @__PURE__ */ createContext2(null);
|
|
1097
1000
|
var GlobalChartsProvider = ({
|
|
1098
1001
|
children,
|
|
1099
|
-
theme
|
|
1100
|
-
portalContainer
|
|
1002
|
+
theme
|
|
1101
1003
|
}) => {
|
|
1102
1004
|
const [charts, setCharts] = useState(() => /* @__PURE__ */ new Map());
|
|
1103
1005
|
const [hiddenSeries, setHiddenSeries] = useState(() => /* @__PURE__ */ new Map());
|
|
1104
1006
|
const wrapperRef = useRef(null);
|
|
1105
|
-
useTooltipPortalRelocator(portalContainer ?? wrapperRef);
|
|
1106
1007
|
const providerTheme = useMemo(() => {
|
|
1107
1008
|
return theme ? mergeThemes(defaultTheme, theme) : defaultTheme;
|
|
1108
1009
|
}, [theme]);
|
|
@@ -1150,13 +1051,13 @@ var GlobalChartsProvider = ({
|
|
|
1150
1051
|
maxHue
|
|
1151
1052
|
});
|
|
1152
1053
|
}, [providerTheme]);
|
|
1153
|
-
|
|
1054
|
+
useEffect(() => {
|
|
1154
1055
|
if (colorCache.colors.length > 0) {
|
|
1155
1056
|
setIsColorPaletteResolved(true);
|
|
1156
1057
|
}
|
|
1157
1058
|
}, [colorCache]);
|
|
1158
1059
|
const [groupToColorMap, setGroupToColorMap] = useState(() => /* @__PURE__ */ new Map());
|
|
1159
|
-
|
|
1060
|
+
useEffect(() => {
|
|
1160
1061
|
setGroupToColorMap(/* @__PURE__ */ new Map());
|
|
1161
1062
|
}, [providerTheme.colors]);
|
|
1162
1063
|
const registerChart = useCallback((id, data) => {
|
|
@@ -1279,7 +1180,7 @@ var useChartId = (providedId) => {
|
|
|
1279
1180
|
};
|
|
1280
1181
|
|
|
1281
1182
|
// src/providers/chart-context/hooks/use-chart-registration.ts
|
|
1282
|
-
import { useEffect as
|
|
1183
|
+
import { useEffect as useEffect3, useMemo as useMemo8 } from "react";
|
|
1283
1184
|
|
|
1284
1185
|
// src/hooks/use-deep-memo.ts
|
|
1285
1186
|
var import_fast_deep_equal = __toESM(require_fast_deep_equal(), 1);
|
|
@@ -1362,6 +1263,9 @@ var useChartMargin = (height, options, data, theme, horizontal = false) => {
|
|
|
1362
1263
|
if (horizontal) {
|
|
1363
1264
|
return allDataPoints.map((d) => d.label || options.axis?.y?.tickFormat(d.date.getTime(), 0, []));
|
|
1364
1265
|
}
|
|
1266
|
+
if (options.axis?.y?.tickValues?.length) {
|
|
1267
|
+
return options.axis.y.tickValues;
|
|
1268
|
+
}
|
|
1365
1269
|
const minY = Math.min(...allDataPoints.map((d) => d.value));
|
|
1366
1270
|
const maxY = Math.max(...allDataPoints.map((d) => d.value));
|
|
1367
1271
|
const yScale = createScale({
|
|
@@ -1565,12 +1469,12 @@ var useInteractiveLegendData = ({
|
|
|
1565
1469
|
};
|
|
1566
1470
|
|
|
1567
1471
|
// src/hooks/use-prefers-reduced-motion.ts
|
|
1568
|
-
import { useState as useState4, useEffect as
|
|
1472
|
+
import { useState as useState4, useEffect as useEffect2 } from "react";
|
|
1569
1473
|
var QUERY = "(prefers-reduced-motion: no-preference)";
|
|
1570
1474
|
var getInitialState = () => !window.matchMedia(QUERY).matches;
|
|
1571
1475
|
function usePrefersReducedMotion() {
|
|
1572
1476
|
const [prefersReducedMotion, setPrefersReducedMotion] = useState4(getInitialState);
|
|
1573
|
-
|
|
1477
|
+
useEffect2(() => {
|
|
1574
1478
|
const mediaQueryList = window.matchMedia(QUERY);
|
|
1575
1479
|
const listener = (event) => {
|
|
1576
1480
|
setPrefersReducedMotion(!event.matches);
|
|
@@ -1594,7 +1498,7 @@ var useChartRegistration = ({
|
|
|
1594
1498
|
const { registerChart, unregisterChart } = useGlobalChartsContext();
|
|
1595
1499
|
const stableLegendItems = useDeepMemo(legendItems);
|
|
1596
1500
|
const memoizedMetadata = useMemo8(() => metadata, [metadata]);
|
|
1597
|
-
|
|
1501
|
+
useEffect3(() => {
|
|
1598
1502
|
if (isDataValid) {
|
|
1599
1503
|
registerChart(chartId, {
|
|
1600
1504
|
legendItems: stableLegendItems,
|
|
@@ -1647,7 +1551,7 @@ import {
|
|
|
1647
1551
|
useContext as useContext4,
|
|
1648
1552
|
useDebugValue,
|
|
1649
1553
|
useDeferredValue,
|
|
1650
|
-
useEffect as
|
|
1554
|
+
useEffect as useEffect4,
|
|
1651
1555
|
useId as useId2,
|
|
1652
1556
|
useMemo as useMemo9,
|
|
1653
1557
|
useImperativeHandle,
|
|
@@ -2694,7 +2598,7 @@ var BaseTooltip = ({
|
|
|
2694
2598
|
|
|
2695
2599
|
// src/components/tooltip/accessible-tooltip.tsx
|
|
2696
2600
|
import { Tooltip, TooltipContext } from "@visx/xychart";
|
|
2697
|
-
import { useContext as useContext7, useEffect as
|
|
2601
|
+
import { useContext as useContext7, useEffect as useEffect5, useCallback as useCallback6, useMemo as useMemo12 } from "react";
|
|
2698
2602
|
import { jsx as _jsx5 } from "react/jsx-runtime";
|
|
2699
2603
|
var AccessibleTooltip = ({
|
|
2700
2604
|
renderTooltip,
|
|
@@ -2726,7 +2630,7 @@ var AccessibleTooltip = ({
|
|
|
2726
2630
|
}
|
|
2727
2631
|
return flattened;
|
|
2728
2632
|
}, [series, mode]);
|
|
2729
|
-
|
|
2633
|
+
useEffect5(() => {
|
|
2730
2634
|
if (selectedIndex === void 0) {
|
|
2731
2635
|
tooltipContext?.hideTooltip();
|
|
2732
2636
|
return;
|
|
@@ -2925,7 +2829,7 @@ function useChartChildren(children, chartType) {
|
|
|
2925
2829
|
}
|
|
2926
2830
|
|
|
2927
2831
|
// src/charts/private/chart-layout/chart-layout.tsx
|
|
2928
|
-
import { useEffect as
|
|
2832
|
+
import { useEffect as useEffect6 } from "react";
|
|
2929
2833
|
|
|
2930
2834
|
// src/charts/private/chart-layout/chart-layout.module.scss
|
|
2931
2835
|
var chart_layout_module_default = {
|
|
@@ -2953,7 +2857,7 @@ var ChartLayout = ({
|
|
|
2953
2857
|
const visibilityStyle = isRenderProp && !isMeasured ? {
|
|
2954
2858
|
visibility: "hidden"
|
|
2955
2859
|
} : {};
|
|
2956
|
-
|
|
2860
|
+
useEffect6(() => {
|
|
2957
2861
|
if (isRenderProp && onContentHeightChange && isMeasured) {
|
|
2958
2862
|
onContentHeightChange(contentHeight);
|
|
2959
2863
|
}
|
|
@@ -3198,7 +3102,7 @@ var line_chart_module_default = {
|
|
|
3198
3102
|
import { __ } from "@wordpress/i18n";
|
|
3199
3103
|
import { Icon, close } from "@wordpress/icons";
|
|
3200
3104
|
import clsx3 from "clsx";
|
|
3201
|
-
import { useEffect as
|
|
3105
|
+
import { useEffect as useEffect7, useId as useId3, useRef as useRef7, useState as useState6 } from "react";
|
|
3202
3106
|
import { jsx as _jsx12, jsxs as _jsxs4 } from "react/jsx-runtime";
|
|
3203
3107
|
var POPOVER_BUTTON_SIZE = 44;
|
|
3204
3108
|
var LineChartAnnotationLabelWithPopover = ({
|
|
@@ -3212,7 +3116,7 @@ var LineChartAnnotationLabelWithPopover = ({
|
|
|
3212
3116
|
const popoverRef = useRef7(null);
|
|
3213
3117
|
const [isPositioned, setIsPositioned] = useState6(false);
|
|
3214
3118
|
const isBrowserSafari = isSafari();
|
|
3215
|
-
|
|
3119
|
+
useEffect7(() => {
|
|
3216
3120
|
const button = buttonRef.current;
|
|
3217
3121
|
const popover = popoverRef.current;
|
|
3218
3122
|
if (!button || !popover) return;
|
|
@@ -3285,7 +3189,7 @@ var line_chart_annotation_label_popover_default = LineChartAnnotationLabelWithPo
|
|
|
3285
3189
|
|
|
3286
3190
|
// src/charts/line-chart/private/line-chart-annotations-overlay.tsx
|
|
3287
3191
|
import { DataContext as DataContext2 } from "@visx/xychart";
|
|
3288
|
-
import { useEffect as
|
|
3192
|
+
import { useEffect as useEffect8, useState as useState7, useCallback as useCallback7 } from "react";
|
|
3289
3193
|
import { jsx as _jsx13 } from "react/jsx-runtime";
|
|
3290
3194
|
var LineChartAnnotationsOverlay = ({
|
|
3291
3195
|
children
|
|
@@ -3320,7 +3224,7 @@ var LineChartAnnotationsOverlay = ({
|
|
|
3320
3224
|
}
|
|
3321
3225
|
return null;
|
|
3322
3226
|
}, [chartRef, createScaleSignature]);
|
|
3323
|
-
|
|
3227
|
+
useEffect8(() => {
|
|
3324
3228
|
let timeoutId = null;
|
|
3325
3229
|
let lastSignature = null;
|
|
3326
3230
|
let retryCount = 0;
|
|
@@ -3384,7 +3288,7 @@ var line_chart_annotations_overlay_default = LineChartAnnotationsOverlay;
|
|
|
3384
3288
|
import { Annotation, CircleSubject, Connector, HtmlLabel, Label, LineSubject } from "@visx/annotation";
|
|
3385
3289
|
import { DataContext as DataContext3 } from "@visx/xychart";
|
|
3386
3290
|
import merge from "deepmerge";
|
|
3387
|
-
import { useContext as useContext9, useRef as useRef8, useEffect as
|
|
3291
|
+
import { useContext as useContext9, useRef as useRef8, useEffect as useEffect9, useState as useState8, useMemo as useMemo14 } from "react";
|
|
3388
3292
|
import { jsx as _jsx14, jsxs as _jsxs5 } from "react/jsx-runtime";
|
|
3389
3293
|
var ANNOTATION_MAX_WIDTH = 125;
|
|
3390
3294
|
var ANNOTATION_INIT_HEIGHT = 100;
|
|
@@ -3481,7 +3385,7 @@ var LineChartAnnotation = ({
|
|
|
3481
3385
|
const labelRef = useRef8(null);
|
|
3482
3386
|
const [height, setHeight] = useState8(null);
|
|
3483
3387
|
const styles = merge(providerTheme.annotationStyles ?? {}, datumStyles ?? {});
|
|
3484
|
-
|
|
3388
|
+
useEffect9(() => {
|
|
3485
3389
|
if (labelRef.current?.getBBox) {
|
|
3486
3390
|
const bbox = labelRef.current.getBBox();
|
|
3487
3391
|
setHeight(bbox.height);
|
|
@@ -4299,6 +4203,42 @@ var AreaChartInternal = /* @__PURE__ */ forwardRef5(({
|
|
|
4299
4203
|
chartRef,
|
|
4300
4204
|
totalPoints: dataSorted[0]?.data.length || 0
|
|
4301
4205
|
});
|
|
4206
|
+
const fixedYDomain = useMemo16(() => {
|
|
4207
|
+
if (!legendInteractive || !dataSorted.length || !dataSorted[0].data.length || stacked && stackOffset !== "none") {
|
|
4208
|
+
return void 0;
|
|
4209
|
+
}
|
|
4210
|
+
if (stacked) {
|
|
4211
|
+
const numPoints = Math.max(...dataSorted.map((s) => s.data.length));
|
|
4212
|
+
let posMax = 0;
|
|
4213
|
+
let negMin = 0;
|
|
4214
|
+
for (let i = 0; i < numPoints; i++) {
|
|
4215
|
+
let posSum = 0;
|
|
4216
|
+
let negSum = 0;
|
|
4217
|
+
for (const series of dataSorted) {
|
|
4218
|
+
const v = Number(series.data[i]?.value);
|
|
4219
|
+
if (Number.isNaN(v)) continue;
|
|
4220
|
+
if (v >= 0) posSum += v;
|
|
4221
|
+
else negSum += v;
|
|
4222
|
+
}
|
|
4223
|
+
if (posSum > posMax) posMax = posSum;
|
|
4224
|
+
if (negSum < negMin) negMin = negSum;
|
|
4225
|
+
}
|
|
4226
|
+
return [negMin, posMax];
|
|
4227
|
+
}
|
|
4228
|
+
let max = -Infinity;
|
|
4229
|
+
let min = Infinity;
|
|
4230
|
+
for (const series of dataSorted) {
|
|
4231
|
+
for (const point of series.data) {
|
|
4232
|
+
const v = Number(point?.value);
|
|
4233
|
+
if (!Number.isNaN(v)) {
|
|
4234
|
+
if (v > max) max = v;
|
|
4235
|
+
if (v < min) min = v;
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
}
|
|
4239
|
+
if (max === -Infinity) return void 0;
|
|
4240
|
+
return [Math.min(0, min), max];
|
|
4241
|
+
}, [dataSorted, stacked, stackOffset, legendInteractive]);
|
|
4302
4242
|
const chartOptions = useMemo16(() => {
|
|
4303
4243
|
const formatter = options?.axis?.x?.tickFormat || getFormatter(dataSorted);
|
|
4304
4244
|
return {
|
|
@@ -4327,10 +4267,13 @@ var AreaChartInternal = /* @__PURE__ */ forwardRef5(({
|
|
|
4327
4267
|
nice: true,
|
|
4328
4268
|
// Stacked areas should always include zero so the baseline is meaningful.
|
|
4329
4269
|
zero: stacked,
|
|
4270
|
+
...fixedYDomain ? {
|
|
4271
|
+
domain: fixedYDomain
|
|
4272
|
+
} : {},
|
|
4330
4273
|
...options?.yScale
|
|
4331
4274
|
}
|
|
4332
4275
|
};
|
|
4333
|
-
}, [options, dataSorted, width, stacked]);
|
|
4276
|
+
}, [options, dataSorted, width, stacked, fixedYDomain]);
|
|
4334
4277
|
const defaultMargin = useChartMargin(height, chartOptions, dataSorted, theme);
|
|
4335
4278
|
const error = validateData2(dataSorted);
|
|
4336
4279
|
const isDataValid = !error;
|
|
@@ -4353,10 +4296,33 @@ var AreaChartInternal = /* @__PURE__ */ forwardRef5(({
|
|
|
4353
4296
|
metadata: chartMetadata
|
|
4354
4297
|
});
|
|
4355
4298
|
const prefersReducedMotion = usePrefersReducedMotion();
|
|
4299
|
+
const animationEnabled = !!animation && !prefersReducedMotion;
|
|
4356
4300
|
const accessors = {
|
|
4357
4301
|
xAccessor: (d) => d?.date,
|
|
4358
4302
|
yAccessor: (d) => d?.value
|
|
4359
4303
|
};
|
|
4304
|
+
const zeroYAccessor = useCallback9(() => 0, []);
|
|
4305
|
+
const visibleLabels = useMemo16(() => new Set(seriesWithVisibility.filter((s) => s.isVisible).map((s) => s.series.label)), [seriesWithVisibility]);
|
|
4306
|
+
const filteredRenderTooltip = useCallback9((params) => {
|
|
4307
|
+
if (!legendInteractive) return renderTooltip(params);
|
|
4308
|
+
const datumByKey = params?.tooltipData?.datumByKey;
|
|
4309
|
+
if (!datumByKey) return renderTooltip(params);
|
|
4310
|
+
const filtered = Object.fromEntries(Object.entries(datumByKey).filter(([key]) => visibleLabels.has(key)));
|
|
4311
|
+
if (Object.keys(filtered).length === 0) return null;
|
|
4312
|
+
const nearestDatum = params?.tooltipData?.nearestDatum;
|
|
4313
|
+
const nextNearest = nearestDatum && visibleLabels.has(nearestDatum.key) ? nearestDatum : {
|
|
4314
|
+
...Object.values(filtered)[0],
|
|
4315
|
+
distance: nearestDatum?.distance ?? 0
|
|
4316
|
+
};
|
|
4317
|
+
return renderTooltip({
|
|
4318
|
+
...params,
|
|
4319
|
+
tooltipData: {
|
|
4320
|
+
...params.tooltipData,
|
|
4321
|
+
datumByKey: filtered,
|
|
4322
|
+
nearestDatum: nextNearest
|
|
4323
|
+
}
|
|
4324
|
+
});
|
|
4325
|
+
}, [renderTooltip, legendInteractive, visibleLabels]);
|
|
4360
4326
|
const resolvedFillOpacity = fillOpacity ?? (stacked ? 0.85 : 0.4);
|
|
4361
4327
|
const resolvedWithStroke = withStroke ?? !stacked;
|
|
4362
4328
|
if (error) {
|
|
@@ -4382,6 +4348,35 @@ var AreaChartInternal = /* @__PURE__ */ forwardRef5(({
|
|
|
4382
4348
|
isVisible
|
|
4383
4349
|
}) => isVisible);
|
|
4384
4350
|
const curve = getCurveType(curveType, smoothing);
|
|
4351
|
+
const renderSeries = ({
|
|
4352
|
+
series: seriesData,
|
|
4353
|
+
index,
|
|
4354
|
+
isVisible
|
|
4355
|
+
}) => {
|
|
4356
|
+
const {
|
|
4357
|
+
color,
|
|
4358
|
+
lineStyles
|
|
4359
|
+
} = getElementStyles({
|
|
4360
|
+
data: seriesData,
|
|
4361
|
+
index
|
|
4362
|
+
});
|
|
4363
|
+
return /* @__PURE__ */ _jsx17(AnimatedAreaSeries, {
|
|
4364
|
+
dataKey: seriesData?.label,
|
|
4365
|
+
data: seriesData.data,
|
|
4366
|
+
xAccessor: accessors.xAccessor,
|
|
4367
|
+
yAccessor: isVisible || !legendInteractive ? accessors.yAccessor : zeroYAccessor,
|
|
4368
|
+
fill: color,
|
|
4369
|
+
fillOpacity: resolvedFillOpacity,
|
|
4370
|
+
...stacked ? {} : {
|
|
4371
|
+
renderLine: resolvedWithStroke,
|
|
4372
|
+
curve
|
|
4373
|
+
},
|
|
4374
|
+
lineProps: {
|
|
4375
|
+
stroke: color,
|
|
4376
|
+
...lineStyles
|
|
4377
|
+
}
|
|
4378
|
+
}, seriesData?.label || index);
|
|
4379
|
+
};
|
|
4385
4380
|
return /* @__PURE__ */ _jsx17(SingleChartContext.Provider, {
|
|
4386
4381
|
value: {
|
|
4387
4382
|
chartId,
|
|
@@ -4395,7 +4390,7 @@ var AreaChartInternal = /* @__PURE__ */ forwardRef5(({
|
|
|
4395
4390
|
legendChildren,
|
|
4396
4391
|
gap,
|
|
4397
4392
|
className: clsx5("area-chart", area_chart_module_default["area-chart"], {
|
|
4398
|
-
[area_chart_module_default["area-chart--animated"]]:
|
|
4393
|
+
[area_chart_module_default["area-chart--animated"]]: animationEnabled
|
|
4399
4394
|
}, className),
|
|
4400
4395
|
style: {
|
|
4401
4396
|
width,
|
|
@@ -4444,63 +4439,17 @@ var AreaChartInternal = /* @__PURE__ */ forwardRef5(({
|
|
|
4444
4439
|
width,
|
|
4445
4440
|
height: chartHeight,
|
|
4446
4441
|
children: __4("All series are hidden. Click legend items to show data.", "jetpack-charts")
|
|
4447
|
-
}) : null, !allSeriesHidden && stacked && /* @__PURE__ */ _jsx17(
|
|
4442
|
+
}) : null, !allSeriesHidden && stacked && /* @__PURE__ */ _jsx17(AnimatedAreaStack, {
|
|
4448
4443
|
curve,
|
|
4449
4444
|
offset: stackOffset,
|
|
4450
4445
|
renderLine: resolvedWithStroke,
|
|
4451
|
-
children:
|
|
4452
|
-
|
|
4453
|
-
index
|
|
4454
|
-
}) => {
|
|
4455
|
-
const {
|
|
4456
|
-
color,
|
|
4457
|
-
lineStyles
|
|
4458
|
-
} = getElementStyles({
|
|
4459
|
-
data: seriesData,
|
|
4460
|
-
index
|
|
4461
|
-
});
|
|
4462
|
-
return /* @__PURE__ */ _jsx17(AreaSeries2, {
|
|
4463
|
-
dataKey: seriesData?.label,
|
|
4464
|
-
data: seriesData.data,
|
|
4465
|
-
...accessors,
|
|
4466
|
-
fill: color,
|
|
4467
|
-
fillOpacity: resolvedFillOpacity,
|
|
4468
|
-
lineProps: {
|
|
4469
|
-
stroke: color,
|
|
4470
|
-
...lineStyles
|
|
4471
|
-
}
|
|
4472
|
-
}, seriesData?.label || index);
|
|
4473
|
-
})
|
|
4474
|
-
}), !allSeriesHidden && !stacked && visibleSeries.map(({
|
|
4475
|
-
series: seriesData,
|
|
4476
|
-
index
|
|
4477
|
-
}) => {
|
|
4478
|
-
const {
|
|
4479
|
-
color,
|
|
4480
|
-
lineStyles
|
|
4481
|
-
} = getElementStyles({
|
|
4482
|
-
data: seriesData,
|
|
4483
|
-
index
|
|
4484
|
-
});
|
|
4485
|
-
return /* @__PURE__ */ _jsx17(AreaSeries2, {
|
|
4486
|
-
dataKey: seriesData?.label,
|
|
4487
|
-
data: seriesData.data,
|
|
4488
|
-
...accessors,
|
|
4489
|
-
fill: color,
|
|
4490
|
-
fillOpacity: resolvedFillOpacity,
|
|
4491
|
-
renderLine: resolvedWithStroke,
|
|
4492
|
-
curve,
|
|
4493
|
-
lineProps: {
|
|
4494
|
-
stroke: color,
|
|
4495
|
-
...lineStyles
|
|
4496
|
-
}
|
|
4497
|
-
}, seriesData?.label || index);
|
|
4498
|
-
}), withTooltips && /* @__PURE__ */ _jsxs7(_Fragment4, {
|
|
4446
|
+
children: seriesWithVisibility.map(renderSeries)
|
|
4447
|
+
}), !allSeriesHidden && !stacked && seriesWithVisibility.map(renderSeries), withTooltips && /* @__PURE__ */ _jsxs7(_Fragment4, {
|
|
4499
4448
|
children: [/* @__PURE__ */ _jsx17(AccessibleTooltip, {
|
|
4500
4449
|
detectBounds: true,
|
|
4501
4450
|
snapTooltipToDatumX: true,
|
|
4502
4451
|
snapTooltipToDatumY: !stacked,
|
|
4503
|
-
renderTooltip,
|
|
4452
|
+
renderTooltip: filteredRenderTooltip,
|
|
4504
4453
|
showVerticalCrosshair: withTooltipCrosshairs?.showVertical,
|
|
4505
4454
|
showHorizontalCrosshair: withTooltipCrosshairs?.showHorizontal,
|
|
4506
4455
|
selectedIndex,
|
|
@@ -5332,7 +5281,7 @@ var BarListChartResponsive = withResponsive(BarListChart);
|
|
|
5332
5281
|
// src/charts/conversion-funnel-chart/conversion-funnel-chart.tsx
|
|
5333
5282
|
import { useTooltip, useTooltipInPortal } from "@visx/tooltip";
|
|
5334
5283
|
import clsx7 from "clsx";
|
|
5335
|
-
import { useRef as useRef12, useMemo as useMemo20, useEffect as
|
|
5284
|
+
import { useRef as useRef12, useMemo as useMemo20, useEffect as useEffect10, useCallback as useCallback12, useContext as useContext17 } from "react";
|
|
5336
5285
|
|
|
5337
5286
|
// src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss
|
|
5338
5287
|
var conversion_funnel_chart_module_default = {
|
|
@@ -5542,7 +5491,7 @@ var ConversionFunnelChartInternal = ({
|
|
|
5542
5491
|
});
|
|
5543
5492
|
return handlers;
|
|
5544
5493
|
}, [steps, handleStepInteraction, handleBarKeyDown]);
|
|
5545
|
-
|
|
5494
|
+
useEffect10(() => {
|
|
5546
5495
|
const handleDocumentClick = (event) => {
|
|
5547
5496
|
if (selectedBarRef.current && !selectedBarRef.current.contains(event.target)) {
|
|
5548
5497
|
clearSelectionAndRef();
|
|
@@ -5922,14 +5871,14 @@ var GeoChartResponsive = withResponsive(GeoChartWithProvider);
|
|
|
5922
5871
|
// ../../../node_modules/.pnpm/@wordpress+components@32.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@wordpress/components/build-module/utils/hooks/use-update-effect.mjs
|
|
5923
5872
|
function useUpdateEffect(effect, deps) {
|
|
5924
5873
|
const mountedRef = useRef5(false);
|
|
5925
|
-
|
|
5874
|
+
useEffect4(() => {
|
|
5926
5875
|
if (mountedRef.current) {
|
|
5927
5876
|
return effect();
|
|
5928
5877
|
}
|
|
5929
5878
|
mountedRef.current = true;
|
|
5930
5879
|
return void 0;
|
|
5931
5880
|
}, deps);
|
|
5932
|
-
|
|
5881
|
+
useEffect4(() => () => {
|
|
5933
5882
|
mountedRef.current = false;
|
|
5934
5883
|
}, []);
|
|
5935
5884
|
}
|
|
@@ -7946,7 +7895,7 @@ var useBreakpointIndex = (options = {}) => {
|
|
|
7946
7895
|
throw new RangeError(`Default breakpoint index out of range. Theme has ${breakpoints.length} breakpoints, got index ${defaultIndex}`);
|
|
7947
7896
|
}
|
|
7948
7897
|
const [value, setValue] = useState5(defaultIndex);
|
|
7949
|
-
|
|
7898
|
+
useEffect4(() => {
|
|
7950
7899
|
const getIndex = () => breakpoints.filter((bp) => {
|
|
7951
7900
|
return typeof window !== "undefined" ? window.matchMedia(`screen and (min-width: ${bp})`).matches : false;
|
|
7952
7901
|
}).length;
|