@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,307 @@
|
|
|
1
|
+
const _excluded = ["compact", "gutter"];
|
|
2
|
+
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); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { Animated, StyleSheet, View } from 'react-native';
|
|
6
|
+
import { minMax } from '@coinbase/cds-common/utils/chart';
|
|
7
|
+
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
8
|
+
import { useSparklineCoordinates } from '@coinbase/cds-common/visualizations/useSparklineCoordinates';
|
|
9
|
+
import { chartFallbackNegative, chartFallbackPositive } from '@coinbase/cds-lottie-files';
|
|
10
|
+
import { Lottie } from '@coinbase/cds-mobile/animation';
|
|
11
|
+
import { useScreenReaderStatus } from '@coinbase/cds-mobile/hooks/useScreenReaderStatus';
|
|
12
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
13
|
+
import { Box } from '@coinbase/cds-mobile/layout';
|
|
14
|
+
import { emptyArray, noop } from '@coinbase/cds-utils';
|
|
15
|
+
import isEqual from 'lodash/isEqual';
|
|
16
|
+
import isObject from 'lodash/isObject';
|
|
17
|
+
import { SparklineAccessibleView } from './SparklineAccessibleView';
|
|
18
|
+
import { SparklineInteractiveHoverDate } from './SparklineInteractiveHoverDate';
|
|
19
|
+
import { SparklineInteractiveLineVertical } from './SparklineInteractiveLineVertical';
|
|
20
|
+
import { SparklineInteractiveMarkerDates } from './SparklineInteractiveMarkerDates';
|
|
21
|
+
import { SparklineInteractiveMinMax } from './SparklineInteractiveMinMax';
|
|
22
|
+
import { SparklineInteractivePanGestureHandler } from './SparklineInteractivePanGestureHandler';
|
|
23
|
+
import { SparklineInteractivePaths } from './SparklineInteractivePaths';
|
|
24
|
+
import { SparklineInteractivePeriodSelector } from './SparklineInteractivePeriodSelector';
|
|
25
|
+
import { SparklineInteractiveProvider, useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
26
|
+
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
27
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
28
|
+
export * from '@coinbase/cds-common/types/Chart';
|
|
29
|
+
const DefaultFallback = /*#__PURE__*/memo(_ref => {
|
|
30
|
+
let {
|
|
31
|
+
fallbackType
|
|
32
|
+
} = _ref;
|
|
33
|
+
const source = fallbackType === 'negative' ? chartFallbackNegative : chartFallbackPositive;
|
|
34
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
justifyContent: "center",
|
|
37
|
+
children: /*#__PURE__*/_jsx(Lottie, {
|
|
38
|
+
autoplay: true,
|
|
39
|
+
loop: true,
|
|
40
|
+
height: "100%",
|
|
41
|
+
source: source
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
function defaultFormatMinMaxLabel(value) {
|
|
46
|
+
return "" + value;
|
|
47
|
+
}
|
|
48
|
+
function BelowChartWithGeneric(_ref2) {
|
|
49
|
+
let {
|
|
50
|
+
color,
|
|
51
|
+
formatDate,
|
|
52
|
+
getMarker,
|
|
53
|
+
periods,
|
|
54
|
+
selectedPeriod,
|
|
55
|
+
setSelectedPeriod,
|
|
56
|
+
timePeriodGutter
|
|
57
|
+
} = _ref2;
|
|
58
|
+
const theme = useTheme();
|
|
59
|
+
const style = useMemo(() => {
|
|
60
|
+
if (timePeriodGutter) {
|
|
61
|
+
return {
|
|
62
|
+
paddingHorizontal: theme.space[timePeriodGutter]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {};
|
|
66
|
+
}, [theme.space, timePeriodGutter]);
|
|
67
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
68
|
+
style: style,
|
|
69
|
+
children: [/*#__PURE__*/_jsx(SparklineInteractiveMarkerDates, {
|
|
70
|
+
formatDate: formatDate,
|
|
71
|
+
getMarker: getMarker,
|
|
72
|
+
selectedPeriod: selectedPeriod,
|
|
73
|
+
timePeriodGutter: timePeriodGutter
|
|
74
|
+
}), /*#__PURE__*/_jsx(SparklineInteractivePeriodSelector, {
|
|
75
|
+
color: color,
|
|
76
|
+
periods: periods,
|
|
77
|
+
selectedPeriod: selectedPeriod,
|
|
78
|
+
setSelectedPeriod: setSelectedPeriod
|
|
79
|
+
})]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const BelowChart = /*#__PURE__*/memo(BelowChartWithGeneric);
|
|
83
|
+
function SparklineInteractiveContentWithGeneric(_ref3) {
|
|
84
|
+
let {
|
|
85
|
+
data,
|
|
86
|
+
periods,
|
|
87
|
+
defaultPeriod,
|
|
88
|
+
onPeriodChanged,
|
|
89
|
+
strokeColor,
|
|
90
|
+
onScrub = noop,
|
|
91
|
+
onScrubStart = noop,
|
|
92
|
+
onScrubEnd = noop,
|
|
93
|
+
formatMinMaxLabel = defaultFormatMinMaxLabel,
|
|
94
|
+
formatDate,
|
|
95
|
+
fallback = null,
|
|
96
|
+
hideMinMaxLabel = false,
|
|
97
|
+
hidePeriodSelector = false,
|
|
98
|
+
disableScrubbing = false,
|
|
99
|
+
fill = true,
|
|
100
|
+
fillType = 'gradient',
|
|
101
|
+
yAxisScalingFactor = 1.0,
|
|
102
|
+
formatHoverDate,
|
|
103
|
+
headerNode,
|
|
104
|
+
fallbackType = 'positive',
|
|
105
|
+
disableHorizontalPadding = false,
|
|
106
|
+
hoverData,
|
|
107
|
+
timePeriodGutter,
|
|
108
|
+
allowOverflowGestures,
|
|
109
|
+
style,
|
|
110
|
+
styles,
|
|
111
|
+
headerTestID
|
|
112
|
+
} = _ref3;
|
|
113
|
+
const [isScrubbing, setIsScrubbing] = useState(false);
|
|
114
|
+
const {
|
|
115
|
+
isFallbackVisible,
|
|
116
|
+
showFallback,
|
|
117
|
+
chartOpacity,
|
|
118
|
+
minMaxOpacity,
|
|
119
|
+
compact
|
|
120
|
+
} = useSparklineInteractiveContext();
|
|
121
|
+
const color = strokeColor;
|
|
122
|
+
const [selectedPeriod, setSelectedPeriod] = useState(defaultPeriod);
|
|
123
|
+
const chartHoverTextInputRef = useRef(null);
|
|
124
|
+
const theme = useTheme();
|
|
125
|
+
const isScreenReaderEnabled = useScreenReaderStatus();
|
|
126
|
+
const lineVerticalColor = useMemo(() => {
|
|
127
|
+
const lineColor = color !== 'auto' ? color : getAccessibleColor({
|
|
128
|
+
background: theme.color.bg,
|
|
129
|
+
foreground: 'auto',
|
|
130
|
+
usage: 'graphic'
|
|
131
|
+
});
|
|
132
|
+
return hoverData ? theme.color.bgLineHeavy : lineColor;
|
|
133
|
+
}, [hoverData, color, theme.color.bg, theme.color.bgLineHeavy]);
|
|
134
|
+
const dataForPeriod = useMemo(() => {
|
|
135
|
+
var _data$selectedPeriod;
|
|
136
|
+
if (!data) {
|
|
137
|
+
return emptyArray;
|
|
138
|
+
}
|
|
139
|
+
return (_data$selectedPeriod = data[selectedPeriod]) != null ? _data$selectedPeriod : emptyArray;
|
|
140
|
+
}, [data, selectedPeriod]);
|
|
141
|
+
|
|
142
|
+
// If dataForPeriod is empty we know that we are either loading
|
|
143
|
+
// or backend returned bad data and we should show fallback UI.
|
|
144
|
+
const hasData = dataForPeriod.length > 0;
|
|
145
|
+
const [min, max] = useMemo(() => {
|
|
146
|
+
return minMax(dataForPeriod, d => d.value);
|
|
147
|
+
}, [dataForPeriod]);
|
|
148
|
+
const chartOpacityStyle = useMemo(() => {
|
|
149
|
+
return {
|
|
150
|
+
opacity: chartOpacity
|
|
151
|
+
};
|
|
152
|
+
}, [chartOpacity]);
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
var _data$selectedPeriod2;
|
|
155
|
+
// If there is no data for selected period show fallback loader
|
|
156
|
+
if (isObject(data) && !((_data$selectedPeriod2 = data[selectedPeriod]) != null && _data$selectedPeriod2.length) && !isFallbackVisible) {
|
|
157
|
+
showFallback();
|
|
158
|
+
}
|
|
159
|
+
}, [data, isFallbackVisible, selectedPeriod, showFallback]);
|
|
160
|
+
const updatePeriod = useCallback(period => {
|
|
161
|
+
if (isObject(data) && period !== selectedPeriod) {
|
|
162
|
+
// This can sometimes happen for newer assets which
|
|
163
|
+
// will have their 'all' chart data be the same as
|
|
164
|
+
// their 'year' chart data. In those cases we don't
|
|
165
|
+
// want to animate out the min/max since we rely on
|
|
166
|
+
// AnimatedChartPath to animate those components back in -
|
|
167
|
+
// and AnimatedChartPath will not trigger an animation
|
|
168
|
+
// if it's chartData is the same between re-renders
|
|
169
|
+
if (!isEqual(data[period], data[selectedPeriod])) {
|
|
170
|
+
minMaxOpacity.setValue(0);
|
|
171
|
+
}
|
|
172
|
+
setSelectedPeriod(period);
|
|
173
|
+
onPeriodChanged == null || onPeriodChanged(period);
|
|
174
|
+
}
|
|
175
|
+
}, [data, selectedPeriod, onPeriodChanged, minMaxOpacity]);
|
|
176
|
+
const {
|
|
177
|
+
chartHorizontalGutter,
|
|
178
|
+
chartDimensionStyles,
|
|
179
|
+
chartWidth,
|
|
180
|
+
chartHeight
|
|
181
|
+
} = useSparklineInteractiveConstants({
|
|
182
|
+
compact
|
|
183
|
+
});
|
|
184
|
+
const {
|
|
185
|
+
xFunction,
|
|
186
|
+
path,
|
|
187
|
+
area,
|
|
188
|
+
getMarker
|
|
189
|
+
} = useSparklineCoordinates({
|
|
190
|
+
data: dataForPeriod,
|
|
191
|
+
width: chartWidth,
|
|
192
|
+
height: chartHeight,
|
|
193
|
+
yAxisScalingFactor
|
|
194
|
+
});
|
|
195
|
+
const handleScrub = useCallback(params => {
|
|
196
|
+
var _chartHoverTextInputR;
|
|
197
|
+
(_chartHoverTextInputR = chartHoverTextInputRef.current) == null || _chartHoverTextInputR.update(params);
|
|
198
|
+
onScrub == null || onScrub(params);
|
|
199
|
+
}, [onScrub]);
|
|
200
|
+
const handleScrubStart = useCallback(() => {
|
|
201
|
+
if (hoverData) {
|
|
202
|
+
setIsScrubbing(true);
|
|
203
|
+
}
|
|
204
|
+
onScrubStart == null || onScrubStart();
|
|
205
|
+
}, [hoverData, onScrubStart]);
|
|
206
|
+
const handleScrubEnd = useCallback(() => {
|
|
207
|
+
if (hoverData) {
|
|
208
|
+
setIsScrubbing(false);
|
|
209
|
+
}
|
|
210
|
+
onScrubEnd == null || onScrubEnd();
|
|
211
|
+
}, [hoverData, onScrubEnd]);
|
|
212
|
+
let header;
|
|
213
|
+
if (headerNode) {
|
|
214
|
+
header = /*#__PURE__*/_jsx(Box, {
|
|
215
|
+
paddingBottom: 2,
|
|
216
|
+
style: styles == null ? void 0 : styles.header,
|
|
217
|
+
testID: headerTestID,
|
|
218
|
+
children: headerNode
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
const rootStyles = useMemo(() => {
|
|
222
|
+
return [!disableHorizontalPadding && {
|
|
223
|
+
paddingHorizontal: chartHorizontalGutter
|
|
224
|
+
}, style, styles == null ? void 0 : styles.root];
|
|
225
|
+
}, [style, styles == null ? void 0 : styles.root, chartHorizontalGutter, disableHorizontalPadding]);
|
|
226
|
+
return /*#__PURE__*/_jsxs(Animated.View, {
|
|
227
|
+
style: rootStyles,
|
|
228
|
+
children: [header, /*#__PURE__*/_jsxs(SparklineInteractivePanGestureHandler, {
|
|
229
|
+
allowOverflowGestures: allowOverflowGestures,
|
|
230
|
+
disabled: disableScrubbing,
|
|
231
|
+
getMarker: getMarker,
|
|
232
|
+
onScrub: handleScrub,
|
|
233
|
+
onScrubEnd: handleScrubEnd,
|
|
234
|
+
onScrubStart: handleScrubStart,
|
|
235
|
+
selectedPeriod: selectedPeriod,
|
|
236
|
+
children: [!!formatHoverDate && /*#__PURE__*/_jsx(SparklineInteractiveHoverDate, {
|
|
237
|
+
ref: chartHoverTextInputRef,
|
|
238
|
+
formatHoverDate: formatHoverDate,
|
|
239
|
+
shouldTakeUpHeight: hideMinMaxLabel
|
|
240
|
+
}), !hideMinMaxLabel && /*#__PURE__*/_jsx(SparklineInteractiveMinMax, {
|
|
241
|
+
dataPoint: max,
|
|
242
|
+
formatMinMaxLabel: formatMinMaxLabel,
|
|
243
|
+
xFunction: xFunction
|
|
244
|
+
}), /*#__PURE__*/_jsxs(View, {
|
|
245
|
+
style: chartDimensionStyles,
|
|
246
|
+
children: [isScreenReaderEnabled && /*#__PURE__*/_jsx(SparklineAccessibleView, {
|
|
247
|
+
data: data,
|
|
248
|
+
selectedPeriod: selectedPeriod
|
|
249
|
+
}), !!isFallbackVisible && /*#__PURE__*/_jsx(View, {
|
|
250
|
+
style: StyleSheet.absoluteFill,
|
|
251
|
+
children: fallback != null ? fallback : /*#__PURE__*/_jsx(DefaultFallback, {
|
|
252
|
+
fallbackType: fallbackType
|
|
253
|
+
})
|
|
254
|
+
}), /*#__PURE__*/_jsx(Animated.View, {
|
|
255
|
+
style: chartOpacityStyle,
|
|
256
|
+
children: !!hasData && !!path && /*#__PURE__*/_jsxs(_Fragment, {
|
|
257
|
+
children: [/*#__PURE__*/_jsx(SparklineInteractiveLineVertical, {
|
|
258
|
+
color: lineVerticalColor,
|
|
259
|
+
showHoverDate: !!formatHoverDate
|
|
260
|
+
}), /*#__PURE__*/_jsx(SparklineInteractivePaths, {
|
|
261
|
+
area: area,
|
|
262
|
+
compact: compact,
|
|
263
|
+
fill: fill,
|
|
264
|
+
fillType: fillType,
|
|
265
|
+
hoverData: hoverData,
|
|
266
|
+
path: path,
|
|
267
|
+
selectedPeriod: selectedPeriod,
|
|
268
|
+
showHoverData: isScrubbing,
|
|
269
|
+
strokeColor: color,
|
|
270
|
+
yAxisScalingFactor: yAxisScalingFactor
|
|
271
|
+
})]
|
|
272
|
+
})
|
|
273
|
+
})]
|
|
274
|
+
}), !hideMinMaxLabel && /*#__PURE__*/_jsx(SparklineInteractiveMinMax, {
|
|
275
|
+
dataPoint: min,
|
|
276
|
+
formatMinMaxLabel: formatMinMaxLabel,
|
|
277
|
+
xFunction: xFunction
|
|
278
|
+
})]
|
|
279
|
+
}), !hidePeriodSelector && /*#__PURE__*/_jsx(BelowChart, {
|
|
280
|
+
color: color,
|
|
281
|
+
formatDate: formatDate,
|
|
282
|
+
getMarker: getMarker,
|
|
283
|
+
periods: periods,
|
|
284
|
+
selectedPeriod: selectedPeriod,
|
|
285
|
+
setSelectedPeriod: updatePeriod,
|
|
286
|
+
timePeriodGutter: timePeriodGutter
|
|
287
|
+
})]
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
const SparklineInteractiveContent = /*#__PURE__*/memo(SparklineInteractiveContentWithGeneric);
|
|
291
|
+
function SparklineInteractiveWithGeneric(_ref4) {
|
|
292
|
+
let {
|
|
293
|
+
compact,
|
|
294
|
+
gutter
|
|
295
|
+
} = _ref4,
|
|
296
|
+
props = _objectWithoutPropertiesLoose(_ref4, _excluded);
|
|
297
|
+
return /*#__PURE__*/_jsx(SparklineInteractiveProvider, {
|
|
298
|
+
compact: compact,
|
|
299
|
+
gutter: gutter,
|
|
300
|
+
children: /*#__PURE__*/_jsx(SparklineInteractiveContent, _extends({}, props))
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @deprecated Use LineChart instead.
|
|
306
|
+
*/
|
|
307
|
+
export const SparklineInteractive = /*#__PURE__*/memo(SparklineInteractiveWithGeneric);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useValueChanges } from '@coinbase/cds-common/hooks/useValueChanges';
|
|
3
|
+
import * as interpolate from 'd3-interpolate-path';
|
|
4
|
+
import { Sparkline } from '../Sparkline';
|
|
5
|
+
import { SparklineArea } from '../SparklineArea';
|
|
6
|
+
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
7
|
+
import { useInterruptiblePathAnimation } from './useInterruptiblePathAnimation';
|
|
8
|
+
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
export const SparklineInteractiveAnimatedPath = /*#__PURE__*/memo(_ref => {
|
|
11
|
+
let {
|
|
12
|
+
d = '',
|
|
13
|
+
color,
|
|
14
|
+
selectedPeriod,
|
|
15
|
+
area,
|
|
16
|
+
fillType = 'gradient',
|
|
17
|
+
yAxisScalingFactor,
|
|
18
|
+
initialPath,
|
|
19
|
+
initialArea
|
|
20
|
+
} = _ref;
|
|
21
|
+
const {
|
|
22
|
+
isFallbackVisible,
|
|
23
|
+
hideFallback,
|
|
24
|
+
animateMinMaxIn,
|
|
25
|
+
compact
|
|
26
|
+
} = useSparklineInteractiveContext();
|
|
27
|
+
const pathRef = useRef(null);
|
|
28
|
+
const areaRef = useRef(null);
|
|
29
|
+
|
|
30
|
+
// Only tween animation on period changes
|
|
31
|
+
const {
|
|
32
|
+
hasNotChanged: skipAnimation,
|
|
33
|
+
addPreviousValue: addPreviousPeriod
|
|
34
|
+
} = useValueChanges(selectedPeriod);
|
|
35
|
+
const {
|
|
36
|
+
previousValue: previousPath,
|
|
37
|
+
newValue: newPath,
|
|
38
|
+
hasChanged: shouldUpdatePath,
|
|
39
|
+
addPreviousValue: addPreviousPath
|
|
40
|
+
} = useValueChanges(d);
|
|
41
|
+
const {
|
|
42
|
+
previousValue: previousArea,
|
|
43
|
+
newValue: newArea,
|
|
44
|
+
hasChanged: shouldUpdateArea,
|
|
45
|
+
addPreviousValue: addPreviousArea
|
|
46
|
+
} = useValueChanges(area != null ? area : '');
|
|
47
|
+
const pathInterpolator = useMemo(() => interpolate.interpolatePath(previousPath != null ? previousPath : initialPath, newPath), [previousPath, initialPath, newPath]);
|
|
48
|
+
const areaInterpolator = useMemo(() => interpolate.interpolatePath(previousArea != null ? previousArea : initialArea, newArea), [previousArea, initialArea, newArea]);
|
|
49
|
+
const animationListener = useCallback(_ref2 => {
|
|
50
|
+
var _pathRef$current, _areaRef$current;
|
|
51
|
+
let {
|
|
52
|
+
value
|
|
53
|
+
} = _ref2;
|
|
54
|
+
const val = Number(value.toFixed(4));
|
|
55
|
+
(_pathRef$current = pathRef.current) == null || _pathRef$current.setNativeProps({
|
|
56
|
+
d: pathInterpolator(val)
|
|
57
|
+
});
|
|
58
|
+
(_areaRef$current = areaRef.current) == null || _areaRef$current.setNativeProps({
|
|
59
|
+
d: areaInterpolator(val)
|
|
60
|
+
});
|
|
61
|
+
}, [areaInterpolator, pathInterpolator]);
|
|
62
|
+
const updatePathWithoutAnimation = useCallback(() => {
|
|
63
|
+
var _pathRef$current2, _areaRef$current2;
|
|
64
|
+
(_pathRef$current2 = pathRef.current) == null || _pathRef$current2.setNativeProps({
|
|
65
|
+
d: pathInterpolator(1)
|
|
66
|
+
});
|
|
67
|
+
(_areaRef$current2 = areaRef.current) == null || _areaRef$current2.setNativeProps({
|
|
68
|
+
d: areaInterpolator(1)
|
|
69
|
+
});
|
|
70
|
+
animateMinMaxIn.start();
|
|
71
|
+
}, [animateMinMaxIn, areaInterpolator, pathInterpolator]);
|
|
72
|
+
const playAnimation = useInterruptiblePathAnimation({
|
|
73
|
+
animationListener,
|
|
74
|
+
onInterrupt: updatePathWithoutAnimation
|
|
75
|
+
});
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
addPreviousPeriod(selectedPeriod);
|
|
78
|
+
}, [addPreviousPeriod, selectedPeriod]);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
// only update these values when they are used
|
|
81
|
+
addPreviousArea(newArea);
|
|
82
|
+
addPreviousPath(newPath);
|
|
83
|
+
if (shouldUpdatePath) {
|
|
84
|
+
if (isFallbackVisible) {
|
|
85
|
+
hideFallback();
|
|
86
|
+
updatePathWithoutAnimation();
|
|
87
|
+
} else if (skipAnimation) {
|
|
88
|
+
updatePathWithoutAnimation();
|
|
89
|
+
} else {
|
|
90
|
+
playAnimation();
|
|
91
|
+
}
|
|
92
|
+
} else if (shouldUpdateArea) {
|
|
93
|
+
updatePathWithoutAnimation();
|
|
94
|
+
}
|
|
95
|
+
}, [hideFallback, shouldUpdatePath, shouldUpdateArea, skipAnimation, updatePathWithoutAnimation, playAnimation, isFallbackVisible, addPreviousPath, addPreviousArea, newArea, newPath]);
|
|
96
|
+
const {
|
|
97
|
+
chartWidth,
|
|
98
|
+
chartHeight
|
|
99
|
+
} = useSparklineInteractiveConstants({
|
|
100
|
+
compact
|
|
101
|
+
});
|
|
102
|
+
return /*#__PURE__*/_jsx(Sparkline, {
|
|
103
|
+
ref: pathRef,
|
|
104
|
+
color: color,
|
|
105
|
+
fillType: fillType,
|
|
106
|
+
height: chartHeight,
|
|
107
|
+
path: initialPath,
|
|
108
|
+
strokeType: "solid",
|
|
109
|
+
width: chartWidth,
|
|
110
|
+
yAxisScalingFactor: yAxisScalingFactor,
|
|
111
|
+
children: !!area && /*#__PURE__*/_jsx(SparklineArea, {
|
|
112
|
+
ref: areaRef,
|
|
113
|
+
area: initialArea
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
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, useImperativeHandle, useMemo, useRef } from 'react';
|
|
3
|
+
import { Animated, StyleSheet, TextInput } from 'react-native';
|
|
4
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
5
|
+
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
6
|
+
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export function setTransform(x, elWidth, containerWidth, transform, gutter) {
|
|
9
|
+
let newX = x - elWidth / 2;
|
|
10
|
+
newX = Math.max(gutter, newX);
|
|
11
|
+
newX = Math.min(newX, containerWidth - elWidth - gutter);
|
|
12
|
+
transform.setValue({
|
|
13
|
+
x: newX,
|
|
14
|
+
y: 0
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const styles = StyleSheet.create({
|
|
18
|
+
outer: {
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
width: '100%'
|
|
22
|
+
},
|
|
23
|
+
caption: {
|
|
24
|
+
alignSelf: 'center',
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
left: 0
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const MAX_MEASURE_ITERATIONS = 5;
|
|
30
|
+
const SparklineInteractiveHoverDateWithGeneric = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
31
|
+
let {
|
|
32
|
+
formatHoverDate,
|
|
33
|
+
shouldTakeUpHeight
|
|
34
|
+
} = _ref;
|
|
35
|
+
const theme = useTheme();
|
|
36
|
+
const {
|
|
37
|
+
hoverDateOpacity,
|
|
38
|
+
gutter
|
|
39
|
+
} = useSparklineInteractiveContext();
|
|
40
|
+
const {
|
|
41
|
+
SparklineInteractiveMinMaxLabelHeight,
|
|
42
|
+
chartWidth
|
|
43
|
+
} = useSparklineInteractiveConstants({});
|
|
44
|
+
const transform = useRef(new Animated.ValueXY({
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0
|
|
47
|
+
})).current;
|
|
48
|
+
const textInputRef = useRef(null);
|
|
49
|
+
|
|
50
|
+
// period => number mapping
|
|
51
|
+
const measuredWidth = useRef({});
|
|
52
|
+
const measureIterations = useRef({});
|
|
53
|
+
// if we have no gutter the min/max label needs some space so it's not right up against the edge of the screen
|
|
54
|
+
const minGutter = gutter === 0 ? theme.space['1'] : 0;
|
|
55
|
+
useImperativeHandle(ref, () => ({
|
|
56
|
+
update: params => {
|
|
57
|
+
var _textInputRef$current, _measureIterations$cu;
|
|
58
|
+
const {
|
|
59
|
+
point: {
|
|
60
|
+
x,
|
|
61
|
+
date
|
|
62
|
+
},
|
|
63
|
+
period
|
|
64
|
+
} = params;
|
|
65
|
+
|
|
66
|
+
// the second conditional is to let typescript know x is always defined after this line
|
|
67
|
+
if (!Number.isFinite(x) || x === undefined) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const text = formatHoverDate == null ? void 0 : formatHoverDate(date, period);
|
|
71
|
+
if (!text) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// BAD: We only disabled this lint rule to enable eslint upgrade after this component was implemented. These apis should never be used.
|
|
76
|
+
// Usage in this component are known making this a high risk component. Contact team for more information.
|
|
77
|
+
|
|
78
|
+
(_textInputRef$current = textInputRef.current) == null || _textInputRef$current.setNativeProps({
|
|
79
|
+
text: formatHoverDate == null ? void 0 : formatHoverDate(date, period)
|
|
80
|
+
});
|
|
81
|
+
measureIterations.current[period] = (_measureIterations$cu = measureIterations.current[period]) != null ? _measureIterations$cu : 0;
|
|
82
|
+
if (measureIterations.current[period] > MAX_MEASURE_ITERATIONS) {
|
|
83
|
+
const currWidth = measuredWidth.current[period];
|
|
84
|
+
setTransform(x, currWidth, chartWidth, transform, minGutter);
|
|
85
|
+
} else {
|
|
86
|
+
var _textInputRef$current2;
|
|
87
|
+
(_textInputRef$current2 = textInputRef.current) == null || _textInputRef$current2.measure((ox, oy, width) => {
|
|
88
|
+
var _measuredWidth$curren;
|
|
89
|
+
measureIterations.current[period] += 1;
|
|
90
|
+
measuredWidth.current[period] = Math.max(width, (_measuredWidth$curren = measuredWidth.current[period]) != null ? _measuredWidth$curren : 0);
|
|
91
|
+
setTransform(x, measuredWidth.current[period], chartWidth, transform, minGutter);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
const rootStyle = useMemo(() => {
|
|
97
|
+
return _extends({
|
|
98
|
+
position: shouldTakeUpHeight ? 'relative' : 'absolute',
|
|
99
|
+
opacity: hoverDateOpacity,
|
|
100
|
+
backgroundColor: theme.color.bg,
|
|
101
|
+
height: SparklineInteractiveMinMaxLabelHeight
|
|
102
|
+
}, styles.outer);
|
|
103
|
+
}, [SparklineInteractiveMinMaxLabelHeight, hoverDateOpacity, shouldTakeUpHeight, theme.color.bg]);
|
|
104
|
+
const innerStyle = useMemo(() => {
|
|
105
|
+
return _extends({}, styles.caption, {
|
|
106
|
+
transform: transform.getTranslateTransform()
|
|
107
|
+
});
|
|
108
|
+
}, [transform]);
|
|
109
|
+
const textInputStyle = useMemo(() => {
|
|
110
|
+
return {
|
|
111
|
+
fontSize: theme.fontSize.label2,
|
|
112
|
+
lineHeight: theme.lineHeight.label2,
|
|
113
|
+
fontFamily: theme.fontFamily.label2,
|
|
114
|
+
color: theme.color.fgMuted
|
|
115
|
+
};
|
|
116
|
+
}, [theme.color.fgMuted, theme.fontFamily.label2, theme.fontSize.label2, theme.lineHeight.label2]);
|
|
117
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
118
|
+
pointerEvents: "none",
|
|
119
|
+
style: rootStyle,
|
|
120
|
+
children: /*#__PURE__*/_jsx(Animated.View, {
|
|
121
|
+
style: innerStyle,
|
|
122
|
+
children: /*#__PURE__*/_jsx(TextInput, {
|
|
123
|
+
ref: textInputRef,
|
|
124
|
+
accessibilityHint: "Text input field",
|
|
125
|
+
accessibilityLabel: "Text input field",
|
|
126
|
+
style: textInputStyle
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
export const SparklineInteractiveHoverDate = SparklineInteractiveHoverDateWithGeneric;
|
|
@@ -0,0 +1,99 @@
|
|
|
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 as RNAnimated, StyleSheet } from 'react-native';
|
|
4
|
+
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
5
|
+
import { Line, Svg } from 'react-native-svg';
|
|
6
|
+
import { maskOpacity } from '@coinbase/cds-common/tokens/sparkline';
|
|
7
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
8
|
+
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
9
|
+
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
10
|
+
import { useSparklineInteractiveLineStyles } from './useSparklineInteractiveLineStyles';
|
|
11
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
const styles = StyleSheet.create({
|
|
13
|
+
wrapper: _extends({}, StyleSheet.absoluteFillObject, {
|
|
14
|
+
zIndex: 2
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
const SparklineInteractiveDottedLine = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
color,
|
|
20
|
+
showHoverDate
|
|
21
|
+
} = _ref;
|
|
22
|
+
const theme = useTheme();
|
|
23
|
+
const {
|
|
24
|
+
markerXPosition,
|
|
25
|
+
compact
|
|
26
|
+
} = useSparklineInteractiveContext();
|
|
27
|
+
const {
|
|
28
|
+
lineProps
|
|
29
|
+
} = useSparklineInteractiveLineStyles();
|
|
30
|
+
const {
|
|
31
|
+
chartHeight,
|
|
32
|
+
SparklineInteractiveMinMaxLabelHeight,
|
|
33
|
+
chartVerticalLineWidth,
|
|
34
|
+
chartWidth
|
|
35
|
+
} = useSparklineInteractiveConstants({
|
|
36
|
+
compact
|
|
37
|
+
});
|
|
38
|
+
const dottedLineHeight = chartHeight + SparklineInteractiveMinMaxLabelHeight * (showHoverDate ? 1 : 2);
|
|
39
|
+
const lineStyles = useMemo(() => {
|
|
40
|
+
return {
|
|
41
|
+
width: chartVerticalLineWidth,
|
|
42
|
+
height: dottedLineHeight,
|
|
43
|
+
top: showHoverDate ? 0 : -SparklineInteractiveMinMaxLabelHeight,
|
|
44
|
+
zIndex: 2
|
|
45
|
+
};
|
|
46
|
+
}, [SparklineInteractiveMinMaxLabelHeight, chartVerticalLineWidth, dottedLineHeight, showHoverDate]);
|
|
47
|
+
const animatedTranslateX = useAnimatedStyle(() => ({
|
|
48
|
+
transform: [{
|
|
49
|
+
translateX: markerXPosition.value
|
|
50
|
+
}]
|
|
51
|
+
}));
|
|
52
|
+
const dottedLinePositionStyles = useMemo(() => [lineStyles, animatedTranslateX], [lineStyles, animatedTranslateX]);
|
|
53
|
+
const maskStyles = useMemo(() => {
|
|
54
|
+
return _extends({}, StyleSheet.absoluteFillObject, {
|
|
55
|
+
height: dottedLineHeight,
|
|
56
|
+
width: chartWidth,
|
|
57
|
+
top: showHoverDate ? 0 : -SparklineInteractiveMinMaxLabelHeight,
|
|
58
|
+
backgroundColor: theme.color.bg,
|
|
59
|
+
opacity: maskOpacity,
|
|
60
|
+
zIndex: 1
|
|
61
|
+
});
|
|
62
|
+
}, [SparklineInteractiveMinMaxLabelHeight, chartWidth, dottedLineHeight, showHoverDate, theme.color.bg]);
|
|
63
|
+
const maskPositionStyles = useMemo(() => [maskStyles, animatedTranslateX], [maskStyles, animatedTranslateX]);
|
|
64
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
65
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
66
|
+
style: dottedLinePositionStyles,
|
|
67
|
+
children: /*#__PURE__*/_jsx(Svg, {
|
|
68
|
+
children: /*#__PURE__*/_jsx(Line, _extends({}, lineProps, {
|
|
69
|
+
stroke: color,
|
|
70
|
+
y2: dottedLineHeight
|
|
71
|
+
}))
|
|
72
|
+
})
|
|
73
|
+
}), /*#__PURE__*/_jsx(Animated.View, {
|
|
74
|
+
style: maskPositionStyles
|
|
75
|
+
})]
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
export const SparklineInteractiveLineVertical = /*#__PURE__*/memo(_ref2 => {
|
|
79
|
+
let {
|
|
80
|
+
color,
|
|
81
|
+
showHoverDate
|
|
82
|
+
} = _ref2;
|
|
83
|
+
const {
|
|
84
|
+
markerOpacity
|
|
85
|
+
} = useSparklineInteractiveContext();
|
|
86
|
+
const rootStyle = useMemo(() => {
|
|
87
|
+
return _extends({}, styles.wrapper, {
|
|
88
|
+
opacity: markerOpacity
|
|
89
|
+
});
|
|
90
|
+
}, [markerOpacity]);
|
|
91
|
+
return /*#__PURE__*/_jsx(RNAnimated.View, {
|
|
92
|
+
pointerEvents: "none",
|
|
93
|
+
style: rootStyle,
|
|
94
|
+
children: /*#__PURE__*/_jsx(SparklineInteractiveDottedLine, {
|
|
95
|
+
color: color,
|
|
96
|
+
showHoverDate: showHoverDate
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
});
|