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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dts/chart/CartesianChart.d.ts +38 -2
  3. package/dts/chart/CartesianChart.d.ts.map +1 -1
  4. package/dts/chart/Path.d.ts +27 -7
  5. package/dts/chart/Path.d.ts.map +1 -1
  6. package/dts/chart/PeriodSelector.d.ts +0 -4
  7. package/dts/chart/PeriodSelector.d.ts.map +1 -1
  8. package/dts/chart/area/Area.d.ts +54 -24
  9. package/dts/chart/area/Area.d.ts.map +1 -1
  10. package/dts/chart/area/AreaChart.d.ts +33 -6
  11. package/dts/chart/area/AreaChart.d.ts.map +1 -1
  12. package/dts/chart/area/DottedArea.d.ts +21 -44
  13. package/dts/chart/area/DottedArea.d.ts.map +1 -1
  14. package/dts/chart/area/GradientArea.d.ts +21 -12
  15. package/dts/chart/area/GradientArea.d.ts.map +1 -1
  16. package/dts/chart/area/SolidArea.d.ts +16 -1
  17. package/dts/chart/area/SolidArea.d.ts.map +1 -1
  18. package/dts/chart/axis/Axis.d.ts +92 -45
  19. package/dts/chart/axis/Axis.d.ts.map +1 -1
  20. package/dts/chart/axis/DefaultAxisTickLabel.d.ts +8 -0
  21. package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +1 -0
  22. package/dts/chart/axis/XAxis.d.ts +1 -1
  23. package/dts/chart/axis/XAxis.d.ts.map +1 -1
  24. package/dts/chart/axis/YAxis.d.ts +1 -1
  25. package/dts/chart/axis/YAxis.d.ts.map +1 -1
  26. package/dts/chart/axis/index.d.ts +1 -0
  27. package/dts/chart/axis/index.d.ts.map +1 -1
  28. package/dts/chart/bar/Bar.d.ts +16 -13
  29. package/dts/chart/bar/Bar.d.ts.map +1 -1
  30. package/dts/chart/bar/BarChart.d.ts +17 -8
  31. package/dts/chart/bar/BarChart.d.ts.map +1 -1
  32. package/dts/chart/bar/BarPlot.d.ts +2 -1
  33. package/dts/chart/bar/BarPlot.d.ts.map +1 -1
  34. package/dts/chart/bar/BarStack.d.ts +40 -48
  35. package/dts/chart/bar/BarStack.d.ts.map +1 -1
  36. package/dts/chart/bar/BarStackGroup.d.ts +1 -0
  37. package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
  38. package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
  39. package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
  40. package/dts/chart/gradient/Gradient.d.ts +35 -0
  41. package/dts/chart/gradient/Gradient.d.ts.map +1 -0
  42. package/dts/chart/gradient/index.d.ts +2 -0
  43. package/dts/chart/gradient/index.d.ts.map +1 -0
  44. package/dts/chart/index.d.ts +2 -1
  45. package/dts/chart/index.d.ts.map +1 -1
  46. package/dts/chart/line/DefaultReferenceLineLabel.d.ts +9 -0
  47. package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +1 -0
  48. package/dts/chart/line/DottedLine.d.ts +15 -3
  49. package/dts/chart/line/DottedLine.d.ts.map +1 -1
  50. package/dts/chart/line/Line.d.ts +70 -28
  51. package/dts/chart/line/Line.d.ts.map +1 -1
  52. package/dts/chart/line/LineChart.d.ts +26 -8
  53. package/dts/chart/line/LineChart.d.ts.map +1 -1
  54. package/dts/chart/line/ReferenceLine.d.ts +91 -44
  55. package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
  56. package/dts/chart/line/SolidLine.d.ts +14 -3
  57. package/dts/chart/line/SolidLine.d.ts.map +1 -1
  58. package/dts/chart/line/index.d.ts +1 -1
  59. package/dts/chart/line/index.d.ts.map +1 -1
  60. package/dts/chart/point/DefaultPointLabel.d.ts +10 -0
  61. package/dts/chart/point/DefaultPointLabel.d.ts.map +1 -0
  62. package/dts/chart/point/Point.d.ts +201 -0
  63. package/dts/chart/point/Point.d.ts.map +1 -0
  64. package/dts/chart/point/index.d.ts +3 -0
  65. package/dts/chart/point/index.d.ts.map +1 -0
  66. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +24 -0
  67. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -0
  68. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +12 -0
  69. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -0
  70. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +10 -0
  71. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
  72. package/dts/chart/scrubber/Scrubber.d.ts +207 -66
  73. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
  74. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +70 -0
  75. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
  76. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +32 -0
  77. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
  78. package/dts/chart/scrubber/index.d.ts +3 -0
  79. package/dts/chart/scrubber/index.d.ts.map +1 -1
  80. package/dts/chart/text/ChartText.d.ts +46 -43
  81. package/dts/chart/text/ChartText.d.ts.map +1 -1
  82. package/dts/chart/text/{SmartChartTextGroup.d.ts → ChartTextGroup.d.ts} +9 -3
  83. package/dts/chart/text/ChartTextGroup.d.ts.map +1 -0
  84. package/dts/chart/text/index.d.ts +1 -1
  85. package/dts/chart/text/index.d.ts.map +1 -1
  86. package/dts/chart/utils/chart.d.ts +27 -7
  87. package/dts/chart/utils/chart.d.ts.map +1 -1
  88. package/dts/chart/utils/context.d.ts +6 -0
  89. package/dts/chart/utils/context.d.ts.map +1 -1
  90. package/dts/chart/utils/gradient.d.ts +104 -0
  91. package/dts/chart/utils/gradient.d.ts.map +1 -0
  92. package/dts/chart/utils/index.d.ts +4 -0
  93. package/dts/chart/utils/index.d.ts.map +1 -1
  94. package/dts/chart/utils/interpolate.d.ts +112 -0
  95. package/dts/chart/utils/interpolate.d.ts.map +1 -0
  96. package/dts/chart/utils/path.d.ts +24 -1
  97. package/dts/chart/utils/path.d.ts.map +1 -1
  98. package/dts/chart/utils/point.d.ts +29 -0
  99. package/dts/chart/utils/point.d.ts.map +1 -1
  100. package/dts/chart/utils/scrubber.d.ts +39 -0
  101. package/dts/chart/utils/scrubber.d.ts.map +1 -0
  102. package/dts/chart/utils/transition.d.ts +65 -0
  103. package/dts/chart/utils/transition.d.ts.map +1 -0
  104. package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -1
  105. package/esm/chart/CartesianChart.js +140 -85
  106. package/esm/chart/Path.js +53 -47
  107. package/esm/chart/PeriodSelector.js +4 -18
  108. package/esm/chart/area/Area.js +24 -34
  109. package/esm/chart/area/AreaChart.js +24 -15
  110. package/esm/chart/area/DottedArea.js +35 -89
  111. package/esm/chart/area/GradientArea.js +34 -80
  112. package/esm/chart/area/SolidArea.js +29 -11
  113. package/esm/chart/axis/Axis.js +4 -25
  114. package/esm/chart/axis/DefaultAxisTickLabel.js +15 -0
  115. package/esm/chart/axis/XAxis.js +76 -52
  116. package/esm/chart/axis/YAxis.js +80 -49
  117. package/esm/chart/axis/index.js +1 -0
  118. package/esm/chart/bar/Bar.js +3 -1
  119. package/esm/chart/bar/BarChart.js +15 -32
  120. package/esm/chart/bar/BarPlot.js +3 -2
  121. package/esm/chart/bar/BarStack.js +65 -23
  122. package/esm/chart/bar/BarStackGroup.js +7 -17
  123. package/esm/chart/bar/DefaultBar.js +4 -7
  124. package/esm/chart/bar/DefaultBarStack.js +5 -7
  125. package/esm/chart/gradient/Gradient.js +104 -0
  126. package/esm/chart/gradient/index.js +1 -0
  127. package/esm/chart/index.js +2 -1
  128. package/esm/chart/line/DefaultReferenceLineLabel.js +81 -0
  129. package/esm/chart/line/DottedLine.js +38 -17
  130. package/esm/chart/line/Line.js +96 -70
  131. package/esm/chart/line/LineChart.js +18 -6
  132. package/esm/chart/line/ReferenceLine.js +41 -43
  133. package/esm/chart/line/SolidLine.js +36 -15
  134. package/esm/chart/line/index.js +1 -1
  135. package/esm/chart/{line/GradientLine.js → point/DefaultPointLabel.js} +31 -45
  136. package/esm/chart/point/Point.css +2 -0
  137. package/esm/chart/{Point.js → point/Point.js} +66 -57
  138. package/esm/chart/point/index.js +2 -0
  139. package/esm/chart/scrubber/DefaultScrubberBeacon.js +155 -0
  140. package/esm/chart/scrubber/{ScrubberBeaconLabel.js → DefaultScrubberBeaconLabel.js} +23 -10
  141. package/esm/chart/scrubber/DefaultScrubberLabel.js +30 -0
  142. package/esm/chart/scrubber/Scrubber.js +98 -392
  143. package/esm/chart/scrubber/ScrubberBeaconGroup.js +166 -0
  144. package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +186 -0
  145. package/esm/chart/scrubber/index.js +3 -1
  146. package/esm/chart/text/ChartText.js +13 -19
  147. package/esm/chart/text/{SmartChartTextGroup.js → ChartTextGroup.js} +4 -3
  148. package/esm/chart/text/index.js +1 -1
  149. package/esm/chart/utils/chart.js +29 -3
  150. package/esm/chart/utils/gradient.js +257 -0
  151. package/esm/chart/utils/index.js +4 -0
  152. package/esm/chart/utils/interpolate.js +644 -0
  153. package/esm/chart/utils/path.js +32 -9
  154. package/esm/chart/utils/point.js +69 -0
  155. package/esm/chart/utils/scrubber.js +132 -0
  156. package/esm/chart/utils/transition.js +111 -0
  157. package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +8 -4
  158. package/package.json +9 -9
  159. package/dts/chart/Point.d.ts +0 -153
  160. package/dts/chart/Point.d.ts.map +0 -1
  161. package/dts/chart/line/GradientLine.d.ts +0 -42
  162. package/dts/chart/line/GradientLine.d.ts.map +0 -1
  163. package/dts/chart/scrubber/ScrubberBeacon.d.ts +0 -93
  164. package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +0 -1
  165. package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +0 -7
  166. package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +0 -1
  167. package/dts/chart/text/SmartChartTextGroup.d.ts.map +0 -1
  168. package/esm/chart/Point.css +0 -2
  169. package/esm/chart/scrubber/ScrubberBeacon.js +0 -195
