@coinbase/cds-web-visualization 3.4.0-beta.21 → 3.4.0-beta.23

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 (102) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dts/chart/CartesianChart.d.ts +23 -4
  3. package/dts/chart/CartesianChart.d.ts.map +1 -1
  4. package/dts/chart/Path.d.ts.map +1 -1
  5. package/dts/chart/PeriodSelector.d.ts +22 -5
  6. package/dts/chart/PeriodSelector.d.ts.map +1 -1
  7. package/dts/chart/area/Area.d.ts +7 -0
  8. package/dts/chart/area/Area.d.ts.map +1 -1
  9. package/dts/chart/area/AreaChart.d.ts +3 -3
  10. package/dts/chart/area/AreaChart.d.ts.map +1 -1
  11. package/dts/chart/area/DottedArea.d.ts.map +1 -1
  12. package/dts/chart/area/GradientArea.d.ts.map +1 -1
  13. package/dts/chart/area/SolidArea.d.ts.map +1 -1
  14. package/dts/chart/axis/Axis.d.ts +10 -10
  15. package/dts/chart/axis/Axis.d.ts.map +1 -1
  16. package/dts/chart/axis/XAxis.d.ts +6 -0
  17. package/dts/chart/axis/XAxis.d.ts.map +1 -1
  18. package/dts/chart/axis/YAxis.d.ts +1 -0
  19. package/dts/chart/axis/YAxis.d.ts.map +1 -1
  20. package/dts/chart/bar/Bar.d.ts +4 -3
  21. package/dts/chart/bar/Bar.d.ts.map +1 -1
  22. package/dts/chart/bar/BarChart.d.ts +25 -5
  23. package/dts/chart/bar/BarChart.d.ts.map +1 -1
  24. package/dts/chart/bar/BarPlot.d.ts.map +1 -1
  25. package/dts/chart/bar/BarStack.d.ts +47 -12
  26. package/dts/chart/bar/BarStack.d.ts.map +1 -1
  27. package/dts/chart/bar/BarStackGroup.d.ts +1 -1
  28. package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
  29. package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
  30. package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
  31. package/dts/chart/gradient/Gradient.d.ts +7 -0
  32. package/dts/chart/gradient/Gradient.d.ts.map +1 -1
  33. package/dts/chart/line/DottedLine.d.ts.map +1 -1
  34. package/dts/chart/line/Line.d.ts +7 -0
  35. package/dts/chart/line/Line.d.ts.map +1 -1
  36. package/dts/chart/line/LineChart.d.ts +3 -3
  37. package/dts/chart/line/LineChart.d.ts.map +1 -1
  38. package/dts/chart/line/ReferenceLine.d.ts +1 -0
  39. package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
  40. package/dts/chart/line/SolidLine.d.ts.map +1 -1
  41. package/dts/chart/point/Point.d.ts +7 -0
  42. package/dts/chart/point/Point.d.ts.map +1 -1
  43. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -1
  44. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +2 -1
  45. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -1
  46. package/dts/chart/scrubber/Scrubber.d.ts +8 -0
  47. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
  48. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -1
  49. package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
  50. package/dts/chart/utils/axis.d.ts +23 -8
  51. package/dts/chart/utils/axis.d.ts.map +1 -1
  52. package/dts/chart/utils/bar.d.ts +6 -5
  53. package/dts/chart/utils/bar.d.ts.map +1 -1
  54. package/dts/chart/utils/chart.d.ts +13 -0
  55. package/dts/chart/utils/chart.d.ts.map +1 -1
  56. package/dts/chart/utils/context.d.ts +20 -4
  57. package/dts/chart/utils/context.d.ts.map +1 -1
  58. package/dts/chart/utils/gradient.d.ts +3 -1
  59. package/dts/chart/utils/gradient.d.ts.map +1 -1
  60. package/dts/chart/utils/path.d.ts +20 -0
  61. package/dts/chart/utils/path.d.ts.map +1 -1
  62. package/dts/chart/utils/point.d.ts +7 -0
  63. package/dts/chart/utils/point.d.ts.map +1 -1
  64. package/dts/chart/utils/transition.d.ts +3 -3
  65. package/dts/chart/utils/transition.d.ts.map +1 -1
  66. package/esm/chart/CartesianChart.js +89 -57
  67. package/esm/chart/Path.js +21 -6
  68. package/esm/chart/area/Area.js +19 -9
  69. package/esm/chart/area/AreaChart.js +23 -25
  70. package/esm/chart/area/DottedArea.js +11 -6
  71. package/esm/chart/area/GradientArea.js +11 -6
  72. package/esm/chart/area/SolidArea.js +3 -1
  73. package/esm/chart/axis/XAxis.js +11 -12
  74. package/esm/chart/axis/YAxis.js +4 -4
  75. package/esm/chart/bar/Bar.js +11 -5
  76. package/esm/chart/bar/BarChart.js +34 -31
  77. package/esm/chart/bar/BarPlot.js +6 -3
  78. package/esm/chart/bar/BarStack.js +155 -356
  79. package/esm/chart/bar/BarStackGroup.js +36 -27
  80. package/esm/chart/bar/DefaultBar.js +26 -10
  81. package/esm/chart/bar/DefaultBarStack.js +27 -13
  82. package/esm/chart/gradient/Gradient.js +3 -2
  83. package/esm/chart/line/DottedLine.js +3 -1
  84. package/esm/chart/line/Line.js +29 -16
  85. package/esm/chart/line/LineChart.js +12 -11
  86. package/esm/chart/line/SolidLine.js +3 -1
  87. package/esm/chart/point/Point.js +3 -2
  88. package/esm/chart/scrubber/DefaultScrubberBeacon.js +3 -3
  89. package/esm/chart/scrubber/DefaultScrubberLabel.js +26 -8
  90. package/esm/chart/scrubber/Scrubber.js +36 -28
  91. package/esm/chart/scrubber/ScrubberBeaconGroup.js +49 -32
  92. package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +1 -1
  93. package/esm/chart/scrubber/ScrubberProvider.js +44 -39
  94. package/esm/chart/utils/axis.js +44 -13
  95. package/esm/chart/utils/bar.js +6 -4
  96. package/esm/chart/utils/chart.js +18 -5
  97. package/esm/chart/utils/context.js +7 -0
  98. package/esm/chart/utils/gradient.js +6 -4
  99. package/esm/chart/utils/path.js +87 -61
  100. package/esm/chart/utils/point.js +30 -21
  101. package/esm/chart/utils/transition.js +8 -3
  102. package/package.json +5 -5
