@coinbase/cds-mobile-visualization 3.3.0 → 3.4.0-beta.2
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 +30 -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 +2 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/Counter.d.ts +7 -2
- package/dts/sparkline/Sparkline.d.ts +67 -16
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +10 -4
- package/dts/sparkline/SparklineArea.d.ts.map +1 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +12 -4
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
- package/dts/sparkline/SparklineGradient.d.ts +21 -10
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +1 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +8 -2
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
- package/dts/sparkline/index.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts +8 -3
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +132 -110
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +22 -9
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +18 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +9 -4
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +7 -5
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +22 -10
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +21 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +21 -16
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +29 -23
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +22 -14
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +9 -5
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +5 -2
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +17 -17
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +16 -13
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +106 -98
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +22 -19
- 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 -1
- package/esm/sparkline/Sparkline.js +129 -16
- package/esm/sparkline/SparklineArea.js +7 -2
- package/esm/sparkline/SparklineAreaPattern.js +4 -2
- package/esm/sparkline/SparklineGradient.js +4 -0
- package/esm/sparkline/generateSparklineWithId.js +3 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
- package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +27 -0
- package/package.json +11 -11
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts +0 -3
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts.map +0 -1
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts +0 -3
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -3
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -4
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts.map +0 -1
|
@@ -1,15 +1,20 @@
|
|
|
1
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, useRef } from 'react';
|
|
3
|
-
import { Defs, G, Path, Svg } from 'react-native-svg';
|
|
2
|
+
import React, { forwardRef, memo, useMemo, useRef } from 'react';
|
|
3
|
+
import { Defs, G, LinearGradient, Mask, Path, Rect, Stop, Svg } from 'react-native-svg';
|
|
4
|
+
import { getAccessibleForegroundGradient } from '@coinbase/cds-common/color/getAccessibleForegroundGradient';
|
|
4
5
|
import { borderWidth } from '@coinbase/cds-common/tokens/sparkline';
|
|
5
6
|
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
7
|
+
import { getSparklineRange } from '@coinbase/cds-common/visualizations/getSparklineRange';
|
|
6
8
|
import { getSparklineTransform } from '@coinbase/cds-common/visualizations/getSparklineTransform';
|
|
7
9
|
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
8
10
|
import { generateRandomId } from '@coinbase/cds-utils';
|
|
9
11
|
import { generateSparklineAreaWithId } from './generateSparklineWithId';
|
|
10
12
|
import { SparklineAreaPattern } from './SparklineAreaPattern';
|
|
11
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use LineChart instead.
|
|
16
|
+
*/
|
|
17
|
+
export const Sparkline = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
13
18
|
let {
|
|
14
19
|
background,
|
|
15
20
|
color,
|
|
@@ -17,35 +22,143 @@ export const Sparkline = /*#__PURE__*/memo(_ref => {
|
|
|
17
22
|
path,
|
|
18
23
|
width,
|
|
19
24
|
yAxisScalingFactor,
|
|
20
|
-
children
|
|
25
|
+
children,
|
|
26
|
+
strokeType = 'solid',
|
|
27
|
+
fillType = 'dotted'
|
|
21
28
|
} = _ref;
|
|
22
29
|
const theme = useTheme();
|
|
23
30
|
const patternId = useRef(generateRandomId());
|
|
24
|
-
const
|
|
31
|
+
const strokeColor = color !== 'auto' ? color : getAccessibleColor({
|
|
25
32
|
background: background != null ? background : theme.color.bg,
|
|
26
33
|
foreground: 'auto',
|
|
27
34
|
usage: 'graphic'
|
|
28
35
|
});
|
|
29
36
|
const translateProps = getSparklineTransform(width, height, yAxisScalingFactor);
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
const hasChildren = !!children;
|
|
38
|
+
const useModernFill = fillType === 'gradient' || fillType === 'gradientDotted';
|
|
39
|
+
|
|
40
|
+
// Stroke gradient (for strokeType='gradient')
|
|
41
|
+
const strokeGradient = useMemo(() => {
|
|
42
|
+
if (strokeType !== 'gradient') return null;
|
|
43
|
+
return getAccessibleForegroundGradient({
|
|
44
|
+
background: background != null ? background : theme.color.bg,
|
|
45
|
+
color,
|
|
46
|
+
colorScheme: theme.activeColorScheme,
|
|
47
|
+
usage: 'graphic'
|
|
48
|
+
});
|
|
49
|
+
}, [strokeType, background, color, theme]);
|
|
50
|
+
|
|
51
|
+
// Calculate gradient coordinates for modern fills
|
|
52
|
+
const {
|
|
53
|
+
gradientY1,
|
|
54
|
+
gradientY2
|
|
55
|
+
} = useMemo(() => {
|
|
56
|
+
if (!useModernFill) return {
|
|
57
|
+
gradientY1: 0,
|
|
58
|
+
gradientY2: 0
|
|
59
|
+
};
|
|
60
|
+
if (!Number.isFinite(yAxisScalingFactor)) {
|
|
61
|
+
return {
|
|
62
|
+
gradientY1: 2,
|
|
63
|
+
gradientY2: height - 2
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const {
|
|
67
|
+
yRange
|
|
68
|
+
} = getSparklineRange({
|
|
69
|
+
height,
|
|
70
|
+
width,
|
|
71
|
+
yAxisScalingFactor
|
|
72
|
+
});
|
|
73
|
+
const pathHeight = Math.abs(yRange[0] - yRange[1]);
|
|
74
|
+
const yTranslate = height / 2 - pathHeight / 2;
|
|
75
|
+
return {
|
|
76
|
+
gradientY1: yRange[1],
|
|
77
|
+
gradientY2: height - yTranslate
|
|
78
|
+
};
|
|
79
|
+
}, [useModernFill, height, width, yAxisScalingFactor]);
|
|
80
|
+
const maskGradientId = patternId.current + "-mask-gradient";
|
|
81
|
+
const maskId = patternId.current + "-mask";
|
|
82
|
+
const defs = useMemo(() => {
|
|
83
|
+
if (!strokeGradient && !hasChildren) return null;
|
|
84
|
+
return /*#__PURE__*/_jsxs(Defs, {
|
|
85
|
+
children: [strokeGradient && /*#__PURE__*/_jsx(LinearGradient, {
|
|
86
|
+
id: "gradient",
|
|
87
|
+
x1: "0%",
|
|
88
|
+
x2: "100%",
|
|
89
|
+
y1: "0%",
|
|
90
|
+
y2: "0%",
|
|
91
|
+
children: strokeGradient.map((item, i) => /*#__PURE__*/_jsx(Stop, {
|
|
92
|
+
offset: item.offset,
|
|
93
|
+
stopColor: item.color
|
|
94
|
+
}, i + "_" + item))
|
|
95
|
+
}), hasChildren && fillType === 'dotted' && /*#__PURE__*/_jsx(SparklineAreaPattern, {
|
|
96
|
+
color: strokeColor,
|
|
97
|
+
id: patternId.current
|
|
98
|
+
}), hasChildren && fillType === 'gradient' && /*#__PURE__*/_jsxs(LinearGradient, {
|
|
99
|
+
gradientUnits: "userSpaceOnUse",
|
|
100
|
+
id: patternId.current,
|
|
101
|
+
x1: "0",
|
|
102
|
+
x2: "0",
|
|
103
|
+
y1: gradientY1,
|
|
104
|
+
y2: gradientY2,
|
|
105
|
+
children: [/*#__PURE__*/_jsx(Stop, {
|
|
106
|
+
offset: "0%",
|
|
107
|
+
stopColor: strokeColor,
|
|
108
|
+
stopOpacity: 0.3
|
|
109
|
+
}), /*#__PURE__*/_jsx(Stop, {
|
|
110
|
+
offset: "100%",
|
|
111
|
+
stopColor: strokeColor,
|
|
112
|
+
stopOpacity: 0
|
|
113
|
+
})]
|
|
114
|
+
}), hasChildren && fillType === 'gradientDotted' && /*#__PURE__*/_jsxs(_Fragment, {
|
|
115
|
+
children: [/*#__PURE__*/_jsx(SparklineAreaPattern, {
|
|
116
|
+
color: strokeColor,
|
|
117
|
+
id: patternId.current,
|
|
118
|
+
opacity: 1
|
|
119
|
+
}), /*#__PURE__*/_jsxs(LinearGradient, {
|
|
120
|
+
gradientUnits: "userSpaceOnUse",
|
|
121
|
+
id: maskGradientId,
|
|
122
|
+
x1: "0",
|
|
123
|
+
x2: "0",
|
|
124
|
+
y1: gradientY1,
|
|
125
|
+
y2: gradientY2,
|
|
126
|
+
children: [/*#__PURE__*/_jsx(Stop, {
|
|
127
|
+
offset: "0%",
|
|
128
|
+
stopColor: "white",
|
|
129
|
+
stopOpacity: 1
|
|
130
|
+
}), /*#__PURE__*/_jsx(Stop, {
|
|
131
|
+
offset: "100%",
|
|
132
|
+
stopColor: "white",
|
|
133
|
+
stopOpacity: 0
|
|
134
|
+
})]
|
|
135
|
+
}), /*#__PURE__*/_jsx(Mask, {
|
|
136
|
+
id: maskId,
|
|
137
|
+
children: /*#__PURE__*/_jsx(Rect, {
|
|
138
|
+
fill: "url(#" + maskGradientId + ")",
|
|
139
|
+
height: height,
|
|
140
|
+
width: width
|
|
141
|
+
})
|
|
142
|
+
})]
|
|
143
|
+
})]
|
|
144
|
+
});
|
|
145
|
+
}, [strokeGradient, hasChildren, fillType, strokeColor, gradientY1, gradientY2, height, width, maskGradientId, maskId]);
|
|
146
|
+
const stroke = strokeType === 'gradient' ? 'url(#gradient)' : strokeColor;
|
|
147
|
+
const shouldPlaceDefsInside = useModernFill;
|
|
36
148
|
return /*#__PURE__*/_jsxs(Svg, {
|
|
37
149
|
fill: "none",
|
|
38
150
|
height: height,
|
|
39
151
|
width: width,
|
|
40
|
-
children: [defs, /*#__PURE__*/_jsxs(G, _extends({}, translateProps, {
|
|
41
|
-
children: [/*#__PURE__*/_jsx(Path, {
|
|
152
|
+
children: [!shouldPlaceDefsInside && defs, /*#__PURE__*/_jsxs(G, _extends({}, translateProps, {
|
|
153
|
+
children: [shouldPlaceDefsInside && defs, /*#__PURE__*/_jsx(Path, {
|
|
154
|
+
ref: ref,
|
|
42
155
|
d: path,
|
|
43
156
|
stroke: stroke,
|
|
44
157
|
strokeLinecap: "round",
|
|
45
158
|
strokeLinejoin: "round",
|
|
46
159
|
strokeWidth: borderWidth
|
|
47
|
-
}), generateSparklineAreaWithId(patternId.current, children)]
|
|
160
|
+
}), generateSparklineAreaWithId(patternId.current, children, fillType === 'gradientDotted' ? maskId : undefined)]
|
|
48
161
|
}))]
|
|
49
162
|
});
|
|
50
|
-
});
|
|
163
|
+
}));
|
|
51
164
|
Sparkline.displayName = 'Sparkline';
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import React, { forwardRef, memo } from 'react';
|
|
2
2
|
import { Path } from 'react-native-svg';
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use AreaChart instead.
|
|
6
|
+
*/
|
|
4
7
|
export const SparklineArea = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
5
8
|
let {
|
|
6
9
|
area,
|
|
7
|
-
patternId
|
|
10
|
+
patternId,
|
|
11
|
+
maskId
|
|
8
12
|
} = _ref;
|
|
9
13
|
return /*#__PURE__*/_jsx(Path, {
|
|
10
14
|
ref: ref,
|
|
11
15
|
d: area,
|
|
12
|
-
fill: "url(#" + patternId + ")"
|
|
16
|
+
fill: "url(#" + patternId + ")",
|
|
17
|
+
mask: maskId ? "url(#" + maskId + ")" : undefined
|
|
13
18
|
});
|
|
14
19
|
}));
|
|
@@ -6,12 +6,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
export const SparklineAreaPattern = _ref => {
|
|
7
7
|
let {
|
|
8
8
|
color,
|
|
9
|
-
id
|
|
9
|
+
id,
|
|
10
|
+
opacity
|
|
10
11
|
} = _ref;
|
|
11
12
|
const {
|
|
12
13
|
activeColorScheme
|
|
13
14
|
} = useTheme();
|
|
14
|
-
const
|
|
15
|
+
const themeOpacity = useSparklineAreaOpacity(activeColorScheme);
|
|
16
|
+
const fillOpacity = opacity != null ? opacity : themeOpacity;
|
|
15
17
|
return /*#__PURE__*/_jsx(Pattern, {
|
|
16
18
|
height: "4",
|
|
17
19
|
id: id,
|
|
@@ -9,6 +9,10 @@ import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
|
9
9
|
import { generateRandomId } from '@coinbase/cds-utils';
|
|
10
10
|
import { generateSparklineAreaWithId } from './generateSparklineWithId';
|
|
11
11
|
import { SparklineAreaPattern } from './SparklineAreaPattern';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use LineChart instead.
|
|
15
|
+
*/
|
|
12
16
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
17
|
export const SparklineGradient = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
14
18
|
let {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cloneElement } from 'react';
|
|
2
|
-
export function generateSparklineAreaWithId(id, children) {
|
|
2
|
+
export function generateSparklineAreaWithId(id, children, maskId) {
|
|
3
3
|
return children ? /*#__PURE__*/cloneElement(children, {
|
|
4
|
-
patternId: id
|
|
4
|
+
patternId: id,
|
|
5
|
+
maskId
|
|
5
6
|
}) : undefined;
|
|
6
7
|
}
|
|
@@ -97,6 +97,7 @@ function SparklineInteractiveContentWithGeneric(_ref3) {
|
|
|
97
97
|
hidePeriodSelector = false,
|
|
98
98
|
disableScrubbing = false,
|
|
99
99
|
fill = true,
|
|
100
|
+
fillType = 'gradient',
|
|
100
101
|
yAxisScalingFactor = 1.0,
|
|
101
102
|
formatHoverDate,
|
|
102
103
|
headerNode,
|
|
@@ -260,6 +261,7 @@ function SparklineInteractiveContentWithGeneric(_ref3) {
|
|
|
260
261
|
area: area,
|
|
261
262
|
compact: compact,
|
|
262
263
|
fill: fill,
|
|
264
|
+
fillType: fillType,
|
|
263
265
|
hoverData: hoverData,
|
|
264
266
|
path: path,
|
|
265
267
|
selectedPeriod: selectedPeriod,
|
|
@@ -299,5 +301,7 @@ function SparklineInteractiveWithGeneric(_ref4) {
|
|
|
299
301
|
});
|
|
300
302
|
}
|
|
301
303
|
|
|
302
|
-
|
|
304
|
+
/**
|
|
305
|
+
* @deprecated Use LineChart instead.
|
|
306
|
+
*/
|
|
303
307
|
export const SparklineInteractive = /*#__PURE__*/memo(SparklineInteractiveWithGeneric);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
2
|
import { useValueChanges } from '@coinbase/cds-common/hooks/useValueChanges';
|
|
3
3
|
import * as interpolate from 'd3-interpolate-path';
|
|
4
|
+
import { Sparkline } from '../Sparkline';
|
|
4
5
|
import { SparklineArea } from '../SparklineArea';
|
|
5
|
-
import { SparklineGradient } from '../SparklineGradient';
|
|
6
6
|
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
7
7
|
import { useInterruptiblePathAnimation } from './useInterruptiblePathAnimation';
|
|
8
8
|
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
@@ -13,6 +13,7 @@ export const SparklineInteractiveAnimatedPath = /*#__PURE__*/memo(_ref => {
|
|
|
13
13
|
color,
|
|
14
14
|
selectedPeriod,
|
|
15
15
|
area,
|
|
16
|
+
fillType = 'gradient',
|
|
16
17
|
yAxisScalingFactor,
|
|
17
18
|
initialPath,
|
|
18
19
|
initialArea
|
|
@@ -98,11 +99,13 @@ export const SparklineInteractiveAnimatedPath = /*#__PURE__*/memo(_ref => {
|
|
|
98
99
|
} = useSparklineInteractiveConstants({
|
|
99
100
|
compact
|
|
100
101
|
});
|
|
101
|
-
return /*#__PURE__*/_jsx(
|
|
102
|
+
return /*#__PURE__*/_jsx(Sparkline, {
|
|
102
103
|
ref: pathRef,
|
|
103
104
|
color: color,
|
|
105
|
+
fillType: fillType,
|
|
104
106
|
height: chartHeight,
|
|
105
107
|
path: initialPath,
|
|
108
|
+
strokeType: "solid",
|
|
106
109
|
width: chartWidth,
|
|
107
110
|
yAxisScalingFactor: yAxisScalingFactor,
|
|
108
111
|
children: !!area && /*#__PURE__*/_jsx(SparklineArea, {
|
|
@@ -7,6 +7,7 @@ function SparklineInteractivePathsWithGeneric(_ref) {
|
|
|
7
7
|
let {
|
|
8
8
|
showHoverData,
|
|
9
9
|
fill,
|
|
10
|
+
fillType = 'gradient',
|
|
10
11
|
path,
|
|
11
12
|
area,
|
|
12
13
|
selectedPeriod,
|
|
@@ -15,6 +16,8 @@ function SparklineInteractivePathsWithGeneric(_ref) {
|
|
|
15
16
|
hoverData,
|
|
16
17
|
compact
|
|
17
18
|
} = _ref;
|
|
19
|
+
// Map 'dotted' to 'gradientDotted' for Sparkline
|
|
20
|
+
const sparklineFillType = fillType === 'dotted' ? 'gradientDotted' : 'gradient';
|
|
18
21
|
const hoverPathRef = useRef(undefined);
|
|
19
22
|
const hoverAreaRef = useRef(undefined);
|
|
20
23
|
const shouldShowFill = !!fill;
|
|
@@ -37,6 +40,7 @@ function SparklineInteractivePathsWithGeneric(_ref) {
|
|
|
37
40
|
area: shouldShowFill ? area : undefined,
|
|
38
41
|
color: strokeColor,
|
|
39
42
|
d: path,
|
|
43
|
+
fillType: sparklineFillType,
|
|
40
44
|
initialArea: hoverAreaRef.current,
|
|
41
45
|
initialPath: hoverPathRef.current,
|
|
42
46
|
selectedPeriod: selectedPeriod,
|
|
@@ -468,6 +468,33 @@ const SparklineInteractiveScreen = () => {
|
|
|
468
468
|
}
|
|
469
469
|
})]
|
|
470
470
|
})
|
|
471
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
472
|
+
padding: 0,
|
|
473
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
|
474
|
+
children: [/*#__PURE__*/_jsx(TextTitle3, {
|
|
475
|
+
paddingX: 3,
|
|
476
|
+
paddingY: 3,
|
|
477
|
+
children: "Dotted Fill Type"
|
|
478
|
+
}), /*#__PURE__*/_jsx(SparklineInteractiveBuild, {
|
|
479
|
+
data: sparklineInteractiveData,
|
|
480
|
+
fillType: "dotted",
|
|
481
|
+
strokeColor: strokeColor
|
|
482
|
+
})]
|
|
483
|
+
})
|
|
484
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
485
|
+
padding: 0,
|
|
486
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
|
487
|
+
children: [/*#__PURE__*/_jsx(TextTitle3, {
|
|
488
|
+
paddingX: 3,
|
|
489
|
+
paddingY: 3,
|
|
490
|
+
children: "Y Scale Custom"
|
|
491
|
+
}), /*#__PURE__*/_jsx(SparklineInteractiveBuild, {
|
|
492
|
+
data: sparklineInteractiveData,
|
|
493
|
+
fillType: "dotted",
|
|
494
|
+
strokeColor: strokeColor,
|
|
495
|
+
yAxisScalingFactor: 0.1
|
|
496
|
+
})]
|
|
497
|
+
})
|
|
471
498
|
})]
|
|
472
499
|
});
|
|
473
500
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cds-mobile-visualization",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.2",
|
|
4
4
|
"description": "Coinbase Design System - Mobile Visualization Native",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git@github.com:coinbase/cds
|
|
7
|
+
"url": "git@github.com:coinbase/cds.git",
|
|
8
8
|
"directory": "packages/mobile-visualization"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"CHANGELOG"
|
|
33
33
|
],
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@coinbase/cds-common": "
|
|
36
|
-
"@coinbase/cds-lottie-files": "
|
|
37
|
-
"@coinbase/cds-mobile": "
|
|
38
|
-
"@coinbase/cds-utils": "
|
|
35
|
+
"@coinbase/cds-common": "^8.14.0",
|
|
36
|
+
"@coinbase/cds-lottie-files": "^3.3.2",
|
|
37
|
+
"@coinbase/cds-mobile": "^8.14.0",
|
|
38
|
+
"@coinbase/cds-utils": "^2.3.3",
|
|
39
39
|
"react": "^18.3.1",
|
|
40
40
|
"react-native": "^0.74.5",
|
|
41
41
|
"react-native-gesture-handler": "^2.16.2",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"@babel/preset-env": "^7.28.0",
|
|
53
53
|
"@babel/preset-react": "^7.27.1",
|
|
54
54
|
"@babel/preset-typescript": "^7.27.1",
|
|
55
|
-
"@coinbase/cds-common": "
|
|
56
|
-
"@coinbase/cds-lottie-files": "
|
|
57
|
-
"@coinbase/cds-mobile": "
|
|
58
|
-
"@coinbase/cds-utils": "
|
|
55
|
+
"@coinbase/cds-common": "^8.14.0",
|
|
56
|
+
"@coinbase/cds-lottie-files": "^3.3.2",
|
|
57
|
+
"@coinbase/cds-mobile": "^8.14.0",
|
|
58
|
+
"@coinbase/cds-utils": "^2.3.3",
|
|
59
59
|
"@figma/code-connect": "^1.3.4",
|
|
60
60
|
"@types/react": "^18.3.12",
|
|
61
61
|
"react-native-gesture-handler": "2.16.2",
|
|
@@ -64,4 +64,4 @@
|
|
|
64
64
|
"react-native-svg": "14.1.0",
|
|
65
65
|
"react-test-renderer": "^18.3.1"
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Sparkline.stories.d.ts","sourceRoot":"","sources":["../../../src/sparkline/__stories__/Sparkline.stories.tsx"],"names":[],"mappings":"AAgGA,QAAA,MAAM,sBAAsB,+CAwB3B,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineGradient.stories.d.ts","sourceRoot":"","sources":["../../../src/sparkline/__stories__/SparklineGradient.stories.tsx"],"names":[],"mappings":"AA6FA,QAAA,MAAM,sBAAsB,+CA+B3B,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineInteractive.stories.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.tsx"],"names":[],"mappings":"AAsPA,QAAA,MAAM,0BAA0B,+CAqQ/B,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineInteractive.test.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.tsx"],"names":[],"mappings":""}
|
package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineInteractiveHoverDate.test.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineInteractivePanGestureHandler.test.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineInteractivePeriodSelector.test.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineInteractiveTimeseriesPaths.test.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMinMaxTransform.test.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.ts"],"names":[],"mappings":""}
|
package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInterruptiblePathAnimation.test.disable.d.ts","sourceRoot":"","sources":["../../../src/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const SparklineInteractiveHeaderWithCustomTitle: () => import("react/jsx-runtime").JSX.Element;
|
|
2
|
-
declare const SparklineInteractiveHeaderScreen: () => import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
export default SparklineInteractiveHeaderScreen;
|
|
4
|
-
//# sourceMappingURL=SparklineInteractiveHeader.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineInteractiveHeader.stories.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.tsx"],"names":[],"mappings":"AA8aA,eAAO,MAAM,yCAAyC,+CAuFrD,CAAC;AAEF,QAAA,MAAM,gCAAgC,+CA2FrC,CAAC;AAEF,eAAe,gCAAgC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SparklineInteractiveHeader.test.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSparklineInteractiveHeaderStyles.test.d.ts","sourceRoot":"","sources":["../../../../src/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.ts"],"names":[],"mappings":""}
|