@coinbase/cds-web-visualization 0.0.0 → 3.4.0-beta.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 +26 -0
- package/README.md +3 -0
- package/dts/chart/CartesianChart.d.ts +36 -0
- package/dts/chart/CartesianChart.d.ts.map +1 -0
- package/dts/chart/ChartProvider.d.ts +6 -0
- package/dts/chart/ChartProvider.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +34 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +61 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/Point.d.ts +153 -0
- package/dts/chart/Point.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +48 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +52 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +68 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +30 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +8 -0
- package/dts/chart/area/SolidArea.d.ts.map +1 -0
- package/dts/chart/area/index.d.ts +6 -0
- package/dts/chart/area/index.d.ts.map +1 -0
- package/dts/chart/axis/Axis.d.ts +208 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- package/dts/chart/axis/XAxis.d.ts +16 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -0
- package/dts/chart/axis/YAxis.d.ts +21 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -0
- package/dts/chart/axis/index.d.ts +4 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +91 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +53 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +29 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +111 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +35 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBar.d.ts +17 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +16 -0
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
- package/dts/chart/bar/index.d.ts +8 -0
- package/dts/chart/bar/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +13 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +14 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/GradientLine.d.ts +42 -0
- package/dts/chart/line/GradientLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +80 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +59 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +131 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +14 -0
- package/dts/chart/line/SolidLine.d.ts.map +1 -0
- package/dts/chart/line/index.d.ts +7 -0
- package/dts/chart/line/index.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +149 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +93 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +7 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +2 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +114 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts +55 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +3 -0
- package/dts/chart/text/index.d.ts.map +1 -0
- package/dts/chart/utils/axis.d.ts +342 -0
- package/dts/chart/utils/axis.d.ts.map +1 -0
- package/dts/chart/utils/bar.d.ts +20 -0
- package/dts/chart/utils/bar.d.ts.map +1 -0
- package/dts/chart/utils/chart.d.ts +97 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +95 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +8 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +107 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +75 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +43 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/index.d.ts +3 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +8 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +67 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +15 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +14 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +23 -0
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -0
- package/dts/sparkline/SparklinePath.d.ts +12 -0
- package/dts/sparkline/SparklinePath.d.ts.map +1 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +2 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +11 -0
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -0
- package/dts/sparkline/index.d.ts +6 -0
- package/dts/sparkline/index.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +199 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +8 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +30 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +18 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +31 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +112 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +1 -0
- package/esm/chart/CartesianChart.css +1 -0
- package/esm/chart/CartesianChart.js +258 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +89 -0
- package/esm/chart/PeriodSelector.css +1 -0
- package/esm/chart/PeriodSelector.js +126 -0
- package/esm/chart/Point.css +2 -0
- package/esm/chart/Point.js +171 -0
- package/esm/chart/area/Area.js +85 -0
- package/esm/chart/area/AreaChart.js +164 -0
- package/esm/chart/area/DottedArea.js +141 -0
- package/esm/chart/area/GradientArea.js +111 -0
- package/esm/chart/area/SolidArea.js +29 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +46 -0
- package/esm/chart/axis/XAxis.css +2 -0
- package/esm/chart/axis/XAxis.js +195 -0
- package/esm/chart/axis/YAxis.css +2 -0
- package/esm/chart/axis/YAxis.js +183 -0
- package/esm/chart/axis/index.js +5 -0
- package/esm/chart/bar/Bar.js +59 -0
- package/esm/chart/bar/BarChart.js +147 -0
- package/esm/chart/bar/BarPlot.js +96 -0
- package/esm/chart/bar/BarStack.js +519 -0
- package/esm/chart/bar/BarStackGroup.js +96 -0
- package/esm/chart/bar/DefaultBar.js +64 -0
- package/esm/chart/bar/DefaultBarStack.js +60 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/index.js +14 -0
- package/esm/chart/line/DottedLine.js +38 -0
- package/esm/chart/line/GradientLine.js +58 -0
- package/esm/chart/line/Line.js +159 -0
- package/esm/chart/line/LineChart.js +120 -0
- package/esm/chart/line/ReferenceLine.js +142 -0
- package/esm/chart/line/SolidLine.js +34 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/scrubber/Scrubber.js +483 -0
- package/esm/chart/scrubber/ScrubberBeacon.js +195 -0
- package/esm/chart/scrubber/ScrubberBeaconLabel.js +33 -0
- package/esm/chart/scrubber/ScrubberProvider.js +228 -0
- package/esm/chart/scrubber/index.js +2 -0
- package/esm/chart/text/ChartText.js +236 -0
- package/esm/chart/text/SmartChartTextGroup.js +226 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +593 -0
- package/esm/chart/utils/bar.js +24 -0
- package/esm/chart/utils/chart.js +229 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/index.js +9 -0
- package/esm/chart/utils/path.js +204 -0
- package/esm/chart/utils/point.js +118 -0
- package/esm/chart/utils/scale.js +48 -0
- package/esm/index.js +4 -0
- package/esm/sparkline/Counter.css +3 -0
- package/esm/sparkline/Counter.js +35 -0
- package/esm/sparkline/Sparkline.js +164 -0
- package/esm/sparkline/SparklineArea.js +18 -0
- package/esm/sparkline/SparklineAreaPattern.js +37 -0
- package/esm/sparkline/SparklineGradient.js +30 -0
- package/esm/sparkline/SparklinePath.js +19 -0
- package/esm/sparkline/__figma__/Sparkline.figma.js +24 -0
- package/esm/sparkline/generateSparklineWithId.js +7 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.js +21 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +317 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +108 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +26 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.js +24 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.css +4 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +65 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.css +1 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +80 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +56 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +70 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +45 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.css +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.js +199 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.js +39 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +92 -0
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +89 -0
- package/esm/sparkline/sparkline-interactive/fade.css +2 -0
- package/esm/sparkline/sparkline-interactive/fade.js +14 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +28 -0
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +225 -0
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +108 -0
- package/package.json +68 -6
- package/index.js +0 -1
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
import React, { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
7
|
+
import { useRefMap } from '@coinbase/cds-common/hooks/useRefMap';
|
|
8
|
+
import { m as motion } from 'framer-motion';
|
|
9
|
+
import { axisTickLabelsInitialAnimationVariants } from '../axis';
|
|
10
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
11
|
+
import { ReferenceLine } from '../line';
|
|
12
|
+
import { getPointOnScale, useScrubberContext } from '../utils';
|
|
13
|
+
import { ScrubberBeacon } from './ScrubberBeacon';
|
|
14
|
+
import { ScrubberBeaconLabel } from './ScrubberBeaconLabel';
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
const minGap = 2;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for scrubber functionality across chart components.
|
|
20
|
+
* Provides consistent API with smart defaults and component customization.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Unified component that manages all scrubber elements (beacons, line, labels)
|
|
25
|
+
* with intelligent collision detection and consistent positioning.
|
|
26
|
+
*/
|
|
27
|
+
export const Scrubber = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
28
|
+
let {
|
|
29
|
+
seriesIds,
|
|
30
|
+
hideLine,
|
|
31
|
+
label,
|
|
32
|
+
lineStroke,
|
|
33
|
+
labelProps,
|
|
34
|
+
BeaconComponent,
|
|
35
|
+
BeaconLabelComponent,
|
|
36
|
+
LineComponent,
|
|
37
|
+
hideOverlay,
|
|
38
|
+
overlayOffset = 2,
|
|
39
|
+
testID,
|
|
40
|
+
idlePulse,
|
|
41
|
+
styles,
|
|
42
|
+
classNames
|
|
43
|
+
} = _ref;
|
|
44
|
+
const scrubberGroupRef = useRef(null);
|
|
45
|
+
const ScrubberBeaconRefs = useRefMap();
|
|
46
|
+
const {
|
|
47
|
+
scrubberPosition
|
|
48
|
+
} = useScrubberContext();
|
|
49
|
+
const {
|
|
50
|
+
getXScale,
|
|
51
|
+
getYScale,
|
|
52
|
+
getSeriesData,
|
|
53
|
+
getXAxis,
|
|
54
|
+
animate,
|
|
55
|
+
series,
|
|
56
|
+
drawingArea
|
|
57
|
+
} = useCartesianChartContext();
|
|
58
|
+
const getStackedSeriesData = getSeriesData; // getSeriesData now returns stacked data
|
|
59
|
+
|
|
60
|
+
// Track label dimensions for collision detection
|
|
61
|
+
const [labelDimensions, setLabelDimensions] = useState(new Map());
|
|
62
|
+
|
|
63
|
+
// Expose imperative handle with pulse method
|
|
64
|
+
useImperativeHandle(ref, () => ({
|
|
65
|
+
pulse: () => {
|
|
66
|
+
// Pulse all registered scrubber beacons
|
|
67
|
+
Object.values(ScrubberBeaconRefs.refs).forEach(beaconRef => {
|
|
68
|
+
beaconRef === null || beaconRef === void 0 || beaconRef.pulse();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
const {
|
|
73
|
+
dataX,
|
|
74
|
+
dataIndex
|
|
75
|
+
} = useMemo(() => {
|
|
76
|
+
var _series$reduce;
|
|
77
|
+
const xScale = getXScale();
|
|
78
|
+
const xAxis = getXAxis();
|
|
79
|
+
if (!xScale) return {
|
|
80
|
+
dataX: undefined,
|
|
81
|
+
dataIndex: undefined
|
|
82
|
+
};
|
|
83
|
+
const maxDataLength = (_series$reduce = series === null || series === void 0 ? void 0 : series.reduce((max, s) => {
|
|
84
|
+
var _seriesData$length;
|
|
85
|
+
const seriesData = getStackedSeriesData(s.id) || getSeriesData(s.id);
|
|
86
|
+
return Math.max(max, (_seriesData$length = seriesData === null || seriesData === void 0 ? void 0 : seriesData.length) !== null && _seriesData$length !== void 0 ? _seriesData$length : 0);
|
|
87
|
+
}, 0)) !== null && _series$reduce !== void 0 ? _series$reduce : 0;
|
|
88
|
+
const dataIndex = scrubberPosition !== null && scrubberPosition !== void 0 ? scrubberPosition : Math.max(0, maxDataLength - 1);
|
|
89
|
+
|
|
90
|
+
// Convert index to actual x value if axis has data
|
|
91
|
+
let dataX;
|
|
92
|
+
if (xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && xAxis.data[dataIndex] !== undefined) {
|
|
93
|
+
const dataValue = xAxis.data[dataIndex];
|
|
94
|
+
dataX = typeof dataValue === 'string' ? dataIndex : dataValue;
|
|
95
|
+
} else {
|
|
96
|
+
dataX = dataIndex;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
dataX,
|
|
100
|
+
dataIndex
|
|
101
|
+
};
|
|
102
|
+
}, [getXScale, getXAxis, series, scrubberPosition, getStackedSeriesData, getSeriesData]);
|
|
103
|
+
const beaconPositions = useMemo(() => {
|
|
104
|
+
var _series$filter$map$fi, _series$filter;
|
|
105
|
+
const xScale = getXScale();
|
|
106
|
+
if (!xScale || dataX === undefined || dataIndex === undefined) return [];
|
|
107
|
+
return (_series$filter$map$fi = series === null || series === void 0 || (_series$filter = series.filter(s => {
|
|
108
|
+
if (seriesIds === undefined) return true;
|
|
109
|
+
return seriesIds.includes(s.id);
|
|
110
|
+
})) === null || _series$filter === void 0 ? void 0 : _series$filter.map(s => {
|
|
111
|
+
const sourceData = getStackedSeriesData(s.id) || getSeriesData(s.id);
|
|
112
|
+
|
|
113
|
+
// Use dataIndex to get the y value from the series data array
|
|
114
|
+
const stuff = sourceData === null || sourceData === void 0 ? void 0 : sourceData[dataIndex];
|
|
115
|
+
let dataY;
|
|
116
|
+
if (Array.isArray(stuff)) {
|
|
117
|
+
dataY = stuff[stuff.length - 1];
|
|
118
|
+
} else if (typeof stuff === 'number') {
|
|
119
|
+
dataY = stuff;
|
|
120
|
+
}
|
|
121
|
+
if (dataY !== undefined) {
|
|
122
|
+
const yScale = getYScale(s.yAxisId);
|
|
123
|
+
if (!yScale) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const pixelY = getPointOnScale(dataY, yScale);
|
|
127
|
+
const resolvedLabel = typeof s.label === 'function' ? s.label(dataIndex) : s.label;
|
|
128
|
+
return {
|
|
129
|
+
x: dataX,
|
|
130
|
+
y: dataY,
|
|
131
|
+
label: resolvedLabel,
|
|
132
|
+
pixelY,
|
|
133
|
+
targetSeries: s
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}).filter(beacon => beacon !== undefined)) !== null && _series$filter$map$fi !== void 0 ? _series$filter$map$fi : [];
|
|
137
|
+
}, [getXScale, dataX, dataIndex, series, seriesIds, getStackedSeriesData, getSeriesData, getYScale]);
|
|
138
|
+
const labelVerticalInset = 2;
|
|
139
|
+
const labelHorizontalInset = 4;
|
|
140
|
+
|
|
141
|
+
// Calculate optimal label positioning strategy
|
|
142
|
+
const labelPositioning = useMemo(() => {
|
|
143
|
+
// Get current beacon IDs that are actually being rendered
|
|
144
|
+
const currentBeaconIds = new Set(beaconPositions.map(beacon => beacon === null || beacon === void 0 ? void 0 : beacon.targetSeries.id).filter(Boolean));
|
|
145
|
+
|
|
146
|
+
// Only use dimensions for beacons that are currently being rendered
|
|
147
|
+
const dimensions = Array.from(labelDimensions.values()).filter(dim => currentBeaconIds.has(dim.id));
|
|
148
|
+
if (dimensions.length === 0) return {
|
|
149
|
+
strategy: 'auto',
|
|
150
|
+
adjustments: new Map()
|
|
151
|
+
};
|
|
152
|
+
const adjustments = new Map();
|
|
153
|
+
|
|
154
|
+
// Sort by Y position to handle overlaps systematically
|
|
155
|
+
const sortedDimensions = [...dimensions].sort((a, b) => a.preferredY - b.preferredY);
|
|
156
|
+
|
|
157
|
+
// Determine if we need to switch sides globally based on overflow
|
|
158
|
+
let globalSide = 'right';
|
|
159
|
+
const anchorRadius = 10; // Same as used in ScrubberBeaconLabel
|
|
160
|
+
const bufferPx = 5; // Small buffer to prevent premature switching
|
|
161
|
+
|
|
162
|
+
// Safety check for valid bounds
|
|
163
|
+
if (drawingArea.width <= 0 || drawingArea.height <= 0) {
|
|
164
|
+
globalSide = 'right'; // Default to right if bounds are invalid
|
|
165
|
+
} else {
|
|
166
|
+
// Check if labels would overflow when positioned on the right side
|
|
167
|
+
// Account for anchor radius and padding when calculating right edge
|
|
168
|
+
const wouldOverflow = sortedDimensions.some(dim => {
|
|
169
|
+
const labelRightEdge = dim.preferredX + anchorRadius + labelHorizontalInset + dim.width + bufferPx;
|
|
170
|
+
return labelRightEdge > drawingArea.x + drawingArea.width;
|
|
171
|
+
});
|
|
172
|
+
globalSide = wouldOverflow ? 'left' : 'right';
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Initialize all labels at their preferred positions
|
|
176
|
+
for (const dim of sortedDimensions) {
|
|
177
|
+
adjustments.set(dim.id, {
|
|
178
|
+
x: dim.preferredX,
|
|
179
|
+
y: dim.preferredY,
|
|
180
|
+
side: globalSide
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Check for collisions and resolve them
|
|
185
|
+
const maxIterations = 10;
|
|
186
|
+
let iteration = 0;
|
|
187
|
+
while (iteration < maxIterations) {
|
|
188
|
+
let hasCollisions = false;
|
|
189
|
+
iteration++;
|
|
190
|
+
|
|
191
|
+
// Sort by current Y position for systematic collision resolution
|
|
192
|
+
const currentPositions = sortedDimensions.map(dim => _objectSpread(_objectSpread({}, dim), {}, {
|
|
193
|
+
currentY: adjustments.get(dim.id).y
|
|
194
|
+
})).sort((a, b) => a.currentY - b.currentY);
|
|
195
|
+
|
|
196
|
+
// Check adjacent labels for overlaps
|
|
197
|
+
for (let i = 0; i < currentPositions.length - 1; i++) {
|
|
198
|
+
const current = currentPositions[i];
|
|
199
|
+
const next = currentPositions[i + 1];
|
|
200
|
+
const currentAdjustment = adjustments.get(current.id);
|
|
201
|
+
const nextAdjustment = adjustments.get(next.id);
|
|
202
|
+
|
|
203
|
+
// Calculate required separation
|
|
204
|
+
const requiredSeparation = current.height / 2 + next.height / 2 + minGap;
|
|
205
|
+
const currentSeparation = nextAdjustment.y - currentAdjustment.y;
|
|
206
|
+
if (currentSeparation < requiredSeparation) {
|
|
207
|
+
hasCollisions = true;
|
|
208
|
+
const deficit = requiredSeparation - currentSeparation;
|
|
209
|
+
|
|
210
|
+
// Move labels apart - split the adjustment
|
|
211
|
+
const offsetPerLabel = deficit / 2;
|
|
212
|
+
adjustments.set(current.id, _objectSpread(_objectSpread({}, currentAdjustment), {}, {
|
|
213
|
+
y: currentAdjustment.y - offsetPerLabel
|
|
214
|
+
}));
|
|
215
|
+
adjustments.set(next.id, _objectSpread(_objectSpread({}, nextAdjustment), {}, {
|
|
216
|
+
y: nextAdjustment.y + offsetPerLabel
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (!hasCollisions) {
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// After collision resolution, ensure all labels are within bounds
|
|
226
|
+
const labelIds = Array.from(adjustments.keys());
|
|
227
|
+
|
|
228
|
+
// Group labels that are close together or overlapping
|
|
229
|
+
// This prevents distant labels from being unnecessarily shifted
|
|
230
|
+
const findConnectedGroups = () => {
|
|
231
|
+
const groups = [];
|
|
232
|
+
const visited = new Set();
|
|
233
|
+
for (const id of labelIds) {
|
|
234
|
+
if (visited.has(id)) continue;
|
|
235
|
+
const group = [id];
|
|
236
|
+
visited.add(id);
|
|
237
|
+
const queue = [id];
|
|
238
|
+
while (queue.length > 0) {
|
|
239
|
+
const currentId = queue.shift();
|
|
240
|
+
const currentAdjustment = adjustments.get(currentId);
|
|
241
|
+
const currentDim = sortedDimensions.find(d => d.id === currentId);
|
|
242
|
+
|
|
243
|
+
// Check if this label overlaps or is close to any other unvisited label
|
|
244
|
+
for (const otherId of labelIds) {
|
|
245
|
+
if (visited.has(otherId)) continue;
|
|
246
|
+
const otherAdjustment = adjustments.get(otherId);
|
|
247
|
+
const otherDim = sortedDimensions.find(d => d.id === otherId);
|
|
248
|
+
|
|
249
|
+
// Calculate distance between labels
|
|
250
|
+
const distance = Math.abs(currentAdjustment.y - otherAdjustment.y);
|
|
251
|
+
const minDistance = (currentDim.height + otherDim.height) / 2 + minGap * 2;
|
|
252
|
+
|
|
253
|
+
// Labels are considered connected if they're close enough to potentially overlap
|
|
254
|
+
if (distance <= minDistance) {
|
|
255
|
+
visited.add(otherId);
|
|
256
|
+
group.push(otherId);
|
|
257
|
+
queue.push(otherId);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
groups.push(group);
|
|
262
|
+
}
|
|
263
|
+
return groups;
|
|
264
|
+
};
|
|
265
|
+
const connectedGroups = findConnectedGroups();
|
|
266
|
+
|
|
267
|
+
// Process each connected group independently
|
|
268
|
+
for (const groupIds of connectedGroups) {
|
|
269
|
+
// Check if any labels in this group are outside bounds
|
|
270
|
+
const groupOutOfBounds = groupIds.some(id => {
|
|
271
|
+
const adjustment = adjustments.get(id);
|
|
272
|
+
const dim = sortedDimensions.find(d => d.id === id);
|
|
273
|
+
const labelTop = adjustment.y - dim.height / 2;
|
|
274
|
+
const labelBottom = adjustment.y + dim.height / 2;
|
|
275
|
+
return labelTop < drawingArea.y || labelBottom > drawingArea.y + drawingArea.height;
|
|
276
|
+
});
|
|
277
|
+
if (groupOutOfBounds) {
|
|
278
|
+
// Get labels in this group sorted by their preferred Y position
|
|
279
|
+
const groupLabels = groupIds.map(id => ({
|
|
280
|
+
id,
|
|
281
|
+
dim: sortedDimensions.find(d => d.id === id),
|
|
282
|
+
preferredY: sortedDimensions.find(d => d.id === id).preferredY,
|
|
283
|
+
currentY: adjustments.get(id).y
|
|
284
|
+
})).sort((a, b) => a.preferredY - b.preferredY);
|
|
285
|
+
|
|
286
|
+
// Calculate total height needed for this group
|
|
287
|
+
const totalLabelHeight = groupLabels.reduce((sum, label) => sum + label.dim.height, 0);
|
|
288
|
+
const totalGaps = (groupLabels.length - 1) * minGap;
|
|
289
|
+
const totalNeeded = totalLabelHeight + totalGaps;
|
|
290
|
+
if (totalNeeded > drawingArea.height) {
|
|
291
|
+
// Not enough space - use compressed equal spacing as fallback
|
|
292
|
+
const compressedGap = Math.max(2, (drawingArea.height - totalLabelHeight) / Math.max(1, groupLabels.length - 1));
|
|
293
|
+
let currentY = drawingArea.y + groupLabels[0].dim.height / 2;
|
|
294
|
+
for (const label of groupLabels) {
|
|
295
|
+
adjustments.set(label.id, _objectSpread(_objectSpread({}, adjustments.get(label.id)), {}, {
|
|
296
|
+
y: currentY
|
|
297
|
+
}));
|
|
298
|
+
currentY += label.dim.height + compressedGap;
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
// Enough space - use minimal displacement algorithm for this group
|
|
302
|
+
const finalPositions = [...groupLabels];
|
|
303
|
+
|
|
304
|
+
// Ensure minimum spacing between adjacent labels in this group
|
|
305
|
+
for (let i = 1; i < finalPositions.length; i++) {
|
|
306
|
+
const prev = finalPositions[i - 1];
|
|
307
|
+
const current = finalPositions[i];
|
|
308
|
+
|
|
309
|
+
// Calculate minimum Y position for current label
|
|
310
|
+
const minCurrentY = prev.preferredY + prev.dim.height / 2 + minGap + current.dim.height / 2;
|
|
311
|
+
if (current.preferredY < minCurrentY) {
|
|
312
|
+
// Need to push this label down
|
|
313
|
+
current.preferredY = minCurrentY;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Check if this specific group fits within bounds, if not shift only this group
|
|
318
|
+
const groupTop = finalPositions[0].preferredY - finalPositions[0].dim.height / 2;
|
|
319
|
+
const groupBottom = finalPositions[finalPositions.length - 1].preferredY + finalPositions[finalPositions.length - 1].dim.height / 2;
|
|
320
|
+
let shiftAmount = 0;
|
|
321
|
+
if (groupTop < drawingArea.y) {
|
|
322
|
+
// Group is too high, shift down
|
|
323
|
+
shiftAmount = drawingArea.y - groupTop;
|
|
324
|
+
} else if (groupBottom > drawingArea.y + drawingArea.height) {
|
|
325
|
+
// Group is too low, shift up
|
|
326
|
+
shiftAmount = drawingArea.y + drawingArea.height - groupBottom;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Apply final positions with shift only to this group
|
|
330
|
+
for (const label of finalPositions) {
|
|
331
|
+
const finalY = label.preferredY + shiftAmount;
|
|
332
|
+
|
|
333
|
+
// Final bounds check for individual labels
|
|
334
|
+
const clampedY = Math.max(drawingArea.y + label.dim.height / 2, Math.min(drawingArea.y + drawingArea.height - label.dim.height / 2, finalY));
|
|
335
|
+
adjustments.set(label.id, _objectSpread(_objectSpread({}, adjustments.get(label.id)), {}, {
|
|
336
|
+
y: clampedY
|
|
337
|
+
}));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
strategy: globalSide,
|
|
344
|
+
adjustments
|
|
345
|
+
};
|
|
346
|
+
}, [beaconPositions, labelDimensions, drawingArea]);
|
|
347
|
+
|
|
348
|
+
// Callback for labels to register their dimensions
|
|
349
|
+
const registerLabelDimensions = useCallback((id, width, height, x, y) => {
|
|
350
|
+
setLabelDimensions(prev => {
|
|
351
|
+
const existing = prev.get(id);
|
|
352
|
+
const newDimensions = {
|
|
353
|
+
id,
|
|
354
|
+
width,
|
|
355
|
+
height,
|
|
356
|
+
preferredX: x,
|
|
357
|
+
preferredY: y
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// Only update if dimensions actually changed
|
|
361
|
+
if (existing && existing.width === width && existing.height === height && existing.preferredX === x && existing.preferredY === y) {
|
|
362
|
+
return prev;
|
|
363
|
+
}
|
|
364
|
+
const next = new Map(prev);
|
|
365
|
+
next.set(id, newDimensions);
|
|
366
|
+
return next;
|
|
367
|
+
});
|
|
368
|
+
}, []);
|
|
369
|
+
|
|
370
|
+
// Callback to create ref handlers for scrubber beacons
|
|
371
|
+
const createScrubberBeaconRef = useCallback(seriesId => {
|
|
372
|
+
return beaconRef => {
|
|
373
|
+
if (beaconRef) {
|
|
374
|
+
ScrubberBeaconRefs.registerRef(seriesId, beaconRef);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}, [ScrubberBeaconRefs]);
|
|
378
|
+
|
|
379
|
+
// synchronize label positioning state when the position of any scrubber beacons change
|
|
380
|
+
useEffect(() => {
|
|
381
|
+
const currentBeaconIds = new Set(beaconPositions.map(beacon => beacon === null || beacon === void 0 ? void 0 : beacon.targetSeries.id).filter(Boolean));
|
|
382
|
+
setLabelDimensions(prev => {
|
|
383
|
+
const next = new Map();
|
|
384
|
+
for (const [id, dimensions] of prev) {
|
|
385
|
+
if (currentBeaconIds.has(id)) {
|
|
386
|
+
next.set(id, dimensions);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return next;
|
|
390
|
+
});
|
|
391
|
+
}, [beaconPositions]);
|
|
392
|
+
|
|
393
|
+
// Check if we have at least the default X scale
|
|
394
|
+
const defaultXScale = getXScale();
|
|
395
|
+
if (!defaultXScale) return null;
|
|
396
|
+
|
|
397
|
+
// Use custom components if provided
|
|
398
|
+
const ScrubberLineComponent = LineComponent !== null && LineComponent !== void 0 ? LineComponent : ReferenceLine;
|
|
399
|
+
const ScrubberBeaconComponent = BeaconComponent !== null && BeaconComponent !== void 0 ? BeaconComponent : ScrubberBeacon;
|
|
400
|
+
const ScrubberBeaconLabelComponent = BeaconLabelComponent !== null && BeaconLabelComponent !== void 0 ? BeaconLabelComponent : ScrubberBeaconLabel;
|
|
401
|
+
const pixelX = dataX !== undefined && defaultXScale ? getPointOnScale(dataX, defaultXScale) : undefined;
|
|
402
|
+
return /*#__PURE__*/_jsxs(motion.g, _objectSpread(_objectSpread({
|
|
403
|
+
ref: scrubberGroupRef,
|
|
404
|
+
"data-component": "scrubber-group",
|
|
405
|
+
"data-testid": testID
|
|
406
|
+
}, animate ? {
|
|
407
|
+
animate: 'animate',
|
|
408
|
+
exit: 'exit',
|
|
409
|
+
initial: 'initial',
|
|
410
|
+
variants: axisTickLabelsInitialAnimationVariants
|
|
411
|
+
} : {}), {}, {
|
|
412
|
+
children: [!hideOverlay && dataX !== undefined && scrubberPosition !== undefined && pixelX !== undefined && /*#__PURE__*/_jsx("rect", {
|
|
413
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.overlay,
|
|
414
|
+
fill: "var(--color-bg)",
|
|
415
|
+
height: drawingArea.height + overlayOffset * 2,
|
|
416
|
+
opacity: 0.8,
|
|
417
|
+
style: styles === null || styles === void 0 ? void 0 : styles.overlay,
|
|
418
|
+
width: drawingArea.x + drawingArea.width - pixelX + overlayOffset,
|
|
419
|
+
x: pixelX,
|
|
420
|
+
y: drawingArea.y - overlayOffset
|
|
421
|
+
}), !hideLine && scrubberPosition !== undefined && dataX !== undefined && /*#__PURE__*/_jsx(ScrubberLineComponent, {
|
|
422
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.line,
|
|
423
|
+
dataX: dataX,
|
|
424
|
+
label: typeof label === 'function' ? label(dataIndex) : label,
|
|
425
|
+
labelProps: _objectSpread({
|
|
426
|
+
verticalAlignment: 'middle',
|
|
427
|
+
// Place in the middle vertically by default
|
|
428
|
+
dy: -0.5 * drawingArea.y
|
|
429
|
+
}, labelProps),
|
|
430
|
+
stroke: lineStroke,
|
|
431
|
+
style: styles === null || styles === void 0 ? void 0 : styles.line
|
|
432
|
+
}), beaconPositions.map(beacon => {
|
|
433
|
+
var _beacon$targetSeries, _beacon$targetSeries2;
|
|
434
|
+
if (!beacon) return null;
|
|
435
|
+
const adjustment = labelPositioning.adjustments.get(beacon.targetSeries.id);
|
|
436
|
+
const dotStroke = ((_beacon$targetSeries = beacon.targetSeries) === null || _beacon$targetSeries === void 0 ? void 0 : _beacon$targetSeries.color) || 'var(--color-fgPrimary)';
|
|
437
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
438
|
+
"data-component": "scrubber-beacon",
|
|
439
|
+
children: [/*#__PURE__*/_jsx(ScrubberBeaconComponent, {
|
|
440
|
+
ref: createScrubberBeaconRef(beacon.targetSeries.id),
|
|
441
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.beacon,
|
|
442
|
+
color: (_beacon$targetSeries2 = beacon.targetSeries) === null || _beacon$targetSeries2 === void 0 ? void 0 : _beacon$targetSeries2.color,
|
|
443
|
+
dataX: beacon.x,
|
|
444
|
+
dataY: beacon.y,
|
|
445
|
+
idlePulse: idlePulse,
|
|
446
|
+
seriesId: beacon.targetSeries.id,
|
|
447
|
+
style: styles === null || styles === void 0 ? void 0 : styles.beacon,
|
|
448
|
+
testID: testID ? "".concat(testID, "-").concat(beacon.targetSeries.id, "-dot") : undefined
|
|
449
|
+
}), beacon.label && pixelX !== undefined && ((_adjustment$x, _adjustment$y, _adjustment$side) => {
|
|
450
|
+
const finalAnchorX = (_adjustment$x = adjustment === null || adjustment === void 0 ? void 0 : adjustment.x) !== null && _adjustment$x !== void 0 ? _adjustment$x : pixelX;
|
|
451
|
+
const finalAnchorY = (_adjustment$y = adjustment === null || adjustment === void 0 ? void 0 : adjustment.y) !== null && _adjustment$y !== void 0 ? _adjustment$y : beacon.pixelY;
|
|
452
|
+
const finalSide = (_adjustment$side = adjustment === null || adjustment === void 0 ? void 0 : adjustment.side) !== null && _adjustment$side !== void 0 ? _adjustment$side : labelPositioning.strategy;
|
|
453
|
+
return /*#__PURE__*/_jsx(ScrubberBeaconLabelComponent, {
|
|
454
|
+
background: "var(--color-bg)",
|
|
455
|
+
bounds: drawingArea,
|
|
456
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.beaconLabel,
|
|
457
|
+
color: dotStroke,
|
|
458
|
+
dx: finalSide === 'right' ? 16 : -16,
|
|
459
|
+
horizontalAlignment: finalSide === 'right' ? 'left' : 'right',
|
|
460
|
+
inset: {
|
|
461
|
+
left: labelHorizontalInset,
|
|
462
|
+
right: labelHorizontalInset,
|
|
463
|
+
top: labelVerticalInset,
|
|
464
|
+
bottom: labelVerticalInset
|
|
465
|
+
},
|
|
466
|
+
onDimensionsChange: _ref2 => {
|
|
467
|
+
let {
|
|
468
|
+
width,
|
|
469
|
+
height
|
|
470
|
+
} = _ref2;
|
|
471
|
+
return registerLabelDimensions(beacon.targetSeries.id, width, height, pixelX, beacon.pixelY);
|
|
472
|
+
},
|
|
473
|
+
style: styles === null || styles === void 0 ? void 0 : styles.beaconLabel,
|
|
474
|
+
testID: testID ? "".concat(testID, "-").concat(beacon.targetSeries.id, "-label") : undefined,
|
|
475
|
+
x: finalAnchorX,
|
|
476
|
+
y: finalAnchorY,
|
|
477
|
+
children: beacon.label
|
|
478
|
+
});
|
|
479
|
+
})()]
|
|
480
|
+
}, beacon.targetSeries.id);
|
|
481
|
+
})]
|
|
482
|
+
}));
|
|
483
|
+
}));
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { forwardRef, memo, useImperativeHandle, useMemo } from 'react';
|
|
2
|
+
import { m as motion, useAnimate } from 'framer-motion';
|
|
3
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
4
|
+
import { projectPoint, useScrubberContext } from '../utils';
|
|
5
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
const pulseTransitionConfig = {
|
|
7
|
+
duration: 2,
|
|
8
|
+
repeat: Infinity,
|
|
9
|
+
ease: 'easeInOut'
|
|
10
|
+
};
|
|
11
|
+
const singlePulseTransitionConfig = {
|
|
12
|
+
duration: 1,
|
|
13
|
+
ease: 'easeInOut'
|
|
14
|
+
};
|
|
15
|
+
const radius = 5;
|
|
16
|
+
const glowRadius = 10;
|
|
17
|
+
const pulseRadius = 15;
|
|
18
|
+
/**
|
|
19
|
+
* The ScrubberBeacon is a special instance of a Point used to mark the scrubber's position on a specific series.
|
|
20
|
+
* It renders a glow effect around the point to highlight the scrubber position.
|
|
21
|
+
*/
|
|
22
|
+
export const ScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
23
|
+
var _ref2;
|
|
24
|
+
let {
|
|
25
|
+
seriesId,
|
|
26
|
+
dataX: dataXProp,
|
|
27
|
+
dataY: dataYProp,
|
|
28
|
+
color,
|
|
29
|
+
testID,
|
|
30
|
+
idlePulse,
|
|
31
|
+
opacity = 1,
|
|
32
|
+
className,
|
|
33
|
+
style
|
|
34
|
+
} = _ref;
|
|
35
|
+
const [scope, animate] = useAnimate();
|
|
36
|
+
const {
|
|
37
|
+
getSeries,
|
|
38
|
+
getXScale,
|
|
39
|
+
getYScale,
|
|
40
|
+
getSeriesData,
|
|
41
|
+
animate: animationEnabled
|
|
42
|
+
} = useCartesianChartContext();
|
|
43
|
+
const {
|
|
44
|
+
scrubberPosition
|
|
45
|
+
} = useScrubberContext();
|
|
46
|
+
const targetSeries = getSeries(seriesId);
|
|
47
|
+
const sourceData = getSeriesData(seriesId);
|
|
48
|
+
const xScale = getXScale();
|
|
49
|
+
const yScale = getYScale(targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.yAxisId);
|
|
50
|
+
const isIdleState = scrubberPosition === undefined;
|
|
51
|
+
|
|
52
|
+
// Expose imperative handle for triggering pulse animations
|
|
53
|
+
useImperativeHandle(ref, () => ({
|
|
54
|
+
pulse: () => {
|
|
55
|
+
// Only pulse when idle
|
|
56
|
+
if (isIdleState && scope.current) {
|
|
57
|
+
animate(scope.current, {
|
|
58
|
+
opacity: [0.1, 0]
|
|
59
|
+
}, singlePulseTransitionConfig);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
const {
|
|
64
|
+
dataX,
|
|
65
|
+
dataY
|
|
66
|
+
} = useMemo(() => {
|
|
67
|
+
let x;
|
|
68
|
+
let y;
|
|
69
|
+
if (xScale && yScale) {
|
|
70
|
+
if (dataXProp !== undefined && dataYProp !== undefined && !isNaN(dataYProp) && !isNaN(dataXProp)) {
|
|
71
|
+
// Use direct coordinates if provided
|
|
72
|
+
x = dataXProp;
|
|
73
|
+
y = dataYProp;
|
|
74
|
+
} else if (sourceData && scrubberPosition != null && scrubberPosition >= 0 && scrubberPosition < sourceData.length) {
|
|
75
|
+
// Use series data at highlight index
|
|
76
|
+
x = scrubberPosition;
|
|
77
|
+
const dataValue = sourceData[scrubberPosition];
|
|
78
|
+
if (typeof dataValue === 'number') {
|
|
79
|
+
y = dataValue;
|
|
80
|
+
} else if (Array.isArray(dataValue)) {
|
|
81
|
+
const validValues = dataValue.filter(val => val !== null);
|
|
82
|
+
if (validValues.length >= 2) {
|
|
83
|
+
y = validValues[1];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
dataX: x,
|
|
90
|
+
dataY: y
|
|
91
|
+
};
|
|
92
|
+
}, [dataXProp, dataYProp, sourceData, scrubberPosition, xScale, yScale]);
|
|
93
|
+
const pixelCoordinate = useMemo(() => {
|
|
94
|
+
if (!xScale || !yScale || dataX === undefined || dataY === undefined) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return projectPoint({
|
|
98
|
+
x: dataX,
|
|
99
|
+
y: dataY,
|
|
100
|
+
xScale,
|
|
101
|
+
yScale
|
|
102
|
+
});
|
|
103
|
+
}, [xScale, yScale, dataX, dataY]);
|
|
104
|
+
if (!pixelCoordinate) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const pointColor = (_ref2 = color !== null && color !== void 0 ? color : targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.color) !== null && _ref2 !== void 0 ? _ref2 : 'var(--color-fgPrimary)';
|
|
108
|
+
const shouldPulse = animationEnabled && isIdleState && idlePulse;
|
|
109
|
+
if (animationEnabled && isIdleState) {
|
|
110
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
111
|
+
"data-testid": testID,
|
|
112
|
+
opacity: opacity,
|
|
113
|
+
children: [/*#__PURE__*/_jsx(motion.circle, {
|
|
114
|
+
animate: {
|
|
115
|
+
cx: pixelCoordinate.x,
|
|
116
|
+
cy: pixelCoordinate.y
|
|
117
|
+
},
|
|
118
|
+
cx: pixelCoordinate.x,
|
|
119
|
+
cy: pixelCoordinate.y,
|
|
120
|
+
fill: pointColor,
|
|
121
|
+
initial: false,
|
|
122
|
+
opacity: 0.15,
|
|
123
|
+
r: glowRadius,
|
|
124
|
+
transition: {
|
|
125
|
+
duration: 0.3,
|
|
126
|
+
ease: 'easeInOut'
|
|
127
|
+
}
|
|
128
|
+
}), /*#__PURE__*/_jsx(motion.g, {
|
|
129
|
+
animate: {
|
|
130
|
+
x: pixelCoordinate.x,
|
|
131
|
+
y: pixelCoordinate.y
|
|
132
|
+
},
|
|
133
|
+
initial: false,
|
|
134
|
+
transition: {
|
|
135
|
+
duration: 0.3,
|
|
136
|
+
ease: 'easeInOut'
|
|
137
|
+
},
|
|
138
|
+
children: /*#__PURE__*/_jsx(motion.circle, {
|
|
139
|
+
ref: scope,
|
|
140
|
+
animate: shouldPulse ? {
|
|
141
|
+
opacity: [0.1, 0, 0.1],
|
|
142
|
+
transition: pulseTransitionConfig
|
|
143
|
+
} : {
|
|
144
|
+
opacity: 0
|
|
145
|
+
},
|
|
146
|
+
cx: 0,
|
|
147
|
+
cy: 0,
|
|
148
|
+
fill: pointColor,
|
|
149
|
+
initial: {
|
|
150
|
+
opacity: shouldPulse ? 0.1 : 0
|
|
151
|
+
},
|
|
152
|
+
r: pulseRadius
|
|
153
|
+
})
|
|
154
|
+
}), /*#__PURE__*/_jsx(motion.circle, {
|
|
155
|
+
animate: {
|
|
156
|
+
cx: pixelCoordinate.x,
|
|
157
|
+
cy: pixelCoordinate.y
|
|
158
|
+
},
|
|
159
|
+
className: className,
|
|
160
|
+
cx: pixelCoordinate.x,
|
|
161
|
+
cy: pixelCoordinate.y,
|
|
162
|
+
fill: pointColor,
|
|
163
|
+
initial: false,
|
|
164
|
+
r: radius,
|
|
165
|
+
stroke: "var(--color-bg)",
|
|
166
|
+
strokeWidth: 2,
|
|
167
|
+
style: style,
|
|
168
|
+
transition: {
|
|
169
|
+
duration: 0.3,
|
|
170
|
+
ease: 'easeInOut'
|
|
171
|
+
}
|
|
172
|
+
})]
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
176
|
+
"data-testid": testID,
|
|
177
|
+
opacity: opacity,
|
|
178
|
+
children: [/*#__PURE__*/_jsx("circle", {
|
|
179
|
+
cx: pixelCoordinate.x,
|
|
180
|
+
cy: pixelCoordinate.y,
|
|
181
|
+
fill: pointColor,
|
|
182
|
+
opacity: 0.15,
|
|
183
|
+
r: glowRadius
|
|
184
|
+
}), /*#__PURE__*/_jsx("circle", {
|
|
185
|
+
className: className,
|
|
186
|
+
cx: pixelCoordinate.x,
|
|
187
|
+
cy: pixelCoordinate.y,
|
|
188
|
+
fill: pointColor,
|
|
189
|
+
r: radius,
|
|
190
|
+
stroke: "var(--color-bg)",
|
|
191
|
+
strokeWidth: 2,
|
|
192
|
+
style: style
|
|
193
|
+
})]
|
|
194
|
+
});
|
|
195
|
+
}));
|