@@ -1,4 +1,4 @@
1
- const _excluded = ["series", "yAxisId", "stackIndex", "totalStacks", "barPadding"];
1
+ const _excluded = ["series", "xAxisId", "yAxisId", "stackIndex", "totalStacks", "barPadding"];
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; }
@@ -18,6 +18,7 @@ import { BarStack } from './BarStack';
18
18
  export const BarStackGroup = /*#__PURE__*/memo(_ref => {
19
19
  let {
20
20
  series,
21
+ xAxisId,
21
22
  yAxisId,
22
23
  stackIndex,
23
24
  totalStacks,
@@ -25,62 +26,70 @@ export const BarStackGroup = /*#__PURE__*/memo(_ref => {
25
26
  } = _ref,
26
27
  props = _objectWithoutProperties(_ref, _excluded);
27
28
  const {
29
+ layout,
28
30
  getXScale,
29
31
  getYScale,
30
32
  drawingArea,
31
33
  dataLength
32
34
  } = useCartesianChartContext();
33
- const xScale = getXScale();
35
+ const xScale = getXScale(xAxisId);
34
36
  const yScale = getYScale(yAxisId);
35
37
  const stackConfigs = useMemo(() => {
36
38
  if (!xScale || !yScale || !drawingArea || dataLength === 0) return [];
37
- if (!isCategoricalScale(xScale)) {
39
+ const indexScale = layout !== 'horizontal' ? xScale : yScale;
40
+ if (!isCategoricalScale(indexScale)) {
38
41
  return [];
39
42
  }
40
- const categoryWidth = xScale.bandwidth();
43
+ const categoryWidth = indexScale.bandwidth();
41
44
 
42
- // Calculate width for each stack within a category
43
- // Only apply barPadding when there are multiple stacks
44
- const gapWidth = totalStacks > 1 ? categoryWidth * barPadding / (totalStacks - 1) : 0;
45
- const barWidth = categoryWidth / totalStacks - getBarSizeAdjustment(totalStacks, gapWidth);
45
+ // Calculate thickness for each stack within a category
46
+ const gapSize = totalStacks > 1 ? categoryWidth * barPadding / (totalStacks - 1) : 0;
47
+ const stackThickness = categoryWidth / totalStacks - getBarSizeAdjustment(totalStacks, gapSize);
46
48
  const configs = [];
47
49
 
48
50
  // Calculate position for each category
49
- // todo: look at using xDomain for this instead of dataLength
50
51
  for (let categoryIndex = 0; categoryIndex < dataLength; categoryIndex++) {
51
- // Get x position for this category
52
- const categoryX = xScale(categoryIndex);
53
- if (categoryX !== undefined) {
54
- // Calculate x position for this specific stack within the category
55
- const stackX = categoryX + stackIndex * (barWidth + gapWidth);
52
+ // Get position for this category along the index axis
53
+ const categoryPos = indexScale(categoryIndex);
54
+ if (categoryPos !== undefined) {
55
+ // Calculate position for this specific stack within the category
56
+ const stackPos = categoryPos + stackIndex * (stackThickness + gapSize);
56
57
  configs.push({
57
58
  categoryIndex,
58
- x: stackX,
59
- width: barWidth
59
+ indexPos: stackPos,
60
+ thickness: stackThickness
60
61
  });
61
62
  }
62
63
  }
63
64
  return configs;
64
- }, [xScale, yScale, drawingArea, dataLength, stackIndex, totalStacks, barPadding]);
65
- if (xScale && !isCategoricalScale(xScale)) {
66
- throw new Error('BarStackGroup requires a band scale for x-axis. See https://cds.coinbase.com/components/charts/XAxis/#scale-type');
65
+ }, [xScale, yScale, drawingArea, dataLength, layout, totalStacks, barPadding, stackIndex]);
66
+ const indexScaleComputed = layout !== 'horizontal' ? xScale : yScale;
67
+ const valueScaleComputed = layout !== 'horizontal' ? yScale : xScale;
68
+ if (indexScaleComputed && !isCategoricalScale(indexScaleComputed)) {
69
+ throw new Error("BarStackGroup requires a band scale for ".concat(layout !== 'horizontal' ? 'x-axis' : 'y-axis', ". See https://cds.coinbase.com/components/graphs/").concat(layout !== 'horizontal' ? 'XAxis' : 'YAxis', "/#scale-type"));
67
70
  }
68
- if (!yScale || !drawingArea || stackConfigs.length === 0) return null;
69
- return stackConfigs.map(_ref2 => {
71
+ if (!indexScaleComputed || !valueScaleComputed || !drawingArea || stackConfigs.length === 0) return null;
72
+
73
+ // In horizontal layout, render stacks in reverse order so top rows (lower categoryIndex)
74
+ // appear on top in SVG. Otherwise bottom rows would overlap and obscure top rows during animation.
75
+ const orderedConfigs = layout === 'horizontal' ? [...stackConfigs].reverse() : stackConfigs;
76
+ return orderedConfigs.map(_ref2 => {
70
77
  let {
71
78
  categoryIndex,
72
- x,
73
- width
79
+ indexPos,
80
+ thickness
74
81
  } = _ref2;
75
82
  return /*#__PURE__*/_createElement(BarStack, _objectSpread(_objectSpread({}, props), {}, {
76
83
  key: "stack-".concat(stackIndex, "-category-").concat(categoryIndex),
77
84
  categoryIndex: categoryIndex,
85
+ indexPos: indexPos,
86
+ indexScale: indexScaleComputed,
78
87
  rect: drawingArea,
79
88
  series: series,
80
- width: width,
81
- x: x,
82
- yAxisId: yAxisId,
83
- yScale: yScale
89
+ thickness: thickness,
90
+ valueScale: valueScaleComputed,
91
+ xAxisId: xAxisId,
92
+ yAxisId: yAxisId
84
93
  }));
85
94
  });
86
95
  });
@@ -1,4 +1,4 @@
1
- const _excluded = ["x", "width", "borderRadius", "roundTop", "roundBottom", "originY", "d", "fill", "fillOpacity", "dataX", "dataY", "seriesId", "transitions", "transition"];
1
+ const _excluded = ["x", "y", "width", "height", "borderRadius", "roundTop", "roundBottom", "origin", "d", "fill", "fillOpacity", "dataX", "dataY", "seriesId", "transitions", "transition"];
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; }
@@ -17,11 +17,13 @@ import { jsx as _jsx } from "react/jsx-runtime";
17
17
  export const DefaultBar = /*#__PURE__*/memo(_ref => {
18
18
  let {
19
19
  x,
20
+ y,
20
21
  width,
22
+ height,
21
23
  borderRadius = 4,
22
24
  roundTop,
23
25
  roundBottom,
24
- originY,
26
+ origin,
25
27
  d,
26
28
  fill = 'var(--color-fgPrimary)',
27
29
  fillOpacity = 1,
@@ -34,16 +36,30 @@ export const DefaultBar = /*#__PURE__*/memo(_ref => {
34
36
  props = _objectWithoutProperties(_ref, _excluded);
35
37
  const {
36
38
  animate,
37
- drawingArea
39
+ drawingArea,
40
+ layout
38
41
  } = useCartesianChartContext();
39
- const normalizedX = useMemo(() => drawingArea.width > 0 ? (x - drawingArea.x) / drawingArea.width : 0, [x, drawingArea.x, drawingArea.width]);
40
- const enterTransition = useMemo(() => withStaggerDelayTransition(getTransition(transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, defaultBarEnterTransition), normalizedX), [transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, normalizedX]);
41
- const updateTransition = useMemo(() => withStaggerDelayTransition(getTransition((transitions === null || transitions === void 0 ? void 0 : transitions.update) !== undefined ? transitions.update : transition, animate, defaultTransition), normalizedX), [transitions === null || transitions === void 0 ? void 0 : transitions.update, transition, animate, normalizedX]);
42
+
43
+ // For vertical layout, stagger by x (category axis). For horizontal, stagger by y (category axis).
44
+ const normalizedStagger = useMemo(() => {
45
+ const barsGrowVertically = layout !== 'horizontal';
46
+ if (barsGrowVertically) {
47
+ return drawingArea.width > 0 ? (x - drawingArea.x) / drawingArea.width : 0;
48
+ }
49
+ return drawingArea.height > 0 ? (y - drawingArea.y) / drawingArea.height : 0;
50
+ }, [layout, x, y, drawingArea.x, drawingArea.y, drawingArea.width, drawingArea.height]);
51
+ const enterTransition = useMemo(() => withStaggerDelayTransition(getTransition(transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, defaultBarEnterTransition), normalizedStagger), [transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, normalizedStagger]);
52
+ const updateTransition = useMemo(() => withStaggerDelayTransition(getTransition((transitions === null || transitions === void 0 ? void 0 : transitions.update) !== undefined ? transitions.update : transition, animate, defaultTransition), normalizedStagger), [transitions === null || transitions === void 0 ? void 0 : transitions.update, transition, animate, normalizedStagger]);
42
53
  const initialPath = useMemo(() => {
43
- const minHeight = 1;
44
- const initialY = (originY !== null && originY !== void 0 ? originY : 0) - minHeight;
45
- return getBarPath(x, initialY, width, minHeight, borderRadius !== null && borderRadius !== void 0 ? borderRadius : 0, !!roundTop, !!roundBottom);
46
- }, [x, originY, width, borderRadius, roundTop, roundBottom]);
54
+ if (!animate) return undefined;
55
+ const minSize = 1;
56
+ const barsGrowVertically = layout !== 'horizontal';
57
+ const initialX = barsGrowVertically ? x : origin !== null && origin !== void 0 ? origin : x;
58
+ const initialY = barsGrowVertically ? origin !== null && origin !== void 0 ? origin : y + height : y;
59
+ const initialWidth = barsGrowVertically ? width : minSize;
60
+ const initialHeight = barsGrowVertically ? minSize : height;
61
+ return getBarPath(initialX, initialY, initialWidth, initialHeight, borderRadius !== null && borderRadius !== void 0 ? borderRadius : 0, !!roundTop, !!roundBottom, layout);
62
+ }, [animate, layout, x, y, origin, width, height, borderRadius, roundTop, roundBottom]);
47
63
  return /*#__PURE__*/_jsx(Path, _objectSpread(_objectSpread({}, props), {}, {
48
64
  animate: animate,
49
65
  clipRect: null,
@@ -25,22 +25,36 @@ export const DefaultBarStack = /*#__PURE__*/memo(_ref => {
25
25
  } = _ref;
26
26
  const {
27
27
  animate,
28
- drawingArea
28
+ drawingArea,
29
+ layout
29
30
  } = useCartesianChartContext();
30
31
  const clipPathId = useId();
31
- const normalizedX = useMemo(() => drawingArea.width > 0 ? (x - drawingArea.x) / drawingArea.width : 0, [x, drawingArea.x, drawingArea.width]);
32
- const enterTransition = useMemo(() => withStaggerDelayTransition(getTransition(transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, defaultBarEnterTransition), normalizedX), [animate, transitions === null || transitions === void 0 ? void 0 : transitions.enter, normalizedX]);
33
- const updateTransition = useMemo(() => withStaggerDelayTransition(getTransition((transitions === null || transitions === void 0 ? void 0 : transitions.update) !== undefined ? transitions.update : transition, animate, defaultTransition), normalizedX), [animate, transitions === null || transitions === void 0 ? void 0 : transitions.update, transition, normalizedX]);
34
- const targetPath = useMemo(() => {
35
- return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom);
36
- }, [x, y, width, height, borderRadius, roundTop, roundBottom]);
37
- const initialPath = useMemo(() => {
38
- const baselineY = yOrigin !== null && yOrigin !== void 0 ? yOrigin : y + height;
39
- return getBarPath(x, baselineY, width, 1, borderRadius, roundTop, roundBottom);
40
- }, [x, yOrigin, y, height, width, borderRadius, roundTop, roundBottom]);
32
+
33
+ // For vertical layout, stagger by x (category axis). For horizontal, stagger by y (category axis).
34
+ const normalizedStagger = useMemo(() => {
35
+ const barsGrowVertically = layout !== 'horizontal';
36
+ if (barsGrowVertically) {
37
+ return drawingArea.width > 0 ? (x - drawingArea.x) / drawingArea.width : 0;
38
+ }
39
+ return drawingArea.height > 0 ? (y - drawingArea.y) / drawingArea.height : 0;
40
+ }, [layout, x, y, drawingArea.x, drawingArea.y, drawingArea.width, drawingArea.height]);
41
+ const enterTransition = useMemo(() => withStaggerDelayTransition(getTransition(transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, defaultBarEnterTransition), normalizedStagger), [transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, normalizedStagger]);
42
+ const updateTransition = useMemo(() => withStaggerDelayTransition(getTransition((transitions === null || transitions === void 0 ? void 0 : transitions.update) !== undefined ? transitions.update : transition, animate, defaultTransition), normalizedStagger), [transitions === null || transitions === void 0 ? void 0 : transitions.update, transition, animate, normalizedStagger]);
43
+ const clipPathData = useMemo(() => {
44
+ return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom, layout);
45
+ }, [x, y, width, height, borderRadius, roundTop, roundBottom, layout]);
46
+ const initialClipPathData = useMemo(() => {
47
+ if (!animate) return undefined;
48
+ const barsGrowVertically = layout !== 'horizontal';
49
+ const initialX = barsGrowVertically ? x : yOrigin !== null && yOrigin !== void 0 ? yOrigin : x;
50
+ const initialY = barsGrowVertically ? yOrigin !== null && yOrigin !== void 0 ? yOrigin : y + height : y;
51
+ const initialWidth = barsGrowVertically ? width : 1;
52
+ const initialHeight = barsGrowVertically ? 1 : height;
53
+ return getBarPath(initialX, initialY, initialWidth, initialHeight, borderRadius, roundTop, roundBottom, layout);
54
+ }, [animate, layout, x, yOrigin, y, height, width, borderRadius, roundTop, roundBottom]);
41
55
  const animatedClipPath = usePathTransition({
42
- currentPath: targetPath,
43
- initialPath,
56
+ currentPath: clipPathData,
57
+ initialPath: initialClipPathData,
44
58
  transitions: {
45
59
  enter: enterTransition,
46
60
  update: updateTransition
@@ -17,13 +17,14 @@ export const Gradient = /*#__PURE__*/memo(_ref => {
17
17
  let {
18
18
  id,
19
19
  gradient,
20
+ xAxisId,
20
21
  yAxisId,
21
22
  animate: animateProp,
22
23
  transition
23
24
  } = _ref;
24
25
  const context = useCartesianChartContext();
25
26
  const animate = animateProp !== null && animateProp !== void 0 ? animateProp : context.animate;
26
- const xScale = context.getXScale();
27
+ const xScale = context.getXScale(xAxisId);
27
28
  const yScale = context.getYScale(yAxisId);
28
29
 
29
30
  // Process gradient definition into stops
@@ -33,7 +34,7 @@ export const Gradient = /*#__PURE__*/memo(_ref => {
33
34
  }, [gradient, xScale, yScale]);
34
35
  const drawingArea = context.drawingArea;
35
36
  const yAxis = context.getYAxis(yAxisId);
36
- const xAxis = context.getXAxis();
37
+ const xAxis = context.getXAxis(xAxisId);
37
38
 
38
39
  // If gradient processing failed, don't render
39
40
  if (!stops) return null;
@@ -1,4 +1,4 @@
1
- const _excluded = ["fill", "stroke", "strokeDasharray", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "vectorEffect", "gradient", "yAxisId", "animate", "transitions", "transition", "d"];
1
+ const _excluded = ["fill", "stroke", "strokeDasharray", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "vectorEffect", "gradient", "xAxisId", "yAxisId", "animate", "transitions", "transition", "d"];
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; }
@@ -26,6 +26,7 @@ export const DottedLine = /*#__PURE__*/memo(_ref => {
26
26
  strokeWidth = 2,
27
27
  vectorEffect = 'non-scaling-stroke',
28
28
  gradient,
29
+ xAxisId,
29
30
  yAxisId,
30
31
  animate,
31
32
  transitions,
@@ -41,6 +42,7 @@ export const DottedLine = /*#__PURE__*/memo(_ref => {
41
42
  gradient: gradient,
42
43
  id: gradientId,
43
44
  transition: (_transitions$update = transitions === null || transitions === void 0 ? void 0 : transitions.update) !== null && _transitions$update !== void 0 ? _transitions$update : transition,
45
+ xAxisId: xAxisId,
44
46
  yAxisId: yAxisId
45
47
  })
46
48
  }), /*#__PURE__*/_jsx(Path, _objectSpread({
@@ -37,6 +37,7 @@ export const Line = /*#__PURE__*/memo(_ref => {
37
37
  } = _ref,
38
38
  props = _objectWithoutProperties(_ref, _excluded);
39
39
  const {
40
+ layout,
40
41
  animate,
41
42
  getSeries,
42
43
  getSeriesData,
@@ -48,26 +49,36 @@ export const Line = /*#__PURE__*/memo(_ref => {
48
49
  const matchedSeries = useMemo(() => getSeries(seriesId), [getSeries, seriesId]);
49
50
  const gradient = useMemo(() => gradientProp !== null && gradientProp !== void 0 ? gradientProp : matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.gradient, [gradientProp, matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.gradient]);
50
51
  const sourceData = useMemo(() => getSeriesData(seriesId), [getSeriesData, seriesId]);
51
- const xAxis = useMemo(() => getXAxis(), [getXAxis]);
52
- const xScale = useMemo(() => getXScale(), [getXScale]);
52
+ const xAxis = useMemo(() => getXAxis(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId), [getXAxis, matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId]);
53
+ const xScale = useMemo(() => getXScale(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId), [getXScale, matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId]);
53
54
  const yScale = useMemo(() => getYScale(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId), [getYScale, matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId]);
55
+ const yAxis = useMemo(() => getYAxis(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId), [getYAxis, matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId]);
54
56
 
55
57
  // Convert sourceData to number array (line only supports numbers, not tuples)
56
58
  const chartData = useMemo(() => getLineData(sourceData), [sourceData]);
59
+ const categoryAxisIsX = useMemo(() => {
60
+ return layout !== 'horizontal';
61
+ }, [layout]);
62
+ const categoryAxis = useMemo(() => {
63
+ return categoryAxisIsX ? xAxis : yAxis;
64
+ }, [categoryAxisIsX, xAxis, yAxis]);
57
65
  const path = useMemo(() => {
58
66
  if (!xScale || !yScale || chartData.length === 0) return '';
59
67
 
60
- // Get numeric x-axis data if available
61
- const xData = xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
68
+ // Get numeric category-axis data if available
69
+ const indexAxis = categoryAxis;
70
+ const indexData = indexAxis !== null && indexAxis !== void 0 && indexAxis.data && Array.isArray(indexAxis.data) && typeof indexAxis.data[0] === 'number' ? indexAxis.data : undefined;
62
71
  return getLinePath({
63
72
  data: chartData,
64
73
  xScale,
65
74
  yScale,
66
75
  curve,
67
- xData,
68
- connectNulls
76
+ xData: categoryAxisIsX ? indexData : undefined,
77
+ yData: !categoryAxisIsX ? indexData : undefined,
78
+ connectNulls,
79
+ layout
69
80
  });
70
- }, [chartData, xScale, yScale, curve, xAxis === null || xAxis === void 0 ? void 0 : xAxis.data, connectNulls]);
81
+ }, [xScale, yScale, chartData, categoryAxis, curve, categoryAxisIsX, connectNulls, layout]);
71
82
  const LineComponent = useMemo(() => {
72
83
  if (SelectedLineComponent) {
73
84
  return SelectedLineComponent;
@@ -82,10 +93,10 @@ export const Line = /*#__PURE__*/memo(_ref => {
82
93
 
83
94
  // Get series color for stroke
84
95
  const stroke = (_ref2 = strokeProp !== null && strokeProp !== void 0 ? strokeProp : matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.color) !== null && _ref2 !== void 0 ? _ref2 : 'var(--color-fgPrimary)';
85
- const xData = useMemo(() => {
86
- const data = xAxis === null || xAxis === void 0 ? void 0 : xAxis.data;
96
+ const categoryData = useMemo(() => {
97
+ const data = categoryAxis === null || categoryAxis === void 0 ? void 0 : categoryAxis.data;
87
98
  return data && Array.isArray(data) && data.length > 0 && typeof data[0] === 'number' ? data : null;
88
- }, [xAxis === null || xAxis === void 0 ? void 0 : xAxis.data]);
99
+ }, [categoryAxis]);
89
100
  const gradientConfig = useMemo(() => {
90
101
  if (!gradient || !xScale || !yScale) return;
91
102
  const gradientScale = gradient.axis === 'x' ? xScale : yScale;
@@ -117,19 +128,20 @@ export const Line = /*#__PURE__*/memo(_ref => {
117
128
  strokeOpacity: strokeOpacity !== null && strokeOpacity !== void 0 ? strokeOpacity : opacity,
118
129
  transition: transition,
119
130
  transitions: transitions,
131
+ xAxisId: matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId,
120
132
  yAxisId: matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId
121
133
  }, props)), points && /*#__PURE__*/_jsx("g", {
122
134
  "data-component": "line-points-group",
123
135
  children: chartData.map((value, index) => {
124
136
  var _pointConfig$onClick;
125
137
  if (value === null) return;
126
- const xValue = xData && xData[index] !== undefined ? xData[index] : index;
138
+ const indexValue = categoryData && categoryData[index] !== undefined ? categoryData[index] : index;
127
139
  let pointFill = stroke;
128
140
  if (gradientConfig && gradient) {
129
141
  var _gradient$axis;
130
- // Use the appropriate data value based on gradient axis
131
- const axis = (_gradient$axis = gradient.axis) !== null && _gradient$axis !== void 0 ? _gradient$axis : 'y';
132
- const dataValue = axis === 'x' ? xValue : value;
142
+ // Match gradient sampling to the chart axis roles for each layout.
143
+ const gradientAxis = (_gradient$axis = gradient.axis) !== null && _gradient$axis !== void 0 ? _gradient$axis : 'y';
144
+ const dataValue = gradientAxis === 'x' ? categoryAxisIsX ? indexValue : value : categoryAxisIsX ? value : indexValue;
133
145
  const evaluatedColor = evaluateGradientAtValue(gradientConfig.stops, dataValue, gradientConfig.scale);
134
146
  if (evaluatedColor) {
135
147
  // Apply gradient color to fill if not explicitly set
@@ -139,9 +151,10 @@ export const Line = /*#__PURE__*/memo(_ref => {
139
151
 
140
152
  // Build defaults that would be passed to Point
141
153
  const defaults = {
142
- dataX: xValue,
143
- dataY: value,
154
+ dataX: categoryAxisIsX ? indexValue : value,
155
+ dataY: categoryAxisIsX ? value : indexValue,
144
156
  fill: pointFill,
157
+ xAxisId: matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId,
145
158
  yAxisId: matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId,
146
159
  opacity,
147
160
  testID: undefined
@@ -1,7 +1,7 @@
1
1
  const _excluded = ["series", "showArea", "areaType", "type", "onPointClick", "LineComponent", "AreaComponent", "curve", "points", "strokeWidth", "strokeOpacity", "connectNulls", "transitions", "transition", "opacity", "showXAxis", "showYAxis", "xAxis", "yAxis", "inset", "children"],
2
- _excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
2
+ _excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
3
3
  _excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
4
- _excluded4 = ["id", "data", "label", "color", "yAxisId", "legendShape"];
4
+ _excluded4 = ["id", "data", "label", "color", "xAxisId", "yAxisId", "legendShape"];
5
5
  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; }
6
6
  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; }
7
7
  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; }
@@ -13,7 +13,6 @@ import { forwardRef, memo, useMemo } from 'react';
13
13
  import { XAxis } from '../axis/XAxis';
14
14
  import { YAxis } from '../axis/YAxis';
15
15
  import { CartesianChart } from '../CartesianChart';
16
- import { defaultChartInset, getChartInset } from '../utils';
17
16
  import { Line } from './Line';
18
17
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
18
  export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
@@ -41,8 +40,6 @@ export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
41
40
  children
42
41
  } = _ref,
43
42
  chartProps = _objectWithoutProperties(_ref, _excluded);
44
- const calculatedInset = useMemo(() => getChartInset(inset, defaultChartInset), [inset]);
45
-
46
43
  // Convert LineSeries to Series for Chart context
47
44
  const chartSeries = useMemo(() => {
48
45
  return series === null || series === void 0 ? void 0 : series.map(s => ({
@@ -50,6 +47,7 @@ export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
50
47
  data: s.data,
51
48
  label: s.label,
52
49
  color: s.color,
50
+ xAxisId: s.xAxisId,
53
51
  yAxisId: s.yAxisId,
54
52
  stackId: s.stackId,
55
53
  gradient: s.gradient,
@@ -65,7 +63,8 @@ export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
65
63
  categoryPadding: xCategoryPadding,
66
64
  domain: xDomain,
67
65
  domainLimit: xDomainLimit,
68
- range: xRange
66
+ range: xRange,
67
+ id: xAxisId
69
68
  } = _ref2,
70
69
  xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
71
70
  const _ref3 = yAxis || {},
@@ -97,19 +96,21 @@ export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
97
96
  };
98
97
  return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
99
98
  ref: ref,
100
- inset: calculatedInset,
99
+ inset: inset,
101
100
  series: chartSeries,
102
101
  xAxis: xAxisConfig,
103
102
  yAxis: yAxisConfig,
104
- children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
103
+ children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({
104
+ axisId: xAxisId
105
+ }, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
105
106
  axisId: yAxisId
106
107
  }, yAxisVisualProps)), series === null || series === void 0 ? void 0 : series.map(_ref4 => {
107
- var _linePropsFromSeries$, _linePropsFromSeries$2;
108
108
  let {
109
109
  id,
110
110
  data,
111
111
  label,
112
112
  color,
113
+ xAxisId,
113
114
  yAxisId,
114
115
  legendShape
115
116
  } = _ref4,
@@ -127,8 +128,8 @@ export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
127
128
  showArea: showArea,
128
129
  strokeOpacity: strokeOpacity,
129
130
  strokeWidth: strokeWidth,
130
- transition: (_linePropsFromSeries$ = linePropsFromSeries.transition) !== null && _linePropsFromSeries$ !== void 0 ? _linePropsFromSeries$ : transition,
131
- transitions: (_linePropsFromSeries$2 = linePropsFromSeries.transitions) !== null && _linePropsFromSeries$2 !== void 0 ? _linePropsFromSeries$2 : transitions,
131
+ transition: transition,
132
+ transitions: transitions,
132
133
  type: type
133
134
  }, linePropsFromSeries), id);
134
135
  }), children]
@@ -1,4 +1,4 @@
1
- const _excluded = ["fill", "stroke", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "gradient", "yAxisId", "animate", "transitions", "transition", "d"];
1
+ const _excluded = ["fill", "stroke", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "gradient", "xAxisId", "yAxisId", "animate", "transitions", "transition", "d"];
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; }
@@ -24,6 +24,7 @@ export const SolidLine = /*#__PURE__*/memo(_ref => {
24
24
  strokeOpacity = 1,
25
25
  strokeWidth = 2,
26
26
  gradient,
27
+ xAxisId,
27
28
  yAxisId,
28
29
  animate,
29
30
  transitions,
@@ -39,6 +40,7 @@ export const SolidLine = /*#__PURE__*/memo(_ref => {
39
40
  gradient: gradient,
40
41
  id: gradientId,
41
42
  transition: (_transitions$update = transitions === null || transitions === void 0 ? void 0 : transitions.update) !== null && _transitions$update !== void 0 ? _transitions$update : transition,
43
+ xAxisId: xAxisId,
42
44
  yAxisId: yAxisId
43
45
  })
44
46
  }), /*#__PURE__*/_jsx(Path, _objectSpread({
@@ -1,4 +1,4 @@
1
- const _excluded = ["dataX", "dataY", "yAxisId", "fill", "radius", "opacity", "onClick", "className", "style", "classNames", "styles", "stroke", "strokeWidth", "accessibilityLabel", "label", "LabelComponent", "labelPosition", "labelOffset", "labelFont", "testID", "animate", "transitions", "transition"];
1
+ const _excluded = ["dataX", "dataY", "xAxisId", "yAxisId", "fill", "radius", "opacity", "onClick", "className", "style", "classNames", "styles", "stroke", "strokeWidth", "accessibilityLabel", "label", "LabelComponent", "labelPosition", "labelOffset", "labelFont", "testID", "animate", "transitions", "transition"];
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; }
@@ -24,6 +24,7 @@ export const Point = /*#__PURE__*/memo(_ref => {
24
24
  let {
25
25
  dataX,
26
26
  dataY,
27
+ xAxisId,
27
28
  yAxisId,
28
29
  fill = 'var(--color-fgPrimary)',
29
30
  radius = 5,
@@ -56,7 +57,7 @@ export const Point = /*#__PURE__*/memo(_ref => {
56
57
  const animate = animateProp !== null && animateProp !== void 0 ? animateProp : animationEnabled;
57
58
  const enterTransition = useMemo(() => getTransition(transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, defaultAccessoryEnterTransition), [animate, transitions === null || transitions === void 0 ? void 0 : transitions.enter]);
58
59
  const updateTransition = useMemo(() => getTransition((transitions === null || transitions === void 0 ? void 0 : transitions.update) !== undefined ? transitions.update : transition, animate, defaultTransition), [animate, transitions === null || transitions === void 0 ? void 0 : transitions.update, transition]);
59
- const xScale = getXScale();
60
+ const xScale = getXScale(xAxisId);
60
61
  const yScale = getYScale(yAxisId);
61
62
  const pixelCoordinate = useMemo(() => {
62
63
  if (!xScale || !yScale) {
@@ -49,7 +49,7 @@ export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((
49
49
  } = useCartesianChartContext();
50
50
  const animate = animateProp !== null && animateProp !== void 0 ? animateProp : animateContext;
51
51
  const targetSeries = getSeries(seriesId);
52
- const xScale = getXScale();
52
+ const xScale = getXScale(targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.xAxisId);
53
53
  const yScale = getYScale(targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.yAxisId);
54
54
  const color = useMemo(() => {
55
55
  var _ref2;
@@ -132,7 +132,7 @@ export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((
132
132
  y: pixelCoordinate.y
133
133
  },
134
134
  initial: false,
135
- transition: updateTransition,
135
+ transition: updateTransition !== null && updateTransition !== void 0 ? updateTransition : instantTransition,
136
136
  children: pulseCircle
137
137
  }), /*#__PURE__*/_jsx(motion.circle, {
138
138
  animate: {
@@ -148,7 +148,7 @@ export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((
148
148
  stroke: stroke,
149
149
  strokeWidth: strokeWidth,
150
150
  style: style,
151
- transition: updateTransition
151
+ transition: updateTransition !== null && updateTransition !== void 0 ? updateTransition : instantTransition
152
152
  })]
153
153
  });
154
154
  }));
@@ -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
  });