@coinbase/cds-web-visualization 3.4.0-beta.8 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/dts/chart/CartesianChart.d.ts +40 -4
  3. package/dts/chart/CartesianChart.d.ts.map +1 -1
  4. package/dts/chart/ChartProvider.d.ts +3 -0
  5. package/dts/chart/ChartProvider.d.ts.map +1 -1
  6. package/dts/chart/Path.d.ts +51 -12
  7. package/dts/chart/Path.d.ts.map +1 -1
  8. package/dts/chart/PeriodSelector.d.ts +25 -4
  9. package/dts/chart/PeriodSelector.d.ts.map +1 -1
  10. package/dts/chart/area/Area.d.ts +13 -11
  11. package/dts/chart/area/Area.d.ts.map +1 -1
  12. package/dts/chart/area/AreaChart.d.ts +18 -5
  13. package/dts/chart/area/AreaChart.d.ts.map +1 -1
  14. package/dts/chart/area/DottedArea.d.ts.map +1 -1
  15. package/dts/chart/area/GradientArea.d.ts.map +1 -1
  16. package/dts/chart/area/SolidArea.d.ts.map +1 -1
  17. package/dts/chart/axis/Axis.d.ts +29 -29
  18. package/dts/chart/axis/Axis.d.ts.map +1 -1
  19. package/dts/chart/axis/XAxis.d.ts +6 -0
  20. package/dts/chart/axis/XAxis.d.ts.map +1 -1
  21. package/dts/chart/axis/YAxis.d.ts +2 -1
  22. package/dts/chart/axis/YAxis.d.ts.map +1 -1
  23. package/dts/chart/bar/Bar.d.ts +51 -51
  24. package/dts/chart/bar/Bar.d.ts.map +1 -1
  25. package/dts/chart/bar/BarChart.d.ts +29 -6
  26. package/dts/chart/bar/BarChart.d.ts.map +1 -1
  27. package/dts/chart/bar/BarPlot.d.ts +2 -1
  28. package/dts/chart/bar/BarPlot.d.ts.map +1 -1
  29. package/dts/chart/bar/BarStack.d.ts +58 -20
  30. package/dts/chart/bar/BarStack.d.ts.map +1 -1
  31. package/dts/chart/bar/BarStackGroup.d.ts +2 -1
  32. package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
  33. package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
  34. package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
  35. package/dts/chart/gradient/Gradient.d.ts +7 -0
  36. package/dts/chart/gradient/Gradient.d.ts.map +1 -1
  37. package/dts/chart/index.d.ts +1 -0
  38. package/dts/chart/index.d.ts.map +1 -1
  39. package/dts/chart/legend/DefaultLegendEntry.d.ts +21 -0
  40. package/dts/chart/legend/DefaultLegendEntry.d.ts.map +1 -0
  41. package/dts/chart/legend/DefaultLegendShape.d.ts +7 -0
  42. package/dts/chart/legend/DefaultLegendShape.d.ts.map +1 -0
  43. package/dts/chart/legend/Legend.d.ts +169 -0
  44. package/dts/chart/legend/Legend.d.ts.map +1 -0
  45. package/dts/chart/legend/index.d.ts +4 -0
  46. package/dts/chart/legend/index.d.ts.map +1 -0
  47. package/dts/chart/line/DottedLine.d.ts.map +1 -1
  48. package/dts/chart/line/Line.d.ts +45 -24
  49. package/dts/chart/line/Line.d.ts.map +1 -1
  50. package/dts/chart/line/LineChart.d.ts +5 -3
  51. package/dts/chart/line/LineChart.d.ts.map +1 -1
  52. package/dts/chart/line/ReferenceLine.d.ts +9 -0
  53. package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
  54. package/dts/chart/line/SolidLine.d.ts.map +1 -1
  55. package/dts/chart/point/Point.d.ts +26 -2
  56. package/dts/chart/point/Point.d.ts.map +1 -1
  57. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +34 -17
  58. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -1
  59. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -1
  60. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +2 -1
  61. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -1
  62. package/dts/chart/scrubber/Scrubber.d.ts +148 -46
  63. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
  64. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +10 -0
  65. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -1
  66. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +25 -1
  67. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -1
  68. package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
  69. package/dts/chart/text/ChartText.d.ts.map +1 -1
  70. package/dts/chart/utils/axis.d.ts +48 -9
  71. package/dts/chart/utils/axis.d.ts.map +1 -1
  72. package/dts/chart/utils/bar.d.ts +188 -0
  73. package/dts/chart/utils/bar.d.ts.map +1 -1
  74. package/dts/chart/utils/chart.d.ts +32 -0
  75. package/dts/chart/utils/chart.d.ts.map +1 -1
  76. package/dts/chart/utils/context.d.ts +20 -4
  77. package/dts/chart/utils/context.d.ts.map +1 -1
  78. package/dts/chart/utils/gradient.d.ts +3 -1
  79. package/dts/chart/utils/gradient.d.ts.map +1 -1
  80. package/dts/chart/utils/path.d.ts +26 -0
  81. package/dts/chart/utils/path.d.ts.map +1 -1
  82. package/dts/chart/utils/point.d.ts +18 -7
  83. package/dts/chart/utils/point.d.ts.map +1 -1
  84. package/dts/chart/utils/scale.d.ts +11 -0
  85. package/dts/chart/utils/scale.d.ts.map +1 -1
  86. package/dts/chart/utils/scrubber.d.ts +2 -1
  87. package/dts/chart/utils/scrubber.d.ts.map +1 -1
  88. package/dts/chart/utils/transition.d.ts +50 -14
  89. package/dts/chart/utils/transition.d.ts.map +1 -1
  90. package/dts/sparkline/Sparkline.d.ts +2 -1
  91. package/dts/sparkline/Sparkline.d.ts.map +1 -1
  92. package/dts/sparkline/SparklineArea.d.ts +2 -1
  93. package/dts/sparkline/SparklineArea.d.ts.map +1 -1
  94. package/dts/sparkline/SparklineGradient.d.ts +2 -1
  95. package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
  96. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +2 -1
  97. package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
  98. package/esm/chart/CartesianChart.js +154 -90
  99. package/esm/chart/ChartProvider.js +2 -2
  100. package/esm/chart/Path.js +35 -19
  101. package/esm/chart/PeriodSelector.js +33 -15
  102. package/esm/chart/area/Area.js +21 -9
  103. package/esm/chart/area/AreaChart.js +28 -25
  104. package/esm/chart/area/DottedArea.js +18 -9
  105. package/esm/chart/area/GradientArea.js +16 -8
  106. package/esm/chart/area/SolidArea.js +8 -3
  107. package/esm/chart/axis/Axis.js +3 -17
  108. package/esm/chart/axis/XAxis.js +153 -50
  109. package/esm/chart/axis/YAxis.js +146 -36
  110. package/esm/chart/bar/Bar.js +16 -8
  111. package/esm/chart/bar/BarChart.js +38 -33
  112. package/esm/chart/bar/BarPlot.js +20 -25
  113. package/esm/chart/bar/BarStack.js +109 -505
  114. package/esm/chart/bar/BarStackGroup.js +36 -27
  115. package/esm/chart/bar/DefaultBar.js +34 -26
  116. package/esm/chart/bar/DefaultBarStack.js +31 -18
  117. package/esm/chart/gradient/Gradient.js +3 -2
  118. package/esm/chart/index.js +1 -0
  119. package/esm/chart/legend/DefaultLegendEntry.css +1 -0
  120. package/esm/chart/legend/DefaultLegendEntry.js +50 -0
  121. package/esm/chart/legend/DefaultLegendShape.css +5 -0
  122. package/esm/chart/legend/DefaultLegendShape.js +47 -0
  123. package/esm/chart/legend/Legend.js +76 -0
  124. package/esm/chart/legend/index.js +3 -0
  125. package/esm/chart/line/DottedLine.js +7 -2
  126. package/esm/chart/line/Line.js +41 -42
  127. package/esm/chart/line/LineChart.js +18 -13
  128. package/esm/chart/line/ReferenceLine.js +6 -2
  129. package/esm/chart/line/SolidLine.js +8 -3
  130. package/esm/chart/point/Point.js +41 -24
  131. package/esm/chart/scrubber/DefaultScrubberBeacon.js +64 -65
  132. package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +25 -14
  133. package/esm/chart/scrubber/DefaultScrubberLabel.js +26 -8
  134. package/esm/chart/scrubber/Scrubber.js +54 -43
  135. package/esm/chart/scrubber/ScrubberBeaconGroup.js +60 -35
  136. package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +31 -8
  137. package/esm/chart/scrubber/ScrubberProvider.js +44 -39
  138. package/esm/chart/text/ChartText.js +3 -2
  139. package/esm/chart/utils/axis.js +90 -43
  140. package/esm/chart/utils/bar.js +863 -0
  141. package/esm/chart/utils/chart.js +34 -7
  142. package/esm/chart/utils/context.js +7 -0
  143. package/esm/chart/utils/gradient.js +6 -4
  144. package/esm/chart/utils/path.js +88 -61
  145. package/esm/chart/utils/point.js +57 -30
  146. package/esm/chart/utils/scale.js +13 -2
  147. package/esm/chart/utils/scrubber.js +9 -4
  148. package/esm/chart/utils/transition.js +68 -41
  149. package/esm/sparkline/Sparkline.js +2 -1
  150. package/esm/sparkline/SparklineArea.js +2 -1
  151. package/esm/sparkline/SparklineGradient.js +2 -1
  152. package/esm/sparkline/__figma__/Sparkline.figma.js +1 -1
  153. package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +2 -1
  154. package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +1 -1
  155. package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +1 -1
  156. package/package.json +12 -11
