@coinbase/cds-mobile-visualization 3.4.0-beta.13 → 3.4.0-beta.15
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 +14 -0
- package/dts/chart/CartesianChart.d.ts +35 -1
- package/dts/chart/CartesianChart.d.ts.map +1 -1
- package/dts/chart/bar/Bar.d.ts +4 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -1
- package/dts/chart/bar/BarChart.d.ts +6 -3
- package/dts/chart/bar/BarChart.d.ts.map +1 -1
- package/dts/chart/bar/BarStack.d.ts +11 -2
- package/dts/chart/bar/BarStack.d.ts.map +1 -1
- package/dts/chart/index.d.ts +1 -0
- package/dts/chart/index.d.ts.map +1 -1
- package/dts/chart/legend/DefaultLegendEntry.d.ts +5 -0
- package/dts/chart/legend/DefaultLegendEntry.d.ts.map +1 -0
- package/dts/chart/legend/DefaultLegendShape.d.ts +5 -0
- package/dts/chart/legend/DefaultLegendShape.d.ts.map +1 -0
- package/dts/chart/legend/Legend.d.ts +168 -0
- package/dts/chart/legend/Legend.d.ts.map +1 -0
- package/dts/chart/legend/index.d.ts +4 -0
- package/dts/chart/legend/index.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -1
- package/dts/chart/scrubber/Scrubber.d.ts +8 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
- package/dts/chart/utils/chart.d.ts +18 -0
- package/dts/chart/utils/chart.d.ts.map +1 -1
- package/esm/chart/CartesianChart.js +40 -10
- package/esm/chart/PeriodSelector.js +5 -1
- package/esm/chart/__stories__/CartesianChart.stories.js +3 -3
- package/esm/chart/__stories__/PeriodSelector.stories.js +24 -0
- package/esm/chart/bar/Bar.js +2 -0
- package/esm/chart/bar/BarStack.js +8 -1
- package/esm/chart/index.js +1 -0
- package/esm/chart/legend/DefaultLegendEntry.js +42 -0
- package/esm/chart/legend/DefaultLegendShape.js +64 -0
- package/esm/chart/legend/Legend.js +59 -0
- package/esm/chart/legend/__stories__/Legend.stories.js +574 -0
- package/esm/chart/legend/index.js +3 -0
- package/esm/chart/line/LineChart.js +2 -1
- package/esm/chart/line/__stories__/LineChart.stories.js +37 -4
- package/esm/chart/scrubber/Scrubber.js +2 -1
- package/esm/chart/utils/chart.js +13 -0
- package/package.json +5 -5
|
@@ -70,6 +70,27 @@ const MinWidthPeriodSelectorExample = () => {
|
|
|
70
70
|
width: "fit-content"
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
+
const PaddedPeriodSelectorExample = () => {
|
|
74
|
+
const tabs = [{
|
|
75
|
+
id: '1W',
|
|
76
|
+
label: '1W'
|
|
77
|
+
}, {
|
|
78
|
+
id: '1M',
|
|
79
|
+
label: '1M'
|
|
80
|
+
}, {
|
|
81
|
+
id: 'YTD',
|
|
82
|
+
label: 'YTD'
|
|
83
|
+
}];
|
|
84
|
+
const [activeTab, setActiveTab] = useState(tabs[0]);
|
|
85
|
+
return /*#__PURE__*/_jsx(PeriodSelector, {
|
|
86
|
+
activeTab: activeTab,
|
|
87
|
+
gap: 2,
|
|
88
|
+
onChange: tab => setActiveTab(tab),
|
|
89
|
+
padding: 3,
|
|
90
|
+
tabs: tabs,
|
|
91
|
+
width: "fit-content"
|
|
92
|
+
});
|
|
93
|
+
};
|
|
73
94
|
const LivePeriodSelectorExample = () => {
|
|
74
95
|
const tabs = useMemo(() => [{
|
|
75
96
|
id: '1H',
|
|
@@ -317,6 +338,9 @@ export default function All() {
|
|
|
317
338
|
}), /*#__PURE__*/_jsx(Example, {
|
|
318
339
|
title: "Colored Excluding Live",
|
|
319
340
|
children: /*#__PURE__*/_jsx(ColoredExcludingLivePeriodSelectorExample, {})
|
|
341
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
342
|
+
title: "With Padding",
|
|
343
|
+
children: /*#__PURE__*/_jsx(PaddedPeriodSelectorExample, {})
|
|
320
344
|
})]
|
|
321
345
|
});
|
|
322
346
|
}
|
package/esm/chart/bar/Bar.js
CHANGED
|
@@ -24,6 +24,7 @@ export const Bar = /*#__PURE__*/memo(_ref => {
|
|
|
24
24
|
originY,
|
|
25
25
|
dataX,
|
|
26
26
|
dataY,
|
|
27
|
+
seriesId,
|
|
27
28
|
BarComponent = DefaultBar,
|
|
28
29
|
fill,
|
|
29
30
|
fillOpacity = 1,
|
|
@@ -59,6 +60,7 @@ export const Bar = /*#__PURE__*/memo(_ref => {
|
|
|
59
60
|
originY: effectiveOriginY,
|
|
60
61
|
roundBottom: roundBottom,
|
|
61
62
|
roundTop: roundTop,
|
|
63
|
+
seriesId: seriesId,
|
|
62
64
|
stroke: stroke,
|
|
63
65
|
strokeWidth: strokeWidth,
|
|
64
66
|
transition: transition,
|
|
@@ -8,6 +8,11 @@ import { Bar } from './Bar';
|
|
|
8
8
|
import { DefaultBarStack } from './DefaultBarStack';
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
const EPSILON = 1e-4;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Extended series type that includes bar-specific properties.
|
|
14
|
+
*/
|
|
15
|
+
|
|
11
16
|
/**
|
|
12
17
|
* BarStack component that renders a single stack of bars at a specific category index.
|
|
13
18
|
* Handles the stacking logic for bars within a single category.
|
|
@@ -153,6 +158,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
153
158
|
// Check if the bar should be rounded based on the baseline, with an epsilon to handle floating-point rounding
|
|
154
159
|
roundTop: roundBaseline || Math.abs(barTop - baseline) >= EPSILON,
|
|
155
160
|
roundBottom: roundBaseline || Math.abs(barBottom - baseline) >= EPSILON,
|
|
161
|
+
BarComponent: s.BarComponent,
|
|
156
162
|
shouldApplyGap
|
|
157
163
|
});
|
|
158
164
|
});
|
|
@@ -514,7 +520,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
514
520
|
const xData = xAxis != null && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
515
521
|
const dataX = xData ? xData[categoryIndex] : categoryIndex;
|
|
516
522
|
const barElements = bars.map((bar, index) => /*#__PURE__*/_jsx(Bar, {
|
|
517
|
-
BarComponent: defaultBarComponent,
|
|
523
|
+
BarComponent: bar.BarComponent || defaultBarComponent,
|
|
518
524
|
borderRadius: borderRadius,
|
|
519
525
|
dataX: dataX,
|
|
520
526
|
dataY: bar.dataY,
|
|
@@ -524,6 +530,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
524
530
|
originY: baseline,
|
|
525
531
|
roundBottom: bar.roundBottom,
|
|
526
532
|
roundTop: bar.roundTop,
|
|
533
|
+
seriesId: bar.seriesId,
|
|
527
534
|
stroke: defaultStroke,
|
|
528
535
|
strokeWidth: defaultStrokeWidth,
|
|
529
536
|
transition: transition,
|
package/esm/chart/index.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const _excluded = ["label", "color", "shape", "ShapeComponent", "gap", "style", "styles", "testID"];
|
|
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 { StyleSheet } from 'react-native';
|
|
6
|
+
import { HStack } from '@coinbase/cds-mobile/layout';
|
|
7
|
+
import { Text } from '@coinbase/cds-mobile/typography/Text';
|
|
8
|
+
import { DefaultLegendShape } from './DefaultLegendShape';
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
const styles = StyleSheet.create({
|
|
11
|
+
legendEntry: {
|
|
12
|
+
alignItems: 'center'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
export const DefaultLegendEntry = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
let {
|
|
17
|
+
label,
|
|
18
|
+
color,
|
|
19
|
+
shape,
|
|
20
|
+
ShapeComponent = DefaultLegendShape,
|
|
21
|
+
gap = 1,
|
|
22
|
+
style,
|
|
23
|
+
styles: stylesProp,
|
|
24
|
+
testID
|
|
25
|
+
} = _ref,
|
|
26
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
27
|
+
return /*#__PURE__*/_jsxs(HStack, _extends({
|
|
28
|
+
gap: gap,
|
|
29
|
+
style: [styles.legendEntry, style, stylesProp == null ? void 0 : stylesProp.root],
|
|
30
|
+
testID: testID
|
|
31
|
+
}, props, {
|
|
32
|
+
children: [/*#__PURE__*/_jsx(ShapeComponent, {
|
|
33
|
+
color: color,
|
|
34
|
+
shape: shape,
|
|
35
|
+
style: stylesProp == null ? void 0 : stylesProp.shape
|
|
36
|
+
}), typeof label === 'string' ? /*#__PURE__*/_jsx(Text, {
|
|
37
|
+
font: "label1",
|
|
38
|
+
style: stylesProp == null ? void 0 : stylesProp.label,
|
|
39
|
+
children: label
|
|
40
|
+
}) : label]
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const _excluded = ["color", "shape", "style", "testID"];
|
|
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 { StyleSheet, View } from 'react-native';
|
|
6
|
+
import { useTheme } from '@coinbase/cds-mobile';
|
|
7
|
+
import { Box } from '@coinbase/cds-mobile/layout';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
const styles = StyleSheet.create({
|
|
10
|
+
container: {
|
|
11
|
+
width: 10,
|
|
12
|
+
height: 24,
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
justifyContent: 'center'
|
|
15
|
+
},
|
|
16
|
+
pill: {
|
|
17
|
+
width: 6,
|
|
18
|
+
height: 24,
|
|
19
|
+
borderRadius: 3
|
|
20
|
+
},
|
|
21
|
+
circle: {
|
|
22
|
+
width: 10,
|
|
23
|
+
height: 10,
|
|
24
|
+
borderRadius: 5
|
|
25
|
+
},
|
|
26
|
+
square: {
|
|
27
|
+
width: 10,
|
|
28
|
+
height: 10
|
|
29
|
+
},
|
|
30
|
+
squircle: {
|
|
31
|
+
width: 10,
|
|
32
|
+
height: 10,
|
|
33
|
+
borderRadius: 2
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const stylesByVariant = {
|
|
37
|
+
pill: styles.pill,
|
|
38
|
+
circle: styles.circle,
|
|
39
|
+
square: styles.square,
|
|
40
|
+
squircle: styles.squircle
|
|
41
|
+
};
|
|
42
|
+
const isVariantShape = shape => typeof shape === 'string' && shape in stylesByVariant;
|
|
43
|
+
export const DefaultLegendShape = /*#__PURE__*/memo(_ref => {
|
|
44
|
+
let {
|
|
45
|
+
color,
|
|
46
|
+
shape = 'circle',
|
|
47
|
+
style,
|
|
48
|
+
testID
|
|
49
|
+
} = _ref,
|
|
50
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
51
|
+
const theme = useTheme();
|
|
52
|
+
if (!isVariantShape(shape)) return shape;
|
|
53
|
+
const variantStyle = stylesByVariant[shape];
|
|
54
|
+
return /*#__PURE__*/_jsx(Box, _extends({
|
|
55
|
+
style: [styles.container, style],
|
|
56
|
+
testID: testID
|
|
57
|
+
}, props, {
|
|
58
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
59
|
+
style: [variantStyle, {
|
|
60
|
+
backgroundColor: color != null ? color : theme.color.fgPrimary
|
|
61
|
+
}]
|
|
62
|
+
})
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const _excluded = ["flexDirection", "justifyContent", "alignItems", "flexWrap", "rowGap", "columnGap", "seriesIds", "EntryComponent", "ShapeComponent", "accessibilityLabel", "style", "styles"];
|
|
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 { forwardRef, memo, useMemo } from 'react';
|
|
5
|
+
import { Box } from '@coinbase/cds-mobile/layout';
|
|
6
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
7
|
+
import { DefaultLegendEntry } from './DefaultLegendEntry';
|
|
8
|
+
import { DefaultLegendShape } from './DefaultLegendShape';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
export const Legend = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
11
|
+
let {
|
|
12
|
+
flexDirection = 'row',
|
|
13
|
+
justifyContent = 'center',
|
|
14
|
+
alignItems = flexDirection === 'row' ? 'center' : 'flex-start',
|
|
15
|
+
flexWrap = 'wrap',
|
|
16
|
+
rowGap = 0.75,
|
|
17
|
+
columnGap = 2,
|
|
18
|
+
seriesIds,
|
|
19
|
+
EntryComponent = DefaultLegendEntry,
|
|
20
|
+
ShapeComponent = DefaultLegendShape,
|
|
21
|
+
accessibilityLabel = 'Legend',
|
|
22
|
+
style,
|
|
23
|
+
styles
|
|
24
|
+
} = _ref,
|
|
25
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
26
|
+
const {
|
|
27
|
+
series
|
|
28
|
+
} = useCartesianChartContext();
|
|
29
|
+
const filteredSeries = useMemo(() => {
|
|
30
|
+
if (seriesIds === undefined) return series.filter(s => s.label !== undefined);
|
|
31
|
+
return series.filter(s => seriesIds.includes(s.id) && s.label !== undefined);
|
|
32
|
+
}, [series, seriesIds]);
|
|
33
|
+
if (filteredSeries.length === 0) return;
|
|
34
|
+
return /*#__PURE__*/_jsx(Box, _extends({
|
|
35
|
+
ref: ref,
|
|
36
|
+
accessibilityLabel: accessibilityLabel,
|
|
37
|
+
accessibilityRole: "summary",
|
|
38
|
+
alignItems: alignItems,
|
|
39
|
+
columnGap: columnGap,
|
|
40
|
+
flexDirection: flexDirection,
|
|
41
|
+
flexWrap: flexWrap,
|
|
42
|
+
justifyContent: justifyContent,
|
|
43
|
+
rowGap: rowGap,
|
|
44
|
+
style: [style, styles == null ? void 0 : styles.root]
|
|
45
|
+
}, props, {
|
|
46
|
+
children: filteredSeries.map(s => /*#__PURE__*/_jsx(EntryComponent, {
|
|
47
|
+
ShapeComponent: ShapeComponent,
|
|
48
|
+
color: s.color,
|
|
49
|
+
label: s.label,
|
|
50
|
+
seriesId: s.id,
|
|
51
|
+
shape: s.legendShape,
|
|
52
|
+
styles: {
|
|
53
|
+
root: styles == null ? void 0 : styles.entry,
|
|
54
|
+
shape: styles == null ? void 0 : styles.entryShape,
|
|
55
|
+
label: styles == null ? void 0 : styles.entryLabel
|
|
56
|
+
}
|
|
57
|
+
}, s.id))
|
|
58
|
+
}));
|
|
59
|
+
}));
|