@coinbase/cds-web-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 +36 -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 +34 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +61 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/Point.d.ts +153 -0
- package/dts/chart/Point.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +48 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +52 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +68 -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 +208 -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 +91 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +53 -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 +17 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +16 -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 +14 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/GradientLine.d.ts +42 -0
- package/dts/chart/line/GradientLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +80 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +59 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +131 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +14 -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 +149 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +93 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +7 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.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 +114 -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 +61 -16
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +12 -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/SparklinePath.d.ts +8 -6
- 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/InnerSparklineInteractiveProvider.d.ts +9 -5
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +168 -118
- 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 +4 -2
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +4 -2
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +5 -3
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
- 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 +17 -12
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +23 -10
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +12 -12
- 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/fade.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +11 -11
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +101 -93
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
- package/esm/chart/CartesianChart.css +1 -0
- package/esm/chart/CartesianChart.js +258 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +89 -0
- package/esm/chart/PeriodSelector.css +1 -0
- package/esm/chart/PeriodSelector.js +126 -0
- package/esm/chart/Point.css +2 -0
- package/esm/chart/Point.js +171 -0
- package/esm/chart/area/Area.js +85 -0
- package/esm/chart/area/AreaChart.js +164 -0
- package/esm/chart/area/DottedArea.js +141 -0
- package/esm/chart/area/GradientArea.js +111 -0
- package/esm/chart/area/SolidArea.js +29 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +46 -0
- package/esm/chart/axis/XAxis.css +2 -0
- package/esm/chart/axis/XAxis.js +195 -0
- package/esm/chart/axis/YAxis.css +2 -0
- package/esm/chart/axis/YAxis.js +183 -0
- package/esm/chart/axis/index.js +5 -0
- package/esm/chart/bar/Bar.js +59 -0
- package/esm/chart/bar/BarChart.js +147 -0
- package/esm/chart/bar/BarPlot.js +96 -0
- package/esm/chart/bar/BarStack.js +519 -0
- package/esm/chart/bar/BarStackGroup.js +96 -0
- package/esm/chart/bar/DefaultBar.js +64 -0
- package/esm/chart/bar/DefaultBarStack.js +60 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/index.js +14 -0
- package/esm/chart/line/DottedLine.js +38 -0
- package/esm/chart/line/GradientLine.js +58 -0
- package/esm/chart/line/Line.js +159 -0
- package/esm/chart/line/LineChart.js +120 -0
- package/esm/chart/line/ReferenceLine.js +142 -0
- package/esm/chart/line/SolidLine.js +34 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/scrubber/Scrubber.js +483 -0
- package/esm/chart/scrubber/ScrubberBeacon.js +195 -0
- package/esm/chart/scrubber/ScrubberBeaconLabel.js +33 -0
- package/esm/chart/scrubber/ScrubberProvider.js +228 -0
- package/esm/chart/scrubber/index.js +2 -0
- package/esm/chart/text/ChartText.js +236 -0
- package/esm/chart/text/SmartChartTextGroup.js +226 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +593 -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 +204 -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 -15
- package/esm/sparkline/SparklineArea.js +7 -2
- package/esm/sparkline/SparklineAreaPattern.js +4 -2
- package/esm/sparkline/SparklineGradient.js +16 -58
- 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/package.json +15 -11
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -374
- 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__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -87
- 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
|
@@ -3,16 +3,21 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
3
3
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
5
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
-
import React, { memo, useRef } from 'react';
|
|
6
|
+
import React, { forwardRef, memo, useId, useMemo, useRef } from 'react';
|
|
7
|
+
import { getAccessibleForegroundGradient } from '@coinbase/cds-common/color/getAccessibleForegroundGradient';
|
|
7
8
|
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
9
|
+
import { getSparklineRange } from '@coinbase/cds-common/visualizations/getSparklineRange';
|
|
8
10
|
import { getSparklineTransform } from '@coinbase/cds-common/visualizations/getSparklineTransform';
|
|
9
11
|
import { generateRandomId } from '@coinbase/cds-utils';
|
|
10
12
|
import { useTheme } from '@coinbase/cds-web/hooks/useTheme';
|
|
11
13
|
import { generateSparklineAreaWithId } from './generateSparklineWithId';
|
|
12
14
|
import { SparklineAreaPattern } from './SparklineAreaPattern';
|
|
13
15
|
import { SparklinePath } from './SparklinePath';
|
|
14
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
-
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use LineChart instead.
|
|
19
|
+
*/
|
|
20
|
+
export const Sparkline = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
16
21
|
let {
|
|
17
22
|
background,
|
|
18
23
|
color,
|
|
@@ -20,31 +25,140 @@ export const Sparkline = /*#__PURE__*/memo(_ref => {
|
|
|
20
25
|
path,
|
|
21
26
|
width,
|
|
22
27
|
yAxisScalingFactor,
|
|
23
|
-
children
|
|
28
|
+
children,
|
|
29
|
+
strokeType = 'solid',
|
|
30
|
+
fillType = 'dotted'
|
|
24
31
|
} = _ref;
|
|
25
32
|
const theme = useTheme();
|
|
26
33
|
const patternId = useRef(generateRandomId());
|
|
27
|
-
const
|
|
34
|
+
const strokeColor = color !== 'auto' ? color : getAccessibleColor({
|
|
28
35
|
background: background !== null && background !== void 0 ? background : theme.color.bg,
|
|
29
36
|
foreground: 'auto',
|
|
30
37
|
usage: 'graphic'
|
|
31
38
|
});
|
|
32
39
|
const translateProps = getSparklineTransform(width, height, yAxisScalingFactor);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
const hasChildren = !!children;
|
|
41
|
+
const useModernFill = fillType === 'gradient' || fillType === 'gradientDotted';
|
|
42
|
+
|
|
43
|
+
// Stroke gradient (for strokeType='gradient')
|
|
44
|
+
const strokeGradient = useMemo(() => {
|
|
45
|
+
if (strokeType !== 'gradient') return null;
|
|
46
|
+
return getAccessibleForegroundGradient({
|
|
47
|
+
background: background !== null && background !== void 0 ? background : theme.color.bg,
|
|
48
|
+
color,
|
|
49
|
+
colorScheme: theme.activeColorScheme,
|
|
50
|
+
usage: 'graphic'
|
|
51
|
+
});
|
|
52
|
+
}, [strokeType, background, color, theme]);
|
|
53
|
+
|
|
54
|
+
// Calculate gradient coordinates for modern fills
|
|
55
|
+
const {
|
|
56
|
+
gradientY1,
|
|
57
|
+
gradientY2
|
|
58
|
+
} = useMemo(() => {
|
|
59
|
+
if (!useModernFill) return {
|
|
60
|
+
gradientY1: 0,
|
|
61
|
+
gradientY2: 0
|
|
62
|
+
};
|
|
63
|
+
if (!Number.isFinite(yAxisScalingFactor)) {
|
|
64
|
+
return {
|
|
65
|
+
gradientY1: 2,
|
|
66
|
+
gradientY2: height - 2
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const {
|
|
70
|
+
yRange
|
|
71
|
+
} = getSparklineRange({
|
|
72
|
+
height,
|
|
73
|
+
width,
|
|
74
|
+
yAxisScalingFactor
|
|
75
|
+
});
|
|
76
|
+
const pathHeight = Math.abs(yRange[0] - yRange[1]);
|
|
77
|
+
const yTranslate = height / 2 - pathHeight / 2;
|
|
78
|
+
return {
|
|
79
|
+
gradientY1: yRange[1],
|
|
80
|
+
gradientY2: height - yTranslate
|
|
81
|
+
};
|
|
82
|
+
}, [useModernFill, height, width, yAxisScalingFactor]);
|
|
83
|
+
const strokeGradientId = useId();
|
|
84
|
+
const maskGradientId = "".concat(patternId.current, "-mask-gradient");
|
|
85
|
+
const maskId = "".concat(patternId.current, "-mask");
|
|
86
|
+
const defs = useMemo(() => {
|
|
87
|
+
if (!strokeGradient && !hasChildren) return null;
|
|
88
|
+
return /*#__PURE__*/_jsxs("defs", {
|
|
89
|
+
children: [strokeGradient && /*#__PURE__*/_jsx("linearGradient", {
|
|
90
|
+
id: strokeGradientId,
|
|
91
|
+
x1: "0%",
|
|
92
|
+
x2: "100%",
|
|
93
|
+
y1: "0%",
|
|
94
|
+
y2: "0%",
|
|
95
|
+
children: strokeGradient.map((item, i) => /*#__PURE__*/_jsx("stop", {
|
|
96
|
+
offset: item.offset,
|
|
97
|
+
stopColor: item.color
|
|
98
|
+
}, "".concat(i, "_").concat(item)))
|
|
99
|
+
}), hasChildren && fillType === 'dotted' && /*#__PURE__*/_jsx(SparklineAreaPattern, {
|
|
100
|
+
color: strokeColor,
|
|
101
|
+
id: patternId.current
|
|
102
|
+
}), hasChildren && fillType === 'gradient' && /*#__PURE__*/_jsxs("linearGradient", {
|
|
103
|
+
gradientUnits: "userSpaceOnUse",
|
|
104
|
+
id: patternId.current,
|
|
105
|
+
x1: "0",
|
|
106
|
+
x2: "0",
|
|
107
|
+
y1: gradientY1,
|
|
108
|
+
y2: gradientY2,
|
|
109
|
+
children: [/*#__PURE__*/_jsx("stop", {
|
|
110
|
+
offset: "0%",
|
|
111
|
+
stopColor: strokeColor,
|
|
112
|
+
stopOpacity: 0.3
|
|
113
|
+
}), /*#__PURE__*/_jsx("stop", {
|
|
114
|
+
offset: "100%",
|
|
115
|
+
stopColor: strokeColor,
|
|
116
|
+
stopOpacity: 0
|
|
117
|
+
})]
|
|
118
|
+
}), hasChildren && fillType === 'gradientDotted' && /*#__PURE__*/_jsxs(_Fragment, {
|
|
119
|
+
children: [/*#__PURE__*/_jsx(SparklineAreaPattern, {
|
|
120
|
+
color: strokeColor,
|
|
121
|
+
id: patternId.current,
|
|
122
|
+
opacity: 1
|
|
123
|
+
}), /*#__PURE__*/_jsxs("linearGradient", {
|
|
124
|
+
gradientUnits: "userSpaceOnUse",
|
|
125
|
+
id: maskGradientId,
|
|
126
|
+
x1: "0",
|
|
127
|
+
x2: "0",
|
|
128
|
+
y1: gradientY1,
|
|
129
|
+
y2: gradientY2,
|
|
130
|
+
children: [/*#__PURE__*/_jsx("stop", {
|
|
131
|
+
offset: "0%",
|
|
132
|
+
stopColor: "white",
|
|
133
|
+
stopOpacity: 1
|
|
134
|
+
}), /*#__PURE__*/_jsx("stop", {
|
|
135
|
+
offset: "100%",
|
|
136
|
+
stopColor: "white",
|
|
137
|
+
stopOpacity: 0
|
|
138
|
+
})]
|
|
139
|
+
}), /*#__PURE__*/_jsx("mask", {
|
|
140
|
+
id: maskId,
|
|
141
|
+
children: /*#__PURE__*/_jsx("rect", {
|
|
142
|
+
fill: "url(#".concat(maskGradientId, ")"),
|
|
143
|
+
height: height,
|
|
144
|
+
width: width
|
|
145
|
+
})
|
|
146
|
+
})]
|
|
147
|
+
})]
|
|
148
|
+
});
|
|
149
|
+
}, [strokeGradient, strokeGradientId, hasChildren, fillType, strokeColor, gradientY1, gradientY2, height, width, maskGradientId, maskId]);
|
|
150
|
+
const stroke = strokeType === 'gradient' ? "url(#".concat(strokeGradientId, ")") : strokeColor;
|
|
151
|
+
const shouldPlaceDefsInside = useModernFill;
|
|
39
152
|
return /*#__PURE__*/_jsxs("svg", {
|
|
40
153
|
height: height,
|
|
41
154
|
width: width,
|
|
42
|
-
children: [defs, /*#__PURE__*/_jsxs("g", _objectSpread(_objectSpread({}, translateProps), {}, {
|
|
43
|
-
children: [/*#__PURE__*/_jsx(SparklinePath, {
|
|
155
|
+
children: [!shouldPlaceDefsInside && defs, /*#__PURE__*/_jsxs("g", _objectSpread(_objectSpread({}, translateProps), {}, {
|
|
156
|
+
children: [shouldPlaceDefsInside && defs, /*#__PURE__*/_jsx(SparklinePath, {
|
|
157
|
+
ref: ref,
|
|
44
158
|
path: path,
|
|
45
159
|
stroke: stroke
|
|
46
|
-
}), generateSparklineAreaWithId(patternId.current, children)]
|
|
160
|
+
}), generateSparklineAreaWithId(patternId.current, children, fillType === 'gradientDotted' ? maskId : undefined)]
|
|
47
161
|
}))]
|
|
48
162
|
});
|
|
49
|
-
});
|
|
163
|
+
}));
|
|
50
164
|
Sparkline.displayName = 'Sparkline';
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import React, { forwardRef, memo } from 'react';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use AreaChart instead.
|
|
5
|
+
*/
|
|
3
6
|
export const SparklineArea = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
4
7
|
let {
|
|
5
8
|
area,
|
|
6
|
-
patternId
|
|
9
|
+
patternId,
|
|
10
|
+
maskId
|
|
7
11
|
} = _ref;
|
|
8
12
|
return /*#__PURE__*/_jsx("path", {
|
|
9
13
|
ref: ref,
|
|
10
14
|
d: area,
|
|
11
|
-
fill: "url(#".concat(patternId, ")")
|
|
15
|
+
fill: "url(#".concat(patternId, ")"),
|
|
16
|
+
mask: maskId ? "url(#".concat(maskId, ")") : undefined
|
|
12
17
|
});
|
|
13
18
|
}));
|
|
@@ -5,12 +5,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
export const SparklineAreaPattern = _ref => {
|
|
6
6
|
let {
|
|
7
7
|
color,
|
|
8
|
-
id
|
|
8
|
+
id,
|
|
9
|
+
opacity
|
|
9
10
|
} = _ref;
|
|
10
11
|
const {
|
|
11
12
|
activeColorScheme
|
|
12
13
|
} = useTheme();
|
|
13
|
-
const
|
|
14
|
+
const themeOpacity = useSparklineAreaOpacity(activeColorScheme);
|
|
15
|
+
const fillOpacity = opacity !== null && opacity !== void 0 ? opacity : themeOpacity;
|
|
14
16
|
return /*#__PURE__*/_jsx("pattern", {
|
|
15
17
|
height: "4",
|
|
16
18
|
id: id,
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
9
|
-
import { getSparklineTransform } from '@coinbase/cds-common/visualizations/getSparklineTransform';
|
|
10
|
-
import { generateRandomId } from '@coinbase/cds-utils';
|
|
11
|
-
import { useTheme } from '@coinbase/cds-web/hooks/useTheme';
|
|
12
|
-
import { generateSparklineAreaWithId } from './generateSparklineWithId';
|
|
13
|
-
import { SparklineAreaPattern } from './SparklineAreaPattern';
|
|
14
|
-
import { SparklinePath } from './SparklinePath';
|
|
15
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
-
export const SparklineGradient = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, forwardedRef) => {
|
|
1
|
+
import React, { forwardRef, memo } from 'react';
|
|
2
|
+
import { Sparkline } from './Sparkline';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use LineChart instead.
|
|
6
|
+
*/
|
|
7
|
+
export const SparklineGradient = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
17
8
|
let {
|
|
18
9
|
background,
|
|
19
10
|
color,
|
|
@@ -23,50 +14,17 @@ export const SparklineGradient = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref
|
|
|
23
14
|
yAxisScalingFactor,
|
|
24
15
|
children
|
|
25
16
|
} = _ref;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
colorScheme: theme.activeColorScheme,
|
|
32
|
-
usage: 'graphic'
|
|
33
|
-
});
|
|
34
|
-
const areaColor = color !== 'auto' ? color : getAccessibleColor({
|
|
35
|
-
background: background !== null && background !== void 0 ? background : theme.color.bg,
|
|
36
|
-
foreground: 'auto',
|
|
37
|
-
usage: 'graphic'
|
|
38
|
-
});
|
|
39
|
-
const gradientId = useId();
|
|
40
|
-
const translateProps = getSparklineTransform(width, height, yAxisScalingFactor);
|
|
41
|
-
const hasChildren = !!children;
|
|
42
|
-
const linearGradient = useMemo(() => {
|
|
43
|
-
return /*#__PURE__*/_jsxs("defs", {
|
|
44
|
-
children: [/*#__PURE__*/_jsx("linearGradient", {
|
|
45
|
-
id: gradientId,
|
|
46
|
-
x1: "0%",
|
|
47
|
-
x2: "100%",
|
|
48
|
-
y1: "0%",
|
|
49
|
-
y2: "0%",
|
|
50
|
-
children: gradient.map((item, i) => /*#__PURE__*/_jsx("stop", {
|
|
51
|
-
offset: item.offset,
|
|
52
|
-
stopColor: item.color
|
|
53
|
-
}, "".concat(i, "_").concat(item)))
|
|
54
|
-
}), hasChildren && /*#__PURE__*/_jsx(SparklineAreaPattern, {
|
|
55
|
-
color: areaColor,
|
|
56
|
-
id: patternId.current
|
|
57
|
-
})]
|
|
58
|
-
});
|
|
59
|
-
}, [gradientId, gradient, hasChildren, areaColor]);
|
|
60
|
-
return /*#__PURE__*/_jsxs("svg", {
|
|
17
|
+
return /*#__PURE__*/_jsx(Sparkline, {
|
|
18
|
+
ref: ref,
|
|
19
|
+
background: background,
|
|
20
|
+
color: color,
|
|
21
|
+
fillType: "dotted",
|
|
61
22
|
height: height,
|
|
23
|
+
path: path,
|
|
24
|
+
strokeType: "gradient",
|
|
62
25
|
width: width,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
ref: forwardedRef,
|
|
66
|
-
path: path,
|
|
67
|
-
stroke: "url(#".concat(gradientId, ")")
|
|
68
|
-
}), generateSparklineAreaWithId(patternId.current, children)]
|
|
69
|
-
}))]
|
|
26
|
+
yAxisScalingFactor: yAxisScalingFactor,
|
|
27
|
+
children: children
|
|
70
28
|
});
|
|
71
29
|
}));
|
|
72
30
|
SparklineGradient.displayName = 'SparklineGradient';
|
|
@@ -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
|
}
|
|
@@ -67,6 +67,7 @@ function SparklineInteractiveContentWithGeneric(_ref2) {
|
|
|
67
67
|
hidePeriodSelector = false,
|
|
68
68
|
disableScrubbing = false,
|
|
69
69
|
fill = true,
|
|
70
|
+
fillType = 'gradient',
|
|
70
71
|
yAxisScalingFactor = 1.0,
|
|
71
72
|
compact,
|
|
72
73
|
formatHoverDate,
|
|
@@ -248,6 +249,7 @@ function SparklineInteractiveContentWithGeneric(_ref2) {
|
|
|
248
249
|
area: area,
|
|
249
250
|
compact: compact,
|
|
250
251
|
fill: fill,
|
|
252
|
+
fillType: fillType,
|
|
251
253
|
hoverData: hoverData,
|
|
252
254
|
path: path,
|
|
253
255
|
selectedPeriod: selectedPeriod,
|
|
@@ -309,5 +311,7 @@ function SparklineInteractiveWithGeneric(_ref4) {
|
|
|
309
311
|
}, resizeKey);
|
|
310
312
|
}
|
|
311
313
|
|
|
312
|
-
|
|
314
|
+
/**
|
|
315
|
+
* @deprecated Use LineChart instead.
|
|
316
|
+
*/
|
|
313
317
|
export const SparklineInteractive = /*#__PURE__*/memo(SparklineInteractiveWithGeneric);
|
|
@@ -5,8 +5,8 @@ import { animatedPathConfig } from '@coinbase/cds-common/animation/sparkline';
|
|
|
5
5
|
import { useValueChanges } from '@coinbase/cds-common/hooks/useValueChanges';
|
|
6
6
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
7
7
|
import { select } from 'd3-selection';
|
|
8
|
+
import { Sparkline } from '../Sparkline';
|
|
8
9
|
import { SparklineArea } from '../SparklineArea';
|
|
9
|
-
import { SparklineGradient } from '../SparklineGradient';
|
|
10
10
|
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
11
11
|
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -20,6 +20,7 @@ export const SparklineInteractiveAnimatedPath = /*#__PURE__*/memo(_ref => {
|
|
|
20
20
|
color,
|
|
21
21
|
selectedPeriod,
|
|
22
22
|
area,
|
|
23
|
+
fillType = 'gradient',
|
|
23
24
|
yAxisScalingFactor,
|
|
24
25
|
initialPath,
|
|
25
26
|
initialArea
|
|
@@ -92,10 +93,12 @@ export const SparklineInteractiveAnimatedPath = /*#__PURE__*/memo(_ref => {
|
|
|
92
93
|
updatePathWithoutAnimation();
|
|
93
94
|
}
|
|
94
95
|
}, [addPreviousArea, addPreviousPath, hideFallback, isFallbackVisible, newArea, newPath, playAnimation, shouldUpdateArea, shouldUpdatePath, skipAnimation, updatePathWithoutAnimation]);
|
|
95
|
-
return /*#__PURE__*/_jsx(
|
|
96
|
+
return /*#__PURE__*/_jsx(Sparkline, {
|
|
96
97
|
ref: pathRef,
|
|
97
98
|
color: color,
|
|
99
|
+
fillType: fillType,
|
|
98
100
|
height: chartHeight,
|
|
101
|
+
strokeType: "solid",
|
|
99
102
|
width: chartWidth,
|
|
100
103
|
yAxisScalingFactor: yAxisScalingFactor,
|
|
101
104
|
children: !!area && /*#__PURE__*/_jsx(SparklineArea, {
|
|
@@ -8,6 +8,7 @@ function SparklineInteractivePathsWithGeneric(_ref) {
|
|
|
8
8
|
let {
|
|
9
9
|
showHoverData,
|
|
10
10
|
fill,
|
|
11
|
+
fillType = 'gradient',
|
|
11
12
|
path,
|
|
12
13
|
area,
|
|
13
14
|
selectedPeriod,
|
|
@@ -16,6 +17,8 @@ function SparklineInteractivePathsWithGeneric(_ref) {
|
|
|
16
17
|
hoverData,
|
|
17
18
|
compact
|
|
18
19
|
} = _ref;
|
|
20
|
+
// Map 'dotted' to 'gradientDotted' for Sparkline
|
|
21
|
+
const sparklineFillType = fillType === 'dotted' ? 'gradientDotted' : 'gradient';
|
|
19
22
|
const hoverPathRef = useRef(undefined);
|
|
20
23
|
const hoverAreaRef = useRef(undefined);
|
|
21
24
|
const shouldShowFill = !!fill;
|
|
@@ -36,6 +39,7 @@ function SparklineInteractivePathsWithGeneric(_ref) {
|
|
|
36
39
|
area: shouldShowFill ? area : undefined,
|
|
37
40
|
color: strokeColor,
|
|
38
41
|
d: path,
|
|
42
|
+
fillType: sparklineFillType,
|
|
39
43
|
initialArea: hoverAreaRef.current,
|
|
40
44
|
initialPath: hoverPathRef.current,
|
|
41
45
|
selectedPeriod: selectedPeriod,
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cds-web-visualization",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.2",
|
|
4
4
|
"description": "Coinbase Design System - Web Sparkline",
|
|
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/web-visualization"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"types": "./dts/index.d.ts",
|
|
17
17
|
"default": "./esm/index.js"
|
|
18
18
|
},
|
|
19
|
+
"./chart": {
|
|
20
|
+
"types": "./dts/chart/index.d.ts",
|
|
21
|
+
"default": "./esm/chart/index.js"
|
|
22
|
+
},
|
|
19
23
|
"./sparkline": {
|
|
20
24
|
"types": "./dts/sparkline/index.d.ts",
|
|
21
25
|
"default": "./esm/sparkline/index.js"
|
|
@@ -34,10 +38,10 @@
|
|
|
34
38
|
"CHANGELOG"
|
|
35
39
|
],
|
|
36
40
|
"peerDependencies": {
|
|
37
|
-
"@coinbase/cds-common": "
|
|
38
|
-
"@coinbase/cds-lottie-files": "
|
|
39
|
-
"@coinbase/cds-utils": "
|
|
40
|
-
"@coinbase/cds-web": "
|
|
41
|
+
"@coinbase/cds-common": "^8.14.0",
|
|
42
|
+
"@coinbase/cds-lottie-files": "^3.3.2",
|
|
43
|
+
"@coinbase/cds-utils": "^2.3.3",
|
|
44
|
+
"@coinbase/cds-web": "^8.14.0",
|
|
41
45
|
"react": "^18.3.1",
|
|
42
46
|
"react-dom": "^18.3.1"
|
|
43
47
|
},
|
|
@@ -54,13 +58,13 @@
|
|
|
54
58
|
"@babel/preset-env": "^7.28.0",
|
|
55
59
|
"@babel/preset-react": "^7.27.1",
|
|
56
60
|
"@babel/preset-typescript": "^7.27.1",
|
|
57
|
-
"@coinbase/cds-common": "
|
|
58
|
-
"@coinbase/cds-lottie-files": "
|
|
59
|
-
"@coinbase/cds-utils": "
|
|
60
|
-
"@coinbase/cds-web": "
|
|
61
|
+
"@coinbase/cds-common": "^8.14.0",
|
|
62
|
+
"@coinbase/cds-lottie-files": "^3.3.2",
|
|
63
|
+
"@coinbase/cds-utils": "^2.3.3",
|
|
64
|
+
"@coinbase/cds-web": "^8.14.0",
|
|
61
65
|
"@figma/code-connect": "^1.3.4",
|
|
62
66
|
"@linaria/core": "^3.0.0-beta.22",
|
|
63
67
|
"@types/react": "^18.3.12",
|
|
64
68
|
"@types/react-dom": "^18.3.1"
|
|
65
69
|
}
|
|
66
|
-
}
|
|
70
|
+
}
|