@coinbase/cds-mobile-visualization 3.3.0 → 3.4.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -0
- package/dts/chart/CartesianChart.d.ts +125 -0
- package/dts/chart/CartesianChart.d.ts.map +1 -0
- package/dts/chart/ChartContextBridge.d.ts +28 -0
- package/dts/chart/ChartContextBridge.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 +91 -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/area/Area.d.ts +77 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +131 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +46 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +36 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +23 -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 +194 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts +8 -0
- package/dts/chart/axis/DefaultAxisTickLabel.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 +5 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +92 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +113 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +30 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +102 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +36 -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/gradient/Gradient.d.ts +25 -0
- package/dts/chart/gradient/Gradient.d.ts.map +1 -0
- package/dts/chart/gradient/index.d.ts +2 -0
- package/dts/chart/gradient/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +15 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts +9 -0
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +20 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +115 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +118 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +139 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +15 -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/point/DefaultPointLabel.d.ts +10 -0
- package/dts/chart/point/DefaultPointLabel.d.ts.map +1 -0
- package/dts/chart/point/Point.d.ts +120 -0
- package/dts/chart/point/Point.d.ts.map +1 -0
- package/dts/chart/point/index.d.ts +3 -0
- package/dts/chart/point/index.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +8 -0
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +12 -0
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +11 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +233 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +44 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +31 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +20 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +5 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +164 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/ChartTextGroup.d.ts +61 -0
- package/dts/chart/text/ChartTextGroup.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 +124 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +116 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/gradient.d.ts +117 -0
- package/dts/chart/utils/gradient.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +11 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +160 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +134 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +134 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/chart/utils/scrubber.d.ts +39 -0
- package/dts/chart/utils/scrubber.d.ts.map +1 -0
- package/dts/chart/utils/transition.d.ts +140 -0
- package/dts/chart/utils/transition.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 +335 -0
- package/esm/chart/ChartContextBridge.js +148 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +218 -0
- package/esm/chart/PeriodSelector.js +136 -0
- package/esm/chart/__stories__/CartesianChart.stories.js +723 -0
- package/esm/chart/__stories__/Chart.stories.js +77 -0
- package/esm/chart/__stories__/PeriodSelector.stories.js +322 -0
- package/esm/chart/area/Area.js +75 -0
- package/esm/chart/area/AreaChart.js +151 -0
- package/esm/chart/area/DottedArea.js +80 -0
- package/esm/chart/area/GradientArea.js +54 -0
- package/esm/chart/area/SolidArea.js +38 -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 +45 -0
- package/esm/chart/axis/DefaultAxisTickLabel.js +11 -0
- package/esm/chart/axis/XAxis.js +188 -0
- package/esm/chart/axis/YAxis.js +177 -0
- package/esm/chart/axis/__stories__/Axis.stories.js +276 -0
- package/esm/chart/axis/index.js +6 -0
- package/esm/chart/bar/Bar.js +69 -0
- package/esm/chart/bar/BarChart.js +125 -0
- package/esm/chart/bar/BarPlot.js +102 -0
- package/esm/chart/bar/BarStack.js +551 -0
- package/esm/chart/bar/BarStackGroup.js +79 -0
- package/esm/chart/bar/DefaultBar.js +56 -0
- package/esm/chart/bar/DefaultBarStack.js +47 -0
- package/esm/chart/bar/__stories__/BarChart.stories.js +668 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/gradient/Gradient.js +53 -0
- package/esm/chart/gradient/index.js +1 -0
- package/esm/chart/index.js +16 -0
- package/esm/chart/line/DefaultReferenceLineLabel.js +66 -0
- package/esm/chart/line/DottedLine.js +50 -0
- package/esm/chart/line/Line.js +178 -0
- package/esm/chart/line/LineChart.js +121 -0
- package/esm/chart/line/ReferenceLine.js +132 -0
- package/esm/chart/line/SolidLine.js +46 -0
- package/esm/chart/line/__stories__/LineChart.stories.js +2372 -0
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +132 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/point/DefaultPointLabel.js +39 -0
- package/esm/chart/point/Point.js +188 -0
- package/esm/chart/point/index.js +2 -0
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +179 -0
- package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +43 -0
- package/esm/chart/scrubber/DefaultScrubberLabel.js +28 -0
- package/esm/chart/scrubber/Scrubber.js +166 -0
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +161 -0
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +185 -0
- package/esm/chart/scrubber/ScrubberProvider.js +135 -0
- package/esm/chart/scrubber/index.js +4 -0
- package/esm/chart/text/ChartText.js +305 -0
- package/esm/chart/text/ChartTextGroup.js +211 -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 +270 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/gradient.js +305 -0
- package/esm/chart/utils/index.js +12 -0
- package/esm/chart/utils/path.js +274 -0
- package/esm/chart/utils/point.js +229 -0
- package/esm/chart/utils/scale.js +277 -0
- package/esm/chart/utils/scrubber.js +139 -0
- package/esm/chart/utils/transition.js +185 -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/__stories__/Sparkline.stories.js +11 -7
- package/esm/sparkline/__stories__/SparklineGradient.stories.js +7 -4
- 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 +76 -24
- package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +17 -9
- package/package.json +17 -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,77 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
3
|
+
import { CartesianChart, DottedArea, Line, LineChart, SolidLine } from '../';
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
const defaultChartHeight = 250;
|
|
6
|
+
const BasicLineChart = () => {
|
|
7
|
+
const chartData = [65, 78, 45, 88, 92, 73, 69];
|
|
8
|
+
return /*#__PURE__*/_jsx(LineChart, {
|
|
9
|
+
showYAxis: true,
|
|
10
|
+
height: defaultChartHeight,
|
|
11
|
+
series: [{
|
|
12
|
+
id: 'monthly-growth',
|
|
13
|
+
data: chartData,
|
|
14
|
+
label: 'Monthly Growth',
|
|
15
|
+
color: '#2ca02c'
|
|
16
|
+
}],
|
|
17
|
+
yAxis: {
|
|
18
|
+
requestedTickCount: 2,
|
|
19
|
+
tickLabelFormatter: value => "$" + value,
|
|
20
|
+
showGrid: true
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const LineStyles = () => {
|
|
25
|
+
const topChartData = [15, 28, 32, 44, 46, 36, 40, 45, 48, 38];
|
|
26
|
+
const upperMiddleChartData = [12, 23, 21, 29, 34, 28, 31, 38, 42, 35];
|
|
27
|
+
const lowerMiddleChartData = [8, 15, 14, 25, 20, 18, 22, 28, 24, 30];
|
|
28
|
+
const bottomChartData = [4, 8, 11, 15, 16, 14, 16, 10, 12, 14];
|
|
29
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
30
|
+
height: defaultChartHeight,
|
|
31
|
+
series: [{
|
|
32
|
+
id: 'top',
|
|
33
|
+
data: topChartData
|
|
34
|
+
}, {
|
|
35
|
+
id: 'upperMiddle',
|
|
36
|
+
data: upperMiddleChartData,
|
|
37
|
+
color: '#ef4444'
|
|
38
|
+
}, {
|
|
39
|
+
id: 'lowerMiddle',
|
|
40
|
+
data: lowerMiddleChartData,
|
|
41
|
+
color: '#f59e0b'
|
|
42
|
+
}, {
|
|
43
|
+
id: 'bottom',
|
|
44
|
+
data: bottomChartData,
|
|
45
|
+
color: '#800080'
|
|
46
|
+
}],
|
|
47
|
+
children: [/*#__PURE__*/_jsx(Line, {
|
|
48
|
+
seriesId: "top"
|
|
49
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
50
|
+
seriesId: "upperMiddle",
|
|
51
|
+
type: "dotted"
|
|
52
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
53
|
+
LineComponent: props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
|
|
54
|
+
strokeWidth: 4
|
|
55
|
+
})),
|
|
56
|
+
curve: "natural",
|
|
57
|
+
seriesId: "lowerMiddle"
|
|
58
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
59
|
+
showArea: true,
|
|
60
|
+
AreaComponent: DottedArea,
|
|
61
|
+
curve: "step",
|
|
62
|
+
seriesId: "bottom"
|
|
63
|
+
})]
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const ChartStories = () => {
|
|
67
|
+
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
68
|
+
children: [/*#__PURE__*/_jsx(Example, {
|
|
69
|
+
title: "Basic Line Chart",
|
|
70
|
+
children: /*#__PURE__*/_jsx(BasicLineChart, {})
|
|
71
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
72
|
+
title: "Line Styles",
|
|
73
|
+
children: /*#__PURE__*/_jsx(LineStyles, {})
|
|
74
|
+
})]
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export default ChartStories;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
const _excluded = ["label"],
|
|
2
|
+
_excluded2 = ["label", "font", "hideDot", "style"];
|
|
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
|
+
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); }
|
|
5
|
+
import { forwardRef, memo, useMemo, useState } from 'react';
|
|
6
|
+
import { ScrollView, View } from 'react-native';
|
|
7
|
+
import { assets } from '@coinbase/cds-common/internal/data/assets';
|
|
8
|
+
import { useTabsContext } from '@coinbase/cds-common/tabs/TabsContext';
|
|
9
|
+
import { IconButton } from '@coinbase/cds-mobile/buttons';
|
|
10
|
+
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
11
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
12
|
+
import { HStack } from '@coinbase/cds-mobile/layout';
|
|
13
|
+
import { SegmentedTab } from '@coinbase/cds-mobile/tabs/SegmentedTab';
|
|
14
|
+
import { Text } from '@coinbase/cds-mobile/typography';
|
|
15
|
+
import { LiveTabLabel, PeriodSelector, PeriodSelectorActiveIndicator } from '../PeriodSelector';
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
const PeriodSelectorExample = () => {
|
|
18
|
+
const tabs = [{
|
|
19
|
+
id: '1H',
|
|
20
|
+
label: '1H'
|
|
21
|
+
}, {
|
|
22
|
+
id: '1D',
|
|
23
|
+
label: '1D'
|
|
24
|
+
}, {
|
|
25
|
+
id: '1W',
|
|
26
|
+
label: '1W'
|
|
27
|
+
}, {
|
|
28
|
+
id: '1M',
|
|
29
|
+
label: '1M'
|
|
30
|
+
}, {
|
|
31
|
+
id: '1Y',
|
|
32
|
+
label: '1Y'
|
|
33
|
+
}, {
|
|
34
|
+
id: 'All',
|
|
35
|
+
label: 'All'
|
|
36
|
+
}];
|
|
37
|
+
const [activeTab, setActiveTab] = useState(tabs[0]);
|
|
38
|
+
return /*#__PURE__*/_jsx(PeriodSelector, {
|
|
39
|
+
activeTab: activeTab,
|
|
40
|
+
onChange: tab => setActiveTab(tab),
|
|
41
|
+
tabs: tabs
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const MinWidthPeriodSelectorExample = () => {
|
|
45
|
+
const tabs = [{
|
|
46
|
+
id: '1H',
|
|
47
|
+
label: '1H'
|
|
48
|
+
}, {
|
|
49
|
+
id: '1D',
|
|
50
|
+
label: '1D'
|
|
51
|
+
}, {
|
|
52
|
+
id: '1W',
|
|
53
|
+
label: '1W'
|
|
54
|
+
}, {
|
|
55
|
+
id: '1M',
|
|
56
|
+
label: '1M'
|
|
57
|
+
}, {
|
|
58
|
+
id: '1Y',
|
|
59
|
+
label: '1Y'
|
|
60
|
+
}, {
|
|
61
|
+
id: 'All',
|
|
62
|
+
label: 'All'
|
|
63
|
+
}];
|
|
64
|
+
const [activeTab, setActiveTab] = useState(tabs[0]);
|
|
65
|
+
return /*#__PURE__*/_jsx(PeriodSelector, {
|
|
66
|
+
activeTab: activeTab,
|
|
67
|
+
gap: 0.5,
|
|
68
|
+
onChange: tab => setActiveTab(tab),
|
|
69
|
+
tabs: tabs,
|
|
70
|
+
width: "fit-content"
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const LivePeriodSelectorExample = () => {
|
|
74
|
+
const tabs = useMemo(() => [{
|
|
75
|
+
id: '1H',
|
|
76
|
+
label: /*#__PURE__*/_jsx(LiveTabLabel, {})
|
|
77
|
+
}, {
|
|
78
|
+
id: '1D',
|
|
79
|
+
label: '1D'
|
|
80
|
+
}, {
|
|
81
|
+
id: '1W',
|
|
82
|
+
label: '1W'
|
|
83
|
+
}, {
|
|
84
|
+
id: '1M',
|
|
85
|
+
label: '1M'
|
|
86
|
+
}, {
|
|
87
|
+
id: '1Y',
|
|
88
|
+
label: '1Y'
|
|
89
|
+
}, {
|
|
90
|
+
id: 'All',
|
|
91
|
+
label: 'All'
|
|
92
|
+
}], []);
|
|
93
|
+
const [activeTab, setActiveTab] = useState(tabs[0]);
|
|
94
|
+
const isLive = useMemo(() => (activeTab == null ? void 0 : activeTab.id) === '1H', [activeTab]);
|
|
95
|
+
const activeBackground = useMemo(() => !isLive ? 'bgPrimaryWash' : 'bgNegativeWash', [isLive]);
|
|
96
|
+
return /*#__PURE__*/_jsx(PeriodSelector, {
|
|
97
|
+
activeBackground: activeBackground,
|
|
98
|
+
activeTab: activeTab,
|
|
99
|
+
onChange: setActiveTab,
|
|
100
|
+
tabs: tabs
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const TooManyPeriodsSelectorExample = () => {
|
|
104
|
+
const tabs = useMemo(() => [{
|
|
105
|
+
id: '1H',
|
|
106
|
+
label: /*#__PURE__*/_jsx(LiveTabLabel, {})
|
|
107
|
+
}, {
|
|
108
|
+
id: '1D',
|
|
109
|
+
label: '1D'
|
|
110
|
+
}, {
|
|
111
|
+
id: '1W',
|
|
112
|
+
label: '1W'
|
|
113
|
+
}, {
|
|
114
|
+
id: '1M',
|
|
115
|
+
label: '1M'
|
|
116
|
+
}, {
|
|
117
|
+
id: 'YTD',
|
|
118
|
+
label: 'YTD'
|
|
119
|
+
}, {
|
|
120
|
+
id: '1Y',
|
|
121
|
+
label: '1Y'
|
|
122
|
+
}, {
|
|
123
|
+
id: '5Y',
|
|
124
|
+
label: '5Y'
|
|
125
|
+
}, {
|
|
126
|
+
id: 'All',
|
|
127
|
+
label: 'All'
|
|
128
|
+
}], []);
|
|
129
|
+
const [activeTab, setActiveTab] = useState(tabs[0]);
|
|
130
|
+
const isLive = useMemo(() => (activeTab == null ? void 0 : activeTab.id) === '1H', [activeTab]);
|
|
131
|
+
const activeBackground = useMemo(() => !isLive ? 'bgPrimaryWash' : 'bgNegativeWash', [isLive]);
|
|
132
|
+
return /*#__PURE__*/_jsxs(HStack, {
|
|
133
|
+
alignItems: "center",
|
|
134
|
+
justifyContent: "space-between",
|
|
135
|
+
maxWidth: "100%",
|
|
136
|
+
width: "100%",
|
|
137
|
+
children: [/*#__PURE__*/_jsx(ScrollView, {
|
|
138
|
+
horizontal: true,
|
|
139
|
+
contentContainerStyle: {
|
|
140
|
+
paddingEnd: 8,
|
|
141
|
+
flexGrow: 1
|
|
142
|
+
},
|
|
143
|
+
showsHorizontalScrollIndicator: false,
|
|
144
|
+
children: /*#__PURE__*/_jsx(PeriodSelector, {
|
|
145
|
+
activeBackground: activeBackground,
|
|
146
|
+
activeTab: activeTab,
|
|
147
|
+
gap: 1,
|
|
148
|
+
justifyContent: "flex-start",
|
|
149
|
+
onChange: setActiveTab,
|
|
150
|
+
tabs: tabs,
|
|
151
|
+
width: "fit-content"
|
|
152
|
+
})
|
|
153
|
+
}), /*#__PURE__*/_jsx(IconButton, {
|
|
154
|
+
compact: true,
|
|
155
|
+
accessibilityLabel: "Configure chart",
|
|
156
|
+
flexShrink: 0,
|
|
157
|
+
name: "filter",
|
|
158
|
+
variant: "secondary"
|
|
159
|
+
})]
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
const btcColor = assets.btc.color;
|
|
163
|
+
const BTCActiveIndicator = /*#__PURE__*/memo(props => {
|
|
164
|
+
const theme = useTheme();
|
|
165
|
+
const {
|
|
166
|
+
activeTab
|
|
167
|
+
} = useTabsContext();
|
|
168
|
+
const isLive = useMemo(() => (activeTab == null ? void 0 : activeTab.id) === '1H', [activeTab]);
|
|
169
|
+
const backgroundColor = useMemo(() => isLive ? theme.color.bgNegativeWash : btcColor + "1A", [isLive, theme.color.bgNegativeWash]);
|
|
170
|
+
return /*#__PURE__*/_jsx(PeriodSelectorActiveIndicator, _extends({}, props, {
|
|
171
|
+
background: backgroundColor
|
|
172
|
+
}));
|
|
173
|
+
});
|
|
174
|
+
const BTCActiveExcludingLiveIndicator = /*#__PURE__*/memo(props => {
|
|
175
|
+
const theme = useTheme();
|
|
176
|
+
const {
|
|
177
|
+
activeTab
|
|
178
|
+
} = useTabsContext();
|
|
179
|
+
const isLive = useMemo(() => (activeTab == null ? void 0 : activeTab.id) === '1H', [activeTab]);
|
|
180
|
+
const backgroundColor = useMemo(() => isLive ? theme.color.bgNegativeWash : btcColor + "1A", [isLive, theme.color.bgNegativeWash]);
|
|
181
|
+
return /*#__PURE__*/_jsx(PeriodSelectorActiveIndicator, _extends({}, props, {
|
|
182
|
+
background: backgroundColor
|
|
183
|
+
}));
|
|
184
|
+
});
|
|
185
|
+
const BTCTab = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
186
|
+
let {
|
|
187
|
+
label
|
|
188
|
+
} = _ref,
|
|
189
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
190
|
+
const {
|
|
191
|
+
activeTab
|
|
192
|
+
} = useTabsContext();
|
|
193
|
+
const isActive = (activeTab == null ? void 0 : activeTab.id) === props.id;
|
|
194
|
+
const theme = useTheme();
|
|
195
|
+
|
|
196
|
+
// If label is already a React element (like LiveTabLabel), pass it through directly
|
|
197
|
+
// For string labels, wrap with custom BTC color when active
|
|
198
|
+
const wrappedLabel = typeof label === 'string' ? /*#__PURE__*/_jsx(Text, {
|
|
199
|
+
dangerouslySetColor: isActive ? btcColor : theme.color.fg,
|
|
200
|
+
font: "label1",
|
|
201
|
+
children: label
|
|
202
|
+
}) : label;
|
|
203
|
+
return /*#__PURE__*/_jsx(SegmentedTab, _extends({
|
|
204
|
+
ref: ref,
|
|
205
|
+
label: wrappedLabel
|
|
206
|
+
}, props));
|
|
207
|
+
}));
|
|
208
|
+
const BTCLiveLabel = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
209
|
+
let {
|
|
210
|
+
label = 'LIVE',
|
|
211
|
+
font = 'label1',
|
|
212
|
+
hideDot,
|
|
213
|
+
style
|
|
214
|
+
} = _ref2,
|
|
215
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
216
|
+
const theme = useTheme();
|
|
217
|
+
const dotStyle = useMemo(() => ({
|
|
218
|
+
width: theme.space[1],
|
|
219
|
+
height: theme.space[1],
|
|
220
|
+
borderRadius: 1000,
|
|
221
|
+
marginRight: theme.space[0.75],
|
|
222
|
+
backgroundColor: btcColor
|
|
223
|
+
}), [theme.space]);
|
|
224
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
225
|
+
ref: ref,
|
|
226
|
+
style: [{
|
|
227
|
+
flexDirection: 'row',
|
|
228
|
+
alignItems: 'center'
|
|
229
|
+
}, style],
|
|
230
|
+
children: [!hideDot && /*#__PURE__*/_jsx(View, {
|
|
231
|
+
style: dotStyle
|
|
232
|
+
}), /*#__PURE__*/_jsx(Text, _extends({
|
|
233
|
+
font: font,
|
|
234
|
+
style: {
|
|
235
|
+
color: btcColor
|
|
236
|
+
}
|
|
237
|
+
}, props, {
|
|
238
|
+
children: label
|
|
239
|
+
}))]
|
|
240
|
+
});
|
|
241
|
+
}));
|
|
242
|
+
const ColoredPeriodSelectorExample = () => {
|
|
243
|
+
const tabs = [{
|
|
244
|
+
id: '1H',
|
|
245
|
+
label: /*#__PURE__*/_jsx(BTCLiveLabel, {})
|
|
246
|
+
}, {
|
|
247
|
+
id: '1D',
|
|
248
|
+
label: '1D'
|
|
249
|
+
}, {
|
|
250
|
+
id: '1W',
|
|
251
|
+
label: '1W'
|
|
252
|
+
}, {
|
|
253
|
+
id: '1M',
|
|
254
|
+
label: '1M'
|
|
255
|
+
}, {
|
|
256
|
+
id: '1Y',
|
|
257
|
+
label: '1Y'
|
|
258
|
+
}, {
|
|
259
|
+
id: 'All',
|
|
260
|
+
label: 'All'
|
|
261
|
+
}];
|
|
262
|
+
const [activeTab, setActiveTab] = useState(tabs[0]);
|
|
263
|
+
return /*#__PURE__*/_jsx(PeriodSelector, {
|
|
264
|
+
TabComponent: BTCTab,
|
|
265
|
+
TabsActiveIndicatorComponent: BTCActiveIndicator,
|
|
266
|
+
activeTab: activeTab,
|
|
267
|
+
onChange: tab => setActiveTab(tab),
|
|
268
|
+
tabs: tabs
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
const ColoredExcludingLivePeriodSelectorExample = () => {
|
|
272
|
+
const tabs = [{
|
|
273
|
+
id: '1H',
|
|
274
|
+
label: /*#__PURE__*/_jsx(LiveTabLabel, {})
|
|
275
|
+
}, {
|
|
276
|
+
id: '1D',
|
|
277
|
+
label: '1D'
|
|
278
|
+
}, {
|
|
279
|
+
id: '1W',
|
|
280
|
+
label: '1W'
|
|
281
|
+
}, {
|
|
282
|
+
id: '1M',
|
|
283
|
+
label: '1M'
|
|
284
|
+
}, {
|
|
285
|
+
id: '1Y',
|
|
286
|
+
label: '1Y'
|
|
287
|
+
}, {
|
|
288
|
+
id: 'All',
|
|
289
|
+
label: 'All'
|
|
290
|
+
}];
|
|
291
|
+
const [activeTab, setActiveTab] = useState(tabs[0]);
|
|
292
|
+
return /*#__PURE__*/_jsx(PeriodSelector, {
|
|
293
|
+
TabComponent: BTCTab,
|
|
294
|
+
TabsActiveIndicatorComponent: BTCActiveExcludingLiveIndicator,
|
|
295
|
+
activeTab: activeTab,
|
|
296
|
+
onChange: tab => setActiveTab(tab),
|
|
297
|
+
tabs: tabs
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
export default function All() {
|
|
301
|
+
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
302
|
+
children: [/*#__PURE__*/_jsx(Example, {
|
|
303
|
+
title: "Basic",
|
|
304
|
+
children: /*#__PURE__*/_jsx(PeriodSelectorExample, {})
|
|
305
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
306
|
+
title: "Min Width",
|
|
307
|
+
children: /*#__PURE__*/_jsx(MinWidthPeriodSelectorExample, {})
|
|
308
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
309
|
+
title: "Live Period",
|
|
310
|
+
children: /*#__PURE__*/_jsx(LivePeriodSelectorExample, {})
|
|
311
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
312
|
+
title: "Too Many Periods",
|
|
313
|
+
children: /*#__PURE__*/_jsx(TooManyPeriodsSelectorExample, {})
|
|
314
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
315
|
+
title: "Colored (BTC)",
|
|
316
|
+
children: /*#__PURE__*/_jsx(ColoredPeriodSelectorExample, {})
|
|
317
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
318
|
+
title: "Colored Excluding Live",
|
|
319
|
+
children: /*#__PURE__*/_jsx(ColoredExcludingLivePeriodSelectorExample, {})
|
|
320
|
+
})]
|
|
321
|
+
});
|
|
322
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
let {
|
|
10
|
+
seriesId,
|
|
11
|
+
curve = 'bump',
|
|
12
|
+
type = 'solid',
|
|
13
|
+
AreaComponent: AreaComponentProp,
|
|
14
|
+
fill: fillProp,
|
|
15
|
+
fillOpacity = 1,
|
|
16
|
+
baseline,
|
|
17
|
+
connectNulls,
|
|
18
|
+
gradient: gradientProp,
|
|
19
|
+
transition,
|
|
20
|
+
animate
|
|
21
|
+
} = _ref;
|
|
22
|
+
const {
|
|
23
|
+
getSeries,
|
|
24
|
+
getSeriesData,
|
|
25
|
+
getXScale,
|
|
26
|
+
getYScale,
|
|
27
|
+
getXAxis
|
|
28
|
+
} = useCartesianChartContext();
|
|
29
|
+
const matchedSeries = useMemo(() => getSeries(seriesId), [seriesId, getSeries]);
|
|
30
|
+
const gradient = useMemo(() => gradientProp != null ? gradientProp : matchedSeries == null ? void 0 : matchedSeries.gradient, [gradientProp, matchedSeries == null ? void 0 : matchedSeries.gradient]);
|
|
31
|
+
const fill = useMemo(() => fillProp != null ? fillProp : matchedSeries == null ? void 0 : matchedSeries.color, [fillProp, matchedSeries == null ? void 0 : matchedSeries.color]);
|
|
32
|
+
const sourceData = useMemo(() => getSeriesData(seriesId), [seriesId, getSeriesData]);
|
|
33
|
+
const xAxis = getXAxis();
|
|
34
|
+
const xScale = getXScale();
|
|
35
|
+
const yScale = getYScale(matchedSeries == null ? void 0 : matchedSeries.yAxisId);
|
|
36
|
+
const area = useMemo(() => {
|
|
37
|
+
if (!sourceData || sourceData.length === 0 || !xScale || !yScale) return '';
|
|
38
|
+
|
|
39
|
+
// Get numeric x-axis data if available
|
|
40
|
+
const xData = xAxis != null && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
41
|
+
return getAreaPath({
|
|
42
|
+
data: sourceData,
|
|
43
|
+
xScale,
|
|
44
|
+
yScale,
|
|
45
|
+
curve,
|
|
46
|
+
xData,
|
|
47
|
+
connectNulls
|
|
48
|
+
});
|
|
49
|
+
}, [sourceData, xScale, yScale, curve, xAxis == null ? void 0 : xAxis.data, connectNulls]);
|
|
50
|
+
const AreaComponent = useMemo(() => {
|
|
51
|
+
if (AreaComponentProp) {
|
|
52
|
+
return AreaComponentProp;
|
|
53
|
+
}
|
|
54
|
+
switch (type) {
|
|
55
|
+
case 'dotted':
|
|
56
|
+
return DottedArea;
|
|
57
|
+
case 'gradient':
|
|
58
|
+
return GradientArea;
|
|
59
|
+
case 'solid':
|
|
60
|
+
default:
|
|
61
|
+
return SolidArea;
|
|
62
|
+
}
|
|
63
|
+
}, [AreaComponentProp, type]);
|
|
64
|
+
if (!xScale || !yScale || !sourceData || !area) return;
|
|
65
|
+
return /*#__PURE__*/_jsx(AreaComponent, {
|
|
66
|
+
animate: animate,
|
|
67
|
+
baseline: baseline,
|
|
68
|
+
d: area,
|
|
69
|
+
fill: fill,
|
|
70
|
+
fillOpacity: fillOpacity,
|
|
71
|
+
gradient: gradient,
|
|
72
|
+
transition: transition,
|
|
73
|
+
yAxisId: matchedSeries == null ? void 0 : matchedSeries.yAxisId
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const _excluded = ["series", "stacked", "AreaComponent", "curve", "fillOpacity", "type", "connectNulls", "transition", "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", "type", "lineType"];
|
|
6
|
+
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); }
|
|
7
|
+
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; }
|
|
8
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
9
|
+
import { XAxis, YAxis } from '../axis';
|
|
10
|
+
import { CartesianChart } from '../CartesianChart';
|
|
11
|
+
import { Line } from '../line/Line';
|
|
12
|
+
import { defaultChartInset, defaultStackId, getChartInset } from '../utils';
|
|
13
|
+
import { Area } from './Area';
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
16
|
+
let {
|
|
17
|
+
series,
|
|
18
|
+
stacked,
|
|
19
|
+
AreaComponent,
|
|
20
|
+
curve,
|
|
21
|
+
fillOpacity,
|
|
22
|
+
type,
|
|
23
|
+
connectNulls,
|
|
24
|
+
transition,
|
|
25
|
+
LineComponent,
|
|
26
|
+
strokeWidth,
|
|
27
|
+
showXAxis,
|
|
28
|
+
showYAxis,
|
|
29
|
+
showLines,
|
|
30
|
+
lineType = 'solid',
|
|
31
|
+
xAxis,
|
|
32
|
+
yAxis,
|
|
33
|
+
inset,
|
|
34
|
+
children
|
|
35
|
+
} = _ref,
|
|
36
|
+
chartProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
37
|
+
const calculatedInset = useMemo(() => getChartInset(inset, defaultChartInset), [inset]);
|
|
38
|
+
|
|
39
|
+
// Convert AreaSeries to Series for Chart context
|
|
40
|
+
const chartSeries = useMemo(() => {
|
|
41
|
+
return series == null ? void 0 : series.map(s => ({
|
|
42
|
+
id: s.id,
|
|
43
|
+
data: s.data,
|
|
44
|
+
label: s.label,
|
|
45
|
+
color: s.color,
|
|
46
|
+
gradient: s.gradient,
|
|
47
|
+
yAxisId: s.yAxisId,
|
|
48
|
+
stackId: s.stackId
|
|
49
|
+
}));
|
|
50
|
+
}, [series]);
|
|
51
|
+
const transformedSeries = useMemo(() => {
|
|
52
|
+
if (!stacked || !chartSeries) return chartSeries;
|
|
53
|
+
return chartSeries.map(s => {
|
|
54
|
+
var _s$stackId;
|
|
55
|
+
return _extends({}, s, {
|
|
56
|
+
stackId: (_s$stackId = s.stackId) != null ? _s$stackId : defaultStackId
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}, [chartSeries, stacked]);
|
|
60
|
+
const seriesToRender = transformedSeries != null ? transformedSeries : chartSeries;
|
|
61
|
+
|
|
62
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
63
|
+
const _ref2 = xAxis || {},
|
|
64
|
+
{
|
|
65
|
+
scaleType: xScaleType,
|
|
66
|
+
data: xData,
|
|
67
|
+
categoryPadding: xCategoryPadding,
|
|
68
|
+
domain: xDomain,
|
|
69
|
+
domainLimit: xDomainLimit,
|
|
70
|
+
range: xRange
|
|
71
|
+
} = _ref2,
|
|
72
|
+
xAxisVisualProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
73
|
+
const _ref3 = yAxis || {},
|
|
74
|
+
{
|
|
75
|
+
scaleType: yScaleType,
|
|
76
|
+
data: yData,
|
|
77
|
+
categoryPadding: yCategoryPadding,
|
|
78
|
+
domain: yDomain,
|
|
79
|
+
domainLimit: yDomainLimit,
|
|
80
|
+
range: yRange,
|
|
81
|
+
id: yAxisId
|
|
82
|
+
} = _ref3,
|
|
83
|
+
yAxisVisualProps = _objectWithoutPropertiesLoose(_ref3, _excluded3);
|
|
84
|
+
const xAxisConfig = {
|
|
85
|
+
scaleType: xScaleType,
|
|
86
|
+
data: xData,
|
|
87
|
+
categoryPadding: xCategoryPadding,
|
|
88
|
+
domain: xDomain,
|
|
89
|
+
domainLimit: xDomainLimit,
|
|
90
|
+
range: xRange
|
|
91
|
+
};
|
|
92
|
+
const hasNegativeValues = useMemo(() => {
|
|
93
|
+
if (!series) return false;
|
|
94
|
+
return series.some(s => {
|
|
95
|
+
var _s$data;
|
|
96
|
+
return (_s$data = s.data) == null ? void 0 : _s$data.some(value => typeof value === 'number' && value < 0 || Array.isArray(value) && value.some(v => typeof v === 'number' && v < 0));
|
|
97
|
+
});
|
|
98
|
+
}, [series]);
|
|
99
|
+
|
|
100
|
+
// Set default min domain to 0 for area chart, but only if there are no negative values
|
|
101
|
+
const yAxisConfig = {
|
|
102
|
+
scaleType: yScaleType,
|
|
103
|
+
data: yData,
|
|
104
|
+
categoryPadding: yCategoryPadding,
|
|
105
|
+
domain: hasNegativeValues ? yDomain : _extends({
|
|
106
|
+
min: 0
|
|
107
|
+
}, yDomain),
|
|
108
|
+
domainLimit: yDomainLimit,
|
|
109
|
+
range: yRange
|
|
110
|
+
};
|
|
111
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _extends({}, chartProps, {
|
|
112
|
+
ref: ref,
|
|
113
|
+
inset: calculatedInset,
|
|
114
|
+
series: seriesToRender,
|
|
115
|
+
xAxis: xAxisConfig,
|
|
116
|
+
yAxis: yAxisConfig,
|
|
117
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _extends({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _extends({
|
|
118
|
+
axisId: yAxisId
|
|
119
|
+
}, yAxisVisualProps)), series == null ? void 0 : series.map(_ref4 => {
|
|
120
|
+
let {
|
|
121
|
+
id
|
|
122
|
+
} = _ref4,
|
|
123
|
+
areaPropsFromSeries = _objectWithoutPropertiesLoose(_ref4, _excluded4);
|
|
124
|
+
return /*#__PURE__*/_jsx(Area, _extends({
|
|
125
|
+
AreaComponent: AreaComponent,
|
|
126
|
+
connectNulls: connectNulls,
|
|
127
|
+
curve: curve,
|
|
128
|
+
fillOpacity: fillOpacity,
|
|
129
|
+
seriesId: id,
|
|
130
|
+
transition: transition,
|
|
131
|
+
type: type
|
|
132
|
+
}, areaPropsFromSeries), id);
|
|
133
|
+
}), showLines && (series == null ? void 0 : series.map(_ref5 => {
|
|
134
|
+
let {
|
|
135
|
+
id,
|
|
136
|
+
// Area type (don't pass to Line)
|
|
137
|
+
lineType: seriesLineType
|
|
138
|
+
} = _ref5,
|
|
139
|
+
otherPropsFromSeries = _objectWithoutPropertiesLoose(_ref5, _excluded5);
|
|
140
|
+
return /*#__PURE__*/_jsx(Line, _extends({
|
|
141
|
+
LineComponent: LineComponent,
|
|
142
|
+
connectNulls: connectNulls,
|
|
143
|
+
curve: curve,
|
|
144
|
+
seriesId: id,
|
|
145
|
+
strokeWidth: strokeWidth,
|
|
146
|
+
transition: transition,
|
|
147
|
+
type: seriesLineType != null ? seriesLineType : lineType
|
|
148
|
+
}, otherPropsFromSeries), id);
|
|
149
|
+
})), children]
|
|
150
|
+
}));
|
|
151
|
+
}));
|