@coinbase/cds-web-visualization 0.0.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/README.md +3 -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 +3 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +8 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +67 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +15 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +14 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +23 -0
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -0
- package/dts/sparkline/SparklinePath.d.ts +12 -0
- package/dts/sparkline/SparklinePath.d.ts.map +1 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +2 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +11 -0
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -0
- package/dts/sparkline/index.d.ts +6 -0
- package/dts/sparkline/index.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +199 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +8 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +30 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +18 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +31 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +112 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +1 -0
- 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 -0
- package/esm/sparkline/Counter.css +3 -0
- package/esm/sparkline/Counter.js +35 -0
- package/esm/sparkline/Sparkline.js +164 -0
- package/esm/sparkline/SparklineArea.js +18 -0
- package/esm/sparkline/SparklineAreaPattern.js +37 -0
- package/esm/sparkline/SparklineGradient.js +30 -0
- package/esm/sparkline/SparklinePath.js +19 -0
- package/esm/sparkline/__figma__/Sparkline.figma.js +24 -0
- package/esm/sparkline/generateSparklineWithId.js +7 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.js +21 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +317 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +108 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +26 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.js +24 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.css +4 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +65 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.css +1 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +80 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +56 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +70 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +45 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.css +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.js +199 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.js +39 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +92 -0
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +89 -0
- package/esm/sparkline/sparkline-interactive/fade.css +2 -0
- package/esm/sparkline/sparkline-interactive/fade.js +14 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +28 -0
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +225 -0
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +108 -0
- package/package.json +68 -6
- package/index.js +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { memo, useId, useMemo } from 'react';
|
|
2
|
+
import { m as motion } from 'framer-motion';
|
|
3
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
4
|
+
import { getBarPath } from '../utils';
|
|
5
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* Default stack component that renders children in a group with animated clip path.
|
|
8
|
+
*/
|
|
9
|
+
export const DefaultBarStack = /*#__PURE__*/memo(_ref => {
|
|
10
|
+
let {
|
|
11
|
+
children,
|
|
12
|
+
className,
|
|
13
|
+
style,
|
|
14
|
+
width,
|
|
15
|
+
height,
|
|
16
|
+
x,
|
|
17
|
+
y,
|
|
18
|
+
borderRadius = 4,
|
|
19
|
+
roundTop = true,
|
|
20
|
+
roundBottom = true,
|
|
21
|
+
yOrigin
|
|
22
|
+
} = _ref;
|
|
23
|
+
const {
|
|
24
|
+
animate
|
|
25
|
+
} = useCartesianChartContext();
|
|
26
|
+
const clipPathId = useId();
|
|
27
|
+
const clipPathData = useMemo(() => {
|
|
28
|
+
return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom);
|
|
29
|
+
}, [x, y, width, height, borderRadius, roundTop, roundBottom]);
|
|
30
|
+
const initialClipPathData = useMemo(() => {
|
|
31
|
+
return getBarPath(x, yOrigin !== null && yOrigin !== void 0 ? yOrigin : y + height, width, 1, borderRadius, roundTop, roundBottom);
|
|
32
|
+
}, [x, yOrigin, y, height, width, borderRadius, roundTop, roundBottom]);
|
|
33
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
34
|
+
children: [/*#__PURE__*/_jsx("defs", {
|
|
35
|
+
children: /*#__PURE__*/_jsx("clipPath", {
|
|
36
|
+
id: clipPathId,
|
|
37
|
+
children: animate ? /*#__PURE__*/_jsx(motion.path, {
|
|
38
|
+
animate: {
|
|
39
|
+
d: clipPathData
|
|
40
|
+
},
|
|
41
|
+
initial: {
|
|
42
|
+
d: initialClipPathData
|
|
43
|
+
},
|
|
44
|
+
transition: {
|
|
45
|
+
type: 'spring',
|
|
46
|
+
duration: 1,
|
|
47
|
+
bounce: 0
|
|
48
|
+
}
|
|
49
|
+
}) : /*#__PURE__*/_jsx("path", {
|
|
50
|
+
d: clipPathData
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
54
|
+
className: className,
|
|
55
|
+
clipPath: "url(#".concat(clipPathId, ")"),
|
|
56
|
+
style: style,
|
|
57
|
+
children: children
|
|
58
|
+
})]
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// codegen:start {preset: barrel, include: ./*.tsx, exclude: ./__stories__/*.tsx}
|
|
2
|
+
export * from './Bar';
|
|
3
|
+
export * from './BarChart';
|
|
4
|
+
export * from './BarPlot';
|
|
5
|
+
export * from './BarStack';
|
|
6
|
+
export * from './BarStackGroup';
|
|
7
|
+
export * from './DefaultBar';
|
|
8
|
+
export * from './DefaultBarStack';
|
|
9
|
+
// codegen:end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// codegen:start {preset: barrel, include: [./*.tsx, ./*/index.ts]}
|
|
2
|
+
export * from './area/index';
|
|
3
|
+
export * from './axis/index';
|
|
4
|
+
export * from './bar/index';
|
|
5
|
+
export * from './CartesianChart';
|
|
6
|
+
export * from './ChartProvider';
|
|
7
|
+
export * from './line/index';
|
|
8
|
+
export * from './Path';
|
|
9
|
+
export * from './PeriodSelector';
|
|
10
|
+
export * from './Point';
|
|
11
|
+
export * from './scrubber/index';
|
|
12
|
+
export * from './text/index';
|
|
13
|
+
export * from './utils/index';
|
|
14
|
+
// codegen:end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "strokeDasharray", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "vectorEffect"];
|
|
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 { Path } from '../Path';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
/**
|
|
13
|
+
* A customizable dotted line component which uses path element.
|
|
14
|
+
*/
|
|
15
|
+
export const DottedLine = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
let {
|
|
17
|
+
fill = 'none',
|
|
18
|
+
stroke = 'var(--color-bgLine)',
|
|
19
|
+
strokeDasharray = '0 4',
|
|
20
|
+
strokeLinecap = 'round',
|
|
21
|
+
strokeLinejoin = 'round',
|
|
22
|
+
strokeOpacity = 1,
|
|
23
|
+
strokeWidth = 2,
|
|
24
|
+
vectorEffect = 'non-scaling-stroke'
|
|
25
|
+
} = _ref,
|
|
26
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
+
return /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
28
|
+
clipOffset: strokeWidth,
|
|
29
|
+
fill: fill,
|
|
30
|
+
stroke: stroke,
|
|
31
|
+
strokeDasharray: strokeDasharray,
|
|
32
|
+
strokeLinecap: strokeLinecap,
|
|
33
|
+
strokeLinejoin: strokeLinejoin,
|
|
34
|
+
strokeOpacity: strokeOpacity,
|
|
35
|
+
strokeWidth: strokeWidth,
|
|
36
|
+
vectorEffect: vectorEffect
|
|
37
|
+
}, props));
|
|
38
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "startColor", "endColor", "strokeOpacity", "startOpacity", "endOpacity", "strokeLinecap", "strokeLinejoin", "strokeWidth"];
|
|
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, useId } from 'react';
|
|
10
|
+
import { Path } from '../Path';
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
|
+
/**
|
|
13
|
+
* A gradient line component which uses path element.
|
|
14
|
+
*/
|
|
15
|
+
export const GradientLine = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
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
|
|
27
|
+
} = _ref,
|
|
28
|
+
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
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const _excluded = ["seriesId", "curve", "type", "areaType", "areaBaseline", "stroke", "onPointClick", "showArea", "LineComponent", "AreaComponent", "opacity", "renderPoints"];
|
|
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, useMemo } from 'react';
|
|
10
|
+
import { m as motion } from 'framer-motion';
|
|
11
|
+
import { Area } from '../area/Area';
|
|
12
|
+
import { axisTickLabelsInitialAnimationVariants } from '../axis';
|
|
13
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
14
|
+
import { Point } from '../Point';
|
|
15
|
+
import { getLinePath } from '../utils';
|
|
16
|
+
import { DottedLine } from './DottedLine';
|
|
17
|
+
import { GradientLine } from './GradientLine';
|
|
18
|
+
import { SolidLine } from './SolidLine';
|
|
19
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
export const Line = /*#__PURE__*/memo(_ref => {
|
|
21
|
+
var _ref2;
|
|
22
|
+
let {
|
|
23
|
+
seriesId,
|
|
24
|
+
curve = 'linear',
|
|
25
|
+
type = 'solid',
|
|
26
|
+
areaType = 'gradient',
|
|
27
|
+
areaBaseline,
|
|
28
|
+
stroke: specifiedStroke,
|
|
29
|
+
onPointClick,
|
|
30
|
+
showArea = false,
|
|
31
|
+
LineComponent: SelectedLineComponent,
|
|
32
|
+
AreaComponent,
|
|
33
|
+
opacity = 1,
|
|
34
|
+
renderPoints
|
|
35
|
+
} = _ref,
|
|
36
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
37
|
+
const {
|
|
38
|
+
animate,
|
|
39
|
+
getSeries,
|
|
40
|
+
getSeriesData,
|
|
41
|
+
getXScale,
|
|
42
|
+
getYScale,
|
|
43
|
+
getXAxis
|
|
44
|
+
} = useCartesianChartContext();
|
|
45
|
+
const matchedSeries = getSeries(seriesId);
|
|
46
|
+
const sourceData = useMemo(() => {
|
|
47
|
+
const stackedData = getSeriesData(seriesId);
|
|
48
|
+
if (stackedData) {
|
|
49
|
+
return stackedData;
|
|
50
|
+
}
|
|
51
|
+
return getSeriesData(seriesId) || null;
|
|
52
|
+
}, [seriesId, getSeriesData]);
|
|
53
|
+
const xAxis = getXAxis();
|
|
54
|
+
const xScale = getXScale();
|
|
55
|
+
const yScale = getYScale(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId);
|
|
56
|
+
|
|
57
|
+
// Convert sourceData to number array (line only supports numbers, not tuples)
|
|
58
|
+
// If data is stacked (tuples), extract the actual values from [baseline, actualValue] format
|
|
59
|
+
const chartData = useMemo(() => {
|
|
60
|
+
if (!sourceData) return [];
|
|
61
|
+
|
|
62
|
+
// Check if this is stacked data (array of tuples)
|
|
63
|
+
const firstNonNull = sourceData.find(d => d !== null);
|
|
64
|
+
if (Array.isArray(firstNonNull)) {
|
|
65
|
+
// Extract actual values from [baseline, value] tuples
|
|
66
|
+
return sourceData.map(d => {
|
|
67
|
+
if (d === null) return null;
|
|
68
|
+
if (Array.isArray(d)) return d[1];
|
|
69
|
+
return d;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Regular number array
|
|
74
|
+
if (sourceData.every(d => typeof d === 'number' || d === null)) {
|
|
75
|
+
return sourceData;
|
|
76
|
+
}
|
|
77
|
+
return [];
|
|
78
|
+
}, [sourceData]);
|
|
79
|
+
const path = useMemo(() => {
|
|
80
|
+
if (!xScale || !yScale || chartData.length === 0) return '';
|
|
81
|
+
|
|
82
|
+
// Get numeric x-axis data if available
|
|
83
|
+
const xData = xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
84
|
+
return getLinePath({
|
|
85
|
+
data: chartData,
|
|
86
|
+
xScale,
|
|
87
|
+
yScale,
|
|
88
|
+
curve,
|
|
89
|
+
xData
|
|
90
|
+
});
|
|
91
|
+
}, [chartData, xScale, yScale, curve, xAxis === null || xAxis === void 0 ? void 0 : xAxis.data]);
|
|
92
|
+
const LineComponent = useMemo(() => {
|
|
93
|
+
if (SelectedLineComponent) {
|
|
94
|
+
return SelectedLineComponent;
|
|
95
|
+
}
|
|
96
|
+
switch (type) {
|
|
97
|
+
case 'dotted':
|
|
98
|
+
return DottedLine;
|
|
99
|
+
case 'gradient':
|
|
100
|
+
return GradientLine;
|
|
101
|
+
case 'solid':
|
|
102
|
+
default:
|
|
103
|
+
return SolidLine;
|
|
104
|
+
}
|
|
105
|
+
}, [SelectedLineComponent, type]);
|
|
106
|
+
|
|
107
|
+
// Get series color for stroke
|
|
108
|
+
const stroke = (_ref2 = specifiedStroke !== null && specifiedStroke !== void 0 ? specifiedStroke : matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.color) !== null && _ref2 !== void 0 ? _ref2 : 'var(--color-fgPrimary)';
|
|
109
|
+
const xData = useMemo(() => {
|
|
110
|
+
const data = xAxis === null || xAxis === void 0 ? void 0 : xAxis.data;
|
|
111
|
+
return data && Array.isArray(data) && data.length > 0 && typeof data[0] === 'number' ? data : null;
|
|
112
|
+
}, [xAxis === null || xAxis === void 0 ? void 0 : xAxis.data]);
|
|
113
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
114
|
+
children: [showArea && /*#__PURE__*/_jsx(Area, {
|
|
115
|
+
AreaComponent: AreaComponent,
|
|
116
|
+
baseline: areaBaseline,
|
|
117
|
+
curve: curve,
|
|
118
|
+
fill: stroke,
|
|
119
|
+
fillOpacity: opacity,
|
|
120
|
+
seriesId: seriesId,
|
|
121
|
+
type: areaType
|
|
122
|
+
}), /*#__PURE__*/_jsx(LineComponent, _objectSpread({
|
|
123
|
+
d: path,
|
|
124
|
+
stroke: stroke,
|
|
125
|
+
strokeOpacity: opacity
|
|
126
|
+
}, props)), renderPoints && /*#__PURE__*/_jsx(motion.g, _objectSpread(_objectSpread({
|
|
127
|
+
"data-component": "line-points-group"
|
|
128
|
+
}, animate ? {
|
|
129
|
+
animate: 'animate',
|
|
130
|
+
exit: 'exit',
|
|
131
|
+
initial: 'initial',
|
|
132
|
+
variants: axisTickLabelsInitialAnimationVariants
|
|
133
|
+
} : {}), {}, {
|
|
134
|
+
children: chartData.map((value, index) => {
|
|
135
|
+
var _xScale, _yScale, _pointConfig$fill, _pointConfig$onClick, _pointConfig$opacity;
|
|
136
|
+
if (value === null) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const xValue = xData && xData[index] !== undefined ? xData[index] : index;
|
|
140
|
+
const point = renderPoints({
|
|
141
|
+
dataY: value,
|
|
142
|
+
dataX: xValue,
|
|
143
|
+
x: (_xScale = xScale === null || xScale === void 0 ? void 0 : xScale(xValue)) !== null && _xScale !== void 0 ? _xScale : 0,
|
|
144
|
+
y: (_yScale = yScale === null || yScale === void 0 ? void 0 : yScale(value)) !== null && _yScale !== void 0 ? _yScale : 0
|
|
145
|
+
});
|
|
146
|
+
if (!point) return;
|
|
147
|
+
const pointConfig = typeof point === 'object' ? point : {};
|
|
148
|
+
return /*#__PURE__*/_jsx(Point, _objectSpread(_objectSpread({
|
|
149
|
+
dataX: xValue,
|
|
150
|
+
dataY: value
|
|
151
|
+
}, pointConfig), {}, {
|
|
152
|
+
fill: (_pointConfig$fill = pointConfig.fill) !== null && _pointConfig$fill !== void 0 ? _pointConfig$fill : stroke,
|
|
153
|
+
onClick: (_pointConfig$onClick = pointConfig.onClick) !== null && _pointConfig$onClick !== void 0 ? _pointConfig$onClick : onPointClick,
|
|
154
|
+
opacity: (_pointConfig$opacity = pointConfig.opacity) !== null && _pointConfig$opacity !== void 0 ? _pointConfig$opacity : opacity
|
|
155
|
+
}), "".concat(seriesId, "-renderpoint-").concat(index));
|
|
156
|
+
})
|
|
157
|
+
}))]
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const _excluded = ["series", "showArea", "areaType", "type", "onPointClick", "LineComponent", "AreaComponent", "curve", "renderPoints", "strokeWidth", "showXAxis", "showYAxis", "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"];
|
|
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
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
13
|
+
import { XAxis } from '../axis/XAxis';
|
|
14
|
+
import { YAxis } from '../axis/YAxis';
|
|
15
|
+
import { CartesianChart } from '../CartesianChart';
|
|
16
|
+
import { defaultChartInset, getChartInset } from '../utils';
|
|
17
|
+
import { Line } from './Line';
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
20
|
+
let {
|
|
21
|
+
series,
|
|
22
|
+
showArea,
|
|
23
|
+
areaType,
|
|
24
|
+
type,
|
|
25
|
+
onPointClick,
|
|
26
|
+
LineComponent,
|
|
27
|
+
AreaComponent,
|
|
28
|
+
curve,
|
|
29
|
+
renderPoints,
|
|
30
|
+
strokeWidth,
|
|
31
|
+
showXAxis,
|
|
32
|
+
showYAxis,
|
|
33
|
+
xAxis,
|
|
34
|
+
yAxis,
|
|
35
|
+
inset: userInset,
|
|
36
|
+
children
|
|
37
|
+
} = _ref,
|
|
38
|
+
chartProps = _objectWithoutProperties(_ref, _excluded);
|
|
39
|
+
const calculatedInset = useMemo(() => getChartInset(userInset, defaultChartInset), [userInset]);
|
|
40
|
+
|
|
41
|
+
// Convert LineSeries to Series for Chart context
|
|
42
|
+
const chartSeries = useMemo(() => {
|
|
43
|
+
return series === null || series === void 0 ? void 0 : series.map(s => ({
|
|
44
|
+
id: s.id,
|
|
45
|
+
data: s.data,
|
|
46
|
+
label: s.label,
|
|
47
|
+
color: s.color
|
|
48
|
+
}));
|
|
49
|
+
}, [series]);
|
|
50
|
+
|
|
51
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
52
|
+
const _ref2 = xAxis || {},
|
|
53
|
+
{
|
|
54
|
+
scaleType: xScaleType,
|
|
55
|
+
data: xData,
|
|
56
|
+
categoryPadding: xCategoryPadding,
|
|
57
|
+
domain: xDomain,
|
|
58
|
+
domainLimit: xDomainLimit,
|
|
59
|
+
range: xRange
|
|
60
|
+
} = _ref2,
|
|
61
|
+
xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
62
|
+
const _ref3 = yAxis || {},
|
|
63
|
+
{
|
|
64
|
+
scaleType: yScaleType,
|
|
65
|
+
data: yData,
|
|
66
|
+
categoryPadding: yCategoryPadding,
|
|
67
|
+
domain: yDomain,
|
|
68
|
+
domainLimit: yDomainLimit,
|
|
69
|
+
range: yRange,
|
|
70
|
+
id: yAxisId
|
|
71
|
+
} = _ref3,
|
|
72
|
+
yAxisVisualProps = _objectWithoutProperties(_ref3, _excluded3);
|
|
73
|
+
const xAxisConfig = {
|
|
74
|
+
scaleType: xScaleType,
|
|
75
|
+
data: xData,
|
|
76
|
+
categoryPadding: xCategoryPadding,
|
|
77
|
+
domain: xDomain,
|
|
78
|
+
domainLimit: xDomainLimit,
|
|
79
|
+
range: xRange
|
|
80
|
+
};
|
|
81
|
+
const yAxisConfig = {
|
|
82
|
+
scaleType: yScaleType,
|
|
83
|
+
data: yData,
|
|
84
|
+
categoryPadding: yCategoryPadding,
|
|
85
|
+
domain: yDomain,
|
|
86
|
+
domainLimit: yDomainLimit,
|
|
87
|
+
range: yRange
|
|
88
|
+
};
|
|
89
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
|
|
90
|
+
ref: ref,
|
|
91
|
+
inset: calculatedInset,
|
|
92
|
+
series: chartSeries,
|
|
93
|
+
xAxis: xAxisConfig,
|
|
94
|
+
yAxis: yAxisConfig,
|
|
95
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
|
|
96
|
+
axisId: yAxisId
|
|
97
|
+
}, yAxisVisualProps)), series === null || series === void 0 ? void 0 : series.map(_ref4 => {
|
|
98
|
+
let {
|
|
99
|
+
id,
|
|
100
|
+
data,
|
|
101
|
+
label,
|
|
102
|
+
color,
|
|
103
|
+
yAxisId
|
|
104
|
+
} = _ref4,
|
|
105
|
+
linePropsFromSeries = _objectWithoutProperties(_ref4, _excluded4);
|
|
106
|
+
return /*#__PURE__*/_jsx(Line, _objectSpread({
|
|
107
|
+
AreaComponent: AreaComponent,
|
|
108
|
+
LineComponent: LineComponent,
|
|
109
|
+
areaType: areaType,
|
|
110
|
+
curve: curve,
|
|
111
|
+
onPointClick: onPointClick,
|
|
112
|
+
renderPoints: renderPoints,
|
|
113
|
+
seriesId: id,
|
|
114
|
+
showArea: showArea,
|
|
115
|
+
strokeWidth: strokeWidth,
|
|
116
|
+
type: type
|
|
117
|
+
}, linePropsFromSeries), id);
|
|
118
|
+
}), children]
|
|
119
|
+
}));
|
|
120
|
+
}));
|
|
@@ -0,0 +1,142 @@
|
|
|
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 React, { memo, useMemo } from 'react';
|
|
7
|
+
import { cx } from '@coinbase/cds-web';
|
|
8
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
9
|
+
import { ChartText } from '../text';
|
|
10
|
+
import { getPointOnScale } from '../utils';
|
|
11
|
+
import { DottedLine } from './DottedLine';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for ReferenceLine label rendering using ChartText.
|
|
15
|
+
*/
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export const ReferenceLine = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
dataX,
|
|
20
|
+
dataY,
|
|
21
|
+
yAxisId,
|
|
22
|
+
label,
|
|
23
|
+
labelPosition = dataY !== undefined ? 'right' : 'top',
|
|
24
|
+
testID,
|
|
25
|
+
LineComponent = DottedLine,
|
|
26
|
+
stroke = 'var(--color-bgLine)',
|
|
27
|
+
labelProps,
|
|
28
|
+
className,
|
|
29
|
+
style,
|
|
30
|
+
classNames,
|
|
31
|
+
styles
|
|
32
|
+
} = _ref;
|
|
33
|
+
const {
|
|
34
|
+
getXScale,
|
|
35
|
+
getYScale,
|
|
36
|
+
drawingArea
|
|
37
|
+
} = useCartesianChartContext();
|
|
38
|
+
|
|
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
|
+
// Combine root classNames
|
|
70
|
+
const rootClassName = cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root);
|
|
71
|
+
// Combine root styles
|
|
72
|
+
const rootStyle = _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root);
|
|
73
|
+
|
|
74
|
+
// Horizontal reference line logic
|
|
75
|
+
if (dataY !== undefined) {
|
|
76
|
+
const yScale = getYScale(yAxisId);
|
|
77
|
+
|
|
78
|
+
// Don't render if we don't have a scale
|
|
79
|
+
if (!yScale) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const yPixel = yScale(dataY);
|
|
83
|
+
if (yPixel === undefined) return null;
|
|
84
|
+
let labelX;
|
|
85
|
+
if (labelPosition === 'left') {
|
|
86
|
+
labelX = drawingArea.x;
|
|
87
|
+
} else if (labelPosition === 'center') {
|
|
88
|
+
labelX = drawingArea.x + drawingArea.width / 2;
|
|
89
|
+
} else {
|
|
90
|
+
labelX = drawingArea.x + drawingArea.width;
|
|
91
|
+
}
|
|
92
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
93
|
+
className: rootClassName,
|
|
94
|
+
"data-testid": testID,
|
|
95
|
+
style: rootStyle,
|
|
96
|
+
children: [/*#__PURE__*/_jsx(LineComponent, {
|
|
97
|
+
animate: false,
|
|
98
|
+
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), {}, {
|
|
101
|
+
x: labelX,
|
|
102
|
+
y: yPixel,
|
|
103
|
+
children: label
|
|
104
|
+
}))]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Vertical reference line logic
|
|
109
|
+
if (dataX !== undefined) {
|
|
110
|
+
const xScale = getXScale();
|
|
111
|
+
|
|
112
|
+
// Don't render if we don't have scales
|
|
113
|
+
if (!xScale) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const xPixel = getPointOnScale(dataX, xScale);
|
|
117
|
+
if (xPixel === undefined) return null;
|
|
118
|
+
let labelY;
|
|
119
|
+
if (labelPosition === 'top') {
|
|
120
|
+
labelY = drawingArea.y;
|
|
121
|
+
} else if (labelPosition === 'middle') {
|
|
122
|
+
labelY = drawingArea.y + drawingArea.height / 2;
|
|
123
|
+
} else {
|
|
124
|
+
labelY = drawingArea.y + drawingArea.height;
|
|
125
|
+
}
|
|
126
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
127
|
+
className: rootClassName,
|
|
128
|
+
"data-testid": testID,
|
|
129
|
+
style: rootStyle,
|
|
130
|
+
children: [/*#__PURE__*/_jsx(LineComponent, {
|
|
131
|
+
animate: false,
|
|
132
|
+
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), {}, {
|
|
135
|
+
x: xPixel,
|
|
136
|
+
y: labelY,
|
|
137
|
+
children: label
|
|
138
|
+
}))]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth"];
|
|
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 { Path } from '../Path';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
/**
|
|
13
|
+
* A customizable solid line component which uses path element.
|
|
14
|
+
*/
|
|
15
|
+
export const SolidLine = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
let {
|
|
17
|
+
fill = 'none',
|
|
18
|
+
stroke = 'var(--color-bgLine)',
|
|
19
|
+
strokeLinecap = 'round',
|
|
20
|
+
strokeLinejoin = 'round',
|
|
21
|
+
strokeOpacity = 1,
|
|
22
|
+
strokeWidth = 2
|
|
23
|
+
} = _ref,
|
|
24
|
+
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));
|
|
34
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// codegen:start {preset: barrel, include: ./*.tsx, exclude: ./__stories__/*.tsx}
|
|
2
|
+
export * from './DottedLine';
|
|
3
|
+
export * from './GradientLine';
|
|
4
|
+
export * from './Line';
|
|
5
|
+
export * from './LineChart';
|
|
6
|
+
export * from './ReferenceLine';
|
|
7
|
+
export * from './SolidLine';
|
|
8
|
+
// codegen:end
|