@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,82 @@
|
|
|
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, { memo, useMemo } from 'react';
|
|
3
|
+
import { Animated, StyleSheet } from 'react-native';
|
|
4
|
+
import { useDateLookup } from '@coinbase/cds-common/visualizations/useDateLookup';
|
|
5
|
+
import { useLayout } from '@coinbase/cds-mobile/hooks/useLayout';
|
|
6
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
7
|
+
import { TextLabel2 } from '@coinbase/cds-mobile/typography';
|
|
8
|
+
import times from 'lodash/times';
|
|
9
|
+
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const numberOfLabels = 5;
|
|
12
|
+
const styles = StyleSheet.create({
|
|
13
|
+
wrapper: {
|
|
14
|
+
flexDirection: 'row',
|
|
15
|
+
justifyContent: 'space-between',
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
top: 0,
|
|
18
|
+
left: 0,
|
|
19
|
+
right: 0,
|
|
20
|
+
zIndex: 1
|
|
21
|
+
},
|
|
22
|
+
label: {
|
|
23
|
+
width: 100 / numberOfLabels + "%"
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const SparklineInteractiveMarkerDate = /*#__PURE__*/memo(_ref => {
|
|
27
|
+
let {
|
|
28
|
+
getFormattedDate
|
|
29
|
+
} = _ref;
|
|
30
|
+
const [label, onLayout] = useLayout();
|
|
31
|
+
const x = useMemo(() => {
|
|
32
|
+
return label.x + label.width / 2;
|
|
33
|
+
}, [label.width, label.x]);
|
|
34
|
+
return /*#__PURE__*/_jsx(TextLabel2, {
|
|
35
|
+
align: "center",
|
|
36
|
+
color: "fgMuted",
|
|
37
|
+
onLayout: onLayout,
|
|
38
|
+
paddingTop: 3,
|
|
39
|
+
style: styles.label,
|
|
40
|
+
children: getFormattedDate(x)
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
function SparklineInteractiveMarkerDatesWithGeneric(_ref2) {
|
|
44
|
+
let {
|
|
45
|
+
formatDate,
|
|
46
|
+
selectedPeriod,
|
|
47
|
+
getMarker,
|
|
48
|
+
timePeriodGutter
|
|
49
|
+
} = _ref2;
|
|
50
|
+
const {
|
|
51
|
+
markerOpacity
|
|
52
|
+
} = useSparklineInteractiveContext();
|
|
53
|
+
const theme = useTheme();
|
|
54
|
+
const getFormattedDate = useDateLookup({
|
|
55
|
+
getMarker,
|
|
56
|
+
formatDate,
|
|
57
|
+
selectedPeriod
|
|
58
|
+
});
|
|
59
|
+
const paddingHorizontalStyle = useMemo(() => {
|
|
60
|
+
const localStyle = {};
|
|
61
|
+
if (timePeriodGutter) {
|
|
62
|
+
localStyle.paddingHorizontal = theme.space[timePeriodGutter];
|
|
63
|
+
}
|
|
64
|
+
return localStyle;
|
|
65
|
+
}, [theme.space, timePeriodGutter]);
|
|
66
|
+
const rootStyle = useMemo(() => {
|
|
67
|
+
return _extends({}, styles.wrapper, {
|
|
68
|
+
opacity: markerOpacity,
|
|
69
|
+
backgroundColor: theme.color.bg
|
|
70
|
+
}, paddingHorizontalStyle);
|
|
71
|
+
}, [markerOpacity, paddingHorizontalStyle, theme.color.bg]);
|
|
72
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
73
|
+
pointerEvents: "none",
|
|
74
|
+
style: rootStyle,
|
|
75
|
+
children: times(numberOfLabels).map((_, i) => {
|
|
76
|
+
return /*#__PURE__*/_jsx(SparklineInteractiveMarkerDate, {
|
|
77
|
+
getFormattedDate: getFormattedDate
|
|
78
|
+
}, i);
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export const SparklineInteractiveMarkerDates = /*#__PURE__*/memo(SparklineInteractiveMarkerDatesWithGeneric);
|
|
@@ -0,0 +1,103 @@
|
|
|
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, { memo, useCallback, useMemo, useRef } from 'react';
|
|
3
|
+
import { Animated, StyleSheet } from 'react-native';
|
|
4
|
+
import { useLayout } from '@coinbase/cds-mobile/hooks/useLayout';
|
|
5
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
6
|
+
import { TextLabel2 } from '@coinbase/cds-mobile/typography';
|
|
7
|
+
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
8
|
+
import { useMinMaxTransform } from './useMinMaxTransform';
|
|
9
|
+
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const styles = StyleSheet.create({
|
|
12
|
+
outer: {
|
|
13
|
+
width: '100%',
|
|
14
|
+
alignItems: 'center'
|
|
15
|
+
},
|
|
16
|
+
caption: {
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
left: 0,
|
|
19
|
+
top: 0
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const SparklineInteractiveMinMaxContent = /*#__PURE__*/memo(_ref => {
|
|
23
|
+
let {
|
|
24
|
+
x,
|
|
25
|
+
children
|
|
26
|
+
} = _ref;
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const [minMaxLayout, onMinMaxLayout] = useLayout();
|
|
29
|
+
const opacity = useRef(new Animated.Value(0)).current;
|
|
30
|
+
const transform = useRef(new Animated.ValueXY({
|
|
31
|
+
x: 0,
|
|
32
|
+
y: 0
|
|
33
|
+
})).current;
|
|
34
|
+
useMinMaxTransform({
|
|
35
|
+
minMaxLayout,
|
|
36
|
+
x,
|
|
37
|
+
transform,
|
|
38
|
+
opacity
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Only do the layout if there is a new child.
|
|
42
|
+
// This prevents jitter in the case where children is
|
|
43
|
+
// set to undefined, then returned to the previous value,
|
|
44
|
+
// as is the case for privacy mode (where we hide the value)
|
|
45
|
+
const onLayout = useCallback(event => {
|
|
46
|
+
if (!children) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
return onMinMaxLayout(event);
|
|
50
|
+
}, [onMinMaxLayout, children]);
|
|
51
|
+
const rootStyle = useMemo(() => {
|
|
52
|
+
return _extends({}, styles.caption, {
|
|
53
|
+
height: theme.lineHeight.label2,
|
|
54
|
+
opacity,
|
|
55
|
+
transform: transform.getTranslateTransform()
|
|
56
|
+
});
|
|
57
|
+
}, [opacity, theme.lineHeight.label2, transform]);
|
|
58
|
+
const textLabelStyle = useMemo(() => {
|
|
59
|
+
return _extends({}, styles.caption, {
|
|
60
|
+
backgroundColor: theme.color.bg
|
|
61
|
+
});
|
|
62
|
+
}, [theme.color.bg]);
|
|
63
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
64
|
+
pointerEvents: "none",
|
|
65
|
+
style: rootStyle,
|
|
66
|
+
children: /*#__PURE__*/_jsx(TextLabel2, {
|
|
67
|
+
color: "fgMuted",
|
|
68
|
+
onLayout: onLayout,
|
|
69
|
+
padding: 0,
|
|
70
|
+
style: textLabelStyle,
|
|
71
|
+
children: children
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
export const SparklineInteractiveMinMax = /*#__PURE__*/memo(_ref2 => {
|
|
76
|
+
let {
|
|
77
|
+
formatMinMaxLabel,
|
|
78
|
+
dataPoint,
|
|
79
|
+
xFunction
|
|
80
|
+
} = _ref2;
|
|
81
|
+
const theme = useTheme();
|
|
82
|
+
const {
|
|
83
|
+
minMaxOpacity
|
|
84
|
+
} = useSparklineInteractiveContext();
|
|
85
|
+
const {
|
|
86
|
+
SparklineInteractiveMinMaxLabelHeight
|
|
87
|
+
} = useSparklineInteractiveConstants({});
|
|
88
|
+
const rootStyle = useMemo(() => {
|
|
89
|
+
return _extends({}, styles.outer, {
|
|
90
|
+
opacity: minMaxOpacity,
|
|
91
|
+
backgroundColor: theme.color.bg,
|
|
92
|
+
height: SparklineInteractiveMinMaxLabelHeight
|
|
93
|
+
});
|
|
94
|
+
}, [SparklineInteractiveMinMaxLabelHeight, minMaxOpacity, theme.color.bg]);
|
|
95
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
96
|
+
pointerEvents: "none",
|
|
97
|
+
style: rootStyle,
|
|
98
|
+
children: !!dataPoint && /*#__PURE__*/_jsx(SparklineInteractiveMinMaxContent, {
|
|
99
|
+
x: xFunction(dataPoint.date),
|
|
100
|
+
children: formatMinMaxLabel(dataPoint.value)
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { Animated as RNAnimated, Platform, View } from 'react-native';
|
|
3
|
+
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
4
|
+
import Animated, { runOnJS } from 'react-native-reanimated';
|
|
5
|
+
import { Haptics } from '@coinbase/cds-mobile/utils/haptics';
|
|
6
|
+
import { noop } from '@coinbase/cds-utils';
|
|
7
|
+
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
8
|
+
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
const {
|
|
11
|
+
lightImpact
|
|
12
|
+
} = Haptics;
|
|
13
|
+
// Generics do not work with React.memo or forwardRef
|
|
14
|
+
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref/58473012
|
|
15
|
+
export const SparklineInteractivePanGestureHandler = function SparklineInteractivePanGestureHandler(_ref) {
|
|
16
|
+
let {
|
|
17
|
+
onScrubEnd = noop,
|
|
18
|
+
onScrubStart = noop,
|
|
19
|
+
onScrub = noop,
|
|
20
|
+
getMarker,
|
|
21
|
+
selectedPeriod,
|
|
22
|
+
children,
|
|
23
|
+
disabled,
|
|
24
|
+
allowOverflowGestures
|
|
25
|
+
} = _ref;
|
|
26
|
+
const {
|
|
27
|
+
markerXPosition,
|
|
28
|
+
markerGestureState,
|
|
29
|
+
animateMarkerIn,
|
|
30
|
+
animateMarkerOut,
|
|
31
|
+
animateMinMaxIn,
|
|
32
|
+
animateMinxMaxOut,
|
|
33
|
+
animateHoverDateIn,
|
|
34
|
+
animateHoverDateOut
|
|
35
|
+
} = useSparklineInteractiveContext();
|
|
36
|
+
const {
|
|
37
|
+
chartVerticalLineWidth,
|
|
38
|
+
endX,
|
|
39
|
+
startX
|
|
40
|
+
} = useSparklineInteractiveConstants({});
|
|
41
|
+
const handleOnStartJsThread = useCallback(() => {
|
|
42
|
+
void lightImpact();
|
|
43
|
+
onScrubStart();
|
|
44
|
+
RNAnimated.parallel([animateMarkerIn, animateMinxMaxOut, animateHoverDateIn]).start();
|
|
45
|
+
}, [animateHoverDateIn, animateMarkerIn, animateMinxMaxOut, onScrubStart]);
|
|
46
|
+
const handleOnUpdateJsThread = useCallback(() => {
|
|
47
|
+
const dataPoint = getMarker(markerXPosition.value);
|
|
48
|
+
if (dataPoint) {
|
|
49
|
+
onScrub({
|
|
50
|
+
point: dataPoint,
|
|
51
|
+
period: selectedPeriod
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}, [getMarker, markerXPosition.value, onScrub, selectedPeriod]);
|
|
55
|
+
const handleOnEndOrCancelledJsThread = useCallback(() => {
|
|
56
|
+
onScrubEnd();
|
|
57
|
+
RNAnimated.parallel([animateMarkerOut, animateMinMaxIn, animateHoverDateOut]).start(_ref2 => {
|
|
58
|
+
let {
|
|
59
|
+
finished
|
|
60
|
+
} = _ref2;
|
|
61
|
+
if (finished) {
|
|
62
|
+
markerXPosition.value = -1;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}, [animateHoverDateOut, animateMarkerOut, animateMinMaxIn, markerXPosition, onScrubEnd]);
|
|
66
|
+
const handleOnEndJsThread = useCallback(() => {
|
|
67
|
+
void Haptics.lightImpact();
|
|
68
|
+
handleOnEndOrCancelledJsThread();
|
|
69
|
+
}, [handleOnEndOrCancelledJsThread]);
|
|
70
|
+
if (disabled) {
|
|
71
|
+
return /*#__PURE__*/_jsx(View, {
|
|
72
|
+
children: children
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const longPressGesture = Gesture.Pan().activateAfterLongPress(110).shouldCancelWhenOutside(!allowOverflowGestures).onStart(function onStart(event) {
|
|
76
|
+
runOnJS(handleOnStartJsThread)();
|
|
77
|
+
markerGestureState.value = 1;
|
|
78
|
+
|
|
79
|
+
// Android does not trigger onUpdate when the gesture starts. This achieves consistent behavior across both iOS and Android
|
|
80
|
+
if (Platform.OS === 'android') {
|
|
81
|
+
const newMarkerXPosition = Math.min(endX, Math.max(startX, event.x - chartVerticalLineWidth / 2));
|
|
82
|
+
markerXPosition.value = newMarkerXPosition;
|
|
83
|
+
runOnJS(handleOnUpdateJsThread)();
|
|
84
|
+
}
|
|
85
|
+
}).onUpdate(function onUpdate(event) {
|
|
86
|
+
const newMarkerXPosition = Math.min(endX, Math.max(startX, event.x - chartVerticalLineWidth / 2));
|
|
87
|
+
markerXPosition.value = newMarkerXPosition;
|
|
88
|
+
if (markerGestureState.value === 1) {
|
|
89
|
+
runOnJS(handleOnUpdateJsThread)();
|
|
90
|
+
}
|
|
91
|
+
}).onEnd(function onEnd() {
|
|
92
|
+
markerGestureState.value = 0;
|
|
93
|
+
runOnJS(handleOnEndJsThread)();
|
|
94
|
+
}).onTouchesCancelled(function onTouchesCancelled() {
|
|
95
|
+
markerGestureState.value = 0;
|
|
96
|
+
runOnJS(handleOnEndOrCancelledJsThread)();
|
|
97
|
+
});
|
|
98
|
+
return /*#__PURE__*/_jsx(GestureDetector, {
|
|
99
|
+
gesture: longPressGesture,
|
|
100
|
+
children: /*#__PURE__*/_jsx(Animated.View, {
|
|
101
|
+
children: children
|
|
102
|
+
})
|
|
103
|
+
});
|
|
104
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React, { memo, useCallback, useRef } from 'react';
|
|
2
|
+
import { SparklineInteractiveAnimatedPath } from './SparklineInteractiveAnimatedPath';
|
|
3
|
+
import { SparklineInteractiveTimeseriesPaths } from './SparklineInteractiveTimeseriesPaths';
|
|
4
|
+
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
5
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
function SparklineInteractivePathsWithGeneric(_ref) {
|
|
7
|
+
let {
|
|
8
|
+
showHoverData,
|
|
9
|
+
fill,
|
|
10
|
+
fillType = 'gradient',
|
|
11
|
+
path,
|
|
12
|
+
area,
|
|
13
|
+
selectedPeriod,
|
|
14
|
+
yAxisScalingFactor,
|
|
15
|
+
strokeColor,
|
|
16
|
+
hoverData,
|
|
17
|
+
compact
|
|
18
|
+
} = _ref;
|
|
19
|
+
// Map 'dotted' to 'gradientDotted' for Sparkline
|
|
20
|
+
const sparklineFillType = fillType === 'dotted' ? 'gradientDotted' : 'gradient';
|
|
21
|
+
const hoverPathRef = useRef(undefined);
|
|
22
|
+
const hoverAreaRef = useRef(undefined);
|
|
23
|
+
const shouldShowFill = !!fill;
|
|
24
|
+
const {
|
|
25
|
+
chartWidth,
|
|
26
|
+
chartHeight
|
|
27
|
+
} = useSparklineInteractiveConstants({
|
|
28
|
+
compact
|
|
29
|
+
});
|
|
30
|
+
const handleMultiTimeseriesRender = useCallback(_ref2 => {
|
|
31
|
+
let {
|
|
32
|
+
area: timeseriesArea,
|
|
33
|
+
path: timeseriesPath
|
|
34
|
+
} = _ref2;
|
|
35
|
+
hoverPathRef.current = timeseriesPath;
|
|
36
|
+
hoverAreaRef.current = timeseriesArea;
|
|
37
|
+
}, []);
|
|
38
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
39
|
+
children: [!showHoverData && /*#__PURE__*/_jsx(SparklineInteractiveAnimatedPath, {
|
|
40
|
+
area: shouldShowFill ? area : undefined,
|
|
41
|
+
color: strokeColor,
|
|
42
|
+
d: path,
|
|
43
|
+
fillType: sparklineFillType,
|
|
44
|
+
initialArea: hoverAreaRef.current,
|
|
45
|
+
initialPath: hoverPathRef.current,
|
|
46
|
+
selectedPeriod: selectedPeriod,
|
|
47
|
+
yAxisScalingFactor: yAxisScalingFactor
|
|
48
|
+
}), !!showHoverData && /*#__PURE__*/_jsx(SparklineInteractiveTimeseriesPaths, {
|
|
49
|
+
data: hoverData == null ? void 0 : hoverData[selectedPeriod],
|
|
50
|
+
height: chartHeight,
|
|
51
|
+
initialPath: path,
|
|
52
|
+
onRender: handleMultiTimeseriesRender,
|
|
53
|
+
width: chartWidth
|
|
54
|
+
})]
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export const SparklineInteractivePaths = /*#__PURE__*/memo(SparklineInteractivePathsWithGeneric);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, { memo, useCallback, useMemo } from 'react';
|
|
2
|
+
import { ScrollView, StyleSheet } from 'react-native';
|
|
3
|
+
import { periodLabelMap } from '@coinbase/cds-common/tokens/sparkline';
|
|
4
|
+
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
5
|
+
import { useHorizontallyScrollingPressables } from '@coinbase/cds-mobile/hooks/useHorizontallyScrollingPressables';
|
|
6
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
7
|
+
import { Box } from '@coinbase/cds-mobile/layout/Box';
|
|
8
|
+
import { HStack } from '@coinbase/cds-mobile/layout/HStack';
|
|
9
|
+
import { OverflowGradient } from '@coinbase/cds-mobile/layout/OverflowGradient';
|
|
10
|
+
import { Pressable } from '@coinbase/cds-mobile/system/Pressable';
|
|
11
|
+
import { TextLabel1 } from '@coinbase/cds-mobile/typography';
|
|
12
|
+
import { Haptics } from '@coinbase/cds-mobile/utils/haptics';
|
|
13
|
+
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
function SparklineInteractivePeriodWithGeneric(_ref) {
|
|
16
|
+
var _periodLabelMap$perio;
|
|
17
|
+
let {
|
|
18
|
+
period,
|
|
19
|
+
selectedPeriod,
|
|
20
|
+
setSelectedPeriod,
|
|
21
|
+
getLayoutHandler,
|
|
22
|
+
color
|
|
23
|
+
} = _ref;
|
|
24
|
+
const isSelected = period.value === selectedPeriod;
|
|
25
|
+
const periodLabel = (_periodLabelMap$perio = periodLabelMap[period.label]) != null ? _periodLabelMap$perio : period.label;
|
|
26
|
+
const periodHint = useMemo(() => isSelected ? "Currently showing data for the " + periodLabel + " timeframe" : "Show data for the " + periodLabel + " timeframe", [isSelected, periodLabel]);
|
|
27
|
+
const handleOnPress = useCallback(() => {
|
|
28
|
+
void Haptics.lightImpact();
|
|
29
|
+
setSelectedPeriod(period.value);
|
|
30
|
+
}, [period, setSelectedPeriod]);
|
|
31
|
+
const theme = useTheme();
|
|
32
|
+
const textStyle = useMemo(() => ({
|
|
33
|
+
color: isSelected ? color : theme.color.fgMuted
|
|
34
|
+
}), [color, isSelected, theme.color.fgMuted]);
|
|
35
|
+
const accessibilityState = useMemo(() => ({
|
|
36
|
+
selected: isSelected
|
|
37
|
+
}), [isSelected]);
|
|
38
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
39
|
+
alignItems: "center",
|
|
40
|
+
justifyContent: "center",
|
|
41
|
+
onLayout: getLayoutHandler(period.value),
|
|
42
|
+
paddingY: 2,
|
|
43
|
+
children: /*#__PURE__*/_jsx(Pressable, {
|
|
44
|
+
accessibilityHint: periodHint,
|
|
45
|
+
accessibilityLabel: periodLabel,
|
|
46
|
+
accessibilityState: accessibilityState,
|
|
47
|
+
background: isSelected ? 'bgPrimaryWash' : 'bg',
|
|
48
|
+
borderColor: "transparent",
|
|
49
|
+
borderRadius: 1000,
|
|
50
|
+
onPress: handleOnPress,
|
|
51
|
+
children: /*#__PURE__*/_jsx(TextLabel1, {
|
|
52
|
+
paddingX: 2,
|
|
53
|
+
paddingY: 1,
|
|
54
|
+
style: textStyle,
|
|
55
|
+
children: period.label
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
}, period.value);
|
|
59
|
+
}
|
|
60
|
+
const periodSelectorStyles = StyleSheet.create({
|
|
61
|
+
scrollViewContainer: {
|
|
62
|
+
flexGrow: 1
|
|
63
|
+
},
|
|
64
|
+
hStackContainer: {
|
|
65
|
+
flex: 1
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const SparklineInteractivePeriod = /*#__PURE__*/memo(SparklineInteractivePeriodWithGeneric);
|
|
69
|
+
export const SparklineInteractivePeriodSelector = _ref2 => {
|
|
70
|
+
let {
|
|
71
|
+
selectedPeriod,
|
|
72
|
+
setSelectedPeriod,
|
|
73
|
+
periods,
|
|
74
|
+
color
|
|
75
|
+
} = _ref2;
|
|
76
|
+
const theme = useTheme();
|
|
77
|
+
const accessibleForeground = color !== 'auto' ? color : getAccessibleColor({
|
|
78
|
+
background: theme.color.bg,
|
|
79
|
+
foreground: 'auto'
|
|
80
|
+
});
|
|
81
|
+
const {
|
|
82
|
+
markerOpacity
|
|
83
|
+
} = useSparklineInteractiveContext();
|
|
84
|
+
const {
|
|
85
|
+
scrollRef,
|
|
86
|
+
isScrollContentOverflowing,
|
|
87
|
+
isScrollContentOffscreenRight,
|
|
88
|
+
handleScroll,
|
|
89
|
+
handleScrollContainerLayout,
|
|
90
|
+
handleScrollContentSizeChange,
|
|
91
|
+
getPressableLayoutHandler
|
|
92
|
+
} = useHorizontallyScrollingPressables(selectedPeriod);
|
|
93
|
+
const opacity = markerOpacity.interpolate({
|
|
94
|
+
inputRange: [0, 1],
|
|
95
|
+
outputRange: [1, 0]
|
|
96
|
+
});
|
|
97
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
98
|
+
animated: true,
|
|
99
|
+
background: "bg",
|
|
100
|
+
opacity: opacity,
|
|
101
|
+
children: [/*#__PURE__*/_jsx(ScrollView, {
|
|
102
|
+
ref: scrollRef,
|
|
103
|
+
horizontal: true,
|
|
104
|
+
contentContainerStyle: periodSelectorStyles.scrollViewContainer,
|
|
105
|
+
onContentSizeChange: handleScrollContentSizeChange,
|
|
106
|
+
onLayout: handleScrollContainerLayout,
|
|
107
|
+
onScroll: handleScroll,
|
|
108
|
+
scrollEventThrottle: 1,
|
|
109
|
+
showsHorizontalScrollIndicator: false,
|
|
110
|
+
children: /*#__PURE__*/_jsx(HStack, {
|
|
111
|
+
justifyContent: "space-between",
|
|
112
|
+
padding: 0,
|
|
113
|
+
style: periodSelectorStyles.hStackContainer,
|
|
114
|
+
children: periods.map(period => /*#__PURE__*/_jsx(SparklineInteractivePeriod, {
|
|
115
|
+
color: accessibleForeground,
|
|
116
|
+
getLayoutHandler: getPressableLayoutHandler,
|
|
117
|
+
period: period,
|
|
118
|
+
selectedPeriod: selectedPeriod,
|
|
119
|
+
setSelectedPeriod: setSelectedPeriod
|
|
120
|
+
}, period.value))
|
|
121
|
+
})
|
|
122
|
+
}), isScrollContentOverflowing && isScrollContentOffscreenRight && /*#__PURE__*/_jsx(OverflowGradient, {})]
|
|
123
|
+
});
|
|
124
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React, { createContext, memo, useCallback, useContext, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
import { makeMutable, useSharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { gutter } from '@coinbase/cds-common/tokens/sizing';
|
|
5
|
+
import { noop } from '@coinbase/cds-utils';
|
|
6
|
+
import { useOpacityAnimation } from './useOpacityAnimation';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const SparklineInteractiveContext = /*#__PURE__*/createContext({
|
|
9
|
+
isFallbackVisible: true,
|
|
10
|
+
markerXPosition: makeMutable(0),
|
|
11
|
+
markerGestureState: makeMutable(0),
|
|
12
|
+
showFallback: noop,
|
|
13
|
+
hideFallback: noop,
|
|
14
|
+
chartOpacity: new Animated.Value(0),
|
|
15
|
+
animateChartIn: noop,
|
|
16
|
+
markerOpacity: new Animated.Value(0),
|
|
17
|
+
animateMarkerIn: noop,
|
|
18
|
+
animateMarkerOut: noop,
|
|
19
|
+
minMaxOpacity: new Animated.Value(0),
|
|
20
|
+
animateMinMaxIn: noop,
|
|
21
|
+
animateMinxMaxOut: noop,
|
|
22
|
+
hoverDateOpacity: new Animated.Value(0),
|
|
23
|
+
animateHoverDateIn: noop,
|
|
24
|
+
animateHoverDateOut: noop,
|
|
25
|
+
compact: false,
|
|
26
|
+
gutter
|
|
27
|
+
});
|
|
28
|
+
export const SparklineInteractiveProvider = /*#__PURE__*/memo(_ref => {
|
|
29
|
+
let {
|
|
30
|
+
children,
|
|
31
|
+
compact = false,
|
|
32
|
+
gutter: propGutter
|
|
33
|
+
} = _ref;
|
|
34
|
+
const [isFallbackVisible, setIsFallbackVisible] = useState(true);
|
|
35
|
+
const markerXPosition = useSharedValue(-1);
|
|
36
|
+
const markerGestureState = useSharedValue(0);
|
|
37
|
+
const [chartOpacity, animateChartIn, animateChartOut] = useOpacityAnimation();
|
|
38
|
+
const [markerOpacity, animateMarkerIn, animateMarkerOut] = useOpacityAnimation();
|
|
39
|
+
const [minMaxOpacity, animateMinMaxIn, animateMinxMaxOut] = useOpacityAnimation();
|
|
40
|
+
const [hoverDateOpacity, animateHoverDateIn, animateHoverDateOut] = useOpacityAnimation();
|
|
41
|
+
const chartGutter = useRef(propGutter != null ? propGutter : gutter).current;
|
|
42
|
+
const showFallback = useCallback(() => {
|
|
43
|
+
animateChartOut.start();
|
|
44
|
+
setIsFallbackVisible(true);
|
|
45
|
+
}, [animateChartOut]);
|
|
46
|
+
const hideFallback = useCallback(() => {
|
|
47
|
+
animateChartIn.start();
|
|
48
|
+
animateMinMaxIn.start();
|
|
49
|
+
setIsFallbackVisible(false);
|
|
50
|
+
}, [animateChartIn, animateMinMaxIn]);
|
|
51
|
+
const sparklineProviderVal = useMemo(() => {
|
|
52
|
+
return {
|
|
53
|
+
isFallbackVisible,
|
|
54
|
+
markerXPosition,
|
|
55
|
+
markerGestureState,
|
|
56
|
+
showFallback,
|
|
57
|
+
hideFallback,
|
|
58
|
+
chartOpacity,
|
|
59
|
+
animateChartIn,
|
|
60
|
+
markerOpacity,
|
|
61
|
+
animateMarkerIn,
|
|
62
|
+
animateMarkerOut,
|
|
63
|
+
minMaxOpacity,
|
|
64
|
+
animateMinMaxIn,
|
|
65
|
+
animateMinxMaxOut,
|
|
66
|
+
hoverDateOpacity,
|
|
67
|
+
animateHoverDateIn,
|
|
68
|
+
animateHoverDateOut,
|
|
69
|
+
compact,
|
|
70
|
+
gutter: chartGutter
|
|
71
|
+
};
|
|
72
|
+
}, [animateChartIn, animateHoverDateIn, animateHoverDateOut, animateMarkerIn, animateMarkerOut, animateMinMaxIn, animateMinxMaxOut, chartOpacity, compact, hideFallback, hoverDateOpacity, isFallbackVisible, markerGestureState, markerOpacity, markerXPosition, minMaxOpacity, showFallback, chartGutter]);
|
|
73
|
+
return /*#__PURE__*/_jsx(SparklineInteractiveContext.Provider, {
|
|
74
|
+
value: sparklineProviderVal,
|
|
75
|
+
children: children
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
export function useSparklineInteractiveContext() {
|
|
79
|
+
return useContext(SparklineInteractiveContext);
|
|
80
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
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, { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { G, Path, Svg } from 'react-native-svg';
|
|
4
|
+
import { borderWidth } from '@coinbase/cds-common/tokens/sparkline';
|
|
5
|
+
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
6
|
+
import { getSparklineTransform } from '@coinbase/cds-common/visualizations/getSparklineTransform';
|
|
7
|
+
import { useTimeseriesPaths } from '@coinbase/cds-common/visualizations/useTimeseriesPaths';
|
|
8
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
9
|
+
import * as interpolate from 'd3-interpolate-path';
|
|
10
|
+
import { useInterruptiblePathAnimation } from './useInterruptiblePathAnimation';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
const TimeseriesPath = /*#__PURE__*/memo(_ref => {
|
|
13
|
+
let {
|
|
14
|
+
timeseries,
|
|
15
|
+
lineFn,
|
|
16
|
+
initialPath,
|
|
17
|
+
onRender,
|
|
18
|
+
areaFn
|
|
19
|
+
} = _ref;
|
|
20
|
+
const theme = useTheme();
|
|
21
|
+
const pathRef = useRef(null);
|
|
22
|
+
const {
|
|
23
|
+
strokeColor
|
|
24
|
+
} = timeseries;
|
|
25
|
+
const lineColor = strokeColor !== 'auto' ? strokeColor : getAccessibleColor({
|
|
26
|
+
background: theme.color.bg,
|
|
27
|
+
foreground: 'auto',
|
|
28
|
+
usage: 'graphic'
|
|
29
|
+
});
|
|
30
|
+
const newPath = useMemo(() => lineFn(timeseries.points), [lineFn, timeseries.points]);
|
|
31
|
+
const newArea = useMemo(() => onRender ? areaFn(timeseries.points) : null, [areaFn, onRender, timeseries.points]);
|
|
32
|
+
const pathInterpolator = useMemo(() => interpolate.interpolatePath(initialPath, newPath), [initialPath, newPath]);
|
|
33
|
+
const animationListener = useCallback(_ref2 => {
|
|
34
|
+
var _pathRef$current;
|
|
35
|
+
let {
|
|
36
|
+
value
|
|
37
|
+
} = _ref2;
|
|
38
|
+
const val = Number(value.toFixed(4));
|
|
39
|
+
// BAD: We only disabled this lint rule to enable eslint upgrade after this component was implemented. These apis should never be used.
|
|
40
|
+
// Usage in this component are known making this a high risk component. Contact team for more information.
|
|
41
|
+
|
|
42
|
+
(_pathRef$current = pathRef.current) == null || _pathRef$current.setNativeProps({
|
|
43
|
+
d: pathInterpolator(val)
|
|
44
|
+
});
|
|
45
|
+
}, [pathInterpolator]);
|
|
46
|
+
const updatePathWithoutAnimation = useCallback(() => {
|
|
47
|
+
var _pathRef$current2;
|
|
48
|
+
// BAD: We only disabled this lint rule to enable eslint upgrade after this component was implemented. These apis should never be used.
|
|
49
|
+
// Usage in this component are known making this a high risk component. Contact team for more information.
|
|
50
|
+
|
|
51
|
+
(_pathRef$current2 = pathRef.current) == null || _pathRef$current2.setNativeProps({
|
|
52
|
+
d: pathInterpolator(1)
|
|
53
|
+
});
|
|
54
|
+
}, [pathInterpolator]);
|
|
55
|
+
const playAnimation = useInterruptiblePathAnimation({
|
|
56
|
+
animationListener,
|
|
57
|
+
onInterrupt: updatePathWithoutAnimation,
|
|
58
|
+
ignoreMinMax: true
|
|
59
|
+
});
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
playAnimation();
|
|
62
|
+
onRender == null || onRender({
|
|
63
|
+
path: newPath,
|
|
64
|
+
area: newArea
|
|
65
|
+
});
|
|
66
|
+
}, [newArea, newPath, onRender, pathInterpolator, playAnimation]);
|
|
67
|
+
return /*#__PURE__*/_jsx(Path, {
|
|
68
|
+
ref: pathRef,
|
|
69
|
+
d: initialPath,
|
|
70
|
+
stroke: lineColor,
|
|
71
|
+
strokeLinecap: "round",
|
|
72
|
+
strokeLinejoin: "round",
|
|
73
|
+
strokeWidth: borderWidth
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
export const SparklineInteractiveTimeseriesPaths = /*#__PURE__*/memo(_ref3 => {
|
|
77
|
+
let {
|
|
78
|
+
data,
|
|
79
|
+
width,
|
|
80
|
+
height,
|
|
81
|
+
initialPath,
|
|
82
|
+
onRender
|
|
83
|
+
} = _ref3;
|
|
84
|
+
const {
|
|
85
|
+
lineFn,
|
|
86
|
+
areaFn
|
|
87
|
+
} = useTimeseriesPaths({
|
|
88
|
+
data,
|
|
89
|
+
width,
|
|
90
|
+
height
|
|
91
|
+
});
|
|
92
|
+
const translateProps = useMemo(() => getSparklineTransform(width, height), [width, height]);
|
|
93
|
+
const paths = data.map((timeseries, index) => {
|
|
94
|
+
return /*#__PURE__*/_jsx(TimeseriesPath, {
|
|
95
|
+
areaFn: areaFn,
|
|
96
|
+
initialPath: initialPath,
|
|
97
|
+
lineFn: lineFn,
|
|
98
|
+
onRender: index === 0 ? onRender : undefined,
|
|
99
|
+
timeseries: timeseries
|
|
100
|
+
}, timeseries.id);
|
|
101
|
+
});
|
|
102
|
+
return /*#__PURE__*/_jsx(Svg, {
|
|
103
|
+
height: height,
|
|
104
|
+
width: width,
|
|
105
|
+
children: /*#__PURE__*/_jsx(G, _extends({}, translateProps, {
|
|
106
|
+
children: paths
|
|
107
|
+
}))
|
|
108
|
+
});
|
|
109
|
+
});
|