@coinbase/cds-mobile-visualization 3.4.0-beta.9 → 3.6.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 +150 -0
- package/dts/chart/CartesianChart.d.ts +92 -7
- package/dts/chart/CartesianChart.d.ts.map +1 -1
- package/dts/chart/ChartContextBridge.d.ts.map +1 -1
- package/dts/chart/ChartProvider.d.ts +3 -0
- package/dts/chart/ChartProvider.d.ts.map +1 -1
- package/dts/chart/Path.d.ts +43 -13
- package/dts/chart/Path.d.ts.map +1 -1
- package/dts/chart/PeriodSelector.d.ts +20 -5
- package/dts/chart/PeriodSelector.d.ts.map +1 -1
- package/dts/chart/area/Area.d.ts +14 -11
- package/dts/chart/area/Area.d.ts.map +1 -1
- package/dts/chart/area/AreaChart.d.ts +33 -9
- package/dts/chart/area/AreaChart.d.ts.map +1 -1
- package/dts/chart/area/DottedArea.d.ts.map +1 -1
- package/dts/chart/area/GradientArea.d.ts.map +1 -1
- package/dts/chart/area/SolidArea.d.ts.map +1 -1
- package/dts/chart/axis/Axis.d.ts +22 -42
- package/dts/chart/axis/Axis.d.ts.map +1 -1
- package/dts/chart/axis/XAxis.d.ts +6 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -1
- package/dts/chart/axis/YAxis.d.ts +1 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -1
- package/dts/chart/bar/Bar.d.ts +59 -51
- package/dts/chart/bar/Bar.d.ts.map +1 -1
- package/dts/chart/bar/BarChart.d.ts +56 -11
- 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 +45 -20
- package/dts/chart/bar/BarStack.d.ts.map +1 -1
- package/dts/chart/bar/BarStackGroup.d.ts +2 -1
- package/dts/chart/bar/BarStackGroup.d.ts.map +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/bar/PercentageBarChart.d.ts +106 -0
- package/dts/chart/bar/PercentageBarChart.d.ts.map +1 -0
- package/dts/chart/bar/index.d.ts +1 -0
- package/dts/chart/bar/index.d.ts.map +1 -1
- package/dts/chart/gradient/Gradient.d.ts +5 -0
- package/dts/chart/gradient/Gradient.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/DottedLine.d.ts.map +1 -1
- package/dts/chart/line/Line.d.ts +23 -19
- package/dts/chart/line/Line.d.ts.map +1 -1
- package/dts/chart/line/LineChart.d.ts +26 -9
- package/dts/chart/line/LineChart.d.ts.map +1 -1
- package/dts/chart/line/ReferenceLine.d.ts +1 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
- package/dts/chart/line/SolidLine.d.ts.map +1 -1
- package/dts/chart/point/Point.d.ts +26 -2
- package/dts/chart/point/Point.d.ts.map +1 -1
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +32 -2
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -1
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +2 -1
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -1
- package/dts/chart/scrubber/Scrubber.d.ts +86 -17
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
- package/dts/chart/scrubber/ScrubberAccessibilityView.d.ts +12 -0
- package/dts/chart/scrubber/ScrubberAccessibilityView.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +10 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -1
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +16 -1
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -1
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
- package/dts/chart/utils/axis.d.ts +45 -10
- package/dts/chart/utils/axis.d.ts.map +1 -1
- package/dts/chart/utils/bar.d.ts +195 -0
- package/dts/chart/utils/bar.d.ts.map +1 -1
- package/dts/chart/utils/chart.d.ts +32 -0
- package/dts/chart/utils/chart.d.ts.map +1 -1
- package/dts/chart/utils/context.d.ts +21 -6
- package/dts/chart/utils/context.d.ts.map +1 -1
- package/dts/chart/utils/gradient.d.ts +3 -1
- package/dts/chart/utils/gradient.d.ts.map +1 -1
- package/dts/chart/utils/path.d.ts +26 -0
- package/dts/chart/utils/path.d.ts.map +1 -1
- package/dts/chart/utils/point.d.ts +24 -12
- package/dts/chart/utils/point.d.ts.map +1 -1
- package/dts/chart/utils/scale.d.ts +11 -0
- package/dts/chart/utils/scale.d.ts.map +1 -1
- package/dts/chart/utils/scrubber.d.ts +2 -1
- package/dts/chart/utils/scrubber.d.ts.map +1 -1
- package/dts/chart/utils/transition.d.ts +63 -22
- package/dts/chart/utils/transition.d.ts.map +1 -1
- package/dts/sparkline/Sparkline.d.ts +2 -1
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +2 -1
- package/dts/sparkline/SparklineArea.d.ts.map +1 -1
- package/dts/sparkline/SparklineGradient.d.ts +2 -1
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +2 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
- package/esm/chart/CartesianChart.js +176 -82
- package/esm/chart/ChartContextBridge.js +14 -3
- package/esm/chart/ChartProvider.js +2 -2
- package/esm/chart/Path.js +68 -31
- package/esm/chart/PeriodSelector.js +5 -1
- package/esm/chart/__stories__/CartesianChart.stories.js +16 -80
- package/esm/chart/__stories__/ChartAccessibility.stories.js +721 -0
- package/esm/chart/__stories__/ChartTransitions.stories.js +625 -0
- package/esm/chart/__stories__/PeriodSelector.stories.js +99 -1
- package/esm/chart/area/Area.js +21 -9
- package/esm/chart/area/AreaChart.js +18 -13
- package/esm/chart/area/DottedArea.js +28 -18
- package/esm/chart/area/GradientArea.js +14 -7
- package/esm/chart/area/SolidArea.js +6 -2
- package/esm/chart/area/__stories__/AreaChart.stories.js +47 -5
- package/esm/chart/axis/Axis.js +5 -41
- package/esm/chart/axis/XAxis.js +116 -47
- package/esm/chart/axis/YAxis.js +105 -26
- package/esm/chart/axis/__stories__/Axis.stories.js +324 -48
- package/esm/chart/bar/Bar.js +17 -15
- package/esm/chart/bar/BarChart.js +38 -33
- package/esm/chart/bar/BarPlot.js +40 -45
- package/esm/chart/bar/BarStack.js +92 -475
- package/esm/chart/bar/BarStackGroup.js +37 -27
- package/esm/chart/bar/DefaultBar.js +41 -18
- package/esm/chart/bar/DefaultBarStack.js +25 -9
- package/esm/chart/bar/PercentageBarChart.js +99 -0
- package/esm/chart/bar/__stories__/BarChart.stories.js +721 -54
- package/esm/chart/bar/__stories__/PercentageBarChart.stories.js +833 -0
- package/esm/chart/bar/index.js +1 -0
- package/esm/chart/gradient/Gradient.js +2 -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/DottedLine.js +6 -2
- package/esm/chart/line/Line.js +42 -38
- package/esm/chart/line/LineChart.js +36 -12
- package/esm/chart/line/SolidLine.js +6 -2
- package/esm/chart/line/__stories__/LineChart.stories.js +236 -590
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +95 -1
- package/esm/chart/point/Point.js +35 -36
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +41 -38
- package/esm/chart/scrubber/DefaultScrubberLabel.js +26 -10
- package/esm/chart/scrubber/Scrubber.js +67 -35
- package/esm/chart/scrubber/ScrubberAccessibilityView.js +177 -0
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +30 -22
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +35 -8
- package/esm/chart/scrubber/ScrubberProvider.js +29 -24
- package/esm/chart/scrubber/__stories__/Scrubber.stories.js +946 -0
- package/esm/chart/utils/axis.js +88 -44
- package/esm/chart/utils/bar.js +829 -0
- package/esm/chart/utils/chart.js +34 -7
- package/esm/chart/utils/context.js +7 -0
- package/esm/chart/utils/gradient.js +8 -4
- package/esm/chart/utils/path.js +91 -61
- package/esm/chart/utils/point.js +92 -39
- package/esm/chart/utils/scale.js +13 -2
- package/esm/chart/utils/scrubber.js +12 -5
- package/esm/chart/utils/transition.js +116 -60
- package/esm/sparkline/Sparkline.js +2 -1
- package/esm/sparkline/SparklineArea.js +2 -1
- package/esm/sparkline/SparklineGradient.js +2 -1
- package/esm/sparkline/__figma__/Sparkline.figma.js +1 -1
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +2 -1
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +1 -1
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +1 -1
- package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +2 -0
- package/package.json +5 -6
- package/esm/chart/__stories__/Chart.stories.js +0 -77
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["series", "yAxisId", "stackIndex", "totalStacks", "barPadding"];
|
|
1
|
+
const _excluded = ["series", "xAxisId", "yAxisId", "stackIndex", "totalStacks", "barPadding"];
|
|
2
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
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
4
|
import { memo, useMemo, createElement as _createElement } from 'react';
|
|
@@ -12,6 +12,7 @@ import { BarStack } from './BarStack';
|
|
|
12
12
|
export const BarStackGroup = /*#__PURE__*/memo(_ref => {
|
|
13
13
|
let {
|
|
14
14
|
series,
|
|
15
|
+
xAxisId = defaultAxisId,
|
|
15
16
|
yAxisId = defaultAxisId,
|
|
16
17
|
stackIndex,
|
|
17
18
|
totalStacks,
|
|
@@ -19,61 +20,70 @@ export const BarStackGroup = /*#__PURE__*/memo(_ref => {
|
|
|
19
20
|
} = _ref,
|
|
20
21
|
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
21
22
|
const {
|
|
23
|
+
layout,
|
|
22
24
|
getXScale,
|
|
23
25
|
getYScale,
|
|
24
26
|
drawingArea,
|
|
25
27
|
dataLength
|
|
26
28
|
} = useCartesianChartContext();
|
|
27
|
-
const xScale = getXScale();
|
|
29
|
+
const xScale = getXScale(xAxisId);
|
|
28
30
|
const yScale = getYScale(yAxisId);
|
|
29
31
|
const stackConfigs = useMemo(() => {
|
|
30
32
|
if (!xScale || !yScale || !drawingArea || dataLength === 0) return [];
|
|
31
|
-
|
|
33
|
+
const indexScale = layout !== 'horizontal' ? xScale : yScale;
|
|
34
|
+
if (!isCategoricalScale(indexScale)) {
|
|
32
35
|
return [];
|
|
33
36
|
}
|
|
34
|
-
const categoryWidth =
|
|
37
|
+
const categoryWidth = indexScale.bandwidth();
|
|
35
38
|
|
|
36
|
-
// Calculate
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const barWidth = categoryWidth / totalStacks - getBarSizeAdjustment(totalStacks, gapWidth);
|
|
39
|
+
// Calculate thickness for each stack within a category.
|
|
40
|
+
const gapSize = totalStacks > 1 ? categoryWidth * barPadding / (totalStacks - 1) : 0;
|
|
41
|
+
const stackThickness = categoryWidth / totalStacks - getBarSizeAdjustment(totalStacks, gapSize);
|
|
40
42
|
const configs = [];
|
|
41
43
|
|
|
42
|
-
// Calculate position for each category
|
|
43
|
-
// todo: look at using xDomain for this instead of dataLength
|
|
44
|
+
// Calculate position for each category.
|
|
44
45
|
for (let categoryIndex = 0; categoryIndex < dataLength; categoryIndex++) {
|
|
45
|
-
// Get
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
// Calculate
|
|
49
|
-
const
|
|
46
|
+
// Get position for this category along the index axis.
|
|
47
|
+
const categoryPos = indexScale(categoryIndex);
|
|
48
|
+
if (categoryPos !== undefined) {
|
|
49
|
+
// Calculate position for this specific stack within the category.
|
|
50
|
+
const stackPos = categoryPos + stackIndex * (stackThickness + gapSize);
|
|
50
51
|
configs.push({
|
|
51
52
|
categoryIndex,
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
indexPos: stackPos,
|
|
54
|
+
thickness: stackThickness
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
return configs;
|
|
58
|
-
}, [xScale, yScale, drawingArea, dataLength,
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
}, [xScale, yScale, drawingArea, dataLength, layout, totalStacks, barPadding, stackIndex]);
|
|
60
|
+
const indexScaleComputed = layout !== 'horizontal' ? xScale : yScale;
|
|
61
|
+
const valueScaleComputed = layout !== 'horizontal' ? yScale : xScale;
|
|
62
|
+
if (indexScaleComputed && !isCategoricalScale(indexScaleComputed)) {
|
|
63
|
+
throw new Error("BarStackGroup requires a band scale for " + (layout !== 'horizontal' ? 'x-axis' : 'y-axis') + ". See https://cds.coinbase.com/components/charts/" + (layout !== 'horizontal' ? 'XAxis' : 'YAxis') + "/#scale-type");
|
|
61
64
|
}
|
|
62
|
-
if (!
|
|
63
|
-
|
|
65
|
+
if (!indexScaleComputed || !valueScaleComputed || !drawingArea || stackConfigs.length === 0) return;
|
|
66
|
+
|
|
67
|
+
// In horizontal layout, render stacks in reverse order so top rows (lower categoryIndex)
|
|
68
|
+
// appear on top. Otherwise bottom rows would overlap and obscure top rows during animation.
|
|
69
|
+
const orderedConfigs = layout === 'horizontal' ? [...stackConfigs].reverse() : stackConfigs;
|
|
70
|
+
return orderedConfigs.map(_ref2 => {
|
|
64
71
|
let {
|
|
65
72
|
categoryIndex,
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
indexPos,
|
|
74
|
+
thickness
|
|
68
75
|
} = _ref2;
|
|
69
76
|
return /*#__PURE__*/_createElement(BarStack, _extends({}, props, {
|
|
70
77
|
key: "stack-" + stackIndex + "-category-" + categoryIndex,
|
|
71
78
|
categoryIndex: categoryIndex,
|
|
79
|
+
indexPos: indexPos,
|
|
80
|
+
indexScale: indexScaleComputed,
|
|
72
81
|
rect: drawingArea,
|
|
73
82
|
series: series,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
thickness: thickness,
|
|
84
|
+
valueScale: valueScaleComputed,
|
|
85
|
+
xAxisId: xAxisId,
|
|
86
|
+
yAxisId: yAxisId
|
|
77
87
|
}));
|
|
78
88
|
});
|
|
79
89
|
});
|
|
@@ -1,8 +1,11 @@
|
|
|
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); }
|
|
1
2
|
import { memo, useMemo } from 'react';
|
|
2
3
|
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
3
4
|
import { useCartesianChartContext } from '../ChartProvider';
|
|
4
5
|
import { Path } from '../Path';
|
|
5
|
-
import { getBarPath } from '../utils';
|
|
6
|
+
import { defaultBarEnterOpacityTransition, defaultBarEnterTransition, getBarPath, withStaggerDelayTransition } from '../utils';
|
|
7
|
+
import { getNormalizedStagger } from '../utils/bar';
|
|
8
|
+
import { defaultTransition, getTransition } from '../utils/transition';
|
|
6
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
10
|
/**
|
|
8
11
|
* Default bar component that renders a solid bar with animation support.
|
|
@@ -13,7 +16,7 @@ export const DefaultBar = /*#__PURE__*/memo(_ref => {
|
|
|
13
16
|
y,
|
|
14
17
|
width,
|
|
15
18
|
height,
|
|
16
|
-
borderRadius,
|
|
19
|
+
borderRadius = 4,
|
|
17
20
|
roundTop,
|
|
18
21
|
roundBottom,
|
|
19
22
|
d,
|
|
@@ -21,36 +24,56 @@ export const DefaultBar = /*#__PURE__*/memo(_ref => {
|
|
|
21
24
|
fillOpacity = 1,
|
|
22
25
|
stroke,
|
|
23
26
|
strokeWidth,
|
|
24
|
-
|
|
27
|
+
origin,
|
|
28
|
+
minSize = 1,
|
|
29
|
+
transitions,
|
|
25
30
|
transition
|
|
26
31
|
} = _ref;
|
|
27
32
|
const {
|
|
28
|
-
animate
|
|
33
|
+
animate,
|
|
34
|
+
drawingArea,
|
|
35
|
+
layout
|
|
29
36
|
} = useCartesianChartContext();
|
|
30
37
|
const theme = useTheme();
|
|
31
38
|
const defaultFill = fill || theme.color.fgPrimary;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
const normalizedStagger = useMemo(() => getNormalizedStagger(layout, x, y, drawingArea), [layout, x, y, drawingArea]);
|
|
40
|
+
const enterTransition = useMemo(() => getTransition(transitions == null ? void 0 : transitions.enter, animate, defaultBarEnterTransition), [transitions == null ? void 0 : transitions.enter, animate]);
|
|
41
|
+
const enterTransitionWithStagger = useMemo(() => withStaggerDelayTransition(enterTransition, normalizedStagger), [enterTransition, normalizedStagger]);
|
|
42
|
+
const enterOpacityTransition = useMemo(() => {
|
|
43
|
+
var _enterOpacityTransiti, _enterOpacityTransiti2;
|
|
44
|
+
if ((transitions == null ? void 0 : transitions.enterOpacity) === undefined && enterTransition === null) return null;
|
|
45
|
+
const enterOpacityTransition = getTransition(transitions == null ? void 0 : transitions.enterOpacity, animate, defaultBarEnterOpacityTransition);
|
|
46
|
+
if (!enterOpacityTransition) return null;
|
|
47
|
+
return _extends({}, enterOpacityTransition, {
|
|
48
|
+
delay: (_enterOpacityTransiti = enterOpacityTransition.delay) != null ? _enterOpacityTransiti : enterTransition == null ? void 0 : enterTransition.delay,
|
|
49
|
+
staggerDelay: (_enterOpacityTransiti2 = enterOpacityTransition.staggerDelay) != null ? _enterOpacityTransiti2 : enterTransition == null ? void 0 : enterTransition.staggerDelay
|
|
50
|
+
});
|
|
51
|
+
}, [transitions == null ? void 0 : transitions.enterOpacity, animate, enterTransition]);
|
|
52
|
+
const enterOpacityTransitionWithStagger = useMemo(() => withStaggerDelayTransition(enterOpacityTransition, normalizedStagger), [enterOpacityTransition, normalizedStagger]);
|
|
53
|
+
const updateTransition = useMemo(() => withStaggerDelayTransition(getTransition((transitions == null ? void 0 : transitions.update) !== undefined ? transitions.update : transition, animate, defaultTransition), normalizedStagger), [transitions == null ? void 0 : transitions.update, transition, animate, normalizedStagger]);
|
|
38
54
|
const initialPath = useMemo(() => {
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
if (!animate) return;
|
|
56
|
+
const isHorizontalLayout = layout === 'horizontal';
|
|
57
|
+
const baseline = origin != null ? origin : isHorizontalLayout ? x : y + height;
|
|
58
|
+
const initialX = isHorizontalLayout ? baseline : x;
|
|
59
|
+
const initialY = isHorizontalLayout ? y : baseline;
|
|
60
|
+
const initialWidth = isHorizontalLayout ? minSize : width;
|
|
61
|
+
const initialHeight = isHorizontalLayout ? height : minSize;
|
|
62
|
+
return getBarPath(initialX, initialY, initialWidth, initialHeight, borderRadius, !!roundTop, !!roundBottom, layout);
|
|
63
|
+
}, [animate, layout, x, y, origin, width, height, borderRadius, roundTop, roundBottom, minSize]);
|
|
45
64
|
return /*#__PURE__*/_jsx(Path, {
|
|
46
65
|
animate: animate,
|
|
47
66
|
clipPath: null,
|
|
48
|
-
d:
|
|
67
|
+
d: d,
|
|
49
68
|
fill: stroke ? 'none' : defaultFill,
|
|
50
69
|
fillOpacity: fillOpacity,
|
|
51
70
|
initialPath: initialPath,
|
|
52
71
|
stroke: stroke,
|
|
53
72
|
strokeWidth: strokeWidth,
|
|
54
|
-
|
|
73
|
+
transitions: {
|
|
74
|
+
enter: enterTransitionWithStagger,
|
|
75
|
+
enterOpacity: enterOpacityTransitionWithStagger,
|
|
76
|
+
update: updateTransition
|
|
77
|
+
}
|
|
55
78
|
});
|
|
56
79
|
});
|
|
@@ -2,7 +2,8 @@ import { memo, useMemo } from 'react';
|
|
|
2
2
|
import { Group } from '@shopify/react-native-skia';
|
|
3
3
|
import { useCartesianChartContext } from '../ChartProvider';
|
|
4
4
|
import { getBarPath } from '../utils';
|
|
5
|
-
import {
|
|
5
|
+
import { defaultBarEnterTransition, getNormalizedStagger, getStackInitialClipRect, withStaggerDelayTransition } from '../utils/bar';
|
|
6
|
+
import { defaultTransition, getTransition, usePathTransition } from '../utils/transition';
|
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
8
|
/**
|
|
8
9
|
* Default stack component that renders children in a group with animated clip path.
|
|
@@ -17,27 +18,42 @@ export const DefaultBarStack = /*#__PURE__*/memo(_ref => {
|
|
|
17
18
|
borderRadius = 4,
|
|
18
19
|
roundTop = true,
|
|
19
20
|
roundBottom = true,
|
|
20
|
-
|
|
21
|
+
origin,
|
|
22
|
+
transitions,
|
|
21
23
|
transition
|
|
22
24
|
} = _ref;
|
|
23
25
|
const {
|
|
24
|
-
animate
|
|
26
|
+
animate,
|
|
27
|
+
drawingArea,
|
|
28
|
+
layout
|
|
25
29
|
} = useCartesianChartContext();
|
|
30
|
+
const normalizedStagger = useMemo(() => getNormalizedStagger(layout, x, y, drawingArea), [layout, x, y, drawingArea]);
|
|
31
|
+
const enterTransition = useMemo(() => withStaggerDelayTransition(getTransition(transitions == null ? void 0 : transitions.enter, animate, defaultBarEnterTransition), normalizedStagger), [animate, transitions == null ? void 0 : transitions.enter, normalizedStagger]);
|
|
32
|
+
const updateTransition = useMemo(() => withStaggerDelayTransition(getTransition((transitions == null ? void 0 : transitions.update) !== undefined ? transitions.update : transition, animate, defaultTransition), normalizedStagger), [animate, transitions == null ? void 0 : transitions.update, transition, normalizedStagger]);
|
|
26
33
|
|
|
27
34
|
// Generate target clip path (full bar)
|
|
28
35
|
const targetPath = useMemo(() => {
|
|
29
|
-
return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom);
|
|
30
|
-
}, [x, y, width, height, borderRadius, roundTop, roundBottom]);
|
|
36
|
+
return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom, layout);
|
|
37
|
+
}, [x, y, width, height, borderRadius, roundTop, roundBottom, layout]);
|
|
31
38
|
|
|
32
39
|
// Initial clip path for entry animation (bar at baseline with minimal height)
|
|
33
40
|
const initialPath = useMemo(() => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
if (!animate) return;
|
|
42
|
+
const initialClipRect = getStackInitialClipRect({
|
|
43
|
+
x,
|
|
44
|
+
y,
|
|
45
|
+
width,
|
|
46
|
+
height
|
|
47
|
+
}, layout, origin);
|
|
48
|
+
return getBarPath(initialClipRect.x, initialClipRect.y, initialClipRect.width, initialClipRect.height, borderRadius, roundTop, roundBottom, layout);
|
|
49
|
+
}, [animate, layout, x, y, height, width, borderRadius, roundTop, roundBottom, origin]);
|
|
37
50
|
const animatedClipPath = usePathTransition({
|
|
38
51
|
currentPath: targetPath,
|
|
39
52
|
initialPath,
|
|
40
|
-
|
|
53
|
+
transitions: {
|
|
54
|
+
enter: enterTransition,
|
|
55
|
+
update: updateTransition
|
|
56
|
+
}
|
|
41
57
|
});
|
|
42
58
|
const clipPath = animate ? animatedClipPath : targetPath;
|
|
43
59
|
return /*#__PURE__*/_jsx(Group, {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const _excluded = ["series", "layout", "roundBaseline", "inset", "transitions", "xAxis", "yAxis", "testID", "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 { forwardRef, memo, useMemo } from 'react';
|
|
5
|
+
import { BarChart } from './BarChart';
|
|
6
|
+
|
|
7
|
+
/** Extended series type that supports single data values. */
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
/**
|
|
10
|
+
* Returns the value for a group index from numeric shorthand or per-group series data.
|
|
11
|
+
* @param data - A single number (group `0` only) or an array of values per group.
|
|
12
|
+
* @param groupIndex - The group index to read.
|
|
13
|
+
* @returns The clamped value for that group, or `null` when the value is `null`, undefined, or out of range.
|
|
14
|
+
*/
|
|
15
|
+
const unwrapSeriesDataValue = (data, groupIndex) => {
|
|
16
|
+
const raw = typeof data === 'number' ? groupIndex === 0 ? data : null : data[groupIndex];
|
|
17
|
+
return raw != null ? Math.max(0, raw) : null;
|
|
18
|
+
};
|
|
19
|
+
export const PercentageBarChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
20
|
+
let {
|
|
21
|
+
series,
|
|
22
|
+
layout = 'horizontal',
|
|
23
|
+
roundBaseline = true,
|
|
24
|
+
inset = 0,
|
|
25
|
+
transitions,
|
|
26
|
+
xAxis,
|
|
27
|
+
yAxis,
|
|
28
|
+
testID,
|
|
29
|
+
children
|
|
30
|
+
} = _ref,
|
|
31
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
32
|
+
const barSeries = useMemo(() => {
|
|
33
|
+
var _series$map;
|
|
34
|
+
const groupCount = Math.max(0, ...((_series$map = series == null ? void 0 : series.map(_ref2 => {
|
|
35
|
+
let {
|
|
36
|
+
data
|
|
37
|
+
} = _ref2;
|
|
38
|
+
return typeof data === 'number' ? 1 : data.length;
|
|
39
|
+
})) != null ? _series$map : []));
|
|
40
|
+
const totals = Array.from({
|
|
41
|
+
length: groupCount
|
|
42
|
+
}, (_, i) => {
|
|
43
|
+
var _series$reduce;
|
|
44
|
+
return (_series$reduce = series == null ? void 0 : series.reduce((sum, _ref3) => {
|
|
45
|
+
var _unwrapSeriesDataValu;
|
|
46
|
+
let {
|
|
47
|
+
data
|
|
48
|
+
} = _ref3;
|
|
49
|
+
return sum + ((_unwrapSeriesDataValu = unwrapSeriesDataValue(data, i)) != null ? _unwrapSeriesDataValu : 0);
|
|
50
|
+
}, 0)) != null ? _series$reduce : 0;
|
|
51
|
+
});
|
|
52
|
+
return series == null ? void 0 : series.map(s => _extends({}, s, {
|
|
53
|
+
data: Array.from({
|
|
54
|
+
length: groupCount
|
|
55
|
+
}, (_, i) => {
|
|
56
|
+
const val = unwrapSeriesDataValue(s.data, i);
|
|
57
|
+
return val != null && totals[i] > 0 ? val / totals[i] * 100 : null;
|
|
58
|
+
})
|
|
59
|
+
}));
|
|
60
|
+
}, [series]);
|
|
61
|
+
const isHorizontalLayout = layout === 'horizontal';
|
|
62
|
+
const xAxisConfig = useMemo(() => {
|
|
63
|
+
return isHorizontalLayout ? _extends({
|
|
64
|
+
domain: {
|
|
65
|
+
min: 0,
|
|
66
|
+
max: 100
|
|
67
|
+
},
|
|
68
|
+
domainLimit: 'strict'
|
|
69
|
+
}, xAxis) : _extends({
|
|
70
|
+
categoryPadding: 0
|
|
71
|
+
}, xAxis);
|
|
72
|
+
}, [isHorizontalLayout, xAxis]);
|
|
73
|
+
const yAxisConfig = useMemo(() => {
|
|
74
|
+
return isHorizontalLayout ? _extends({
|
|
75
|
+
categoryPadding: 0
|
|
76
|
+
}, yAxis) : _extends({
|
|
77
|
+
domain: {
|
|
78
|
+
min: 0,
|
|
79
|
+
max: 100
|
|
80
|
+
},
|
|
81
|
+
domainLimit: 'strict'
|
|
82
|
+
}, yAxis);
|
|
83
|
+
}, [isHorizontalLayout, yAxis]);
|
|
84
|
+
return /*#__PURE__*/_jsx(BarChart, _extends({
|
|
85
|
+
ref: ref,
|
|
86
|
+
stacked: true,
|
|
87
|
+
inset: inset,
|
|
88
|
+
layout: layout,
|
|
89
|
+
roundBaseline: roundBaseline,
|
|
90
|
+
series: barSeries,
|
|
91
|
+
testID: testID,
|
|
92
|
+
transitions: transitions,
|
|
93
|
+
xAxis: xAxisConfig,
|
|
94
|
+
yAxis: yAxisConfig
|
|
95
|
+
}, props, {
|
|
96
|
+
children: children
|
|
97
|
+
}));
|
|
98
|
+
}));
|
|
99
|
+
PercentageBarChart.displayName = 'PercentageBarChart';
|