@coinbase/cds-mobile-visualization 0.0.0 → 3.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +3 -0
- package/dts/chart/CartesianChart.d.ts +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 +3 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +8 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +73 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +14 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +14 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +23 -0
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +2 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +11 -0
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -0
- package/dts/sparkline/index.d.ts +6 -0
- package/dts/sparkline/index.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts +23 -0
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +184 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +28 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +11 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +39 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +31 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +16 -0
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +6 -0
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +22 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +34 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +118 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +29 -0
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts.map +1 -0
- 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 -0
- package/esm/sparkline/Counter.js +45 -0
- package/esm/sparkline/Sparkline.js +164 -0
- package/esm/sparkline/SparklineArea.js +19 -0
- package/esm/sparkline/SparklineAreaPattern.js +38 -0
- package/esm/sparkline/SparklineGradient.js +76 -0
- package/esm/sparkline/__figma__/Sparkline.figma.js +22 -0
- package/esm/sparkline/__stories__/Sparkline.stories.js +120 -0
- package/esm/sparkline/__stories__/SparklineGradient.stories.js +123 -0
- package/esm/sparkline/generateSparklineWithId.js +7 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineAccessibleView.js +75 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +307 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +116 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +131 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +99 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +82 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMinMax.js +103 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.js +104 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +57 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +124 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +80 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +109 -0
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +85 -0
- package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +501 -0
- package/esm/sparkline/sparkline-interactive/useInterruptiblePathAnimation.js +58 -0
- package/esm/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.js +37 -0
- package/esm/sparkline/sparkline-interactive/useMinMaxTransform.js +56 -0
- package/esm/sparkline/sparkline-interactive/useOpacityAnimation.js +23 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +47 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.js +34 -0
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +233 -0
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +104 -0
- package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +555 -0
- package/esm/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.js +117 -0
- package/package.json +65 -6
- package/index.js +0 -1
|
@@ -0,0 +1,164 @@
|
|
|
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 React, { forwardRef, memo, useMemo, useRef } from 'react';
|
|
3
|
+
import { Defs, G, LinearGradient, Mask, Path, Rect, Stop, Svg } from 'react-native-svg';
|
|
4
|
+
import { getAccessibleForegroundGradient } from '@coinbase/cds-common/color/getAccessibleForegroundGradient';
|
|
5
|
+
import { borderWidth } from '@coinbase/cds-common/tokens/sparkline';
|
|
6
|
+
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
7
|
+
import { getSparklineRange } from '@coinbase/cds-common/visualizations/getSparklineRange';
|
|
8
|
+
import { getSparklineTransform } from '@coinbase/cds-common/visualizations/getSparklineTransform';
|
|
9
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
10
|
+
import { generateRandomId } from '@coinbase/cds-utils';
|
|
11
|
+
import { generateSparklineAreaWithId } from './generateSparklineWithId';
|
|
12
|
+
import { SparklineAreaPattern } from './SparklineAreaPattern';
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use LineChart instead.
|
|
16
|
+
*/
|
|
17
|
+
export const Sparkline = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
18
|
+
let {
|
|
19
|
+
background,
|
|
20
|
+
color,
|
|
21
|
+
height,
|
|
22
|
+
path,
|
|
23
|
+
width,
|
|
24
|
+
yAxisScalingFactor,
|
|
25
|
+
children,
|
|
26
|
+
strokeType = 'solid',
|
|
27
|
+
fillType = 'dotted'
|
|
28
|
+
} = _ref;
|
|
29
|
+
const theme = useTheme();
|
|
30
|
+
const patternId = useRef(generateRandomId());
|
|
31
|
+
const strokeColor = color !== 'auto' ? color : getAccessibleColor({
|
|
32
|
+
background: background != null ? background : theme.color.bg,
|
|
33
|
+
foreground: 'auto',
|
|
34
|
+
usage: 'graphic'
|
|
35
|
+
});
|
|
36
|
+
const translateProps = getSparklineTransform(width, height, yAxisScalingFactor);
|
|
37
|
+
const hasChildren = !!children;
|
|
38
|
+
const useModernFill = fillType === 'gradient' || fillType === 'gradientDotted';
|
|
39
|
+
|
|
40
|
+
// Stroke gradient (for strokeType='gradient')
|
|
41
|
+
const strokeGradient = useMemo(() => {
|
|
42
|
+
if (strokeType !== 'gradient') return null;
|
|
43
|
+
return getAccessibleForegroundGradient({
|
|
44
|
+
background: background != null ? background : theme.color.bg,
|
|
45
|
+
color,
|
|
46
|
+
colorScheme: theme.activeColorScheme,
|
|
47
|
+
usage: 'graphic'
|
|
48
|
+
});
|
|
49
|
+
}, [strokeType, background, color, theme]);
|
|
50
|
+
|
|
51
|
+
// Calculate gradient coordinates for modern fills
|
|
52
|
+
const {
|
|
53
|
+
gradientY1,
|
|
54
|
+
gradientY2
|
|
55
|
+
} = useMemo(() => {
|
|
56
|
+
if (!useModernFill) return {
|
|
57
|
+
gradientY1: 0,
|
|
58
|
+
gradientY2: 0
|
|
59
|
+
};
|
|
60
|
+
if (!Number.isFinite(yAxisScalingFactor)) {
|
|
61
|
+
return {
|
|
62
|
+
gradientY1: 2,
|
|
63
|
+
gradientY2: height - 2
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const {
|
|
67
|
+
yRange
|
|
68
|
+
} = getSparklineRange({
|
|
69
|
+
height,
|
|
70
|
+
width,
|
|
71
|
+
yAxisScalingFactor
|
|
72
|
+
});
|
|
73
|
+
const pathHeight = Math.abs(yRange[0] - yRange[1]);
|
|
74
|
+
const yTranslate = height / 2 - pathHeight / 2;
|
|
75
|
+
return {
|
|
76
|
+
gradientY1: yRange[1],
|
|
77
|
+
gradientY2: height - yTranslate
|
|
78
|
+
};
|
|
79
|
+
}, [useModernFill, height, width, yAxisScalingFactor]);
|
|
80
|
+
const maskGradientId = patternId.current + "-mask-gradient";
|
|
81
|
+
const maskId = patternId.current + "-mask";
|
|
82
|
+
const defs = useMemo(() => {
|
|
83
|
+
if (!strokeGradient && !hasChildren) return null;
|
|
84
|
+
return /*#__PURE__*/_jsxs(Defs, {
|
|
85
|
+
children: [strokeGradient && /*#__PURE__*/_jsx(LinearGradient, {
|
|
86
|
+
id: "gradient",
|
|
87
|
+
x1: "0%",
|
|
88
|
+
x2: "100%",
|
|
89
|
+
y1: "0%",
|
|
90
|
+
y2: "0%",
|
|
91
|
+
children: strokeGradient.map((item, i) => /*#__PURE__*/_jsx(Stop, {
|
|
92
|
+
offset: item.offset,
|
|
93
|
+
stopColor: item.color
|
|
94
|
+
}, i + "_" + item))
|
|
95
|
+
}), hasChildren && fillType === 'dotted' && /*#__PURE__*/_jsx(SparklineAreaPattern, {
|
|
96
|
+
color: strokeColor,
|
|
97
|
+
id: patternId.current
|
|
98
|
+
}), hasChildren && fillType === 'gradient' && /*#__PURE__*/_jsxs(LinearGradient, {
|
|
99
|
+
gradientUnits: "userSpaceOnUse",
|
|
100
|
+
id: patternId.current,
|
|
101
|
+
x1: "0",
|
|
102
|
+
x2: "0",
|
|
103
|
+
y1: gradientY1,
|
|
104
|
+
y2: gradientY2,
|
|
105
|
+
children: [/*#__PURE__*/_jsx(Stop, {
|
|
106
|
+
offset: "0%",
|
|
107
|
+
stopColor: strokeColor,
|
|
108
|
+
stopOpacity: 0.3
|
|
109
|
+
}), /*#__PURE__*/_jsx(Stop, {
|
|
110
|
+
offset: "100%",
|
|
111
|
+
stopColor: strokeColor,
|
|
112
|
+
stopOpacity: 0
|
|
113
|
+
})]
|
|
114
|
+
}), hasChildren && fillType === 'gradientDotted' && /*#__PURE__*/_jsxs(_Fragment, {
|
|
115
|
+
children: [/*#__PURE__*/_jsx(SparklineAreaPattern, {
|
|
116
|
+
color: strokeColor,
|
|
117
|
+
id: patternId.current,
|
|
118
|
+
opacity: 1
|
|
119
|
+
}), /*#__PURE__*/_jsxs(LinearGradient, {
|
|
120
|
+
gradientUnits: "userSpaceOnUse",
|
|
121
|
+
id: maskGradientId,
|
|
122
|
+
x1: "0",
|
|
123
|
+
x2: "0",
|
|
124
|
+
y1: gradientY1,
|
|
125
|
+
y2: gradientY2,
|
|
126
|
+
children: [/*#__PURE__*/_jsx(Stop, {
|
|
127
|
+
offset: "0%",
|
|
128
|
+
stopColor: "white",
|
|
129
|
+
stopOpacity: 1
|
|
130
|
+
}), /*#__PURE__*/_jsx(Stop, {
|
|
131
|
+
offset: "100%",
|
|
132
|
+
stopColor: "white",
|
|
133
|
+
stopOpacity: 0
|
|
134
|
+
})]
|
|
135
|
+
}), /*#__PURE__*/_jsx(Mask, {
|
|
136
|
+
id: maskId,
|
|
137
|
+
children: /*#__PURE__*/_jsx(Rect, {
|
|
138
|
+
fill: "url(#" + maskGradientId + ")",
|
|
139
|
+
height: height,
|
|
140
|
+
width: width
|
|
141
|
+
})
|
|
142
|
+
})]
|
|
143
|
+
})]
|
|
144
|
+
});
|
|
145
|
+
}, [strokeGradient, hasChildren, fillType, strokeColor, gradientY1, gradientY2, height, width, maskGradientId, maskId]);
|
|
146
|
+
const stroke = strokeType === 'gradient' ? 'url(#gradient)' : strokeColor;
|
|
147
|
+
const shouldPlaceDefsInside = useModernFill;
|
|
148
|
+
return /*#__PURE__*/_jsxs(Svg, {
|
|
149
|
+
fill: "none",
|
|
150
|
+
height: height,
|
|
151
|
+
width: width,
|
|
152
|
+
children: [!shouldPlaceDefsInside && defs, /*#__PURE__*/_jsxs(G, _extends({}, translateProps, {
|
|
153
|
+
children: [shouldPlaceDefsInside && defs, /*#__PURE__*/_jsx(Path, {
|
|
154
|
+
ref: ref,
|
|
155
|
+
d: path,
|
|
156
|
+
stroke: stroke,
|
|
157
|
+
strokeLinecap: "round",
|
|
158
|
+
strokeLinejoin: "round",
|
|
159
|
+
strokeWidth: borderWidth
|
|
160
|
+
}), generateSparklineAreaWithId(patternId.current, children, fillType === 'gradientDotted' ? maskId : undefined)]
|
|
161
|
+
}))]
|
|
162
|
+
});
|
|
163
|
+
}));
|
|
164
|
+
Sparkline.displayName = 'Sparkline';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { forwardRef, memo } from 'react';
|
|
2
|
+
import { Path } from 'react-native-svg';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use AreaChart instead.
|
|
6
|
+
*/
|
|
7
|
+
export const SparklineArea = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
8
|
+
let {
|
|
9
|
+
area,
|
|
10
|
+
patternId,
|
|
11
|
+
maskId
|
|
12
|
+
} = _ref;
|
|
13
|
+
return /*#__PURE__*/_jsx(Path, {
|
|
14
|
+
ref: ref,
|
|
15
|
+
d: area,
|
|
16
|
+
fill: "url(#" + patternId + ")",
|
|
17
|
+
mask: maskId ? "url(#" + maskId + ")" : undefined
|
|
18
|
+
});
|
|
19
|
+
}));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Circle, G, Pattern, Rect } from 'react-native-svg';
|
|
3
|
+
import { useSparklineAreaOpacity } from '@coinbase/cds-common/visualizations/useSparklineAreaOpacity';
|
|
4
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
5
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
export const SparklineAreaPattern = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
color,
|
|
9
|
+
id,
|
|
10
|
+
opacity
|
|
11
|
+
} = _ref;
|
|
12
|
+
const {
|
|
13
|
+
activeColorScheme
|
|
14
|
+
} = useTheme();
|
|
15
|
+
const themeOpacity = useSparklineAreaOpacity(activeColorScheme);
|
|
16
|
+
const fillOpacity = opacity != null ? opacity : themeOpacity;
|
|
17
|
+
return /*#__PURE__*/_jsx(Pattern, {
|
|
18
|
+
height: "4",
|
|
19
|
+
id: id,
|
|
20
|
+
patternUnits: "userSpaceOnUse",
|
|
21
|
+
width: "4",
|
|
22
|
+
x: "0",
|
|
23
|
+
y: "0",
|
|
24
|
+
children: /*#__PURE__*/_jsxs(G, {
|
|
25
|
+
children: [/*#__PURE__*/_jsx(Rect, {
|
|
26
|
+
fill: "transparent",
|
|
27
|
+
height: "4",
|
|
28
|
+
width: "4"
|
|
29
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
30
|
+
cx: "1",
|
|
31
|
+
cy: "1",
|
|
32
|
+
fill: color,
|
|
33
|
+
fillOpacity: fillOpacity,
|
|
34
|
+
r: "1"
|
|
35
|
+
})]
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
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 React, { forwardRef, memo, useMemo, useRef } from 'react';
|
|
3
|
+
import { Defs, G, LinearGradient, Path, Stop, Svg } from 'react-native-svg';
|
|
4
|
+
import { getAccessibleForegroundGradient } from '@coinbase/cds-common/color/getAccessibleForegroundGradient';
|
|
5
|
+
import { borderWidth } from '@coinbase/cds-common/tokens/sparkline';
|
|
6
|
+
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
7
|
+
import { getSparklineTransform } from '@coinbase/cds-common/visualizations/getSparklineTransform';
|
|
8
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
9
|
+
import { generateRandomId } from '@coinbase/cds-utils';
|
|
10
|
+
import { generateSparklineAreaWithId } from './generateSparklineWithId';
|
|
11
|
+
import { SparklineAreaPattern } from './SparklineAreaPattern';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use LineChart instead.
|
|
15
|
+
*/
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export const SparklineGradient = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
18
|
+
let {
|
|
19
|
+
background,
|
|
20
|
+
color,
|
|
21
|
+
path,
|
|
22
|
+
height,
|
|
23
|
+
width,
|
|
24
|
+
yAxisScalingFactor,
|
|
25
|
+
children
|
|
26
|
+
} = _ref;
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const patternId = useRef(generateRandomId());
|
|
29
|
+
const translateProps = getSparklineTransform(width, height, yAxisScalingFactor);
|
|
30
|
+
const gradient = getAccessibleForegroundGradient({
|
|
31
|
+
background: background != null ? background : theme.color.bg,
|
|
32
|
+
color,
|
|
33
|
+
colorScheme: theme.activeColorScheme,
|
|
34
|
+
usage: 'graphic'
|
|
35
|
+
});
|
|
36
|
+
const areaColor = color !== 'auto' ? color : getAccessibleColor({
|
|
37
|
+
background: background != null ? background : theme.color.bg,
|
|
38
|
+
foreground: 'auto',
|
|
39
|
+
usage: 'graphic'
|
|
40
|
+
});
|
|
41
|
+
const hasChildren = !!children;
|
|
42
|
+
const linearGradient = useMemo(() => {
|
|
43
|
+
return /*#__PURE__*/_jsxs(Defs, {
|
|
44
|
+
children: [/*#__PURE__*/_jsx(LinearGradient, {
|
|
45
|
+
id: "gradient",
|
|
46
|
+
x1: "0%",
|
|
47
|
+
x2: "100%",
|
|
48
|
+
y1: "0%",
|
|
49
|
+
y2: "0%",
|
|
50
|
+
children: gradient.map((item, i) => /*#__PURE__*/_jsx(Stop, {
|
|
51
|
+
offset: item.offset,
|
|
52
|
+
stopColor: item.color
|
|
53
|
+
}, i + "_" + item))
|
|
54
|
+
}), hasChildren && /*#__PURE__*/_jsx(SparklineAreaPattern, {
|
|
55
|
+
color: areaColor,
|
|
56
|
+
id: patternId.current
|
|
57
|
+
})]
|
|
58
|
+
});
|
|
59
|
+
}, [areaColor, hasChildren, gradient]);
|
|
60
|
+
return /*#__PURE__*/_jsxs(Svg, {
|
|
61
|
+
fill: "none",
|
|
62
|
+
height: height,
|
|
63
|
+
width: width,
|
|
64
|
+
children: [linearGradient, /*#__PURE__*/_jsxs(G, _extends({}, translateProps, {
|
|
65
|
+
children: [/*#__PURE__*/_jsx(Path, {
|
|
66
|
+
ref: ref,
|
|
67
|
+
d: path,
|
|
68
|
+
stroke: "url(#gradient)",
|
|
69
|
+
strokeLinecap: "round",
|
|
70
|
+
strokeLinejoin: "round",
|
|
71
|
+
strokeWidth: borderWidth
|
|
72
|
+
}), generateSparklineAreaWithId(patternId.current, children)]
|
|
73
|
+
}))]
|
|
74
|
+
});
|
|
75
|
+
}));
|
|
76
|
+
SparklineGradient.displayName = 'SparklineGradient';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSparklinePath } from '@coinbase/cds-common/visualizations/useSparklinePath';
|
|
3
|
+
import { figma } from '@figma/code-connect';
|
|
4
|
+
import { Sparkline } from '../Sparkline';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
figma.connect(Sparkline, 'https://www.figma.com/design/k5CtyJccNQUGMI5bI4lJ2g/%E2%9C%A8-CDS-Components?node-id=320%3A15040', {
|
|
7
|
+
imports: ["import { Sparkline } from '@coinbase/cds-mobile-visualization';", "import { useSparklinePath } from '@coinbase/cds-common/visualizations/useSparklinePath';"],
|
|
8
|
+
example: function Example() {
|
|
9
|
+
const data = [20, 30, 5, 45, 0];
|
|
10
|
+
const path = useSparklinePath({
|
|
11
|
+
height: 200,
|
|
12
|
+
width: 200,
|
|
13
|
+
data
|
|
14
|
+
});
|
|
15
|
+
return /*#__PURE__*/_jsx(Sparkline, {
|
|
16
|
+
color: "auto",
|
|
17
|
+
height: 200,
|
|
18
|
+
path: path,
|
|
19
|
+
width: 400
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
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 React from 'react';
|
|
3
|
+
import { Dimensions } from 'react-native';
|
|
4
|
+
import { assets } from '@coinbase/cds-common/internal/data/assets';
|
|
5
|
+
import { prices, pricesWithScalingFactor } from '@coinbase/cds-common/internal/data/prices';
|
|
6
|
+
import { gutter } from '@coinbase/cds-common/tokens/sizing';
|
|
7
|
+
import { useSparklineArea } from '@coinbase/cds-common/visualizations/useSparklineArea';
|
|
8
|
+
import { useSparklinePath } from '@coinbase/cds-common/visualizations/useSparklinePath';
|
|
9
|
+
import { Cell } from '@coinbase/cds-mobile/cells/Cell';
|
|
10
|
+
import { CellMedia } from '@coinbase/cds-mobile/cells/CellMedia';
|
|
11
|
+
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
12
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
13
|
+
import { HStack } from '@coinbase/cds-mobile/layout/HStack';
|
|
14
|
+
import { VStack } from '@coinbase/cds-mobile/layout/VStack';
|
|
15
|
+
import { TextBody } from '@coinbase/cds-mobile/typography/TextBody';
|
|
16
|
+
import { TextHeadline } from '@coinbase/cds-mobile/typography/TextHeadline';
|
|
17
|
+
import { Sparkline } from '../Sparkline';
|
|
18
|
+
import { SparklineArea } from '../SparklineArea';
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
const SparklineExample = _ref => {
|
|
21
|
+
let {
|
|
22
|
+
imageUrl,
|
|
23
|
+
name,
|
|
24
|
+
symbol,
|
|
25
|
+
color
|
|
26
|
+
} = _ref;
|
|
27
|
+
const dimensions = {
|
|
28
|
+
width: 64,
|
|
29
|
+
height: 20
|
|
30
|
+
};
|
|
31
|
+
const path = useSparklinePath(_extends({}, dimensions, {
|
|
32
|
+
data: prices
|
|
33
|
+
}));
|
|
34
|
+
return /*#__PURE__*/_jsx(Cell, {
|
|
35
|
+
detail: /*#__PURE__*/_jsxs(HStack, {
|
|
36
|
+
alignItems: "center",
|
|
37
|
+
children: [/*#__PURE__*/_jsx(Sparkline, _extends({}, dimensions, {
|
|
38
|
+
color: color,
|
|
39
|
+
path: path
|
|
40
|
+
})), /*#__PURE__*/_jsxs(VStack, {
|
|
41
|
+
alignContent: "flex-end",
|
|
42
|
+
alignItems: "flex-end",
|
|
43
|
+
justifyContent: "center",
|
|
44
|
+
paddingStart: 2,
|
|
45
|
+
children: [/*#__PURE__*/_jsx(TextBody, {
|
|
46
|
+
align: "end",
|
|
47
|
+
numberOfLines: 1,
|
|
48
|
+
children: "$2,874.49"
|
|
49
|
+
}), /*#__PURE__*/_jsx(TextBody, {
|
|
50
|
+
align: "end",
|
|
51
|
+
color: "fgMuted",
|
|
52
|
+
numberOfLines: 1,
|
|
53
|
+
children: "+36.08%"
|
|
54
|
+
})]
|
|
55
|
+
})]
|
|
56
|
+
}),
|
|
57
|
+
media: /*#__PURE__*/_jsx(CellMedia, {
|
|
58
|
+
source: imageUrl,
|
|
59
|
+
title: "Title",
|
|
60
|
+
type: "image"
|
|
61
|
+
}),
|
|
62
|
+
children: /*#__PURE__*/_jsxs(VStack, {
|
|
63
|
+
justifyContent: "center",
|
|
64
|
+
children: [/*#__PURE__*/_jsx(TextHeadline, {
|
|
65
|
+
ellipsize: "tail",
|
|
66
|
+
numberOfLines: 1,
|
|
67
|
+
children: name
|
|
68
|
+
}), /*#__PURE__*/_jsx(TextBody, {
|
|
69
|
+
ellipsize: "tail",
|
|
70
|
+
numberOfLines: 1,
|
|
71
|
+
children: symbol
|
|
72
|
+
})]
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const SparklineScalingExample = props => {
|
|
77
|
+
const theme = useTheme();
|
|
78
|
+
const chartHorizontalGutter = theme.space[gutter];
|
|
79
|
+
const width = Dimensions.get('screen').width - chartHorizontalGutter * 2;
|
|
80
|
+
const dimensions = {
|
|
81
|
+
width,
|
|
82
|
+
height: 320
|
|
83
|
+
};
|
|
84
|
+
const path = useSparklinePath(_extends({}, dimensions, props));
|
|
85
|
+
const area = useSparklineArea(_extends({}, dimensions, props));
|
|
86
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
87
|
+
children: [/*#__PURE__*/_jsxs(TextHeadline, {
|
|
88
|
+
ellipsize: "tail",
|
|
89
|
+
numberOfLines: 1,
|
|
90
|
+
children: ["Scale: ", props.yAxisScalingFactor]
|
|
91
|
+
}), /*#__PURE__*/_jsx(Sparkline, _extends({}, dimensions, {
|
|
92
|
+
color: "#F7931A",
|
|
93
|
+
path: path,
|
|
94
|
+
yAxisScalingFactor: props.yAxisScalingFactor,
|
|
95
|
+
children: props.fill && /*#__PURE__*/_jsx(SparklineArea, {
|
|
96
|
+
area: area
|
|
97
|
+
})
|
|
98
|
+
}))]
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
const PressableOpacityScreen = () => {
|
|
102
|
+
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
103
|
+
children: [/*#__PURE__*/_jsx(Example, {
|
|
104
|
+
title: "Sparkline",
|
|
105
|
+
children: /*#__PURE__*/_jsxs(VStack, {
|
|
106
|
+
marginX: -2,
|
|
107
|
+
children: [/*#__PURE__*/_jsx(SparklineExample, _extends({}, assets.btc)), /*#__PURE__*/_jsx(SparklineExample, _extends({}, assets.eth)), /*#__PURE__*/_jsx(SparklineExample, _extends({}, assets.xrp)), /*#__PURE__*/_jsx(SparklineExample, _extends({}, assets.dai)), /*#__PURE__*/_jsx(SparklineExample, _extends({}, assets.sushi))]
|
|
108
|
+
})
|
|
109
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
110
|
+
title: "SparklineWithScale",
|
|
111
|
+
children: pricesWithScalingFactor.map(item => /*#__PURE__*/_jsx(SparklineScalingExample, _extends({}, item), item.yAxisScalingFactor))
|
|
112
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
113
|
+
title: "SparklineWithScaleAndFill",
|
|
114
|
+
children: pricesWithScalingFactor.map(item => /*#__PURE__*/_jsx(SparklineScalingExample, _extends({}, item, {
|
|
115
|
+
fill: true
|
|
116
|
+
}), item.yAxisScalingFactor))
|
|
117
|
+
})]
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
export default PressableOpacityScreen;
|
|
@@ -0,0 +1,123 @@
|
|
|
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 React from 'react';
|
|
3
|
+
import { Dimensions } from 'react-native';
|
|
4
|
+
import { assets } from '@coinbase/cds-common/internal/data/assets';
|
|
5
|
+
import { prices, pricesWithScalingFactor } from '@coinbase/cds-common/internal/data/prices';
|
|
6
|
+
import { gutter } from '@coinbase/cds-common/tokens/sizing';
|
|
7
|
+
import { useSparklineArea } from '@coinbase/cds-common/visualizations/useSparklineArea';
|
|
8
|
+
import { useSparklinePath } from '@coinbase/cds-common/visualizations/useSparklinePath';
|
|
9
|
+
import { Cell } from '@coinbase/cds-mobile/cells/Cell';
|
|
10
|
+
import { CellMedia } from '@coinbase/cds-mobile/cells/CellMedia';
|
|
11
|
+
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
12
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
13
|
+
import { VStack } from '@coinbase/cds-mobile/layout';
|
|
14
|
+
import { TextBody, TextHeadline } from '@coinbase/cds-mobile/typography';
|
|
15
|
+
import { SparklineArea } from '../SparklineArea';
|
|
16
|
+
import { SparklineGradient } from '../SparklineGradient';
|
|
17
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
const height = 320;
|
|
19
|
+
const SparklineGradientExample = _ref => {
|
|
20
|
+
let {
|
|
21
|
+
imageUrl,
|
|
22
|
+
name,
|
|
23
|
+
symbol,
|
|
24
|
+
color,
|
|
25
|
+
fill
|
|
26
|
+
} = _ref;
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const chartHorizontalGutter = theme.space[gutter];
|
|
29
|
+
const width = Dimensions.get('screen').width - chartHorizontalGutter * 2;
|
|
30
|
+
const dimensions = {
|
|
31
|
+
width,
|
|
32
|
+
height
|
|
33
|
+
};
|
|
34
|
+
const path = useSparklinePath(_extends({}, dimensions, {
|
|
35
|
+
data: prices
|
|
36
|
+
}));
|
|
37
|
+
const area = useSparklineArea(_extends({}, dimensions, {
|
|
38
|
+
data: prices
|
|
39
|
+
}));
|
|
40
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
41
|
+
children: [/*#__PURE__*/_jsx(Cell, {
|
|
42
|
+
media: /*#__PURE__*/_jsx(CellMedia, {
|
|
43
|
+
source: imageUrl,
|
|
44
|
+
type: "image"
|
|
45
|
+
}),
|
|
46
|
+
children: /*#__PURE__*/_jsxs(VStack, {
|
|
47
|
+
justifyContent: "center",
|
|
48
|
+
children: [/*#__PURE__*/_jsx(TextHeadline, {
|
|
49
|
+
ellipsize: "tail",
|
|
50
|
+
numberOfLines: 1,
|
|
51
|
+
children: name
|
|
52
|
+
}), /*#__PURE__*/_jsx(TextBody, {
|
|
53
|
+
ellipsize: "tail",
|
|
54
|
+
numberOfLines: 1,
|
|
55
|
+
children: symbol
|
|
56
|
+
})]
|
|
57
|
+
})
|
|
58
|
+
}), /*#__PURE__*/_jsx(SparklineGradient, _extends({}, dimensions, {
|
|
59
|
+
color: color,
|
|
60
|
+
path: path,
|
|
61
|
+
children: fill && /*#__PURE__*/_jsx(SparklineArea, {
|
|
62
|
+
area: area
|
|
63
|
+
})
|
|
64
|
+
}))]
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
const SparklineScalingExample = props => {
|
|
68
|
+
const theme = useTheme();
|
|
69
|
+
const chartHorizontalGutter = theme.space[gutter];
|
|
70
|
+
const width = Dimensions.get('screen').width - chartHorizontalGutter * 2;
|
|
71
|
+
const dimensions = {
|
|
72
|
+
width,
|
|
73
|
+
height
|
|
74
|
+
};
|
|
75
|
+
const path = useSparklinePath(_extends({}, dimensions, props));
|
|
76
|
+
const area = useSparklineArea(_extends({}, dimensions, props));
|
|
77
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
78
|
+
children: [/*#__PURE__*/_jsxs(TextHeadline, {
|
|
79
|
+
ellipsize: "tail",
|
|
80
|
+
numberOfLines: 1,
|
|
81
|
+
children: ["Scale: ", props.yAxisScalingFactor]
|
|
82
|
+
}), /*#__PURE__*/_jsx(SparklineGradient, _extends({}, dimensions, {
|
|
83
|
+
color: "#F7931A",
|
|
84
|
+
path: path,
|
|
85
|
+
yAxisScalingFactor: props.yAxisScalingFactor,
|
|
86
|
+
children: props.fill && /*#__PURE__*/_jsx(SparklineArea, {
|
|
87
|
+
area: area
|
|
88
|
+
})
|
|
89
|
+
}))]
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const PressableOpacityScreen = () => {
|
|
93
|
+
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
94
|
+
children: [/*#__PURE__*/_jsxs(Example, {
|
|
95
|
+
title: "SparklineGradient",
|
|
96
|
+
children: [/*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.btc)), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.eth)), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.ltc)), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.xrp)), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.dai)), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.sushi))]
|
|
97
|
+
}), /*#__PURE__*/_jsxs(Example, {
|
|
98
|
+
title: "SparklineGradientWithArea",
|
|
99
|
+
children: [/*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.btc, {
|
|
100
|
+
fill: true
|
|
101
|
+
})), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.eth, {
|
|
102
|
+
fill: true
|
|
103
|
+
})), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.ltc, {
|
|
104
|
+
fill: true
|
|
105
|
+
})), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.xrp, {
|
|
106
|
+
fill: true
|
|
107
|
+
})), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.dai, {
|
|
108
|
+
fill: true
|
|
109
|
+
})), /*#__PURE__*/_jsx(SparklineGradientExample, _extends({}, assets.sushi, {
|
|
110
|
+
fill: true
|
|
111
|
+
}))]
|
|
112
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
113
|
+
title: "SparklineGradientWithScale",
|
|
114
|
+
children: pricesWithScalingFactor.map(item => /*#__PURE__*/_jsx(SparklineScalingExample, _extends({}, item), item.yAxisScalingFactor))
|
|
115
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
116
|
+
title: "SparklineGradientWithAreaAndScale",
|
|
117
|
+
children: pricesWithScalingFactor.map(item => /*#__PURE__*/_jsx(SparklineScalingExample, _extends({}, item, {
|
|
118
|
+
fill: true
|
|
119
|
+
}), item.yAxisScalingFactor))
|
|
120
|
+
})]
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
export default PressableOpacityScreen;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React, { memo, useCallback } from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import chunk from 'lodash/chunk';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
const styles = StyleSheet.create({
|
|
6
|
+
container: {
|
|
7
|
+
flexDirection: 'row',
|
|
8
|
+
flex: 1,
|
|
9
|
+
position: 'absolute',
|
|
10
|
+
left: 0,
|
|
11
|
+
top: 0,
|
|
12
|
+
right: 0,
|
|
13
|
+
bottom: 0
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* SparklineAccessibleView renders an accessible view for Sparkline Chart.
|
|
19
|
+
*
|
|
20
|
+
* It chunks the sparkline data into 10 (or fewer) pieces, rendering each as a View with
|
|
21
|
+
* flex width proportional to the chunk size. The first data point in each chunk is used
|
|
22
|
+
* to generate an accessibilityLabel with the date and value.
|
|
23
|
+
*
|
|
24
|
+
* @param data - The sparkline data mapped by time period
|
|
25
|
+
* @param selectedPeriod - The currently selected time period
|
|
26
|
+
*/
|
|
27
|
+
export const SparklineAccessibleView = /*#__PURE__*/memo(function SparklineAccessibleView(_ref) {
|
|
28
|
+
let {
|
|
29
|
+
data,
|
|
30
|
+
selectedPeriod
|
|
31
|
+
} = _ref;
|
|
32
|
+
const chunkedData = data ? chunk(data[selectedPeriod], data[selectedPeriod].length / 10) : [];
|
|
33
|
+
// if the data is not evenly divisible by 10, the last chunk will be smaller than the rest
|
|
34
|
+
// so we need to combine it with the previous chunk
|
|
35
|
+
if (chunkedData.length === 11) {
|
|
36
|
+
const lastChunk = chunkedData.pop();
|
|
37
|
+
chunkedData[chunkedData.length - 1] = chunkedData[chunkedData.length - 1].concat(lastChunk != null ? lastChunk : []);
|
|
38
|
+
}
|
|
39
|
+
const getStyleByLength = useCallback(length => ({
|
|
40
|
+
flex: length
|
|
41
|
+
}), []);
|
|
42
|
+
return /*#__PURE__*/_jsx(View, {
|
|
43
|
+
style: styles.container,
|
|
44
|
+
children: chunkedData.map(dataChunk => {
|
|
45
|
+
// use the first data point in chunk for accessibility label
|
|
46
|
+
const item = dataChunk[0];
|
|
47
|
+
|
|
48
|
+
// only announce time for hour and day
|
|
49
|
+
const shouldAnnounceTime = selectedPeriod === 'hour' || selectedPeriod === 'day';
|
|
50
|
+
|
|
51
|
+
// Extract date formatting options
|
|
52
|
+
const timeOptions = {
|
|
53
|
+
hour: 'numeric',
|
|
54
|
+
minute: 'numeric',
|
|
55
|
+
hour12: true
|
|
56
|
+
};
|
|
57
|
+
const dateOptions = {
|
|
58
|
+
month: 'long',
|
|
59
|
+
day: 'numeric',
|
|
60
|
+
year: 'numeric'
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// TODO: localize date and time
|
|
64
|
+
const dateTime = item.date.toLocaleString('en-US', shouldAnnounceTime ? timeOptions : dateOptions);
|
|
65
|
+
const price = item.value.toFixed(2);
|
|
66
|
+
return /*#__PURE__*/_jsx(View, {
|
|
67
|
+
accessible: true,
|
|
68
|
+
accessibilityLabel: dateTime + ", $" + price
|
|
69
|
+
// variable width base on chunk length
|
|
70
|
+
,
|
|
71
|
+
style: getStyleByLength(dataChunk.length)
|
|
72
|
+
}, String(item.date));
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
});
|