@@ -3,16 +3,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
3
3
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
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
- import React, { memo, useMemo } from 'react';
6
+ import React, { memo } from 'react';
7
7
  import { cx } from '@coinbase/cds-web';
8
8
  import { useCartesianChartContext } from '../ChartProvider';
9
- import { ChartText } from '../text';
10
9
  import { getPointOnScale } from '../utils';
10
+ import { DefaultReferenceLineLabel } from './DefaultReferenceLineLabel';
11
11
  import { DottedLine } from './DottedLine';
12
-
13
- /**
14
- * Configuration for ReferenceLine label rendering using ChartText.
15
- */
16
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
13
  export const ReferenceLine = /*#__PURE__*/memo(_ref => {
18
14
  let {
@@ -23,8 +19,16 @@ export const ReferenceLine = /*#__PURE__*/memo(_ref => {
23
19
  labelPosition = dataY !== undefined ? 'right' : 'top',
24
20
  testID,
25
21
  LineComponent = DottedLine,
22
+ LabelComponent = DefaultReferenceLineLabel,
23
+ labelElevated,
24
+ labelFont,
25
+ labelDx,
26
+ labelDy,
27
+ labelHorizontalAlignment,
28
+ labelVerticalAlignment,
29
+ labelBoundsInset,
26
30
  stroke = 'var(--color-bgLine)',
27
- labelProps,
31
+ opacity,
28
32
  className,
29
33
  style,
30
34
  classNames,
@@ -36,36 +40,6 @@ export const ReferenceLine = /*#__PURE__*/memo(_ref => {
36
40
  drawingArea
37
41
  } = useCartesianChartContext();
38
42
 
39
- // For horizontal lines (dataY defined): default to verticalAlignment: 'middle'
40
- // For vertical lines (dataX defined): default to horizontalAlignment: 'center'
41
- const isHorizontal = dataY !== undefined;
42
-
43
- // Merge default props with user provided props, including text-specific styles and classNames
44
- const finalLabelProps = useMemo(() => _objectSpread(_objectSpread(_objectSpread({
45
- borderRadius: 4,
46
- color: 'var(--color-fgMuted)',
47
- elevation: 0,
48
- inset: {
49
- top: 8,
50
- bottom: 8,
51
- left: 12,
52
- right: 12
53
- }
54
- }, isHorizontal ? {
55
- verticalAlignment: 'middle'
56
- } : {
57
- horizontalAlignment: 'center'
58
- }), labelProps), {}, {
59
- // Merge classNames for text
60
- classNames: _objectSpread(_objectSpread({}, labelProps === null || labelProps === void 0 ? void 0 : labelProps.classNames), (classNames === null || classNames === void 0 ? void 0 : classNames.label) && {
61
- text: classNames.label
62
- }),
63
- // Merge styles for text
64
- styles: _objectSpread(_objectSpread({}, labelProps === null || labelProps === void 0 ? void 0 : labelProps.styles), (styles === null || styles === void 0 ? void 0 : styles.label) && {
65
- text: styles.label
66
- })
67
- }), [isHorizontal, labelProps, classNames === null || classNames === void 0 ? void 0 : classNames.label, styles === null || styles === void 0 ? void 0 : styles.label]);
68
-
69
43
  // Combine root classNames
70
44
  const rootClassName = cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root);
71
45
  // Combine root styles
@@ -96,12 +70,24 @@ export const ReferenceLine = /*#__PURE__*/memo(_ref => {
96
70
  children: [/*#__PURE__*/_jsx(LineComponent, {
97
71
  animate: false,
98
72
  d: "M".concat(drawingArea.x, ",").concat(yPixel, " L").concat(drawingArea.x + drawingArea.width, ",").concat(yPixel),
99
- stroke: stroke
100
- }), label && /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({}, finalLabelProps), {}, {
73
+ stroke: stroke,
74
+ strokeOpacity: opacity
75
+ }), label && /*#__PURE__*/_jsx(LabelComponent, {
76
+ boundsInset: labelBoundsInset,
77
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.label,
78
+ dx: labelDx,
79
+ dy: labelDy,
80
+ elevated: labelElevated,
81
+ font: labelFont,
82
+ horizontalAlignment: labelHorizontalAlignment,
83
+ opacity: opacity,
84
+ style: styles === null || styles === void 0 ? void 0 : styles.label,
85
+ testID: testID,
86
+ verticalAlignment: labelVerticalAlignment !== null && labelVerticalAlignment !== void 0 ? labelVerticalAlignment : 'middle',
101
87
  x: labelX,
102
88
  y: yPixel,
103
89
  children: label
104
- }))]
90
+ })]
105
91
  });
