@coinbase/cds-web-visualization 3.4.0-beta.5 → 3.4.0-beta.6

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 (167) hide show
  1. package/CHANGELOG.md +9 -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 +89 -43
  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 +85 -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 +203 -64
  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/esm/chart/CartesianChart.js +140 -85
  105. package/esm/chart/Path.js +51 -46
  106. package/esm/chart/PeriodSelector.js +4 -18
  107. package/esm/chart/area/Area.js +24 -34
  108. package/esm/chart/area/AreaChart.js +24 -15
  109. package/esm/chart/area/DottedArea.js +35 -89
  110. package/esm/chart/area/GradientArea.js +34 -80
  111. package/esm/chart/area/SolidArea.js +29 -11
  112. package/esm/chart/axis/Axis.js +4 -25
  113. package/esm/chart/axis/DefaultAxisTickLabel.js +15 -0
  114. package/esm/chart/axis/XAxis.js +53 -36
  115. package/esm/chart/axis/YAxis.js +55 -32
  116. package/esm/chart/axis/index.js +1 -0
  117. package/esm/chart/bar/Bar.js +3 -1
  118. package/esm/chart/bar/BarChart.js +15 -32
  119. package/esm/chart/bar/BarPlot.js +3 -2
  120. package/esm/chart/bar/BarStack.js +65 -23
  121. package/esm/chart/bar/BarStackGroup.js +7 -17
  122. package/esm/chart/bar/DefaultBar.js +4 -7
  123. package/esm/chart/bar/DefaultBarStack.js +5 -7
  124. package/esm/chart/gradient/Gradient.js +104 -0
  125. package/esm/chart/gradient/index.js +1 -0
  126. package/esm/chart/index.js +2 -1
  127. package/esm/chart/line/DefaultReferenceLineLabel.js +81 -0
  128. package/esm/chart/line/DottedLine.js +38 -17
  129. package/esm/chart/line/Line.js +96 -70
  130. package/esm/chart/line/LineChart.js +18 -6
  131. package/esm/chart/line/ReferenceLine.js +34 -41
  132. package/esm/chart/line/SolidLine.js +36 -15
  133. package/esm/chart/line/index.js +1 -1
  134. package/esm/chart/{line/GradientLine.js → point/DefaultPointLabel.js} +31 -45
  135. package/esm/chart/point/Point.css +2 -0
  136. package/esm/chart/{Point.js → point/Point.js} +66 -57
  137. package/esm/chart/point/index.js +2 -0
  138. package/esm/chart/scrubber/DefaultScrubberBeacon.js +155 -0
  139. package/esm/chart/scrubber/{ScrubberBeaconLabel.js → DefaultScrubberBeaconLabel.js} +23 -10
  140. package/esm/chart/scrubber/DefaultScrubberLabel.js +30 -0
  141. package/esm/chart/scrubber/Scrubber.js +98 -392
  142. package/esm/chart/scrubber/ScrubberBeaconGroup.js +166 -0
  143. package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +186 -0
  144. package/esm/chart/scrubber/index.js +3 -1
  145. package/esm/chart/text/ChartText.js +13 -19
  146. package/esm/chart/text/{SmartChartTextGroup.js → ChartTextGroup.js} +4 -3
  147. package/esm/chart/text/index.js +1 -1
  148. package/esm/chart/utils/chart.js +29 -3
  149. package/esm/chart/utils/gradient.js +257 -0
  150. package/esm/chart/utils/index.js +4 -0
  151. package/esm/chart/utils/interpolate.js +644 -0
  152. package/esm/chart/utils/path.js +32 -9
  153. package/esm/chart/utils/point.js +69 -0
  154. package/esm/chart/utils/scrubber.js +132 -0
  155. package/esm/chart/utils/transition.js +111 -0
  156. package/package.json +5 -5
  157. package/dts/chart/Point.d.ts +0 -153
  158. package/dts/chart/Point.d.ts.map +0 -1
  159. package/dts/chart/line/GradientLine.d.ts +0 -42
  160. package/dts/chart/line/GradientLine.d.ts.map +0 -1
  161. package/dts/chart/scrubber/ScrubberBeacon.d.ts +0 -93
  162. package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +0 -1
  163. package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +0 -7
  164. package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +0 -1
  165. package/dts/chart/text/SmartChartTextGroup.d.ts.map +0 -1
  166. package/esm/chart/Point.css +0 -2
  167. package/esm/chart/scrubber/ScrubberBeacon.js +0 -195
