@coinbase/cds-mobile-visualization 3.4.0-beta.4 → 3.4.0-beta.6
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 +13 -0
- package/dts/chart/CartesianChart.d.ts +57 -33
- package/dts/chart/CartesianChart.d.ts.map +1 -1
- package/dts/chart/ChartContextBridge.d.ts +28 -0
- package/dts/chart/ChartContextBridge.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +77 -34
- package/dts/chart/Path.d.ts.map +1 -1
- package/dts/chart/PeriodSelector.d.ts +1 -1
- package/dts/chart/PeriodSelector.d.ts.map +1 -1
- package/dts/chart/area/Area.d.ts +42 -27
- package/dts/chart/area/Area.d.ts.map +1 -1
- package/dts/chart/area/AreaChart.d.ts +51 -10
- package/dts/chart/area/AreaChart.d.ts.map +1 -1
- package/dts/chart/area/DottedArea.d.ts +21 -2
- package/dts/chart/area/DottedArea.d.ts.map +1 -1
- package/dts/chart/area/GradientArea.d.ts +19 -13
- package/dts/chart/area/GradientArea.d.ts.map +1 -1
- package/dts/chart/area/SolidArea.d.ts +17 -2
- package/dts/chart/area/SolidArea.d.ts.map +1 -1
- package/dts/chart/axis/Axis.d.ts +68 -78
- package/dts/chart/axis/Axis.d.ts.map +1 -1
- 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 +1 -1
- package/dts/chart/axis/XAxis.d.ts.map +1 -1
- package/dts/chart/axis/YAxis.d.ts +2 -2
- package/dts/chart/axis/YAxis.d.ts.map +1 -1
- package/dts/chart/axis/index.d.ts +1 -0
- package/dts/chart/axis/index.d.ts.map +1 -1
- package/dts/chart/bar/Bar.d.ts +16 -13
- package/dts/chart/bar/Bar.d.ts.map +1 -1
- package/dts/chart/bar/BarChart.d.ts +36 -20
- package/dts/chart/bar/BarChart.d.ts.map +1 -1
- package/dts/chart/bar/BarPlot.d.ts +2 -1
- package/dts/chart/bar/BarPlot.d.ts.map +1 -1
- package/dts/chart/bar/BarStack.d.ts +39 -48
- package/dts/chart/bar/BarStack.d.ts.map +1 -1
- package/dts/chart/bar/BarStackGroup.d.ts +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
- package/dts/chart/bar/DefaultBar.d.ts +1 -1
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
- 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 +3 -1
- package/dts/chart/index.d.ts.map +1 -1
- 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 +13 -5
- package/dts/chart/line/DottedLine.d.ts.map +1 -1
- package/dts/chart/line/Line.d.ts +62 -25
- package/dts/chart/line/Line.d.ts.map +1 -1
- package/dts/chart/line/LineChart.d.ts +43 -9
- package/dts/chart/line/LineChart.d.ts.map +1 -1
- package/dts/chart/line/ReferenceLine.d.ts +65 -22
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
- package/dts/chart/line/SolidLine.d.ts +8 -5
- package/dts/chart/line/SolidLine.d.ts.map +1 -1
- package/dts/chart/line/index.d.ts +1 -1
- package/dts/chart/line/index.d.ts.map +1 -1
- 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 +168 -41
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
- 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 +6 -3
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
- package/dts/chart/scrubber/index.d.ts +3 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -1
- package/dts/chart/text/ChartText.d.ts +151 -77
- package/dts/chart/text/ChartText.d.ts.map +1 -1
- package/dts/chart/text/{SmartChartTextGroup.d.ts → ChartTextGroup.d.ts} +9 -3
- package/dts/chart/text/ChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +1 -1
- package/dts/chart/text/index.d.ts.map +1 -1
- package/dts/chart/utils/chart.d.ts +34 -7
- package/dts/chart/utils/chart.d.ts.map +1 -1
- package/dts/chart/utils/context.d.ts +28 -7
- package/dts/chart/utils/context.d.ts.map +1 -1
- 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 +3 -0
- package/dts/chart/utils/index.d.ts.map +1 -1
- package/dts/chart/utils/path.d.ts +53 -0
- package/dts/chart/utils/path.d.ts.map +1 -1
- package/dts/chart/utils/point.d.ts +60 -1
- package/dts/chart/utils/point.d.ts.map +1 -1
- package/dts/chart/utils/scale.d.ts +91 -0
- package/dts/chart/utils/scale.d.ts.map +1 -1
- 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/esm/chart/CartesianChart.js +164 -70
- package/esm/chart/ChartContextBridge.js +148 -0
- package/esm/chart/Path.js +196 -113
- package/esm/chart/PeriodSelector.js +1 -1
- package/esm/chart/__stories__/CartesianChart.stories.js +371 -129
- package/esm/chart/__stories__/Chart.stories.js +2 -4
- package/esm/chart/area/Area.js +25 -35
- package/esm/chart/area/AreaChart.js +17 -12
- package/esm/chart/area/DottedArea.js +61 -109
- package/esm/chart/area/GradientArea.js +35 -91
- package/esm/chart/area/SolidArea.js +22 -8
- package/esm/chart/area/__stories__/AreaChart.stories.js +1 -1
- package/esm/chart/axis/Axis.js +2 -0
- package/esm/chart/axis/DefaultAxisTickLabel.js +11 -0
- package/esm/chart/axis/XAxis.js +62 -56
- package/esm/chart/axis/YAxis.js +58 -52
- package/esm/chart/axis/__stories__/Axis.stories.js +0 -1
- package/esm/chart/axis/index.js +1 -0
- package/esm/chart/bar/Bar.js +3 -1
- package/esm/chart/bar/BarChart.js +15 -37
- package/esm/chart/bar/BarPlot.js +41 -35
- package/esm/chart/bar/BarStack.js +75 -38
- package/esm/chart/bar/BarStackGroup.js +6 -16
- package/esm/chart/bar/DefaultBar.js +26 -48
- package/esm/chart/bar/DefaultBarStack.js +23 -58
- package/esm/chart/bar/__stories__/BarChart.stories.js +463 -77
- package/esm/chart/gradient/Gradient.js +53 -0
- package/esm/chart/gradient/index.js +1 -0
- package/esm/chart/index.js +3 -1
- package/esm/chart/line/DefaultReferenceLineLabel.js +66 -0
- package/esm/chart/line/DottedLine.js +29 -14
- package/esm/chart/line/Line.js +106 -67
- package/esm/chart/line/LineChart.js +20 -14
- package/esm/chart/line/ReferenceLine.js +73 -62
- package/esm/chart/line/SolidLine.js +25 -10
- package/esm/chart/line/__stories__/LineChart.stories.js +2098 -1975
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +83 -28
- package/esm/chart/line/index.js +1 -1
- 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 +130 -148
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +161 -0
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +185 -0
- package/esm/chart/scrubber/ScrubberProvider.js +46 -54
- package/esm/chart/scrubber/index.js +3 -1
- package/esm/chart/text/ChartText.js +242 -174
- package/esm/chart/text/{SmartChartTextGroup.js → ChartTextGroup.js} +6 -5
- package/esm/chart/text/index.js +1 -1
- package/esm/chart/utils/chart.js +44 -3
- package/esm/chart/utils/gradient.js +305 -0
- package/esm/chart/utils/index.js +3 -0
- package/esm/chart/utils/path.js +76 -8
- package/esm/chart/utils/point.js +116 -5
- package/esm/chart/utils/scale.js +230 -1
- package/esm/chart/utils/scrubber.js +139 -0
- package/esm/chart/utils/transition.js +221 -0
- package/package.json +11 -9
- package/dts/chart/Point.d.ts +0 -103
- package/dts/chart/Point.d.ts.map +0 -1
- package/dts/chart/line/GradientLine.d.ts +0 -45
- package/dts/chart/line/GradientLine.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +0 -75
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +0 -1
- package/dts/chart/text/SmartChartTextGroup.d.ts.map +0 -1
- package/esm/chart/Point.js +0 -111
- package/esm/chart/line/GradientLine.js +0 -62
- package/esm/chart/scrubber/ScrubberBeacon.js +0 -199
|
@@ -1,21 +1,23 @@
|
|
|
1
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';
|
|
2
|
+
import { memo, useCallback, useMemo, useState } from 'react';
|
|
3
3
|
import { Image, ScrollView, StyleSheet } from 'react-native';
|
|
4
|
-
import { Circle, G } from 'react-native-svg';
|
|
5
4
|
import { assets } from '@coinbase/cds-common/internal/data/assets';
|
|
6
5
|
import { candles as btcCandles } from '@coinbase/cds-common/internal/data/candles';
|
|
7
6
|
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
8
7
|
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
9
8
|
import { Box, HStack, VStack } from '@coinbase/cds-mobile/layout';
|
|
10
9
|
import { TextLabel1, TextLabel2, TextTitle1, TextTitle2 } from '@coinbase/cds-mobile/typography';
|
|
10
|
+
import { Circle, Group, Skia } from '@shopify/react-native-skia';
|
|
11
11
|
import { Area } from '../area/Area';
|
|
12
12
|
import { XAxis, YAxis } from '../axis';
|
|
13
13
|
import { BarPlot } from '../bar/BarPlot';
|
|
14
14
|
import { useCartesianChartContext } from '../ChartProvider';
|
|
15
15
|
import { Line } from '../line/Line';
|
|
16
|
+
import { Point } from '../point/Point';
|
|
16
17
|
import { Scrubber } from '../scrubber/Scrubber';
|
|
18
|
+
import { ChartText } from '../text';
|
|
17
19
|
import { isCategoricalScale } from '../utils';
|
|
18
|
-
import { CartesianChart, DottedArea,
|
|
20
|
+
import { CartesianChart, DottedArea, ReferenceLine, SolidLine } from '../';
|
|
19
21
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
22
|
const defaultChartHeight = 250;
|
|
21
23
|
const LineStyles = () => {
|
|
@@ -47,14 +49,9 @@ const LineStyles = () => {
|
|
|
47
49
|
seriesId: "upperMiddle",
|
|
48
50
|
type: "dotted"
|
|
49
51
|
}), /*#__PURE__*/_jsx(Line, {
|
|
50
|
-
LineComponent: lineProps => /*#__PURE__*/_jsx(
|
|
51
|
-
d: lineProps.d,
|
|
52
|
-
endColor: "#F7931A",
|
|
53
|
-
startColor: "#E3D74D",
|
|
54
|
-
stroke: lineProps.stroke,
|
|
55
|
-
strokeOpacity: lineProps.strokeOpacity,
|
|
52
|
+
LineComponent: lineProps => /*#__PURE__*/_jsx(SolidLine, _extends({}, lineProps, {
|
|
56
53
|
strokeWidth: 4
|
|
57
|
-
}),
|
|
54
|
+
})),
|
|
58
55
|
curve: "natural",
|
|
59
56
|
seriesId: "lowerMiddle"
|
|
60
57
|
}), /*#__PURE__*/_jsx(Line, {
|
|
@@ -108,7 +105,7 @@ const EarningsHistory = () => {
|
|
|
108
105
|
|
|
109
106
|
// Have circle diameter be the smaller of the x scale bandwidth or 10% of the y space available
|
|
110
107
|
const diameter = Math.min(xScale.bandwidth(), yScaleSize / 10);
|
|
111
|
-
return /*#__PURE__*/_jsx(
|
|
108
|
+
return /*#__PURE__*/_jsx(Group, {
|
|
112
109
|
children: data.map((value, index) => {
|
|
113
110
|
if (value === null || value === undefined) return null;
|
|
114
111
|
|
|
@@ -122,9 +119,9 @@ const EarningsHistory = () => {
|
|
|
122
119
|
const centerY = yScale(yValue);
|
|
123
120
|
if (centerY === undefined) return null;
|
|
124
121
|
return /*#__PURE__*/_jsx(Circle, {
|
|
122
|
+
color: (series == null ? void 0 : series.color) || theme.color.fgPrimary,
|
|
125
123
|
cx: centerX,
|
|
126
124
|
cy: centerY,
|
|
127
|
-
fill: (series == null ? void 0 : series.color) || theme.color.fgPrimary,
|
|
128
125
|
opacity: opacity,
|
|
129
126
|
r: diameter / 2
|
|
130
127
|
}, seriesId + "-" + index);
|
|
@@ -186,7 +183,6 @@ const EarningsHistory = () => {
|
|
|
186
183
|
left: 0,
|
|
187
184
|
right: 0
|
|
188
185
|
},
|
|
189
|
-
overflow: "visible",
|
|
190
186
|
series: [{
|
|
191
187
|
id: 'estimatedEPS',
|
|
192
188
|
data: estimatedEPS,
|
|
@@ -229,27 +225,24 @@ const EarningsHistory = () => {
|
|
|
229
225
|
})]
|
|
230
226
|
});
|
|
231
227
|
};
|
|
232
|
-
const
|
|
228
|
+
const btcData = btcCandles.slice(0, 180).reverse();
|
|
229
|
+
const btcPrices = btcData.map(candle => parseFloat(candle.close));
|
|
230
|
+
const btcVolumes = btcData.map(candle => parseFloat(candle.volume));
|
|
231
|
+
const btcDates = btcData.map(candle => new Date(parseInt(candle.start) * 1000));
|
|
232
|
+
const displayIndex = btcPrices.length - 1;
|
|
233
|
+
const currentPrice = btcPrices[displayIndex];
|
|
234
|
+
const currentDate = btcDates[displayIndex];
|
|
235
|
+
const PriceWithVolumeChart = /*#__PURE__*/memo(_ref3 => {
|
|
236
|
+
let {
|
|
237
|
+
onScrubberPositionChange
|
|
238
|
+
} = _ref3;
|
|
233
239
|
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
240
|
const formatPriceInThousands = useCallback(price => {
|
|
245
241
|
return "$" + (price / 1000).toLocaleString('en-US', {
|
|
246
242
|
minimumFractionDigits: 0,
|
|
247
243
|
maximumFractionDigits: 2
|
|
248
244
|
}) + "k";
|
|
249
245
|
}, []);
|
|
250
|
-
const formatVolume = useCallback(volume => {
|
|
251
|
-
return (volume / 1000).toFixed(2) + "K";
|
|
252
|
-
}, []);
|
|
253
246
|
const formatDate = useCallback(date => {
|
|
254
247
|
return date.toLocaleDateString('en-US', {
|
|
255
248
|
month: 'short',
|
|
@@ -258,110 +251,147 @@ const PriceWithVolume = () => {
|
|
|
258
251
|
}, []);
|
|
259
252
|
const scrubberLabel = useCallback(dataIndex => {
|
|
260
253
|
return formatDate(btcDates[dataIndex]);
|
|
261
|
-
}, [
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
254
|
+
}, [formatDate]);
|
|
255
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
256
|
+
enableScrubbing: true,
|
|
257
|
+
height: defaultChartHeight,
|
|
258
|
+
onScrubberPositionChange: onScrubberPositionChange,
|
|
259
|
+
series: [{
|
|
260
|
+
id: 'prices',
|
|
261
|
+
data: btcPrices,
|
|
262
|
+
color: assets.btc.color,
|
|
263
|
+
yAxisId: 'price'
|
|
264
|
+
}, {
|
|
265
|
+
id: 'volume',
|
|
266
|
+
data: btcVolumes,
|
|
267
|
+
color: theme.color.fgMuted,
|
|
268
|
+
yAxisId: 'volume'
|
|
269
|
+
}],
|
|
270
|
+
xAxis: {
|
|
271
|
+
scaleType: 'band',
|
|
272
|
+
range: _ref4 => {
|
|
273
|
+
let {
|
|
274
|
+
min,
|
|
275
|
+
max
|
|
276
|
+
} = _ref4;
|
|
277
|
+
return {
|
|
278
|
+
min,
|
|
279
|
+
max: max - 8
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
yAxis: [{
|
|
284
|
+
id: 'price',
|
|
285
|
+
domain: _ref5 => {
|
|
286
|
+
let {
|
|
287
|
+
min,
|
|
288
|
+
max
|
|
289
|
+
} = _ref5;
|
|
290
|
+
return {
|
|
291
|
+
min: min * 0.9,
|
|
292
|
+
max
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}, {
|
|
296
|
+
id: 'volume',
|
|
297
|
+
range: _ref6 => {
|
|
298
|
+
let {
|
|
299
|
+
min,
|
|
300
|
+
max
|
|
301
|
+
} = _ref6;
|
|
302
|
+
return {
|
|
303
|
+
min: max - 32,
|
|
304
|
+
max
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}],
|
|
308
|
+
children: [/*#__PURE__*/_jsx(YAxis, {
|
|
309
|
+
showGrid: true,
|
|
310
|
+
axisId: "price",
|
|
311
|
+
tickLabelFormatter: formatPriceInThousands,
|
|
312
|
+
width: 20
|
|
313
|
+
}), /*#__PURE__*/_jsx(BarPlot, {
|
|
314
|
+
seriesIds: ['volume']
|
|
315
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
316
|
+
showArea: true,
|
|
317
|
+
seriesId: "prices"
|
|
318
|
+
}), /*#__PURE__*/_jsx(Scrubber, {
|
|
319
|
+
label: scrubberLabel,
|
|
320
|
+
seriesIds: ['prices']
|
|
321
|
+
})]
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
const PriceWithVolumeHeader = /*#__PURE__*/memo(_ref7 => {
|
|
325
|
+
let {
|
|
326
|
+
currentIndex
|
|
327
|
+
} = _ref7;
|
|
328
|
+
const theme = useTheme();
|
|
329
|
+
const formatPrice = useCallback(price => {
|
|
330
|
+
return "$" + price.toLocaleString('en-US', {
|
|
331
|
+
minimumFractionDigits: 2,
|
|
332
|
+
maximumFractionDigits: 2
|
|
333
|
+
});
|
|
334
|
+
}, []);
|
|
335
|
+
const formatDate = useCallback(date => {
|
|
336
|
+
return date.toLocaleDateString('en-US', {
|
|
337
|
+
month: 'short',
|
|
338
|
+
day: 'numeric'
|
|
339
|
+
});
|
|
340
|
+
}, []);
|
|
341
|
+
const formatVolume = useCallback(volume => {
|
|
342
|
+
return (volume / 1000).toFixed(2) + "K";
|
|
343
|
+
}, []);
|
|
344
|
+
const volumeText = useMemo(() => {
|
|
345
|
+
return formatVolume(currentIndex !== undefined ? btcVolumes[currentIndex] : btcVolumes[displayIndex]);
|
|
346
|
+
}, [currentIndex, formatVolume]);
|
|
347
|
+
return /*#__PURE__*/_jsxs(HStack, {
|
|
269
348
|
gap: 2,
|
|
270
|
-
|
|
349
|
+
justifyContent: "space-between",
|
|
350
|
+
paddingX: 0,
|
|
351
|
+
children: [/*#__PURE__*/_jsxs(VStack, {
|
|
352
|
+
gap: 0,
|
|
353
|
+
children: [/*#__PURE__*/_jsx(TextTitle1, {
|
|
354
|
+
children: "Bitcoin"
|
|
355
|
+
}), /*#__PURE__*/_jsx(TextTitle2, {
|
|
356
|
+
children: formatPrice(currentPrice)
|
|
357
|
+
})]
|
|
358
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
271
359
|
gap: 2,
|
|
272
|
-
justifyContent: "space-between",
|
|
273
|
-
paddingX: 0,
|
|
274
360
|
children: [/*#__PURE__*/_jsxs(VStack, {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
})
|
|
361
|
+
alignItems: "flex-end",
|
|
362
|
+
justifyContent: "center",
|
|
363
|
+
children: [/*#__PURE__*/_jsx(TextLabel1, {
|
|
364
|
+
children: formatDate(currentDate)
|
|
365
|
+
}), /*#__PURE__*/_jsx(TextLabel2, {
|
|
366
|
+
children: volumeText
|
|
303
367
|
})]
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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']
|
|
368
|
+
}), /*#__PURE__*/_jsx(VStack, {
|
|
369
|
+
justifyContent: "center",
|
|
370
|
+
children: /*#__PURE__*/_jsx(Image, {
|
|
371
|
+
source: {
|
|
372
|
+
uri: assets.btc.imageUrl
|
|
373
|
+
},
|
|
374
|
+
style: {
|
|
375
|
+
width: theme.iconSize.l,
|
|
376
|
+
height: theme.iconSize.l,
|
|
377
|
+
borderRadius: 1000
|
|
378
|
+
}
|
|
379
|
+
})
|
|
361
380
|
})]
|
|
362
381
|
})]
|
|
363
382
|
});
|
|
364
|
-
};
|
|
383
|
+
});
|
|
384
|
+
const PriceWithVolume = /*#__PURE__*/memo(() => {
|
|
385
|
+
const [currentIndex, setCurrentIndex] = useState();
|
|
386
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
387
|
+
gap: 2,
|
|
388
|
+
children: [/*#__PURE__*/_jsx(PriceWithVolumeHeader, {
|
|
389
|
+
currentIndex: currentIndex
|
|
390
|
+
}), /*#__PURE__*/_jsx(PriceWithVolumeChart, {
|
|
391
|
+
onScrubberPositionChange: setCurrentIndex
|
|
392
|
+
})]
|
|
393
|
+
});
|
|
394
|
+
});
|
|
365
395
|
function TradingTrends() {
|
|
366
396
|
const theme = useTheme();
|
|
367
397
|
const profitData = [34, 24, 28, -4, 8, -16, -3, 12, 24, 18, 20, 28];
|
|
@@ -402,11 +432,11 @@ function TradingTrends() {
|
|
|
402
432
|
},
|
|
403
433
|
yAxis: [{
|
|
404
434
|
id: 'profit',
|
|
405
|
-
range:
|
|
435
|
+
range: _ref8 => {
|
|
406
436
|
let {
|
|
407
437
|
min,
|
|
408
438
|
max
|
|
409
|
-
} =
|
|
439
|
+
} = _ref8;
|
|
410
440
|
return {
|
|
411
441
|
min: min,
|
|
412
442
|
max: max - 64
|
|
@@ -418,11 +448,11 @@ function TradingTrends() {
|
|
|
418
448
|
}
|
|
419
449
|
}, {
|
|
420
450
|
id: 'revenue',
|
|
421
|
-
range:
|
|
451
|
+
range: _ref9 => {
|
|
422
452
|
let {
|
|
423
453
|
min,
|
|
424
454
|
max
|
|
425
|
-
} =
|
|
455
|
+
} = _ref9;
|
|
426
456
|
return {
|
|
427
457
|
min: max - 64,
|
|
428
458
|
max
|
|
@@ -446,11 +476,220 @@ function TradingTrends() {
|
|
|
446
476
|
seriesIds: ['gains', 'losses']
|
|
447
477
|
}), /*#__PURE__*/_jsx(Line, {
|
|
448
478
|
showArea: true,
|
|
449
|
-
curve: "monotone",
|
|
450
479
|
seriesId: "revenue"
|
|
451
480
|
})]
|
|
452
481
|
});
|
|
453
482
|
}
|
|
483
|
+
const UVGradient = {
|
|
484
|
+
axis: 'y',
|
|
485
|
+
stops: [{
|
|
486
|
+
offset: 0,
|
|
487
|
+
color: 'green'
|
|
488
|
+
}, {
|
|
489
|
+
offset: 3,
|
|
490
|
+
color: 'yellow'
|
|
491
|
+
}, {
|
|
492
|
+
offset: 5,
|
|
493
|
+
color: 'orange'
|
|
494
|
+
}, {
|
|
495
|
+
offset: 8,
|
|
496
|
+
color: 'red'
|
|
497
|
+
}, {
|
|
498
|
+
offset: 10,
|
|
499
|
+
color: 'purple'
|
|
500
|
+
}]
|
|
501
|
+
};
|
|
502
|
+
const PreviousData = /*#__PURE__*/memo(_ref0 => {
|
|
503
|
+
let {
|
|
504
|
+
children,
|
|
505
|
+
currentHour,
|
|
506
|
+
clipOffset = 0
|
|
507
|
+
} = _ref0;
|
|
508
|
+
// we will clip the data to the current hour
|
|
509
|
+
const {
|
|
510
|
+
drawingArea,
|
|
511
|
+
getXScale
|
|
512
|
+
} = useCartesianChartContext();
|
|
513
|
+
const xScale = getXScale();
|
|
514
|
+
const currentHourX = xScale == null ? void 0 : xScale(currentHour);
|
|
515
|
+
const clipPath = useMemo(() => {
|
|
516
|
+
if (!xScale || currentHourX === undefined) return null;
|
|
517
|
+
|
|
518
|
+
// Create a rectangle from top-left of drawing area to currentHourX on the right
|
|
519
|
+
// Apply clipOffset to left, top, and bottom edges only (NOT to currentHourX)
|
|
520
|
+
const pathString = "M " + (drawingArea.x - clipOffset) + " " + (drawingArea.y - clipOffset) + " L " + currentHourX + " " + (drawingArea.y - clipOffset) + " L " + currentHourX + " " + (drawingArea.y + drawingArea.height + clipOffset) + " L " + (drawingArea.x - clipOffset) + " " + (drawingArea.y + drawingArea.height + clipOffset) + " Z";
|
|
521
|
+
return Skia.Path.MakeFromSVGString(pathString);
|
|
522
|
+
}, [xScale, currentHourX, drawingArea, clipOffset]);
|
|
523
|
+
if (!clipPath) return null;
|
|
524
|
+
return /*#__PURE__*/_jsx(Group, {
|
|
525
|
+
clip: clipPath,
|
|
526
|
+
opacity: 0.75,
|
|
527
|
+
children: children
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
const FutureData = /*#__PURE__*/memo(_ref1 => {
|
|
531
|
+
let {
|
|
532
|
+
children,
|
|
533
|
+
currentHour,
|
|
534
|
+
clipOffset = 0
|
|
535
|
+
} = _ref1;
|
|
536
|
+
// we will clip the data from the current hour to the right edge
|
|
537
|
+
const {
|
|
538
|
+
drawingArea,
|
|
539
|
+
getXScale
|
|
540
|
+
} = useCartesianChartContext();
|
|
541
|
+
const xScale = getXScale();
|
|
542
|
+
const currentHourX = xScale == null ? void 0 : xScale(currentHour);
|
|
543
|
+
const clipPath = useMemo(() => {
|
|
544
|
+
if (!xScale || currentHourX === undefined) return null;
|
|
545
|
+
|
|
546
|
+
// Create a rectangle from currentHourX to right edge of drawing area
|
|
547
|
+
// Apply clipOffset to top, bottom, and right, but NOT left (currentHourX)
|
|
548
|
+
const pathString = "M " + currentHourX + " " + (drawingArea.y - clipOffset) + " L " + (drawingArea.x + drawingArea.width + clipOffset) + " " + (drawingArea.y - clipOffset) + " L " + (drawingArea.x + drawingArea.width + clipOffset) + " " + (drawingArea.y + drawingArea.height + clipOffset) + " L " + currentHourX + " " + (drawingArea.y + drawingArea.height + clipOffset) + " Z";
|
|
549
|
+
return Skia.Path.MakeFromSVGString(pathString);
|
|
550
|
+
}, [xScale, currentHourX, drawingArea, clipOffset]);
|
|
551
|
+
if (!clipPath) return null;
|
|
552
|
+
return /*#__PURE__*/_jsx(Group, {
|
|
553
|
+
clip: clipPath,
|
|
554
|
+
children: children
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
const ScatterplotWithCustomLabels = /*#__PURE__*/memo(() => {
|
|
558
|
+
const theme = useTheme();
|
|
559
|
+
const dataPoints = useMemo(() => [{
|
|
560
|
+
x: 12,
|
|
561
|
+
y: 34,
|
|
562
|
+
label: 'A',
|
|
563
|
+
color: theme.color.accentBoldBlue
|
|
564
|
+
}, {
|
|
565
|
+
x: 28,
|
|
566
|
+
y: 67,
|
|
567
|
+
label: 'B',
|
|
568
|
+
color: theme.color.accentBoldBlue
|
|
569
|
+
}, {
|
|
570
|
+
x: 45,
|
|
571
|
+
y: 23,
|
|
572
|
+
label: 'C',
|
|
573
|
+
color: theme.color.accentBoldBlue
|
|
574
|
+
}, {
|
|
575
|
+
x: 67,
|
|
576
|
+
y: 89,
|
|
577
|
+
label: 'D',
|
|
578
|
+
color: theme.color.bgPositive
|
|
579
|
+
}, {
|
|
580
|
+
x: 82,
|
|
581
|
+
y: 76,
|
|
582
|
+
label: 'E',
|
|
583
|
+
color: theme.color.bgPositive
|
|
584
|
+
}, {
|
|
585
|
+
x: 34,
|
|
586
|
+
y: 91,
|
|
587
|
+
label: 'F',
|
|
588
|
+
color: theme.color.bgPositive
|
|
589
|
+
}, {
|
|
590
|
+
x: 56,
|
|
591
|
+
y: 45,
|
|
592
|
+
label: 'G',
|
|
593
|
+
color: theme.color.bgPositive
|
|
594
|
+
}, {
|
|
595
|
+
x: 19,
|
|
596
|
+
y: 12,
|
|
597
|
+
label: 'H',
|
|
598
|
+
color: theme.color.fgWarning
|
|
599
|
+
}, {
|
|
600
|
+
x: 73,
|
|
601
|
+
y: 28,
|
|
602
|
+
label: 'I',
|
|
603
|
+
color: theme.color.fgWarning
|
|
604
|
+
}, {
|
|
605
|
+
x: 91,
|
|
606
|
+
y: 54,
|
|
607
|
+
label: 'J',
|
|
608
|
+
color: theme.color.fgWarning
|
|
609
|
+
}, {
|
|
610
|
+
x: 15,
|
|
611
|
+
y: 58,
|
|
612
|
+
label: 'K',
|
|
613
|
+
color: theme.color.fgPrimary
|
|
614
|
+
}, {
|
|
615
|
+
x: 39,
|
|
616
|
+
y: 72,
|
|
617
|
+
label: 'L',
|
|
618
|
+
color: theme.color.fgPrimary
|
|
619
|
+
}, {
|
|
620
|
+
x: 88,
|
|
621
|
+
y: 15,
|
|
622
|
+
label: 'M',
|
|
623
|
+
color: theme.color.fgPrimary
|
|
624
|
+
}, {
|
|
625
|
+
x: 52,
|
|
626
|
+
y: 82,
|
|
627
|
+
label: 'N',
|
|
628
|
+
color: theme.color.fgPrimary
|
|
629
|
+
}], [theme]);
|
|
630
|
+
|
|
631
|
+
// Calculate domain based on data
|
|
632
|
+
const xValues = useMemo(() => dataPoints.map(p => p.x), [dataPoints]);
|
|
633
|
+
const yValues = useMemo(() => dataPoints.map(p => p.y), [dataPoints]);
|
|
634
|
+
const xMin = Math.min(...xValues);
|
|
635
|
+
const xMax = Math.max(...xValues);
|
|
636
|
+
const yMin = Math.min(...yValues);
|
|
637
|
+
const yMax = Math.max(...yValues);
|
|
638
|
+
|
|
639
|
+
// Custom label component that places labels to the top-right
|
|
640
|
+
const TopRightPointLabel = useCallback(_ref10 => {
|
|
641
|
+
let {
|
|
642
|
+
x,
|
|
643
|
+
y,
|
|
644
|
+
offset = 0,
|
|
645
|
+
children
|
|
646
|
+
} = _ref10;
|
|
647
|
+
return /*#__PURE__*/_jsx(ChartText, {
|
|
648
|
+
font: "label1",
|
|
649
|
+
fontWeight: 600,
|
|
650
|
+
horizontalAlignment: "left",
|
|
651
|
+
verticalAlignment: "bottom",
|
|
652
|
+
x: x + offset,
|
|
653
|
+
y: y - offset,
|
|
654
|
+
children: children
|
|
655
|
+
});
|
|
656
|
+
}, []);
|
|
657
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
658
|
+
height: 300,
|
|
659
|
+
xAxis: {
|
|
660
|
+
domain: {
|
|
661
|
+
min: xMin,
|
|
662
|
+
max: xMax
|
|
663
|
+
},
|
|
664
|
+
domainLimit: 'nice'
|
|
665
|
+
},
|
|
666
|
+
yAxis: {
|
|
667
|
+
domain: {
|
|
668
|
+
min: yMin,
|
|
669
|
+
max: yMax
|
|
670
|
+
},
|
|
671
|
+
domainLimit: 'nice'
|
|
672
|
+
},
|
|
673
|
+
children: [/*#__PURE__*/_jsx(XAxis, {
|
|
674
|
+
showGrid: true,
|
|
675
|
+
showLine: true,
|
|
676
|
+
showTickMarks: true
|
|
677
|
+
}), /*#__PURE__*/_jsx(YAxis, {
|
|
678
|
+
showGrid: true,
|
|
679
|
+
showLine: true,
|
|
680
|
+
showTickMarks: true,
|
|
681
|
+
position: "left"
|
|
682
|
+
}), dataPoints.map((point, index) => /*#__PURE__*/_jsx(Point, {
|
|
683
|
+
LabelComponent: TopRightPointLabel,
|
|
684
|
+
dataX: point.x,
|
|
685
|
+
dataY: point.y,
|
|
686
|
+
fill: point.color,
|
|
687
|
+
label: point.label,
|
|
688
|
+
labelOffset: 8,
|
|
689
|
+
radius: 5
|
|
690
|
+
}, index))]
|
|
691
|
+
});
|
|
692
|
+
});
|
|
454
693
|
const ChartStories = () => {
|
|
455
694
|
return /*#__PURE__*/_jsx(ScrollView, {
|
|
456
695
|
children: /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
@@ -469,6 +708,9 @@ const ChartStories = () => {
|
|
|
469
708
|
}), /*#__PURE__*/_jsx(Example, {
|
|
470
709
|
title: "Trading Trends",
|
|
471
710
|
children: /*#__PURE__*/_jsx(TradingTrends, {})
|
|
711
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
712
|
+
title: "Scatterplot with Custom Labels",
|
|
713
|
+
children: /*#__PURE__*/_jsx(ScatterplotWithCustomLabels, {})
|
|
472
714
|
})]
|
|
473
715
|
})
|
|
474
716
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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
2
|
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
3
|
-
import { CartesianChart, DottedArea,
|
|
3
|
+
import { CartesianChart, DottedArea, Line, LineChart, SolidLine } from '../';
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
const defaultChartHeight = 250;
|
|
6
6
|
const BasicLineChart = () => {
|
|
@@ -50,9 +50,7 @@ const LineStyles = () => {
|
|
|
50
50
|
seriesId: "upperMiddle",
|
|
51
51
|
type: "dotted"
|
|
52
52
|
}), /*#__PURE__*/_jsx(Line, {
|
|
53
|
-
LineComponent: props => /*#__PURE__*/_jsx(
|
|
54
|
-
endColor: "#F7931A",
|
|
55
|
-
startColor: "#E3D74D",
|
|
53
|
+
LineComponent: props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
|
|
56
54
|
strokeWidth: 4
|
|
57
55
|
})),
|
|
58
56
|
curve: "natural",
|