106
92
  }
107
93
 
@@ -130,12 +116,24 @@ export const ReferenceLine = /*#__PURE__*/memo(_ref => {
130
116
  children: [/*#__PURE__*/_jsx(LineComponent, {
131
117
  animate: false,
132
118
  d: "M".concat(xPixel, ",").concat(drawingArea.y, " L").concat(xPixel, ",").concat(drawingArea.y + drawingArea.height),
133
- stroke: stroke
134
- }), label && /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({}, finalLabelProps), {}, {
119
+ stroke: stroke,
120
+ strokeOpacity: opacity
121
+ }), label && /*#__PURE__*/_jsx(LabelComponent, {
122
+ boundsInset: labelBoundsInset,
123
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.label,
124
+ dx: labelDx,
125
+ dy: labelDy,
126
+ elevated: labelElevated,
127
+ font: labelFont,
128
+ horizontalAlignment: labelHorizontalAlignment !== null && labelHorizontalAlignment !== void 0 ? labelHorizontalAlignment : 'center',
129
+ opacity: opacity,
130
+ style: styles === null || styles === void 0 ? void 0 : styles.label,
131
+ testID: testID,
132
+ verticalAlignment: labelVerticalAlignment,
135
133
  x: xPixel,
136
134
  y: labelY,
137
135
  children: label
138
- }))]
136
+ })]
139
137
  });
