@coinbase/cds-web-visualization 3.3.2 → 3.4.0-beta.10

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.
Files changed (212) hide show
  1. package/CHANGELOG.md +50 -2
  2. package/dts/chart/CartesianChart.d.ts +72 -0
  3. package/dts/chart/CartesianChart.d.ts.map +1 -0
  4. package/dts/chart/ChartProvider.d.ts +6 -0
  5. package/dts/chart/ChartProvider.d.ts.map +1 -0
  6. package/dts/chart/Path.d.ts +54 -0
  7. package/dts/chart/Path.d.ts.map +1 -0
  8. package/dts/chart/PeriodSelector.d.ts +57 -0
  9. package/dts/chart/PeriodSelector.d.ts.map +1 -0
  10. package/dts/chart/area/Area.d.ts +78 -0
  11. package/dts/chart/area/Area.d.ts.map +1 -0
  12. package/dts/chart/area/AreaChart.d.ts +79 -0
  13. package/dts/chart/area/AreaChart.d.ts.map +1 -0
  14. package/dts/chart/area/DottedArea.d.ts +45 -0
  15. package/dts/chart/area/DottedArea.d.ts.map +1 -0
  16. package/dts/chart/area/GradientArea.d.ts +39 -0
  17. package/dts/chart/area/GradientArea.d.ts.map +1 -0
  18. package/dts/chart/area/SolidArea.d.ts +23 -0
  19. package/dts/chart/area/SolidArea.d.ts.map +1 -0
  20. package/dts/chart/area/index.d.ts +6 -0
  21. package/dts/chart/area/index.d.ts.map +1 -0
  22. package/dts/chart/axis/Axis.d.ts +255 -0
  23. package/dts/chart/axis/Axis.d.ts.map +1 -0
  24. package/dts/chart/axis/DefaultAxisTickLabel.d.ts +8 -0
  25. package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +1 -0
  26. package/dts/chart/axis/XAxis.d.ts +16 -0
  27. package/dts/chart/axis/XAxis.d.ts.map +1 -0
  28. package/dts/chart/axis/YAxis.d.ts +21 -0
  29. package/dts/chart/axis/YAxis.d.ts.map +1 -0
  30. package/dts/chart/axis/index.d.ts +5 -0
  31. package/dts/chart/axis/index.d.ts.map +1 -0
  32. package/dts/chart/bar/Bar.d.ts +94 -0
  33. package/dts/chart/bar/Bar.d.ts.map +1 -0
  34. package/dts/chart/bar/BarChart.d.ts +62 -0
  35. package/dts/chart/bar/BarChart.d.ts.map +1 -0
  36. package/dts/chart/bar/BarPlot.d.ts +30 -0
  37. package/dts/chart/bar/BarPlot.d.ts.map +1 -0
  38. package/dts/chart/bar/BarStack.d.ts +103 -0
  39. package/dts/chart/bar/BarStack.d.ts.map +1 -0
  40. package/dts/chart/bar/BarStackGroup.d.ts +36 -0
  41. package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
  42. package/dts/chart/bar/DefaultBar.d.ts +17 -0
  43. package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
  44. package/dts/chart/bar/DefaultBarStack.d.ts +16 -0
  45. package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
  46. package/dts/chart/bar/index.d.ts +8 -0
  47. package/dts/chart/bar/index.d.ts.map +1 -0
  48. package/dts/chart/gradient/Gradient.d.ts +35 -0
  49. package/dts/chart/gradient/Gradient.d.ts.map +1 -0
  50. package/dts/chart/gradient/index.d.ts +2 -0
  51. package/dts/chart/gradient/index.d.ts.map +1 -0
  52. package/dts/chart/index.d.ts +14 -0
  53. package/dts/chart/index.d.ts.map +1 -0
  54. package/dts/chart/line/DefaultReferenceLineLabel.d.ts +9 -0
  55. package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +1 -0
  56. package/dts/chart/line/DottedLine.d.ts +26 -0
  57. package/dts/chart/line/DottedLine.d.ts.map +1 -0
  58. package/dts/chart/line/Line.d.ts +122 -0
  59. package/dts/chart/line/Line.d.ts.map +1 -0
  60. package/dts/chart/line/LineChart.d.ts +77 -0
  61. package/dts/chart/line/LineChart.d.ts.map +1 -0
  62. package/dts/chart/line/ReferenceLine.d.ts +178 -0
  63. package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
  64. package/dts/chart/line/SolidLine.d.ts +25 -0
  65. package/dts/chart/line/SolidLine.d.ts.map +1 -0
  66. package/dts/chart/line/index.d.ts +7 -0
  67. package/dts/chart/line/index.d.ts.map +1 -0
  68. package/dts/chart/point/DefaultPointLabel.d.ts +10 -0
  69. package/dts/chart/point/DefaultPointLabel.d.ts.map +1 -0
  70. package/dts/chart/point/Point.d.ts +201 -0
  71. package/dts/chart/point/Point.d.ts.map +1 -0
  72. package/dts/chart/point/index.d.ts +3 -0
  73. package/dts/chart/point/index.d.ts.map +1 -0
  74. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +24 -0
  75. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -0
  76. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +12 -0
  77. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -0
  78. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +10 -0
  79. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
  80. package/dts/chart/scrubber/Scrubber.d.ts +290 -0
  81. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
  82. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +70 -0
  83. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
  84. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +32 -0
  85. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
  86. package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
  87. package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
  88. package/dts/chart/scrubber/index.d.ts +5 -0
  89. package/dts/chart/scrubber/index.d.ts.map +1 -0
  90. package/dts/chart/text/ChartText.d.ts +117 -0
  91. package/dts/chart/text/ChartText.d.ts.map +1 -0
  92. package/dts/chart/text/ChartTextGroup.d.ts +61 -0
  93. package/dts/chart/text/ChartTextGroup.d.ts.map +1 -0
  94. package/dts/chart/text/index.d.ts +3 -0
  95. package/dts/chart/text/index.d.ts.map +1 -0
  96. package/dts/chart/utils/axis.d.ts +342 -0
  97. package/dts/chart/utils/axis.d.ts.map +1 -0
  98. package/dts/chart/utils/bar.d.ts +20 -0
  99. package/dts/chart/utils/bar.d.ts.map +1 -0
  100. package/dts/chart/utils/chart.d.ts +117 -0
  101. package/dts/chart/utils/chart.d.ts.map +1 -0
  102. package/dts/chart/utils/context.d.ts +101 -0
  103. package/dts/chart/utils/context.d.ts.map +1 -0
  104. package/dts/chart/utils/gradient.d.ts +104 -0
  105. package/dts/chart/utils/gradient.d.ts.map +1 -0
  106. package/dts/chart/utils/index.d.ts +12 -0
  107. package/dts/chart/utils/index.d.ts.map +1 -0
  108. package/dts/chart/utils/interpolate.d.ts +112 -0
  109. package/dts/chart/utils/interpolate.d.ts.map +1 -0
  110. package/dts/chart/utils/path.d.ts +130 -0
  111. package/dts/chart/utils/path.d.ts.map +1 -0
  112. package/dts/chart/utils/point.d.ts +104 -0
  113. package/dts/chart/utils/point.d.ts.map +1 -0
  114. package/dts/chart/utils/scale.d.ts +43 -0
  115. package/dts/chart/utils/scale.d.ts.map +1 -0
  116. package/dts/chart/utils/scrubber.d.ts +39 -0
  117. package/dts/chart/utils/scrubber.d.ts.map +1 -0
  118. package/dts/chart/utils/transition.d.ts +65 -0
  119. package/dts/chart/utils/transition.d.ts.map +1 -0
  120. package/dts/index.d.ts +1 -0
  121. package/dts/index.d.ts.map +1 -1
  122. package/dts/sparkline/Sparkline.d.ts +44 -9
  123. package/dts/sparkline/Sparkline.d.ts.map +1 -1
  124. package/dts/sparkline/SparklineArea.d.ts +4 -0
  125. package/dts/sparkline/SparklineArea.d.ts.map +1 -1
  126. package/dts/sparkline/SparklineAreaPattern.d.ts +5 -0
  127. package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
  128. package/dts/sparkline/SparklineGradient.d.ts +5 -0
  129. package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
  130. package/dts/sparkline/generateSparklineWithId.d.ts +1 -0
  131. package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
  132. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +9 -0
  133. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
  134. package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +3 -0
  135. package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
  136. package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +2 -1
  137. package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
  138. package/esm/chart/CartesianChart.css +1 -0
  139. package/esm/chart/CartesianChart.js +313 -0
  140. package/esm/chart/ChartProvider.js +10 -0
  141. package/esm/chart/Path.js +95 -0
  142. package/esm/chart/PeriodSelector.css +1 -0
  143. package/esm/chart/PeriodSelector.js +112 -0
  144. package/esm/chart/area/Area.js +75 -0
  145. package/esm/chart/area/AreaChart.js +173 -0
  146. package/esm/chart/area/DottedArea.js +87 -0
  147. package/esm/chart/area/GradientArea.js +65 -0
  148. package/esm/chart/area/SolidArea.js +47 -0
  149. package/esm/chart/area/index.js +7 -0
  150. package/esm/chart/axis/Axis.js +25 -0
  151. package/esm/chart/axis/DefaultAxisTickLabel.js +15 -0
  152. package/esm/chart/axis/XAxis.css +2 -0
  153. package/esm/chart/axis/XAxis.js +219 -0
  154. package/esm/chart/axis/YAxis.css +2 -0
  155. package/esm/chart/axis/YAxis.js +214 -0
  156. package/esm/chart/axis/index.js +6 -0
  157. package/esm/chart/bar/Bar.js +61 -0
  158. package/esm/chart/bar/BarChart.js +130 -0
  159. package/esm/chart/bar/BarPlot.js +97 -0
  160. package/esm/chart/bar/BarStack.js +561 -0
  161. package/esm/chart/bar/BarStackGroup.js +86 -0
  162. package/esm/chart/bar/DefaultBar.js +61 -0
  163. package/esm/chart/bar/DefaultBarStack.js +58 -0
  164. package/esm/chart/bar/index.js +9 -0
  165. package/esm/chart/gradient/Gradient.js +104 -0
  166. package/esm/chart/gradient/index.js +1 -0
  167. package/esm/chart/index.js +15 -0
  168. package/esm/chart/line/DefaultReferenceLineLabel.js +81 -0
  169. package/esm/chart/line/DottedLine.js +59 -0
  170. package/esm/chart/line/Line.js +185 -0
  171. package/esm/chart/line/LineChart.js +132 -0
  172. package/esm/chart/line/ReferenceLine.js +140 -0
  173. package/esm/chart/line/SolidLine.js +55 -0
  174. package/esm/chart/line/index.js +8 -0
  175. package/esm/chart/point/DefaultPointLabel.js +44 -0
  176. package/esm/chart/point/Point.css +2 -0
  177. package/esm/chart/point/Point.js +180 -0
  178. package/esm/chart/point/index.js +2 -0
  179. package/esm/chart/scrubber/DefaultScrubberBeacon.js +155 -0
  180. package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +46 -0
  181. package/esm/chart/scrubber/DefaultScrubberLabel.js +30 -0
  182. package/esm/chart/scrubber/Scrubber.js +189 -0
  183. package/esm/chart/scrubber/ScrubberBeaconGroup.js +166 -0
  184. package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +186 -0
  185. package/esm/chart/scrubber/ScrubberProvider.js +228 -0
  186. package/esm/chart/scrubber/index.js +4 -0
  187. package/esm/chart/text/ChartText.js +230 -0
  188. package/esm/chart/text/ChartTextGroup.js +227 -0
  189. package/esm/chart/text/index.js +4 -0
  190. package/esm/chart/utils/axis.js +593 -0
  191. package/esm/chart/utils/bar.js +24 -0
  192. package/esm/chart/utils/chart.js +255 -0
  193. package/esm/chart/utils/context.js +15 -0
  194. package/esm/chart/utils/gradient.js +257 -0
  195. package/esm/chart/utils/index.js +13 -0
  196. package/esm/chart/utils/interpolate.js +644 -0
  197. package/esm/chart/utils/path.js +227 -0
  198. package/esm/chart/utils/point.js +187 -0
  199. package/esm/chart/utils/scale.js +48 -0
  200. package/esm/chart/utils/scrubber.js +132 -0
  201. package/esm/chart/utils/transition.js +111 -0
  202. package/esm/index.js +4 -1
  203. package/esm/sparkline/Sparkline.js +129 -15
  204. package/esm/sparkline/SparklineArea.js +7 -2
  205. package/esm/sparkline/SparklineAreaPattern.js +4 -2
  206. package/esm/sparkline/SparklineGradient.js +16 -58
  207. package/esm/sparkline/generateSparklineWithId.js +3 -2
  208. package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
  209. package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
  210. package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +1 -1
  211. package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
  212. package/package.json +13 -9
