@coinbase/cds-mobile-visualization 3.4.0-beta.4 → 3.4.0-beta.6
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 +13 -0
- package/dts/chart/CartesianChart.d.ts +57 -33
- package/dts/chart/CartesianChart.d.ts.map +1 -1
- package/dts/chart/ChartContextBridge.d.ts +28 -0
- package/dts/chart/ChartContextBridge.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +77 -34
- package/dts/chart/Path.d.ts.map +1 -1
- package/dts/chart/PeriodSelector.d.ts +1 -1
- package/dts/chart/PeriodSelector.d.ts.map +1 -1
- package/dts/chart/area/Area.d.ts +42 -27
- package/dts/chart/area/Area.d.ts.map +1 -1
- package/dts/chart/area/AreaChart.d.ts +51 -10
- package/dts/chart/area/AreaChart.d.ts.map +1 -1
- package/dts/chart/area/DottedArea.d.ts +21 -2
- package/dts/chart/area/DottedArea.d.ts.map +1 -1
- package/dts/chart/area/GradientArea.d.ts +19 -13
- package/dts/chart/area/GradientArea.d.ts.map +1 -1
- package/dts/chart/area/SolidArea.d.ts +17 -2
- package/dts/chart/area/SolidArea.d.ts.map +1 -1
- package/dts/chart/axis/Axis.d.ts +68 -78
- package/dts/chart/axis/Axis.d.ts.map +1 -1
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts +8 -0
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +1 -0
- package/dts/chart/axis/XAxis.d.ts +1 -1
- package/dts/chart/axis/XAxis.d.ts.map +1 -1
- package/dts/chart/axis/YAxis.d.ts +2 -2
- package/dts/chart/axis/YAxis.d.ts.map +1 -1
- package/dts/chart/axis/index.d.ts +1 -0
- package/dts/chart/axis/index.d.ts.map +1 -1
- package/dts/chart/bar/Bar.d.ts +16 -13
- package/dts/chart/bar/Bar.d.ts.map +1 -1
- package/dts/chart/bar/BarChart.d.ts +36 -20
- package/dts/chart/bar/BarChart.d.ts.map +1 -1
- package/dts/chart/bar/BarPlot.d.ts +2 -1
- package/dts/chart/bar/BarPlot.d.ts.map +1 -1
- package/dts/chart/bar/BarStack.d.ts +39 -48
- package/dts/chart/bar/BarStack.d.ts.map +1 -1
- package/dts/chart/bar/BarStackGroup.d.ts +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
- package/dts/chart/bar/DefaultBar.d.ts +1 -1
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
- package/dts/chart/gradient/Gradient.d.ts +25 -0
- package/dts/chart/gradient/Gradient.d.ts.map +1 -0
- package/dts/chart/gradient/index.d.ts +2 -0
- package/dts/chart/gradient/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +3 -1
- package/dts/chart/index.d.ts.map +1 -1
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts +9 -0
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +13 -5
- package/dts/chart/line/DottedLine.d.ts.map +1 -1
- package/dts/chart/line/Line.d.ts +62 -25
- package/dts/chart/line/Line.d.ts.map +1 -1
- package/dts/chart/line/LineChart.d.ts +43 -9
- package/dts/chart/line/LineChart.d.ts.map +1 -1
- package/dts/chart/line/ReferenceLine.d.ts +65 -22
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
- package/dts/chart/line/SolidLine.d.ts +8 -5
- package/dts/chart/line/SolidLine.d.ts.map +1 -1
- package/dts/chart/line/index.d.ts +1 -1
- package/dts/chart/line/index.d.ts.map +1 -1
- package/dts/chart/point/DefaultPointLabel.d.ts +10 -0
- package/dts/chart/point/DefaultPointLabel.d.ts.map +1 -0
- package/dts/chart/point/Point.d.ts +120 -0
- package/dts/chart/point/Point.d.ts.map +1 -0
- package/dts/chart/point/index.d.ts +3 -0
- package/dts/chart/point/index.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +8 -0
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +12 -0
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +11 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +168 -41
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +44 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +31 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +6 -3
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
- package/dts/chart/scrubber/index.d.ts +3 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -1
- package/dts/chart/text/ChartText.d.ts +151 -77
- package/dts/chart/text/ChartText.d.ts.map +1 -1
- package/dts/chart/text/{SmartChartTextGroup.d.ts → ChartTextGroup.d.ts} +9 -3
- package/dts/chart/text/ChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +1 -1
- package/dts/chart/text/index.d.ts.map +1 -1
- package/dts/chart/utils/chart.d.ts +34 -7
- package/dts/chart/utils/chart.d.ts.map +1 -1
- package/dts/chart/utils/context.d.ts +28 -7
- package/dts/chart/utils/context.d.ts.map +1 -1
- package/dts/chart/utils/gradient.d.ts +117 -0
- package/dts/chart/utils/gradient.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +3 -0
- package/dts/chart/utils/index.d.ts.map +1 -1
- package/dts/chart/utils/path.d.ts +53 -0
- package/dts/chart/utils/path.d.ts.map +1 -1
- package/dts/chart/utils/point.d.ts +60 -1
- package/dts/chart/utils/point.d.ts.map +1 -1
- package/dts/chart/utils/scale.d.ts +91 -0
- package/dts/chart/utils/scale.d.ts.map +1 -1
- package/dts/chart/utils/scrubber.d.ts +39 -0
- package/dts/chart/utils/scrubber.d.ts.map +1 -0
- package/dts/chart/utils/transition.d.ts +140 -0
- package/dts/chart/utils/transition.d.ts.map +1 -0
- package/esm/chart/CartesianChart.js +164 -70
- package/esm/chart/ChartContextBridge.js +148 -0
- package/esm/chart/Path.js +196 -113
- package/esm/chart/PeriodSelector.js +1 -1
- package/esm/chart/__stories__/CartesianChart.stories.js +371 -129
- package/esm/chart/__stories__/Chart.stories.js +2 -4
- package/esm/chart/area/Area.js +25 -35
- package/esm/chart/area/AreaChart.js +17 -12
- package/esm/chart/area/DottedArea.js +61 -109
- package/esm/chart/area/GradientArea.js +35 -91
- package/esm/chart/area/SolidArea.js +22 -8
- package/esm/chart/area/__stories__/AreaChart.stories.js +1 -1
- package/esm/chart/axis/Axis.js +2 -0
- package/esm/chart/axis/DefaultAxisTickLabel.js +11 -0
- package/esm/chart/axis/XAxis.js +62 -56
- package/esm/chart/axis/YAxis.js +58 -52
- package/esm/chart/axis/__stories__/Axis.stories.js +0 -1
- package/esm/chart/axis/index.js +1 -0
- package/esm/chart/bar/Bar.js +3 -1
- package/esm/chart/bar/BarChart.js +15 -37
- package/esm/chart/bar/BarPlot.js +41 -35
- package/esm/chart/bar/BarStack.js +75 -38
- package/esm/chart/bar/BarStackGroup.js +6 -16
- package/esm/chart/bar/DefaultBar.js +26 -48
- package/esm/chart/bar/DefaultBarStack.js +23 -58
- package/esm/chart/bar/__stories__/BarChart.stories.js +463 -77
- package/esm/chart/gradient/Gradient.js +53 -0
- package/esm/chart/gradient/index.js +1 -0
- package/esm/chart/index.js +3 -1
- package/esm/chart/line/DefaultReferenceLineLabel.js +66 -0
- package/esm/chart/line/DottedLine.js +29 -14
- package/esm/chart/line/Line.js +106 -67
- package/esm/chart/line/LineChart.js +20 -14
- package/esm/chart/line/ReferenceLine.js +73 -62
- package/esm/chart/line/SolidLine.js +25 -10
- package/esm/chart/line/__stories__/LineChart.stories.js +2098 -1975
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +83 -28
- package/esm/chart/line/index.js +1 -1
- package/esm/chart/point/DefaultPointLabel.js +39 -0
- package/esm/chart/point/Point.js +188 -0
- package/esm/chart/point/index.js +2 -0
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +179 -0
- package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +43 -0
- package/esm/chart/scrubber/DefaultScrubberLabel.js +28 -0
- package/esm/chart/scrubber/Scrubber.js +130 -148
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +161 -0
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +185 -0
- package/esm/chart/scrubber/ScrubberProvider.js +46 -54
- package/esm/chart/scrubber/index.js +3 -1
- package/esm/chart/text/ChartText.js +242 -174
- package/esm/chart/text/{SmartChartTextGroup.js → ChartTextGroup.js} +6 -5
- package/esm/chart/text/index.js +1 -1
- package/esm/chart/utils/chart.js +44 -3
- package/esm/chart/utils/gradient.js +305 -0
- package/esm/chart/utils/index.js +3 -0
- package/esm/chart/utils/path.js +76 -8
- package/esm/chart/utils/point.js +116 -5
- package/esm/chart/utils/scale.js +230 -1
- package/esm/chart/utils/scrubber.js +139 -0
- package/esm/chart/utils/transition.js +221 -0
- package/package.json +11 -9
- package/dts/chart/Point.d.ts +0 -103
- package/dts/chart/Point.d.ts.map +0 -1
- package/dts/chart/line/GradientLine.d.ts +0 -45
- package/dts/chart/line/GradientLine.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +0 -75
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +0 -1
- package/dts/chart/text/SmartChartTextGroup.d.ts.map +0 -1
- package/esm/chart/Point.js +0 -111
- package/esm/chart/line/GradientLine.js +0 -62
- package/esm/chart/scrubber/ScrubberBeacon.js +0 -199
|
@@ -1,16 +1,63 @@
|
|
|
1
|
+
const _excluded = ["accentColor", "yellowColor"];
|
|
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, useCallback } from 'react';
|
|
1
5
|
import { useTheme } from '@coinbase/cds-mobile';
|
|
2
6
|
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
7
|
+
import { DefaultReferenceLineLabel } from '../DefaultReferenceLineLabel';
|
|
8
|
+
import { DottedLine } from '../DottedLine';
|
|
3
9
|
import { LineChart } from '../LineChart';
|
|
4
10
|
import { ReferenceLine } from '../ReferenceLine';
|
|
5
11
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
const LiquidationLabelMobile = /*#__PURE__*/memo(_ref => {
|
|
13
|
+
let {
|
|
14
|
+
accentColor,
|
|
15
|
+
yellowColor
|
|
16
|
+
} = _ref,
|
|
17
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
18
|
+
return /*#__PURE__*/_jsx(DefaultReferenceLineLabel, _extends({}, props, {
|
|
19
|
+
background: accentColor,
|
|
20
|
+
borderRadius: 100,
|
|
21
|
+
color: "rgb(" + yellowColor + ")",
|
|
22
|
+
horizontalAlignment: "left",
|
|
23
|
+
inset: {
|
|
24
|
+
top: 4,
|
|
25
|
+
bottom: 4,
|
|
26
|
+
left: 8,
|
|
27
|
+
right: 8
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
});
|
|
6
31
|
const ReferenceLineStories = () => {
|
|
7
32
|
const theme = useTheme();
|
|
33
|
+
const liquidationLabelComponent = useCallback(props => /*#__PURE__*/_jsx(LiquidationLabelMobile, _extends({}, props, {
|
|
34
|
+
accentColor: theme.color.accentSubtleYellow,
|
|
35
|
+
yellowColor: theme.spectrum.yellow70
|
|
36
|
+
})), [theme.color.accentSubtleYellow, theme.spectrum.yellow70]);
|
|
8
37
|
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
9
38
|
children: [/*#__PURE__*/_jsx(Example, {
|
|
10
|
-
title: "
|
|
39
|
+
title: "Simple Reference Line",
|
|
40
|
+
children: /*#__PURE__*/_jsx(LineChart, {
|
|
41
|
+
showArea: true,
|
|
42
|
+
height: 250,
|
|
43
|
+
series: [{
|
|
44
|
+
id: 'prices',
|
|
45
|
+
data: [10, 22, 29, 45, 98, 45, 22, 52, 21, 4, 68, 20, 21, 58],
|
|
46
|
+
color: theme.color.fgPositive
|
|
47
|
+
}],
|
|
48
|
+
children: /*#__PURE__*/_jsx(ReferenceLine, {
|
|
49
|
+
LineComponent: props => /*#__PURE__*/_jsx(DottedLine, _extends({}, props, {
|
|
50
|
+
dashIntervals: [0, 16],
|
|
51
|
+
strokeWidth: 3
|
|
52
|
+
})),
|
|
53
|
+
dataY: 10,
|
|
54
|
+
stroke: theme.color.fg
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
58
|
+
title: "With Labels",
|
|
11
59
|
children: /*#__PURE__*/_jsxs(LineChart, {
|
|
12
60
|
showArea: true,
|
|
13
|
-
curve: "monotone",
|
|
14
61
|
height: 250,
|
|
15
62
|
inset: 0,
|
|
16
63
|
series: [{
|
|
@@ -20,26 +67,46 @@ const ReferenceLineStories = () => {
|
|
|
20
67
|
children: [/*#__PURE__*/_jsx(ReferenceLine, {
|
|
21
68
|
dataX: 4,
|
|
22
69
|
label: "Vertical Reference Line",
|
|
23
|
-
|
|
24
|
-
horizontalAlignment: 'left',
|
|
25
|
-
dx: 6,
|
|
26
|
-
inset: 0
|
|
27
|
-
}
|
|
70
|
+
labelHorizontalAlignment: "left"
|
|
28
71
|
}), /*#__PURE__*/_jsx(ReferenceLine, {
|
|
29
72
|
dataY: 70,
|
|
30
73
|
label: "Horizontal Reference Line",
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
74
|
+
labelHorizontalAlignment: "right",
|
|
75
|
+
labelVerticalAlignment: "bottom"
|
|
76
|
+
})]
|
|
77
|
+
})
|
|
78
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
79
|
+
title: "Label Customization",
|
|
80
|
+
children: /*#__PURE__*/_jsxs(LineChart, {
|
|
81
|
+
showArea: true,
|
|
82
|
+
height: 250,
|
|
83
|
+
series: [{
|
|
84
|
+
id: 'prices',
|
|
85
|
+
data: [10, 22, 29, 45, 98, 45, 22, 52, 21, 4, 68, 20, 21, 58]
|
|
86
|
+
}],
|
|
87
|
+
children: [/*#__PURE__*/_jsx(ReferenceLine, {
|
|
88
|
+
dataY: 75,
|
|
89
|
+
label: "Top Right",
|
|
90
|
+
labelDx: -8,
|
|
91
|
+
labelDy: -8,
|
|
92
|
+
labelFont: "label1",
|
|
93
|
+
labelHorizontalAlignment: "right",
|
|
94
|
+
labelPosition: "right",
|
|
95
|
+
labelVerticalAlignment: "bottom"
|
|
96
|
+
}), /*#__PURE__*/_jsx(ReferenceLine, {
|
|
97
|
+
dataX: 7,
|
|
98
|
+
label: "Bottom Left",
|
|
99
|
+
labelDx: 8,
|
|
100
|
+
labelDy: 8,
|
|
101
|
+
labelFont: "label1",
|
|
102
|
+
labelHorizontalAlignment: "left",
|
|
103
|
+
labelPosition: "top",
|
|
104
|
+
labelVerticalAlignment: "top"
|
|
37
105
|
})]
|
|
38
106
|
})
|
|
39
107
|
}), /*#__PURE__*/_jsx(Example, {
|
|
40
|
-
title: "With Custom Label",
|
|
108
|
+
title: "With Custom Label Component",
|
|
41
109
|
children: /*#__PURE__*/_jsx(LineChart, {
|
|
42
|
-
curve: "monotone",
|
|
43
110
|
height: 250,
|
|
44
111
|
inset: {
|
|
45
112
|
right: 32,
|
|
@@ -52,22 +119,10 @@ const ReferenceLineStories = () => {
|
|
|
52
119
|
data: [10, 22, 29, 45, 98, 45, 22, 52, 21, 4, 68, 20, 21, 58]
|
|
53
120
|
}],
|
|
54
121
|
children: /*#__PURE__*/_jsx(ReferenceLine, {
|
|
122
|
+
LabelComponent: liquidationLabelComponent,
|
|
55
123
|
dataY: 25,
|
|
56
124
|
label: "Liquidation",
|
|
57
125
|
labelPosition: "left",
|
|
58
|
-
labelProps: {
|
|
59
|
-
dx: 4,
|
|
60
|
-
borderRadius: 100,
|
|
61
|
-
inset: {
|
|
62
|
-
top: 4,
|
|
63
|
-
bottom: 4,
|
|
64
|
-
left: 8,
|
|
65
|
-
right: 8
|
|
66
|
-
},
|
|
67
|
-
horizontalAlignment: 'left',
|
|
68
|
-
color: "rgb(" + theme.spectrum.yellow70 + ")",
|
|
69
|
-
background: theme.color.accentSubtleYellow
|
|
70
|
-
},
|
|
71
126
|
stroke: theme.color.bgWarning
|
|
72
127
|
})
|
|
73
128
|
})
|
package/esm/chart/line/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// codegen:start {preset: barrel, include: ./*.tsx, exclude: ./__stories__/*.tsx}
|
|
2
|
+
export * from './DefaultReferenceLineLabel';
|
|
2
3
|
export * from './DottedLine';
|
|
3
|
-
export * from './GradientLine';
|
|
4
4
|
export * from './Line';
|
|
5
5
|
export * from './LineChart';
|
|
6
6
|
export * from './ReferenceLine';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const _excluded = ["x", "y", "position", "offset", "children"];
|
|
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, useMemo } from 'react';
|
|
5
|
+
import { ChartText } from '../text';
|
|
6
|
+
import { getAlignmentFromPosition, getLabelCoordinates } from '../utils/point';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
/**
|
|
9
|
+
* DefaultPointLabel is the default label component for point labels.
|
|
10
|
+
* It renders text at the specified position relative to the point.
|
|
11
|
+
*/
|
|
12
|
+
export const DefaultPointLabel = /*#__PURE__*/memo(_ref => {
|
|
13
|
+
let {
|
|
14
|
+
x,
|
|
15
|
+
y,
|
|
16
|
+
position = 'center',
|
|
17
|
+
offset,
|
|
18
|
+
children
|
|
19
|
+
} = _ref,
|
|
20
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
21
|
+
const {
|
|
22
|
+
horizontalAlignment,
|
|
23
|
+
verticalAlignment
|
|
24
|
+
} = useMemo(() => getAlignmentFromPosition(position), [position]);
|
|
25
|
+
const labelCoordinates = useMemo(() => {
|
|
26
|
+
if (offset === undefined) return {
|
|
27
|
+
x,
|
|
28
|
+
y
|
|
29
|
+
};
|
|
30
|
+
return getLabelCoordinates(x, y, position, offset);
|
|
31
|
+
}, [x, y, position, offset]);
|
|
32
|
+
return /*#__PURE__*/_jsx(ChartText, _extends({}, props, {
|
|
33
|
+
horizontalAlignment: horizontalAlignment,
|
|
34
|
+
verticalAlignment: verticalAlignment,
|
|
35
|
+
x: labelCoordinates.x,
|
|
36
|
+
y: labelCoordinates.y,
|
|
37
|
+
children: children
|
|
38
|
+
}));
|
|
39
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { memo, useEffect, useMemo } from 'react';
|
|
2
|
+
import { cancelAnimation, useDerivedValue, useSharedValue } from 'react-native-reanimated';
|
|
3
|
+
import { usePreviousValue } from '@coinbase/cds-common/hooks/usePreviousValue';
|
|
4
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
5
|
+
import { Circle, Group, interpolateColors } from '@shopify/react-native-skia';
|
|
6
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
7
|
+
import { projectPoint } from '../utils';
|
|
8
|
+
import { buildTransition, defaultTransition } from '../utils/transition';
|
|
9
|
+
import { DefaultPointLabel } from './DefaultPointLabel';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Props for point label components.
|
|
13
|
+
*/
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
15
|
+
export const Point = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
let {
|
|
17
|
+
dataX,
|
|
18
|
+
dataY,
|
|
19
|
+
yAxisId,
|
|
20
|
+
fill: fillProp,
|
|
21
|
+
radius = 5,
|
|
22
|
+
opacity,
|
|
23
|
+
stroke: strokeProp,
|
|
24
|
+
strokeWidth = 2,
|
|
25
|
+
label,
|
|
26
|
+
LabelComponent = DefaultPointLabel,
|
|
27
|
+
labelPosition = 'center',
|
|
28
|
+
labelOffset,
|
|
29
|
+
labelFont,
|
|
30
|
+
transition = defaultTransition,
|
|
31
|
+
animate: animateProp
|
|
32
|
+
} = _ref;
|
|
33
|
+
const theme = useTheme();
|
|
34
|
+
const stroke = strokeProp != null ? strokeProp : theme.color.bg;
|
|
35
|
+
const fill = fillProp != null ? fillProp : theme.color.fgPrimary;
|
|
36
|
+
const {
|
|
37
|
+
getXScale,
|
|
38
|
+
getYScale,
|
|
39
|
+
animate: animationEnabled,
|
|
40
|
+
drawingArea
|
|
41
|
+
} = useCartesianChartContext();
|
|
42
|
+
const animate = animateProp != null ? animateProp : animationEnabled;
|
|
43
|
+
const xScale = getXScale();
|
|
44
|
+
const yScale = getYScale(yAxisId);
|
|
45
|
+
const shouldAnimate = animate != null ? animate : false;
|
|
46
|
+
|
|
47
|
+
// Calculate pixel coordinates from data coordinates
|
|
48
|
+
const pixelCoordinate = useMemo(() => {
|
|
49
|
+
if (!xScale || !yScale) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return projectPoint({
|
|
53
|
+
x: dataX,
|
|
54
|
+
y: dataY,
|
|
55
|
+
xScale,
|
|
56
|
+
yScale
|
|
57
|
+
});
|
|
58
|
+
}, [xScale, yScale, dataX, dataY]);
|
|
59
|
+
const previousPixelCoordinate = usePreviousValue(pixelCoordinate);
|
|
60
|
+
const previousFill = usePreviousValue(fill);
|
|
61
|
+
|
|
62
|
+
// Animated values for position
|
|
63
|
+
const animatedX = useSharedValue(0);
|
|
64
|
+
const animatedY = useSharedValue(0);
|
|
65
|
+
|
|
66
|
+
// Animated value for color interpolation (0 = old color, 1 = new color)
|
|
67
|
+
const colorProgress = useSharedValue(1);
|
|
68
|
+
|
|
69
|
+
// Update position when coordinates change
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!pixelCoordinate) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (shouldAnimate && previousPixelCoordinate) {
|
|
75
|
+
animatedX.value = buildTransition(pixelCoordinate.x, transition);
|
|
76
|
+
animatedY.value = buildTransition(pixelCoordinate.y, transition);
|
|
77
|
+
} else {
|
|
78
|
+
cancelAnimation(animatedX);
|
|
79
|
+
cancelAnimation(animatedY);
|
|
80
|
+
animatedX.value = pixelCoordinate.x;
|
|
81
|
+
animatedY.value = pixelCoordinate.y;
|
|
82
|
+
}
|
|
83
|
+
}, [pixelCoordinate, shouldAnimate, previousPixelCoordinate, animatedX, animatedY, transition]);
|
|
84
|
+
|
|
85
|
+
// Update color when fill changes
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (shouldAnimate && previousFill && previousFill !== fill) {
|
|
88
|
+
colorProgress.value = 0;
|
|
89
|
+
colorProgress.value = buildTransition(1, transition);
|
|
90
|
+
} else {
|
|
91
|
+
cancelAnimation(colorProgress);
|
|
92
|
+
colorProgress.value = 1;
|
|
93
|
+
}
|
|
94
|
+
}, [fill, shouldAnimate, previousFill, colorProgress, transition]);
|
|
95
|
+
|
|
96
|
+
// Create animated point for circles
|
|
97
|
+
const animatedPoint = useDerivedValue(() => {
|
|
98
|
+
return {
|
|
99
|
+
x: animatedX.value,
|
|
100
|
+
y: animatedY.value
|
|
101
|
+
};
|
|
102
|
+
}, [animatedX, animatedY]);
|
|
103
|
+
|
|
104
|
+
// Interpolate between previous and current fill color
|
|
105
|
+
const animatedFillColor = useDerivedValue(() => {
|
|
106
|
+
if (!previousFill || previousFill === fill) {
|
|
107
|
+
return fill;
|
|
108
|
+
}
|
|
109
|
+
return interpolateColors(colorProgress.value, [0, 1], [previousFill, fill]);
|
|
110
|
+
}, [colorProgress, previousFill, fill]);
|
|
111
|
+
|
|
112
|
+
// Check if point is within drawing area
|
|
113
|
+
const isWithinDrawingArea = useDerivedValue(() => {
|
|
114
|
+
return animatedX.value >= drawingArea.x && animatedX.value <= drawingArea.x + drawingArea.width && animatedY.value >= drawingArea.y && animatedY.value <= drawingArea.y + drawingArea.height;
|
|
115
|
+
}, [animatedX, animatedY, drawingArea]);
|
|
116
|
+
|
|
117
|
+
// Compute effective opacity based on drawing area bounds
|
|
118
|
+
const effectiveOpacity = useDerivedValue(() => {
|
|
119
|
+
const baseOpacity = opacity != null ? opacity : 1;
|
|
120
|
+
return isWithinDrawingArea.value ? baseOpacity : 0;
|
|
121
|
+
}, [isWithinDrawingArea, opacity]);
|
|
122
|
+
const offset = useMemo(() => labelOffset != null ? labelOffset : radius * 2, [labelOffset, radius]);
|
|
123
|
+
if (!pixelCoordinate) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// If animation is disabled or on first render, use static rendering
|
|
128
|
+
if (!shouldAnimate || !previousPixelCoordinate) {
|
|
129
|
+
const isWithinBounds = pixelCoordinate.x >= drawingArea.x && pixelCoordinate.x <= drawingArea.x + drawingArea.width && pixelCoordinate.y >= drawingArea.y && pixelCoordinate.y <= drawingArea.y + drawingArea.height;
|
|
130
|
+
const staticOpacity = isWithinBounds ? opacity != null ? opacity : 1 : 0;
|
|
131
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
132
|
+
children: [/*#__PURE__*/_jsxs(Group, {
|
|
133
|
+
opacity: staticOpacity,
|
|
134
|
+
children: [strokeWidth > 0 && /*#__PURE__*/_jsx(Circle, {
|
|
135
|
+
c: {
|
|
136
|
+
x: pixelCoordinate.x,
|
|
137
|
+
y: pixelCoordinate.y
|
|
138
|
+
},
|
|
139
|
+
color: stroke,
|
|
140
|
+
r: radius + strokeWidth / 2
|
|
141
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
142
|
+
c: {
|
|
143
|
+
x: pixelCoordinate.x,
|
|
144
|
+
y: pixelCoordinate.y
|
|
145
|
+
},
|
|
146
|
+
color: fill,
|
|
147
|
+
r: radius - strokeWidth / 2
|
|
148
|
+
})]
|
|
149
|
+
}), label && /*#__PURE__*/_jsx(LabelComponent, {
|
|
150
|
+
dataX: dataX,
|
|
151
|
+
dataY: dataY,
|
|
152
|
+
fill: fill,
|
|
153
|
+
font: labelFont,
|
|
154
|
+
offset: offset,
|
|
155
|
+
position: labelPosition,
|
|
156
|
+
x: pixelCoordinate.x,
|
|
157
|
+
y: pixelCoordinate.y,
|
|
158
|
+
children: label
|
|
159
|
+
})]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Animated rendering
|
|
164
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
165
|
+
children: [/*#__PURE__*/_jsxs(Group, {
|
|
166
|
+
opacity: effectiveOpacity,
|
|
167
|
+
children: [strokeWidth > 0 && /*#__PURE__*/_jsx(Circle, {
|
|
168
|
+
c: animatedPoint,
|
|
169
|
+
color: stroke,
|
|
170
|
+
r: radius + strokeWidth / 2
|
|
171
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
172
|
+
c: animatedPoint,
|
|
173
|
+
color: animatedFillColor,
|
|
174
|
+
r: radius - strokeWidth / 2
|
|
175
|
+
})]
|
|
176
|
+
}), label && /*#__PURE__*/_jsx(LabelComponent, {
|
|
177
|
+
dataX: dataX,
|
|
178
|
+
dataY: dataY,
|
|
179
|
+
fill: fill,
|
|
180
|
+
font: labelFont,
|
|
181
|
+
offset: offset,
|
|
182
|
+
position: labelPosition,
|
|
183
|
+
x: pixelCoordinate.x,
|
|
184
|
+
y: pixelCoordinate.y,
|
|
185
|
+
children: label
|
|
186
|
+
})]
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
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 { forwardRef, memo, useImperativeHandle, useMemo } from 'react';
|
|
3
|
+
import { cancelAnimation, Easing, useAnimatedReaction, useDerivedValue, useSharedValue, withRepeat, withSequence } from 'react-native-reanimated';
|
|
4
|
+
import { useTheme } from '@coinbase/cds-mobile';
|
|
5
|
+
import { Circle, Group } from '@shopify/react-native-skia';
|
|
6
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
7
|
+
import { unwrapAnimatedValue } from '../utils';
|
|
8
|
+
import { projectPointWithSerializableScale } from '../utils/point';
|
|
9
|
+
import { buildTransition, defaultTransition } from '../utils/transition';
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const radius = 5;
|
|
12
|
+
const strokeWidth = 2;
|
|
13
|
+
const pulseOpacityStart = 0.5;
|
|
14
|
+
const pulseOpacityEnd = 0;
|
|
15
|
+
const pulseRadiusStart = 10;
|
|
16
|
+
const pulseRadiusEnd = 15;
|
|
17
|
+
const defaultPulseTransition = {
|
|
18
|
+
type: 'timing',
|
|
19
|
+
duration: 1600,
|
|
20
|
+
easing: Easing.bezier(0.0, 0.0, 0.0, 1.0)
|
|
21
|
+
};
|
|
22
|
+
const defaultPulseRepeatDelay = 400;
|
|
23
|
+
export const DefaultScrubberBeacon = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
24
|
+
let {
|
|
25
|
+
seriesId,
|
|
26
|
+
color: colorProp,
|
|
27
|
+
dataX,
|
|
28
|
+
dataY,
|
|
29
|
+
isIdle,
|
|
30
|
+
idlePulse,
|
|
31
|
+
animate = true,
|
|
32
|
+
transitions,
|
|
33
|
+
opacity: opacityProp = 1
|
|
34
|
+
} = _ref;
|
|
35
|
+
const theme = useTheme();
|
|
36
|
+
const {
|
|
37
|
+
getSeries,
|
|
38
|
+
getXSerializableScale,
|
|
39
|
+
getYSerializableScale,
|
|
40
|
+
drawingArea
|
|
41
|
+
} = useCartesianChartContext();
|
|
42
|
+
const targetSeries = useMemo(() => getSeries(seriesId), [getSeries, seriesId]);
|
|
43
|
+
const xScale = useMemo(() => getXSerializableScale(), [getXSerializableScale]);
|
|
44
|
+
const yScale = useMemo(() => getYSerializableScale(targetSeries == null ? void 0 : targetSeries.yAxisId), [getYSerializableScale, targetSeries == null ? void 0 : targetSeries.yAxisId]);
|
|
45
|
+
const color = useMemo(() => {
|
|
46
|
+
var _ref2;
|
|
47
|
+
return (_ref2 = colorProp != null ? colorProp : targetSeries == null ? void 0 : targetSeries.color) != null ? _ref2 : theme.color.fgPrimary;
|
|
48
|
+
}, [colorProp, targetSeries == null ? void 0 : targetSeries.color, theme.color.fgPrimary]);
|
|
49
|
+
const updateTransition = useMemo(() => {
|
|
50
|
+
var _transitions$update;
|
|
51
|
+
return (_transitions$update = transitions == null ? void 0 : transitions.update) != null ? _transitions$update : defaultTransition;
|
|
52
|
+
}, [transitions == null ? void 0 : transitions.update]);
|
|
53
|
+
const pulseTransition = useMemo(() => {
|
|
54
|
+
var _transitions$pulse;
|
|
55
|
+
return (_transitions$pulse = transitions == null ? void 0 : transitions.pulse) != null ? _transitions$pulse : defaultPulseTransition;
|
|
56
|
+
}, [transitions == null ? void 0 : transitions.pulse]);
|
|
57
|
+
const pulseRepeatDelay = useMemo(() => {
|
|
58
|
+
var _transitions$pulseRep;
|
|
59
|
+
return (_transitions$pulseRep = transitions == null ? void 0 : transitions.pulseRepeatDelay) != null ? _transitions$pulseRep : defaultPulseRepeatDelay;
|
|
60
|
+
}, [transitions == null ? void 0 : transitions.pulseRepeatDelay]);
|
|
61
|
+
const pulseOpacity = useSharedValue(0);
|
|
62
|
+
const pulseRadius = useSharedValue(pulseRadiusStart);
|
|
63
|
+
const animatedX = useSharedValue(0);
|
|
64
|
+
const animatedY = useSharedValue(0);
|
|
65
|
+
|
|
66
|
+
// Calculate the target point position - project data to pixels
|
|
67
|
+
const targetPoint = useDerivedValue(() => {
|
|
68
|
+
if (!xScale || !yScale) return {
|
|
69
|
+
x: 0,
|
|
70
|
+
y: 0
|
|
71
|
+
};
|
|
72
|
+
return projectPointWithSerializableScale({
|
|
73
|
+
x: unwrapAnimatedValue(dataX),
|
|
74
|
+
y: unwrapAnimatedValue(dataY),
|
|
75
|
+
xScale,
|
|
76
|
+
yScale
|
|
77
|
+
});
|
|
78
|
+
}, [dataX, dataY, xScale, yScale]);
|
|
79
|
+
useAnimatedReaction(() => {
|
|
80
|
+
return {
|
|
81
|
+
point: targetPoint.value,
|
|
82
|
+
isIdle: unwrapAnimatedValue(isIdle)
|
|
83
|
+
};
|
|
84
|
+
}, (current, previous) => {
|
|
85
|
+
// When animation is disabled, on initial render, or when we are starting,
|
|
86
|
+
// continuing, or finishing scrubbing we should immediately transition
|
|
87
|
+
if (!animate || previous === null || !previous.isIdle || !current.isIdle) {
|
|
88
|
+
animatedX.value = current.point.x;
|
|
89
|
+
animatedY.value = current.point.y;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
animatedX.value = buildTransition(current.point.x, updateTransition);
|
|
93
|
+
animatedY.value = buildTransition(current.point.y, updateTransition);
|
|
94
|
+
}, [animate, updateTransition]);
|
|
95
|
+
|
|
96
|
+
// Create animated point using the animated values
|
|
97
|
+
const animatedPoint = useDerivedValue(() => {
|
|
98
|
+
return {
|
|
99
|
+
x: animatedX.value,
|
|
100
|
+
y: animatedY.value
|
|
101
|
+
};
|
|
102
|
+
}, [animatedX, animatedY]);
|
|
103
|
+
useImperativeHandle(ref, () => ({
|
|
104
|
+
pulse: () => {
|
|
105
|
+
// Only trigger manual pulse when idlePulse is not enabled
|
|
106
|
+
if (!idlePulse) {
|
|
107
|
+
cancelAnimation(pulseOpacity);
|
|
108
|
+
cancelAnimation(pulseRadius);
|
|
109
|
+
|
|
110
|
+
// Manual pulse without delay
|
|
111
|
+
const immediatePulseTransition = _extends({}, pulseTransition, {
|
|
112
|
+
delay: 0
|
|
113
|
+
});
|
|
114
|
+
pulseOpacity.value = pulseOpacityStart;
|
|
115
|
+
pulseRadius.value = pulseRadiusStart;
|
|
116
|
+
pulseOpacity.value = buildTransition(pulseOpacityEnd, immediatePulseTransition);
|
|
117
|
+
pulseRadius.value = buildTransition(pulseRadiusEnd, immediatePulseTransition);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}), [idlePulse, pulseOpacity, pulseRadius, pulseTransition]);
|
|
121
|
+
|
|
122
|
+
// Watch idlePulse changes and control continuous pulse
|
|
123
|
+
useAnimatedReaction(() => idlePulse, (current, previous) => {
|
|
124
|
+
if (!animate) return;
|
|
125
|
+
if (current) {
|
|
126
|
+
// Start continuous pulse when idlePulse is enabled
|
|
127
|
+
// Create instant transition to reset pulse after delay
|
|
128
|
+
const instantTransition = {
|
|
129
|
+
type: 'timing',
|
|
130
|
+
duration: 0
|
|
131
|
+
};
|
|
132
|
+
const resetWithDelay = _extends({}, instantTransition, {
|
|
133
|
+
delay: pulseRepeatDelay
|
|
134
|
+
});
|
|
135
|
+
pulseOpacity.value = pulseOpacityStart;
|
|
136
|
+
pulseRadius.value = pulseRadiusStart;
|
|
137
|
+
pulseOpacity.value = withRepeat(withSequence(buildTransition(pulseOpacityEnd, pulseTransition), buildTransition(pulseOpacityStart, resetWithDelay)), -1,
|
|
138
|
+
// infinite loop
|
|
139
|
+
false);
|
|
140
|
+
pulseRadius.value = withRepeat(withSequence(buildTransition(pulseRadiusEnd, pulseTransition), buildTransition(pulseRadiusStart, resetWithDelay)), -1,
|
|
141
|
+
// infinite loop
|
|
142
|
+
false);
|
|
143
|
+
} else {
|
|
144
|
+
// Stop pulse when idlePulse is disabled
|
|
145
|
+
cancelAnimation(pulseOpacity);
|
|
146
|
+
cancelAnimation(pulseRadius);
|
|
147
|
+
pulseOpacity.value = pulseOpacityEnd;
|
|
148
|
+
pulseRadius.value = pulseRadiusStart;
|
|
149
|
+
}
|
|
150
|
+
}, [animate, pulseTransition, pulseRepeatDelay]);
|
|
151
|
+
const pulseVisibility = useDerivedValue(() => {
|
|
152
|
+
// Never pulse when scrubbing
|
|
153
|
+
if (!unwrapAnimatedValue(isIdle)) return 0;
|
|
154
|
+
return pulseOpacity.value;
|
|
155
|
+
}, [isIdle, pulseOpacity]);
|
|
156
|
+
const beaconOpacity = useDerivedValue(() => {
|
|
157
|
+
const point = targetPoint.value;
|
|
158
|
+
const isWithinDrawingArea = point.x >= drawingArea.x && point.x <= drawingArea.x + drawingArea.width && point.y >= drawingArea.y && point.y <= drawingArea.y + drawingArea.height;
|
|
159
|
+
const userOpacity = unwrapAnimatedValue(opacityProp);
|
|
160
|
+
return isWithinDrawingArea ? userOpacity : 0;
|
|
161
|
+
}, [targetPoint, drawingArea, opacityProp]);
|
|
162
|
+
return /*#__PURE__*/_jsxs(Group, {
|
|
163
|
+
opacity: beaconOpacity,
|
|
164
|
+
children: [/*#__PURE__*/_jsx(Circle, {
|
|
165
|
+
c: animatedPoint,
|
|
166
|
+
color: color,
|
|
167
|
+
opacity: pulseVisibility,
|
|
168
|
+
r: pulseRadius
|
|
169
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
170
|
+
c: animatedPoint,
|
|
171
|
+
color: theme.color.bg,
|
|
172
|
+
r: radius + strokeWidth / 2
|
|
173
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
174
|
+
c: animatedPoint,
|
|
175
|
+
color: color,
|
|
176
|
+
r: radius - strokeWidth / 2
|
|
177
|
+
})]
|
|
178
|
+
});
|
|
179
|
+
}));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const _excluded = ["background", "color", "elevated", "borderRadius", "font", "verticalAlignment", "inset", "label"];
|
|
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';
|
|
6
|
+
import { ChartText } from '../text';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const labelVerticalInset = 3.5;
|
|
9
|
+
const labelHorizontalInset = 4;
|
|
10
|
+
/**
|
|
11
|
+
* DefaultScrubberBeaconLabel is a special instance of ChartText used to label a series' scrubber beacon.
|
|
12
|
+
*/
|
|
13
|
+
export const DefaultScrubberBeaconLabel = /*#__PURE__*/memo(_ref => {
|
|
14
|
+
let {
|
|
15
|
+
background,
|
|
16
|
+
color,
|
|
17
|
+
elevated = true,
|
|
18
|
+
borderRadius = 4,
|
|
19
|
+
font = 'label1',
|
|
20
|
+
verticalAlignment = 'middle',
|
|
21
|
+
inset = {
|
|
22
|
+
left: labelHorizontalInset,
|
|
23
|
+
right: labelHorizontalInset,
|
|
24
|
+
top: labelVerticalInset,
|
|
25
|
+
bottom: labelVerticalInset
|
|
26
|
+
},
|
|
27
|
+
label
|
|
28
|
+
} = _ref,
|
|
29
|
+
chartTextProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
return /*#__PURE__*/_jsx(ChartText, _extends({
|
|
32
|
+
disableRepositioning: true,
|
|
33
|
+
background: background != null ? background : theme.color.bg,
|
|
34
|
+
borderRadius: borderRadius,
|
|
35
|
+
color: color != null ? color : theme.color.fgPrimary,
|
|
36
|
+
elevated: elevated,
|
|
37
|
+
font: font,
|
|
38
|
+
inset: inset,
|
|
39
|
+
verticalAlignment: verticalAlignment
|
|
40
|
+
}, chartTextProps, {
|
|
41
|
+
children: label
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const _excluded = ["verticalAlignment", "dy", "boundsInset"];
|
|
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 { useCartesianChartContext } from '../ChartProvider';
|
|
6
|
+
import { DefaultReferenceLineLabel } from '../line';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
/**
|
|
9
|
+
* DefaultScrubberLabel is the default label component for the scrubber line.
|
|
10
|
+
* It will automatically add padding around the label when elevated to fit within chart bounds to prevent shadow from being cutoff.
|
|
11
|
+
* It will also center the label vertically with the top available area.
|
|
12
|
+
*/
|
|
13
|
+
export const DefaultScrubberLabel = /*#__PURE__*/memo(_ref => {
|
|
14
|
+
let {
|
|
15
|
+
verticalAlignment = 'middle',
|
|
16
|
+
dy,
|
|
17
|
+
boundsInset
|
|
18
|
+
} = _ref,
|
|
19
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
20
|
+
const {
|
|
21
|
+
drawingArea
|
|
22
|
+
} = useCartesianChartContext();
|
|
23
|
+
return /*#__PURE__*/_jsx(DefaultReferenceLineLabel, _extends({
|
|
24
|
+
boundsInset: boundsInset,
|
|
25
|
+
dy: dy != null ? dy : -0.5 * drawingArea.y,
|
|
26
|
+
verticalAlignment: verticalAlignment
|
|
27
|
+
}, props));
|
|
28
|
+
});
|