@@ -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';
@@ -0,0 +1,155 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ import { forwardRef, memo, useImperativeHandle, useMemo } from 'react';
7
+ import { m as motion, useAnimate } from 'framer-motion';
8
+ import { useCartesianChartContext } from '../ChartProvider';
9
+ import { defaultTransition, projectPoint } from '../utils';
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ const radius = 5;
12
+ const strokeWidth = 2;
13
+ const pulseOpacityStart = 0.5;
14
+ const pulseOpacityEnd = 0;
15
+ const pulseRadiusStart = 10;
16
+ const pulseRadiusEnd = 15;
17
+ const defaultPulseTransition = {
18
+ duration: 1.6,
19
+ ease: [0.0, 0.0, 0.0, 1.0]
20
+ };
21
+ const defaultPulseRepeatDelay = 0.4;
22
+ export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
23
+ let {
24
+ seriesId,
25
+ color: colorProp,
26
+ dataX,
27
+ dataY,
28
+ isIdle,
29
+ idlePulse,
30
+ transitions,
31
+ opacity = 1,
32
+ className,
33
+ style,
34
+ testID
35
+ } = _ref;
36
+ const [scope, animate] = useAnimate();
37
+ const {
38
+ getSeries,
39
+ getXScale,
40
+ getYScale,
41
+ drawingArea
42
+ } = useCartesianChartContext();
43
+ const targetSeries = getSeries(seriesId);
44
+ const xScale = getXScale();
45
+ const yScale = getYScale(targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.yAxisId);
46
+ const color = useMemo(() => {
47
+ var _ref2;
48
+ return (_ref2 = colorProp !== null && colorProp !== void 0 ? colorProp : targetSeries === null || targetSeries === void 0 ? void 0 : targetSeries.color) !== null && _ref2 !== void 0 ? _ref2 : 'var(--color-fgPrimary)';
49
+ }, [colorProp, targetSeries]);
50
+ const updateTransition = useMemo(() => {
51
+ var _transitions$update;
52
+ return (_transitions$update = transitions === null || transitions === void 0 ? void 0 : transitions.update) !== null && _transitions$update !== void 0 ? _transitions$update : defaultTransition;
53
+ }, [transitions === null || transitions === void 0 ? void 0 : transitions.update]);
54
+ const pulseTransition = useMemo(() => {
55
+ var _transitions$pulse;
56
+ return (_transitions$pulse = transitions === null || transitions === void 0 ? void 0 : transitions.pulse) !== null && _transitions$pulse !== void 0 ? _transitions$pulse : defaultPulseTransition;
57
+ }, [transitions === null || transitions === void 0 ? void 0 : transitions.pulse]);
58
+ const pulseRepeatDelay = useMemo(() => {
59
+ var _transitions$pulseRep;
60
+ return (_transitions$pulseRep = transitions === null || transitions === void 0 ? void 0 : transitions.pulseRepeatDelay) !== null && _transitions$pulseRep !== void 0 ? _transitions$pulseRep : defaultPulseRepeatDelay;
61
+ }, [transitions === null || transitions === void 0 ? void 0 : transitions.pulseRepeatDelay]);
62
+ const pixelCoordinate = useMemo(() => {
63
+ if (!xScale || !yScale) return;
64
+ return projectPoint({
65
+ x: dataX,
66
+ y: dataY,
67
+ xScale,
68
+ yScale
69
+ });
70
+ }, [dataX, dataY, xScale, yScale]);
71
+ useImperativeHandle(ref, () => ({
72
+ pulse: () => {
73
+ // Only pulse when idle and idlePulse is not enabled
74
+ if (isIdle && !idlePulse && scope.current) {
75
+ animate(scope.current, {
76
+ opacity: [pulseOpacityStart, pulseOpacityEnd],
77
+ r: [pulseRadiusStart, pulseRadiusEnd]
78
+ }, pulseTransition);
79
+ }
80
+ }
81
+ }), [isIdle, idlePulse, scope, animate, pulseTransition]);
82
+
83
+ // Create continuous pulse transition by repeating the base pulse transition with delay
84
+ const continuousPulseTransition = useMemo(() => _objectSpread(_objectSpread({}, pulseTransition), {}, {
85
+ repeat: Infinity,
86
+ repeatDelay: pulseRepeatDelay
87
+ }), [pulseTransition, pulseRepeatDelay]);
88
+ const shouldPulse = isIdle && idlePulse;
89
+ const isWithinDrawingArea = useMemo(() => {
90
+ if (!pixelCoordinate) return false;
91
+ return pixelCoordinate.x >= drawingArea.x && pixelCoordinate.x <= drawingArea.x + drawingArea.width && pixelCoordinate.y >= drawingArea.y && pixelCoordinate.y <= drawingArea.y + drawingArea.height;
92
+ }, [pixelCoordinate, drawingArea]);
93
+ if (!pixelCoordinate) return;
94
+ if (isIdle) {
95
+ return /*#__PURE__*/_jsxs("g", {
96
+ "data-testid": testID,
97
+ opacity: isWithinDrawingArea ? opacity : 0,
98
+ children: [/*#__PURE__*/_jsx(motion.g, {
99
+ animate: {
100
+ x: pixelCoordinate.x,
101
+ y: pixelCoordinate.y
102
+ },
103
+ initial: false,
104
+ transition: updateTransition,
105
+ children: /*#__PURE__*/_jsx(motion.circle, {
106
+ ref: scope,
107
+ animate: shouldPulse ? {
108
+ opacity: [pulseOpacityStart, pulseOpacityEnd],
109
+ r: [pulseRadiusStart, pulseRadiusEnd],
110
+ transition: continuousPulseTransition
111
+ } : {
112
+ opacity: pulseOpacityEnd,
113
+ r: pulseRadiusStart
114
+ },
115
+ cx: 0,
116
+ cy: 0,
117
+ fill: color,
118
+ initial: {
119
+ opacity: shouldPulse ? pulseOpacityStart : pulseOpacityEnd,
120
+ r: pulseRadiusStart
121
+ }
122
+ })
123
+ }), /*#__PURE__*/_jsx(motion.circle, {
124
+ animate: {
125
+ cx: pixelCoordinate.x,
126
+ cy: pixelCoordinate.y
127
+ },
128
+ className: className,
129
+ cx: pixelCoordinate.x,
130
+ cy: pixelCoordinate.y,
131
+ fill: color,
132
+ initial: false,
133
+ r: radius,
134
+ stroke: "var(--color-bg)",
135
+ strokeWidth: strokeWidth,
136
+ style: style,
137
+ transition: updateTransition
138
+ })]
139
+ });
140
+ }
141
+ return /*#__PURE__*/_jsx("g", {
142
+ "data-testid": testID,
143
+ opacity: isWithinDrawingArea ? opacity : 0,
144
+ children: /*#__PURE__*/_jsx("circle", {
145
+ className: className,
146
+ cx: pixelCoordinate.x,
147
+ cy: pixelCoordinate.y,
148
+ fill: color,
149
+ r: radius,
150
+ stroke: "var(--color-bg)",
151
+ strokeWidth: strokeWidth,
152
+ style: style
153
+ })
154
+ });
155
+ }));
@@ -1,4 +1,4 @@
1
- const _excluded = ["background", "color", "elevation", "borderRadius", "font", "verticalAlignment"];
1
+ const _excluded = ["background", "color", "elevated", "borderRadius", "font", "verticalAlignment", "inset", "label"];
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; }
@@ -9,25 +9,38 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
9
9
  import { memo } from 'react';