@@ -0,0 +1,155 @@
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 { forwardRef, memo, useImperativeHandle, useMemo } from 'react';
7
+ import { m as motion, useAnimate } from 'framer-motion';
8
+ import { useCartesianChartContext } from '../ChartProvider';
9
+ import { defaultTransition, projectPoint } from '../utils';
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ const radius = 5;
12
+ const strokeWidth = 2;
13
+ const pulseOpacityStart = 0.5;
14
+ const pulseOpacityEnd = 0;
15
+ const pulseRadiusStart = 10;
16
+ const pulseRadiusEnd = 15;
17
+ const defaultPulseTransition = {
18
+ duration: 1.6,
19
+ ease: [0.0, 0.0, 0.0, 1.0]
20
+ };
21
+ const defaultPulseRepeatDelay = 0.4;
22
+ export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
23
+ let {
24
+ seriesId,
25
+ color: colorProp,
26
+ dataX,
27
+ dataY,
28
+ isIdle,
29
+ idlePulse,
30
+ transitions,
31
+ opacity = 1,
32
+ className,
33
+ style,
34
+ testID
35
+ } = _ref;
36
+ const [scope, animate] = useAnimate();
37
+ const {
38
+ getSeries,
39
+ getXScale,
40
+ getYScale,
41
+ drawingArea
42
+ } = useCartesianChartContext();
43
+ const targetSeries = getSeries(seriesId);
44
+ const xScale = getXScale();
45
+ const yScale = getYScale(targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.yAxisId);
46
+ const color = useMemo(() => {
47
+ var _ref2;
48
+ return (_ref2 = colorProp !== null && colorProp !== void 0 ? colorProp : targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.color) !== null && _ref2 !== void 0 ? _ref2 : 'var(--color-fgPrimary)';
49
+ }, [colorProp, targetSeries]);
50
+ const updateTransition = useMemo(() => {
51
+ var _transitions$update;
52
+ return (_transitions$update = transitions === null || transitions === void 0 ? void 0 : transitions.update) !== null && _transitions$update !== void 0 ? _transitions$update : defaultTransition;
53
+ }, [transitions === null || transitions === void 0 ? void 0 : transitions.update]);
54
+ const pulseTransition = useMemo(() => {
55
+ var _transitions$pulse;
56
+ return (_transitions$pulse = transitions === null || transitions === void 0 ? void 0 : transitions.pulse) !== null && _transitions$pulse !== void 0 ? _transitions$pulse : defaultPulseTransition;
57
+ }, [transitions === null || transitions === void 0 ? void 0 : transitions.pulse]);
58
+ const pulseRepeatDelay = useMemo(() => {
59
+ var _transitions$pulseRep;
60
+ return (_transitions$pulseRep = transitions === null || transitions === void 0 ? void 0 : transitions.pulseRepeatDelay) !== null && _transitions$pulseRep !== void 0 ? _transitions$pulseRep : defaultPulseRepeatDelay;
61
+ }, [transitions === null || transitions === void 0 ? void 0 : transitions.pulseRepeatDelay]);
62
+ const pixelCoordinate = useMemo(() => {
63
+ if (!xScale || !yScale) return;
64
+ return projectPoint({
65
+ x: dataX,
66
+ y: dataY,
67
+ xScale,
68
+ yScale
69
+ });
70
+ }, [dataX, dataY, xScale, yScale]);
71
+ useImperativeHandle(ref, () => ({
72
+ pulse: () => {
73
+ // Only pulse when idle and idlePulse is not enabled
74
+ if (isIdle && !idlePulse && scope.current) {
75
+ animate(scope.current, {
76
+ opacity: [pulseOpacityStart, pulseOpacityEnd],
77
+ r: [pulseRadiusStart, pulseRadiusEnd]
78
+ }, pulseTransition);
79
+ }
80
+ }
81
+ }), [isIdle, idlePulse, scope, animate, pulseTransition]);
82
+
83
+ // Create continuous pulse transition by repeating the base pulse transition with delay
84
+ const continuousPulseTransition = useMemo(() => _objectSpread(_objectSpread({}, pulseTransition), {}, {
85
+ repeat: Infinity,
86
+ repeatDelay: pulseRepeatDelay
87
+ }), [pulseTransition, pulseRepeatDelay]);
88
+ const shouldPulse = isIdle && idlePulse;
89
+ const isWithinDrawingArea = useMemo(() => {
90
+ if (!pixelCoordinate) return false;
91
+ return pixelCoordinate.x >= drawingArea.x && pixelCoordinate.x <= drawingArea.x + drawingArea.width && pixelCoordinate.y >= drawingArea.y && pixelCoordinate.y <= drawingArea.y + drawingArea.height;
92
+ }, [pixelCoordinate, drawingArea]);
93
+ if (!pixelCoordinate) return;
94
+ if (isIdle) {
95
+ return /*#__PURE__*/_jsxs("g", {
96
+ "data-testid": testID,
97
+ opacity: isWithinDrawingArea ? opacity : 0,
98
+ children: [/*#__PURE__*/_jsx(motion.g, {
99
+ animate: {
100
+ x: pixelCoordinate.x,
101
+ y: pixelCoordinate.y
102
+ },
103
+ initial: false,
104
+ transition: updateTransition,
105
+ children: /*#__PURE__*/_jsx(motion.circle, {
106
+ ref: scope,
107
+ animate: shouldPulse ? {
108
+ opacity: [pulseOpacityStart, pulseOpacityEnd],
109
+ r: [pulseRadiusStart, pulseRadiusEnd],
110
+ transition: continuousPulseTransition
111
+ } : {
112
+ opacity: pulseOpacityEnd,
113
+ r: pulseRadiusStart
114
+ },
115
+ cx: 0,
116
+ cy: 0,
117
+ fill: color,
118
+ initial: {
119
+ opacity: shouldPulse ? pulseOpacityStart : pulseOpacityEnd,
120
+ r: pulseRadiusStart
121
+ }
122
+ })
123
+ }), /*#__PURE__*/_jsx(motion.circle, {
124
+ animate: {
125
+ cx: pixelCoordinate.x,
126
+ cy: pixelCoordinate.y
127
+ },
128
+ className: className,
129
+ cx: pixelCoordinate.x,
130
+ cy: pixelCoordinate.y,
131
+ fill: color,
132
+ initial: false,
133
+ r: radius,
134
+ stroke: "var(--color-bg)",
135
+ strokeWidth: strokeWidth,
136
+ style: style,
137
+ transition: updateTransition
138
+ })]
139
+ });
140
+ }
141
+ return /*#__PURE__*/_jsx("g", {
142
+ "data-testid": testID,
143
+ opacity: isWithinDrawingArea ? opacity : 0,
144
+ children: /*#__PURE__*/_jsx("circle", {
145
+ className: className,
146
+ cx: pixelCoordinate.x,
147
+ cy: pixelCoordinate.y,
148
+ fill: color,
149
+ r: radius,
150
+ stroke: "var(--color-bg)",
151
+ strokeWidth: strokeWidth,
152
+ style: style
153
+ })
154
+ });
155
+ }));
@@ -0,0 +1,46 @@
1
+ const _excluded = ["background", "color", "elevated", "borderRadius", "font", "verticalAlignment", "inset", "label"];
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
6
+ 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); }
7
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
8
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
9
+ import { memo } from 'react';
10
+ import { ChartText } from '../text';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ const labelVerticalInset = 3.5;
13
+ const labelHorizontalInset = 4;
14
+ /**
15
+ * DefaultScrubberBeaconLabel is a special instance of ChartText used to label a series' scrubber beacon (i.e. a point on the series pinned to the scrubber position).
16
+ */
17
+ export const DefaultScrubberBeaconLabel = /*#__PURE__*/memo(_ref => {
18
+ let {
19
+ background = 'var(--color-bg',
20
+ color = 'var(--color-fgPrimary)',
21
+ elevated = true,
22
+ borderRadius = 4,
23
+ font = 'label1',
24
+ verticalAlignment = 'middle',
25
+ inset = {
26
+ left: labelHorizontalInset,
27
+ right: labelHorizontalInset,
28
+ top: labelVerticalInset,
29
+ bottom: labelVerticalInset
30
+ },
31
+ label
32
+ } = _ref,
33
+ chartTextProps = _objectWithoutProperties(_ref, _excluded);
34
+ return /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({
35
+ disableRepositioning: true,
36
+ background: background,
37
+ borderRadius: borderRadius,
38
+ color: color,
39
+ elevated: elevated,
40
+ font: font,
41
+ inset: inset,
42
+ verticalAlignment: verticalAlignment
43
+ }, chartTextProps), {}, {
44
+ children: label
45
+ }));
46
+ });
@@ -0,0 +1,30 @@
1
+ const _excluded = ["verticalAlignment", "dy"];
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
6
+ 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); }
7
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
8
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
9
+ import { memo } from 'react';
10
+ import { useCartesianChartContext } from '../ChartProvider';
11
+ import { DefaultReferenceLineLabel } from '../line';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ /**
14
+ * DefaultScrubberLabel is the default label component for the scrubber line.
15
+ * It will center the label vertically with the top available area.
16
+ */
17
+ export const DefaultScrubberLabel = /*#__PURE__*/memo(_ref => {
18
+ let {
19
+ verticalAlignment = 'middle',
20
+ dy
21
+ } = _ref,
22
+ props = _objectWithoutProperties(_ref, _excluded);
23
+ const {
24
+ drawingArea
25
+ } = useCartesianChartContext();
26
+ return /*#__PURE__*/_jsx(DefaultReferenceLineLabel, _objectSpread({
27
+ dy: dy !== null && dy !== void 0 ? dy : -0.5 * drawingArea.y,
28
+ verticalAlignment: verticalAlignment
29
+ }, props));
30
+ });
@@ -0,0 +1,189 @@
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, useImperativeHandle, useMemo } from 'react';
7
+ import { m as motion } from 'framer-motion';
8
+ import { useCartesianChartContext } from '../ChartProvider';
9
+ import { ReferenceLine } from '../line';
10
+ import { accessoryFadeTransitionDelay, accessoryFadeTransitionDuration, getPointOnScale, useScrubberContext } from '../utils';
11
+ import { DefaultScrubberBeacon } from './DefaultScrubberBeacon';
12
+ import { DefaultScrubberLabel } from './DefaultScrubberLabel';
13
+ import { ScrubberBeaconGroup } from './ScrubberBeaconGroup';
14
+ import { ScrubberBeaconLabelGroup } from './ScrubberBeaconLabelGroup';
15
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
+ /**
17
+ * Unified component that manages all scrubber elements (beacons, line, labels).
18
+ */
19
+ export const Scrubber = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
20
+ let {
21
+ seriesIds,
22
+ hideLine,
23
+ label,
24
+ accessibilityLabel,
25
+ lineStroke,
26
+ BeaconComponent = DefaultScrubberBeacon,
27
+ BeaconLabelComponent,
28
+ LineComponent,
29
+ LabelComponent = DefaultScrubberLabel,
30
+ labelElevated,
31
+ hideOverlay,
32
+ overlayOffset = 2,
33
+ beaconLabelMinGap,
34
+ beaconLabelHorizontalOffset,
35
+ labelFont,
36
+ labelBoundsInset,
37
+ beaconLabelFont,
38
+ testID,
39
+ idlePulse,
40
+ beaconTransitions,
41
+ styles,
42
+ classNames
43
+ } = _ref;
44
+ const beaconGroupRef = React.useRef(null);
45
+ const {
46
+ scrubberPosition
47
+ } = useScrubberContext();
48
+ const {
49
+ getXScale,
50
+ getXAxis,
51
+ animate,
52
+ series,
53
+ drawingArea,
54
+ dataLength
55
+ } = useCartesianChartContext();
56
+
57
+ // Expose imperative handle with pulse method
58
+ useImperativeHandle(ref, () => ({
59
+ pulse: () => {
60
+ var _beaconGroupRef$curre;
61
+ (_beaconGroupRef$curre = beaconGroupRef.current) === null || _beaconGroupRef$curre === void 0 || _beaconGroupRef$curre.pulse();
62
+ }
63
+ }));
64
+ const filteredSeriesIds = useMemo(() => {
65
+ if (seriesIds === undefined) {
66
+ var _series$map;
67
+ return (_series$map = series === null || series === void 0 ? void 0 : series.map(s => s.id)) !== null && _series$map !== void 0 ? _series$map : [];
68
+ }
69
+ return seriesIds;
70
+ }, [series, seriesIds]);
71
+ const {
72
+ dataX,
73
+ dataIndex
74
+ } = useMemo(() => {
75
+ const xScale = getXScale();
76
+ const xAxis = getXAxis();
77
+ if (!xScale) return {
78
+ dataX: undefined,
79
+ dataIndex: undefined
80
+ };
81
+ const dataIndex = scrubberPosition !== null && scrubberPosition !== void 0 ? scrubberPosition : Math.max(0, dataLength - 1);
82
+
83
+ // Convert index to actual x value if axis has data
84
+ let dataX;
85
+ if (xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && xAxis.data[dataIndex] !== undefined) {
86
+ const dataValue = xAxis.data[dataIndex];
87
+ dataX = typeof dataValue === 'string' ? dataIndex : dataValue;
88
+ } else {
89
+ dataX = dataIndex;
90
+ }
91
+ return {
92
+ dataX,
93
+ dataIndex
94
+ };
95
+ }, [getXScale, getXAxis, scrubberPosition, dataLength]);
96
+
97
+ // Compute resolved accessibility label
98
+ const resolvedAccessibilityLabel = useMemo(() => {
99
+ if (dataIndex === undefined) return undefined;
100
+
101
+ // If accessibilityLabel is provided, use it
102
+ if (accessibilityLabel) {
103
+ return typeof accessibilityLabel === 'function' ? accessibilityLabel(dataIndex) : accessibilityLabel;
104
+ }
105
+
106
+ // Otherwise, if label resolves to a string, use that
107
+ const resolvedLabel = typeof label === 'function' ? label(dataIndex) : label;
108
+ return typeof resolvedLabel === 'string' ? resolvedLabel : undefined;
109
+ }, [accessibilityLabel, label, dataIndex]);
110
+ const beaconLabels = useMemo(() => {
111
+ var _series$filter$filter;
112
+ return (_series$filter$filter = series === null || series === void 0 ? void 0 : series.filter(s => filteredSeriesIds.includes(s.id)).filter(s => s.label !== undefined && s.label.length > 0).map(s => ({
113
+ seriesId: s.id,
114
+ label: s.label,
115
+ color: s.color
116
+ }))) !== null && _series$filter$filter !== void 0 ? _series$filter$filter : [];
117
+ }, [series, filteredSeriesIds]);
118
+
119
+ // Check if we have at least the default X scale
120
+ const defaultXScale = getXScale();
121
+ if (!defaultXScale) return null;
122
+ const pixelX = dataX !== undefined && defaultXScale ? getPointOnScale(dataX, defaultXScale) : undefined;
123
+ return /*#__PURE__*/_jsxs(motion.g, _objectSpread(_objectSpread({
124
+ "aria-atomic": "true",
125
+ "aria-label": resolvedAccessibilityLabel,
126
+ "aria-live": "polite",
127
+ "data-component": "scrubber-group",
128
+ "data-testid": testID,
129
+ role: "status"
130
+ }, animate ? {
131
+ animate: {
132
+ opacity: 1,
133
+ transition: {
134
+ duration: accessoryFadeTransitionDuration,
135
+ delay: accessoryFadeTransitionDelay
136
+ }
137
+ },
138
+ exit: {
139
+ opacity: 0,
140
+ transition: {
141
+ duration: accessoryFadeTransitionDuration
142
+ }
143
+ },
144
+ initial: {
145
+ opacity: 0
146
+ }
147
+ } : {}), {}, {
148
+ children: [!hideOverlay && scrubberPosition !== undefined && pixelX !== undefined && /*#__PURE__*/_jsx("rect", {
149
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.overlay,
150
+ fill: "var(--color-bg)",
151
+ height: drawingArea.height + overlayOffset * 2,
152
+ opacity: 0.8,
153
+ style: styles === null || styles === void 0 ? void 0 : styles.overlay,
154
+ width: drawingArea.x + drawingArea.width - pixelX + overlayOffset,
155
+ x: pixelX,
156
+ y: drawingArea.y - overlayOffset
157
+ }), !hideLine && scrubberPosition !== undefined && dataX !== undefined && /*#__PURE__*/_jsx(ReferenceLine, {
158
+ LabelComponent: LabelComponent,
159
+ LineComponent: LineComponent,
160
+ classNames: {
161
+ label: classNames === null || classNames === void 0 ? void 0 : classNames.line
162
+ },
163
+ dataX: dataX,
164
+ label: typeof label === 'function' ? label(dataIndex) : label,
165
+ labelBoundsInset: labelBoundsInset,
166
+ labelElevated: labelElevated,
167
+ labelFont: labelFont,
168
+ stroke: lineStroke,
169
+ styles: {
170
+ label: styles === null || styles === void 0 ? void 0 : styles.line
171
+ }
172
+ }), /*#__PURE__*/_jsx(ScrubberBeaconGroup, {
173
+ ref: beaconGroupRef,
174
+ BeaconComponent: BeaconComponent,
175
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.beacon,
176
+ idlePulse: idlePulse,
177
+ seriesIds: filteredSeriesIds,
178
+ style: styles === null || styles === void 0 ? void 0 : styles.beacon,
179
+ testID: testID,
180
+ transitions: beaconTransitions
181
+ }), beaconLabels.length > 0 && /*#__PURE__*/_jsx(ScrubberBeaconLabelGroup, {
182
+ BeaconLabelComponent: BeaconLabelComponent,
183
+ labelFont: beaconLabelFont,
184
+ labelHorizontalOffset: beaconLabelHorizontalOffset,
185
+ labelMinGap: beaconLabelMinGap,
186
+ labels: beaconLabels
187
+ })]
188
+ }));
189
+ }));
@@ -0,0 +1,166 @@
1
+ import { forwardRef, memo, useCallback, useImperativeHandle, useMemo } from 'react';
2
+ import { useRefMap } from '@coinbase/cds-common/hooks/useRefMap';
3
+ import { useCartesianChartContext } from '../ChartProvider';
4
+ import { evaluateGradientAtValue, getGradientConfig, useScrubberContext } from '../utils';
5
+ import { DefaultScrubberBeacon } from './DefaultScrubberBeacon';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ // Helper component to calculate beacon data for a specific series
8
+ const BeaconWithData = /*#__PURE__*/memo(_ref => {
9
+ let {
10
+ seriesId,
11
+ dataIndex,
12
+ dataX,
13
+ isIdle,
14
+ BeaconComponent,
15
+ idlePulse,
16
+ transitions,
17
+ className,
18
+ style,
19
+ testID,
20
+ beaconRef
21
+ } = _ref;
22
+ const {
23
+ getSeries,
24
+ getSeriesData,
25
+ getXScale,
26
+ getYScale
27
+ } = useCartesianChartContext();
28
+ const series = useMemo(() => getSeries(seriesId), [getSeries, seriesId]);
29
+ const sourceData = useMemo(() => getSeriesData(seriesId), [getSeriesData, seriesId]);
30
+ const gradient = series === null || series === void 0 ? void 0 : series.gradient;
31
+
32
+ // Get dataY from series data
33
+ const dataY = useMemo(() => {
34
+ if (sourceData && dataIndex >= 0 && dataIndex < sourceData.length) {
35
+ const dataValue = sourceData[dataIndex];
36
+ if (typeof dataValue === 'number') {
37
+ return dataValue;
38
+ } else if (Array.isArray(dataValue)) {
39
+ const validValues = dataValue.filter(val => val !== null);
40
+ if (validValues.length >= 1) {
41
+ return validValues[validValues.length - 1];
42
+ }
43
+ }
44
+ }
45
+ return undefined;
46
+ }, [sourceData, dataIndex]);
47
+
48
+ // Evaluate gradient color
49
+ const color = useMemo(() => {
50
+ var _series$color, _series$color2;
51
+ if (dataY === undefined) return (_series$color = series === null || series === void 0 ? void 0 : series.color) !== null && _series$color !== void 0 ? _series$color : 'var(--color-fgPrimary)';
52
+ if (gradient) {
53
+ const xScale = getXScale();
54
+ const yScale = getYScale(series === null || series === void 0 ? void 0 : series.yAxisId);
55
+ if (xScale && yScale) {
56
+ const gradientScale = gradient.axis === 'x' ? xScale : yScale;
57
+ const stops = getGradientConfig(gradient, xScale, yScale);
58
+ if (stops) {
59
+ var _gradient$axis;
60
+ const gradientAxis = (_gradient$axis = gradient.axis) !== null && _gradient$axis !== void 0 ? _gradient$axis : 'y';
61
+ const dataValue = gradientAxis === 'x' ? dataX : dataY;
62
+ const evaluatedColor = evaluateGradientAtValue(stops, dataValue, gradientScale);
63
+ if (evaluatedColor) {
64
+ return evaluatedColor;
65
+ }
66
+ }
67
+ }
68
+ }
69
+ return (_series$color2 = series === null || series === void 0 ? void 0 : series.color) !== null && _series$color2 !== void 0 ? _series$color2 : 'var(--color-fgPrimary)';
70
+ }, [gradient, dataX, dataY, series === null || series === void 0 ? void 0 : series.color, series === null || series === void 0 ? void 0 : series.yAxisId, getXScale, getYScale]);
71
+ if (dataY === undefined) return null;
72
+ return /*#__PURE__*/_jsx(BeaconComponent, {
73
+ ref: beaconRef,
74
+ className: className,
75
+ color: color,
76
+ dataX: dataX,
77
+ dataY: dataY,
78
+ idlePulse: idlePulse,
79
+ isIdle: isIdle,
80
+ seriesId: seriesId,
81
+ style: style,
82
+ testID: testID,
83
+ transitions: transitions
84
+ });
85
+ });
86
+ export const ScrubberBeaconGroup = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2, ref) => {
87
+ let {
88
+ seriesIds,
89
+ idlePulse,
90
+ transitions,
91
+ BeaconComponent = DefaultScrubberBeacon,
92
+ className,
93
+ style,
94
+ testID
95
+ } = _ref2;
96
+ const ScrubberBeaconRefs = useRefMap();
97
+ const {
98
+ scrubberPosition
99
+ } = useScrubberContext();
100
+ const {
101
+ getXScale,
102
+ getXAxis,
103
+ dataLength,
104
+ series
105
+ } = useCartesianChartContext();
106
+
107
+ // Expose imperative handle with pulse method
108
+ useImperativeHandle(ref, () => ({
109
+ pulse: () => {
110
+ Object.values(ScrubberBeaconRefs.refs).forEach(beaconRef => {
111
+ beaconRef === null || beaconRef === void 0 || beaconRef.pulse();
112
+ });
113
+ }
114
+ }));
115
+ const filteredSeries = useMemo(() => {
116
+ var _series$filter;
117
+ return (_series$filter = series === null || series === void 0 ? void 0 : series.filter(s => seriesIds.includes(s.id))) !== null && _series$filter !== void 0 ? _series$filter : [];
118
+ }, [series, seriesIds]);
119
+ const {
120
+ dataX,
121
+ dataIndex
122
+ } = useMemo(() => {
123
+ const xScale = getXScale();
124
+ const xAxis = getXAxis();
125
+ if (!xScale) return {
126
+ dataX: undefined,
127
+ dataIndex: undefined
128
+ };
129
+ const dataIndex = scrubberPosition !== null && scrubberPosition !== void 0 ? scrubberPosition : Math.max(0, dataLength - 1);
130
+
131
+ // Convert index to actual x value if axis has data
132
+ let dataX;
133
+ if (xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && xAxis.data[dataIndex] !== undefined) {
134
+ const dataValue = xAxis.data[dataIndex];
135
+ dataX = typeof dataValue === 'string' ? dataIndex : dataValue;
136
+ } else {
137
+ dataX = dataIndex;
138
+ }
139
+ return {
140
+ dataX,
141
+ dataIndex
142
+ };
143
+ }, [getXScale, getXAxis, scrubberPosition, dataLength]);
144
+ const isIdle = scrubberPosition === undefined;
145
+ const createBeaconRef = useCallback(seriesId => {
146
+ return beaconRef => {
147
+ if (beaconRef) {
148
+ ScrubberBeaconRefs.registerRef(seriesId, beaconRef);
149
+ }
150
+ };
151
+ }, [ScrubberBeaconRefs]);
152
+ if (dataX === undefined || dataIndex === undefined) return null;
153
+ return filteredSeries.map(s => /*#__PURE__*/_jsx(BeaconWithData, {
154
+ BeaconComponent: BeaconComponent,
155
+ beaconRef: createBeaconRef(s.id),
156
+ className: className,
157
+ dataIndex: dataIndex,
158
+ dataX: dataX,
159
+ idlePulse: idlePulse,
160
+ isIdle: isIdle,
161
+ seriesId: s.id,
162
+ style: style,
163
+ testID: testID ? "".concat(testID !== null && testID !== void 0 ? testID : 'beacon', "-").concat(s.id) : undefined,
164
+ transitions: transitions
165
+ }, s.id));
166
+ }));