@coinbase/cds-mobile-visualization 0.0.0 → 3.3.0
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/README.md +3 -0
- package/dts/index.d.ts +2 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +3 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +22 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +8 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +6 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +12 -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/__stories__/Sparkline.stories.d.ts +3 -0
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts.map +1 -0
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts +3 -0
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +5 -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 +18 -0
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +162 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +12 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +8 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +12 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +9 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +14 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +11 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +20 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +33 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +23 -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/__stories__/SparklineInteractive.stories.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +9 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +11 -0
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +3 -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 +31 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +110 -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/__stories__/SparklineInteractiveHeader.stories.d.ts +4 -0
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts.map +1 -0
- package/esm/index.js +1 -0
- package/esm/sparkline/Counter.js +45 -0
- package/esm/sparkline/Sparkline.js +51 -0
- package/esm/sparkline/SparklineArea.js +14 -0
- package/esm/sparkline/SparklineAreaPattern.js +36 -0
- package/esm/sparkline/SparklineGradient.js +72 -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 +6 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineAccessibleView.js +75 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +303 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +113 -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 +53 -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 +474 -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 +64 -5
- package/index.js +0 -1
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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 { figma } from '@figma/code-connect';
|
|
4
|
+
import { SparklineInteractive } from '../SparklineInteractive';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
figma.connect(SparklineInteractive, 'https://www.figma.com/design/k5CtyJccNQUGMI5bI4lJ2g/%E2%9C%A8-CDS-Components?node-id=320-14858&m=dev', {
|
|
7
|
+
imports: ["import { SparklineInteractive } from '@coinbase/cds-web-visualization';"],
|
|
8
|
+
props: {
|
|
9
|
+
compact: figma.boolean('compact'),
|
|
10
|
+
disableScrubbing: figma.boolean('scrubbing', {
|
|
11
|
+
false: true,
|
|
12
|
+
true: false
|
|
13
|
+
})
|
|
14
|
+
},
|
|
15
|
+
example: props => {
|
|
16
|
+
const periods = [{
|
|
17
|
+
label: '1H',
|
|
18
|
+
value: 'hour'
|
|
19
|
+
}, {
|
|
20
|
+
label: '1D',
|
|
21
|
+
value: 'day'
|
|
22
|
+
}, {
|
|
23
|
+
label: '1W',
|
|
24
|
+
value: 'week'
|
|
25
|
+
}, {
|
|
26
|
+
label: '1M',
|
|
27
|
+
value: 'month'
|
|
28
|
+
}, {
|
|
29
|
+
label: '1Y',
|
|
30
|
+
value: 'year'
|
|
31
|
+
}, {
|
|
32
|
+
label: 'All',
|
|
33
|
+
value: 'all'
|
|
34
|
+
}];
|
|
35
|
+
const data = {
|
|
36
|
+
hour: [],
|
|
37
|
+
day: [{
|
|
38
|
+
value: 49259.38,
|
|
39
|
+
date: new Date('2021-12-05T04:00:00.000Z')
|
|
40
|
+
}, {
|
|
41
|
+
value: 49163.79,
|
|
42
|
+
date: new Date('2021-12-05T04:05:00.000Z')
|
|
43
|
+
}, {
|
|
44
|
+
value: 49146.66,
|
|
45
|
+
date: new Date('2021-12-05T04:10:00.000Z')
|
|
46
|
+
}, {
|
|
47
|
+
value: 49083.92,
|
|
48
|
+
date: new Date('2021-12-05T04:15:00.000Z')
|
|
49
|
+
}, {
|
|
50
|
+
value: 49115.3,
|
|
51
|
+
date: new Date('2021-12-05T04:20:00.000Z')
|
|
52
|
+
}, {
|
|
53
|
+
value: 48992.14,
|
|
54
|
+
date: new Date('2021-12-05T04:25:00.000Z')
|
|
55
|
+
}, {
|
|
56
|
+
value: 49075.75,
|
|
57
|
+
date: new Date('2021-12-05T04:30:00.000Z')
|
|
58
|
+
}, {
|
|
59
|
+
value: 49025.78,
|
|
60
|
+
date: new Date('2021-12-05T04:35:00.000Z')
|
|
61
|
+
}, {
|
|
62
|
+
value: 49066.23,
|
|
63
|
+
date: new Date('2021-12-05T04:40:00.000Z')
|
|
64
|
+
}, {
|
|
65
|
+
value: 49247.82,
|
|
66
|
+
date: new Date('2021-12-05T04:45:00.000Z')
|
|
67
|
+
}],
|
|
68
|
+
week: [],
|
|
69
|
+
month: [],
|
|
70
|
+
year: [],
|
|
71
|
+
all: []
|
|
72
|
+
};
|
|
73
|
+
return /*#__PURE__*/_jsx(SparklineInteractive, _extends({
|
|
74
|
+
data: data,
|
|
75
|
+
defaultPeriod: "day",
|
|
76
|
+
formatDate: date => date.toLocaleString('en-US', {
|
|
77
|
+
timeZone: 'America/New_York',
|
|
78
|
+
hour: 'numeric',
|
|
79
|
+
minute: 'numeric'
|
|
80
|
+
}),
|
|
81
|
+
periods: periods,
|
|
82
|
+
strokeColor: "#cb51bb"
|
|
83
|
+
}, props));
|
|
84
|
+
}
|
|
85
|
+
});
|