140
138
  }
141
139
  return;
@@ -1,4 +1,4 @@
1
- const _excluded = ["fill", "stroke", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth"];
1
+ const _excluded = ["fill", "stroke", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "gradient", "yAxisId", "animate", "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; }
@@ -6,29 +6,50 @@ 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, useId } from 'react';
10
+ import { Gradient } from '../gradient';
10
11
  import { Path } from '../Path';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
12
13
  /**
13
- * A customizable solid line component which uses path element.
14
+ * A customizable solid line component.
15
+ * Supports gradient for gradient effects and smooth data transitions.
14
16
  */
15
17
  export const SolidLine = /*#__PURE__*/memo(_ref => {
16
18
  let {
17
19
  fill = 'none',
18
- stroke = 'var(--color-bgLine)',
20
+ stroke = 'var(--color-fgPrimary)',
19
21
  strokeLinecap = 'round',
20
22
  strokeLinejoin = 'round',
21
23
  strokeOpacity = 1,
22
- strokeWidth = 2
24
+ strokeWidth = 2,
25
+ gradient,
26
+ yAxisId,
27
+ animate,
28
+ transition,
29
+ d
23
30
  } = _ref,
24
31
  props = _objectWithoutProperties(_ref, _excluded);
25
- return /*#__PURE__*/_jsx(Path, _objectSpread({
26
- clipOffset: strokeWidth,
27
- fill: fill,
28
- stroke: stroke,
29
- strokeLinecap: strokeLinecap,
30
- strokeLinejoin: strokeLinejoin,
31
- strokeOpacity: strokeOpacity,
32
- strokeWidth: strokeWidth
33
- }, props));
32
+ const gradientId = useId();
33
+ return /*#__PURE__*/_jsxs(_Fragment, {
34
+ children: [gradient && /*#__PURE__*/_jsx("defs", {
35
+ children: /*#__PURE__*/_jsx(Gradient, {
36
+ animate: animate,
37
+ gradient: gradient,
38
+ id: gradientId,
39
+ transition: transition,
40
+ yAxisId: yAxisId
41
+ })
42
+ }), /*#__PURE__*/_jsx(Path, _objectSpread({
43
+ animate: animate,
44
+ clipOffset: strokeWidth,
45
+ d: d,
46
+ fill: fill,
47
+ stroke: gradient ? "url(#".concat(gradientId, ")") : stroke,
48
+ strokeLinecap: strokeLinecap,
49
+ strokeLinejoin: strokeLinejoin,
50
+ strokeOpacity: strokeOpacity,
51
+ strokeWidth: strokeWidth,
52
+ transition: transition
53
+ }, props))]
54
+ });
34
55
  });
@@ -1,6 +1,6 @@
1
1
  // codegen:start {preset: barrel, include: ./*.tsx, exclude: ./__stories__/*.tsx}
2
+ export * from './DefaultReferenceLineLabel';
2
3
  export * from './DottedLine';
3
- export * from './GradientLine';
4
4
  export * from './Line';
5
5
  export * from './LineChart';
6
6
  export * from './ReferenceLine';
@@ -1,4 +1,4 @@
1
- const _excluded = ["fill", "stroke", "startColor", "endColor", "strokeOpacity", "startOpacity", "endOpacity", "strokeLinecap", "strokeLinejoin", "strokeWidth"];
1
+ const _excluded = ["x", "y", "position", "offset", "children"];
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,53 +6,39 @@ 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, useId } from 'react';
10
- import { Path } from '../Path';
11
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
9
+ import { memo, useMemo } from 'react';
10
+ import { ChartText } from '../text';
11
+ import { getAlignmentFromPosition, getLabelCoordinates } from '../utils/point';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
12
13
  /**
13
- * A gradient line component which uses path element.
14
+ * DefaultPointLabel is the default label component for point labels.
15
+ * It renders text at the specified position relative to the point.
14
16
  */