@@ -4,16 +4,18 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
4
4
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
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
6
  import { forwardRef, memo, useImperativeHandle, useMemo } from 'react';
7
+ import { usePreviousValue } from '@coinbase/cds-common/hooks/usePreviousValue';
7
8
  import { m as motion, useAnimate } from 'framer-motion';
8
9
  import { useCartesianChartContext } from '../ChartProvider';
9
- import { defaultTransition, projectPoint } from '../utils';
10
+ import { defaultTransition, getTransition, instantTransition, projectPoint } from '../utils';
10
11
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- const radius = 5;
12
- const strokeWidth = 2;
12
+ const defaultRadius = 5;
13
+ const defaultStrokeWidth = 2;
14
+ const defaultStroke = 'var(--color-bg)';
13
15
  const pulseOpacityStart = 0.5;
14
16
  const pulseOpacityEnd = 0;
15
- const pulseRadiusStart = 10;
16
- const pulseRadiusEnd = 15;
17
+ const pulseRadiusStartMultiplier = 2;
18
+ const pulseRadiusEndMultiplier = 3;
17
19
  const defaultPulseTransition = {
18
20
  duration: 1.6,
19
21
  ease: [0.0, 0.0, 0.0, 1.0]
@@ -27,30 +29,39 @@ export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((
27
29
  dataY,
28
30
  isIdle,
29
31
  idlePulse,
32
+ animate: animateProp,
30
33
  transitions,
31
34
  opacity = 1,
35
+ radius = defaultRadius,
36
+ stroke = defaultStroke,
37
+ strokeWidth = defaultStrokeWidth,
32
38
  className,
33
39
  style,
34
- testID
40
+ testID = "".concat(seriesId, "-beacon")
35
41
  } = _ref;
36
- const [scope, animate] = useAnimate();
42
+ const [scope, animateFn] = useAnimate();
37
43
  const {
44
+ animate: animateContext,
38
45
  getSeries,
39
46
  getXScale,
40
47
  getYScale,
41
48
  drawingArea
42
49
  } = useCartesianChartContext();
50
+ const animate = animateProp !== null && animateProp !== void 0 ? animateProp : animateContext;
43
51
  const targetSeries = getSeries(seriesId);
44
- const xScale = getXScale();
52
+ const xScale = getXScale(targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.xAxisId);
45
53
  const yScale = getYScale(targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.yAxisId);
46
54
  const color = useMemo(() => {
47
55
  var _ref2;
48
56
  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
57
  }, [colorProp, targetSeries]);
58
+ const prevIsIdle = usePreviousValue(isIdle);
59
+ const isIdleTransition = prevIsIdle !== undefined && isIdle !== prevIsIdle;
50
60
  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]);
