@coinbase/cds-mobile-visualization 3.3.0 → 3.4.0-beta.2
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 +30 -0
- package/dts/chart/CartesianChart.d.ts +101 -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 +48 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +85 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/Point.d.ts +103 -0
- package/dts/chart/Point.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +62 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +90 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +27 -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 +204 -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 +89 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +97 -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 +7 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +7 -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 +12 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/GradientLine.d.ts +45 -0
- package/dts/chart/line/GradientLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +78 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +84 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +91 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +12 -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 +104 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +75 -0
- package/dts/chart/scrubber/ScrubberBeacon.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 +90 -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 +67 -16
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +10 -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/__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/SparklineAccessibleView.d.ts +8 -3
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +132 -110
- 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 +18 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +9 -4
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +7 -5
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +22 -10
- 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 +29 -23
- 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/useInterruptiblePathAnimation.d.ts +9 -5
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +5 -2
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +17 -17
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +16 -13
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +106 -98
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +22 -19
- package/esm/chart/CartesianChart.js +241 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +133 -0
- package/esm/chart/PeriodSelector.js +136 -0
- package/esm/chart/Point.js +111 -0
- package/esm/chart/__stories__/CartesianChart.stories.js +476 -0
- package/esm/chart/__stories__/Chart.stories.js +79 -0
- package/esm/chart/__stories__/PeriodSelector.stories.js +294 -0
- package/esm/chart/area/Area.js +85 -0
- package/esm/chart/area/AreaChart.js +146 -0
- package/esm/chart/area/DottedArea.js +128 -0
- package/esm/chart/area/GradientArea.js +110 -0
- package/esm/chart/area/SolidArea.js +24 -0
- package/esm/chart/area/__stories__/AreaChart.stories.js +100 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +43 -0
- package/esm/chart/axis/XAxis.js +181 -0
- package/esm/chart/axis/YAxis.js +170 -0
- package/esm/chart/axis/__stories__/Axis.stories.js +277 -0
- package/esm/chart/axis/index.js +5 -0
- package/esm/chart/bar/Bar.js +67 -0
- package/esm/chart/bar/BarChart.js +147 -0
- package/esm/chart/bar/BarPlot.js +96 -0
- package/esm/chart/bar/BarStack.js +514 -0
- package/esm/chart/bar/BarStackGroup.js +89 -0
- package/esm/chart/bar/DefaultBar.js +78 -0
- package/esm/chart/bar/DefaultBarStack.js +82 -0
- package/esm/chart/bar/__stories__/BarChart.stories.js +282 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/index.js +14 -0
- package/esm/chart/line/DottedLine.js +35 -0
- package/esm/chart/line/GradientLine.js +62 -0
- package/esm/chart/line/Line.js +139 -0
- package/esm/chart/line/LineChart.js +115 -0
- package/esm/chart/line/ReferenceLine.js +115 -0
- package/esm/chart/line/SolidLine.js +31 -0
- package/esm/chart/line/__stories__/LineChart.stories.js +2248 -0
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +77 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/scrubber/Scrubber.js +186 -0
- package/esm/chart/scrubber/ScrubberBeacon.js +199 -0
- package/esm/chart/scrubber/ScrubberProvider.js +143 -0
- package/esm/chart/scrubber/index.js +2 -0
- package/esm/chart/text/ChartText.js +237 -0
- package/esm/chart/text/SmartChartTextGroup.js +210 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +592 -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 +206 -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 -16
- package/esm/sparkline/SparklineArea.js +7 -2
- package/esm/sparkline/SparklineAreaPattern.js +4 -2
- package/esm/sparkline/SparklineGradient.js +4 -0
- 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/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +27 -0
- package/package.json +11 -11
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts +0 -3
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts.map +0 -1
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts +0 -3
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -3
- 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__/SparklineInteractiveHoverDate.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.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/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -4
- 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
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { memo, useCallback, useEffect, useId, useMemo, useRef } from 'react';
|
|
2
|
+
import { runOnJS, useAnimatedReaction, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
3
|
+
import { ClipPath, Defs, G, Path } from 'react-native-svg';
|
|
4
|
+
import { usePreviousValue } from '@coinbase/cds-common/hooks/usePreviousValue';
|
|
5
|
+
import * as interpolate from 'd3-interpolate-path';
|
|
6
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
7
|
+
import { getBarPath } from '../utils';
|
|
8
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
/**
|
|
10
|
+
* Default stack component that renders children in a group with animated clip path.
|
|
11
|
+
*/
|
|
12
|
+
export const DefaultBarStack = /*#__PURE__*/memo(_ref => {
|
|
13
|
+
let {
|
|
14
|
+
children,
|
|
15
|
+
width,
|
|
16
|
+
height,
|
|
17
|
+
x,
|
|
18
|
+
y,
|
|
19
|
+
borderRadius = 4,
|
|
20
|
+
roundTop = true,
|
|
21
|
+
roundBottom = true,
|
|
22
|
+
yOrigin
|
|
23
|
+
} = _ref;
|
|
24
|
+
const pathRef = useRef(null);
|
|
25
|
+
const {
|
|
26
|
+
animate
|
|
27
|
+
} = useCartesianChartContext();
|
|
28
|
+
const clipPathId = useId();
|
|
29
|
+
const animationProgress = useSharedValue(0);
|
|
30
|
+
const targetClipPath = useMemo(() => {
|
|
31
|
+
return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom);
|
|
32
|
+
}, [x, y, width, height, borderRadius, roundTop, roundBottom]);
|
|
33
|
+
const previousClipPath = usePreviousValue(targetClipPath);
|
|
34
|
+
const initialClipPath = useMemo(() => {
|
|
35
|
+
return getBarPath(x, yOrigin != null ? yOrigin : y + height, width, 1, borderRadius, roundTop, roundBottom);
|
|
36
|
+
}, [x, yOrigin, y, height, width, borderRadius, roundTop, roundBottom]);
|
|
37
|
+
const fromClipPath = useMemo(() => {
|
|
38
|
+
if (!animate) return targetClipPath;
|
|
39
|
+
return previousClipPath || initialClipPath;
|
|
40
|
+
}, [animate, previousClipPath, initialClipPath, targetClipPath]);
|
|
41
|
+
const clipPathInterpolator = useMemo(() => interpolate.interpolatePath(fromClipPath, targetClipPath), [fromClipPath, targetClipPath]);
|
|
42
|
+
const updateClipPath = useCallback(progress => {
|
|
43
|
+
var _pathRef$current;
|
|
44
|
+
const val = Number(progress.toFixed(4));
|
|
45
|
+
(_pathRef$current = pathRef.current) == null || _pathRef$current.setNativeProps({
|
|
46
|
+
d: clipPathInterpolator(val)
|
|
47
|
+
});
|
|
48
|
+
}, [clipPathInterpolator]);
|
|
49
|
+
useAnimatedReaction(() => animationProgress.value, progress => {
|
|
50
|
+
'worklet';
|
|
51
|
+
|
|
52
|
+
runOnJS(updateClipPath)(progress);
|
|
53
|
+
}, [updateClipPath]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!pathRef.current) return;
|
|
56
|
+
if (!animate) {
|
|
57
|
+
pathRef.current.setNativeProps({
|
|
58
|
+
d: targetClipPath
|
|
59
|
+
});
|
|
60
|
+
animationProgress.value = 1;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
animationProgress.value = 0;
|
|
64
|
+
animationProgress.value = withTiming(1, {
|
|
65
|
+
duration: 300
|
|
66
|
+
});
|
|
67
|
+
}, [animate, animationProgress, targetClipPath, initialClipPath]);
|
|
68
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
69
|
+
children: [/*#__PURE__*/_jsx(Defs, {
|
|
70
|
+
children: /*#__PURE__*/_jsx(ClipPath, {
|
|
71
|
+
id: clipPathId,
|
|
72
|
+
children: /*#__PURE__*/_jsx(Path, {
|
|
73
|
+
ref: pathRef,
|
|
74
|
+
d: fromClipPath
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
}), /*#__PURE__*/_jsx(G, {
|
|
78
|
+
clipPath: "url(#" + clipPathId + ")",
|
|
79
|
+
children: children
|
|
80
|
+
})]
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
const _excluded = ["children"];
|
|
2
|
+
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; }
|
|
3
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
|
+
import { memo, useContext, useState } from 'react';
|
|
5
|
+
import { Rect as SvgRect } from 'react-native-svg';
|
|
6
|
+
import { Button } from '@coinbase/cds-mobile/buttons';
|
|
7
|
+
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
8
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
9
|
+
import { VStack } from '@coinbase/cds-mobile/layout';
|
|
10
|
+
import { XAxis, YAxis } from '../../axis';
|
|
11
|
+
import { CartesianChart } from '../../CartesianChart';
|
|
12
|
+
import { useCartesianChartContext } from '../../ChartProvider';
|
|
13
|
+
import { ReferenceLine, SolidLine } from '../../line';
|
|
14
|
+
import { isCategoricalScale, ScrubberContext } from '../../utils';
|
|
15
|
+
import { Bar } from '../Bar';
|
|
16
|
+
import { BarChart } from '../BarChart';
|
|
17
|
+
import { BarPlot } from '../BarPlot';
|
|
18
|
+
import { DefaultBarStack } from '../DefaultBarStack';
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
const ThinSolidLine = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
|
|
21
|
+
strokeWidth: 1
|
|
22
|
+
})));
|
|
23
|
+
const defaultChartHeight = 250;
|
|
24
|
+
const PositiveAndNegativeCashFlow = () => {
|
|
25
|
+
const theme = useTheme();
|
|
26
|
+
const categories = Array.from({
|
|
27
|
+
length: 31
|
|
28
|
+
}, (_, i) => "3/" + (i + 1));
|
|
29
|
+
const gains = [5, 0, 6, 18, 0, 5, 12, 0, 12, 22, 28, 18, 0, 12, 6, 0, 0, 24, 0, 0, 4, 0, 18, 0, 0, 14, 10, 16, 0, 0, 0];
|
|
30
|
+
const losses = [-4, 0, -8, -12, -6, 0, 0, 0, -18, 0, -12, 0, -9, -6, 0, 0, 0, 0, -22, -8, 0, 0, -10, -14, 0, 0, 0, 0, 0, -12, -10];
|
|
31
|
+
const series = [{
|
|
32
|
+
id: 'gains',
|
|
33
|
+
data: gains,
|
|
34
|
+
color: theme.color.fgPositive,
|
|
35
|
+
stackId: 'bars'
|
|
36
|
+
}, {
|
|
37
|
+
id: 'losses',
|
|
38
|
+
data: losses,
|
|
39
|
+
color: theme.color.fgNegative,
|
|
40
|
+
stackId: 'bars'
|
|
41
|
+
}];
|
|
42
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
43
|
+
height: 420,
|
|
44
|
+
inset: 32,
|
|
45
|
+
series: series,
|
|
46
|
+
xAxis: {
|
|
47
|
+
data: categories,
|
|
48
|
+
scaleType: 'band'
|
|
49
|
+
},
|
|
50
|
+
children: [/*#__PURE__*/_jsx(XAxis, {}), /*#__PURE__*/_jsx(YAxis, {
|
|
51
|
+
showGrid: true,
|
|
52
|
+
GridLineComponent: ThinSolidLine,
|
|
53
|
+
tickLabelFormatter: value => "$" + value + "M"
|
|
54
|
+
}), /*#__PURE__*/_jsx(BarPlot, {}), /*#__PURE__*/_jsx(ReferenceLine, {
|
|
55
|
+
LineComponent: SolidLine,
|
|
56
|
+
dataY: 0
|
|
57
|
+
})]
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const FiatAndStablecoinBalance = () => {
|
|
61
|
+
const theme = useTheme();
|
|
62
|
+
const categories = Array.from({
|
|
63
|
+
length: 31
|
|
64
|
+
}, (_, i) => "3/" + (i + 1));
|
|
65
|
+
const usd = [20, 20, 20, 20, 20, 40, 60, 60, 80, 120, 200, 240, 240, 240, 240, 240, 240, 240, 240, 60, 30, 20, 25, 5, 0, 0, 0, 0, 80, 120, 150];
|
|
66
|
+
const usdc = [0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 260, 260, 240, 220, 180, 160, 200, 240, 220, 0, 0, 0, 0, 0, 0, 250, 250, 250, 250, 250, 250];
|
|
67
|
+
const brl = [0, 0, 0, 0, 0, 0, 0, 20, 40, 100, 60, 60, 60, 0, 0, 0, 0, 0, 0, 160, 40, 80, 140, 180, 120, 0, 0, 0, 30, 30, 40];
|
|
68
|
+
const series = [{
|
|
69
|
+
id: 'BRL',
|
|
70
|
+
data: brl,
|
|
71
|
+
color: theme.color.accentBoldGreen
|
|
72
|
+
}, {
|
|
73
|
+
id: 'USDC',
|
|
74
|
+
data: usdc,
|
|
75
|
+
color: theme.color.accentBoldBlue
|
|
76
|
+
}, {
|
|
77
|
+
id: 'USD',
|
|
78
|
+
data: usd,
|
|
79
|
+
color: '#5b6cff'
|
|
80
|
+
}];
|
|
81
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
82
|
+
showXAxis: true,
|
|
83
|
+
stacked: true,
|
|
84
|
+
barMinSize: 8,
|
|
85
|
+
height: 420,
|
|
86
|
+
inset: 32,
|
|
87
|
+
series: series,
|
|
88
|
+
stackGap: 2,
|
|
89
|
+
stackMinSize: 16,
|
|
90
|
+
xAxis: {
|
|
91
|
+
data: categories
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const MonthlyRewards = () => {
|
|
96
|
+
const theme = useTheme();
|
|
97
|
+
const months = ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'];
|
|
98
|
+
const purple = [null, 6, 8, 10, 7, 6, 6, 8, null, null, null, null];
|
|
99
|
+
const blue = [null, 10, 12, 11, 10, 9, 10, 11, null, null, null, null];
|
|
100
|
+
const cyan = [null, 7, 10, 12, 11, 10, 8, 11, null, null, null, null];
|
|
101
|
+
const green = [10, null, null, null, 1, null, null, 6, null, null, null, null];
|
|
102
|
+
const series = [{
|
|
103
|
+
id: 'purple',
|
|
104
|
+
data: purple,
|
|
105
|
+
color: '#b399ff'
|
|
106
|
+
}, {
|
|
107
|
+
id: 'blue',
|
|
108
|
+
data: blue,
|
|
109
|
+
color: '#4f7cff'
|
|
110
|
+
}, {
|
|
111
|
+
id: 'cyan',
|
|
112
|
+
data: cyan,
|
|
113
|
+
color: '#00c2df'
|
|
114
|
+
}, {
|
|
115
|
+
id: 'green',
|
|
116
|
+
data: green,
|
|
117
|
+
color: '#33c481'
|
|
118
|
+
}];
|
|
119
|
+
const CustomBarStackComponent = _ref => {
|
|
120
|
+
let {
|
|
121
|
+
children
|
|
122
|
+
} = _ref,
|
|
123
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
124
|
+
if (props.height === 0) {
|
|
125
|
+
const diameter = props.width;
|
|
126
|
+
return /*#__PURE__*/_jsx(Bar, {
|
|
127
|
+
roundBottom: true,
|
|
128
|
+
roundTop: true,
|
|
129
|
+
borderRadius: 1000,
|
|
130
|
+
fill: theme.color.bgTertiary,
|
|
131
|
+
height: diameter,
|
|
132
|
+
originY: props.y,
|
|
133
|
+
width: diameter,
|
|
134
|
+
x: props.x,
|
|
135
|
+
y: props.y - diameter
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return /*#__PURE__*/_jsx(DefaultBarStack, _extends({}, props, {
|
|
139
|
+
children: children
|
|
140
|
+
}));
|
|
141
|
+
};
|
|
142
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
143
|
+
roundBaseline: true,
|
|
144
|
+
showXAxis: true,
|
|
145
|
+
stacked: true,
|
|
146
|
+
BarStackComponent: CustomBarStackComponent,
|
|
147
|
+
borderRadius: 1000,
|
|
148
|
+
height: 300,
|
|
149
|
+
inset: 0,
|
|
150
|
+
series: series,
|
|
151
|
+
showYAxis: false,
|
|
152
|
+
stackMinSize: 24,
|
|
153
|
+
xAxis: {
|
|
154
|
+
tickLabelFormatter: index => {
|
|
155
|
+
return months[index];
|
|
156
|
+
},
|
|
157
|
+
categoryPadding: 0.27
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
const MultipleYAxes = () => {
|
|
162
|
+
const theme = useTheme();
|
|
163
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
164
|
+
height: defaultChartHeight,
|
|
165
|
+
series: [{
|
|
166
|
+
id: 'revenue',
|
|
167
|
+
data: [455, 520, 380, 455, 190, 235],
|
|
168
|
+
yAxisId: 'revenue',
|
|
169
|
+
color: theme.color.accentBoldYellow
|
|
170
|
+
}, {
|
|
171
|
+
id: 'profit',
|
|
172
|
+
data: [23, 15, 30, 56, 4, 12],
|
|
173
|
+
yAxisId: 'profit',
|
|
174
|
+
color: theme.color.fgPositive
|
|
175
|
+
}],
|
|
176
|
+
xAxis: {
|
|
177
|
+
data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
|
|
178
|
+
scaleType: 'band'
|
|
179
|
+
},
|
|
180
|
+
yAxis: [{
|
|
181
|
+
id: 'revenue'
|
|
182
|
+
}, {
|
|
183
|
+
id: 'profit'
|
|
184
|
+
}],
|
|
185
|
+
children: [/*#__PURE__*/_jsx(XAxis, {
|
|
186
|
+
showLine: true,
|
|
187
|
+
showTickMarks: true
|
|
188
|
+
}), /*#__PURE__*/_jsx(YAxis, {
|
|
189
|
+
showGrid: true,
|
|
190
|
+
showLine: true,
|
|
191
|
+
showTickMarks: true,
|
|
192
|
+
axisId: "revenue",
|
|
193
|
+
position: "left",
|
|
194
|
+
requestedTickCount: 5,
|
|
195
|
+
tickLabelFormatter: value => "$" + value + "k",
|
|
196
|
+
width: 60
|
|
197
|
+
}), /*#__PURE__*/_jsx(YAxis, {
|
|
198
|
+
showLine: true,
|
|
199
|
+
showTickMarks: true,
|
|
200
|
+
axisId: "profit",
|
|
201
|
+
requestedTickCount: 5,
|
|
202
|
+
tickLabelFormatter: value => "$" + value + "k"
|
|
203
|
+
}), /*#__PURE__*/_jsx(BarPlot, {})]
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
const UpdatingChartValues = () => {
|
|
207
|
+
const [data, setData] = useState([45, 52, 38, 45, 19, 23, 32]);
|
|
208
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
209
|
+
gap: 2,
|
|
210
|
+
children: [/*#__PURE__*/_jsx(BarChart, {
|
|
211
|
+
showXAxis: true,
|
|
212
|
+
showYAxis: true,
|
|
213
|
+
height: defaultChartHeight,
|
|
214
|
+
series: [{
|
|
215
|
+
id: 'weekly-data',
|
|
216
|
+
data: data
|
|
217
|
+
}],
|
|
218
|
+
xAxis: {
|
|
219
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
220
|
+
showTickMarks: true,
|
|
221
|
+
showLine: true
|
|
222
|
+
},
|
|
223
|
+
yAxis: {
|
|
224
|
+
requestedTickCount: 5,
|
|
225
|
+
tickLabelFormatter: value => "$" + value + "k",
|
|
226
|
+
showGrid: true,
|
|
227
|
+
showTickMarks: true,
|
|
228
|
+
showLine: true,
|
|
229
|
+
tickMarkSize: 12
|
|
230
|
+
}
|
|
231
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
232
|
+
onPress: () => setData(data => data.map(d => d + 10)),
|
|
233
|
+
children: "Update Data"
|
|
234
|
+
})]
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
const tabs = [{
|
|
238
|
+
id: 'week',
|
|
239
|
+
label: '1W'
|
|
240
|
+
}, {
|
|
241
|
+
id: 'month',
|
|
242
|
+
label: '1M'
|
|
243
|
+
}, {
|
|
244
|
+
id: 'year',
|
|
245
|
+
label: '1Y'
|
|
246
|
+
}];
|
|
247
|
+
const ScrubberRect = /*#__PURE__*/memo(() => {
|
|
248
|
+
var _useContext;
|
|
249
|
+
const theme = useTheme();
|
|
250
|
+
const {
|
|
251
|
+
getXScale,
|
|
252
|
+
getYScale
|
|
253
|
+
} = useCartesianChartContext();
|
|
254
|
+
const {
|
|
255
|
+
scrubberPosition
|
|
256
|
+
} = (_useContext = useContext(ScrubberContext)) != null ? _useContext : {};
|
|
257
|
+
const xScale = getXScale();
|
|
258
|
+
const yScale = getYScale();
|
|
259
|
+
if (!xScale || !yScale || scrubberPosition === undefined || !isCategoricalScale(xScale)) return null;
|
|
260
|
+
const yScaleDomain = yScale.range();
|
|
261
|
+
const [yMax, yMin] = yScaleDomain;
|
|
262
|
+
const barWidth = xScale.bandwidth();
|
|
263
|
+
return /*#__PURE__*/_jsx(SvgRect, {
|
|
264
|
+
fill: theme.color.bgLine,
|
|
265
|
+
height: yMax - yMin,
|
|
266
|
+
width: barWidth,
|
|
267
|
+
x: xScale(scrubberPosition),
|
|
268
|
+
y: yMin
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
const BarChartStories = () => {
|
|
272
|
+
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
273
|
+
children: [/*#__PURE__*/_jsx(Example, {
|
|
274
|
+
title: "Basic",
|
|
275
|
+
children: /*#__PURE__*/_jsx(UpdatingChartValues, {})
|
|
276
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
277
|
+
title: "Positive and Negative Cash Flow",
|
|
278
|
+
children: /*#__PURE__*/_jsx(PositiveAndNegativeCashFlow, {})
|
|
279
|
+
})]
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
export default BarChartStories;
|
|
@@ -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';
|
|
3
|
+
export * from './axis';
|
|
4
|
+
export * from './bar';
|
|
5
|
+
export * from './CartesianChart';
|
|
6
|
+
export * from './ChartProvider';
|
|
7
|
+
export * from './line';
|
|
8
|
+
export * from './Path';
|
|
9
|
+
export * from './PeriodSelector';
|
|
10
|
+
export * from './Point';
|
|
11
|
+
export * from './scrubber';
|
|
12
|
+
export * from './text';
|
|
13
|
+
export * from './utils';
|
|
14
|
+
// codegen:end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "strokeDasharray", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "vectorEffect"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
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; }
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
6
|
+
import { Path } from '../Path';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
/**
|
|
9
|
+
* A customizable dotted line component which uses path element.
|
|
10
|
+
*/
|
|
11
|
+
export const DottedLine = /*#__PURE__*/memo(_ref => {
|
|
12
|
+
let {
|
|
13
|
+
fill = 'none',
|
|
14
|
+
stroke,
|
|
15
|
+
strokeDasharray = '0 4',
|
|
16
|
+
strokeLinecap = 'round',
|
|
17
|
+
strokeLinejoin = 'round',
|
|
18
|
+
strokeOpacity = 1,
|
|
19
|
+
strokeWidth = 2,
|
|
20
|
+
vectorEffect = 'non-scaling-stroke'
|
|
21
|
+
} = _ref,
|
|
22
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
|
+
const theme = useTheme();
|
|
24
|
+
return /*#__PURE__*/_jsx(Path, _extends({
|
|
25
|
+
clipOffset: strokeWidth,
|
|
26
|
+
fill: fill,
|
|
27
|
+
stroke: stroke != null ? stroke : theme.color.bgLine,
|
|
28
|
+
strokeDasharray: strokeDasharray,
|
|
29
|
+
strokeLinecap: strokeLinecap,
|
|
30
|
+
strokeLinejoin: strokeLinejoin,
|
|
31
|
+
strokeOpacity: strokeOpacity,
|
|
32
|
+
strokeWidth: strokeWidth,
|
|
33
|
+
vectorEffect: vectorEffect
|
|
34
|
+
}, props));
|
|
35
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "startColor", "endColor", "strokeOpacity", "startOpacity", "endOpacity", "strokeLinecap", "strokeLinejoin", "strokeWidth", "animate"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
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; }
|
|
4
|
+
import { memo, useId } from 'react';
|
|
5
|
+
import { Defs, LinearGradient, Stop } from 'react-native-svg';
|
|
6
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
7
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
8
|
+
import { Path } from '../Path';
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
+
/**
|
|
11
|
+
* A gradient line component which uses path element.
|
|
12
|
+
*/
|
|
13
|
+
export const GradientLine = /*#__PURE__*/memo(_ref => {
|
|
14
|
+
var _ref2, _ref3;
|
|
15
|
+
let {
|
|
16
|
+
fill = 'none',
|
|
17
|
+
stroke,
|
|
18
|
+
startColor,
|
|
19
|
+
endColor,
|
|
20
|
+
strokeOpacity = 1,
|
|
21
|
+
startOpacity = strokeOpacity,
|
|
22
|
+
endOpacity = strokeOpacity,
|
|
23
|
+
strokeLinecap = 'round',
|
|
24
|
+
strokeLinejoin = 'round',
|
|
25
|
+
strokeWidth = 2,
|
|
26
|
+
animate
|
|
27
|
+
} = _ref,
|
|
28
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
29
|
+
const context = useCartesianChartContext();
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
const patternId = useId();
|
|
32
|
+
const shouldAnimate = animate != null ? animate : context.animate;
|
|
33
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
34
|
+
children: [/*#__PURE__*/_jsx(Defs, {
|
|
35
|
+
children: /*#__PURE__*/_jsxs(LinearGradient, {
|
|
36
|
+
id: patternId,
|
|
37
|
+
x1: "0%",
|
|
38
|
+
x2: "0%",
|
|
39
|
+
y1: "0%",
|
|
40
|
+
y2: "100%",
|
|
41
|
+
children: [/*#__PURE__*/_jsx(Stop, {
|
|
42
|
+
offset: "0%",
|
|
43
|
+
stopColor: (_ref2 = startColor != null ? startColor : stroke) != null ? _ref2 : theme.color.bgLine,
|
|
44
|
+
stopOpacity: startOpacity
|
|
45
|
+
}), /*#__PURE__*/_jsx(Stop, {
|
|
46
|
+
offset: "100%",
|
|
47
|
+
stopColor: (_ref3 = endColor != null ? endColor : stroke) != null ? _ref3 : theme.color.bgLine,
|
|
48
|
+
stopOpacity: endOpacity
|
|
49
|
+
})]
|
|
50
|
+
})
|
|
51
|
+
}), /*#__PURE__*/_jsx(Path, _extends({
|
|
52
|
+
animate: shouldAnimate,
|
|
53
|
+
clipOffset: strokeWidth,
|
|
54
|
+
fill: fill,
|
|
55
|
+
stroke: "url(#" + patternId + ")",
|
|
56
|
+
strokeLinecap: strokeLinecap,
|
|
57
|
+
strokeLinejoin: strokeLinejoin,
|
|
58
|
+
strokeOpacity: strokeOpacity,
|
|
59
|
+
strokeWidth: strokeWidth
|
|
60
|
+
}, props))]
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const _excluded = ["seriesId", "curve", "type", "areaType", "areaBaseline", "stroke", "showArea", "LineComponent", "AreaComponent", "opacity", "renderPoints"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
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; }
|
|
4
|
+
import React, { memo, useMemo } from 'react';
|
|
5
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
6
|
+
import { Area } from '../area/Area';
|
|
7
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
8
|
+
import { Point } from '../Point';
|
|
9
|
+
import { getLinePath } from '../utils';
|
|
10
|
+
import { DottedLine } from './DottedLine';
|
|
11
|
+
import { GradientLine } from './GradientLine';
|
|
12
|
+
import { SolidLine } from './SolidLine';
|
|
13
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
export const Line = /*#__PURE__*/memo(_ref => {
|
|
15
|
+
var _ref2;
|
|
16
|
+
let {
|
|
17
|
+
seriesId,
|
|
18
|
+
curve = 'linear',
|
|
19
|
+
type = 'solid',
|
|
20
|
+
areaType = 'gradient',
|
|
21
|
+
areaBaseline,
|
|
22
|
+
stroke: specifiedStroke,
|
|
23
|
+
showArea = false,
|
|
24
|
+
LineComponent: SelectedLineComponent,
|
|
25
|
+
AreaComponent,
|
|
26
|
+
opacity = 1,
|
|
27
|
+
renderPoints
|
|
28
|
+
} = _ref,
|
|
29
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
const {
|
|
32
|
+
getSeries,
|
|
33
|
+
getSeriesData,
|
|
34
|
+
getXScale,
|
|
35
|
+
getYScale,
|
|
36
|
+
getXAxis
|
|
37
|
+
} = useCartesianChartContext();
|
|
38
|
+
const matchedSeries = getSeries(seriesId);
|
|
39
|
+
const sourceData = useMemo(() => {
|
|
40
|
+
return getSeriesData(seriesId) || null;
|
|
41
|
+
}, [seriesId, getSeriesData]);
|
|
42
|
+
const xAxis = getXAxis();
|
|
43
|
+
const xScale = getXScale();
|
|
44
|
+
const yScale = getYScale(matchedSeries == null ? void 0 : matchedSeries.yAxisId);
|
|
45
|
+
|
|
46
|
+
// Convert sourceData to number array (line only supports numbers, not tuples)
|
|
47
|
+
// If data is stacked (tuples), extract the actual values from [baseline, actualValue] format
|
|
48
|
+
const chartData = useMemo(() => {
|
|
49
|
+
if (!sourceData) return [];
|
|
50
|
+
|
|
51
|
+
// Check if this is stacked data (array of tuples)
|
|
52
|
+
const firstNonNull = sourceData.find(d => d !== null);
|
|
53
|
+
if (Array.isArray(firstNonNull)) {
|
|
54
|
+
// Extract actual values from [baseline, value] tuples
|
|
55
|
+
return sourceData.map(d => {
|
|
56
|
+
if (d === null) return null;
|
|
57
|
+
if (Array.isArray(d)) return d[1];
|
|
58
|
+
return d;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Regular number array
|
|
63
|
+
if (sourceData.every(d => typeof d === 'number' || d === null)) {
|
|
64
|
+
return sourceData;
|
|
65
|
+
}
|
|
66
|
+
return [];
|
|
67
|
+
}, [sourceData]);
|
|
68
|
+
const path = useMemo(() => {
|
|
69
|
+
if (!xScale || !yScale || chartData.length === 0) return '';
|
|
70
|
+
|
|
71
|
+
// Get numeric x-axis data if available
|
|
72
|
+
const xData = xAxis != null && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
73
|
+
return getLinePath({
|
|
74
|
+
data: chartData,
|
|
75
|
+
xScale,
|
|
76
|
+
yScale,
|
|
77
|
+
curve,
|
|
78
|
+
xData
|
|
79
|
+
});
|
|
80
|
+
}, [chartData, xScale, yScale, curve, xAxis == null ? void 0 : xAxis.data]);
|
|
81
|
+
const LineComponent = useMemo(() => {
|
|
82
|
+
if (SelectedLineComponent) {
|
|
83
|
+
return SelectedLineComponent;
|
|
84
|
+
}
|
|
85
|
+
switch (type) {
|
|
86
|
+
case 'dotted':
|
|
87
|
+
return DottedLine;
|
|
88
|
+
case 'gradient':
|
|
89
|
+
return GradientLine;
|
|
90
|
+
case 'solid':
|
|
91
|
+
default:
|
|
92
|
+
return SolidLine;
|
|
93
|
+
}
|
|
94
|
+
}, [SelectedLineComponent, type]);
|
|
95
|
+
const stroke = (_ref2 = specifiedStroke != null ? specifiedStroke : matchedSeries == null ? void 0 : matchedSeries.color) != null ? _ref2 : theme.color.fgPrimary;
|
|
96
|
+
const xData = useMemo(() => {
|
|
97
|
+
const data = xAxis == null ? void 0 : xAxis.data;
|
|
98
|
+
return data && Array.isArray(data) && data.length > 0 && typeof data[0] === 'number' ? data : null;
|
|
99
|
+
}, [xAxis == null ? void 0 : xAxis.data]);
|
|
100
|
+
if (!xScale || !yScale) return;
|
|
101
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
102
|
+
children: [showArea && /*#__PURE__*/_jsx(Area, {
|
|
103
|
+
AreaComponent: AreaComponent,
|
|
104
|
+
baseline: areaBaseline,
|
|
105
|
+
curve: curve,
|
|
106
|
+
fill: stroke,
|
|
107
|
+
fillOpacity: opacity,
|
|
108
|
+
seriesId: seriesId,
|
|
109
|
+
type: areaType
|
|
110
|
+
}), /*#__PURE__*/_jsx(LineComponent, _extends({
|
|
111
|
+
d: path,
|
|
112
|
+
stroke: stroke,
|
|
113
|
+
strokeOpacity: opacity
|
|
114
|
+
}, props)), renderPoints && chartData.map((value, index) => {
|
|
115
|
+
var _xScale, _yScale, _pointConfig$fill, _pointConfig$opacity;
|
|
116
|
+
if (value === null) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const xValue = xData && xData[index] !== undefined ? xData[index] : index;
|
|
120
|
+
const pointResult = renderPoints({
|
|
121
|
+
dataY: value,
|
|
122
|
+
dataX: xValue,
|
|
123
|
+
x: (_xScale = xScale == null ? void 0 : xScale(xValue)) != null ? _xScale : 0,
|
|
124
|
+
y: (_yScale = yScale == null ? void 0 : yScale(value)) != null ? _yScale : 0
|
|
125
|
+
});
|
|
126
|
+
if (pointResult === false || pointResult === null || pointResult === undefined) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const pointConfig = pointResult === true ? {} : pointResult;
|
|
130
|
+
return /*#__PURE__*/_jsx(Point, _extends({
|
|
131
|
+
dataX: xValue,
|
|
132
|
+
dataY: value
|
|
133
|
+
}, pointConfig, {
|
|
134
|
+
fill: (_pointConfig$fill = pointConfig.fill) != null ? _pointConfig$fill : stroke,
|
|
135
|
+
opacity: (_pointConfig$opacity = pointConfig.opacity) != null ? _pointConfig$opacity : opacity
|
|
136
|
+
}), seriesId + "-renderpoint-" + index);
|
|
137
|
+
})]
|
|
138
|
+
});
|
|
139
|
+
});
|