@coinbase/cds-web-visualization 3.3.0 → 3.4.0-beta.1
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.
- package/CHANGELOG.md +26 -0
- package/dts/chart/CartesianChart.d.ts +36 -0
- package/dts/chart/CartesianChart.d.ts.map +1 -0
- package/dts/chart/ChartProvider.d.ts +6 -0
- package/dts/chart/ChartProvider.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +34 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +61 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/Point.d.ts +153 -0
- package/dts/chart/Point.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +48 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +52 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +68 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +30 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +8 -0
- package/dts/chart/area/SolidArea.d.ts.map +1 -0
- package/dts/chart/area/index.d.ts +6 -0
- package/dts/chart/area/index.d.ts.map +1 -0
- package/dts/chart/axis/Axis.d.ts +208 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- package/dts/chart/axis/XAxis.d.ts +16 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -0
- package/dts/chart/axis/YAxis.d.ts +21 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -0
- package/dts/chart/axis/index.d.ts +4 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +91 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +53 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +29 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +111 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +35 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBar.d.ts +17 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +16 -0
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
- package/dts/chart/bar/index.d.ts +8 -0
- package/dts/chart/bar/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +13 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +14 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/GradientLine.d.ts +42 -0
- package/dts/chart/line/GradientLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +80 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +59 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +131 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +14 -0
- package/dts/chart/line/SolidLine.d.ts.map +1 -0
- package/dts/chart/line/index.d.ts +7 -0
- package/dts/chart/line/index.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +149 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +93 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +7 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +2 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +114 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts +55 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +3 -0
- package/dts/chart/text/index.d.ts.map +1 -0
- package/dts/chart/utils/axis.d.ts +342 -0
- package/dts/chart/utils/axis.d.ts.map +1 -0
- package/dts/chart/utils/bar.d.ts +20 -0
- package/dts/chart/utils/bar.d.ts.map +1 -0
- package/dts/chart/utils/chart.d.ts +97 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +95 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +8 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +107 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +75 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +43 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/index.d.ts +2 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/Counter.d.ts +7 -2
- package/dts/sparkline/Sparkline.d.ts +61 -16
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +12 -4
- package/dts/sparkline/SparklineArea.d.ts.map +1 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +12 -4
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
- package/dts/sparkline/SparklineGradient.d.ts +21 -10
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
- package/dts/sparkline/SparklinePath.d.ts +8 -6
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +1 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +8 -2
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
- package/dts/sparkline/index.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +9 -5
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +168 -118
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +22 -9
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +4 -2
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +4 -2
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +5 -3
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +21 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +21 -16
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +17 -12
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +23 -10
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +12 -12
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +22 -14
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/fade.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +11 -11
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +101 -93
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
- package/esm/chart/CartesianChart.css +1 -0
- package/esm/chart/CartesianChart.js +258 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +89 -0
- package/esm/chart/PeriodSelector.css +1 -0
- package/esm/chart/PeriodSelector.js +126 -0
- package/esm/chart/Point.css +2 -0
- package/esm/chart/Point.js +171 -0
- package/esm/chart/area/Area.js +85 -0
- package/esm/chart/area/AreaChart.js +164 -0
- package/esm/chart/area/DottedArea.js +141 -0
- package/esm/chart/area/GradientArea.js +111 -0
- package/esm/chart/area/SolidArea.js +29 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +46 -0
- package/esm/chart/axis/XAxis.css +2 -0
- package/esm/chart/axis/XAxis.js +195 -0
- package/esm/chart/axis/YAxis.css +2 -0
- package/esm/chart/axis/YAxis.js +183 -0
- package/esm/chart/axis/index.js +5 -0
- package/esm/chart/bar/Bar.js +59 -0
- package/esm/chart/bar/BarChart.js +147 -0
- package/esm/chart/bar/BarPlot.js +96 -0
- package/esm/chart/bar/BarStack.js +519 -0
- package/esm/chart/bar/BarStackGroup.js +96 -0
- package/esm/chart/bar/DefaultBar.js +64 -0
- package/esm/chart/bar/DefaultBarStack.js +60 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/index.js +14 -0
- package/esm/chart/line/DottedLine.js +38 -0
- package/esm/chart/line/GradientLine.js +58 -0
- package/esm/chart/line/Line.js +159 -0
- package/esm/chart/line/LineChart.js +120 -0
- package/esm/chart/line/ReferenceLine.js +142 -0
- package/esm/chart/line/SolidLine.js +34 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/scrubber/Scrubber.js +483 -0
- package/esm/chart/scrubber/ScrubberBeacon.js +195 -0
- package/esm/chart/scrubber/ScrubberBeaconLabel.js +33 -0
- package/esm/chart/scrubber/ScrubberProvider.js +228 -0
- package/esm/chart/scrubber/index.js +2 -0
- package/esm/chart/text/ChartText.js +236 -0
- package/esm/chart/text/SmartChartTextGroup.js +226 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +593 -0
- package/esm/chart/utils/bar.js +24 -0
- package/esm/chart/utils/chart.js +229 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/index.js +9 -0
- package/esm/chart/utils/path.js +204 -0
- package/esm/chart/utils/point.js +118 -0
- package/esm/chart/utils/scale.js +48 -0
- package/esm/index.js +4 -1
- package/esm/sparkline/Sparkline.js +129 -15
- package/esm/sparkline/SparklineArea.js +7 -2
- package/esm/sparkline/SparklineAreaPattern.js +4 -2
- package/esm/sparkline/SparklineGradient.js +16 -58
- package/esm/sparkline/generateSparklineWithId.js +3 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
- package/package.json +15 -11
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -374
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -87
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const _excluded = ["animate", "clipRect", "clipOffset", "d"];
|
|
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 'd3-transition';
|
|
10
|
+
import { memo, useCallback, useEffect, useId, useRef } from 'react';
|
|
11
|
+
import { useValueChanges } from '@coinbase/cds-common/hooks/useValueChanges';
|
|
12
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
13
|
+
import { select } from 'd3-selection';
|
|
14
|
+
import { m as motion } from 'framer-motion';
|
|
15
|
+
import { useCartesianChartContext } from './ChartProvider';
|
|
16
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export const Path = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
animate: animateProp,
|
|
20
|
+
clipRect,
|
|
21
|
+
clipOffset = 0,
|
|
22
|
+
d = ''
|
|
23
|
+
} = _ref,
|
|
24
|
+
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
+
const pathRef = useRef(null);
|
|
26
|
+
const clipPathId = useId();
|
|
27
|
+
const context = useCartesianChartContext();
|
|
28
|
+
const rect = clipRect !== null && clipRect !== void 0 ? clipRect : context.drawingArea;
|
|
29
|
+
const animate = animateProp !== null && animateProp !== void 0 ? animateProp : context.animate;
|
|
30
|
+
const {
|
|
31
|
+
previousValue: previousPath,
|
|
32
|
+
newValue: newPath,
|
|
33
|
+
hasChanged,
|
|
34
|
+
addPreviousValue
|
|
35
|
+
} = useValueChanges(d);
|
|
36
|
+
const morphPath = useCallback(() => {
|
|
37
|
+
if (!pathRef.current || !newPath || !previousPath) return;
|
|
38
|
+
select(pathRef.current).transition().duration(300).attrTween('d', function tween() {
|
|
39
|
+
return interpolatePath(previousPath, newPath);
|
|
40
|
+
});
|
|
41
|
+
}, [previousPath, newPath]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
addPreviousValue(newPath);
|
|
44
|
+
if (animate && hasChanged && previousPath) {
|
|
45
|
+
morphPath();
|
|
46
|
+
}
|
|
47
|
+
}, [addPreviousValue, newPath, animate, hasChanged, previousPath, morphPath]);
|
|
48
|
+
|
|
49
|
+
// The clip offset provides extra padding to prevent path from being cut off
|
|
50
|
+
// Area charts typically use offset=0 for exact clipping, while lines use offset=2 for breathing room
|
|
51
|
+
const totalOffset = clipOffset * 2; // Applied on both sides
|
|
52
|
+
|
|
53
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
54
|
+
children: [/*#__PURE__*/_jsx("defs", {
|
|
55
|
+
children: /*#__PURE__*/_jsx("clipPath", {
|
|
56
|
+
id: clipPathId,
|
|
57
|
+
children: !animate ? /*#__PURE__*/_jsx("rect", {
|
|
58
|
+
height: rect.height + totalOffset,
|
|
59
|
+
width: rect.width + totalOffset,
|
|
60
|
+
x: rect.x - clipOffset,
|
|
61
|
+
y: rect.y - clipOffset
|
|
62
|
+
}) : /*#__PURE__*/_jsx(motion.rect, {
|
|
63
|
+
animate: "visible",
|
|
64
|
+
height: rect.height + totalOffset,
|
|
65
|
+
initial: "hidden",
|
|
66
|
+
variants: {
|
|
67
|
+
hidden: {
|
|
68
|
+
width: 0
|
|
69
|
+
},
|
|
70
|
+
visible: {
|
|
71
|
+
width: rect.width + totalOffset,
|
|
72
|
+
transition: {
|
|
73
|
+
type: 'spring',
|
|
74
|
+
duration: 1,
|
|
75
|
+
bounce: 0
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
x: rect.x - clipOffset,
|
|
80
|
+
y: rect.y - clipOffset
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
}), /*#__PURE__*/_jsx("path", _objectSpread({
|
|
84
|
+
ref: pathRef,
|
|
85
|
+
clipPath: "url(#".concat(clipPathId, ")"),
|
|
86
|
+
d: d
|
|
87
|
+
}, pathProps))]
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.cds-dotBaseCss-dfbcvh4{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;width:var(--space-1);height:var(--space-1);background:currentColor;border-radius:1000px;margin-inline-end:var(--space-0_75);}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const _excluded = ["as", "color", "label", "display", "alignItems", "font", "hideDot", "disablePulse"],
|
|
2
|
+
_excluded2 = ["background", "activeBackground", "width", "justifyContent", "TabComponent", "TabsActiveIndicatorComponent"];
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
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; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
+
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); }
|
|
10
|
+
import React, { forwardRef, memo, useMemo } from 'react';
|
|
11
|
+
import { Box } from '@coinbase/cds-web/layout';
|
|
12
|
+
import { SegmentedTabs, tabsTransitionConfig } from '@coinbase/cds-web/tabs';
|
|
13
|
+
import { SegmentedTab } from '@coinbase/cds-web/tabs/SegmentedTab';
|
|
14
|
+
import { Text } from '@coinbase/cds-web/typography';
|
|
15
|
+
import { m as motion } from 'framer-motion';
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
const MotionBox = motion(Box);
|
|
18
|
+
const pulseTransitionConfig = {
|
|
19
|
+
duration: 2,
|
|
20
|
+
repeat: Infinity,
|
|
21
|
+
ease: 'easeInOut'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Animated active indicator to support smooth transition of background color
|
|
25
|
+
export const PeriodSelectorActiveIndicator = /*#__PURE__*/memo(_ref => {
|
|
26
|
+
let {
|
|
27
|
+
activeTabRect,
|
|
28
|
+
background = 'bgPrimaryWash',
|
|
29
|
+
position = 'absolute',
|
|
30
|
+
borderRadius = 1000,
|
|
31
|
+
style
|
|
32
|
+
} = _ref;
|
|
33
|
+
const {
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
x
|
|
37
|
+
} = activeTabRect;
|
|
38
|
+
const activeAnimation = useMemo(() => ({
|
|
39
|
+
width,
|
|
40
|
+
x
|
|
41
|
+
}), [width, x]);
|
|
42
|
+
if (!width) return null;
|
|
43
|
+
return /*#__PURE__*/_jsx(MotionBox, {
|
|
44
|
+
animate: activeAnimation,
|
|
45
|
+
borderRadius: borderRadius,
|
|
46
|
+
"data-testid": "period-selector-active-indicator",
|
|
47
|
+
height: height,
|
|
48
|
+
initial: false,
|
|
49
|
+
position: position,
|
|
50
|
+
role: "none",
|
|
51
|
+
style: _objectSpread({
|
|
52
|
+
backgroundColor: "var(--color-".concat(background, ")"),
|
|
53
|
+
transition: 'background-color 0.2s ease'
|
|
54
|
+
}, style),
|
|
55
|
+
transition: tabsTransitionConfig
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
export const liveTabLabelDefaultElement = 'span';
|
|
59
|
+
// is this bad to use var(--space-1) for height and width?
|
|
60
|
+
const dotBaseCss = "cds-dotBaseCss-dfbcvh4";
|
|
61
|
+
export const LiveTabLabel = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
62
|
+
let {
|
|
63
|
+
as,
|
|
64
|
+
color = 'fgNegative',
|
|
65
|
+
label = 'LIVE',
|
|
66
|
+
display = 'inline-flex',
|
|
67
|
+
alignItems = 'center',
|
|
68
|
+
font = 'label1',
|
|
69
|
+
hideDot,
|
|
70
|
+
disablePulse
|
|
71
|
+
} = _ref2,
|
|
72
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
73
|
+
const Component = as !== null && as !== void 0 ? as : liveTabLabelDefaultElement;
|
|
74
|
+
const pulseAnimation = !disablePulse ? {
|
|
75
|
+
opacity: [1, 0, 1],
|
|
76
|
+
transition: pulseTransitionConfig
|
|
77
|
+
} : undefined;
|
|
78
|
+
return /*#__PURE__*/_jsxs(Text, _objectSpread(_objectSpread({
|
|
79
|
+
ref: ref,
|
|
80
|
+
alignItems: alignItems,
|
|
81
|
+
as: Component,
|
|
82
|
+
color: color,
|
|
83
|
+
display: display,
|
|
84
|
+
font: font
|
|
85
|
+
}, props), {}, {
|
|
86
|
+
children: [!hideDot && /*#__PURE__*/_jsx(motion.span, {
|
|
87
|
+
animate: !disablePulse && pulseAnimation,
|
|
88
|
+
className: dotBaseCss,
|
|
89
|
+
initial: {
|
|
90
|
+
opacity: 1
|
|
91
|
+
}
|
|
92
|
+
}), label]
|
|
93
|
+
}));
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
// Custom tab component with primary color for active state
|
|
97
|
+
const PeriodSelectorTab = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/_jsx(SegmentedTab, _objectSpread({
|
|
98
|
+
ref: ref,
|
|
99
|
+
activeColor: "fgPrimary",
|
|
100
|
+
font: "label1"
|
|
101
|
+
}, props))));
|
|
102
|
+
/**
|
|
103
|
+
* PeriodSelector is a specialized version of SegmentedTabs optimized for chart period selection.
|
|
104
|
+
* It provides transparent background, primary wash active state, and full-width layout by default.
|
|
105
|
+
*/
|
|
106
|
+
export const PeriodSelector = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref3, ref) => {
|
|
107
|
+
let {
|
|
108
|
+
background = 'transparent',
|
|
109
|
+
activeBackground = 'bgPrimaryWash',
|
|
110
|
+
width = '100%',
|
|
111
|
+
justifyContent = 'space-between',
|
|
112
|
+
TabComponent = PeriodSelectorTab,
|
|
113
|
+
TabsActiveIndicatorComponent = PeriodSelectorActiveIndicator
|
|
114
|
+
} = _ref3,
|
|
115
|
+
props = _objectWithoutProperties(_ref3, _excluded2);
|
|
116
|
+
return /*#__PURE__*/_jsx(SegmentedTabs, _objectSpread({
|
|
117
|
+
ref: ref,
|
|
118
|
+
TabComponent: TabComponent,
|
|
119
|
+
TabsActiveIndicatorComponent: TabsActiveIndicatorComponent,
|
|
120
|
+
activeBackground: activeBackground,
|
|
121
|
+
background: background,
|
|
122
|
+
justifyContent: justifyContent,
|
|
123
|
+
width: width
|
|
124
|
+
}, props));
|
|
125
|
+
}));
|
|
126
|
+
import "./PeriodSelector.css";
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
const _excluded = ["dataX", "dataY", "yAxisId", "fill", "radius", "opacity", "onClick", "onScrubberEnter", "className", "style", "classNames", "styles", "stroke", "strokeWidth", "accessibilityLabel", "label", "labelProps", "testID", "pixelCoordinates", "animate"];
|
|
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, useEffect, useMemo } from 'react';
|
|
10
|
+
import { cx } from '@coinbase/cds-web';
|
|
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";
|
|
18
|
+
|
|
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.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export const Point = /*#__PURE__*/memo(_ref => {
|
|
29
|
+
let {
|
|
30
|
+
dataX,
|
|
31
|
+
dataY,
|
|
32
|
+
yAxisId,
|
|
33
|
+
fill = 'var(--color-fgPrimary)',
|
|
34
|
+
radius = 4,
|
|
35
|
+
opacity,
|
|
36
|
+
onClick,
|
|
37
|
+
onScrubberEnter,
|
|
38
|
+
className,
|
|
39
|
+
style,
|
|
40
|
+
classNames,
|
|
41
|
+
styles,
|
|
42
|
+
stroke = 'var(--color-bg)',
|
|
43
|
+
strokeWidth = 2,
|
|
44
|
+
accessibilityLabel,
|
|
45
|
+
label,
|
|
46
|
+
labelProps,
|
|
47
|
+
testID,
|
|
48
|
+
pixelCoordinates,
|
|
49
|
+
animate
|
|
50
|
+
} = _ref,
|
|
51
|
+
svgProps = _objectWithoutProperties(_ref, _excluded);
|
|
52
|
+
const {
|
|
53
|
+
getXScale,
|
|
54
|
+
getYScale,
|
|
55
|
+
animate: animationEnabled
|
|
56
|
+
} = useCartesianChartContext();
|
|
57
|
+
const {
|
|
58
|
+
scrubberPosition
|
|
59
|
+
} = useScrubberContext();
|
|
60
|
+
const xScale = getXScale();
|
|
61
|
+
const yScale = getYScale(yAxisId);
|
|
62
|
+
const isScrubberHighlighted = scrubberPosition !== undefined && scrubberPosition === dataX;
|
|
63
|
+
const pixelCoordinate = useMemo(() => {
|
|
64
|
+
if (pixelCoordinates) {
|
|
65
|
+
return pixelCoordinates;
|
|
66
|
+
}
|
|
67
|
+
if (!xScale || !yScale) {
|
|
68
|
+
return {
|
|
69
|
+
x: 0,
|
|
70
|
+
y: 0
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return projectPoint({
|
|
74
|
+
x: dataX,
|
|
75
|
+
y: dataY,
|
|
76
|
+
xScale,
|
|
77
|
+
yScale
|
|
78
|
+
});
|
|
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]);
|
|
88
|
+
const innerPoint = useMemo(() => {
|
|
89
|
+
const mergedStyles = _objectSpread(_objectSpread({
|
|
90
|
+
cursor: onClick !== undefined ? 'pointer' : undefined
|
|
91
|
+
}, style), styles === null || styles === void 0 ? void 0 : styles.point);
|
|
92
|
+
|
|
93
|
+
// interaction animations to scale radius of point
|
|
94
|
+
const variants = {
|
|
95
|
+
hovered: {
|
|
96
|
+
r: radius * 1.2
|
|
97
|
+
},
|
|
98
|
+
pressed: {
|
|
99
|
+
r: radius * 0.9
|
|
100
|
+
},
|
|
101
|
+
default: {
|
|
102
|
+
r: radius
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const handleKeyDown = onClick ? event => {
|
|
106
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
onClick(event, {
|
|
109
|
+
dataX,
|
|
110
|
+
dataY,
|
|
111
|
+
x: pixelCoordinate.x,
|
|
112
|
+
y: pixelCoordinate.y
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
} : 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;
|
|
120
|
+
return /*#__PURE__*/_jsx(motion.circle, _objectSpread({
|
|
121
|
+
animate: shouldAnimatePosition ? {
|
|
122
|
+
cx: pixelCoordinate.x,
|
|
123
|
+
cy: pixelCoordinate.y
|
|
124
|
+
} : undefined,
|
|
125
|
+
"aria-label": accessibilityLabel,
|
|
126
|
+
className: cx(innerPointCss, className, classNames === null || classNames === void 0 ? void 0 : classNames.point),
|
|
127
|
+
cx: pixelCoordinate.x,
|
|
128
|
+
cy: pixelCoordinate.y,
|
|
129
|
+
fill: fill,
|
|
130
|
+
initial: false,
|
|
131
|
+
onClick: onClick ? event => onClick(event, {
|
|
132
|
+
dataX,
|
|
133
|
+
dataY,
|
|
134
|
+
x: pixelCoordinate.x,
|
|
135
|
+
y: pixelCoordinate.y
|
|
136
|
+
}) : undefined,
|
|
137
|
+
onKeyDown: handleKeyDown,
|
|
138
|
+
r: radius,
|
|
139
|
+
role: onClick ? 'button' : undefined,
|
|
140
|
+
stroke: stroke,
|
|
141
|
+
strokeWidth: strokeWidth,
|
|
142
|
+
style: mergedStyles,
|
|
143
|
+
tabIndex: onClick ? 0 : -1,
|
|
144
|
+
transition: {
|
|
145
|
+
duration: 0.3,
|
|
146
|
+
ease: 'easeInOut'
|
|
147
|
+
},
|
|
148
|
+
variants: variants,
|
|
149
|
+
whileHover: shouldAnimateInteractions && onClick ? 'hovered' : 'default',
|
|
150
|
+
whileTap: shouldAnimateInteractions && onClick ? 'pressed' : 'default'
|
|
151
|
+
}, 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]);
|
|
153
|
+
if (!xScale || !yScale) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
157
|
+
children: [/*#__PURE__*/_jsx("g", {
|
|
158
|
+
className: cx(containerCss, classNames === null || classNames === void 0 ? void 0 : classNames.container),
|
|
159
|
+
"data-testid": testID,
|
|
160
|
+
opacity: opacity,
|
|
161
|
+
style: styles === null || styles === void 0 ? void 0 : styles.container,
|
|
162
|
+
children: innerPoint
|
|
163
|
+
}), label && /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({
|
|
164
|
+
x: pixelCoordinate.x,
|
|
165
|
+
y: pixelCoordinate.y
|
|
166
|
+
}, labelProps), {}, {
|
|
167
|
+
children: label
|
|
168
|
+
}))]
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
import "./Point.css";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React, { memo, useMemo } from 'react';
|
|
2
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
3
|
+
import { getAreaPath } from '../utils';
|
|
4
|
+
import { DottedArea } from './DottedArea';
|
|
5
|
+
import { GradientArea } from './GradientArea';
|
|
6
|
+
import { SolidArea } from './SolidArea';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export const Area = /*#__PURE__*/memo(_ref => {
|
|
9
|
+
var _ref2;
|
|
10
|
+
let {
|
|
11
|
+
seriesId,
|
|
12
|
+
curve = 'linear',
|
|
13
|
+
type = 'solid',
|
|
14
|
+
AreaComponent: SelectedAreaComponent,
|
|
15
|
+
fill: specifiedFill,
|
|
16
|
+
fillOpacity = 1,
|
|
17
|
+
stroke,
|
|
18
|
+
strokeWidth,
|
|
19
|
+
baseline
|
|
20
|
+
} = _ref;
|
|
21
|
+
const {
|
|
22
|
+
getSeries,
|
|
23
|
+
getSeriesData,
|
|
24
|
+
getXScale,
|
|
25
|
+
getYScale,
|
|
26
|
+
getXAxis
|
|
27
|
+
} = useCartesianChartContext();
|
|
28
|
+
|
|
29
|
+
// Get sourceData from series (using stacked data if available)
|
|
30
|
+
const matchedSeries = useMemo(() => getSeries(seriesId), [seriesId, getSeries]);
|
|
31
|
+
|
|
32
|
+
// Check for stacked data first, then fall back to raw data
|
|
33
|
+
const sourceData = useMemo(() => {
|
|
34
|
+
const stackedData = getSeriesData(seriesId);
|
|
35
|
+
if (stackedData) {
|
|
36
|
+
return stackedData;
|
|
37
|
+
}
|
|
38
|
+
return getSeriesData(seriesId) || null;
|
|
39
|
+
}, [seriesId, getSeriesData]);
|
|
40
|
+
|
|
41
|
+
// Get scales and axes for this series
|
|
42
|
+
const xAxis = getXAxis();
|
|
43
|
+
const xScale = getXScale();
|
|
44
|
+
const yScale = getYScale(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId);
|
|
45
|
+
const area = useMemo(() => {
|
|
46
|
+
if (!sourceData || sourceData.length === 0 || !xScale || !yScale) return '';
|
|
47
|
+
|
|
48
|
+
// Get numeric x-axis data if available
|
|
49
|
+
const xData = xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
50
|
+
return getAreaPath({
|
|
51
|
+
data: sourceData,
|
|
52
|
+
xScale,
|
|
53
|
+
yScale,
|
|
54
|
+
curve,
|
|
55
|
+
xData
|
|
56
|
+
});
|
|
57
|
+
}, [sourceData, xScale, yScale, curve, xAxis === null || xAxis === void 0 ? void 0 : xAxis.data]);
|
|
58
|
+
const AreaComponent = useMemo(() => {
|
|
59
|
+
if (SelectedAreaComponent) {
|
|
60
|
+
return SelectedAreaComponent;
|
|
61
|
+
}
|
|
62
|
+
switch (type) {
|
|
63
|
+
case 'solid':
|
|
64
|
+
return SolidArea;
|
|
65
|
+
case 'dotted':
|
|
66
|
+
return DottedArea;
|
|
67
|
+
case 'gradient':
|
|
68
|
+
default:
|
|
69
|
+
return GradientArea;
|
|
70
|
+
}
|
|
71
|
+
}, [SelectedAreaComponent, type]);
|
|
72
|
+
if (!xScale || !yScale || !sourceData || !area) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const fill = (_ref2 = specifiedFill !== null && specifiedFill !== void 0 ? specifiedFill : matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.color) !== null && _ref2 !== void 0 ? _ref2 : 'var(--color-fgPrimary)';
|
|
76
|
+
return /*#__PURE__*/_jsx(AreaComponent, {
|
|
77
|
+
baseline: baseline,
|
|
78
|
+
d: area,
|
|
79
|
+
fill: fill,
|
|
80
|
+
fillOpacity: fillOpacity,
|
|
81
|
+
stroke: stroke,
|
|
82
|
+
strokeWidth: strokeWidth,
|
|
83
|
+
yAxisId: matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const _excluded = ["series", "stacked", "AreaComponent", "curve", "fillOpacity", "type", "LineComponent", "strokeWidth", "showXAxis", "showYAxis", "showLines", "lineType", "xAxis", "yAxis", "inset", "children"],
|
|
2
|
+
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
|
|
3
|
+
_excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
|
|
4
|
+
_excluded4 = ["id", "data", "label", "color", "yAxisId", "opacity", "LineComponent", "stackId"],
|
|
5
|
+
_excluded5 = ["id", "data", "label", "color", "yAxisId", "fill", "fillOpacity", "stackId"];
|
|
6
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
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
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
14
|
+
import { XAxis, YAxis } from '../axis';
|
|
15
|
+
import { CartesianChart } from '../CartesianChart';
|
|
16
|
+
import { Line } from '../line/Line';
|
|
17
|
+
import { defaultChartInset, defaultStackId, getChartInset } from '../utils';
|
|
18
|
+
import { Area } from './Area';
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
21
|
+
let {
|
|
22
|
+
series,
|
|
23
|
+
stacked,
|
|
24
|
+
AreaComponent,
|
|
25
|
+
curve,
|
|
26
|
+
fillOpacity,
|
|
27
|
+
type,
|
|
28
|
+
LineComponent,
|
|
29
|
+
strokeWidth,
|
|
30
|
+
showXAxis,
|
|
31
|
+
showYAxis,
|
|
32
|
+
showLines,
|
|
33
|
+
lineType = 'solid',
|
|
34
|
+
xAxis,
|
|
35
|
+
yAxis,
|
|
36
|
+
inset: userInset,
|
|
37
|
+
children
|
|
38
|
+
} = _ref,
|
|
39
|
+
chartProps = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
+
const calculatedInset = useMemo(() => getChartInset(userInset, defaultChartInset), [userInset]);
|
|
41
|
+
|
|
42
|
+
// Convert AreaSeries to Series for Chart context
|
|
43
|
+
const chartSeries = useMemo(() => {
|
|
44
|
+
return series === null || series === void 0 ? void 0 : series.map(s => ({
|
|
45
|
+
id: s.id,
|
|
46
|
+
data: s.data,
|
|
47
|
+
label: s.label,
|
|
48
|
+
color: s.color,
|
|
49
|
+
yAxisId: s.yAxisId,
|
|
50
|
+
stackId: s.stackId
|
|
51
|
+
}));
|
|
52
|
+
}, [series]);
|
|
53
|
+
const transformedSeries = useMemo(() => {
|
|
54
|
+
if (!stacked || !chartSeries) return chartSeries;
|
|
55
|
+
return chartSeries.map(s => {
|
|
56
|
+
var _s$stackId;
|
|
57
|
+
return _objectSpread(_objectSpread({}, s), {}, {
|
|
58
|
+
stackId: (_s$stackId = s.stackId) !== null && _s$stackId !== void 0 ? _s$stackId : defaultStackId
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}, [chartSeries, stacked]);
|
|
62
|
+
const seriesToRender = transformedSeries !== null && transformedSeries !== void 0 ? transformedSeries : chartSeries;
|
|
63
|
+
|
|
64
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
65
|
+
const _ref2 = xAxis || {},
|
|
66
|
+
{
|
|
67
|
+
scaleType: xScaleType,
|
|
68
|
+
data: xData,
|
|
69
|
+
categoryPadding: xCategoryPadding,
|
|
70
|
+
domain: xDomain,
|
|
71
|
+
domainLimit: xDomainLimit,
|
|
72
|
+
range: xRange
|
|
73
|
+
} = _ref2,
|
|
74
|
+
xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
75
|
+
const _ref3 = yAxis || {},
|
|
76
|
+
{
|
|
77
|
+
scaleType: yScaleType,
|
|
78
|
+
data: yData,
|
|
79
|
+
categoryPadding: yCategoryPadding,
|
|
80
|
+
domain: yDomain,
|
|
81
|
+
domainLimit: yDomainLimit,
|
|
82
|
+
range: yRange,
|
|
83
|
+
id: yAxisId
|
|
84
|
+
} = _ref3,
|
|
85
|
+
yAxisVisualProps = _objectWithoutProperties(_ref3, _excluded3);
|
|
86
|
+
const xAxisConfig = {
|
|
87
|
+
scaleType: xScaleType,
|
|
88
|
+
data: xData,
|
|
89
|
+
categoryPadding: xCategoryPadding,
|
|
90
|
+
domain: xDomain,
|
|
91
|
+
domainLimit: xDomainLimit,
|
|
92
|
+
range: xRange
|
|
93
|
+
};
|
|
94
|
+
const hasNegativeValues = useMemo(() => {
|
|
95
|
+
if (!series) return false;
|
|
96
|
+
return series.some(s => {
|
|
97
|
+
var _s$data;
|
|
98
|
+
return (_s$data = s.data) === null || _s$data === void 0 ? void 0 : _s$data.some(value => typeof value === 'number' && value < 0 || Array.isArray(value) && value.some(v => typeof v === 'number' && v < 0));
|
|
99
|
+
});
|
|
100
|
+
}, [series]);
|
|
101
|
+
|
|
102
|
+
// Set default min domain to 0 for area chart, but only if there are no negative values
|
|
103
|
+
const yAxisConfig = {
|
|
104
|
+
scaleType: yScaleType,
|
|
105
|
+
data: yData,
|
|
106
|
+
categoryPadding: yCategoryPadding,
|
|
107
|
+
domain: hasNegativeValues ? yDomain : _objectSpread({
|
|
108
|
+
min: 0
|
|
109
|
+
}, yDomain),
|
|
110
|
+
domainLimit: yDomainLimit,
|
|
111
|
+
range: yRange
|
|
112
|
+
};
|
|
113
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
|
|
114
|
+
ref: ref,
|
|
115
|
+
inset: calculatedInset,
|
|
116
|
+
series: seriesToRender,
|
|
117
|
+
xAxis: xAxisConfig,
|
|
118
|
+
yAxis: yAxisConfig,
|
|
119
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
|
|
120
|
+
axisId: yAxisId
|
|
121
|
+
}, yAxisVisualProps)), series === null || series === void 0 ? void 0 : series.map(_ref4 => {
|
|
122
|
+
let {
|
|
123
|
+
id,
|
|
124
|
+
data,
|
|
125
|
+
label,
|
|
126
|
+
color,
|
|
127
|
+
yAxisId,
|
|
128
|
+
opacity,
|
|
129
|
+
LineComponent,
|
|
130
|
+
stackId
|
|
131
|
+
} = _ref4,
|
|
132
|
+
areaPropsFromSeries = _objectWithoutProperties(_ref4, _excluded4);
|
|
133
|
+
return /*#__PURE__*/_jsx(Area, _objectSpread({
|
|
134
|
+
AreaComponent: AreaComponent,
|
|
135
|
+
curve: curve,
|
|
136
|
+
fillOpacity: fillOpacity,
|
|
137
|
+
seriesId: id,
|
|
138
|
+
type: type
|
|
139
|
+
}, areaPropsFromSeries), id);
|
|
140
|
+
}), showLines && (series === null || series === void 0 ? void 0 : series.map(_ref5 => {
|
|
141
|
+
let {
|
|
142
|
+
id,
|
|
143
|
+
data,
|
|
144
|
+
label,
|
|
145
|
+
color,
|
|
146
|
+
yAxisId,
|
|
147
|
+
fill,
|
|
148
|
+
fillOpacity,
|
|
149
|
+
stackId
|
|
150
|
+
} = _ref5,
|
|
151
|
+
linePropsFromSeries = _objectWithoutProperties(_ref5, _excluded5);
|
|
152
|
+
return /*#__PURE__*/_jsx(Line, _objectSpread({
|
|
153
|
+
LineComponent: LineComponent,
|
|
154
|
+
curve: curve,
|
|
155
|
+
seriesId: id // Line component now handles stacked data automatically
|
|
156
|
+
,
|
|
157
|
+
stroke: color // Default to series color
|
|
158
|
+
,
|
|
159
|
+
strokeWidth: strokeWidth,
|
|
160
|
+
type: lineType
|
|
161
|
+
}, linePropsFromSeries), "".concat(id, "-line"));
|
|
162
|
+
})), children]
|
|
163
|
+
}));
|
|
164
|
+
}));
|