61
+ if (isIdleTransition) return instantTransition;
62
+ if (!isIdle) return instantTransition;
63
+ return getTransition(transitions === null || transitions === void 0 ? void 0 : transitions.update, animate, defaultTransition);
64
+ }, [transitions === null || transitions === void 0 ? void 0 : transitions.update, isIdle, animate, isIdleTransition]);
54
65
  const pulseTransition = useMemo(() => {
55
66
  var _transitions$pulse;
56
67
  return (_transitions$pulse = transitions === null || transitions === void 0 ? void 0 : transitions.pulse) !== null && _transitions$pulse !== void 0 ? _transitions$pulse : defaultPulseTransition;
@@ -68,17 +79,19 @@ export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((
68
79
  yScale
69
80
  });
70
81
  }, [dataX, dataY, xScale, yScale]);
82
+ const pulseRadiusStart = radius * pulseRadiusStartMultiplier;
83
+ const pulseRadiusEnd = radius * pulseRadiusEndMultiplier;
71
84
  useImperativeHandle(ref, () => ({
72
85
  pulse: () => {
73
86
  // Only pulse when idle and idlePulse is not enabled
74
87
  if (isIdle && !idlePulse && scope.current) {
75
- animate(scope.current, {
88
+ animateFn(scope.current, {
76
89
  opacity: [pulseOpacityStart, pulseOpacityEnd],
77
90
  r: [pulseRadiusStart, pulseRadiusEnd]
78
91
  }, pulseTransition);
79
92
  }
80
93
  }
81
- }), [isIdle, idlePulse, scope, animate, pulseTransition]);
94
+ }), [isIdle, idlePulse, scope, animateFn, pulseTransition, pulseRadiusStart, pulseRadiusEnd]);
82
95
 