15
- export const GradientLine = /*#__PURE__*/memo(_ref => {
17
+ export const DefaultPointLabel = /*#__PURE__*/memo(_ref => {
16
18
  let {
17
- fill = 'none',
18
- stroke = 'var(--color-bgLine)',
19
- startColor,
20
- endColor,
21
- strokeOpacity = 1,
22
- startOpacity = strokeOpacity,
23
- endOpacity = strokeOpacity,
24
- strokeLinecap = 'round',
25
- strokeLinejoin = 'round',
26
- strokeWidth = 2
19
+ x,
20
+ y,
21
+ position = 'center',
22
+ offset,
23
+ children
27
24
  } = _ref,
28
25
  props = _objectWithoutProperties(_ref, _excluded);
29
- const patternId = useId();
30
- return /*#__PURE__*/_jsxs(_Fragment, {
31
- children: [/*#__PURE__*/_jsx("defs", {
32
- children: /*#__PURE__*/_jsxs("linearGradient", {
33
- id: patternId,
34
- x1: "0%",
35
- x2: "0%",
36
- y1: "0%",
37
- y2: "100%",
38
- children: [/*#__PURE__*/_jsx("stop", {
39
- offset: "0%",
40
- stopColor: startColor !== null && startColor !== void 0 ? startColor : stroke,
41
- stopOpacity: startOpacity
42
- }), /*#__PURE__*/_jsx("stop", {
43
- offset: "100%",
44
- stopColor: endColor !== null && endColor !== void 0 ? endColor : stroke,
45
- stopOpacity: endOpacity
46
- })]
47
- })
48
- }), /*#__PURE__*/_jsx(Path, _objectSpread({
49
- clipOffset: strokeWidth,
50
- fill: fill,
51
- stroke: "url(#".concat(patternId, ")"),
52
- strokeLinecap: strokeLinecap,
53
- strokeLinejoin: strokeLinejoin,
54
- strokeOpacity: strokeOpacity,
55
- strokeWidth: strokeWidth
56
- }, props))]
57
- });
26
+ const {
27
+ horizontalAlignment,
28
+ verticalAlignment
29
+ } = useMemo(() => getAlignmentFromPosition(position), [position]);
30
+ const labelCoordinates = useMemo(() => {
31
+ if (offset === undefined) return {
32
+ x,
33
+ y
34
+ };
35
+ return getLabelCoordinates(x, y, position, offset);
36
+ }, [x, y, position, offset]);
37
+ return /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({}, props), {}, {
38
+ horizontalAlignment: horizontalAlignment,
39
+ verticalAlignment: verticalAlignment,
40
+ x: labelCoordinates.x,
41
+ y: labelCoordinates.y,
42
+ children: children
43
+ }));
58
44
  });
