@coinbase/cds-web-visualization 3.4.0-beta.1 → 3.4.0-beta.11
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 +53 -0
- package/dts/chart/CartesianChart.d.ts +38 -2
- package/dts/chart/CartesianChart.d.ts.map +1 -1
- package/dts/chart/Path.d.ts +27 -7
- package/dts/chart/Path.d.ts.map +1 -1
- package/dts/chart/PeriodSelector.d.ts +0 -4
- package/dts/chart/PeriodSelector.d.ts.map +1 -1
- package/dts/chart/area/Area.d.ts +54 -24
- package/dts/chart/area/Area.d.ts.map +1 -1
- package/dts/chart/area/AreaChart.d.ts +33 -6
- package/dts/chart/area/AreaChart.d.ts.map +1 -1
- package/dts/chart/area/DottedArea.d.ts +21 -44
- package/dts/chart/area/DottedArea.d.ts.map +1 -1
- package/dts/chart/area/GradientArea.d.ts +21 -12
- package/dts/chart/area/GradientArea.d.ts.map +1 -1
- package/dts/chart/area/SolidArea.d.ts +16 -1
- package/dts/chart/area/SolidArea.d.ts.map +1 -1
- package/dts/chart/axis/Axis.d.ts +109 -63
- 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 +17 -8
- 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 +40 -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.map +1 -1
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
- package/dts/chart/gradient/Gradient.d.ts +35 -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 +2 -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 +15 -3
- package/dts/chart/line/DottedLine.d.ts.map +1 -1
- package/dts/chart/line/Line.d.ts +87 -28
- package/dts/chart/line/Line.d.ts.map +1 -1
- package/dts/chart/line/LineChart.d.ts +26 -8
- package/dts/chart/line/LineChart.d.ts.map +1 -1
- package/dts/chart/line/ReferenceLine.d.ts +91 -44
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
- package/dts/chart/line/SolidLine.d.ts +14 -3
- 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 +201 -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 +24 -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 +10 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +207 -66
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +70 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +32 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
- 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 +46 -43
- 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/axis.d.ts +25 -1
- package/dts/chart/utils/axis.d.ts.map +1 -1
- package/dts/chart/utils/chart.d.ts +27 -7
- package/dts/chart/utils/chart.d.ts.map +1 -1
- package/dts/chart/utils/context.d.ts +6 -0
- package/dts/chart/utils/context.d.ts.map +1 -1
- package/dts/chart/utils/gradient.d.ts +104 -0
- package/dts/chart/utils/gradient.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +4 -0
- package/dts/chart/utils/index.d.ts.map +1 -1
- package/dts/chart/utils/interpolate.d.ts +112 -0
- package/dts/chart/utils/interpolate.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +24 -1
- package/dts/chart/utils/path.d.ts.map +1 -1
- package/dts/chart/utils/point.d.ts +40 -7
- 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 +39 -0
- package/dts/chart/utils/scrubber.d.ts.map +1 -0
- package/dts/chart/utils/transition.d.ts +65 -0
- package/dts/chart/utils/transition.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -1
- package/esm/chart/CartesianChart.js +140 -85
- package/esm/chart/Path.js +53 -47
- package/esm/chart/PeriodSelector.js +4 -18
- package/esm/chart/area/Area.js +24 -34
- package/esm/chart/area/AreaChart.js +24 -15
- package/esm/chart/area/DottedArea.js +35 -89
- package/esm/chart/area/GradientArea.js +34 -80
- package/esm/chart/area/SolidArea.js +29 -11
- package/esm/chart/axis/Axis.js +4 -39
- package/esm/chart/axis/DefaultAxisTickLabel.js +15 -0
- package/esm/chart/axis/XAxis.js +184 -63
- package/esm/chart/axis/YAxis.js +190 -57
- package/esm/chart/axis/index.js +1 -0
- package/esm/chart/bar/Bar.js +3 -1
- package/esm/chart/bar/BarChart.js +15 -32
- package/esm/chart/bar/BarPlot.js +3 -2
- package/esm/chart/bar/BarStack.js +65 -23
- package/esm/chart/bar/BarStackGroup.js +7 -17
- package/esm/chart/bar/DefaultBar.js +4 -7
- package/esm/chart/bar/DefaultBarStack.js +5 -7
- package/esm/chart/gradient/Gradient.js +104 -0
- package/esm/chart/gradient/index.js +1 -0
- package/esm/chart/index.js +2 -1
- package/esm/chart/line/DefaultReferenceLineLabel.js +81 -0
- package/esm/chart/line/DottedLine.js +38 -17
- package/esm/chart/line/Line.js +96 -70
- package/esm/chart/line/LineChart.js +18 -6
- package/esm/chart/line/ReferenceLine.js +41 -43
- package/esm/chart/line/SolidLine.js +36 -15
- package/esm/chart/line/index.js +1 -1
- package/esm/chart/{line/GradientLine.js → point/DefaultPointLabel.js} +31 -45
- package/esm/chart/point/Point.css +2 -0
- package/esm/chart/{Point.js → point/Point.js} +66 -57
- package/esm/chart/point/index.js +2 -0
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +155 -0
- package/esm/chart/scrubber/{ScrubberBeaconLabel.js → DefaultScrubberBeaconLabel.js} +23 -10
- package/esm/chart/scrubber/DefaultScrubberLabel.js +30 -0
- package/esm/chart/scrubber/Scrubber.js +98 -392
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +166 -0
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +186 -0
- package/esm/chart/scrubber/index.js +3 -1
- package/esm/chart/text/ChartText.js +15 -20
- package/esm/chart/text/{SmartChartTextGroup.js → ChartTextGroup.js} +4 -3
- package/esm/chart/text/index.js +1 -1
- package/esm/chart/utils/axis.js +45 -29
- package/esm/chart/utils/chart.js +29 -3
- package/esm/chart/utils/gradient.js +257 -0
- package/esm/chart/utils/index.js +4 -0
- package/esm/chart/utils/interpolate.js +644 -0
- package/esm/chart/utils/path.js +32 -9
- package/esm/chart/utils/point.js +99 -12
- package/esm/chart/utils/scale.js +13 -2
- package/esm/chart/utils/scrubber.js +132 -0
- package/esm/chart/utils/transition.js +111 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +8 -4
- package/package.json +9 -9
- package/dts/chart/Point.d.ts +0 -153
- package/dts/chart/Point.d.ts.map +0 -1
- package/dts/chart/line/GradientLine.d.ts +0 -42
- package/dts/chart/line/GradientLine.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +0 -93
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +0 -7
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +0 -1
- package/dts/chart/text/SmartChartTextGroup.d.ts.map +0 -1
- package/esm/chart/Point.css +0 -2
- package/esm/chart/scrubber/ScrubberBeacon.js +0 -195
package/esm/chart/bar/Bar.js
CHANGED
|
@@ -30,7 +30,8 @@ export const Bar = /*#__PURE__*/memo(_ref => {
|
|
|
30
30
|
strokeWidth,
|
|
31
31
|
borderRadius = 4,
|
|
32
32
|
roundTop = true,
|
|
33
|
-
roundBottom = true
|
|
33
|
+
roundBottom = true,
|
|
34
|
+
transition
|
|
34
35
|
} = _ref;
|
|
35
36
|
const barPath = useMemo(() => {
|
|
36
37
|
return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom);
|
|
@@ -52,6 +53,7 @@ export const Bar = /*#__PURE__*/memo(_ref => {
|
|
|
52
53
|
roundTop: roundTop,
|
|
53
54
|
stroke: stroke,
|
|
54
55
|
strokeWidth: strokeWidth,
|
|
56
|
+
transition: transition,
|
|
55
57
|
width: width,
|
|
56
58
|
x: x,
|
|
57
59
|
y: y
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["series", "stacked", "showXAxis", "showYAxis", "xAxis", "yAxis", "inset", "children", "barPadding", "BarComponent", "fillOpacity", "stroke", "strokeWidth", "borderRadius", "roundBaseline", "BarStackComponent", "stackGap", "barMinSize", "stackMinSize"],
|
|
1
|
+
const _excluded = ["series", "stacked", "showXAxis", "showYAxis", "xAxis", "yAxis", "inset", "children", "barPadding", "BarComponent", "fillOpacity", "stroke", "strokeWidth", "borderRadius", "roundBaseline", "BarStackComponent", "stackGap", "barMinSize", "stackMinSize", "transition"],
|
|
2
2
|
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
|
|
3
3
|
_excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"];
|
|
4
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -22,7 +22,7 @@ export const BarChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =>
|
|
|
22
22
|
showYAxis,
|
|
23
23
|
xAxis,
|
|
24
24
|
yAxis,
|
|
25
|
-
inset
|
|
25
|
+
inset,
|
|
26
26
|
children,
|
|
27
27
|
barPadding,
|
|
28
28
|
BarComponent,
|
|
@@ -34,44 +34,26 @@ export const BarChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =>
|
|
|
34
34
|
BarStackComponent,
|
|
35
35
|
stackGap,
|
|
36
36
|
barMinSize,
|
|
37
|
-
stackMinSize
|
|
37
|
+
stackMinSize,
|
|
38
|
+
transition
|
|
38
39
|
} = _ref,
|
|
39
40
|
chartProps = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
-
const calculatedInset = useMemo(() => getChartInset(
|
|
41
|
-
|
|
42
|
-
// Convert BarSeries to Series for Chart context
|
|
43
|
-
const chartSeries = useMemo(() => {
|
|
44
|
-
return series === null || series === void 0 ? void 0 : series.map(s => ({
|
|
45
|
-
id: s.id,
|
|
46
|
-
data: s.data,
|
|
47
|
-
label: s.label,
|
|
48
|
-
color: s.color,
|
|
49
|
-
yAxisId: s.yAxisId,
|
|
50
|
-
stackId: s.stackId
|
|
51
|
-
}));
|
|
52
|
-
}, [series]);
|
|
41
|
+
const calculatedInset = useMemo(() => getChartInset(inset, defaultChartInset), [inset]);
|
|
53
42
|
const transformedSeries = useMemo(() => {
|
|
54
|
-
if (!stacked || !chartSeries) return chartSeries;
|
|
55
|
-
return chartSeries.map(s => {
|
|
56
|
-
var _s$stackId;
|
|
57
|
-
return _objectSpread(_objectSpread({}, s), {}, {
|
|
58
|
-
stackId: (_s$stackId = s.stackId) !== null && _s$stackId !== void 0 ? _s$stackId : defaultStackId
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
}, [chartSeries, stacked]);
|
|
62
|
-
const seriesToRender = transformedSeries !== null && transformedSeries !== void 0 ? transformedSeries : chartSeries;
|
|
63
|
-
|
|
64
|
-
// Keep the original series with bar-specific props for BarPlot
|
|
65
|
-
const barSeriesToRender = useMemo(() => {
|
|
66
43
|
if (!stacked || !series) return series;
|
|
67
44
|
return series.map(s => {
|
|
68
|
-
var _s$
|
|
45
|
+
var _s$stackId;
|
|
69
46
|
return _objectSpread(_objectSpread({}, s), {}, {
|
|
70
|
-
stackId: (_s$
|
|
47
|
+
stackId: (_s$stackId = s.stackId) !== null && _s$stackId !== void 0 ? _s$stackId : defaultStackId
|
|
71
48
|
});
|
|
72
49
|
});
|
|
73
50
|
}, [series, stacked]);
|
|
74
51
|
|
|
52
|
+
// Unlike other charts with custom props per series, we do not need to pick out
|
|
53
|
+
// the props from each series that shouldn't be passed to CartesianChart
|
|
54
|
+
const seriesToRender = transformedSeries !== null && transformedSeries !== void 0 ? transformedSeries : series;
|
|
55
|
+
const seriesIds = seriesToRender === null || seriesToRender === void 0 ? void 0 : seriesToRender.map(s => s.id);
|
|
56
|
+
|
|
75
57
|
// Split axis props into config props for Chart and visual props for axis components
|
|
76
58
|
const _ref2 = xAxis || {},
|
|
77
59
|
{
|
|
@@ -137,11 +119,12 @@ export const BarChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =>
|
|
|
137
119
|
borderRadius: borderRadius,
|
|
138
120
|
fillOpacity: fillOpacity,
|
|
139
121
|
roundBaseline: roundBaseline,
|
|
140
|
-
seriesIds:
|
|
122
|
+
seriesIds: seriesIds,
|
|
141
123
|
stackGap: stackGap,
|
|
142
124
|
stackMinSize: stackMinSize,
|
|
143
125
|
stroke: stroke,
|
|
144
|
-
strokeWidth: strokeWidth
|
|
126
|
+
strokeWidth: strokeWidth,
|
|
127
|
+
transition: transition
|
|
145
128
|
}), children]
|
|
146
129
|
}));
|
|
147
130
|
}));
|
package/esm/chart/bar/BarPlot.js
CHANGED
|
@@ -22,7 +22,8 @@ export const BarPlot = /*#__PURE__*/memo(_ref => {
|
|
|
22
22
|
BarStackComponent,
|
|
23
23
|
stackGap,
|
|
24
24
|
barMinSize,
|
|
25
|
-
stackMinSize
|
|
25
|
+
stackMinSize,
|
|
26
|
+
transition
|
|
26
27
|
} = _ref;
|
|
27
28
|
const {
|
|
28
29
|
series: allSeries,
|
|
@@ -73,7 +74,6 @@ export const BarPlot = /*#__PURE__*/memo(_ref => {
|
|
|
73
74
|
})
|
|
74
75
|
}), /*#__PURE__*/_jsx("g", {
|
|
75
76
|
clipPath: "url(#".concat(clipPathId, ")"),
|
|
76
|
-
"data-testid": "whoa",
|
|
77
77
|
children: stackGroups.map((group, stackIndex) => /*#__PURE__*/_jsx(BarStackGroup, {
|
|
78
78
|
BarComponent: defaultBarComponent,
|
|
79
79
|
BarStackComponent: BarStackComponent,
|
|
@@ -89,6 +89,7 @@ export const BarPlot = /*#__PURE__*/memo(_ref => {
|
|
|
89
89
|
stroke: defaultStroke,
|
|
90
90
|
strokeWidth: defaultStrokeWidth,
|
|
91
91
|
totalStacks: stackGroups.length,
|
|
92
|
+
transition: transition,
|
|
92
93
|
yAxisId: group.yAxisId
|
|
93
94
|
}, group.stackId))
|
|
94
95
|
})]
|
|
@@ -5,9 +5,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
5
5
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
6
|
import React, { memo, useMemo } from 'react';
|
|
7
7
|
import { useCartesianChartContext } from '../ChartProvider';
|
|
8
|
+
import { evaluateGradientAtValue, getGradientConfig } from '../utils/gradient';
|
|
8
9
|
import { Bar } from './Bar';
|
|
9
10
|
import { DefaultBarStack } from './DefaultBarStack';
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
const EPSILON = 1e-4;
|
|
11
13
|
/**
|
|
12
14
|
* BarStack component that renders a single stack of bars at a specific category index.
|
|
13
15
|
* Handles the stacking logic for bars within a single category.
|
|
@@ -29,13 +31,16 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
29
31
|
stackGap,
|
|
30
32
|
barMinSize,
|
|
31
33
|
stackMinSize,
|
|
32
|
-
roundBaseline
|
|
34
|
+
roundBaseline,
|
|
35
|
+
transition
|
|
33
36
|
} = _ref;
|
|
34
37
|
const {
|
|
35
38
|
getSeriesData,
|
|
36
|
-
getXAxis
|
|
39
|
+
getXAxis,
|
|
40
|
+
getXScale,
|
|
41
|
+
getSeries
|
|
37
42
|
} = useCartesianChartContext();
|
|
38
|
-
const
|
|
43
|
+
const xScale = getXScale();
|
|
39
44
|
const barMinSizePx = barMinSize;
|
|
40
45
|
const stackMinSizePx = stackMinSize;
|
|
41
46
|
const xAxis = getXAxis();
|
|
@@ -47,6 +52,20 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
47
52
|
const baseline = (_yScale = yScale(baselineValue)) !== null && _yScale !== void 0 ? _yScale : rect.y + rect.height;
|
|
48
53
|
return Math.max(rect.y, Math.min(baseline, rect.y + rect.height));
|
|
49
54
|
}, [rect.height, rect.y, yScale]);
|
|
55
|
+
const seriesGradients = useMemo(() => {
|
|
56
|
+
return series.map(s => {
|
|
57
|
+
if (!s.gradient || !xScale || !yScale) return null;
|
|
58
|
+
const gradientScale = s.gradient.axis === 'x' ? xScale : yScale;
|
|
59
|
+
const stops = getGradientConfig(s.gradient, xScale, yScale);
|
|
60
|
+
if (!stops) return null;
|
|
61
|
+
return {
|
|
62
|
+
seriesId: s.id,
|
|
63
|
+
gradient: s.gradient,
|
|
64
|
+
scale: gradientScale,
|
|
65
|
+
stops
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}, [series, xScale, yScale]);
|
|
50
69
|
|
|
51
70
|
// Calculate bars for this specific category
|
|
52
71
|
const {
|
|
@@ -65,7 +84,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
65
84
|
|
|
66
85
|
// Process each series in the stack
|
|
67
86
|
series.forEach(s => {
|
|
68
|
-
var _yScale2, _yScale3;
|
|
87
|
+
var _yScale2, _yScale3, _s$color;
|
|
69
88
|
const data = getSeriesData(s.id);
|
|
70
89
|
if (!data) return;
|
|
71
90
|
const value = data[categoryIndex];
|
|
@@ -103,6 +122,30 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
103
122
|
// Update stack bounds
|
|
104
123
|
minY = Math.min(minY, y);
|
|
105
124
|
maxY = Math.max(maxY, y + height);
|
|
125
|
+
let barFill = (_s$color = s.color) !== null && _s$color !== void 0 ? _s$color : 'var(--color-fgPrimary)';
|
|
126
|
+
|
|
127
|
+
// Evaluate gradient if provided (using precomputed stops)
|
|
128
|
+
const seriesGradientConfig = seriesGradients.find(g => (g === null || g === void 0 ? void 0 : g.seriesId) === s.id);
|
|
129
|
+
if (seriesGradientConfig && originalValue !== null && originalValue !== undefined) {
|
|
130
|
+
var _seriesGradientConfig;
|
|
131
|
+
const axis = (_seriesGradientConfig = seriesGradientConfig.gradient.axis) !== null && _seriesGradientConfig !== void 0 ? _seriesGradientConfig : 'y';
|
|
132
|
+
// For x-axis gradient, use the categoryIndex
|
|
133
|
+
// For y-axis gradient, use the ORIGINAL data value (not the processed top value)
|
|
134
|
+
// This is important for bar charts where originalValue might be a single number (e.g., -40, 15)
|
|
135
|
+
// or a tuple (e.g., [0, 10] for range bars)
|
|
136
|
+
let evalValue;
|
|
137
|
+
if (axis === 'x') {
|
|
138
|
+
evalValue = categoryIndex;
|
|
139
|
+
} else {
|
|
140
|
+
// Use original value for evaluation - handles both single numbers and tuples
|
|
141
|
+
evalValue = Array.isArray(originalValue) ? originalValue[1] : originalValue;
|
|
142
|
+
}
|
|
143
|
+
const evaluatedColor = evaluateGradientAtValue(seriesGradientConfig.stops, evalValue, seriesGradientConfig.scale);
|
|
144
|
+
if (evaluatedColor) {
|
|
145
|
+
// Only apply gradient color if fill is not explicitly set
|
|
146
|
+
barFill = evaluatedColor;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
106
149
|
allBars.push({
|
|
107
150
|
seriesId: s.id,
|
|
108
151
|
x,
|
|
@@ -111,21 +154,16 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
111
154
|
height,
|
|
112
155
|
dataY: value,
|
|
113
156
|
// Store the actual data value
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
stroke: s.stroke,
|
|
119
|
-
strokeWidth: s.strokeWidth,
|
|
120
|
-
// Pass context data for custom components
|
|
121
|
-
roundTop: roundBaseline || barTop !== baseline,
|
|
122
|
-
roundBottom: roundBaseline || barBottom !== baseline,
|
|
157
|
+
fill: barFill,
|
|
158
|
+
// Check if the bar should be rounded based on the baseline, with an epsilon to handle floating-point rounding
|
|
159
|
+
roundTop: roundBaseline || Math.abs(barTop - baseline) >= EPSILON,
|
|
160
|
+
roundBottom: roundBaseline || Math.abs(barBottom - baseline) >= EPSILON,
|
|
123
161
|
shouldApplyGap
|
|
124
162
|
});
|
|
125
163
|
});
|
|
126
164
|
|
|
127
165
|
// Apply proportional gap distribution to maintain total stack height
|
|
128
|
-
if (
|
|
166
|
+
if (stackGap && allBars.length > 1) {
|
|
129
167
|
// Separate bars by baseline side
|
|
130
168
|
const barsAboveBaseline = allBars.filter(bar => {
|
|
131
169
|
const [bottom, top] = bar.dataY.sort((a, b) => a - b);
|
|
@@ -138,7 +176,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
138
176
|
|
|
139
177
|
// Apply proportional gaps to bars above baseline
|
|
140
178
|
if (barsAboveBaseline.length > 1) {
|
|
141
|
-
const totalGapSpace =
|
|
179
|
+
const totalGapSpace = stackGap * (barsAboveBaseline.length - 1);
|
|
142
180
|
const totalDataHeight = barsAboveBaseline.reduce((sum, bar) => sum + bar.height, 0);
|
|
143
181
|
const heightReduction = totalGapSpace / totalDataHeight;
|
|
144
182
|
|
|
@@ -160,13 +198,13 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
160
198
|
}
|
|
161
199
|
|
|
162
200
|
// Move to next position (include gap for next bar)
|
|
163
|
-
currentY = newY - (index < sortedBars.length - 1 ?
|
|
201
|
+
currentY = newY - (index < sortedBars.length - 1 ? stackGap : 0);
|
|
164
202
|
});
|
|
165
203
|
}
|
|
166
204
|
|
|
167
205
|
// Apply proportional gaps to bars below baseline
|
|
168
206
|
if (barsBelowBaseline.length > 1) {
|
|
169
|
-
const totalGapSpace =
|
|
207
|
+
const totalGapSpace = stackGap * (barsBelowBaseline.length - 1);
|
|
170
208
|
const totalDataHeight = barsBelowBaseline.reduce((sum, bar) => sum + bar.height, 0);
|
|
171
209
|
const heightReduction = totalGapSpace / totalDataHeight;
|
|
172
210
|
|
|
@@ -187,7 +225,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
187
225
|
}
|
|
188
226
|
|
|
189
227
|
// Move to next position (include gap for next bar)
|
|
190
|
-
currentY = currentY + newHeight + (index < sortedBars.length - 1 ?
|
|
228
|
+
currentY = currentY + newHeight + (index < sortedBars.length - 1 ? stackGap : 0);
|
|
191
229
|
});
|
|
192
230
|
}
|
|
193
231
|
|
|
@@ -323,8 +361,8 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
323
361
|
return bars.sort((a, b) => b.y - a.y).map((a, index) => {
|
|
324
362
|
const barBefore = index > 0 ? bars[index - 1] : null;
|
|
325
363
|
const barAfter = index < bars.length - 1 ? bars[index + 1] : null;
|
|
326
|
-
const shouldRoundTop = index === bars.length - 1 || a.shouldApplyGap &&
|
|
327
|
-
const shouldRoundBottom = index === 0 || a.shouldApplyGap &&
|
|
364
|
+
const shouldRoundTop = index === bars.length - 1 || a.shouldApplyGap && stackGap || !a.shouldApplyGap && barAfter && barAfter.y + barAfter.height !== a.y;
|
|
365
|
+
const shouldRoundBottom = index === 0 || a.shouldApplyGap && stackGap || !a.shouldApplyGap && barBefore && barBefore.y !== a.y + a.height;
|
|
328
366
|
return _objectSpread(_objectSpread({}, a), {}, {
|
|
329
367
|
roundTop: Boolean(a.roundTop && shouldRoundTop),
|
|
330
368
|
roundBottom: Boolean(a.roundBottom && shouldRoundBottom)
|
|
@@ -479,7 +517,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
479
517
|
bars: allBars,
|
|
480
518
|
stackRect: stackBounds
|
|
481
519
|
};
|
|
482
|
-
}, [series,
|
|
520
|
+
}, [series, stackGap, barMinSizePx, x, baseline, width, stackMinSizePx, getSeriesData, categoryIndex, yScale, seriesGradients, roundBaseline]);
|
|
483
521
|
const xData = xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
484
522
|
const dataX = xData ? xData[categoryIndex] : categoryIndex;
|
|
485
523
|
const barElements = bars.map((bar, index) => {
|
|
@@ -497,19 +535,23 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
|
497
535
|
roundTop: bar.roundTop,
|
|
498
536
|
stroke: (_bar$stroke = bar.stroke) !== null && _bar$stroke !== void 0 ? _bar$stroke : defaultStroke,
|
|
499
537
|
strokeWidth: (_bar$strokeWidth = bar.strokeWidth) !== null && _bar$strokeWidth !== void 0 ? _bar$strokeWidth : defaultStrokeWidth,
|
|
538
|
+
transition: transition,
|
|
500
539
|
width: bar.width,
|
|
501
540
|
x: bar.x,
|
|
502
541
|
y: bar.y
|
|
503
542
|
}, "".concat(bar.seriesId, "-").concat(categoryIndex, "-").concat(index));
|
|
504
543
|
});
|
|
505
|
-
|
|
506
|
-
|
|
544
|
+
|
|
545
|
+
// Check if the bar should be rounded based on the baseline, with an epsilon to handle floating-point rounding
|
|
546
|
+
const stackRoundBottom = roundBaseline || Math.abs(stackRect.y + stackRect.height - baseline) >= EPSILON;
|
|
547
|
+
const stackRoundTop = roundBaseline || Math.abs(stackRect.y - baseline) >= EPSILON;
|
|
507
548
|
return /*#__PURE__*/_jsx(BarStackComponent, {
|
|
508
549
|
borderRadius: borderRadius,
|
|
509
550
|
categoryIndex: categoryIndex,
|
|
510
551
|
height: stackRect.height,
|
|
511
552
|
roundBottom: stackRoundBottom,
|
|
512
553
|
roundTop: stackRoundTop,
|
|
554
|
+
transition: transition,
|
|
513
555
|
width: stackRect.width,
|
|
514
556
|
x: stackRect.x,
|
|
515
557
|
y: stackRect.y,
|
|
@@ -25,26 +25,15 @@ export const BarStackGroup = /*#__PURE__*/memo(_ref => {
|
|
|
25
25
|
} = _ref,
|
|
26
26
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
27
27
|
const {
|
|
28
|
-
getSeriesData,
|
|
29
28
|
getXScale,
|
|
30
29
|
getYScale,
|
|
31
|
-
drawingArea
|
|
30
|
+
drawingArea,
|
|
31
|
+
dataLength
|
|
32
32
|
} = useCartesianChartContext();
|
|
33
33
|
const xScale = getXScale();
|
|
34
34
|
const yScale = getYScale(yAxisId);
|
|
35
|
-
const maxDataLength = useMemo(() => {
|
|
36
|
-
if (!series || series.length === 0) return 0;
|
|
37
|
-
let maxLength = 0;
|
|
38
|
-
series.forEach(s => {
|
|
39
|
-
const data = getSeriesData(s.id);
|
|
40
|
-
if (data && data.length > maxLength) {
|
|
41
|
-
maxLength = data.length;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return maxLength;
|
|
45
|
-
}, [series, getSeriesData]);
|
|
46
35
|
const stackConfigs = useMemo(() => {
|
|
47
|
-
if (!xScale || !yScale || !drawingArea ||
|
|
36
|
+
if (!xScale || !yScale || !drawingArea || dataLength === 0) return [];
|
|
48
37
|
if (!isCategoricalScale(xScale)) {
|
|
49
38
|
return [];
|
|
50
39
|
}
|
|
@@ -57,7 +46,8 @@ export const BarStackGroup = /*#__PURE__*/memo(_ref => {
|
|
|
57
46
|
const configs = [];
|
|
58
47
|
|
|
59
48
|
// Calculate position for each category
|
|
60
|
-
|
|
49
|
+
// todo: look at using xDomain for this instead of dataLength
|
|
50
|
+
for (let categoryIndex = 0; categoryIndex < dataLength; categoryIndex++) {
|
|
61
51
|
// Get x position for this category
|
|
62
52
|
const categoryX = xScale(categoryIndex);
|
|
63
53
|
if (categoryX !== undefined) {
|
|
@@ -71,11 +61,11 @@ export const BarStackGroup = /*#__PURE__*/memo(_ref => {
|
|
|
71
61
|
}
|
|
72
62
|
}
|
|
73
63
|
return configs;
|
|
74
|
-
}, [xScale, yScale, drawingArea,
|
|
64
|
+
}, [xScale, yScale, drawingArea, dataLength, stackIndex, totalStacks, barPadding]);
|
|
75
65
|
if (xScale && !isCategoricalScale(xScale)) {
|
|
76
66
|
throw new Error('BarStackGroup requires a band scale for x-axis. See https://cds.coinbase.com/components/graphs/XAxis/#scale-type');
|
|
77
67
|
}
|
|
78
|
-
if (!yScale || !drawingArea || stackConfigs.length === 0) return;
|
|
68
|
+
if (!yScale || !drawingArea || stackConfigs.length === 0) return null;
|
|
79
69
|
return stackConfigs.map(_ref2 => {
|
|
80
70
|
let {
|
|
81
71
|
categoryIndex,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["x", "width", "borderRadius", "roundTop", "roundBottom", "originY", "d", "fill", "fillOpacity", "dataX", "dataY"];
|
|
1
|
+
const _excluded = ["x", "width", "borderRadius", "roundTop", "roundBottom", "originY", "d", "fill", "fillOpacity", "dataX", "dataY", "transition"];
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -26,7 +26,8 @@ export const DefaultBar = /*#__PURE__*/memo(_ref => {
|
|
|
26
26
|
fill = 'var(--color-fgPrimary)',
|
|
27
27
|
fillOpacity = 1,
|
|
28
28
|
dataX,
|
|
29
|
-
dataY
|
|
29
|
+
dataY,
|
|
30
|
+
transition
|
|
30
31
|
} = _ref,
|
|
31
32
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
32
33
|
const {
|
|
@@ -49,11 +50,7 @@ export const DefaultBar = /*#__PURE__*/memo(_ref => {
|
|
|
49
50
|
initial: {
|
|
50
51
|
d: initialPath
|
|
51
52
|
},
|
|
52
|
-
transition:
|
|
53
|
-
type: 'spring',
|
|
54
|
-
duration: 1,
|
|
55
|
-
bounce: 0
|
|
56
|
-
}
|
|
53
|
+
transition: transition
|
|
57
54
|
}));
|
|
58
55
|
}
|
|
59
56
|
return /*#__PURE__*/_jsx("path", _objectSpread(_objectSpread({}, props), {}, {
|
|
@@ -18,7 +18,8 @@ export const DefaultBarStack = /*#__PURE__*/memo(_ref => {
|
|
|
18
18
|
borderRadius = 4,
|
|
19
19
|
roundTop = true,
|
|
20
20
|
roundBottom = true,
|
|
21
|
-
yOrigin
|
|
21
|
+
yOrigin,
|
|
22
|
+
transition
|
|
22
23
|
} = _ref;
|
|
23
24
|
const {
|
|
24
25
|
animate
|
|
@@ -28,8 +29,9 @@ export const DefaultBarStack = /*#__PURE__*/memo(_ref => {
|
|
|
28
29
|
return getBarPath(x, y, width, height, borderRadius, roundTop, roundBottom);
|
|
29
30
|
}, [x, y, width, height, borderRadius, roundTop, roundBottom]);
|
|
30
31
|
const initialClipPathData = useMemo(() => {
|
|
32
|
+
if (!animate) return undefined;
|
|
31
33
|
return getBarPath(x, yOrigin !== null && yOrigin !== void 0 ? yOrigin : y + height, width, 1, borderRadius, roundTop, roundBottom);
|
|
32
|
-
}, [x, yOrigin, y, height, width, borderRadius, roundTop, roundBottom]);
|
|
34
|
+
}, [animate, x, yOrigin, y, height, width, borderRadius, roundTop, roundBottom]);
|
|
33
35
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
34
36
|
children: [/*#__PURE__*/_jsx("defs", {
|
|
35
37
|
children: /*#__PURE__*/_jsx("clipPath", {
|
|
@@ -41,11 +43,7 @@ export const DefaultBarStack = /*#__PURE__*/memo(_ref => {
|
|
|
41
43
|
initial: {
|
|
42
44
|
d: initialClipPathData
|
|
43
45
|
},
|
|
44
|
-
transition:
|
|
45
|
-
type: 'spring',
|
|
46
|
-
duration: 1,
|
|
47
|
-
bounce: 0
|
|
48
|
-
}
|
|
46
|
+
transition: transition
|
|
49
47
|
}) : /*#__PURE__*/_jsx("path", {
|
|
50
48
|
d: clipPathData
|
|
51
49
|
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
import { memo, useMemo } from 'react';
|
|
7
|
+
import { m as motion } from 'framer-motion';
|
|
8
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
9
|
+
import { getGradientConfig } from '../utils/gradient';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
/**
|
|
12
|
+
* Renders an SVG linearGradient element based on a GradientDefinition.
|
|
13
|
+
* The gradient can be referenced via `fill="url(#${id})"` or `stroke="url(#${id})"`.
|
|
14
|
+
*/
|
|
15
|
+
export const Gradient = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
var _gradient$axis;
|
|
17
|
+
let {
|
|
18
|
+
id,
|
|
19
|
+
gradient,
|
|
20
|
+
yAxisId,
|
|
21
|
+
animate: animateProp,
|
|
22
|
+
transition
|
|
23
|
+
} = _ref;
|
|
24
|
+
const context = useCartesianChartContext();
|
|
25
|
+
const animate = animateProp !== null && animateProp !== void 0 ? animateProp : context.animate;
|
|
26
|
+
const xScale = context.getXScale();
|
|
27
|
+
const yScale = context.getYScale(yAxisId);
|
|
28
|
+
|
|
29
|
+
// Process gradient definition into stops
|
|
30
|
+
const stops = useMemo(() => {
|
|
31
|
+
if (!xScale || !yScale) return;
|
|
32
|
+
return getGradientConfig(gradient, xScale, yScale);
|
|
33
|
+
}, [gradient, xScale, yScale]);
|
|
34
|
+
const drawingArea = context.drawingArea;
|
|
35
|
+
const yAxis = context.getYAxis(yAxisId);
|
|
36
|
+
const xAxis = context.getXAxis();
|
|
37
|
+
|
|
38
|
+
// If gradient processing failed, don't render
|
|
39
|
+
if (!stops) return null;
|
|
40
|
+
const axis = (_gradient$axis = gradient.axis) !== null && _gradient$axis !== void 0 ? _gradient$axis : 'y';
|
|
41
|
+
let coordinates;
|
|
42
|
+
if (axis === 'y') {
|
|
43
|
+
const yRange = yAxis === null || yAxis === void 0 ? void 0 : yAxis.range;
|
|
44
|
+
if (yRange) {
|
|
45
|
+
coordinates = {
|
|
46
|
+
x1: drawingArea.x,
|
|
47
|
+
y1: yRange.max,
|
|
48
|
+
x2: drawingArea.x,
|
|
49
|
+
y2: yRange.min
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
coordinates = {
|
|
53
|
+
x1: drawingArea.x,
|
|
54
|
+
y1: drawingArea.y + drawingArea.height,
|
|
55
|
+
x2: drawingArea.x,
|
|
56
|
+
y2: drawingArea.y
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
const xRange = xAxis === null || xAxis === void 0 ? void 0 : xAxis.range;
|
|
61
|
+
if (xRange) {
|
|
62
|
+
coordinates = {
|
|
63
|
+
x1: xRange.min,
|
|
64
|
+
y1: drawingArea.y,
|
|
65
|
+
x2: xRange.max,
|
|
66
|
+
y2: drawingArea.y
|
|
67
|
+
};
|
|
68
|
+
} else {
|
|
69
|
+
coordinates = {
|
|
70
|
+
x1: drawingArea.x,
|
|
71
|
+
y1: drawingArea.y,
|
|
72
|
+
x2: drawingArea.x + drawingArea.width,
|
|
73
|
+
y2: drawingArea.y
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return /*#__PURE__*/_jsx("linearGradient", _objectSpread(_objectSpread({
|
|
78
|
+
gradientUnits: "userSpaceOnUse",
|
|
79
|
+
id: id
|
|
80
|
+
}, coordinates), {}, {
|
|
81
|
+
children: stops.map((stop, index) => {
|
|
82
|
+
const offset = "".concat(stop.offset * 100, "%");
|
|
83
|
+
const opacity = stop.opacity;
|
|
84
|
+
if (!animate) {
|
|
85
|
+
return /*#__PURE__*/_jsx("stop", {
|
|
86
|
+
offset: offset,
|
|
87
|
+
stopColor: stop.color,
|
|
88
|
+
stopOpacity: opacity !== null && opacity !== void 0 ? opacity : 1
|
|
89
|
+
}, "".concat(id, "-stop-").concat(index));
|
|
90
|
+
}
|
|
91
|
+
return /*#__PURE__*/_jsx(motion.stop, {
|
|
92
|
+
animate: {
|
|
93
|
+
offset
|
|
94
|
+
},
|
|
95
|
+
initial: {
|
|
96
|
+
offset
|
|
97
|
+
},
|
|
98
|
+
stopColor: stop.color,
|
|
99
|
+
stopOpacity: opacity !== null && opacity !== void 0 ? opacity : 1,
|
|
100
|
+
transition: transition
|
|
101
|
+
}, "".concat(id, "-stop-").concat(index));
|
|
102
|
+
})
|
|
103
|
+
}));
|
|
104
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Gradient } from './Gradient';
|
package/esm/chart/index.js
CHANGED
|
@@ -4,10 +4,11 @@ export * from './axis/index';
|
|
|
4
4
|
export * from './bar/index';
|
|
5
5
|
export * from './CartesianChart';
|
|
6
6
|
export * from './ChartProvider';
|
|
7
|
+
export * from './gradient/index';
|
|
7
8
|
export * from './line/index';
|
|
8
9
|
export * from './Path';
|
|
9
10
|
export * from './PeriodSelector';
|
|
10
|
-
export * from './
|
|
11
|
+
export * from './point/index';
|
|
11
12
|
export * from './scrubber/index';
|
|
12
13
|
export * from './text/index';
|
|
13
14
|
export * from './utils/index';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const _excluded = ["color", "elevated", "borderRadius", "inset", "boundsInset", "className", "classNames", "style", "styles"];
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
|
+
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; }
|
|
9
|
+
import { memo, useMemo } from 'react';
|
|
10
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
11
|
+
import { ChartText } from '../text';
|
|
12
|
+
import { getChartInset } from '../utils';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
const elevatedInset = {
|
|
15
|
+
top: 8,
|
|
16
|
+
bottom: 8,
|
|
17
|
+
left: 12,
|
|
18
|
+
right: 12
|
|
19
|
+
};
|
|
20
|
+
const elevatedBorderRadius = 4;
|
|
21
|
+
// Default bounds inset when elevated to prevent shadow clipping
|
|
22
|
+
const elevatedBoundsInset = {
|
|
23
|
+
top: 4,
|
|
24
|
+
bottom: 20,
|
|
25
|
+
left: 12,
|
|
26
|
+
right: 12
|
|
27
|
+
};
|
|
28
|
+
const nonElevatedBoundsInset = {
|
|
29
|
+
top: 0,
|
|
30
|
+
bottom: 0,
|
|
31
|
+
left: 0,
|
|
32
|
+
right: 0
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* DefaultReferenceLineLabel is the default label component for ReferenceLine.
|
|
37
|
+
* Provides standard styling with elevation, inset, and color defaults.
|
|
38
|
+
* When elevated, automatically adds bounds to prevent shadow cutoff at chart edges.
|
|
39
|
+
*/
|
|
40
|
+
export const DefaultReferenceLineLabel = /*#__PURE__*/memo(_ref => {
|
|
41
|
+
let {
|
|
42
|
+
color = 'var(--color-fgMuted)',
|
|
43
|
+
elevated,
|
|
44
|
+
borderRadius = elevated ? elevatedBorderRadius : undefined,
|
|
45
|
+
inset = elevated ? elevatedInset : undefined,
|
|
46
|
+
boundsInset: boundsInsetProp,
|
|
47
|
+
className,
|
|
48
|
+
classNames,
|
|
49
|
+
style,
|
|
50
|
+
styles
|
|
51
|
+
} = _ref,
|
|
52
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
53
|
+
const {
|
|
54
|
+
width: chartWidth,
|
|
55
|
+
height: chartHeight
|
|
56
|
+
} = useCartesianChartContext();
|
|
57
|
+
const bounds = useMemo(() => {
|
|
58
|
+
const boundsInset = getChartInset(boundsInsetProp, elevated ? elevatedBoundsInset : nonElevatedBoundsInset);
|
|
59
|
+
return {
|
|
60
|
+
x: boundsInset.left,
|
|
61
|
+
y: boundsInset.top,
|
|
62
|
+
width: chartWidth - boundsInset.left - boundsInset.right,
|
|
63
|
+
height: chartHeight - boundsInset.top - boundsInset.bottom
|
|
64
|
+
};
|
|
65
|
+
}, [elevated, boundsInsetProp, chartWidth, chartHeight]);
|
|
66
|
+
const mergedClassNames = useMemo(() => _objectSpread(_objectSpread({}, className && {
|
|
67
|
+
text: className
|
|
68
|
+
}), classNames), [className, classNames]);
|
|
69
|
+
const mergedStyles = useMemo(() => _objectSpread(_objectSpread({}, style && {
|
|
70
|
+
text: style
|
|
71
|
+
}), styles), [style, styles]);
|
|
72
|
+
return /*#__PURE__*/_jsx(ChartText, _objectSpread({
|
|
73
|
+
borderRadius: borderRadius,
|
|
74
|
+
bounds: bounds,
|
|
75
|
+
classNames: mergedClassNames,
|
|
76
|
+
color: color,
|
|
77
|
+
elevated: elevated,
|
|
78
|
+
inset: inset,
|
|
79
|
+
styles: mergedStyles
|
|
80
|
+
}, props));
|
|
81
|
+
});
|