83
96
  // Create continuous pulse transition by repeating the base pulse transition with delay
84
97
  const continuousPulseTransition = useMemo(() => _objectSpread(_objectSpread({}, pulseTransition), {}, {
@@ -91,65 +104,51 @@ export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((
91
104
  return pixelCoordinate.x >= drawingArea.x && pixelCoordinate.x <= drawingArea.x + drawingArea.width && pixelCoordinate.y >= drawingArea.y && pixelCoordinate.y <= drawingArea.y + drawingArea.height;
92
105
  }, [pixelCoordinate, drawingArea]);
93
106
  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", {
107
+ const pulseCircle = /*#__PURE__*/_jsx(motion.circle, {
108
+ ref: scope,
109
+ animate: shouldPulse ? {
110
+ opacity: [pulseOpacityStart, pulseOpacityEnd],
111
+ r: [pulseRadiusStart, pulseRadiusEnd],
112
+ transition: continuousPulseTransition
113
+ } : {
114
+ opacity: pulseOpacityEnd,
115
+ r: pulseRadiusStart
116
+ },
117
+ cx: 0,
118
+ cy: 0,
119
+ "data-testid": "".concat(testID, "-pulse"),
120
+ fill: color,
121
+ initial: {
122
+ opacity: shouldPulse ? pulseOpacityStart : pulseOpacityEnd,
123
+ r: pulseRadiusStart
124
+ }
125
+ });
126
+ return /*#__PURE__*/_jsxs("g", {
142
127
  "data-testid": testID,
143
128
  opacity: isWithinDrawingArea ? opacity : 0,
144
- children: /*#__PURE__*/_jsx("circle", {
129
+ children: [isIdle && /*#__PURE__*/_jsx(motion.g, {
130
+ animate: {
131
+ x: pixelCoordinate.x,
132
+ y: pixelCoordinate.y
133
+ },
134
+ initial: false,
135
+ transition: updateTransition !== null && updateTransition !== void 0 ? updateTransition : instantTransition,
136
+ children: pulseCircle
137
+ }), /*#__PURE__*/_jsx(motion.circle, {
138
+ animate: {
139
+ cx: pixelCoordinate.x,
140
+ cy: pixelCoordinate.y
141
+ },
145
142
  className: className,
146
143
  cx: pixelCoordinate.x,
147
144
  cy: pixelCoordinate.y,
148
145
  fill: color,
146
+ initial: false,
149
147
  r: radius,
150
- stroke: "var(--color-bg)",
148
+ stroke: stroke,
151
149
  strokeWidth: strokeWidth,
152
- style: style
153
- })
150
+ style: style,
151
+ transition: updateTransition !== null && updateTransition !== void 0 ? updateTransition : instantTransition
152
+ })]
154
153
  });
155
154
  }));
@@ -1,4 +1,4 @@
1
- const _excluded = ["background", "color", "elevated", "borderRadius", "font", "verticalAlignment", "inset", "label"];
1
+ const _excluded = ["background", "color", "elevated", "borderRadius", "font", "verticalAlignment", "inset", "label", "transition", "y"];
2
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
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
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; }
@@ -7,6 +7,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
7
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
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
9
  import { memo } from 'react';
10
+ import { m as motion } from 'framer-motion';
10
11
  import { ChartText } from '../text';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  const labelVerticalInset = 3.5;
