@coinbase/cds-web-visualization 3.3.0 → 3.4.0-beta.2
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 +30 -0
- package/dts/chart/CartesianChart.d.ts +36 -0
- package/dts/chart/CartesianChart.d.ts.map +1 -0
- package/dts/chart/ChartProvider.d.ts +6 -0
- package/dts/chart/ChartProvider.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +34 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +61 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/Point.d.ts +153 -0
- package/dts/chart/Point.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +48 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +52 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +68 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +30 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +8 -0
- package/dts/chart/area/SolidArea.d.ts.map +1 -0
- package/dts/chart/area/index.d.ts +6 -0
- package/dts/chart/area/index.d.ts.map +1 -0
- package/dts/chart/axis/Axis.d.ts +208 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- package/dts/chart/axis/XAxis.d.ts +16 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -0
- package/dts/chart/axis/YAxis.d.ts +21 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -0
- package/dts/chart/axis/index.d.ts +4 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +91 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +53 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +29 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +111 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +35 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBar.d.ts +17 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +16 -0
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
- package/dts/chart/bar/index.d.ts +8 -0
- package/dts/chart/bar/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +13 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +14 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/GradientLine.d.ts +42 -0
- package/dts/chart/line/GradientLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +80 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +59 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +131 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +14 -0
- package/dts/chart/line/SolidLine.d.ts.map +1 -0
- package/dts/chart/line/index.d.ts +7 -0
- package/dts/chart/line/index.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +149 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +93 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +7 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +2 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +114 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts +55 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +3 -0
- package/dts/chart/text/index.d.ts.map +1 -0
- package/dts/chart/utils/axis.d.ts +342 -0
- package/dts/chart/utils/axis.d.ts.map +1 -0
- package/dts/chart/utils/bar.d.ts +20 -0
- package/dts/chart/utils/bar.d.ts.map +1 -0
- package/dts/chart/utils/chart.d.ts +97 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +95 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +8 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +107 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +75 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +43 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/index.d.ts +2 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/Counter.d.ts +7 -2
- package/dts/sparkline/Sparkline.d.ts +61 -16
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +12 -4
- package/dts/sparkline/SparklineArea.d.ts.map +1 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +12 -4
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
- package/dts/sparkline/SparklineGradient.d.ts +21 -10
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
- package/dts/sparkline/SparklinePath.d.ts +8 -6
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +1 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +8 -2
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
- package/dts/sparkline/index.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +9 -5
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +168 -118
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +22 -9
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +4 -2
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +4 -2
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +5 -3
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +21 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +21 -16
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +17 -12
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +23 -10
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +12 -12
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +22 -14
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/fade.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +11 -11
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +101 -93
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
- package/esm/chart/CartesianChart.css +1 -0
- package/esm/chart/CartesianChart.js +258 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +89 -0
- package/esm/chart/PeriodSelector.css +1 -0
- package/esm/chart/PeriodSelector.js +126 -0
- package/esm/chart/Point.css +2 -0
- package/esm/chart/Point.js +171 -0
- package/esm/chart/area/Area.js +85 -0
- package/esm/chart/area/AreaChart.js +164 -0
- package/esm/chart/area/DottedArea.js +141 -0
- package/esm/chart/area/GradientArea.js +111 -0
- package/esm/chart/area/SolidArea.js +29 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +46 -0
- package/esm/chart/axis/XAxis.css +2 -0
- package/esm/chart/axis/XAxis.js +195 -0
- package/esm/chart/axis/YAxis.css +2 -0
- package/esm/chart/axis/YAxis.js +183 -0
- package/esm/chart/axis/index.js +5 -0
- package/esm/chart/bar/Bar.js +59 -0
- package/esm/chart/bar/BarChart.js +147 -0
- package/esm/chart/bar/BarPlot.js +96 -0
- package/esm/chart/bar/BarStack.js +519 -0
- package/esm/chart/bar/BarStackGroup.js +96 -0
- package/esm/chart/bar/DefaultBar.js +64 -0
- package/esm/chart/bar/DefaultBarStack.js +60 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/index.js +14 -0
- package/esm/chart/line/DottedLine.js +38 -0
- package/esm/chart/line/GradientLine.js +58 -0
- package/esm/chart/line/Line.js +159 -0
- package/esm/chart/line/LineChart.js +120 -0
- package/esm/chart/line/ReferenceLine.js +142 -0
- package/esm/chart/line/SolidLine.js +34 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/scrubber/Scrubber.js +483 -0
- package/esm/chart/scrubber/ScrubberBeacon.js +195 -0
- package/esm/chart/scrubber/ScrubberBeaconLabel.js +33 -0
- package/esm/chart/scrubber/ScrubberProvider.js +228 -0
- package/esm/chart/scrubber/index.js +2 -0
- package/esm/chart/text/ChartText.js +236 -0
- package/esm/chart/text/SmartChartTextGroup.js +226 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +593 -0
- package/esm/chart/utils/bar.js +24 -0
- package/esm/chart/utils/chart.js +229 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/index.js +9 -0
- package/esm/chart/utils/path.js +204 -0
- package/esm/chart/utils/point.js +118 -0
- package/esm/chart/utils/scale.js +48 -0
- package/esm/index.js +4 -1
- package/esm/sparkline/Sparkline.js +129 -15
- package/esm/sparkline/SparklineArea.js +7 -2
- package/esm/sparkline/SparklineAreaPattern.js +4 -2
- package/esm/sparkline/SparklineGradient.js +16 -58
- package/esm/sparkline/generateSparklineWithId.js +3 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
- package/package.json +15 -11
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -374
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -87
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +0 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
const _excluded = ["d", "fill", "className", "style", "patternSize", "dotSize", "peakOpacity", "baselineOpacity", "baseline", "yAxisId", "classNames", "styles", "animate"];
|
|
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, useId } from 'react';
|
|
10
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
11
|
+
import { Path } from '../Path';
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
export const DottedArea = /*#__PURE__*/memo(_ref => {
|
|
14
|
+
let {
|
|
15
|
+
d,
|
|
16
|
+
fill,
|
|
17
|
+
className,
|
|
18
|
+
style,
|
|
19
|
+
patternSize = 4,
|
|
20
|
+
dotSize = 1,
|
|
21
|
+
peakOpacity = 1,
|
|
22
|
+
baselineOpacity = 0,
|
|
23
|
+
baseline,
|
|
24
|
+
yAxisId,
|
|
25
|
+
classNames,
|
|
26
|
+
styles,
|
|
27
|
+
animate
|
|
28
|
+
} = _ref,
|
|
29
|
+
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
const context = useCartesianChartContext();
|
|
31
|
+
const patternId = useId();
|
|
32
|
+
const gradientId = useId();
|
|
33
|
+
const maskId = useId();
|
|
34
|
+
const dotCenterPosition = patternSize / 2;
|
|
35
|
+
|
|
36
|
+
// Get the y-scale for the specified axis (or default)
|
|
37
|
+
const yScale = context.getYScale(yAxisId);
|
|
38
|
+
const yRange = yScale === null || yScale === void 0 ? void 0 : yScale.range();
|
|
39
|
+
const yDomain = yScale === null || yScale === void 0 ? void 0 : yScale.domain();
|
|
40
|
+
|
|
41
|
+
// Use chart range if available, otherwise fall back to percentage
|
|
42
|
+
const useUserSpaceUnits = yRange !== undefined;
|
|
43
|
+
|
|
44
|
+
// Auto-calculate baseline position based on domain
|
|
45
|
+
let baselinePosition;
|
|
46
|
+
let baselinePercentage;
|
|
47
|
+
if (yScale && yDomain) {
|
|
48
|
+
const [minValue, maxValue] = yDomain;
|
|
49
|
+
let dataBaseline;
|
|
50
|
+
if (minValue >= 0) {
|
|
51
|
+
// All positive: baseline at min
|
|
52
|
+
dataBaseline = minValue;
|
|
53
|
+
} else if (maxValue <= 0) {
|
|
54
|
+
// All negative: baseline at max
|
|
55
|
+
dataBaseline = maxValue;
|
|
56
|
+
} else {
|
|
57
|
+
// Crosses zero: baseline at 0
|
|
58
|
+
dataBaseline = 0;
|
|
59
|
+
}
|
|
60
|
+
if (useUserSpaceUnits) {
|
|
61
|
+
// Get the actual y coordinate for the baseline
|
|
62
|
+
const scaledValue = yScale(baseline !== null && baseline !== void 0 ? baseline : dataBaseline);
|
|
63
|
+
if (typeof scaledValue === 'number') {
|
|
64
|
+
baselinePosition = scaledValue;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
// Calculate percentage position
|
|
68
|
+
baselinePercentage = "".concat((maxValue - (baseline !== null && baseline !== void 0 ? baseline : dataBaseline)) / (maxValue - minValue) * 100, "%");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const gradientY1 = useUserSpaceUnits ? yRange[1] : '0%';
|
|
72
|
+
const gradientY2 = useUserSpaceUnits ? yRange[0] : '100%';
|
|
73
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
74
|
+
className: className !== null && className !== void 0 ? className : classNames === null || classNames === void 0 ? void 0 : classNames.root,
|
|
75
|
+
style: style !== null && style !== void 0 ? style : styles === null || styles === void 0 ? void 0 : styles.root,
|
|
76
|
+
children: [/*#__PURE__*/_jsxs("defs", {
|
|
77
|
+
children: [/*#__PURE__*/_jsx("pattern", {
|
|
78
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.pattern,
|
|
79
|
+
height: patternSize,
|
|
80
|
+
id: patternId,
|
|
81
|
+
patternUnits: "userSpaceOnUse",
|
|
82
|
+
style: styles === null || styles === void 0 ? void 0 : styles.pattern,
|
|
83
|
+
width: patternSize,
|
|
84
|
+
x: "0",
|
|
85
|
+
y: "0",
|
|
86
|
+
children: /*#__PURE__*/_jsx("circle", {
|
|
87
|
+
cx: dotCenterPosition,
|
|
88
|
+
cy: dotCenterPosition,
|
|
89
|
+
fill: fill,
|
|
90
|
+
r: dotSize
|
|
91
|
+
})
|
|
92
|
+
}), /*#__PURE__*/_jsx("linearGradient", {
|
|
93
|
+
gradientUnits: useUserSpaceUnits ? 'userSpaceOnUse' : 'objectBoundingBox',
|
|
94
|
+
id: gradientId,
|
|
95
|
+
x1: useUserSpaceUnits ? 0 : '0%',
|
|
96
|
+
x2: useUserSpaceUnits ? 0 : '0%',
|
|
97
|
+
y1: gradientY1,
|
|
98
|
+
y2: gradientY2,
|
|
99
|
+
children: baselinePosition !== undefined || baselinePercentage !== undefined ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
100
|
+
children: [/*#__PURE__*/_jsx("stop", {
|
|
101
|
+
offset: "0%",
|
|
102
|
+
stopColor: "white",
|
|
103
|
+
stopOpacity: peakOpacity
|
|
104
|
+
}), /*#__PURE__*/_jsx("stop", {
|
|
105
|
+
offset: baselinePercentage !== null && baselinePercentage !== void 0 ? baselinePercentage : "".concat((baselinePosition - yRange[1]) / (yRange[0] - yRange[1]) * 100, "%"),
|
|
106
|
+
stopColor: "white",
|
|
107
|
+
stopOpacity: baselineOpacity
|
|
108
|
+
}), /*#__PURE__*/_jsx("stop", {
|
|
109
|
+
offset: "100%",
|
|
110
|
+
stopColor: "white",
|
|
111
|
+
stopOpacity: peakOpacity
|
|
112
|
+
})]
|
|
113
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
114
|
+
children: [/*#__PURE__*/_jsx("stop", {
|
|
115
|
+
offset: "0%",
|
|
116
|
+
stopColor: "white",
|
|
117
|
+
stopOpacity: peakOpacity
|
|
118
|
+
}), /*#__PURE__*/_jsx("stop", {
|
|
119
|
+
offset: "100%",
|
|
120
|
+
stopColor: "white",
|
|
121
|
+
stopOpacity: baselineOpacity
|
|
122
|
+
})]
|
|
123
|
+
})
|
|
124
|
+
}), /*#__PURE__*/_jsx("mask", {
|
|
125
|
+
id: maskId,
|
|
126
|
+
children: /*#__PURE__*/_jsx(Path, {
|
|
127
|
+
animate: animate,
|
|
128
|
+
d: d,
|
|
129
|
+
fill: "url(#".concat(gradientId, ")")
|
|
130
|
+
})
|
|
131
|
+
})]
|
|
132
|
+
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
133
|
+
animate: animate,
|
|
134
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.path,
|
|
135
|
+
d: d,
|
|
136
|
+
fill: "url(#".concat(patternId, ")"),
|
|
137
|
+
mask: "url(#".concat(maskId, ")"),
|
|
138
|
+
style: styles === null || styles === void 0 ? void 0 : styles.path
|
|
139
|
+
}, pathProps))]
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const _excluded = ["d", "fill", "fillOpacity", "peakColor", "baselineColor", "peakOpacity", "baselineOpacity", "baseline", "yAxisId"];
|
|
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, useId } from 'react';
|
|
10
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
11
|
+
import { Path } from '../Path';
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* A customizable gradient area component which uses Path.
|
|
15
|
+
*/
|
|
16
|
+
export const GradientArea = /*#__PURE__*/memo(_ref => {
|
|
17
|
+
let {
|
|
18
|
+
d,
|
|
19
|
+
fill = 'var(--color-fgPrimary)',
|
|
20
|
+
fillOpacity = 1,
|
|
21
|
+
peakColor,
|
|
22
|
+
baselineColor,
|
|
23
|
+
peakOpacity = 0.3,
|
|
24
|
+
baselineOpacity = 0,
|
|
25
|
+
baseline,
|
|
26
|
+
yAxisId
|
|
27
|
+
} = _ref,
|
|
28
|
+
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
+
const context = useCartesianChartContext();
|
|
30
|
+
const patternId = useId();
|
|
31
|
+
|
|
32
|
+
// Get the y-scale for the specified axis (or default)
|
|
33
|
+
const yScale = context.getYScale(yAxisId);
|
|
34
|
+
const yRange = yScale === null || yScale === void 0 ? void 0 : yScale.range();
|
|
35
|
+
const yDomain = yScale === null || yScale === void 0 ? void 0 : yScale.domain();
|
|
36
|
+
|
|
37
|
+
// Use chart range if available, otherwise fall back to percentage
|
|
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;
|
|
71
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
72
|
+
children: [/*#__PURE__*/_jsx("defs", {
|
|
73
|
+
children: /*#__PURE__*/_jsx("linearGradient", {
|
|
74
|
+
gradientUnits: useUserSpaceUnits ? 'userSpaceOnUse' : 'objectBoundingBox',
|
|
75
|
+
id: patternId,
|
|
76
|
+
x1: useUserSpaceUnits ? 0 : '0%',
|
|
77
|
+
x2: useUserSpaceUnits ? 0 : '0%',
|
|
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
|
+
})
|
|
105
|
+
})
|
|
106
|
+
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
107
|
+
d: d,
|
|
108
|
+
fill: "url(#".concat(patternId, ")")
|
|
109
|
+
}, pathProps))]
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const _excluded = ["d", "fill", "fillOpacity", "yAxisId", "baseline"];
|
|
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 } from 'react';
|
|
10
|
+
import { Path } from '../Path';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
/**
|
|
13
|
+
* A customizable solid area component which uses Path.
|
|
14
|
+
*/
|
|
15
|
+
export const SolidArea = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
let {
|
|
17
|
+
d,
|
|
18
|
+
fill,
|
|
19
|
+
fillOpacity = 1,
|
|
20
|
+
yAxisId,
|
|
21
|
+
baseline
|
|
22
|
+
} = _ref,
|
|
23
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
24
|
+
return /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
25
|
+
d: d,
|
|
26
|
+
fill: fill,
|
|
27
|
+
fillOpacity: fillOpacity
|
|
28
|
+
}, props));
|
|
29
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export const axisLineStyles = "\n stroke: var(--color-fg);\n stroke-linecap: square;\n stroke-width: 1px;\n";
|
|
2
|
+
export const axisTickMarkStyles = "\n stroke: var(--color-fg);\n stroke-linecap: square;\n stroke-width: 1px;\n";
|
|
3
|
+
|
|
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
|
+
/**
|
|
27
|
+
* Animation variants for axis elements - updates (used for both grid lines and tick labels)
|
|
28
|
+
*/
|
|
29
|
+
export const axisUpdateAnimationVariants = {
|
|
30
|
+
initial: {
|
|
31
|
+
opacity: 0
|
|
32
|
+
},
|
|
33
|
+
animate: {
|
|
34
|
+
opacity: 1,
|
|
35
|
+
transition: {
|
|
36
|
+
duration: 0.15,
|
|
37
|
+
delay: 0.15 // For updates: fade out 150ms, then fade in 150ms
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
exit: {
|
|
41
|
+
opacity: 0,
|
|
42
|
+
transition: {
|
|
43
|
+
duration: 0.15
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
const _excluded = ["position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "style", "className", "styles", "classNames", "GridLineComponent", "tickMarkLabelGap", "height", "minTickLabelGap", "showTickMarks", "showLine", "tickMarkSize", "tickInterval", "tickMinStep", "tickMaxStep"];
|
|
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, useCallback, useEffect, useId, useMemo } from 'react';
|
|
10
|
+
import { cx } from '@coinbase/cds-web';
|
|
11
|
+
import { AnimatePresence, m as motion } from 'framer-motion';
|
|
12
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
13
|
+
import { DottedLine } from '../line/DottedLine';
|
|
14
|
+
import { ReferenceLine } from '../line/ReferenceLine';
|
|
15
|
+
import { SmartChartTextGroup } from '../text/SmartChartTextGroup';
|
|
16
|
+
import { getAxisTicksData, isCategoricalScale } from '../utils';
|
|
17
|
+
import { axisLineStyles, axisTickLabelsInitialAnimationVariants, axisTickMarkStyles, axisUpdateAnimationVariants } from './Axis';
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
const axisTickMarkCss = "cds-axisTickMarkCss-a6j4s2q";
|
|
20
|
+
const axisLineCss = "cds-axisLineCss-a12llxjj";
|
|
21
|
+
export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
22
|
+
let {
|
|
23
|
+
position = 'bottom',
|
|
24
|
+
showGrid,
|
|
25
|
+
requestedTickCount,
|
|
26
|
+
ticks,
|
|
27
|
+
tickLabelFormatter,
|
|
28
|
+
style,
|
|
29
|
+
className,
|
|
30
|
+
styles,
|
|
31
|
+
classNames,
|
|
32
|
+
GridLineComponent = DottedLine,
|
|
33
|
+
tickMarkLabelGap = 2,
|
|
34
|
+
height = 32,
|
|
35
|
+
minTickLabelGap = 4,
|
|
36
|
+
showTickMarks,
|
|
37
|
+
showLine,
|
|
38
|
+
tickMarkSize = 4,
|
|
39
|
+
tickInterval = 32,
|
|
40
|
+
tickMinStep = 1,
|
|
41
|
+
tickMaxStep
|
|
42
|
+
} = _ref,
|
|
43
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
+
const registrationId = useId();
|
|
45
|
+
const {
|
|
46
|
+
animate,
|
|
47
|
+
getXScale,
|
|
48
|
+
getXAxis,
|
|
49
|
+
registerAxis,
|
|
50
|
+
unregisterAxis,
|
|
51
|
+
getAxisBounds
|
|
52
|
+
} = useCartesianChartContext();
|
|
53
|
+
const xScale = getXScale();
|
|
54
|
+
const xAxis = getXAxis();
|
|
55
|
+
const axisBounds = getAxisBounds(registrationId);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
registerAxis(registrationId, position, height);
|
|
58
|
+
return () => unregisterAxis(registrationId);
|
|
59
|
+
}, [registrationId, registerAxis, unregisterAxis, position, height]);
|
|
60
|
+
const formatTick = useCallback(value => {
|
|
61
|
+
var _tickLabelFormatter;
|
|
62
|
+
// If we have string labels and no custom formatter, use the labels
|
|
63
|
+
const axisData = xAxis === null || xAxis === void 0 ? void 0 : xAxis.data;
|
|
64
|
+
const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
|
|
65
|
+
let finalValue = value;
|
|
66
|
+
|
|
67
|
+
// For band scales with string data, value is an index
|
|
68
|
+
if (hasStringLabels && typeof value === 'number' && axisData[value] !== undefined) {
|
|
69
|
+
finalValue = axisData[value];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Use the formatter (if provided) or the value itself
|
|
73
|
+
return (_tickLabelFormatter = tickLabelFormatter === null || tickLabelFormatter === void 0 ? void 0 : tickLabelFormatter(finalValue)) !== null && _tickLabelFormatter !== void 0 ? _tickLabelFormatter : finalValue;
|
|
74
|
+
}, [xAxis === null || xAxis === void 0 ? void 0 : xAxis.data, tickLabelFormatter]);
|
|
75
|
+
const ticksData = useMemo(() => {
|
|
76
|
+
if (!xScale) return [];
|
|
77
|
+
|
|
78
|
+
// Check if we have string labels
|
|
79
|
+
const axisData = xAxis === null || xAxis === void 0 ? void 0 : xAxis.data;
|
|
80
|
+
const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
|
|
81
|
+
|
|
82
|
+
// For band scales, we need categories
|
|
83
|
+
let categories;
|
|
84
|
+
if (hasStringLabels) {
|
|
85
|
+
categories = axisData;
|
|
86
|
+
} else if (isCategoricalScale(xScale)) {
|
|
87
|
+
// For band scales without explicit string data, generate numeric categories
|
|
88
|
+
// based on the domain of the scale
|
|
89
|
+
const domain = xScale.domain();
|
|
90
|
+
categories = domain.map(String);
|
|
91
|
+
}
|
|
92
|
+
let possibleTickValues;
|
|
93
|
+
|
|
94
|
+
// If we have discrete data, we can use the indices as possible tick values
|
|
95
|
+
if (axisData && Array.isArray(axisData) && (typeof axisData[0] === 'string' || typeof axisData[0] === 'number' && isCategoricalScale(xScale))) possibleTickValues = Array.from({
|
|
96
|
+
length: axisData.length
|
|
97
|
+
}, (_, i) => i);
|
|
98
|
+
return getAxisTicksData({
|
|
99
|
+
scaleFunction: xScale,
|
|
100
|
+
ticks,
|
|
101
|
+
requestedTickCount,
|
|
102
|
+
categories,
|
|
103
|
+
possibleTickValues: axisData && Array.isArray(axisData) && typeof axisData[0] === 'string' ? Array.from({
|
|
104
|
+
length: axisData.length
|
|
105
|
+
}, (_, i) => i) : undefined,
|
|
106
|
+
tickInterval: tickInterval,
|
|
107
|
+
options: {
|
|
108
|
+
minStep: tickMinStep,
|
|
109
|
+
maxStep: tickMaxStep
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}, [ticks, xScale, requestedTickCount, tickInterval, tickMinStep, tickMaxStep, xAxis === null || xAxis === void 0 ? void 0 : xAxis.data]);
|
|
113
|
+
const chartTextData = useMemo(() => {
|
|
114
|
+
if (!axisBounds) return null;
|
|
115
|
+
return ticksData.map(tick => {
|
|
116
|
+
const tickOffset = tickMarkLabelGap + (showTickMarks ? tickMarkSize : 0);
|
|
117
|
+
const availableSpace = axisBounds.height - tickOffset;
|
|
118
|
+
const labelOffset = availableSpace / 2;
|
|
119
|
+
const labelY = position === 'top' ? axisBounds.y + labelOffset - tickOffset : axisBounds.y + labelOffset + tickOffset;
|
|
120
|
+
return {
|
|
121
|
+
x: tick.position,
|
|
122
|
+
y: labelY,
|
|
123
|
+
label: formatTick(tick.tick),
|
|
124
|
+
chartTextProps: {
|
|
125
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.tickLabel,
|
|
126
|
+
color: 'var(--color-fgMuted)',
|
|
127
|
+
verticalAlignment: 'middle',
|
|
128
|
+
style: styles === null || styles === void 0 ? void 0 : styles.tickLabel,
|
|
129
|
+
horizontalAlignment: 'center'
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
});
|
|
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;
|
|
135
|
+
return /*#__PURE__*/_jsxs("g", _objectSpread(_objectSpread({
|
|
136
|
+
className: cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root),
|
|
137
|
+
"data-axis": "x",
|
|
138
|
+
"data-position": position,
|
|
139
|
+
style: _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root)
|
|
140
|
+
}, props), {}, {
|
|
141
|
+
children: [showGrid && /*#__PURE__*/_jsx(AnimatePresence, {
|
|
142
|
+
initial: false,
|
|
143
|
+
children: ticksData.map((tick, index) => {
|
|
144
|
+
const verticalLine = /*#__PURE__*/_jsx(ReferenceLine, {
|
|
145
|
+
LineComponent: GridLineComponent,
|
|
146
|
+
dataX: tick.tick
|
|
147
|
+
});
|
|
148
|
+
return animate ? /*#__PURE__*/_jsx(motion.g, {
|
|
149
|
+
animate: "animate",
|
|
150
|
+
exit: "exit",
|
|
151
|
+
initial: "initial",
|
|
152
|
+
variants: axisUpdateAnimationVariants,
|
|
153
|
+
children: verticalLine
|
|
154
|
+
}, "grid-".concat(tick.tick, "-").concat(index)) : /*#__PURE__*/_jsx("g", {
|
|
155
|
+
children: verticalLine
|
|
156
|
+
}, "grid-".concat(tick.tick, "-").concat(index));
|
|
157
|
+
})
|
|
158
|
+
}), chartTextData && /*#__PURE__*/_jsx(AnimatePresence, {
|
|
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
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
}), axisBounds && showTickMarks && /*#__PURE__*/_jsx("g", {
|
|
171
|
+
"data-testid": "tick-marks",
|
|
172
|
+
children: ticksData.map((tick, index) => {
|
|
173
|
+
const tickY = position === 'bottom' ? axisBounds.y : axisBounds.y + axisBounds.height;
|
|
174
|
+
const tickMarkSizePixels = tickMarkSize;
|
|
175
|
+
const tickY2 = position === 'bottom' ? axisBounds.y + tickMarkSizePixels : axisBounds.y + axisBounds.height - tickMarkSizePixels;
|
|
176
|
+
return /*#__PURE__*/_jsx("line", {
|
|
177
|
+
className: cx(axisTickMarkCss, classNames === null || classNames === void 0 ? void 0 : classNames.tickMark),
|
|
178
|
+
style: styles === null || styles === void 0 ? void 0 : styles.tickMark,
|
|
179
|
+
x1: tick.position,
|
|
180
|
+
x2: tick.position,
|
|
181
|
+
y1: tickY,
|
|
182
|
+
y2: tickY2
|
|
183
|
+
}, "tick-mark-".concat(tick.tick, "-").concat(index));
|
|
184
|
+
})
|
|
185
|
+
}), axisBounds && showLine && /*#__PURE__*/_jsx("line", {
|
|
186
|
+
className: cx(axisLineCss, classNames === null || classNames === void 0 ? void 0 : classNames.line),
|
|
187
|
+
style: styles === null || styles === void 0 ? void 0 : styles.line,
|
|
188
|
+
x1: axisBounds.x,
|
|
189
|
+
x2: axisBounds.x + axisBounds.width,
|
|
190
|
+
y1: position === 'bottom' ? axisBounds.y : axisBounds.y + axisBounds.height,
|
|
191
|
+
y2: position === 'bottom' ? axisBounds.y : axisBounds.y + axisBounds.height
|
|
192
|
+
})]
|
|
193
|
+
}));
|
|
194
|
+
});
|
|
195
|
+
import "./XAxis.css";
|