@coinbase/cds-web-visualization 0.0.0 → 3.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +3 -0
- package/dts/chart/CartesianChart.d.ts +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 +3 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +8 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +67 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +15 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +14 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +23 -0
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -0
- package/dts/sparkline/SparklinePath.d.ts +12 -0
- package/dts/sparkline/SparklinePath.d.ts.map +1 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +2 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +11 -0
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -0
- package/dts/sparkline/index.d.ts +6 -0
- package/dts/sparkline/index.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +199 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +8 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +30 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +18 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +31 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +112 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +1 -0
- package/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 -0
- package/esm/sparkline/Counter.css +3 -0
- package/esm/sparkline/Counter.js +35 -0
- package/esm/sparkline/Sparkline.js +164 -0
- package/esm/sparkline/SparklineArea.js +18 -0
- package/esm/sparkline/SparklineAreaPattern.js +37 -0
- package/esm/sparkline/SparklineGradient.js +30 -0
- package/esm/sparkline/SparklinePath.js +19 -0
- package/esm/sparkline/__figma__/Sparkline.figma.js +24 -0
- package/esm/sparkline/generateSparklineWithId.js +7 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.js +21 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +317 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +108 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +26 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.js +24 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.css +4 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +65 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.css +1 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +80 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +56 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +70 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +45 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.css +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.js +199 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.js +39 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +92 -0
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +89 -0
- package/esm/sparkline/sparkline-interactive/fade.css +2 -0
- package/esm/sparkline/sparkline-interactive/fade.js +14 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +28 -0
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +225 -0
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +108 -0
- package/package.json +68 -6
- package/index.js +0 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
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
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
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, { forwardRef, memo, useId, useMemo, useRef } from 'react';
|
|
7
|
+
import { getAccessibleForegroundGradient } from '@coinbase/cds-common/color/getAccessibleForegroundGradient';
|
|
8
|
+
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
9
|
+
import { getSparklineRange } from '@coinbase/cds-common/visualizations/getSparklineRange';
|
|
10
|
+
import { getSparklineTransform } from '@coinbase/cds-common/visualizations/getSparklineTransform';
|
|
11
|
+
import { generateRandomId } from '@coinbase/cds-utils';
|
|
12
|
+
import { useTheme } from '@coinbase/cds-web/hooks/useTheme';
|
|
13
|
+
import { generateSparklineAreaWithId } from './generateSparklineWithId';
|
|
14
|
+
import { SparklineAreaPattern } from './SparklineAreaPattern';
|
|
15
|
+
import { SparklinePath } from './SparklinePath';
|
|
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) => {
|
|
21
|
+
let {
|
|
22
|
+
background,
|
|
23
|
+
color,
|
|
24
|
+
height,
|
|
25
|
+
path,
|
|
26
|
+
width,
|
|
27
|
+
yAxisScalingFactor,
|
|
28
|
+
children,
|
|
29
|
+
strokeType = 'solid',
|
|
30
|
+
fillType = 'dotted'
|
|
31
|
+
} = _ref;
|
|
32
|
+
const theme = useTheme();
|
|
33
|
+
const patternId = useRef(generateRandomId());
|
|
34
|
+
const strokeColor = color !== 'auto' ? color : getAccessibleColor({
|
|
35
|
+
background: background !== null && background !== void 0 ? background : theme.color.bg,
|
|
36
|
+
foreground: 'auto',
|
|
37
|
+
usage: 'graphic'
|
|
38
|
+
});
|
|
39
|
+
const translateProps = getSparklineTransform(width, height, yAxisScalingFactor);
|
|
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;
|
|
152
|
+
return /*#__PURE__*/_jsxs("svg", {
|
|
153
|
+
height: height,
|
|
154
|
+
width: width,
|
|
155
|
+
children: [!shouldPlaceDefsInside && defs, /*#__PURE__*/_jsxs("g", _objectSpread(_objectSpread({}, translateProps), {}, {
|
|
156
|
+
children: [shouldPlaceDefsInside && defs, /*#__PURE__*/_jsx(SparklinePath, {
|
|
157
|
+
ref: ref,
|
|
158
|
+
path: path,
|
|
159
|
+
stroke: stroke
|
|
160
|
+
}), generateSparklineAreaWithId(patternId.current, children, fillType === 'gradientDotted' ? maskId : undefined)]
|
|
161
|
+
}))]
|
|
162
|
+
});
|
|
163
|
+
}));
|
|
164
|
+
Sparkline.displayName = 'Sparkline';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { forwardRef, memo } from 'react';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use AreaChart instead.
|
|
5
|
+
*/
|
|
6
|
+
export const SparklineArea = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
7
|
+
let {
|
|
8
|
+
area,
|
|
9
|
+
patternId,
|
|
10
|
+
maskId
|
|
11
|
+
} = _ref;
|
|
12
|
+
return /*#__PURE__*/_jsx("path", {
|
|
13
|
+
ref: ref,
|
|
14
|
+
d: area,
|
|
15
|
+
fill: "url(#".concat(patternId, ")"),
|
|
16
|
+
mask: maskId ? "url(#".concat(maskId, ")") : undefined
|
|
17
|
+
});
|
|
18
|
+
}));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSparklineAreaOpacity } from '@coinbase/cds-common/visualizations/useSparklineAreaOpacity';
|
|
3
|
+
import { useTheme } from '@coinbase/cds-web/hooks/useTheme';
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
export const SparklineAreaPattern = _ref => {
|
|
6
|
+
let {
|
|
7
|
+
color,
|
|
8
|
+
id,
|
|
9
|
+
opacity
|
|
10
|
+
} = _ref;
|
|
11
|
+
const {
|
|
12
|
+
activeColorScheme
|
|
13
|
+
} = useTheme();
|
|
14
|
+
const themeOpacity = useSparklineAreaOpacity(activeColorScheme);
|
|
15
|
+
const fillOpacity = opacity !== null && opacity !== void 0 ? opacity : themeOpacity;
|
|
16
|
+
return /*#__PURE__*/_jsx("pattern", {
|
|
17
|
+
height: "4",
|
|
18
|
+
id: id,
|
|
19
|
+
patternUnits: "userSpaceOnUse",
|
|
20
|
+
width: "4",
|
|
21
|
+
x: "0",
|
|
22
|
+
y: "0",
|
|
23
|
+
children: /*#__PURE__*/_jsxs("g", {
|
|
24
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
25
|
+
fill: "transparent",
|
|
26
|
+
height: "4",
|
|
27
|
+
width: "4"
|
|
28
|
+
}), /*#__PURE__*/_jsx("circle", {
|
|
29
|
+
cx: "1",
|
|
30
|
+
cy: "1",
|
|
31
|
+
fill: color,
|
|
32
|
+
fillOpacity: fillOpacity,
|
|
33
|
+
r: "1"
|
|
34
|
+
})]
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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) => {
|
|
8
|
+
let {
|
|
9
|
+
background,
|
|
10
|
+
color,
|
|
11
|
+
path,
|
|
12
|
+
height,
|
|
13
|
+
width,
|
|
14
|
+
yAxisScalingFactor,
|
|
15
|
+
children
|
|
16
|
+
} = _ref;
|
|
17
|
+
return /*#__PURE__*/_jsx(Sparkline, {
|
|
18
|
+
ref: ref,
|
|
19
|
+
background: background,
|
|
20
|
+
color: color,
|
|
21
|
+
fillType: "dotted",
|
|
22
|
+
height: height,
|
|
23
|
+
path: path,
|
|
24
|
+
strokeType: "gradient",
|
|
25
|
+
width: width,
|
|
26
|
+
yAxisScalingFactor: yAxisScalingFactor,
|
|
27
|
+
children: children
|
|
28
|
+
});
|
|
29
|
+
}));
|
|
30
|
+
SparklineGradient.displayName = 'SparklineGradient';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { forwardRef, memo } from 'react';
|
|
2
|
+
import { borderWidth } from '@coinbase/cds-common/tokens/sparkline';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export const SparklinePath = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, forwardedRef) => {
|
|
5
|
+
let {
|
|
6
|
+
path,
|
|
7
|
+
stroke
|
|
8
|
+
} = _ref;
|
|
9
|
+
return /*#__PURE__*/_jsx("path", {
|
|
10
|
+
ref: forwardedRef,
|
|
11
|
+
d: path,
|
|
12
|
+
fill: "transparent",
|
|
13
|
+
stroke: stroke,
|
|
14
|
+
strokeLinecap: "round",
|
|
15
|
+
strokeLinejoin: "round",
|
|
16
|
+
strokeWidth: borderWidth
|
|
17
|
+
});
|
|
18
|
+
}));
|
|
19
|
+
SparklinePath.displayName = 'SparklinePath';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { figma } from '@figma/code-connect';
|
|
5
|
+
import { Sparkline } from '../Sparkline';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
figma.connect(Sparkline, 'https://www.figma.com/design/k5CtyJccNQUGMI5bI4lJ2g/✨-CDS-Components?node-id=320-15040&m=dev', {
|
|
8
|
+
imports: ["import { Sparkline } from '@coinbase/cds-web-visualization';", "import { useSparklinePath } from '@coinbase/cds-common/visualizations/useSparklinePath';"],
|
|
9
|
+
example: () => {
|
|
10
|
+
const data = [20, 30, 5, 45, 0];
|
|
11
|
+
// @ts-expect-error: useSparklinePath is not typed correctly
|
|
12
|
+
const path = useSparklinePath({
|
|
13
|
+
height: 200,
|
|
14
|
+
width: 200,
|
|
15
|
+
data
|
|
16
|
+
});
|
|
17
|
+
return /*#__PURE__*/_jsx(Sparkline, {
|
|
18
|
+
color: "auto",
|
|
19
|
+
height: 200,
|
|
20
|
+
path: path,
|
|
21
|
+
width: 400
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
3
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export const InnerSparklineInteractiveProvider = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
width,
|
|
7
|
+
height,
|
|
8
|
+
children
|
|
9
|
+
} = _ref;
|
|
10
|
+
const {
|
|
11
|
+
setWidth,
|
|
12
|
+
setHeight
|
|
13
|
+
} = useSparklineInteractiveContext();
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
setWidth(width);
|
|
16
|
+
setHeight(height);
|
|
17
|
+
}, [width, height, setWidth, setHeight]);
|
|
18
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
19
|
+
children: children
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
const _excluded = ["compact"];
|
|
2
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
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
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
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; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
8
|
+
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); }
|
|
9
|
+
import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
|
|
10
|
+
import { gutter } from '@coinbase/cds-common/tokens/sizing';
|
|
11
|
+
import { chartCompactHeight, chartHeight } from '@coinbase/cds-common/tokens/sparkline';
|
|
12
|
+
import { debounce } from '@coinbase/cds-common/utils/debounce';
|
|
13
|
+
import { getAccessibleColor } from '@coinbase/cds-common/utils/getAccessibleColor';
|
|
14
|
+
import { useSparklineCoordinates } from '@coinbase/cds-common/visualizations/useSparklineCoordinates';
|
|
15
|
+
import { chartFallbackNegative, chartFallbackPositive } from '@coinbase/cds-lottie-files';
|
|
16
|
+
import { emptyArray, isStorybook, noop } from '@coinbase/cds-utils';
|
|
17
|
+
import { cx, useTheme } from '@coinbase/cds-web';
|
|
18
|
+
import { Lottie } from '@coinbase/cds-web/animation';
|
|
19
|
+
import { useDimensions } from '@coinbase/cds-web/hooks/useDimensions';
|
|
20
|
+
import { HStack, VStack } from '@coinbase/cds-web/layout';
|
|
21
|
+
import { Box } from '@coinbase/cds-web/layout/Box';
|
|
22
|
+
import { getBrowserGlobals } from '@coinbase/cds-web/utils/browser';
|
|
23
|
+
import { VisualizationContainer } from '@coinbase/cds-web/visualizations/VisualizationContainer';
|
|
24
|
+
import isEqual from 'lodash/isEqual';
|
|
25
|
+
import isObject from 'lodash/isObject';
|
|
26
|
+
import { InnerSparklineInteractiveProvider } from './InnerSparklineInteractiveProvider';
|
|
27
|
+
import { SparklineInteractiveHoverDate } from './SparklineInteractiveHoverDate';
|
|
28
|
+
import { SparklineInteractiveHoverPrice } from './SparklineInteractiveHoverPrice';
|
|
29
|
+
import { SparklineInteractiveLineVertical } from './SparklineInteractiveLineVertical';
|
|
30
|
+
import { SparklineInteractiveMarkerDates } from './SparklineInteractiveMarkerDates';
|
|
31
|
+
import { SparklineInteractivePaths } from './SparklineInteractivePaths';
|
|
32
|
+
import { SparklineInteractivePeriodSelector } from './SparklineInteractivePeriodSelector';
|
|
33
|
+
import { SparklineInteractiveProvider, useSparklineInteractiveContext } from './SparklineInteractiveProvider';
|
|
34
|
+
import { SparklineInteractiveScrubHandler } from './SparklineInteractiveScrubHandler';
|
|
35
|
+
import { SparklineInteractiveScrubProvider } from './SparklineInteractiveScrubProvider';
|
|
36
|
+
import { useSparklineInteractiveConstants } from './useSparklineInteractiveConstants';
|
|
37
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
38
|
+
export * from '@coinbase/cds-common/types/Chart';
|
|
39
|
+
const DefaultFallback = /*#__PURE__*/memo(_ref => {
|
|
40
|
+
let {
|
|
41
|
+
fallbackType
|
|
42
|
+
} = _ref;
|
|
43
|
+
// don't show lottie animation in story book
|
|
44
|
+
const skipLottie = isStorybook();
|
|
45
|
+
const source = fallbackType === 'negative' ? chartFallbackNegative : chartFallbackPositive;
|
|
46
|
+
return !skipLottie && /*#__PURE__*/_jsx(Lottie, {
|
|
47
|
+
autoplay: true,
|
|
48
|
+
loop: true,
|
|
49
|
+
height: "100%",
|
|
50
|
+
source: source,
|
|
51
|
+
width: "100%"
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
const mobileLayoutBreakpoint = 650;
|
|
55
|
+
function SparklineInteractiveContentWithGeneric(_ref2) {
|
|
56
|
+
let {
|
|
57
|
+
data,
|
|
58
|
+
periods,
|
|
59
|
+
defaultPeriod,
|
|
60
|
+
onPeriodChanged,
|
|
61
|
+
strokeColor,
|
|
62
|
+
onScrub = noop,
|
|
63
|
+
onScrubStart = noop,
|
|
64
|
+
onScrubEnd = noop,
|
|
65
|
+
formatDate,
|
|
66
|
+
fallback = null,
|
|
67
|
+
hidePeriodSelector = false,
|
|
68
|
+
disableScrubbing = false,
|
|
69
|
+
fill = true,
|
|
70
|
+
fillType = 'gradient',
|
|
71
|
+
yAxisScalingFactor = 1.0,
|
|
72
|
+
compact,
|
|
73
|
+
formatHoverDate,
|
|
74
|
+
formatHoverPrice,
|
|
75
|
+
headerNode,
|
|
76
|
+
fallbackType = 'positive',
|
|
77
|
+
timePeriodGutter,
|
|
78
|
+
hoverData,
|
|
79
|
+
periodSelectorPlacement = 'above',
|
|
80
|
+
className,
|
|
81
|
+
classNames,
|
|
82
|
+
style,
|
|
83
|
+
styles,
|
|
84
|
+
headerTestID
|
|
85
|
+
} = _ref2;
|
|
86
|
+
const [isScrubbing, setIsScrubbing] = useState(false);
|
|
87
|
+
const [isMarkerDateVisible, setIsMarkerDateVisible] = useState(false);
|
|
88
|
+
const innerSparklineInteractiveHeight = compact ? chartCompactHeight : chartHeight;
|
|
89
|
+
const {
|
|
90
|
+
isFallbackVisible,
|
|
91
|
+
showFallback
|
|
92
|
+
} = useSparklineInteractiveContext();
|
|
93
|
+
const {
|
|
94
|
+
observe: containerRef,
|
|
95
|
+
width: containerWidth
|
|
96
|
+
} = useDimensions();
|
|
97
|
+
const isMobileLayout = containerWidth > 0 && containerWidth < mobileLayoutBreakpoint;
|
|
98
|
+
const showHeaderPeriodSelector = periodSelectorPlacement === 'above' && !hidePeriodSelector;
|
|
99
|
+
const showBottomMarkerDates = useMemo(() => periodSelectorPlacement === 'above' || periodSelectorPlacement === 'below' && hidePeriodSelector || isMarkerDateVisible, [isMarkerDateVisible, periodSelectorPlacement, hidePeriodSelector]);
|
|
100
|
+
const color = strokeColor;
|
|
101
|
+
const [selectedPeriod, setSelectedPeriod] = useState(defaultPeriod);
|
|
102
|
+
const theme = useTheme();
|
|
103
|
+
const lineVerticalColor = useMemo(() => {
|
|
104
|
+
const lineColor = color !== 'auto' ? color : getAccessibleColor({
|
|
105
|
+
background: theme.color.bg,
|
|
106
|
+
foreground: 'auto',
|
|
107
|
+
usage: 'graphic'
|
|
108
|
+
});
|
|
109
|
+
return hoverData ? 'var(--color-bgLineHeavy)' : lineColor;
|
|
110
|
+
}, [hoverData, color, theme.color.bg]);
|
|
111
|
+
const dataForPeriod = useMemo(() => {
|
|
112
|
+
var _data$selectedPeriod;
|
|
113
|
+
if (!data) {
|
|
114
|
+
return emptyArray;
|
|
115
|
+
}
|
|
116
|
+
return (_data$selectedPeriod = data[selectedPeriod]) !== null && _data$selectedPeriod !== void 0 ? _data$selectedPeriod : emptyArray;
|
|
117
|
+
}, [data, selectedPeriod]);
|
|
118
|
+
const handleScrubStart = useCallback(() => {
|
|
119
|
+
if (hoverData) {
|
|
120
|
+
setIsScrubbing(true);
|
|
121
|
+
}
|
|
122
|
+
setIsMarkerDateVisible(true);
|
|
123
|
+
onScrubStart === null || onScrubStart === void 0 || onScrubStart();
|
|
124
|
+
}, [hoverData, onScrubStart]);
|
|
125
|
+
const handleScrubEnd = useCallback(() => {
|
|
126
|
+
if (hoverData) {
|
|
127
|
+
setIsScrubbing(false);
|
|
128
|
+
}
|
|
129
|
+
setIsMarkerDateVisible(false);
|
|
130
|
+
onScrubEnd === null || onScrubEnd === void 0 || onScrubEnd();
|
|
131
|
+
}, [hoverData, onScrubEnd]);
|
|
132
|
+
|
|
133
|
+
// If dataForPeriod is empty we know that we are either loading
|
|
134
|
+
// or backend returned bad data and we should show fallback UI.
|
|
135
|
+
const hasData = dataForPeriod.length > 0;
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
var _data$selectedPeriod2;
|
|
138
|
+
// If there is no data for selected period show fallback loader
|
|
139
|
+
if (isObject(data) && !((_data$selectedPeriod2 = data[selectedPeriod]) !== null && _data$selectedPeriod2 !== void 0 && _data$selectedPeriod2.length) && !isFallbackVisible) {
|
|
140
|
+
showFallback();
|
|
141
|
+
}
|
|
142
|
+
}, [data, isFallbackVisible, selectedPeriod, showFallback]);
|
|
143
|
+
const updatePeriod = useCallback(period => {
|
|
144
|
+
if (isObject(data) && period !== selectedPeriod) {
|
|
145
|
+
// This can sometimes happen for newer assets which
|
|
146
|
+
// will have their 'all' chart data be the same as
|
|
147
|
+
// their 'year' chart data. In those cases we don't
|
|
148
|
+
// want to animate out the min/max since we rely on
|
|
149
|
+
// AnimatedSparklineInteractivePath to animate those components back in -
|
|
150
|
+
// and AnimatedSparklineInteractivePath will not trigger an animation
|
|
151
|
+
// if it's chartData is the same between re-renders
|
|
152
|
+
if (!isEqual(data[period], data[selectedPeriod])) {
|
|
153
|
+
// minMaxOpacity.setValue(0);
|
|
154
|
+
}
|
|
155
|
+
setSelectedPeriod(period);
|
|
156
|
+
onPeriodChanged === null || onPeriodChanged === void 0 || onPeriodChanged(period);
|
|
157
|
+
}
|
|
158
|
+
}, [data, selectedPeriod, onPeriodChanged /* , minMaxOpacity */]);
|
|
159
|
+
const {
|
|
160
|
+
chartWidth
|
|
161
|
+
} = useSparklineInteractiveConstants();
|
|
162
|
+
const {
|
|
163
|
+
path,
|
|
164
|
+
area,
|
|
165
|
+
getMarker
|
|
166
|
+
} = useSparklineCoordinates({
|
|
167
|
+
data: dataForPeriod,
|
|
168
|
+
width: chartWidth,
|
|
169
|
+
height: innerSparklineInteractiveHeight,
|
|
170
|
+
yAxisScalingFactor
|
|
171
|
+
});
|
|
172
|
+
let header;
|
|
173
|
+
if (headerNode) {
|
|
174
|
+
header = /*#__PURE__*/_jsx(Box, {
|
|
175
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.header,
|
|
176
|
+
flexGrow: 1,
|
|
177
|
+
paddingX: !isMobileLayout ? gutter : 0,
|
|
178
|
+
style: styles === null || styles === void 0 ? void 0 : styles.header,
|
|
179
|
+
testID: headerTestID,
|
|
180
|
+
children: headerNode
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const periodSelector = /*#__PURE__*/_jsx(SparklineInteractivePeriodSelector, {
|
|
184
|
+
color: color,
|
|
185
|
+
periods: periods,
|
|
186
|
+
selectedPeriod: selectedPeriod,
|
|
187
|
+
setSelectedPeriod: updatePeriod
|
|
188
|
+
});
|
|
189
|
+
const rootStyles = useMemo(() => _objectSpread(_objectSpread({
|
|
190
|
+
width: '100%'
|
|
191
|
+
}, style), styles === null || styles === void 0 ? void 0 : styles.root), [style, styles === null || styles === void 0 ? void 0 : styles.root]);
|
|
192
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
193
|
+
ref: containerRef,
|
|
194
|
+
className: cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root),
|
|
195
|
+
style: rootStyles,
|
|
196
|
+
children: [isMobileLayout && showHeaderPeriodSelector && /*#__PURE__*/_jsx(Box, {
|
|
197
|
+
paddingBottom: 2,
|
|
198
|
+
width: "100%",
|
|
199
|
+
children: periodSelector
|
|
200
|
+
}), (!!headerNode || !isMobileLayout && showHeaderPeriodSelector) && /*#__PURE__*/_jsxs(Box, {
|
|
201
|
+
alignItems: "center",
|
|
202
|
+
justifyContent: "space-between",
|
|
203
|
+
paddingBottom: 2,
|
|
204
|
+
children: [header !== null && header !== void 0 ? header : /*#__PURE__*/_jsx("div", {}), !isMobileLayout && showHeaderPeriodSelector && /*#__PURE__*/_jsx(Box, {
|
|
205
|
+
flexGrow: 0,
|
|
206
|
+
children: periodSelector
|
|
207
|
+
})]
|
|
208
|
+
}), /*#__PURE__*/_jsxs(SparklineInteractiveScrubProvider, {
|
|
209
|
+
children: [/*#__PURE__*/_jsxs(VStack, {
|
|
210
|
+
paddingBottom: (formatHoverDate || formatHoverPrice) && 1,
|
|
211
|
+
children: [!!formatHoverDate && /*#__PURE__*/_jsx(SparklineInteractiveHoverDate, {}), !!formatHoverPrice && /*#__PURE__*/_jsx(SparklineInteractiveHoverPrice, {})]
|
|
212
|
+
}), /*#__PURE__*/_jsx(VisualizationContainer, {
|
|
213
|
+
height: innerSparklineInteractiveHeight,
|
|
214
|
+
width: "100%",
|
|
215
|
+
children: _ref3 => {
|
|
216
|
+
let {
|
|
217
|
+
width,
|
|
218
|
+
height
|
|
219
|
+
} = _ref3;
|
|
220
|
+
return /*#__PURE__*/_jsx(InnerSparklineInteractiveProvider, {
|
|
221
|
+
height: height,
|
|
222
|
+
width: width,
|
|
223
|
+
children: /*#__PURE__*/_jsx(SparklineInteractiveScrubHandler, {
|
|
224
|
+
disabled: disableScrubbing,
|
|
225
|
+
formatHoverDate: formatHoverDate,
|
|
226
|
+
formatHoverPrice: formatHoverPrice,
|
|
227
|
+
getMarker: getMarker,
|
|
228
|
+
onScrub: onScrub,
|
|
229
|
+
onScrubEnd: handleScrubEnd,
|
|
230
|
+
onScrubStart: handleScrubStart,
|
|
231
|
+
selectedPeriod: selectedPeriod,
|
|
232
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
|
233
|
+
height: height,
|
|
234
|
+
position: "relative",
|
|
235
|
+
width: width,
|
|
236
|
+
children: [!!isFallbackVisible && /*#__PURE__*/_jsx(Box, {
|
|
237
|
+
height: "100%",
|
|
238
|
+
justifyContent: "center",
|
|
239
|
+
position: "absolute",
|
|
240
|
+
width: "100%",
|
|
241
|
+
children: fallback !== null && fallback !== void 0 ? fallback : /*#__PURE__*/_jsx(DefaultFallback, {
|
|
242
|
+
fallbackType: fallbackType
|
|
243
|
+
})
|
|
244
|
+
}), /*#__PURE__*/_jsx(Box, {
|
|
245
|
+
height: "100%",
|
|
246
|
+
width: "100%",
|
|
247
|
+
children: !!hasData && !!path && /*#__PURE__*/_jsxs(_Fragment, {
|
|
248
|
+
children: [/*#__PURE__*/_jsx(SparklineInteractivePaths, {
|
|
249
|
+
area: area,
|
|
250
|
+
compact: compact,
|
|
251
|
+
fill: fill,
|
|
252
|
+
fillType: fillType,
|
|
253
|
+
hoverData: hoverData,
|
|
254
|
+
path: path,
|
|
255
|
+
selectedPeriod: selectedPeriod,
|
|
256
|
+
showHoverData: isScrubbing,
|
|
257
|
+
strokeColor: color,
|
|
258
|
+
yAxisScalingFactor: yAxisScalingFactor
|
|
259
|
+
}), /*#__PURE__*/_jsx(SparklineInteractiveLineVertical, {
|
|
260
|
+
color: lineVerticalColor
|
|
261
|
+
})]
|
|
262
|
+
})
|
|
263
|
+
})]
|
|
264
|
+
})
|
|
265
|
+
})
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
})]
|
|
269
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
270
|
+
alignItems: "flex-end",
|
|
271
|
+
minHeight: 50,
|
|
272
|
+
width: "100%",
|
|
273
|
+
children: [showBottomMarkerDates && /*#__PURE__*/_jsx(SparklineInteractiveMarkerDates, {
|
|
274
|
+
formatDate: formatDate,
|
|
275
|
+
getMarker: getMarker,
|
|
276
|
+
selectedPeriod: selectedPeriod,
|
|
277
|
+
timePeriodGutter: timePeriodGutter
|
|
278
|
+
}), periodSelectorPlacement === 'below' && !isMarkerDateVisible && !hidePeriodSelector && periodSelector]
|
|
279
|
+
})]
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// typescript doesn't understand the memo with the generic so it gets casted to a base react component
|
|
284
|
+
export const SparklineInteractiveContent = /*#__PURE__*/memo(SparklineInteractiveContentWithGeneric);
|
|
285
|
+
function SparklineInteractiveWithGeneric(_ref4) {
|
|
286
|
+
let {
|
|
287
|
+
compact
|
|
288
|
+
} = _ref4,
|
|
289
|
+
props = _objectWithoutProperties(_ref4, _excluded);
|
|
290
|
+
const [resizeKey, setResizeKey] = useState(0);
|
|
291
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
292
|
+
const resizeHandler = useCallback(debounce(() => {
|
|
293
|
+
// no resizing on percy
|
|
294
|
+
if (!isStorybook()) {
|
|
295
|
+
setResizeKey(prev => prev + 1);
|
|
296
|
+
}
|
|
297
|
+
}, 300), []);
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
var _getBrowserGlobals;
|
|
300
|
+
(_getBrowserGlobals = getBrowserGlobals()) === null || _getBrowserGlobals === void 0 || (_getBrowserGlobals = _getBrowserGlobals.window) === null || _getBrowserGlobals === void 0 || _getBrowserGlobals.addEventListener('resize', resizeHandler);
|
|
301
|
+
return () => {
|
|
302
|
+
var _getBrowserGlobals2;
|
|
303
|
+
(_getBrowserGlobals2 = getBrowserGlobals()) === null || _getBrowserGlobals2 === void 0 || (_getBrowserGlobals2 = _getBrowserGlobals2.window) === null || _getBrowserGlobals2 === void 0 || _getBrowserGlobals2.removeEventListener('resize', resizeHandler);
|
|
304
|
+
};
|
|
305
|
+
}, [resizeHandler]);
|
|
306
|
+
return /*#__PURE__*/_jsx(SparklineInteractiveProvider, {
|
|
307
|
+
compact: compact,
|
|
308
|
+
children: /*#__PURE__*/_jsx(SparklineInteractiveContent, _objectSpread({
|
|
309
|
+
compact: compact
|
|
310
|
+
}, props))
|
|
311
|
+
}, resizeKey);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @deprecated Use LineChart instead.
|
|
316
|
+
*/
|
|
317
|
+
export const SparklineInteractive = /*#__PURE__*/memo(SparklineInteractiveWithGeneric);
|