10
10
  import { ChartText } from '../text';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
+ const labelVerticalInset = 3.5;
13
+ const labelHorizontalInset = 4;
12
14
  /**
13
- * The ScrubberBeaconLabel is a special instance of ChartText used to label a series' scrubber beacon (i.e. a point on the series pinned to the scrubber position).
15
+ * DefaultScrubberBeaconLabel is a special instance of ChartText used to label a series' scrubber beacon (i.e. a point on the series pinned to the scrubber position).
14
16
  */
15
- export const ScrubberBeaconLabel = /*#__PURE__*/memo(_ref => {
17
+ export const DefaultScrubberBeaconLabel = /*#__PURE__*/memo(_ref => {
16
18
  let {
17
- background = 'white',
19
+ background = 'var(--color-bg',
18
20
  color = 'var(--color-fgPrimary)',
19
- elevation = background !== undefined ? 1 : undefined,
20
- borderRadius = background !== undefined ? 4 : undefined,
21
+ elevated = true,
22
+ borderRadius = 4,
21
23
  font = 'label1',
22
- verticalAlignment = 'middle'
24
+ verticalAlignment = 'middle',
25
+ inset = {
26
+ left: labelHorizontalInset,
27
+ right: labelHorizontalInset,
28
+ top: labelVerticalInset,
29
+ bottom: labelVerticalInset
30
+ },
31
+ label
23
32
  } = _ref,
24
33
  chartTextProps = _objectWithoutProperties(_ref, _excluded);
25
- return /*#__PURE__*/_jsx(ChartText, _objectSpread({
34
+ return /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({
35
+ disableRepositioning: true,
26
36
  background: background,
27
37
  borderRadius: borderRadius,
28
38
  color: color,
29
- elevation: elevation,
39
+ elevated: elevated,
30
40
  font: font,
41
+ inset: inset,
31
42
  verticalAlignment: verticalAlignment
32
- }, chartTextProps));
43
+ }, chartTextProps), {}, {
44
+ children: label
45
+ }));
33
46
  });
@@ -0,0 +1,30 @@
1
+ const _excluded = ["verticalAlignment", "dy"];
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
8
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
9
+ import { memo } from 'react';
10
+ import { useCartesianChartContext } from '../ChartProvider';
11
+ import { DefaultReferenceLineLabel } from '../line';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ /**
14
+ * DefaultScrubberLabel is the default label component for the scrubber line.
15
+ * It will center the label vertically with the top available area.
16
+ */
17
+ export const DefaultScrubberLabel = /*#__PURE__*/memo(_ref => {
18
+ let {
19
+ verticalAlignment = 'middle',
20
+ dy
21
+ } = _ref,
22
+ props = _objectWithoutProperties(_ref, _excluded);
23
+ const {
24
+ drawingArea
25
+ } = useCartesianChartContext();
26
+ return /*#__PURE__*/_jsx(DefaultReferenceLineLabel, _objectSpread({
27
+ dy: dy !== null && dy !== void 0 ? dy : -0.5 * drawingArea.y,
28
+ verticalAlignment: verticalAlignment
29
+ }, props));
30
+ });