@@ -28,19 +29,29 @@ export const DefaultScrubberBeaconLabel = /*#__PURE__*/memo(_ref => {
28
29
  top: labelVerticalInset,
29
30
  bottom: labelVerticalInset
30
31
  },
31
- label
32
+ label,
33
+ transition,
34
+ y
32
35
  } = _ref,
33
36
  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
- }));
37
+ return /*#__PURE__*/_jsx(motion.g, {
38
+ animate: {
39
+ y
40
+ },
41
+ initial: false,
42
+ transition: transition,
43
+ children: /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({
44
+ disableRepositioning: true,
45
+ background: background,
46
+ borderRadius: borderRadius,
47
+ color: color,
48
+ elevated: elevated,
49
+ font: font,
50
+ inset: inset,
51
+ verticalAlignment: verticalAlignment,
52
+ y: transition ? 0 : y
53
+ }, chartTextProps), {}, {
54
+ children: label
55
+ }))
56
+ });
46
57
  });
@@ -1,4 +1,4 @@
1
- const _excluded = ["verticalAlignment", "dy"];
1
+ const _excluded = ["dx", "dy"];
2
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
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
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; }
@@ -6,25 +6,43 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
6
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
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
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';
9
+ import { memo, useMemo } from 'react';
10
10
  import { useCartesianChartContext } from '../ChartProvider';
11
11
  import { DefaultReferenceLineLabel } from '../line';
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  /**
14
14
  * DefaultScrubberLabel is the default label component for the scrubber line.
15
- * It will center the label vertically with the top available area.
15
+ * In vertical layout, it positions the label above the scrubber line.
16
+ * In horizontal layout, it centers the label in the chart's right inset.
16
17
  */
17
18
  export const DefaultScrubberLabel = /*#__PURE__*/memo(_ref => {
18
19
  let {
19
- verticalAlignment = 'middle',
20
- dy
20
+ dx: dxProp,
21
+ dy: dyProp
21
22
  } = _ref,
22
23
  props = _objectWithoutProperties(_ref, _excluded);
23
24
  const {
24
- drawingArea
25
+ drawingArea,
26
+ layout,
27
+ width: chartWidth
25
28
  } = useCartesianChartContext();
29
+ const isHorizontalLayout = layout === 'horizontal';
30
+ const dx = useMemo(() => {
31
+ if (dxProp !== undefined) return dxProp;
32
+ if (isHorizontalLayout) {
33
+ const drawingAreaEnd = drawingArea.x + drawingArea.width;
34
+ const rightOffset = chartWidth - drawingAreaEnd;
35
+ return rightOffset / 2;
36
+ }
37
+ return 0;
38
+ }, [drawingArea.width, drawingArea.x, dxProp, isHorizontalLayout, chartWidth]);
39
+ const dy = useMemo(() => {
40
+ if (dyProp !== undefined) return dyProp;
41
+ if (isHorizontalLayout) return 0;
42
+ return -0.5 * drawingArea.y;
43
+ }, [dyProp, isHorizontalLayout, drawingArea.y]);
26
44
  return /*#__PURE__*/_jsx(DefaultReferenceLineLabel, _objectSpread({
27
- dy: dy !== null && dy !== void 0 ? dy : -0.5 * drawingArea.y,
28
- verticalAlignment: verticalAlignment
45
+ dx: dx,
46
+ dy: dy
29
47
  }, props));
30
48
  });
@@ -7,7 +7,7 @@ import React, { forwardRef, memo, useImperativeHandle, useMemo } from 'react';
7
7
  import { m as motion } from 'framer-motion';
8
8
  import { useCartesianChartContext } from '../ChartProvider';
9
9
  import { ReferenceLine } from '../line';
10
- import { accessoryFadeTransitionDelay, accessoryFadeTransitionDuration, getPointOnScale, useScrubberContext } from '../utils';
10
+ import { defaultAccessoryEnterTransition, getPointOnScale, getTransition, useScrubberContext } from '../utils';
11
11
  import { DefaultScrubberBeacon } from './DefaultScrubberBeacon';
12
12
  import { DefaultScrubberLabel } from './DefaultScrubberLabel';
13
13
  import { ScrubberBeaconGroup } from './ScrubberBeaconGroup';
@@ -19,6 +19,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
19
  export const Scrubber = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
