@coinbase/cds-mobile-visualization 3.3.0 → 3.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dts/chart/CartesianChart.d.ts +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,476 @@
|
|
|
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 { memo, useCallback, useMemo } from 'react';
|
|
3
|
+
import { Image, ScrollView, StyleSheet } from 'react-native';
|
|
4
|
+
import { Circle, G } from 'react-native-svg';
|
|
5
|
+
import { assets } from '@coinbase/cds-common/internal/data/assets';
|
|
6
|
+
import { candles as btcCandles } from '@coinbase/cds-common/internal/data/candles';
|
|
7
|
+
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
8
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
9
|
+
import { Box, HStack, VStack } from '@coinbase/cds-mobile/layout';
|
|
10
|
+
import { TextLabel1, TextLabel2, TextTitle1, TextTitle2 } from '@coinbase/cds-mobile/typography';
|
|
11
|
+
import { Area } from '../area/Area';
|
|
12
|
+
import { XAxis, YAxis } from '../axis';
|
|
13
|
+
import { BarPlot } from '../bar/BarPlot';
|
|
14
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
15
|
+
import { Line } from '../line/Line';
|
|
16
|
+
import { Scrubber } from '../scrubber/Scrubber';
|
|
17
|
+
import { isCategoricalScale } from '../utils';
|
|
18
|
+
import { CartesianChart, DottedArea, GradientLine, ReferenceLine, SolidLine } from '../';
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
const defaultChartHeight = 250;
|
|
21
|
+
const LineStyles = () => {
|
|
22
|
+
const topChartData = [15, 28, 32, 44, 46, 36, 40, 45, 48, 38];
|
|
23
|
+
const upperMiddleChartData = [12, 23, 21, 29, 34, 28, 31, 38, 42, 35];
|
|
24
|
+
const lowerMiddleChartData = [8, 15, 14, 25, 20, 18, 22, 28, 24, 30];
|
|
25
|
+
const bottomChartData = [4, 8, 11, 15, 16, 14, 16, 10, 12, 14];
|
|
26
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
27
|
+
height: defaultChartHeight,
|
|
28
|
+
series: [{
|
|
29
|
+
id: 'top',
|
|
30
|
+
data: topChartData
|
|
31
|
+
}, {
|
|
32
|
+
id: 'upperMiddle',
|
|
33
|
+
data: upperMiddleChartData,
|
|
34
|
+
color: '#ef4444'
|
|
35
|
+
}, {
|
|
36
|
+
id: 'lowerMiddle',
|
|
37
|
+
data: lowerMiddleChartData,
|
|
38
|
+
color: '#f59e0b'
|
|
39
|
+
}, {
|
|
40
|
+
id: 'bottom',
|
|
41
|
+
data: bottomChartData,
|
|
42
|
+
color: '#800080'
|
|
43
|
+
}],
|
|
44
|
+
children: [/*#__PURE__*/_jsx(Line, {
|
|
45
|
+
seriesId: "top"
|
|
46
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
47
|
+
seriesId: "upperMiddle",
|
|
48
|
+
type: "dotted"
|
|
49
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
50
|
+
LineComponent: lineProps => /*#__PURE__*/_jsx(GradientLine, {
|
|
51
|
+
d: lineProps.d,
|
|
52
|
+
endColor: "#F7931A",
|
|
53
|
+
startColor: "#E3D74D",
|
|
54
|
+
stroke: lineProps.stroke,
|
|
55
|
+
strokeOpacity: lineProps.strokeOpacity,
|
|
56
|
+
strokeWidth: 4
|
|
57
|
+
}),
|
|
58
|
+
curve: "natural",
|
|
59
|
+
seriesId: "lowerMiddle"
|
|
60
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
61
|
+
showArea: true,
|
|
62
|
+
AreaComponent: DottedArea,
|
|
63
|
+
curve: "step",
|
|
64
|
+
seriesId: "bottom"
|
|
65
|
+
})]
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const MultipleChart = () => {
|
|
69
|
+
const barData = [1, 2, 3, 2, 1];
|
|
70
|
+
const lineData = [4, 3, 1, 3, 4];
|
|
71
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
72
|
+
height: defaultChartHeight,
|
|
73
|
+
series: [{
|
|
74
|
+
id: 'bar',
|
|
75
|
+
data: barData
|
|
76
|
+
}, {
|
|
77
|
+
id: 'line',
|
|
78
|
+
data: lineData
|
|
79
|
+
}],
|
|
80
|
+
children: [/*#__PURE__*/_jsx(Area, {
|
|
81
|
+
seriesId: "bar",
|
|
82
|
+
type: "dotted"
|
|
83
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
84
|
+
curve: "natural",
|
|
85
|
+
seriesId: "line"
|
|
86
|
+
})]
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const EarningsHistory = () => {
|
|
90
|
+
const theme = useTheme();
|
|
91
|
+
const CirclePlot = /*#__PURE__*/memo(_ref => {
|
|
92
|
+
let {
|
|
93
|
+
seriesId,
|
|
94
|
+
opacity = 1
|
|
95
|
+
} = _ref;
|
|
96
|
+
const {
|
|
97
|
+
getSeries,
|
|
98
|
+
getSeriesData,
|
|
99
|
+
getXScale,
|
|
100
|
+
getYScale
|
|
101
|
+
} = useCartesianChartContext();
|
|
102
|
+
const series = getSeries(seriesId);
|
|
103
|
+
const data = getSeriesData(seriesId);
|
|
104
|
+
const xScale = getXScale();
|
|
105
|
+
const yScale = getYScale(series == null ? void 0 : series.yAxisId);
|
|
106
|
+
if (!xScale || !yScale || !data || !isCategoricalScale(xScale)) return null;
|
|
107
|
+
const yScaleSize = Math.abs(yScale.range()[1] - yScale.range()[0]);
|
|
108
|
+
|
|
109
|
+
// Have circle diameter be the smaller of the x scale bandwidth or 10% of the y space available
|
|
110
|
+
const diameter = Math.min(xScale.bandwidth(), yScaleSize / 10);
|
|
111
|
+
return /*#__PURE__*/_jsx(G, {
|
|
112
|
+
children: data.map((value, index) => {
|
|
113
|
+
if (value === null || value === undefined) return null;
|
|
114
|
+
|
|
115
|
+
// Get x position from band scale - center of the band
|
|
116
|
+
const xPos = xScale(index);
|
|
117
|
+
if (xPos === undefined) return null;
|
|
118
|
+
const centerX = xPos + xScale.bandwidth() / 2;
|
|
119
|
+
|
|
120
|
+
// Get y position from value
|
|
121
|
+
const yValue = Array.isArray(value) ? value[1] : value;
|
|
122
|
+
const centerY = yScale(yValue);
|
|
123
|
+
if (centerY === undefined) return null;
|
|
124
|
+
return /*#__PURE__*/_jsx(Circle, {
|
|
125
|
+
cx: centerX,
|
|
126
|
+
cy: centerY,
|
|
127
|
+
fill: (series == null ? void 0 : series.color) || theme.color.fgPrimary,
|
|
128
|
+
opacity: opacity,
|
|
129
|
+
r: diameter / 2
|
|
130
|
+
}, seriesId + "-" + index);
|
|
131
|
+
})
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
const quarters = useMemo(() => ['Q1', 'Q2', 'Q3', 'Q4'], []);
|
|
135
|
+
const estimatedEPS = useMemo(() => [1.71, 1.82, 1.93, 2.34], []);
|
|
136
|
+
const actualEPS = useMemo(() => [1.68, 1.83, 2.01, 2.24], []);
|
|
137
|
+
const formatEarningAmount = useCallback(value => {
|
|
138
|
+
return "$" + value.toLocaleString('en-US', {
|
|
139
|
+
minimumFractionDigits: 2,
|
|
140
|
+
maximumFractionDigits: 2
|
|
141
|
+
});
|
|
142
|
+
}, []);
|
|
143
|
+
const surprisePercentage = useCallback(index => {
|
|
144
|
+
const percentage = (actualEPS[index] - estimatedEPS[index]) / estimatedEPS[index];
|
|
145
|
+
const percentageString = percentage.toLocaleString('en-US', {
|
|
146
|
+
style: 'percent',
|
|
147
|
+
minimumFractionDigits: 2,
|
|
148
|
+
maximumFractionDigits: 2
|
|
149
|
+
});
|
|
150
|
+
const prefix = percentage > 0 ? '+' : '';
|
|
151
|
+
return "" + prefix + percentageString;
|
|
152
|
+
}, [actualEPS, estimatedEPS]);
|
|
153
|
+
const styles = StyleSheet.create({
|
|
154
|
+
legendDot: {
|
|
155
|
+
width: 10,
|
|
156
|
+
height: 10,
|
|
157
|
+
borderRadius: 1000,
|
|
158
|
+
backgroundColor: theme.color.bgPositive
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const LegendItem = /*#__PURE__*/memo(_ref2 => {
|
|
162
|
+
let {
|
|
163
|
+
opacity = 1,
|
|
164
|
+
label
|
|
165
|
+
} = _ref2;
|
|
166
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
167
|
+
alignItems: "center",
|
|
168
|
+
flexDirection: "row",
|
|
169
|
+
gap: 0.5,
|
|
170
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
|
171
|
+
style: [styles.legendDot, {
|
|
172
|
+
opacity
|
|
173
|
+
}]
|
|
174
|
+
}), /*#__PURE__*/_jsx(TextLabel2, {
|
|
175
|
+
children: label
|
|
176
|
+
})]
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
180
|
+
gap: 0.5,
|
|
181
|
+
children: [/*#__PURE__*/_jsxs(CartesianChart, {
|
|
182
|
+
height: defaultChartHeight,
|
|
183
|
+
inset: {
|
|
184
|
+
top: 32,
|
|
185
|
+
bottom: 0,
|
|
186
|
+
left: 0,
|
|
187
|
+
right: 0
|
|
188
|
+
},
|
|
189
|
+
overflow: "visible",
|
|
190
|
+
series: [{
|
|
191
|
+
id: 'estimatedEPS',
|
|
192
|
+
data: estimatedEPS,
|
|
193
|
+
color: theme.color.bgPositive
|
|
194
|
+
}, {
|
|
195
|
+
id: 'actualEPS',
|
|
196
|
+
data: actualEPS,
|
|
197
|
+
color: theme.color.bgPositive
|
|
198
|
+
}],
|
|
199
|
+
xAxis: {
|
|
200
|
+
scaleType: 'band',
|
|
201
|
+
categoryPadding: 0.25
|
|
202
|
+
},
|
|
203
|
+
children: [/*#__PURE__*/_jsx(YAxis, {
|
|
204
|
+
showGrid: true,
|
|
205
|
+
position: "left",
|
|
206
|
+
requestedTickCount: 3,
|
|
207
|
+
tickLabelFormatter: formatEarningAmount
|
|
208
|
+
}), /*#__PURE__*/_jsx(XAxis, {
|
|
209
|
+
height: 20,
|
|
210
|
+
tickLabelFormatter: index => quarters[index]
|
|
211
|
+
}), /*#__PURE__*/_jsx(XAxis, {
|
|
212
|
+
height: 20,
|
|
213
|
+
tickLabelFormatter: surprisePercentage
|
|
214
|
+
}), /*#__PURE__*/_jsx(CirclePlot, {
|
|
215
|
+
opacity: 0.5,
|
|
216
|
+
seriesId: "estimatedEPS"
|
|
217
|
+
}), /*#__PURE__*/_jsx(CirclePlot, {
|
|
218
|
+
seriesId: "actualEPS"
|
|
219
|
+
})]
|
|
220
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
221
|
+
gap: 2,
|
|
222
|
+
justifyContent: "flex-end",
|
|
223
|
+
children: [/*#__PURE__*/_jsx(LegendItem, {
|
|
224
|
+
label: "Estimated EPS",
|
|
225
|
+
opacity: 0.5
|
|
226
|
+
}), /*#__PURE__*/_jsx(LegendItem, {
|
|
227
|
+
label: "Actual EPS"
|
|
228
|
+
})]
|
|
229
|
+
})]
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
const PriceWithVolume = () => {
|
|
233
|
+
const theme = useTheme();
|
|
234
|
+
const btcData = btcCandles.slice(0, 180).reverse();
|
|
235
|
+
const btcPrices = btcData.map(candle => parseFloat(candle.close));
|
|
236
|
+
const btcVolumes = btcData.map(candle => parseFloat(candle.volume));
|
|
237
|
+
const btcDates = btcData.map(candle => new Date(parseInt(candle.start) * 1000));
|
|
238
|
+
const formatPrice = useCallback(price => {
|
|
239
|
+
return "$" + price.toLocaleString('en-US', {
|
|
240
|
+
minimumFractionDigits: 2,
|
|
241
|
+
maximumFractionDigits: 2
|
|
242
|
+
});
|
|
243
|
+
}, []);
|
|
244
|
+
const formatPriceInThousands = useCallback(price => {
|
|
245
|
+
return "$" + (price / 1000).toLocaleString('en-US', {
|
|
246
|
+
minimumFractionDigits: 0,
|
|
247
|
+
maximumFractionDigits: 2
|
|
248
|
+
}) + "k";
|
|
249
|
+
}, []);
|
|
250
|
+
const formatVolume = useCallback(volume => {
|
|
251
|
+
return (volume / 1000).toFixed(2) + "K";
|
|
252
|
+
}, []);
|
|
253
|
+
const formatDate = useCallback(date => {
|
|
254
|
+
return date.toLocaleDateString('en-US', {
|
|
255
|
+
month: 'short',
|
|
256
|
+
day: 'numeric'
|
|
257
|
+
});
|
|
258
|
+
}, []);
|
|
259
|
+
const scrubberLabel = useCallback(dataIndex => {
|
|
260
|
+
return formatDate(btcDates[dataIndex]);
|
|
261
|
+
}, [btcDates, formatDate]);
|
|
262
|
+
|
|
263
|
+
// Display the last values in the header
|
|
264
|
+
const displayIndex = btcPrices.length - 1;
|
|
265
|
+
const currentPrice = btcPrices[displayIndex];
|
|
266
|
+
const currentVolume = btcVolumes[displayIndex];
|
|
267
|
+
const currentDate = btcDates[displayIndex];
|
|
268
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
269
|
+
gap: 2,
|
|
270
|
+
children: [/*#__PURE__*/_jsxs(HStack, {
|
|
271
|
+
gap: 2,
|
|
272
|
+
justifyContent: "space-between",
|
|
273
|
+
paddingX: 0,
|
|
274
|
+
children: [/*#__PURE__*/_jsxs(VStack, {
|
|
275
|
+
gap: 0,
|
|
276
|
+
children: [/*#__PURE__*/_jsx(TextTitle1, {
|
|
277
|
+
children: "Bitcoin"
|
|
278
|
+
}), /*#__PURE__*/_jsx(TextTitle2, {
|
|
279
|
+
children: formatPrice(currentPrice)
|
|
280
|
+
})]
|
|
281
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
282
|
+
gap: 2,
|
|
283
|
+
children: [/*#__PURE__*/_jsxs(VStack, {
|
|
284
|
+
alignItems: "flex-end",
|
|
285
|
+
justifyContent: "center",
|
|
286
|
+
children: [/*#__PURE__*/_jsx(TextLabel1, {
|
|
287
|
+
children: formatDate(currentDate)
|
|
288
|
+
}), /*#__PURE__*/_jsx(TextLabel2, {
|
|
289
|
+
children: formatVolume(currentVolume)
|
|
290
|
+
})]
|
|
291
|
+
}), /*#__PURE__*/_jsx(VStack, {
|
|
292
|
+
justifyContent: "center",
|
|
293
|
+
children: /*#__PURE__*/_jsx(Image, {
|
|
294
|
+
source: {
|
|
295
|
+
uri: assets.btc.imageUrl
|
|
296
|
+
},
|
|
297
|
+
style: {
|
|
298
|
+
width: theme.iconSize.l,
|
|
299
|
+
height: theme.iconSize.l,
|
|
300
|
+
borderRadius: 1000
|
|
301
|
+
}
|
|
302
|
+
})
|
|
303
|
+
})]
|
|
304
|
+
})]
|
|
305
|
+
}), /*#__PURE__*/_jsxs(CartesianChart, {
|
|
306
|
+
enableScrubbing: true,
|
|
307
|
+
height: defaultChartHeight,
|
|
308
|
+
series: [{
|
|
309
|
+
id: 'prices',
|
|
310
|
+
data: btcPrices,
|
|
311
|
+
color: assets.btc.color,
|
|
312
|
+
yAxisId: 'price'
|
|
313
|
+
}, {
|
|
314
|
+
id: 'volume',
|
|
315
|
+
data: btcVolumes,
|
|
316
|
+
color: theme.color.fgMuted,
|
|
317
|
+
yAxisId: 'volume'
|
|
318
|
+
}],
|
|
319
|
+
xAxis: {
|
|
320
|
+
scaleType: 'band'
|
|
321
|
+
},
|
|
322
|
+
yAxis: [{
|
|
323
|
+
id: 'price',
|
|
324
|
+
domain: _ref3 => {
|
|
325
|
+
let {
|
|
326
|
+
min,
|
|
327
|
+
max
|
|
328
|
+
} = _ref3;
|
|
329
|
+
return {
|
|
330
|
+
min: min * 0.9,
|
|
331
|
+
max
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}, {
|
|
335
|
+
id: 'volume',
|
|
336
|
+
range: _ref4 => {
|
|
337
|
+
let {
|
|
338
|
+
min,
|
|
339
|
+
max
|
|
340
|
+
} = _ref4;
|
|
341
|
+
return {
|
|
342
|
+
min: max - 32,
|
|
343
|
+
max
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
}],
|
|
347
|
+
children: [/*#__PURE__*/_jsx(YAxis, {
|
|
348
|
+
showGrid: true,
|
|
349
|
+
axisId: "price",
|
|
350
|
+
tickLabelFormatter: formatPriceInThousands,
|
|
351
|
+
width: 20
|
|
352
|
+
}), /*#__PURE__*/_jsx(BarPlot, {
|
|
353
|
+
seriesIds: ['volume']
|
|
354
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
355
|
+
showArea: true,
|
|
356
|
+
curve: "monotone",
|
|
357
|
+
seriesId: "prices"
|
|
358
|
+
}), /*#__PURE__*/_jsx(Scrubber, {
|
|
359
|
+
label: scrubberLabel,
|
|
360
|
+
seriesIds: ['prices']
|
|
361
|
+
})]
|
|
362
|
+
})]
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
function TradingTrends() {
|
|
366
|
+
const theme = useTheme();
|
|
367
|
+
const profitData = [34, 24, 28, -4, 8, -16, -3, 12, 24, 18, 20, 28];
|
|
368
|
+
const gains = profitData.map(value => value > 0 ? value : 0);
|
|
369
|
+
const losses = profitData.map(value => value < 0 ? value : 0);
|
|
370
|
+
const renderProfit = useCallback(value => {
|
|
371
|
+
return "$" + value + "M";
|
|
372
|
+
}, []);
|
|
373
|
+
const ThinSolidLine = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
|
|
374
|
+
strokeWidth: 1
|
|
375
|
+
})));
|
|
376
|
+
const ThickSolidLine = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
|
|
377
|
+
strokeWidth: 2
|
|
378
|
+
})));
|
|
379
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
380
|
+
height: 250,
|
|
381
|
+
series: [{
|
|
382
|
+
id: 'gains',
|
|
383
|
+
data: gains,
|
|
384
|
+
yAxisId: 'profit',
|
|
385
|
+
color: theme.color.bgPositive,
|
|
386
|
+
stackId: 'bars'
|
|
387
|
+
}, {
|
|
388
|
+
id: 'losses',
|
|
389
|
+
data: losses,
|
|
390
|
+
yAxisId: 'profit',
|
|
391
|
+
color: theme.color.bgNegative,
|
|
392
|
+
stackId: 'bars'
|
|
393
|
+
}, {
|
|
394
|
+
id: 'revenue',
|
|
395
|
+
data: [128, 118, 122, 116, 120, 114, 118, 122, 126, 130, 134, 138],
|
|
396
|
+
yAxisId: 'revenue',
|
|
397
|
+
color: theme.color.fgMuted
|
|
398
|
+
}],
|
|
399
|
+
xAxis: {
|
|
400
|
+
scaleType: 'band',
|
|
401
|
+
data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
402
|
+
},
|
|
403
|
+
yAxis: [{
|
|
404
|
+
id: 'profit',
|
|
405
|
+
range: _ref5 => {
|
|
406
|
+
let {
|
|
407
|
+
min,
|
|
408
|
+
max
|
|
409
|
+
} = _ref5;
|
|
410
|
+
return {
|
|
411
|
+
min: min,
|
|
412
|
+
max: max - 64
|
|
413
|
+
};
|
|
414
|
+
},
|
|
415
|
+
domain: {
|
|
416
|
+
min: -40,
|
|
417
|
+
max: 40
|
|
418
|
+
}
|
|
419
|
+
}, {
|
|
420
|
+
id: 'revenue',
|
|
421
|
+
range: _ref6 => {
|
|
422
|
+
let {
|
|
423
|
+
min,
|
|
424
|
+
max
|
|
425
|
+
} = _ref6;
|
|
426
|
+
return {
|
|
427
|
+
min: max - 64,
|
|
428
|
+
max
|
|
429
|
+
};
|
|
430
|
+
},
|
|
431
|
+
domain: {
|
|
432
|
+
min: 100
|
|
433
|
+
}
|
|
434
|
+
}],
|
|
435
|
+
children: [/*#__PURE__*/_jsx(YAxis, {
|
|
436
|
+
showGrid: true,
|
|
437
|
+
GridLineComponent: ThinSolidLine,
|
|
438
|
+
axisId: "profit",
|
|
439
|
+
position: "left",
|
|
440
|
+
tickLabelFormatter: renderProfit
|
|
441
|
+
}), /*#__PURE__*/_jsx(XAxis, {}), /*#__PURE__*/_jsx(ReferenceLine, {
|
|
442
|
+
LineComponent: ThickSolidLine,
|
|
443
|
+
dataY: 0,
|
|
444
|
+
yAxisId: "profit"
|
|
445
|
+
}), /*#__PURE__*/_jsx(BarPlot, {
|
|
446
|
+
seriesIds: ['gains', 'losses']
|
|
447
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
448
|
+
showArea: true,
|
|
449
|
+
curve: "monotone",
|
|
450
|
+
seriesId: "revenue"
|
|
451
|
+
})]
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
const ChartStories = () => {
|
|
455
|
+
return /*#__PURE__*/_jsx(ScrollView, {
|
|
456
|
+
children: /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
457
|
+
children: [/*#__PURE__*/_jsx(Example, {
|
|
458
|
+
title: "Line Styles",
|
|
459
|
+
children: /*#__PURE__*/_jsx(LineStyles, {})
|
|
460
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
461
|
+
title: "Multiple Types",
|
|
462
|
+
children: /*#__PURE__*/_jsx(MultipleChart, {})
|
|
463
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
464
|
+
title: "Earnings History",
|
|
465
|
+
children: /*#__PURE__*/_jsx(EarningsHistory, {})
|
|
466
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
467
|
+
title: "Price With Volume",
|
|
468
|
+
children: /*#__PURE__*/_jsx(PriceWithVolume, {})
|
|
469
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
470
|
+
title: "Trading Trends",
|
|
471
|
+
children: /*#__PURE__*/_jsx(TradingTrends, {})
|
|
472
|
+
})]
|
|
473
|
+
})
|
|
474
|
+
});
|
|
475
|
+
};
|
|
476
|
+
export default ChartStories;
|
|
@@ -0,0 +1,79 @@
|
|
|
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, GradientLine, Line, LineChart } 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(GradientLine, _extends({}, props, {
|
|
54
|
+
endColor: "#F7931A",
|
|
55
|
+
startColor: "#E3D74D",
|
|
56
|
+
strokeWidth: 4
|
|
57
|
+
})),
|
|
58
|
+
curve: "natural",
|
|
59
|
+
seriesId: "lowerMiddle"
|
|
60
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
61
|
+
showArea: true,
|
|
62
|
+
AreaComponent: DottedArea,
|
|
63
|
+
curve: "step",
|
|
64
|
+
seriesId: "bottom"
|
|
65
|
+
})]
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const ChartStories = () => {
|
|
69
|
+
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
70
|
+
children: [/*#__PURE__*/_jsx(Example, {
|
|
71
|
+
title: "Basic Line Chart",
|
|
72
|
+
children: /*#__PURE__*/_jsx(BasicLineChart, {})
|
|
73
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
74
|
+
title: "Line Styles",
|
|
75
|
+
children: /*#__PURE__*/_jsx(LineStyles, {})
|
|
76
|
+
})]
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
export default ChartStories;
|