@@ -0,0 +1,2 @@
1
+ .cds-containerCss-ckemp0e{outline:none;}
2
+ .cds-innerPointCss-ik8duli{border-radius:var(--borderRadius-1000);outline:none;}.cds-innerPointCss-ik8duli:focus{outline:none;}.cds-innerPointCss-ik8duli:focus-visible{outline:2px solid var(--color-fgPrimary);outline-offset:2px;}
@@ -1,4 +1,4 @@
1
- const _excluded = ["dataX", "dataY", "yAxisId", "fill", "radius", "opacity", "onClick", "onScrubberEnter", "className", "style", "classNames", "styles", "stroke", "strokeWidth", "accessibilityLabel", "label", "labelProps", "testID", "pixelCoordinates", "animate"];
1
+ const _excluded = ["dataX", "dataY", "yAxisId", "fill", "radius", "opacity", "onClick", "className", "style", "classNames", "styles", "stroke", "strokeWidth", "accessibilityLabel", "label", "LabelComponent", "labelPosition", "labelOffset", "labelFont", "testID", "animate", "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; }
@@ -6,23 +6,18 @@ 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 React, { memo, useEffect, useMemo } from 'react';
9
+ import React, { memo, useMemo } from 'react';
10
10
  import { cx } from '@coinbase/cds-web';
11
11
  import { m as motion } from 'framer-motion';
12
- import { useCartesianChartContext } from './ChartProvider';
13
- import { ChartText } from './text';
14
- import { projectPoint, useScrubberContext } from './utils';
15
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
16
- const containerCss = "cds-containerCss-c137x6qr";
17
- const innerPointCss = "cds-innerPointCss-i1qyub1f";
12
+ import { useCartesianChartContext } from '../ChartProvider';
13
+ import { projectPoint } from '../utils';
14
+ import { DefaultPointLabel } from './DefaultPointLabel';
15
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
+ const containerCss = "cds-containerCss-ckemp0e";
17
+ const innerPointCss = "cds-innerPointCss-ik8duli";
18
18
 
19
19
  /**
20
- * Parameters passed to renderPoints callback function.
21
- */
22
-
23
- /**
24
- * Shared configuration for point appearance and behavior.
25
- * Used by line-associated points rendered via Line/LineChart components.
20
+ * Props for point label components.
26
21
  */
27
22
 
28
23
  export const Point = /*#__PURE__*/memo(_ref => {
@@ -31,10 +26,9 @@ export const Point = /*#__PURE__*/memo(_ref => {
31
26
  dataY,
32
27
  yAxisId,
33
28
  fill = 'var(--color-fgPrimary)',
34
- radius = 4,
29
+ radius = 5,
35
30
  opacity,
36
31
  onClick,
37
- onScrubberEnter,
38
32
  className,
39
33
  style,
40
34
  classNames,
@@ -43,27 +37,25 @@ export const Point = /*#__PURE__*/memo(_ref => {
43
37
  strokeWidth = 2,
44
38
  accessibilityLabel,
45
39
  label,
46
- labelProps,
40
+ LabelComponent = DefaultPointLabel,
41
+ labelPosition = 'center',
42
+ labelOffset = radius * 2,
43
+ labelFont,
47
44
  testID,
48
- pixelCoordinates,
49
- animate
45
+ animate: animateProp,
46
+ transition
50
47
  } = _ref,
51
48
  svgProps = _objectWithoutProperties(_ref, _excluded);
52
49
  const {
53
50
  getXScale,
54
51
  getYScale,
55
- animate: animationEnabled
52
+ animate: animationEnabled,
53
+ drawingArea
56
54
  } = useCartesianChartContext();
57
- const {
58
- scrubberPosition
59
- } = useScrubberContext();
55
+ const animate = animateProp !== null && animateProp !== void 0 ? animateProp : animationEnabled;
60
56
  const xScale = getXScale();
61
57
  const yScale = getYScale(yAxisId);
62
- const isScrubberHighlighted = scrubberPosition !== undefined && scrubberPosition === dataX;
63
58
  const pixelCoordinate = useMemo(() => {
64
- if (pixelCoordinates) {
65
- return pixelCoordinates;
66
- }
67
59
  if (!xScale || !yScale) {
68
60
  return {
69
61
  x: 0,
@@ -76,15 +68,11 @@ export const Point = /*#__PURE__*/memo(_ref => {
76
68
  xScale,
77
69
  yScale
78
70
  });
79
- }, [xScale, yScale, dataX, dataY, pixelCoordinates]);
80
- useEffect(() => {
81
- if (isScrubberHighlighted && onScrubberEnter) {
82
- onScrubberEnter({
83
- x: pixelCoordinate.x,
84
- y: pixelCoordinate.y
85
- });
86
- }
87
- }, [isScrubberHighlighted, onScrubberEnter, pixelCoordinate.x, pixelCoordinate.y]);
71
+ }, [xScale, yScale, dataX, dataY]);
72
+ const isWithinDrawingArea = useMemo(() => {
73
+ if (!pixelCoordinate) return false;
74
+ return pixelCoordinate.x >= drawingArea.x && pixelCoordinate.x <= drawingArea.x + drawingArea.width && pixelCoordinate.y >= drawingArea.y && pixelCoordinate.y <= drawingArea.y + drawingArea.height;
75
+ }, [pixelCoordinate, drawingArea]);
88
76
  const innerPoint = useMemo(() => {
89
77
  const mergedStyles = _objectSpread(_objectSpread({
90
78
  cursor: onClick !== undefined ? 'pointer' : undefined
@@ -113,15 +101,33 @@ export const Point = /*#__PURE__*/memo(_ref => {
113
101
  });
114
102
  }
115
103
  } : undefined;
116
-
117
- // Use the animate prop if provided, otherwise fall back to chart context
118
- const shouldAnimateInteractions = animate !== null && animate !== void 0 ? animate : animationEnabled;
119
- const shouldAnimatePosition = animate !== null && animate !== void 0 ? animate : animationEnabled;
104
+ if (!animate) {
105
+ return /*#__PURE__*/_jsx("circle", _objectSpread({
106
+ "aria-label": accessibilityLabel,
107
+ className: cx(innerPointCss, className, classNames === null || classNames === void 0 ? void 0 : classNames.point),
108
+ cx: pixelCoordinate.x,
109
+ cy: pixelCoordinate.y,
110
+ fill: fill,
111
+ onClick: onClick ? event => onClick(event, {
112
+ dataX,
113
+ dataY,
114
+ x: pixelCoordinate.x,
115
+ y: pixelCoordinate.y
116
+ }) : undefined,
117
+ onKeyDown: handleKeyDown,
118
+ r: radius,
119
+ role: onClick ? 'button' : undefined,
120
+ stroke: stroke,
121
+ strokeWidth: strokeWidth,
122
+ style: mergedStyles,
123
+ tabIndex: onClick ? 0 : -1
124
+ }, svgProps));
125
+ }
120
126
  return /*#__PURE__*/_jsx(motion.circle, _objectSpread({
121
- animate: shouldAnimatePosition ? {
127
+ animate: {
122
128
  cx: pixelCoordinate.x,
123
129
  cy: pixelCoordinate.y
124
- } : undefined,
130
+ },
125
131
  "aria-label": accessibilityLabel,
126
132
  className: cx(innerPointCss, className, classNames === null || classNames === void 0 ? void 0 : classNames.point),
127
133
  cx: pixelCoordinate.x,
@@ -141,31 +147,34 @@ export const Point = /*#__PURE__*/memo(_ref => {
141
147
  strokeWidth: strokeWidth,
142
148
  style: mergedStyles,
143
149
  tabIndex: onClick ? 0 : -1,
144
- transition: {
145
- duration: 0.3,
146
- ease: 'easeInOut'
147
- },
150
+ transition: transition,
148
151
  variants: variants,
149
- whileHover: shouldAnimateInteractions && onClick ? 'hovered' : 'default',
150
- whileTap: shouldAnimateInteractions && onClick ? 'pressed' : 'default'
152
+ whileHover: onClick ? 'hovered' : 'default',
153
+ whileTap: onClick ? 'pressed' : 'default'
151
154
  }, svgProps));
152
- }, [style, styles === null || styles === void 0 ? void 0 : styles.point, classNames === null || classNames === void 0 ? void 0 : classNames.point, fill, animate, animationEnabled, radius, className, onClick, stroke, strokeWidth, svgProps, dataX, dataY, pixelCoordinate.x, pixelCoordinate.y, accessibilityLabel]);
155
+ }, [style, styles === null || styles === void 0 ? void 0 : styles.point, classNames === null || classNames === void 0 ? void 0 : classNames.point, fill, animate, radius, className, onClick, stroke, strokeWidth, svgProps, dataX, dataY, pixelCoordinate.x, pixelCoordinate.y, accessibilityLabel, transition]);
153
156
  if (!xScale || !yScale) {
154
- return null;
157
+ return;
155
158
  }
156
- return /*#__PURE__*/_jsxs(_Fragment, {
159
+ return /*#__PURE__*/_jsxs("g", {
160
+ opacity: isWithinDrawingArea ? 1 : 0,
157
161
  children: [/*#__PURE__*/_jsx("g", {
158
- className: cx(containerCss, classNames === null || classNames === void 0 ? void 0 : classNames.container),
162
+ className: cx(containerCss, classNames === null || classNames === void 0 ? void 0 : classNames.root),
159
163
  "data-testid": testID,
160
164
  opacity: opacity,
161
- style: styles === null || styles === void 0 ? void 0 : styles.container,
165
+ style: styles === null || styles === void 0 ? void 0 : styles.root,
162
166
  children: innerPoint
163
- }), label && /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({
167
+ }), label && /*#__PURE__*/_jsx(LabelComponent, {
168
+ dataX: dataX,
169
+ dataY: dataY,
170
+ fill: fill,
171
+ font: labelFont,
172
+ offset: labelOffset,
173
+ position: labelPosition,
164
174
  x: pixelCoordinate.x,
165
- y: pixelCoordinate.y
166
- }, labelProps), {}, {
175
+ y: pixelCoordinate.y,
167
176
  children: label
168
- }))]
177
+ })]
169
178
  });
170
179
  });
171
180
  import "./Point.css";
@@ -0,0 +1,2 @@
1
+ export * from './DefaultPointLabel';
2
+ export * from './Point';