@coinbase/cds-web-visualization 3.4.0-beta.1 → 3.4.0-beta.10
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 +47 -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 +92 -45
- 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 +1 -1
- 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 +70 -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/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 +29 -0
- package/dts/chart/utils/point.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 -25
- package/esm/chart/axis/DefaultAxisTickLabel.js +15 -0
- package/esm/chart/axis/XAxis.js +76 -52
- package/esm/chart/axis/YAxis.js +80 -49
- 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 +13 -19
- package/esm/chart/text/{SmartChartTextGroup.js → ChartTextGroup.js} +4 -3
- package/esm/chart/text/index.js +1 -1
- 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 +69 -0
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["d", "fill", "fillOpacity", "
|
|
1
|
+
const _excluded = ["d", "fill", "fillOpacity", "peakOpacity", "baselineOpacity", "baseline", "yAxisId", "gradient", "animate", "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; }
|
|
@@ -6,106 +6,60 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
6
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
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
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, useId } from 'react';
|
|
9
|
+
import { memo, useId, useMemo } from 'react';
|
|
10
10
|
import { useCartesianChartContext } from '../ChartProvider';
|
|
11
|
+
import { Gradient } from '../gradient';
|
|
11
12
|
import { Path } from '../Path';
|
|
13
|
+
import { createGradient, getBaseline } from '../utils';
|
|
12
14
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
15
|
/**
|
|
14
|
-
* A customizable gradient area component which uses Path.
|
|
16
|
+
* A customizable gradient area component which uses Path with SVG linearGradient.
|
|
17
|
+
*
|
|
18
|
+
* When no gradient is provided, automatically creates an appropriate gradient:
|
|
19
|
+
* - For data crossing zero: Creates a diverging gradient with peak opacity at both extremes
|
|
20
|
+
* and baseline opacity at zero (or the specified baseline).
|
|
21
|
+
* - For all-positive or all-negative data: Creates a simple gradient from baseline to peak.
|
|
15
22
|
*/
|
|
16
23
|
export const GradientArea = /*#__PURE__*/memo(_ref => {
|
|
17
24
|
let {
|
|
18
25
|
d,
|
|
19
26
|
fill = 'var(--color-fgPrimary)',
|
|
20
27
|
fillOpacity = 1,
|
|
21
|
-
peakColor,
|
|
22
|
-
baselineColor,
|
|
23
28
|
peakOpacity = 0.3,
|
|
24
29
|
baselineOpacity = 0,
|
|
25
30
|
baseline,
|
|
26
|
-
yAxisId
|
|
31
|
+
yAxisId,
|
|
32
|
+
gradient: gradientProp,
|
|
33
|
+
animate,
|
|
34
|
+
transition
|
|
27
35
|
} = _ref,
|
|
28
36
|
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
-
const
|
|
37
|
+
const {
|
|
38
|
+
getYAxis
|
|
39
|
+
} = useCartesianChartContext();
|
|
30
40
|
const patternId = useId();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const useUserSpaceUnits = yRange !== undefined;
|
|
39
|
-
const gradientY1 = useUserSpaceUnits ? yRange[1] : '0%';
|
|
40
|
-
const gradientY2 = useUserSpaceUnits ? yRange[0] : '100%';
|
|
41
|
-
|
|
42
|
-
// Auto-calculate baseline position based on domain
|
|
43
|
-
let baselinePosition;
|
|
44
|
-
let baselinePercentage;
|
|
45
|
-
if (yScale && yDomain) {
|
|
46
|
-
const [minValue, maxValue] = yDomain;
|
|
47
|
-
let dataBaseline;
|
|
48
|
-
if (minValue >= 0) {
|
|
49
|
-
// All positive: baseline at min
|
|
50
|
-
dataBaseline = minValue;
|
|
51
|
-
} else if (maxValue <= 0) {
|
|
52
|
-
// All negative: baseline at max
|
|
53
|
-
dataBaseline = maxValue;
|
|
54
|
-
} else {
|
|
55
|
-
// Crosses zero: baseline at 0
|
|
56
|
-
dataBaseline = 0;
|
|
57
|
-
}
|
|
58
|
-
if (useUserSpaceUnits) {
|
|
59
|
-
// Get the actual y coordinate for the baseline
|
|
60
|
-
const scaledValue = yScale(baseline !== null && baseline !== void 0 ? baseline : dataBaseline);
|
|
61
|
-
if (typeof scaledValue === 'number') {
|
|
62
|
-
baselinePosition = scaledValue;
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
// Calculate percentage position
|
|
66
|
-
baselinePercentage = "".concat((maxValue - (baseline !== null && baseline !== void 0 ? baseline : dataBaseline)) / (maxValue - minValue) * 100, "%");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const effectivePeakColor = peakColor !== null && peakColor !== void 0 ? peakColor : fill;
|
|
70
|
-
const effectiveBaselineColor = baselineColor !== null && baselineColor !== void 0 ? baselineColor : fill;
|
|
41
|
+
const yAxisConfig = getYAxis(yAxisId);
|
|
42
|
+
const gradient = useMemo(() => {
|
|
43
|
+
if (gradientProp) return gradientProp;
|
|
44
|
+
if (!yAxisConfig) return;
|
|
45
|
+
const baselineValue = getBaseline(yAxisConfig.domain, baseline);
|
|
46
|
+
return createGradient(yAxisConfig.domain, baselineValue, fill, peakOpacity, baselineOpacity);
|
|
47
|
+
}, [gradientProp, yAxisConfig, fill, baseline, peakOpacity, baselineOpacity]);
|
|
71
48
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
72
|
-
children: [/*#__PURE__*/_jsx("defs", {
|
|
73
|
-
children: /*#__PURE__*/_jsx(
|
|
74
|
-
|
|
49
|
+
children: [gradient && /*#__PURE__*/_jsx("defs", {
|
|
50
|
+
children: /*#__PURE__*/_jsx(Gradient, {
|
|
51
|
+
animate: animate,
|
|
52
|
+
gradient: gradient,
|
|
75
53
|
id: patternId,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
y1: gradientY1,
|
|
79
|
-
y2: gradientY2,
|
|
80
|
-
children: baselinePosition !== undefined || baselinePercentage !== undefined ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
81
|
-
children: [/*#__PURE__*/_jsx("stop", {
|
|
82
|
-
offset: "0%",
|
|
83
|
-
stopColor: effectivePeakColor,
|
|
84
|
-
stopOpacity: peakOpacity
|
|
85
|
-
}), /*#__PURE__*/_jsx("stop", {
|
|
86
|
-
offset: baselinePercentage !== null && baselinePercentage !== void 0 ? baselinePercentage : "".concat((baselinePosition - yRange[1]) / (yRange[0] - yRange[1]) * 100, "%"),
|
|
87
|
-
stopColor: effectiveBaselineColor,
|
|
88
|
-
stopOpacity: baselineOpacity
|
|
89
|
-
}), /*#__PURE__*/_jsx("stop", {
|
|
90
|
-
offset: "100%",
|
|
91
|
-
stopColor: effectivePeakColor,
|
|
92
|
-
stopOpacity: peakOpacity
|
|
93
|
-
})]
|
|
94
|
-
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
95
|
-
children: [/*#__PURE__*/_jsx("stop", {
|
|
96
|
-
offset: "0%",
|
|
97
|
-
stopColor: effectivePeakColor,
|
|
98
|
-
stopOpacity: peakOpacity
|
|
99
|
-
}), /*#__PURE__*/_jsx("stop", {
|
|
100
|
-
offset: "100%",
|
|
101
|
-
stopColor: effectiveBaselineColor,
|
|
102
|
-
stopOpacity: baselineOpacity
|
|
103
|
-
})]
|
|
104
|
-
})
|
|
54
|
+
transition: transition,
|
|
55
|
+
yAxisId: yAxisId
|
|
105
56
|
})
|
|
106
57
|
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
58
|
+
animate: animate,
|
|
107
59
|
d: d,
|
|
108
|
-
fill: "url(#".concat(patternId, ")")
|
|
60
|
+
fill: gradient ? "url(#".concat(patternId, ")") : fill,
|
|
61
|
+
fillOpacity: fillOpacity,
|
|
62
|
+
transition: transition
|
|
109
63
|
}, pathProps))]
|
|
110
64
|
});
|
|
111
65
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["d", "fill", "fillOpacity", "yAxisId", "
|
|
1
|
+
const _excluded = ["d", "fill", "fillOpacity", "yAxisId", "animate", "transition", "gradient"];
|
|
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; }
|
|
@@ -6,24 +6,42 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
6
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
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
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 } from 'react';
|
|
9
|
+
import { memo, useId } from 'react';
|
|
10
|
+
import { Gradient } from '../gradient';
|
|
10
11
|
import { Path } from '../Path';
|
|
11
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
13
|
/**
|
|
13
14
|
* A customizable solid area component which uses Path.
|
|
15
|
+
* When a gradient is provided, renders with gradient fill.
|
|
16
|
+
* Otherwise, renders with solid fill.
|
|
14
17
|
*/
|
|
15
18
|
export const SolidArea = /*#__PURE__*/memo(_ref => {
|
|
16
19
|
let {
|
|
17
20
|
d,
|
|
18
|
-
fill,
|
|
21
|
+
fill = 'var(--color-fgPrimary)',
|
|
19
22
|
fillOpacity = 1,
|
|
20
23
|
yAxisId,
|
|
21
|
-
|
|
24
|
+
animate,
|
|
25
|
+
transition,
|
|
26
|
+
gradient
|
|
22
27
|
} = _ref,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
+
const patternId = useId();
|
|
30
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
31
|
+
children: [gradient && /*#__PURE__*/_jsx("defs", {
|
|
32
|
+
children: /*#__PURE__*/_jsx(Gradient, {
|
|
33
|
+
animate: animate,
|
|
34
|
+
gradient: gradient,
|
|
35
|
+
id: patternId,
|
|
36
|
+
transition: transition,
|
|
37
|
+
yAxisId: yAxisId
|
|
38
|
+
})
|
|
39
|
+
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
40
|
+
animate: animate,
|
|
41
|
+
d: d,
|
|
42
|
+
fill: gradient ? "url(#".concat(patternId, ")") : fill,
|
|
43
|
+
fillOpacity: fillOpacity,
|
|
44
|
+
transition: transition
|
|
45
|
+
}, pathProps))]
|
|
46
|
+
});
|
|
29
47
|
});
|
package/esm/chart/axis/Axis.js
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
|
+
import { accessoryFadeTransitionDuration } from '../utils';
|
|
1
2
|
export const axisLineStyles = "\n stroke: var(--color-fg);\n stroke-linecap: square;\n stroke-width: 1px;\n";
|
|
2
3
|
export const axisTickMarkStyles = "\n stroke: var(--color-fg);\n stroke-linecap: square;\n stroke-width: 1px;\n";
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* Animation variants for grouped axis tick labels - initial mount
|
|
6
|
-
*/
|
|
7
|
-
export const axisTickLabelsInitialAnimationVariants = {
|
|
8
|
-
initial: {
|
|
9
|
-
opacity: 0
|
|
10
|
-
},
|
|
11
|
-
animate: {
|
|
12
|
-
opacity: 1,
|
|
13
|
-
transition: {
|
|
14
|
-
duration: 0.15,
|
|
15
|
-
delay: 0.85 // Initial animation: wait 850ms then fade in over 150ms
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
exit: {
|
|
19
|
-
opacity: 0,
|
|
20
|
-
transition: {
|
|
21
|
-
duration: 0.15
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
5
|
/**
|
|
27
6
|
* Animation variants for axis elements - updates (used for both grid lines and tick labels)
|
|
28
7
|
*/
|
|
@@ -33,14 +12,14 @@ export const axisUpdateAnimationVariants = {
|
|
|
33
12
|
animate: {
|
|
34
13
|
opacity: 1,
|
|
35
14
|
transition: {
|
|
36
|
-
duration:
|
|
37
|
-
delay:
|
|
15
|
+
duration: accessoryFadeTransitionDuration,
|
|
16
|
+
delay: accessoryFadeTransitionDuration
|
|
38
17
|
}
|
|
39
18
|
},
|
|
40
19
|
exit: {
|
|
41
20
|
opacity: 0,
|
|
42
21
|
transition: {
|
|
43
|
-
duration:
|
|
22
|
+
duration: accessoryFadeTransitionDuration
|
|
44
23
|
}
|
|
45
24
|
}
|
|
46
25
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 } from 'react';
|
|
7
|
+
import { ChartText } from '../text';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
/**
|
|
10
|
+
* DefaultAxisTickLabel is the default label component for axis tick labels.
|
|
11
|
+
* Provides standard styling for both X and Y axis tick labels.
|
|
12
|
+
*/
|
|
13
|
+
export const DefaultAxisTickLabel = /*#__PURE__*/memo(props => {
|
|
14
|
+
return /*#__PURE__*/_jsx(ChartText, _objectSpread({}, props));
|
|
15
|
+
});
|
package/esm/chart/axis/XAxis.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "style", "className", "styles", "classNames", "GridLineComponent", "
|
|
1
|
+
const _excluded = ["position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "TickLabelComponent", "style", "className", "styles", "classNames", "GridLineComponent", "LineComponent", "TickMarkLineComponent", "tickMarkLabelGap", "minTickLabelGap", "showTickMarks", "showLine", "tickMarkSize", "tickInterval", "tickMinStep", "tickMaxStep", "label", "labelGap", "height", "testID"];
|
|
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; }
|
|
@@ -12,10 +12,15 @@ import { AnimatePresence, m as motion } from 'framer-motion';
|
|
|
12
12
|
import { useCartesianChartContext } from '../ChartProvider';
|
|
13
13
|
import { DottedLine } from '../line/DottedLine';
|
|
14
14
|
import { ReferenceLine } from '../line/ReferenceLine';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
15
|
+
import { SolidLine } from '../line/SolidLine';
|
|
16
|
+
import { ChartText } from '../text/ChartText';
|
|
17
|
+
import { ChartTextGroup } from '../text/ChartTextGroup';
|
|
18
|
+
import { getAxisTicksData, isCategoricalScale, lineToPath } from '../utils';
|
|
19
|
+
import { axisLineStyles, axisTickMarkStyles, axisUpdateAnimationVariants } from './Axis';
|
|
20
|
+
import { DefaultAxisTickLabel } from './DefaultAxisTickLabel';
|
|
18
21
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
const AXIS_HEIGHT = 32;
|
|
23
|
+
const LABEL_SIZE = 20;
|
|
19
24
|
const axisTickMarkCss = "cds-axisTickMarkCss-a6j4s2q";
|
|
20
25
|
const axisLineCss = "cds-axisLineCss-a12llxjj";
|
|
21
26
|
export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
@@ -25,20 +30,26 @@ export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
|
25
30
|
requestedTickCount,
|
|
26
31
|
ticks,
|
|
27
32
|
tickLabelFormatter,
|
|
33
|
+
TickLabelComponent = DefaultAxisTickLabel,
|
|
28
34
|
style,
|
|
29
35
|
className,
|
|
30
36
|
styles,
|
|
31
37
|
classNames,
|
|
32
38
|
GridLineComponent = DottedLine,
|
|
39
|
+
LineComponent = SolidLine,
|
|
40
|
+
TickMarkLineComponent = SolidLine,
|
|
33
41
|
tickMarkLabelGap = 2,
|
|
34
|
-
height = 32,
|
|
35
42
|
minTickLabelGap = 4,
|
|
36
43
|
showTickMarks,
|
|
37
44
|
showLine,
|
|
38
45
|
tickMarkSize = 4,
|
|
39
46
|
tickInterval = 32,
|
|
40
47
|
tickMinStep = 1,
|
|
41
|
-
tickMaxStep
|
|
48
|
+
tickMaxStep,
|
|
49
|
+
label,
|
|
50
|
+
labelGap = 4,
|
|
51
|
+
height = label ? AXIS_HEIGHT + LABEL_SIZE : AXIS_HEIGHT,
|
|
52
|
+
testID = 'x-axis'
|
|
42
53
|
} = _ref,
|
|
43
54
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
44
55
|
const registrationId = useId();
|
|
@@ -114,9 +125,10 @@ export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
|
114
125
|
if (!axisBounds) return null;
|
|
115
126
|
return ticksData.map(tick => {
|
|
116
127
|
const tickOffset = tickMarkLabelGap + (showTickMarks ? tickMarkSize : 0);
|
|
117
|
-
const availableSpace =
|
|
128
|
+
const availableSpace = AXIS_HEIGHT - tickOffset;
|
|
118
129
|
const labelOffset = availableSpace / 2;
|
|
119
|
-
const
|
|
130
|
+
const baseY = position === 'top' && label ? axisBounds.y + LABEL_SIZE : axisBounds.y;
|
|
131
|
+
const labelY = position === 'top' ? baseY + labelOffset - tickOffset : baseY + labelOffset + tickOffset;
|
|
120
132
|
return {
|
|
121
133
|
x: tick.position,
|
|
122
134
|
y: labelY,
|
|
@@ -130,65 +142,77 @@ export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
|
130
142
|
}
|
|
131
143
|
};
|
|
132
144
|
});
|
|
133
|
-
}, [axisBounds, ticksData, tickMarkLabelGap, showTickMarks, tickMarkSize, position, formatTick, classNames === null || classNames === void 0 ? void 0 : classNames.tickLabel, styles === null || styles === void 0 ? void 0 : styles.tickLabel]);
|
|
134
|
-
if (!xScale) return;
|
|
145
|
+
}, [axisBounds, ticksData, tickMarkLabelGap, showTickMarks, tickMarkSize, position, formatTick, classNames === null || classNames === void 0 ? void 0 : classNames.tickLabel, styles === null || styles === void 0 ? void 0 : styles.tickLabel, label]);
|
|
146
|
+
if (!xScale || !axisBounds) return;
|
|
147
|
+
const labelX = axisBounds.x + axisBounds.width / 2;
|
|
148
|
+
const labelY = position === 'bottom' ? axisBounds.y + axisBounds.height - LABEL_SIZE / 2 : axisBounds.y + LABEL_SIZE / 2;
|
|
135
149
|
return /*#__PURE__*/_jsxs("g", _objectSpread(_objectSpread({
|
|
136
150
|
className: cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root),
|
|
137
151
|
"data-axis": "x",
|
|
138
152
|
"data-position": position,
|
|
139
153
|
style: _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root)
|
|
140
154
|
}, props), {}, {
|
|
141
|
-
children: [showGrid && /*#__PURE__*/_jsx(
|
|
142
|
-
|
|
143
|
-
children:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
children: /*#__PURE__*/_jsx(motion.g, {
|
|
160
|
-
animate: "animate",
|
|
161
|
-
exit: "exit",
|
|
162
|
-
initial: "initial",
|
|
163
|
-
variants: animate ? axisTickLabelsInitialAnimationVariants : undefined,
|
|
164
|
-
children: /*#__PURE__*/_jsx(SmartChartTextGroup, {
|
|
165
|
-
prioritizeEndLabels: true,
|
|
166
|
-
labels: chartTextData,
|
|
167
|
-
minGap: minTickLabelGap
|
|
155
|
+
children: [showGrid && /*#__PURE__*/_jsx("g", {
|
|
156
|
+
"data-testid": "".concat(testID, "-grid"),
|
|
157
|
+
children: /*#__PURE__*/_jsx(AnimatePresence, {
|
|
158
|
+
initial: false,
|
|
159
|
+
children: ticksData.map((tick, index) => {
|
|
160
|
+
const verticalLine = /*#__PURE__*/_jsx(ReferenceLine, {
|
|
161
|
+
LineComponent: GridLineComponent,
|
|
162
|
+
dataX: tick.tick
|
|
163
|
+
});
|
|
164
|
+
return animate ? /*#__PURE__*/_jsx(motion.g, {
|
|
165
|
+
animate: "animate",
|
|
166
|
+
exit: "exit",
|
|
167
|
+
initial: "initial",
|
|
168
|
+
variants: axisUpdateAnimationVariants,
|
|
169
|
+
children: verticalLine
|
|
170
|
+
}, "grid-".concat(tick.tick, "-").concat(index)) : /*#__PURE__*/_jsx("g", {
|
|
171
|
+
children: verticalLine
|
|
172
|
+
}, "grid-".concat(tick.tick, "-").concat(index));
|
|
168
173
|
})
|
|
169
174
|
})
|
|
175
|
+
}), chartTextData && /*#__PURE__*/_jsx(ChartTextGroup, {
|
|
176
|
+
prioritizeEndLabels: true,
|
|
177
|
+
LabelComponent: TickLabelComponent,
|
|
178
|
+
labels: chartTextData,
|
|
179
|
+
minGap: minTickLabelGap
|
|
170
180
|
}), axisBounds && showTickMarks && /*#__PURE__*/_jsx("g", {
|
|
171
|
-
"data-testid": "tick-marks",
|
|
181
|
+
"data-testid": "".concat(testID, "-tick-marks"),
|
|
172
182
|
children: ticksData.map((tick, index) => {
|
|
173
183
|
const tickY = position === 'bottom' ? axisBounds.y : axisBounds.y + axisBounds.height;
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
184
|
+
const tickY2 = position === 'bottom' ? tickY + tickMarkSize : tickY - tickMarkSize;
|
|
185
|
+
return /*#__PURE__*/_jsx(TickMarkLineComponent, {
|
|
186
|
+
animate: false,
|
|
177
187
|
className: cx(axisTickMarkCss, classNames === null || classNames === void 0 ? void 0 : classNames.tickMark),
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
188
|
+
clipRect: null,
|
|
189
|
+
d: lineToPath(tick.position, tickY2, tick.position, tickY),
|
|
190
|
+
stroke: "var(--color-fg)",
|
|
191
|
+
strokeLinecap: "square",
|
|
192
|
+
strokeWidth: 1,
|
|
193
|
+
style: styles === null || styles === void 0 ? void 0 : styles.tickMark
|
|
183
194
|
}, "tick-mark-".concat(tick.tick, "-").concat(index));
|
|
184
195
|
})
|
|
185
|
-
}),
|
|
196
|
+
}), showLine && /*#__PURE__*/_jsx(LineComponent, {
|
|
197
|
+
animate: false,
|
|
186
198
|
className: cx(axisLineCss, classNames === null || classNames === void 0 ? void 0 : classNames.line),
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
199
|
+
clipRect: null,
|
|
200
|
+
d: lineToPath(axisBounds.x, position === 'bottom' ? axisBounds.y : axisBounds.y + axisBounds.height, axisBounds.x + axisBounds.width, position === 'bottom' ? axisBounds.y : axisBounds.y + axisBounds.height),
|
|
201
|
+
"data-testid": "".concat(testID, "-line"),
|
|
202
|
+
stroke: "var(--color-fg)",
|
|
203
|
+
strokeLinecap: "square",
|
|
204
|
+
strokeWidth: 1,
|
|
205
|
+
style: styles === null || styles === void 0 ? void 0 : styles.line
|
|
206
|
+
}), label && /*#__PURE__*/_jsx(ChartText, {
|
|
207
|
+
disableRepositioning: true,
|
|
208
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.label,
|
|
209
|
+
horizontalAlignment: "center",
|
|
210
|
+
style: styles === null || styles === void 0 ? void 0 : styles.label,
|
|
211
|
+
testID: "".concat(testID, "-label"),
|
|
212
|
+
verticalAlignment: "middle",
|
|
213
|
+
x: labelX,
|
|
214
|
+
y: labelY,
|
|
215
|
+
children: label
|
|
192
216
|
})]
|
|
193
217
|
}));
|
|
194
218
|
});
|