20
20
  let {
21
21
  seriesIds,
22
+ hideBeaconLabels,
22
23
  hideLine,
23
24
  label,
24
25
  accessibilityLabel,
@@ -32,12 +33,15 @@ export const Scrubber = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =>
32
33
  overlayOffset = 2,
33
34
  beaconLabelMinGap,
34
35
  beaconLabelHorizontalOffset,
36
+ beaconLabelPreferredSide,
35
37
  labelFont,
36
38
  labelBoundsInset,
37
39
  beaconLabelFont,
38
40
  testID,
39
41
  idlePulse,
40
42
  beaconTransitions,
43
+ transitions = beaconTransitions,
44
+ beaconStroke,
41
45
  styles,
42
46
  classNames
43
47
  } = _ref;
@@ -46,8 +50,11 @@ export const Scrubber = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =>
46
50
  scrubberPosition
47
51
  } = useScrubberContext();
48
52
  const {
53
+ layout,
49
54
  getXScale,
55
+ getYScale,
50
56
  getXAxis,
57
+ getYAxis,
51
58
  animate,
52
59
  series,
53
60
  drawingArea,
@@ -69,30 +76,31 @@ export const Scrubber = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =>
69
76
  return seriesIds;
70
77
  }, [series, seriesIds]);
71
78
  const {
72
- dataX,
79
+ dataValue,
73
80
  dataIndex
74
81
  } = useMemo(() => {
75
- const xScale = getXScale();
76
- const xAxis = getXAxis();
77
- if (!xScale) return {
78
- dataX: undefined,
82
+ const categoryAxisIsX = layout !== 'horizontal';
83
+ const indexScale = categoryAxisIsX ? getXScale() : getYScale();
84
+ const indexAxis = categoryAxisIsX ? getXAxis() : getYAxis();
85
+ if (!indexScale) return {
86
+ dataValue: undefined,
79
87
  dataIndex: undefined
80
88
  };
81
89
  const dataIndex = scrubberPosition !== null && scrubberPosition !== void 0 ? scrubberPosition : Math.max(0, dataLength - 1);
82
90
 
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;
91
+ // Convert index to actual data value if axis has data
92
+ let dataValue;
93
+ if (indexAxis !== null && indexAxis !== void 0 && indexAxis.data && Array.isArray(indexAxis.data) && indexAxis.data[dataIndex] !== undefined) {
94
+ const val = indexAxis.data[dataIndex];
95
+ dataValue = typeof val === 'string' ? dataIndex : val;
88
96
  } else {
89
- dataX = dataIndex;
97
+ dataValue = dataIndex;
90
98
  }
91
99
  return {
92
- dataX,
100
+ dataValue,
93
101
  dataIndex
94
102
  };
95
- }, [getXScale, getXAxis, scrubberPosition, dataLength]);
103
+ }, [getXScale, getYScale, getXAxis, getYAxis, scrubberPosition, dataLength, layout]);
96
104
 
97
105
  // Compute resolved accessibility label
98
106
  const resolvedAccessibilityLabel = useMemo(() => {
@@ -115,11 +123,13 @@ export const Scrubber = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =>
115
123
  color: s.color
116
124
  }))) !== null && _series$filter$filter !== void 0 ? _series$filter$filter : [];
