@coinbase/cds-mobile-visualization 3.8.1 → 4.0.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/CHANGELOG.md +8 -0
- package/dts/chart/index.d.ts +1 -15
- package/dts/chart/index.d.ts.map +1 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/index.d.ts +1 -5
- package/dts/sparkline/index.d.ts.map +1 -1
- package/esm/chart/index.js +1 -17
- package/esm/index.js +1 -3
- package/esm/sparkline/index.js +1 -5
- package/package.json +26 -20
- package/dts/chart/CartesianChart.d.ts +0 -206
- package/dts/chart/CartesianChart.d.ts.map +0 -1
- package/dts/chart/ChartContextBridge.d.ts +0 -28
- package/dts/chart/ChartContextBridge.d.ts.map +0 -1
- package/dts/chart/ChartProvider.d.ts +0 -9
- package/dts/chart/ChartProvider.d.ts.map +0 -1
- package/dts/chart/Path.d.ts +0 -121
- package/dts/chart/Path.d.ts.map +0 -1
- package/dts/chart/PeriodSelector.d.ts +0 -100
- package/dts/chart/PeriodSelector.d.ts.map +0 -1
- package/dts/chart/area/Area.d.ts +0 -83
- package/dts/chart/area/Area.d.ts.map +0 -1
- package/dts/chart/area/AreaChart.d.ts +0 -155
- package/dts/chart/area/AreaChart.d.ts.map +0 -1
- package/dts/chart/area/DottedArea.d.ts +0 -46
- package/dts/chart/area/DottedArea.d.ts.map +0 -1
- package/dts/chart/area/GradientArea.d.ts +0 -36
- package/dts/chart/area/GradientArea.d.ts.map +0 -1
- package/dts/chart/area/SolidArea.d.ts +0 -23
- package/dts/chart/area/SolidArea.d.ts.map +0 -1
- package/dts/chart/area/index.d.ts +0 -6
- package/dts/chart/area/index.d.ts.map +0 -1
- package/dts/chart/axis/Axis.d.ts +0 -174
- package/dts/chart/axis/Axis.d.ts.map +0 -1
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts +0 -8
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +0 -1
- package/dts/chart/axis/XAxis.d.ts +0 -22
- package/dts/chart/axis/XAxis.d.ts.map +0 -1
- package/dts/chart/axis/YAxis.d.ts +0 -22
- package/dts/chart/axis/YAxis.d.ts.map +0 -1
- package/dts/chart/axis/index.d.ts +0 -5
- package/dts/chart/axis/index.d.ts.map +0 -1
- package/dts/chart/bar/Bar.d.ts +0 -100
- package/dts/chart/bar/Bar.d.ts.map +0 -1
- package/dts/chart/bar/BarChart.d.ts +0 -158
- package/dts/chart/bar/BarChart.d.ts.map +0 -1
- package/dts/chart/bar/BarPlot.d.ts +0 -31
- package/dts/chart/bar/BarPlot.d.ts.map +0 -1
- package/dts/chart/bar/BarStack.d.ts +0 -127
- package/dts/chart/bar/BarStack.d.ts.map +0 -1
- package/dts/chart/bar/BarStackGroup.d.ts +0 -37
- package/dts/chart/bar/BarStackGroup.d.ts.map +0 -1
- package/dts/chart/bar/DefaultBar.d.ts +0 -7
- package/dts/chart/bar/DefaultBar.d.ts.map +0 -1
- package/dts/chart/bar/DefaultBarStack.d.ts +0 -7
- package/dts/chart/bar/DefaultBarStack.d.ts.map +0 -1
- package/dts/chart/bar/PercentageBarChart.d.ts +0 -106
- package/dts/chart/bar/PercentageBarChart.d.ts.map +0 -1
- package/dts/chart/bar/index.d.ts +0 -9
- package/dts/chart/bar/index.d.ts.map +0 -1
- package/dts/chart/gradient/Gradient.d.ts +0 -41
- package/dts/chart/gradient/Gradient.d.ts.map +0 -1
- package/dts/chart/gradient/index.d.ts +0 -2
- package/dts/chart/gradient/index.d.ts.map +0 -1
- package/dts/chart/legend/DefaultLegendEntry.d.ts +0 -5
- package/dts/chart/legend/DefaultLegendEntry.d.ts.map +0 -1
- package/dts/chart/legend/DefaultLegendShape.d.ts +0 -5
- package/dts/chart/legend/DefaultLegendShape.d.ts.map +0 -1
- package/dts/chart/legend/Legend.d.ts +0 -168
- package/dts/chart/legend/Legend.d.ts.map +0 -1
- package/dts/chart/legend/index.d.ts +0 -4
- package/dts/chart/legend/index.d.ts.map +0 -1
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts +0 -9
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +0 -1
- package/dts/chart/line/DottedLine.d.ts +0 -20
- package/dts/chart/line/DottedLine.d.ts.map +0 -1
- package/dts/chart/line/Line.d.ts +0 -122
- package/dts/chart/line/Line.d.ts.map +0 -1
- package/dts/chart/line/LineChart.d.ts +0 -135
- package/dts/chart/line/LineChart.d.ts.map +0 -1
- package/dts/chart/line/ReferenceLine.d.ts +0 -140
- package/dts/chart/line/ReferenceLine.d.ts.map +0 -1
- package/dts/chart/line/SolidLine.d.ts +0 -15
- package/dts/chart/line/SolidLine.d.ts.map +0 -1
- package/dts/chart/line/index.d.ts +0 -7
- package/dts/chart/line/index.d.ts.map +0 -1
- package/dts/chart/point/DefaultPointLabel.d.ts +0 -10
- package/dts/chart/point/DefaultPointLabel.d.ts.map +0 -1
- package/dts/chart/point/Point.d.ts +0 -144
- package/dts/chart/point/Point.d.ts.map +0 -1
- package/dts/chart/point/index.d.ts +0 -3
- package/dts/chart/point/index.d.ts.map +0 -1
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +0 -38
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +0 -1
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +0 -12
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +0 -1
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +0 -12
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +0 -1
- package/dts/chart/scrubber/Scrubber.d.ts +0 -302
- package/dts/chart/scrubber/Scrubber.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberAccessibilityView.d.ts +0 -12
- package/dts/chart/scrubber/ScrubberAccessibilityView.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +0 -54
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +0 -46
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberProvider.d.ts +0 -20
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +0 -1
- package/dts/chart/scrubber/index.d.ts +0 -5
- package/dts/chart/scrubber/index.d.ts.map +0 -1
- package/dts/chart/text/ChartText.d.ts +0 -164
- package/dts/chart/text/ChartText.d.ts.map +0 -1
- package/dts/chart/text/ChartTextGroup.d.ts +0 -61
- package/dts/chart/text/ChartTextGroup.d.ts.map +0 -1
- package/dts/chart/text/index.d.ts +0 -3
- package/dts/chart/text/index.d.ts.map +0 -1
- package/dts/chart/utils/axis.d.ts +0 -387
- package/dts/chart/utils/axis.d.ts.map +0 -1
- package/dts/chart/utils/bar.d.ts +0 -225
- package/dts/chart/utils/bar.d.ts.map +0 -1
- package/dts/chart/utils/chart.d.ts +0 -165
- package/dts/chart/utils/chart.d.ts.map +0 -1
- package/dts/chart/utils/context.d.ts +0 -131
- package/dts/chart/utils/context.d.ts.map +0 -1
- package/dts/chart/utils/gradient.d.ts +0 -129
- package/dts/chart/utils/gradient.d.ts.map +0 -1
- package/dts/chart/utils/index.d.ts +0 -11
- package/dts/chart/utils/index.d.ts.map +0 -1
- package/dts/chart/utils/path.d.ts +0 -186
- package/dts/chart/utils/path.d.ts.map +0 -1
- package/dts/chart/utils/point.d.ts +0 -146
- package/dts/chart/utils/point.d.ts.map +0 -1
- package/dts/chart/utils/scale.d.ts +0 -145
- package/dts/chart/utils/scale.d.ts.map +0 -1
- package/dts/chart/utils/scrubber.d.ts +0 -40
- package/dts/chart/utils/scrubber.d.ts.map +0 -1
- package/dts/chart/utils/transition.d.ts +0 -181
- package/dts/chart/utils/transition.d.ts.map +0 -1
- package/dts/sparkline/Counter.d.ts +0 -8
- package/dts/sparkline/Counter.d.ts.map +0 -1
- package/dts/sparkline/Sparkline.d.ts +0 -74
- package/dts/sparkline/Sparkline.d.ts.map +0 -1
- package/dts/sparkline/SparklineArea.d.ts +0 -15
- package/dts/sparkline/SparklineArea.d.ts.map +0 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +0 -14
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +0 -1
- package/dts/sparkline/SparklineGradient.d.ts +0 -24
- package/dts/sparkline/SparklineGradient.d.ts.map +0 -1
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +0 -2
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +0 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +0 -11
- package/dts/sparkline/generateSparklineWithId.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts +0 -23
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +0 -185
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +0 -25
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +0 -28
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +0 -13
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +0 -17
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +0 -11
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +0 -26
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +0 -25
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +0 -25
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +0 -39
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +0 -31
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +0 -13
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +0 -16
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +0 -6
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +0 -22
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +0 -34
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +0 -118
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +0 -29
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts.map +0 -1
- package/esm/chart/CartesianChart.js +0 -431
- package/esm/chart/ChartContextBridge.js +0 -159
- package/esm/chart/ChartProvider.js +0 -10
- package/esm/chart/Path.js +0 -255
- package/esm/chart/PeriodSelector.js +0 -139
- package/esm/chart/__stories__/CartesianChart.stories.js +0 -659
- package/esm/chart/__stories__/ChartAccessibility.stories.js +0 -721
- package/esm/chart/__stories__/ChartTransitions.stories.js +0 -693
- package/esm/chart/__stories__/PeriodSelector.stories.js +0 -420
- package/esm/chart/area/Area.js +0 -85
- package/esm/chart/area/AreaChart.js +0 -152
- package/esm/chart/area/DottedArea.js +0 -92
- package/esm/chart/area/GradientArea.js +0 -63
- package/esm/chart/area/SolidArea.js +0 -45
- package/esm/chart/area/__stories__/AreaChart.stories.js +0 -370
- package/esm/chart/area/index.js +0 -7
- package/esm/chart/axis/Axis.js +0 -9
- package/esm/chart/axis/DefaultAxisTickLabel.js +0 -11
- package/esm/chart/axis/XAxis.js +0 -256
- package/esm/chart/axis/YAxis.js +0 -255
- package/esm/chart/axis/__stories__/Axis.stories.js +0 -552
- package/esm/chart/axis/index.js +0 -6
- package/esm/chart/bar/Bar.js +0 -71
- package/esm/chart/bar/BarChart.js +0 -122
- package/esm/chart/bar/BarPlot.js +0 -106
- package/esm/chart/bar/BarStack.js +0 -173
- package/esm/chart/bar/BarStackGroup.js +0 -89
- package/esm/chart/bar/DefaultBar.js +0 -79
- package/esm/chart/bar/DefaultBarStack.js +0 -68
- package/esm/chart/bar/PercentageBarChart.js +0 -99
- package/esm/chart/bar/__stories__/BarChart.stories.js +0 -1417
- package/esm/chart/bar/__stories__/PercentageBarChart.stories.js +0 -833
- package/esm/chart/bar/index.js +0 -10
- package/esm/chart/gradient/Gradient.js +0 -156
- package/esm/chart/gradient/index.js +0 -1
- package/esm/chart/legend/DefaultLegendEntry.js +0 -42
- package/esm/chart/legend/DefaultLegendShape.js +0 -64
- package/esm/chart/legend/Legend.js +0 -59
- package/esm/chart/legend/__stories__/Legend.stories.js +0 -574
- package/esm/chart/legend/index.js +0 -3
- package/esm/chart/line/DefaultReferenceLineLabel.js +0 -66
- package/esm/chart/line/DottedLine.js +0 -57
- package/esm/chart/line/Line.js +0 -180
- package/esm/chart/line/LineChart.js +0 -149
- package/esm/chart/line/ReferenceLine.js +0 -132
- package/esm/chart/line/SolidLine.js +0 -53
- package/esm/chart/line/__stories__/LineChart.stories.js +0 -2018
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +0 -226
- package/esm/chart/line/index.js +0 -8
- package/esm/chart/point/DefaultPointLabel.js +0 -39
- package/esm/chart/point/Point.js +0 -187
- package/esm/chart/point/index.js +0 -2
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +0 -182
- package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +0 -43
- package/esm/chart/scrubber/DefaultScrubberLabel.js +0 -44
- package/esm/chart/scrubber/Scrubber.js +0 -198
- package/esm/chart/scrubber/ScrubberAccessibilityView.js +0 -177
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +0 -169
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +0 -212
- package/esm/chart/scrubber/ScrubberProvider.js +0 -140
- package/esm/chart/scrubber/__stories__/Scrubber.stories.js +0 -946
- package/esm/chart/scrubber/index.js +0 -4
- package/esm/chart/text/ChartText.js +0 -305
- package/esm/chart/text/ChartTextGroup.js +0 -211
- package/esm/chart/text/index.js +0 -4
- package/esm/chart/utils/axis.js +0 -664
- package/esm/chart/utils/bar.js +0 -906
- package/esm/chart/utils/chart.js +0 -329
- package/esm/chart/utils/context.js +0 -22
- package/esm/chart/utils/gradient.js +0 -319
- package/esm/chart/utils/index.js +0 -12
- package/esm/chart/utils/path.js +0 -304
- package/esm/chart/utils/point.js +0 -282
- package/esm/chart/utils/scale.js +0 -288
- package/esm/chart/utils/scrubber.js +0 -146
- package/esm/chart/utils/transition.js +0 -241
- package/esm/sparkline/Counter.js +0 -45
- package/esm/sparkline/Sparkline.js +0 -165
- package/esm/sparkline/SparklineArea.js +0 -20
- package/esm/sparkline/SparklineAreaPattern.js +0 -38
- package/esm/sparkline/SparklineGradient.js +0 -77
- package/esm/sparkline/__figma__/Sparkline.figma.js +0 -22
- package/esm/sparkline/__stories__/Sparkline.stories.js +0 -124
- package/esm/sparkline/__stories__/SparklineGradient.stories.js +0 -126
- package/esm/sparkline/generateSparklineWithId.js +0 -7
- package/esm/sparkline/sparkline-interactive/SparklineAccessibleView.js +0 -75
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +0 -308
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +0 -116
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +0 -131
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +0 -99
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +0 -82
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMinMax.js +0 -103
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.js +0 -104
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +0 -57
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +0 -124
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +0 -80
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +0 -109
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +0 -85
- package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +0 -526
- package/esm/sparkline/sparkline-interactive/useInterruptiblePathAnimation.js +0 -58
- package/esm/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.js +0 -37
- package/esm/sparkline/sparkline-interactive/useMinMaxTransform.js +0 -56
- package/esm/sparkline/sparkline-interactive/useOpacityAnimation.js +0 -23
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +0 -47
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.js +0 -34
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +0 -233
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +0 -104
- package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +0 -565
- package/esm/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.js +0 -117
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React, { memo, useCallback } from 'react';
|
|
2
|
-
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
import chunk from 'lodash/chunk';
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
const styles = StyleSheet.create({
|
|
6
|
-
container: {
|
|
7
|
-
flexDirection: 'row',
|
|
8
|
-
flex: 1,
|
|
9
|
-
position: 'absolute',
|
|
10
|
-
left: 0,
|
|
11
|
-
top: 0,
|
|
12
|
-
right: 0,
|
|
13
|
-
bottom: 0
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* SparklineAccessibleView renders an accessible view for Sparkline Chart.
|
|
19
|
-
*
|
|
20
|
-
* It chunks the sparkline data into 10 (or fewer) pieces, rendering each as a View with
|
|
21
|
-
* flex width proportional to the chunk size. The first data point in each chunk is used
|
|
22
|
-
* to generate an accessibilityLabel with the date and value.
|
|
23
|
-
*
|
|
24
|
-
* @param data - The sparkline data mapped by time period
|
|
25
|
-
* @param selectedPeriod - The currently selected time period
|
|
26
|
-
*/
|
|
27
|
-
export const SparklineAccessibleView = /*#__PURE__*/memo(function SparklineAccessibleView(_ref) {
|
|
28
|
-
let {
|
|
29
|
-
data,
|
|
30
|
-
selectedPeriod
|
|
31
|
-
} = _ref;
|
|
32
|
-
const chunkedData = data ? chunk(data[selectedPeriod], data[selectedPeriod].length / 10) : [];
|
|
33
|
-
// if the data is not evenly divisible by 10, the last chunk will be smaller than the rest
|
|
34
|
-
// so we need to combine it with the previous chunk
|
|
35
|
-
if (chunkedData.length === 11) {
|
|
36
|
-
const lastChunk = chunkedData.pop();
|
|
37
|
-
chunkedData[chunkedData.length - 1] = chunkedData[chunkedData.length - 1].concat(lastChunk != null ? lastChunk : []);
|
|
38
|
-
}
|
|
39
|
-
const getStyleByLength = useCallback(length => ({
|
|
40
|
-
flex: length
|
|
41
|
-
}), []);
|
|
42
|
-
return /*#__PURE__*/_jsx(View, {
|
|
43
|
-
style: styles.container,
|
|
44
|
-
children: chunkedData.map(dataChunk => {
|
|
45
|
-
// use the first data point in chunk for accessibility label
|
|
46
|
-
const item = dataChunk[0];
|
|
47
|
-
|
|
48
|
-
// only announce time for hour and day
|
|
49
|
-
const shouldAnnounceTime = selectedPeriod === 'hour' || selectedPeriod === 'day';
|
|
50
|
-
|
|
51
|
-
// Extract date formatting options
|
|
52
|
-
const timeOptions = {
|
|
53
|
-
hour: 'numeric',
|
|
54
|
-
minute: 'numeric',
|
|
55
|
-
hour12: true
|
|
56
|
-
};
|
|
57
|
-
const dateOptions = {
|
|
58
|
-
month: 'long',
|
|
59
|
-
day: 'numeric',
|
|
60
|
-
year: 'numeric'
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// TODO: localize date and time
|
|
64
|
-
const dateTime = item.date.toLocaleString('en-US', shouldAnnounceTime ? timeOptions : dateOptions);
|
|
65
|
-
const price = item.value.toFixed(2);
|
|
66
|
-
return /*#__PURE__*/_jsx(View, {
|
|
67
|
-
accessible: true,
|
|
68
|
-
accessibilityLabel: dateTime + ", $" + price
|
|
69
|
-
// variable width base on chunk length
|
|
70
|
-
,
|
|
71
|
-
style: getStyleByLength(dataChunk.length)
|
|
72
|
-
}, String(item.date));
|
|
73
|
-
})
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,308 +0,0 @@
|
|
|
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. This will be removed in a future major release.
|
|
306
|
-
* @deprecationExpectedRemoval v4
|
|
307
|
-
*/
|
|
308
|
-
export const SparklineInteractive = /*#__PURE__*/memo(SparklineInteractiveWithGeneric);
|
|
@@ -1,116 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,131 +0,0 @@
|
|
|
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;
|