@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
@@ -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/graphs/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", "transition"];
1
+ const _excluded = ["x", "y", "width", "height", "borderRadius", "roundTop", "roundBottom", "origin", "d", "fill", "fillOpacity", "dataX", "dataY", "seriesId", "minSize", "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; }
@@ -7,9 +7,10 @@ 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 React, { memo, useMemo } from 'react';
10
- import { m as motion } from 'framer-motion';
11
10
  import { useCartesianChartContext } from '../ChartProvider';
12
- import { getBarPath } from '../utils';
11
+ import { Path } from '../Path';
12
+ import { defaultBarEnterTransition, defaultTransition, getBarPath, getTransition, withStaggerDelayTransition } from '../utils';
13
+ import { getNormalizedStagger } from '../utils/bar';
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
14
15
  /**
15
16
  * Default bar component that renders a solid bar with animation.
@@ -17,45 +18,52 @@ import { jsx as _jsx } from "react/jsx-runtime";
17
18
  export const DefaultBar = /*#__PURE__*/memo(_ref => {
18
19
  let {
19
20
  x,
21
+ y,
20
22
  width,
23
+ height,
21
24
  borderRadius = 4,
22
25
  roundTop,
23
26
  roundBottom,
24
- originY,
27
+ origin,
25
28
  d,
26
29
  fill = 'var(--color-fgPrimary)',
27
30
  fillOpacity = 1,
28
31
  dataX,
29
32
  dataY,
33
+ seriesId,
34
+ minSize = 1,
35
+ transitions,
30
36
  transition
31
37
  } = _ref,
32
38
  props = _objectWithoutProperties(_ref, _excluded);
33
39
  const {
34
- animate
40
+ animate,
41
+ drawingArea,
42
+ layout
35
43
  } = useCartesianChartContext();
44
+ const normalizedStagger = useMemo(() => getNormalizedStagger(layout, x, y, drawingArea), [layout, x, y, drawingArea]);
45
+ 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]);
46
+ 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]);
36
47
  const initialPath = useMemo(() => {
37
- if (!animate) return undefined;
38
- // Need a minimum height to allow for animation
39
- const minHeight = 1;
40
- const initialY = (originY !== null && originY !== void 0 ? originY : 0) - minHeight;
41
- return getBarPath(x, initialY, width, minHeight, borderRadius, !!roundTop, !!roundBottom);
42
- }, [animate, x, originY, width, borderRadius, roundTop, roundBottom]);
43
- if (animate && initialPath) {
44
- return /*#__PURE__*/_jsx(motion.path, _objectSpread(_objectSpread({}, props), {}, {
45
- animate: {
46
- d
47
- },
48
- fill: fill,
49
- fillOpacity: fillOpacity,
50
- initial: {
51
- d: initialPath
52
- },
53
- transition: transition
54
- }));
55
- }
56
- return /*#__PURE__*/_jsx("path", _objectSpread(_objectSpread({}, props), {}, {
48
+ if (!animate) return;
49
+ const isHorizontalLayout = layout === 'horizontal';
50
+ const baseline = origin !== null && origin !== void 0 ? origin : isHorizontalLayout ? x : y + height;
51
+ const initialX = isHorizontalLayout ? baseline : x;
52
+ const initialY = isHorizontalLayout ? y : baseline;
53
+ const initialWidth = isHorizontalLayout ? minSize : width;
54
+ const initialHeight = isHorizontalLayout ? height : minSize;
55
+ return getBarPath(initialX, initialY, initialWidth, initialHeight, borderRadius, !!roundTop, !!roundBottom, layout);
56
+ }, [animate, layout, x, y, origin, width, height, borderRadius, roundTop, roundBottom, minSize]);
57
+ return /*#__PURE__*/_jsx(Path, _objectSpread(_objectSpread({}, props), {}, {
58
+ animate: animate,
59
+ clipRect: null,
57
60
  d: d,
58
61
  fill: fill,
59
- fillOpacity: fillOpacity
62
+ fillOpacity: fillOpacity,
63
+ initialPath: initialPath,
64
+ transitions: {
65
+ enter: enterTransition,
66
+ update: updateTransition
67
+ }
60
68
  }));
61
69
  });
@@ -1,7 +1,8 @@
1
1
  import { memo, useId, useMemo } from 'react';
2
2
  import { m as motion } from 'framer-motion';
3
3
  import { useCartesianChartContext } from '../ChartProvider';