117
125
  }, [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;
126
+ const groupEnterTransition = useMemo(() => getTransition(transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, defaultAccessoryEnterTransition), [transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate]);
127
+ const shouldAnimateGroup = animate && groupEnterTransition !== null;
128
+ const categoryAxisIsX = layout !== 'horizontal';
129
+ const showBeaconLabels = !hideBeaconLabels && categoryAxisIsX && beaconLabels.length > 0;
130
+ const indexScale = categoryAxisIsX ? getXScale() : getYScale();
131
+ if (!indexScale) return null;
132
+ const pixelPos = dataValue !== undefined && indexScale ? getPointOnScale(dataValue, indexScale) : undefined;
123
133
  return /*#__PURE__*/_jsxs(motion.g, _objectSpread(_objectSpread({
124
134
  "aria-atomic": "true",
125
135
  "aria-label": resolvedAccessibilityLabel,
@@ -127,63 +137,64 @@ export const Scrubber = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =>
127
137
  "data-component": "scrubber-group",
128
138
  "data-testid": testID,
129
139
  role: "status"
130
- }, animate ? {
140
+ }, shouldAnimateGroup ? {
131
141
  animate: {
132
142
  opacity: 1,
133
- transition: {
134
- duration: accessoryFadeTransitionDuration,
135
- delay: accessoryFadeTransitionDelay
136
- }
137
- },
138
- exit: {
139
- opacity: 0,
140
- transition: {
141
- duration: accessoryFadeTransitionDuration
142
- }
143
+ transition: groupEnterTransition
143
144
  },
144
145
  initial: {
145
146
  opacity: 0
146
147
  }
147
148
  } : {}), {}, {
148
- children: [!hideOverlay && scrubberPosition !== undefined && pixelX !== undefined && /*#__PURE__*/_jsx("rect", {
149
+ children: [!hideOverlay && scrubberPosition !== undefined && pixelPos !== undefined && /*#__PURE__*/_jsx("rect", {
149
150
  className: classNames === null || classNames === void 0 ? void 0 : classNames.overlay,
150
151
  fill: "var(--color-bg)",
151
- height: drawingArea.height + overlayOffset * 2,
152
+ height: categoryAxisIsX ? drawingArea.height + overlayOffset * 2 : drawingArea.y + drawingArea.height - pixelPos + overlayOffset,
152
153
  opacity: 0.8,
153
154
  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, {
155
+ width: categoryAxisIsX ? drawingArea.x + drawingArea.width - pixelPos + overlayOffset : drawingArea.width + overlayOffset * 2,
156
+ x: categoryAxisIsX ? pixelPos : drawingArea.x - overlayOffset,
157
+ y: categoryAxisIsX ? drawingArea.y - overlayOffset : pixelPos
158
+ }), !hideLine && scrubberPosition !== undefined && dataValue !== undefined && dataIndex !== undefined && /*#__PURE__*/_jsx(ReferenceLine, _objectSpread({
158
159
  LabelComponent: LabelComponent,
159
160
  LineComponent: LineComponent,
160
161
  classNames: {
161
- label: classNames === null || classNames === void 0 ? void 0 : classNames.line
162
+ label: classNames === null || classNames === void 0 ? void 0 : classNames.label,
163
+ line: classNames === null || classNames === void 0 ? void 0 : classNames.line
162
164
  },
163
- dataX: dataX,
164
165
  label: typeof label === 'function' ? label(dataIndex) : label,
165
166
  labelBoundsInset: labelBoundsInset,
166
167
  labelElevated: labelElevated,
167
168
  labelFont: labelFont,
168
169
  stroke: lineStroke,
169
170
  styles: {
170
- label: styles === null || styles === void 0 ? void 0 : styles.line
171
+ label: styles === null || styles === void 0 ? void 0 : styles.label,
172
+ line: styles === null || styles === void 0 ? void 0 : styles.line
171
173
  }
172
- }), /*#__PURE__*/_jsx(ScrubberBeaconGroup, {
174
+ }, categoryAxisIsX ? {
175
+ dataX: dataValue
176
+ } : {
177
+ dataY: dataValue
178
+ })), /*#__PURE__*/_jsx(ScrubberBeaconGroup, {
173
179
  ref: beaconGroupRef,
174
180
  BeaconComponent: BeaconComponent,
175
181
  className: classNames === null || classNames === void 0 ? void 0 : classNames.beacon,
176
182
  idlePulse: idlePulse,
177
183
  seriesIds: filteredSeriesIds,
184
+ stroke: beaconStroke,
178
185
  style: styles === null || styles === void 0 ? void 0 : styles.beacon,
179
186
  testID: testID,
180
- transitions: beaconTransitions
181
- }), beaconLabels.length > 0 && /*#__PURE__*/_jsx(ScrubberBeaconLabelGroup, {
187
+ transitions: transitions
188
+ }), showBeaconLabels && /*#__PURE__*/_jsx(ScrubberBeaconLabelGroup, {
182
189
  BeaconLabelComponent: BeaconLabelComponent,
190
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.beaconLabel,
183
191
  labelFont: beaconLabelFont,
184
192
  labelHorizontalOffset: beaconLabelHorizontalOffset,
185
193
  labelMinGap: beaconLabelMinGap,
186
- labels: beaconLabels
194
+ labelPreferredSide: beaconLabelPreferredSide,
195
+ labels: beaconLabels,
196
+ style: styles === null || styles === void 0 ? void 0 : styles.beaconLabel,
197
+ transitions: transitions
187
198
  })]
188
199
  }));
189
200
  }));