@coinbase/cds-mobile-visualization 3.4.0-beta.5 → 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 +9 -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 +7 -5
- 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,17 +1,15 @@
|
|
|
1
|
-
const _excluded = ["children"]
|
|
1
|
+
const _excluded = ["children"],
|
|
2
|
+
_excluded2 = ["animate"];
|
|
2
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; }
|
|
3
4
|
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); }
|
|
4
|
-
import { memo,
|
|
5
|
-
import { Rect as SvgRect } from 'react-native-svg';
|
|
5
|
+
import { memo, useEffect, useState } from 'react';
|
|
6
6
|
import { Button } from '@coinbase/cds-mobile/buttons';
|
|
7
7
|
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
8
8
|
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
9
9
|
import { VStack } from '@coinbase/cds-mobile/layout';
|
|
10
10
|
import { XAxis, YAxis } from '../../axis';
|
|
11
11
|
import { CartesianChart } from '../../CartesianChart';
|
|
12
|
-
import { useCartesianChartContext } from '../../ChartProvider';
|
|
13
12
|
import { ReferenceLine, SolidLine } from '../../line';
|
|
14
|
-
import { isCategoricalScale, ScrubberContext } from '../../utils';
|
|
15
13
|
import { Bar } from '../Bar';
|
|
16
14
|
import { BarChart } from '../BarChart';
|
|
17
15
|
import { BarPlot } from '../BarPlot';
|
|
@@ -92,13 +90,37 @@ const FiatAndStablecoinBalance = () => {
|
|
|
92
90
|
}
|
|
93
91
|
});
|
|
94
92
|
};
|
|
95
|
-
const
|
|
93
|
+
const CustomBarStackComponent = /*#__PURE__*/memo(_ref => {
|
|
94
|
+
let {
|
|
95
|
+
children
|
|
96
|
+
} = _ref,
|
|
97
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
96
98
|
const theme = useTheme();
|
|
99
|
+
if (props.height === 0) {
|
|
100
|
+
const diameter = props.width;
|
|
101
|
+
return /*#__PURE__*/_jsx(Bar, {
|
|
102
|
+
roundBottom: true,
|
|
103
|
+
roundTop: true,
|
|
104
|
+
borderRadius: 1000,
|
|
105
|
+
fill: theme.color.bgTertiary,
|
|
106
|
+
height: diameter,
|
|
107
|
+
originY: props.y,
|
|
108
|
+
width: diameter,
|
|
109
|
+
x: props.x,
|
|
110
|
+
y: props.y - diameter
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return /*#__PURE__*/_jsx(DefaultBarStack, _extends({}, props, {
|
|
114
|
+
children: children
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
const MonthlyRewards = () => {
|
|
97
118
|
const months = ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'];
|
|
98
119
|
const purple = [null, 6, 8, 10, 7, 6, 6, 8, null, null, null, null];
|
|
99
120
|
const blue = [null, 10, 12, 11, 10, 9, 10, 11, null, null, null, null];
|
|
100
121
|
const cyan = [null, 7, 10, 12, 11, 10, 8, 11, null, null, null, null];
|
|
101
122
|
const green = [10, null, null, null, 1, null, null, 6, null, null, null, null];
|
|
123
|
+
const [roundBaseline, setRoundBaseline] = useState(true);
|
|
102
124
|
const series = [{
|
|
103
125
|
id: 'purple',
|
|
104
126
|
data: purple,
|
|
@@ -116,46 +138,29 @@ const MonthlyRewards = () => {
|
|
|
116
138
|
data: green,
|
|
117
139
|
color: '#33c481'
|
|
118
140
|
}];
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return /*#__PURE__*/_jsx(BarChart, {
|
|
143
|
-
roundBaseline: true,
|
|
144
|
-
showXAxis: true,
|
|
145
|
-
stacked: true,
|
|
146
|
-
BarStackComponent: CustomBarStackComponent,
|
|
147
|
-
borderRadius: 1000,
|
|
148
|
-
height: 300,
|
|
149
|
-
inset: 0,
|
|
150
|
-
series: series,
|
|
151
|
-
showYAxis: false,
|
|
152
|
-
stackMinSize: 24,
|
|
153
|
-
xAxis: {
|
|
154
|
-
tickLabelFormatter: index => {
|
|
155
|
-
return months[index];
|
|
156
|
-
},
|
|
157
|
-
categoryPadding: 0.27
|
|
158
|
-
}
|
|
141
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
142
|
+
gap: 2,
|
|
143
|
+
children: [/*#__PURE__*/_jsx(BarChart, {
|
|
144
|
+
showXAxis: true,
|
|
145
|
+
stacked: true,
|
|
146
|
+
BarStackComponent: CustomBarStackComponent,
|
|
147
|
+
borderRadius: 1000,
|
|
148
|
+
height: 300,
|
|
149
|
+
inset: 0,
|
|
150
|
+
roundBaseline: roundBaseline,
|
|
151
|
+
series: series,
|
|
152
|
+
showYAxis: false,
|
|
153
|
+
stackMinSize: 24,
|
|
154
|
+
xAxis: {
|
|
155
|
+
tickLabelFormatter: index => {
|
|
156
|
+
return months[index];
|
|
157
|
+
},
|
|
158
|
+
categoryPadding: 0.27
|
|
159
|
+
}
|
|
160
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
161
|
+
onPress: () => setRoundBaseline(!roundBaseline),
|
|
162
|
+
children: "Toggle Round Baseline"
|
|
163
|
+
})]
|
|
159
164
|
});
|
|
160
165
|
};
|
|
161
166
|
const MultipleYAxes = () => {
|
|
@@ -184,33 +189,40 @@ const MultipleYAxes = () => {
|
|
|
184
189
|
}],
|
|
185
190
|
children: [/*#__PURE__*/_jsx(XAxis, {
|
|
186
191
|
showLine: true,
|
|
187
|
-
showTickMarks: true
|
|
192
|
+
showTickMarks: true,
|
|
193
|
+
label: "Month"
|
|
188
194
|
}), /*#__PURE__*/_jsx(YAxis, {
|
|
189
195
|
showGrid: true,
|
|
190
196
|
showLine: true,
|
|
191
197
|
showTickMarks: true,
|
|
192
198
|
axisId: "revenue",
|
|
199
|
+
label: "Revenue",
|
|
193
200
|
position: "left",
|
|
194
201
|
requestedTickCount: 5,
|
|
195
202
|
tickLabelFormatter: value => "$" + value + "k",
|
|
196
|
-
width:
|
|
203
|
+
width: 80
|
|
197
204
|
}), /*#__PURE__*/_jsx(YAxis, {
|
|
198
205
|
showLine: true,
|
|
199
206
|
showTickMarks: true,
|
|
200
207
|
axisId: "profit",
|
|
208
|
+
label: "Profit",
|
|
201
209
|
requestedTickCount: 5,
|
|
202
|
-
tickLabelFormatter: value => "$" + value + "k"
|
|
210
|
+
tickLabelFormatter: value => "$" + value + "k",
|
|
211
|
+
width: 70
|
|
203
212
|
}), /*#__PURE__*/_jsx(BarPlot, {})]
|
|
204
213
|
});
|
|
205
214
|
};
|
|
215
|
+
const initialData = [45, 52, 38, 45, 19, 23, 32];
|
|
216
|
+
const MyCustomLine = /*#__PURE__*/memo(_ref2 => {
|
|
217
|
+
let props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
218
|
+
return /*#__PURE__*/_jsx(SolidLine, _extends({}, props));
|
|
219
|
+
});
|
|
206
220
|
const UpdatingChartValues = () => {
|
|
207
|
-
const [data, setData] = useState(
|
|
221
|
+
const [data, setData] = useState(initialData);
|
|
208
222
|
return /*#__PURE__*/_jsxs(VStack, {
|
|
209
223
|
gap: 2,
|
|
210
224
|
children: [/*#__PURE__*/_jsx(BarChart, {
|
|
211
|
-
|
|
212
|
-
showYAxis: true,
|
|
213
|
-
height: defaultChartHeight,
|
|
225
|
+
height: 100,
|
|
214
226
|
series: [{
|
|
215
227
|
id: 'weekly-data',
|
|
216
228
|
data: data
|
|
@@ -226,14 +238,136 @@ const UpdatingChartValues = () => {
|
|
|
226
238
|
showGrid: true,
|
|
227
239
|
showTickMarks: true,
|
|
228
240
|
showLine: true,
|
|
229
|
-
tickMarkSize: 12
|
|
241
|
+
tickMarkSize: 12,
|
|
242
|
+
domain: {
|
|
243
|
+
max: 250
|
|
244
|
+
}
|
|
230
245
|
}
|
|
246
|
+
}), /*#__PURE__*/_jsx(BarChart, {
|
|
247
|
+
height: 100,
|
|
248
|
+
series: [{
|
|
249
|
+
id: 'weekly-data',
|
|
250
|
+
data: data
|
|
251
|
+
}],
|
|
252
|
+
transition: {
|
|
253
|
+
type: 'timing',
|
|
254
|
+
duration: 300
|
|
255
|
+
},
|
|
256
|
+
xAxis: {
|
|
257
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
258
|
+
showTickMarks: true,
|
|
259
|
+
showLine: true
|
|
260
|
+
},
|
|
261
|
+
yAxis: {
|
|
262
|
+
requestedTickCount: 5,
|
|
263
|
+
tickLabelFormatter: value => "$" + value + "k",
|
|
264
|
+
showGrid: true,
|
|
265
|
+
showTickMarks: true,
|
|
266
|
+
showLine: true,
|
|
267
|
+
tickMarkSize: 12,
|
|
268
|
+
domain: {
|
|
269
|
+
max: 250
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}), /*#__PURE__*/_jsx(BarChart, {
|
|
273
|
+
height: 100,
|
|
274
|
+
series: [{
|
|
275
|
+
id: 'weekly-data',
|
|
276
|
+
data: data.map((d, i) => i % 2 === 0 ? d : -d)
|
|
277
|
+
}],
|
|
278
|
+
xAxis: {
|
|
279
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
280
|
+
showTickMarks: true,
|
|
281
|
+
showLine: true
|
|
282
|
+
},
|
|
283
|
+
yAxis: {
|
|
284
|
+
requestedTickCount: 5,
|
|
285
|
+
tickLabelFormatter: value => "$" + value + "k",
|
|
286
|
+
showGrid: true,
|
|
287
|
+
showTickMarks: true,
|
|
288
|
+
showLine: true,
|
|
289
|
+
tickMarkSize: 12,
|
|
290
|
+
domain: {
|
|
291
|
+
max: 250
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
children: /*#__PURE__*/_jsx(ReferenceLine, {
|
|
295
|
+
LineComponent: MyCustomLine,
|
|
296
|
+
dataY: 0
|
|
297
|
+
})
|
|
231
298
|
}), /*#__PURE__*/_jsx(Button, {
|
|
232
|
-
onPress: () => setData(data => data.map(d => d +
|
|
299
|
+
onPress: () => setData(data => data[0] > 200 ? initialData : data.map(d => d + 50)),
|
|
233
300
|
children: "Update Data"
|
|
234
301
|
})]
|
|
235
302
|
});
|
|
236
303
|
};
|
|
304
|
+
const AnimatedUpdatingChartValues = () => {
|
|
305
|
+
const [data, setData] = useState([45, 52, 38, 45, 19, 23, 32]);
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
const interval = setInterval(() => {
|
|
308
|
+
setData(prevData => prevData.map(value => {
|
|
309
|
+
// Generate random change between -15 and +15
|
|
310
|
+
const change = Math.floor(Math.random() * 31) - 15;
|
|
311
|
+
// Ensure values stay between 10 and 200
|
|
312
|
+
return Math.max(10, Math.min(200, value + change));
|
|
313
|
+
}));
|
|
314
|
+
}, 1000);
|
|
315
|
+
return () => clearInterval(interval);
|
|
316
|
+
}, []);
|
|
317
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
318
|
+
showXAxis: true,
|
|
319
|
+
showYAxis: true,
|
|
320
|
+
height: defaultChartHeight,
|
|
321
|
+
series: [{
|
|
322
|
+
id: 'weekly-data',
|
|
323
|
+
data: data
|
|
324
|
+
}],
|
|
325
|
+
xAxis: {
|
|
326
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
327
|
+
showTickMarks: true,
|
|
328
|
+
showLine: true
|
|
329
|
+
},
|
|
330
|
+
yAxis: {
|
|
331
|
+
requestedTickCount: 5,
|
|
332
|
+
tickLabelFormatter: value => "$" + value + "k",
|
|
333
|
+
showGrid: true,
|
|
334
|
+
showTickMarks: true,
|
|
335
|
+
showLine: true,
|
|
336
|
+
tickMarkSize: 12,
|
|
337
|
+
domain: {
|
|
338
|
+
max: 250
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
const NegativeValuesWithTopAxis = () => {
|
|
344
|
+
const theme = useTheme();
|
|
345
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
346
|
+
height: defaultChartHeight,
|
|
347
|
+
series: [{
|
|
348
|
+
id: 'losses',
|
|
349
|
+
data: [-45, -52, -38, -45, -19, -23, -32],
|
|
350
|
+
color: theme.color.fgNegative
|
|
351
|
+
}],
|
|
352
|
+
xAxis: {
|
|
353
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
354
|
+
scaleType: 'band'
|
|
355
|
+
},
|
|
356
|
+
children: [/*#__PURE__*/_jsx(XAxis, {
|
|
357
|
+
showLine: true,
|
|
358
|
+
showTickMarks: true,
|
|
359
|
+
label: "Day of Week",
|
|
360
|
+
position: "top"
|
|
361
|
+
}), /*#__PURE__*/_jsx(YAxis, {
|
|
362
|
+
showGrid: true,
|
|
363
|
+
showLine: true,
|
|
364
|
+
showTickMarks: true,
|
|
365
|
+
label: "Loss",
|
|
366
|
+
requestedTickCount: 5,
|
|
367
|
+
tickLabelFormatter: value => "$" + value + "k"
|
|
368
|
+
}), /*#__PURE__*/_jsx(BarPlot, {})]
|
|
369
|
+
});
|
|
370
|
+
};
|
|
237
371
|
const tabs = [{
|
|
238
372
|
id: 'week',
|
|
239
373
|
label: '1W'
|
|
@@ -244,38 +378,290 @@ const tabs = [{
|
|
|
244
378
|
id: 'year',
|
|
245
379
|
label: '1Y'
|
|
246
380
|
}];
|
|
247
|
-
const
|
|
248
|
-
var _useContext;
|
|
381
|
+
const YAxisContinuousColorMap = () => {
|
|
249
382
|
const theme = useTheme();
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
383
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
384
|
+
showXAxis: true,
|
|
385
|
+
showYAxis: true,
|
|
386
|
+
height: defaultChartHeight,
|
|
387
|
+
series: [{
|
|
388
|
+
id: 'temperature',
|
|
389
|
+
data: [12, 25, 38, 52, 45, 30, 18],
|
|
390
|
+
// Continuous gradient from blue (cold) to red (hot)
|
|
391
|
+
gradient: {
|
|
392
|
+
axis: 'y',
|
|
393
|
+
stops: _ref3 => {
|
|
394
|
+
let {
|
|
395
|
+
min,
|
|
396
|
+
max
|
|
397
|
+
} = _ref3;
|
|
398
|
+
return [{
|
|
399
|
+
offset: min,
|
|
400
|
+
color: theme.color.accentBoldGreen
|
|
401
|
+
}, {
|
|
402
|
+
offset: (min + max) / 2,
|
|
403
|
+
color: theme.color.accentBoldYellow
|
|
404
|
+
}, {
|
|
405
|
+
offset: max,
|
|
406
|
+
color: theme.color.accentBoldRed
|
|
407
|
+
}];
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}],
|
|
411
|
+
xAxis: {
|
|
412
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
413
|
+
},
|
|
414
|
+
yAxis: {
|
|
415
|
+
requestedTickCount: 5,
|
|
416
|
+
tickLabelFormatter: value => value + "\xB0C",
|
|
417
|
+
showGrid: true
|
|
418
|
+
}
|
|
269
419
|
});
|
|
270
|
-
}
|
|
420
|
+
};
|
|
421
|
+
const YAxisDiscreteColorMap = () => {
|
|
422
|
+
const theme = useTheme();
|
|
423
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
424
|
+
showXAxis: true,
|
|
425
|
+
showYAxis: true,
|
|
426
|
+
height: defaultChartHeight,
|
|
427
|
+
series: [{
|
|
428
|
+
id: 'temperature',
|
|
429
|
+
data: [12, 25, 38, 52, 45, 30, 18],
|
|
430
|
+
// Hard transitions based on performance thresholds
|
|
431
|
+
gradient: {
|
|
432
|
+
axis: 'y',
|
|
433
|
+
stops: [{
|
|
434
|
+
offset: 20,
|
|
435
|
+
color: theme.color.accentBoldGreen
|
|
436
|
+
}, {
|
|
437
|
+
offset: 20,
|
|
438
|
+
color: theme.color.accentBoldYellow
|
|
439
|
+
}, {
|
|
440
|
+
offset: 40,
|
|
441
|
+
color: theme.color.accentBoldYellow
|
|
442
|
+
}, {
|
|
443
|
+
offset: 40,
|
|
444
|
+
color: theme.color.accentBoldRed
|
|
445
|
+
}, {
|
|
446
|
+
offset: 60,
|
|
447
|
+
color: theme.color.accentBoldRed
|
|
448
|
+
}] // Hard transitions at 20, 40
|
|
449
|
+
}
|
|
450
|
+
}],
|
|
451
|
+
xAxis: {
|
|
452
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
453
|
+
},
|
|
454
|
+
yAxis: {
|
|
455
|
+
requestedTickCount: 5,
|
|
456
|
+
tickLabelFormatter: value => value + "\xB0C",
|
|
457
|
+
showGrid: true
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
const XAxisContinuousColorMap = () => {
|
|
462
|
+
const theme = useTheme();
|
|
463
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
464
|
+
showXAxis: true,
|
|
465
|
+
showYAxis: true,
|
|
466
|
+
height: defaultChartHeight,
|
|
467
|
+
series: [{
|
|
468
|
+
id: 'weekly-trend',
|
|
469
|
+
data: [45, 52, 38, 45, 48, 50, 55],
|
|
470
|
+
// Gradient from left (start of week) to right (end of week)
|
|
471
|
+
gradient: {
|
|
472
|
+
axis: 'x',
|
|
473
|
+
stops: _ref4 => {
|
|
474
|
+
let {
|
|
475
|
+
min,
|
|
476
|
+
max
|
|
477
|
+
} = _ref4;
|
|
478
|
+
return [{
|
|
479
|
+
offset: min,
|
|
480
|
+
color: theme.color.accentBoldPurple
|
|
481
|
+
}, {
|
|
482
|
+
offset: max,
|
|
483
|
+
color: theme.color.accentBoldBlue
|
|
484
|
+
}];
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}],
|
|
488
|
+
xAxis: {
|
|
489
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
490
|
+
},
|
|
491
|
+
yAxis: {
|
|
492
|
+
requestedTickCount: 5,
|
|
493
|
+
tickLabelFormatter: value => "" + value,
|
|
494
|
+
showGrid: true
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
const XAxisDiscreteColorMap = () => {
|
|
499
|
+
const theme = useTheme();
|
|
500
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
501
|
+
showXAxis: true,
|
|
502
|
+
showYAxis: true,
|
|
503
|
+
height: defaultChartHeight,
|
|
504
|
+
series: [{
|
|
505
|
+
id: 'weekly-trend',
|
|
506
|
+
data: [45, 52, 38, 45, 48, 50, 55],
|
|
507
|
+
// Hard color transition from purple to blue at midweek
|
|
508
|
+
gradient: {
|
|
509
|
+
axis: 'x',
|
|
510
|
+
stops: [{
|
|
511
|
+
offset: 4,
|
|
512
|
+
color: theme.color.accentBoldPurple
|
|
513
|
+
},
|
|
514
|
+
// First half of week
|
|
515
|
+
{
|
|
516
|
+
offset: 4,
|
|
517
|
+
color: theme.color.accentBoldBlue
|
|
518
|
+
} // Second half of week - hard transition at index 4 (Thursday)
|
|
519
|
+
]
|
|
520
|
+
}
|
|
521
|
+
}],
|
|
522
|
+
xAxis: {
|
|
523
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
524
|
+
},
|
|
525
|
+
yAxis: {
|
|
526
|
+
requestedTickCount: 5,
|
|
527
|
+
tickLabelFormatter: value => "" + value,
|
|
528
|
+
showGrid: true
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
const XAxisMultiSegmentColorMap = () => {
|
|
533
|
+
const theme = useTheme();
|
|
534
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
535
|
+
showXAxis: true,
|
|
536
|
+
showYAxis: true,
|
|
537
|
+
height: defaultChartHeight,
|
|
538
|
+
series: [{
|
|
539
|
+
id: 'quarters',
|
|
540
|
+
data: [120, 135, 142, 128, 145, 158, 162, 155, 168, 175, 182, 190],
|
|
541
|
+
// Different color for each quarter
|
|
542
|
+
gradient: {
|
|
543
|
+
axis: 'x',
|
|
544
|
+
stops: [{
|
|
545
|
+
offset: 3,
|
|
546
|
+
color: theme.color.accentBoldBlue
|
|
547
|
+
},
|
|
548
|
+
// Q1 (Jan-Mar)
|
|
549
|
+
{
|
|
550
|
+
offset: 3,
|
|
551
|
+
color: theme.color.accentBoldGreen
|
|
552
|
+
},
|
|
553
|
+
// Q2 (Apr-Jun)
|
|
554
|
+
{
|
|
555
|
+
offset: 6,
|
|
556
|
+
color: theme.color.accentBoldGreen
|
|
557
|
+
}, {
|
|
558
|
+
offset: 6,
|
|
559
|
+
color: theme.color.accentBoldYellow
|
|
560
|
+
},
|
|
561
|
+
// Q3 (Jul-Sep)
|
|
562
|
+
{
|
|
563
|
+
offset: 9,
|
|
564
|
+
color: theme.color.accentBoldYellow
|
|
565
|
+
}, {
|
|
566
|
+
offset: 9,
|
|
567
|
+
color: theme.color.accentBoldPurple
|
|
568
|
+
} // Q4 (Oct-Dec)
|
|
569
|
+
] // Hard transitions at indices 3, 6, 9
|
|
570
|
+
}
|
|
571
|
+
}],
|
|
572
|
+
xAxis: {
|
|
573
|
+
data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
574
|
+
},
|
|
575
|
+
yAxis: {
|
|
576
|
+
requestedTickCount: 5,
|
|
577
|
+
tickLabelFormatter: value => "$" + value + "k",
|
|
578
|
+
showGrid: true
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
const ColorMapWithOpacity = () => {
|
|
583
|
+
const theme = useTheme();
|
|
584
|
+
return /*#__PURE__*/_jsx(BarChart, {
|
|
585
|
+
showXAxis: true,
|
|
586
|
+
showYAxis: true,
|
|
587
|
+
height: defaultChartHeight,
|
|
588
|
+
series: [{
|
|
589
|
+
id: 'confidence',
|
|
590
|
+
data: [25, 35, 45, 55, 65, 75, 85],
|
|
591
|
+
// Gradient with opacity changes
|
|
592
|
+
gradient: {
|
|
593
|
+
axis: 'y',
|
|
594
|
+
stops: _ref5 => {
|
|
595
|
+
let {
|
|
596
|
+
min,
|
|
597
|
+
max
|
|
598
|
+
} = _ref5;
|
|
599
|
+
return [{
|
|
600
|
+
offset: min,
|
|
601
|
+
color: theme.color.accentBoldBlue,
|
|
602
|
+
opacity: 0
|
|
603
|
+
},
|
|
604
|
+
// Low values - more transparent
|
|
605
|
+
{
|
|
606
|
+
offset: max,
|
|
607
|
+
color: theme.color.accentBoldBlue,
|
|
608
|
+
opacity: 1.0
|
|
609
|
+
} // High values - more opaque
|
|
610
|
+
];
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}],
|
|
614
|
+
xAxis: {
|
|
615
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
616
|
+
},
|
|
617
|
+
yAxis: {
|
|
618
|
+
requestedTickCount: 5,
|
|
619
|
+
tickLabelFormatter: value => value + "%",
|
|
620
|
+
showGrid: true
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
};
|
|
271
624
|
const BarChartStories = () => {
|
|
272
625
|
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
273
626
|
children: [/*#__PURE__*/_jsx(Example, {
|
|
274
627
|
title: "Basic",
|
|
275
628
|
children: /*#__PURE__*/_jsx(UpdatingChartValues, {})
|
|
629
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
630
|
+
title: "Animated Auto-Updating",
|
|
631
|
+
children: /*#__PURE__*/_jsx(AnimatedUpdatingChartValues, {})
|
|
632
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
633
|
+
title: "Negative Values with Top Axis",
|
|
634
|
+
children: /*#__PURE__*/_jsx(NegativeValuesWithTopAxis, {})
|
|
276
635
|
}), /*#__PURE__*/_jsx(Example, {
|
|
277
636
|
title: "Positive and Negative Cash Flow",
|
|
278
637
|
children: /*#__PURE__*/_jsx(PositiveAndNegativeCashFlow, {})
|
|
638
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
639
|
+
title: "Fiat & Stablecoin Balance",
|
|
640
|
+
children: /*#__PURE__*/_jsx(FiatAndStablecoinBalance, {})
|
|
641
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
642
|
+
title: "Monthly Rewards",
|
|
643
|
+
children: /*#__PURE__*/_jsx(MonthlyRewards, {})
|
|
644
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
645
|
+
title: "Multiple Y Axes",
|
|
646
|
+
children: /*#__PURE__*/_jsx(MultipleYAxes, {})
|
|
647
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
648
|
+
title: "Y-Axis Continuous ColorMap",
|
|
649
|
+
children: /*#__PURE__*/_jsx(YAxisContinuousColorMap, {})
|
|
650
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
651
|
+
title: "Y-Axis Discrete ColorMap",
|
|
652
|
+
children: /*#__PURE__*/_jsx(YAxisDiscreteColorMap, {})
|
|
653
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
654
|
+
title: "X-Axis Continuous ColorMap",
|
|
655
|
+
children: /*#__PURE__*/_jsx(XAxisContinuousColorMap, {})
|
|
656
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
657
|
+
title: "X-Axis Discrete ColorMap",
|
|
658
|
+
children: /*#__PURE__*/_jsx(XAxisDiscreteColorMap, {})
|
|
659
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
660
|
+
title: "X-Axis Multi-Segment ColorMap",
|
|
661
|
+
children: /*#__PURE__*/_jsx(XAxisMultiSegmentColorMap, {})
|
|
662
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
663
|
+
title: "ColorMap with Opacity",
|
|
664
|
+
children: /*#__PURE__*/_jsx(ColorMapWithOpacity, {})
|
|
279
665
|
})]
|
|
280
666
|
});
|
|
281
667
|
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { memo, useMemo } from 'react';
|
|
2
|
+
import { LinearGradient, vec } from '@shopify/react-native-skia';
|
|
3
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
4
|
+
import { getColorWithOpacity, getGradientConfig } from '../utils/gradient';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* Renders a Skia LinearGradient element based on a GradientDefinition.
|
|
8
|
+
* The gradient should be used as a child of a Path component.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <Path d={pathString} stroke="red">
|
|
12
|
+
* {gradient && <Gradient gradient={gradient} yAxisId={yAxisId} />}
|
|
13
|
+
* </Path>
|
|
14
|
+
*/
|
|
15
|
+
export const Gradient = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
var _gradient$axis;
|
|
17
|
+
let {
|
|
18
|
+
gradient,
|
|
19
|
+
yAxisId
|
|
20
|
+
} = _ref;
|
|
21
|
+
const context = useCartesianChartContext();
|
|
22
|
+
const xScale = context.getXScale();
|
|
23
|
+
const yScale = context.getYScale(yAxisId);
|
|
24
|
+
const axis = (_gradient$axis = gradient.axis) != null ? _gradient$axis : 'y';
|
|
25
|
+
const scale = axis === 'x' ? xScale : yScale;
|
|
26
|
+
|
|
27
|
+
// Process gradient definition into stops
|
|
28
|
+
const stops = useMemo(() => {
|
|
29
|
+
if (!xScale || !yScale) return;
|
|
30
|
+
return getGradientConfig(gradient, xScale, yScale);
|
|
31
|
+
}, [gradient, xScale, yScale]);
|
|
32
|
+
if (!stops || !scale) return;
|
|
33
|
+
const range = scale.range();
|
|
34
|
+
|
|
35
|
+
// Determine gradient direction based on axis
|
|
36
|
+
// For y-axis, we need to flip the gradient direction because y-scales are inverted
|
|
37
|
+
// (higher data values have smaller pixel values, appearing at the top)
|
|
38
|
+
const start = axis === 'x' ? vec(range[0], 0) : vec(0, range[0]);
|
|
39
|
+
const end = axis === 'x' ? vec(range[1], 0) : vec(0, range[1]);
|
|
40
|
+
|
|
41
|
+
// Extract colors and positions for LinearGradient
|
|
42
|
+
const colors = stops.map(s => {
|
|
43
|
+
var _s$opacity;
|
|
44
|
+
return getColorWithOpacity(s.color, (_s$opacity = s.opacity) != null ? _s$opacity : 1);
|
|
45
|
+
});
|
|
46
|
+
const positions = stops.map(s => s.offset);
|
|
47
|
+
return /*#__PURE__*/_jsx(LinearGradient, {
|
|
48
|
+
colors: colors,
|
|
49
|
+
end: end,
|
|
50
|
+
positions: positions,
|
|
51
|
+
start: start
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Gradient';
|
package/esm/chart/index.js
CHANGED
|
@@ -3,11 +3,13 @@ export * from './area';
|
|
|
3
3
|
export * from './axis';
|
|
4
4
|
export * from './bar';
|
|
5
5
|
export * from './CartesianChart';
|
|
6
|
+
export * from './ChartContextBridge';
|
|
6
7
|
export * from './ChartProvider';
|
|
8
|
+
export * from './gradient';
|
|
7
9
|
export * from './line';
|
|
8
10
|
export * from './Path';
|
|
9
11
|
export * from './PeriodSelector';
|
|
10
|
-
export * from './
|
|
12
|
+
export * from './point';
|
|
11
13
|
export * from './scrubber';
|
|
12
14
|
export * from './text';
|
|
13
15
|
export * from './utils';
|