4
- import { getBarPath } from '../utils';
4
+ import { defaultBarEnterTransition, defaultTransition, getBarPath, getNormalizedStagger, getStackInitialClipRect, getTransition, withStaggerDelayTransition } from '../utils';
5
+ import { usePathTransition } from '../utils/transition';
5
6
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
6
7
  /**
7
8
  * Default stack component that renders children in a group with animated clip path.
@@ -18,34 +19,46 @@ export const DefaultBarStack = /*#__PURE__*/memo(_ref => {
18
19
  borderRadius = 4,
19
20
  roundTop = true,
20
21
  roundBottom = true,
21
- yOrigin,
22
+ origin,
23
+ transitions,
22
24
  transition
23
25
  } = _ref;
24
26
  const {
25
- animate
27
+ animate,
28
+ drawingArea,
29
+ layout
26
30
  } = useCartesianChartContext();
27
31
  const clipPathId = useId();
32
+ const normalizedStagger = useMemo(() => getNormalizedStagger(layout, x, y, drawingArea), [layout, x, y, drawingArea]);
33
+ 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]);
34
+ 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]);
28
35
  const clipPathData = useMemo(() => {
29
- return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom);
30
- }, [x, y, width, height, borderRadius, roundTop, roundBottom]);
36
+ return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom, layout);
37
+ }, [x, y, width, height, borderRadius, roundTop, roundBottom, layout]);
31
38
  const initialClipPathData = useMemo(() => {
32
- if (!animate) return undefined;
33
- return getBarPath(x, yOrigin !== null && yOrigin !== void 0 ? yOrigin : y + height, width, 1, borderRadius, roundTop, roundBottom);
34
- }, [animate, x, yOrigin, y, height, width, borderRadius, roundTop, roundBottom]);
39
+ if (!animate) return;
40
+ const initialClipRect = getStackInitialClipRect({
41
+ x,
42
+ y,
43
+ width,
44
+ height
45
+ }, layout, origin);
46
+ return getBarPath(initialClipRect.x, initialClipRect.y, initialClipRect.width, initialClipRect.height, borderRadius, roundTop, roundBottom, layout);
47
+ }, [animate, layout, x, y, height, width, borderRadius, roundTop, roundBottom, origin]);
48
+ const animatedClipPath = usePathTransition({
49
+ currentPath: clipPathData,
50
+ initialPath: initialClipPathData,
51
+ transitions: {
52
+ enter: enterTransition,
53
+ update: updateTransition
54
+ }
55
+ });
35
56
  return /*#__PURE__*/_jsxs(_Fragment, {
36
57
  children: [/*#__PURE__*/_jsx("defs", {
37
58
  children: /*#__PURE__*/_jsx("clipPath", {
38
59
  id: clipPathId,
39
- children: animate ? /*#__PURE__*/_jsx(motion.path, {
40
- animate: {
41
- d: clipPathData
42
- },
43
- initial: {
44
- d: initialClipPathData
45
- },
46
- transition: transition
47
- }) : /*#__PURE__*/_jsx("path", {
48
- d: clipPathData
60
+ children: /*#__PURE__*/_jsx(motion.path, {
61
+ d: animatedClipPath
49
62
  })
50
63
  })
51
64
  }), /*#__PURE__*/_jsx("g", {
@@ -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;
@@ -5,6 +5,7 @@ export * from './bar/index';
5
5
  export * from './CartesianChart';
6
6
  export * from './ChartProvider';
7
7
  export * from './gradient/index';
8
+ export * from './legend/index';
8
9
  export * from './line/index';
9
10
  export * from './Path';
10
11
  export * from './PeriodSelector';
@@ -0,0 +1 @@
1
+ .cds-legendEntryCss-l16mq69f{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}
@@ -0,0 +1,50 @@
1
+ const _excluded = ["seriesId", "label", "color", "shape", "ShapeComponent", "gap", "className", "classNames", "style", "styles", "testID"];
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 { cx } from '@coinbase/cds-web';
11
+ import { HStack } from '@coinbase/cds-web/layout';
12
+ import { Text } from '@coinbase/cds-web/typography';
13
+ import { DefaultLegendShape } from './DefaultLegendShape';
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
+ const legendEntryCss = "cds-legendEntryCss-l16mq69f";
16
+ export const DefaultLegendEntry = /*#__PURE__*/memo(_ref => {
17
+ let {
18
+ seriesId,
19
+ label,
20
+ color,
21
+ shape,
22
+ ShapeComponent = DefaultLegendShape,
23
+ gap = 1,
24
+ className,
25
+ classNames,
26
+ style,
27
+ styles,
28
+ testID
29
+ } = _ref,
30
+ props = _objectWithoutProperties(_ref, _excluded);
31
+ return /*#__PURE__*/_jsxs(HStack, _objectSpread(_objectSpread({
32
+ className: cx(legendEntryCss, className, classNames === null || classNames === void 0 ? void 0 : classNames.root),
33
+ "data-testid": testID,
34
+ gap: gap,
35
+ style: _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root)
36
+ }, props), {}, {
37
+ children: [/*#__PURE__*/_jsx(ShapeComponent, {
38
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.shape,
39
+ color: color,
40
+ shape: shape,
41
+ style: styles === null || styles === void 0 ? void 0 : styles.shape
42
+ }), typeof label === 'string' ? /*#__PURE__*/_jsx(Text, {
43
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.label,
44
+ font: "label1",
45
+ style: styles === null || styles === void 0 ? void 0 : styles.label,
46
+ children: label
47
+ }) : label]
48
+ }));
49
+ });
50
+ import "./DefaultLegendEntry.css";
@@ -0,0 +1,5 @@
1
+ .cds-containerCss-c18taxk5{width:10px;height:24px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}
2
+ .cds-pillCss-p17vg36s{width:6px;height:24px;border-radius:3px;}
3
+ .cds-circleCss-cge4n06{width:10px;height:10px;border-radius:5px;}
4
+ .cds-squareCss-s4trv9b{width:10px;height:10px;}
5
+ .cds-squircleCss-s1e4cx3y{width:10px;height:10px;border-radius:2px;}
@@ -0,0 +1,47 @@
1
+ const _excluded = ["color", "shape", "className", "style"];
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 React, { memo } from 'react';
10
+ import { cx } from '@coinbase/cds-web';
11
+ import { Box } from '@coinbase/cds-web/layout';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ const containerCss = "cds-containerCss-c18taxk5";
14
+ const pillCss = "cds-pillCss-p17vg36s";
15
+ const circleCss = "cds-circleCss-cge4n06";
16
+ const squareCss = "cds-squareCss-s4trv9b";
17
+ const squircleCss = "cds-squircleCss-s1e4cx3y";
18
+ const stylesByVariant = {
19
+ pill: pillCss,
20
+ circle: circleCss,
21
+ square: squareCss,
22
+ squircle: squircleCss
23
+ };
24
+ const isVariantShape = shape => typeof shape === 'string' && shape in stylesByVariant;
25
+ export const DefaultLegendShape = /*#__PURE__*/memo(_ref => {
26
+ let {
27
+ color = 'var(--color-fgPrimary)',
28
+ shape = 'circle',
29
+ className,
30
+ style
31
+ } = _ref,
32
+ props = _objectWithoutProperties(_ref, _excluded);
33
+ if (!isVariantShape(shape)) return shape;
34
+ const variantStyle = stylesByVariant[shape];
35
+ return /*#__PURE__*/_jsx(Box, _objectSpread(_objectSpread({
36
+ className: cx(containerCss, className),
37
+ style: style
38
+ }, props), {}, {
39
+ children: /*#__PURE__*/_jsx("span", {
40
+ className: variantStyle,
41
+ style: {
42
+ backgroundColor: color
43
+ }
44
+ })
45
+ }));
46
+ });
47
+ import "./DefaultLegendShape.css";
@@ -0,0 +1,76 @@
1
+ const _excluded = ["flexDirection", "justifyContent", "alignItems", "flexWrap", "columnGap", "rowGap", "seriesIds", "EntryComponent", "ShapeComponent", "accessibilityLabel", "className", "classNames", "style", "styles"];
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 { forwardRef, memo, useMemo } from 'react';
10
+ import { Box } from '@coinbase/cds-web/layout';
11
+ import { useCartesianChartContext } from '../ChartProvider';
12
+ import { DefaultLegendEntry } from './DefaultLegendEntry';
13
+ import { DefaultLegendShape } from './DefaultLegendShape';
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ export const Legend = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
16
+ var _classNames$root;
17
+ let {
18
+ flexDirection = 'row',
19
+ justifyContent = 'center',
20
+ alignItems = flexDirection === 'row' ? 'center' : 'flex-start',
21
+ flexWrap = 'wrap',
22
+ columnGap = 2,
23
+ rowGap = 0.75,
24
+ seriesIds,
25
+ EntryComponent = DefaultLegendEntry,
26
+ ShapeComponent = DefaultLegendShape,
27
+ accessibilityLabel = 'Legend',
28
+ className,
29
+ classNames,
30
+ style,
31
+ styles
32
+ } = _ref,
33
+ props = _objectWithoutProperties(_ref, _excluded);
34
+ const {
35
+ series
36
+ } = useCartesianChartContext();
37
+ const filteredSeries = useMemo(() => {
38
+ if (seriesIds === undefined) return series;
39
+ return series.filter(s => seriesIds.includes(s.id));
40
+ }, [series, seriesIds]);
41
+ if (filteredSeries.length === 0) return;
42
+ return /*#__PURE__*/_jsx(Box, _objectSpread(_objectSpread({
43
+ ref: ref,
44
+ accessibilityLabel: accessibilityLabel,
45
+ alignItems: alignItems,
46
+ className: (_classNames$root = classNames === null || classNames === void 0 ? void 0 : classNames.root) !== null && _classNames$root !== void 0 ? _classNames$root : className,
47
+ columnGap: columnGap,
48
+ flexDirection: flexDirection,
49
+ flexWrap: flexWrap,
50
+ justifyContent: justifyContent,
51
+ role: "group",
52
+ rowGap: rowGap,
53
+ style: _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root)
54
+ }, props), {}, {
55
+ children: filteredSeries.map(s => {
56
+ var _s$label;
57
+ return /*#__PURE__*/_jsx(EntryComponent, {
58
+ ShapeComponent: ShapeComponent,
59
+ classNames: {
60
+ root: classNames === null || classNames === void 0 ? void 0 : classNames.entry,
61
+ shape: classNames === null || classNames === void 0 ? void 0 : classNames.entryShape,
62
+ label: classNames === null || classNames === void 0 ? void 0 : classNames.entryLabel
63
+ },
64
+ color: s.color,
65
+ label: (_s$label = s.label) !== null && _s$label !== void 0 ? _s$label : s.id,
66
+ seriesId: s.id,
67
+ shape: s.legendShape,
68
+ styles: {
69
+ root: styles === null || styles === void 0 ? void 0 : styles.entry,
70
+ shape: styles === null || styles === void 0 ? void 0 : styles.entryShape,
71
+ label: styles === null || styles === void 0 ? void 0 : styles.entryLabel
72
+ }
73
+ }, s.id);
74
+ })
75
+ }));
76
+ }));
@@ -0,0 +1,3 @@
1
+ export * from './DefaultLegendEntry';
2
+ export * from './DefaultLegendShape';
3
+ export * from './Legend';
@@ -1,4 +1,4 @@
1
- const _excluded = ["fill", "stroke", "strokeDasharray", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "vectorEffect", "gradient", "yAxisId", "animate", "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; }
@@ -15,6 +15,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
15
15
  * Supports gradient for gradient effects on the dots.
16
16
  */
17
17
  export const DottedLine = /*#__PURE__*/memo(_ref => {
18
+ var _transitions$update;
18
19
  let {
19
20
  fill = 'none',
20
21
  stroke = 'var(--color-fgPrimary)',
@@ -25,8 +26,10 @@ export const DottedLine = /*#__PURE__*/memo(_ref => {
25
26
  strokeWidth = 2,
26
27
  vectorEffect = 'non-scaling-stroke',
27
28
  gradient,
29
+ xAxisId,
28
30
  yAxisId,
29
31
  animate,
32
+ transitions,
30
33
  transition,
31
34
  d
32
35
  } = _ref,
@@ -38,7 +41,8 @@ export const DottedLine = /*#__PURE__*/memo(_ref => {
38
41
  animate: animate,
39
42
  gradient: gradient,
40
43
  id: gradientId,
41
- transition: transition,
44
+ transition: (_transitions$update = transitions === null || transitions === void 0 ? void 0 : transitions.update) !== null && _transitions$update !== void 0 ? _transitions$update : transition,
45
+ xAxisId: xAxisId,
42
46
  yAxisId: yAxisId
43
47
  })
44
48
  }), /*#__PURE__*/_jsx(Path, _objectSpread({
@@ -53,6 +57,7 @@ export const DottedLine = /*#__PURE__*/memo(_ref => {
53
57
  strokeOpacity: strokeOpacity,
54
58
  strokeWidth: strokeWidth,
55
59
  transition: transition,
60
+ transitions: transitions,
56
61
  vectorEffect: vectorEffect
57
62
  }, props))]
58
63
  });