@coinbase/cds-mobile-visualization 3.3.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/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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const _excluded = ["series", "showArea", "areaType", "type", "LineComponent", "AreaComponent", "curve", "renderPoints", "strokeWidth", "showXAxis", "showYAxis", "xAxis", "yAxis", "inset", "children"],
|
|
2
|
+
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
|
|
3
|
+
_excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
|
|
4
|
+
_excluded4 = ["id", "data", "label", "color", "yAxisId"];
|
|
5
|
+
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); }
|
|
6
|
+
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; }
|
|
7
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
8
|
+
import { XAxis } from '../axis/XAxis';
|
|
9
|
+
import { YAxis } from '../axis/YAxis';
|
|
10
|
+
import { CartesianChart } from '../CartesianChart';
|
|
11
|
+
import { defaultChartInset, getChartInset } from '../utils';
|
|
12
|
+
import { Line } from './Line';
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
15
|
+
let {
|
|
16
|
+
series,
|
|
17
|
+
showArea,
|
|
18
|
+
areaType,
|
|
19
|
+
type,
|
|
20
|
+
LineComponent,
|
|
21
|
+
AreaComponent,
|
|
22
|
+
curve,
|
|
23
|
+
renderPoints,
|
|
24
|
+
strokeWidth,
|
|
25
|
+
showXAxis,
|
|
26
|
+
showYAxis,
|
|
27
|
+
xAxis,
|
|
28
|
+
yAxis,
|
|
29
|
+
inset: userInset,
|
|
30
|
+
children
|
|
31
|
+
} = _ref,
|
|
32
|
+
chartProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
33
|
+
const calculatedInset = useMemo(() => getChartInset(userInset, defaultChartInset), [userInset]);
|
|
34
|
+
|
|
35
|
+
// Check if we have valid data across all series
|
|
36
|
+
const hasData = useMemo(() => {
|
|
37
|
+
if (!series || series.length === 0) return false;
|
|
38
|
+
return series.some(s => s.data && s.data.length > 0);
|
|
39
|
+
}, [series]);
|
|
40
|
+
|
|
41
|
+
// Convert LineSeries to Series for Chart context
|
|
42
|
+
const chartSeries = useMemo(() => {
|
|
43
|
+
return series == null ? void 0 : series.map(s => ({
|
|
44
|
+
id: s.id,
|
|
45
|
+
data: s.data,
|
|
46
|
+
label: s.label,
|
|
47
|
+
color: s.color
|
|
48
|
+
}));
|
|
49
|
+
}, [series]);
|
|
50
|
+
|
|
51
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
52
|
+
const _ref2 = xAxis || {},
|
|
53
|
+
{
|
|
54
|
+
scaleType: xScaleType,
|
|
55
|
+
data: xData,
|
|
56
|
+
categoryPadding: xCategoryPadding,
|
|
57
|
+
domain: xDomain,
|
|
58
|
+
domainLimit: xDomainLimit,
|
|
59
|
+
range: xRange
|
|
60
|
+
} = _ref2,
|
|
61
|
+
xAxisVisualProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
62
|
+
const _ref3 = yAxis || {},
|
|
63
|
+
{
|
|
64
|
+
scaleType: yScaleType,
|
|
65
|
+
data: yData,
|
|
66
|
+
categoryPadding: yCategoryPadding,
|
|
67
|
+
domain: yDomain,
|
|
68
|
+
domainLimit: yDomainLimit,
|
|
69
|
+
range: yRange,
|
|
70
|
+
id: yAxisId
|
|
71
|
+
} = _ref3,
|
|
72
|
+
yAxisVisualProps = _objectWithoutPropertiesLoose(_ref3, _excluded3);
|
|
73
|
+
const xAxisConfig = {
|
|
74
|
+
scaleType: xScaleType,
|
|
75
|
+
data: xData,
|
|
76
|
+
categoryPadding: xCategoryPadding,
|
|
77
|
+
domain: xDomain,
|
|
78
|
+
domainLimit: xDomainLimit,
|
|
79
|
+
range: xRange
|
|
80
|
+
};
|
|
81
|
+
const yAxisConfig = {
|
|
82
|
+
scaleType: yScaleType,
|
|
83
|
+
data: yData,
|
|
84
|
+
categoryPadding: yCategoryPadding,
|
|
85
|
+
domain: yDomain,
|
|
86
|
+
domainLimit: yDomainLimit,
|
|
87
|
+
range: yRange
|
|
88
|
+
};
|
|
89
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _extends({}, chartProps, {
|
|
90
|
+
ref: ref,
|
|
91
|
+
inset: calculatedInset,
|
|
92
|
+
series: chartSeries,
|
|
93
|
+
xAxis: xAxisConfig,
|
|
94
|
+
yAxis: yAxisConfig,
|
|
95
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _extends({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _extends({
|
|
96
|
+
axisId: yAxisId
|
|
97
|
+
}, yAxisVisualProps)), hasData && (series == null ? void 0 : series.map(_ref4 => {
|
|
98
|
+
let {
|
|
99
|
+
id
|
|
100
|
+
} = _ref4,
|
|
101
|
+
linePropsFromSeries = _objectWithoutPropertiesLoose(_ref4, _excluded4);
|
|
102
|
+
return /*#__PURE__*/_jsx(Line, _extends({
|
|
103
|
+
AreaComponent: AreaComponent,
|
|
104
|
+
LineComponent: LineComponent,
|
|
105
|
+
areaType: areaType,
|
|
106
|
+
curve: curve,
|
|
107
|
+
renderPoints: renderPoints,
|
|
108
|
+
seriesId: id,
|
|
109
|
+
showArea: showArea,
|
|
110
|
+
strokeWidth: strokeWidth,
|
|
111
|
+
type: type
|
|
112
|
+
}, linePropsFromSeries), id);
|
|
113
|
+
})), children]
|
|
114
|
+
}));
|
|
115
|
+
}));
|
|
@@ -0,0 +1,115 @@
|
|
|
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 { memo, useMemo } from 'react';
|
|
3
|
+
import { G } from 'react-native-svg';
|
|
4
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
5
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
6
|
+
import { ChartText } from '../text';
|
|
7
|
+
import { getPointOnScale } from '../utils';
|
|
8
|
+
import { DottedLine } from './DottedLine';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for ReferenceLine label rendering using ChartText.
|
|
12
|
+
*/
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
export const ReferenceLine = /*#__PURE__*/memo(_ref => {
|
|
15
|
+
let {
|
|
16
|
+
dataX,
|
|
17
|
+
dataY,
|
|
18
|
+
yAxisId,
|
|
19
|
+
label,
|
|
20
|
+
labelPosition = dataY !== undefined ? 'right' : 'top',
|
|
21
|
+
testID,
|
|
22
|
+
LineComponent = DottedLine,
|
|
23
|
+
stroke,
|
|
24
|
+
labelProps
|
|
25
|
+
} = _ref;
|
|
26
|
+
const theme = useTheme();
|
|
27
|
+
const {
|
|
28
|
+
getXScale,
|
|
29
|
+
getYScale,
|
|
30
|
+
drawingArea
|
|
31
|
+
} = useCartesianChartContext();
|
|
32
|
+
const effectiveLineStroke = stroke != null ? stroke : theme.color.bgLine;
|
|
33
|
+
|
|
34
|
+
// Merge default props with user provided props
|
|
35
|
+
const finalLabelProps = useMemo(() => _extends({
|
|
36
|
+
borderRadius: 8,
|
|
37
|
+
color: theme.color.fgMuted,
|
|
38
|
+
inset: {
|
|
39
|
+
top: 8,
|
|
40
|
+
bottom: 8,
|
|
41
|
+
left: 12,
|
|
42
|
+
right: 12
|
|
43
|
+
}
|
|
44
|
+
}, dataY !== undefined ? {
|
|
45
|
+
verticalAlignment: 'middle'
|
|
46
|
+
} : {
|
|
47
|
+
horizontalAlignment: 'center'
|
|
48
|
+
}, labelProps), [dataY, labelProps, theme.color.fgMuted]);
|
|
49
|
+
// Horizontal reference line logic
|
|
50
|
+
if (dataY !== undefined) {
|
|
51
|
+
const yScale = getYScale(yAxisId);
|
|
52
|
+
|
|
53
|
+
// Don't render if we don't have a scale
|
|
54
|
+
if (!yScale) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const yPixel = yScale(dataY);
|
|
58
|
+
if (yPixel === undefined) return null;
|
|
59
|
+
let labelX;
|
|
60
|
+
if (labelPosition === 'left') {
|
|
61
|
+
labelX = drawingArea.x;
|
|
62
|
+
} else if (labelPosition === 'center') {
|
|
63
|
+
labelX = drawingArea.x + drawingArea.width / 2;
|
|
64
|
+
} else {
|
|
65
|
+
labelX = drawingArea.x + drawingArea.width;
|
|
66
|
+
}
|
|
67
|
+
return /*#__PURE__*/_jsxs(G, {
|
|
68
|
+
"data-testid": testID,
|
|
69
|
+
children: [/*#__PURE__*/_jsx(LineComponent, {
|
|
70
|
+
animate: false,
|
|
71
|
+
d: "M" + drawingArea.x + "," + yPixel + " L" + (drawingArea.x + drawingArea.width) + "," + yPixel,
|
|
72
|
+
stroke: effectiveLineStroke
|
|
73
|
+
}), label && /*#__PURE__*/_jsx(ChartText, _extends({}, finalLabelProps, {
|
|
74
|
+
x: labelX,
|
|
75
|
+
y: yPixel,
|
|
76
|
+
children: label
|
|
77
|
+
}))]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Vertical reference line logic
|
|
82
|
+
if (dataX !== undefined) {
|
|
83
|
+
const xScale = getXScale();
|
|
84
|
+
|
|
85
|
+
// Don't render if we don't have scales
|
|
86
|
+
if (!xScale) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const xPixel = getPointOnScale(dataX, xScale);
|
|
90
|
+
if (xPixel === undefined) return null;
|
|
91
|
+
let labelY;
|
|
92
|
+
if (labelPosition === 'top') {
|
|
93
|
+
labelY = drawingArea.y;
|
|
94
|
+
} else if (labelPosition === 'middle') {
|
|
95
|
+
labelY = drawingArea.y + drawingArea.height / 2;
|
|
96
|
+
} else {
|
|
97
|
+
labelY = drawingArea.y + drawingArea.height;
|
|
98
|
+
}
|
|
99
|
+
return /*#__PURE__*/_jsxs(G, {
|
|
100
|
+
"data-testid": testID,
|
|
101
|
+
children: [/*#__PURE__*/_jsx(LineComponent, {
|
|
102
|
+
animate: false,
|
|
103
|
+
d: "M" + xPixel + "," + drawingArea.y + " L" + xPixel + "," + (drawingArea.y + drawingArea.height),
|
|
104
|
+
stroke: effectiveLineStroke
|
|
105
|
+
}), label && /*#__PURE__*/_jsx(ChartText, _extends({}, finalLabelProps, {
|
|
106
|
+
x: xPixel,
|
|
107
|
+
y: labelY,
|
|
108
|
+
children: label
|
|
109
|
+
}))]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Should not reach here if types are correct
|
|
114
|
+
return null;
|
|
115
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
6
|
+
import { Path } from '../Path';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
/**
|
|
9
|
+
* A customizable solid line component which uses path element.
|
|
10
|
+
*/
|
|
11
|
+
export const SolidLine = /*#__PURE__*/memo(_ref => {
|
|
12
|
+
let {
|
|
13
|
+
fill = 'none',
|
|
14
|
+
stroke,
|
|
15
|
+
strokeLinecap = 'round',
|
|
16
|
+
strokeLinejoin = 'round',
|
|
17
|
+
strokeOpacity = 1,
|
|
18
|
+
strokeWidth = 2
|
|
19
|
+
} = _ref,
|
|
20
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
21
|
+
const theme = useTheme();
|
|
22
|
+
return /*#__PURE__*/_jsx(Path, _extends({
|
|
23
|
+
clipOffset: strokeWidth,
|
|
24
|
+
fill: fill,
|
|
25
|
+
stroke: stroke != null ? stroke : theme.color.bgLine,
|
|
26
|
+
strokeLinecap: strokeLinecap,
|
|
27
|
+
strokeLinejoin: strokeLinejoin,
|
|
28
|
+
strokeOpacity: strokeOpacity,
|
|
29
|
+
strokeWidth: strokeWidth
|
|
30
|
+
}, props));
|
|
31
|
+
});
|