@coinbase/cds-web-visualization 3.3.2 → 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 +50 -2
- package/dts/chart/CartesianChart.d.ts +72 -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 +54 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +57 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +78 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +79 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +45 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +39 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +23 -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 +255 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- 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 +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 +5 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +94 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +62 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +30 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +103 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +36 -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/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 +14 -0
- package/dts/chart/index.d.ts.map +1 -0
- 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 +26 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +122 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +77 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +178 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +25 -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/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 +290 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- 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/ScrubberProvider.d.ts +17 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +5 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +117 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/ChartTextGroup.d.ts +61 -0
- package/dts/chart/text/ChartTextGroup.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 +117 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +101 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- 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 +12 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- 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 +130 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +104 -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/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/index.d.ts +1 -0
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/Sparkline.d.ts +44 -9
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +4 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +5 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
- package/dts/sparkline/SparklineGradient.d.ts +5 -0
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +9 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +2 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
- package/esm/chart/CartesianChart.css +1 -0
- package/esm/chart/CartesianChart.js +313 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +95 -0
- package/esm/chart/PeriodSelector.css +1 -0
- package/esm/chart/PeriodSelector.js +112 -0
- package/esm/chart/area/Area.js +75 -0
- package/esm/chart/area/AreaChart.js +173 -0
- package/esm/chart/area/DottedArea.js +87 -0
- package/esm/chart/area/GradientArea.js +65 -0
- package/esm/chart/area/SolidArea.js +47 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +25 -0
- package/esm/chart/axis/DefaultAxisTickLabel.js +15 -0
- package/esm/chart/axis/XAxis.css +2 -0
- package/esm/chart/axis/XAxis.js +219 -0
- package/esm/chart/axis/YAxis.css +2 -0
- package/esm/chart/axis/YAxis.js +214 -0
- package/esm/chart/axis/index.js +6 -0
- package/esm/chart/bar/Bar.js +61 -0
- package/esm/chart/bar/BarChart.js +130 -0
- package/esm/chart/bar/BarPlot.js +97 -0
- package/esm/chart/bar/BarStack.js +561 -0
- package/esm/chart/bar/BarStackGroup.js +86 -0
- package/esm/chart/bar/DefaultBar.js +61 -0
- package/esm/chart/bar/DefaultBarStack.js +58 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/gradient/Gradient.js +104 -0
- package/esm/chart/gradient/index.js +1 -0
- package/esm/chart/index.js +15 -0
- package/esm/chart/line/DefaultReferenceLineLabel.js +81 -0
- package/esm/chart/line/DottedLine.js +59 -0
- package/esm/chart/line/Line.js +185 -0
- package/esm/chart/line/LineChart.js +132 -0
- package/esm/chart/line/ReferenceLine.js +140 -0
- package/esm/chart/line/SolidLine.js +55 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/point/DefaultPointLabel.js +44 -0
- package/esm/chart/point/Point.css +2 -0
- package/esm/chart/point/Point.js +180 -0
- package/esm/chart/point/index.js +2 -0
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +155 -0
- package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +46 -0
- package/esm/chart/scrubber/DefaultScrubberLabel.js +30 -0
- package/esm/chart/scrubber/Scrubber.js +189 -0
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +166 -0
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +186 -0
- package/esm/chart/scrubber/ScrubberProvider.js +228 -0
- package/esm/chart/scrubber/index.js +4 -0
- package/esm/chart/text/ChartText.js +230 -0
- package/esm/chart/text/ChartTextGroup.js +227 -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 +255 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/gradient.js +257 -0
- package/esm/chart/utils/index.js +13 -0
- package/esm/chart/utils/interpolate.js +644 -0
- package/esm/chart/utils/path.js +227 -0
- package/esm/chart/utils/point.js +187 -0
- package/esm/chart/utils/scale.js +48 -0
- package/esm/chart/utils/scrubber.js +132 -0
- package/esm/chart/utils/transition.js +111 -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/SparklineInteractiveMarkerDates.js +1 -1
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
- package/package.json +13 -9
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
const _excluded = ["series", "stacked", "AreaComponent", "curve", "fillOpacity", "type", "connectNulls", "transition", "LineComponent", "strokeWidth", "showXAxis", "showYAxis", "showLines", "lineType", "xAxis", "yAxis", "inset", "children"],
|
|
2
|
+
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
|
|
3
|
+
_excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
|
|
4
|
+
_excluded4 = ["id", "data", "label", "color", "yAxisId", "opacity", "LineComponent", "stackId", "transition"],
|
|
5
|
+
_excluded5 = ["id", "data", "label", "color", "yAxisId", "fill", "fillOpacity", "stackId", "type", "lineType", "transition"];
|
|
6
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
14
|
+
import { XAxis, YAxis } from '../axis';
|
|
15
|
+
import { CartesianChart } from '../CartesianChart';
|
|
16
|
+
import { Line } from '../line/Line';
|
|
17
|
+
import { defaultChartInset, defaultStackId, getChartInset } from '../utils';
|
|
18
|
+
import { Area } from './Area';
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
21
|
+
let {
|
|
22
|
+
series,
|
|
23
|
+
stacked,
|
|
24
|
+
AreaComponent,
|
|
25
|
+
curve,
|
|
26
|
+
fillOpacity,
|
|
27
|
+
type,
|
|
28
|
+
connectNulls,
|
|
29
|
+
transition,
|
|
30
|
+
LineComponent,
|
|
31
|
+
strokeWidth,
|
|
32
|
+
showXAxis,
|
|
33
|
+
showYAxis,
|
|
34
|
+
showLines,
|
|
35
|
+
lineType = 'solid',
|
|
36
|
+
xAxis,
|
|
37
|
+
yAxis,
|
|
38
|
+
inset,
|
|
39
|
+
children
|
|
40
|
+
} = _ref,
|
|
41
|
+
chartProps = _objectWithoutProperties(_ref, _excluded);
|
|
42
|
+
const calculatedInset = useMemo(() => getChartInset(inset, defaultChartInset), [inset]);
|
|
43
|
+
|
|
44
|
+
// Convert AreaSeries to Series for Chart context
|
|
45
|
+
const chartSeries = useMemo(() => {
|
|
46
|
+
return series === null || series === void 0 ? void 0 : series.map(s => ({
|
|
47
|
+
id: s.id,
|
|
48
|
+
data: s.data,
|
|
49
|
+
label: s.label,
|
|
50
|
+
color: s.color,
|
|
51
|
+
yAxisId: s.yAxisId,
|
|
52
|
+
stackId: s.stackId,
|
|
53
|
+
gradient: s.gradient
|
|
54
|
+
}));
|
|
55
|
+
}, [series]);
|
|
56
|
+
const transformedSeries = useMemo(() => {
|
|
57
|
+
if (!stacked || !chartSeries) return chartSeries;
|
|
58
|
+
return chartSeries.map(s => {
|
|
59
|
+
var _s$stackId;
|
|
60
|
+
return _objectSpread(_objectSpread({}, s), {}, {
|
|
61
|
+
stackId: (_s$stackId = s.stackId) !== null && _s$stackId !== void 0 ? _s$stackId : defaultStackId
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}, [chartSeries, stacked]);
|
|
65
|
+
const seriesToRender = transformedSeries !== null && transformedSeries !== void 0 ? transformedSeries : chartSeries;
|
|
66
|
+
|
|
67
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
68
|
+
const _ref2 = xAxis || {},
|
|
69
|
+
{
|
|
70
|
+
scaleType: xScaleType,
|
|
71
|
+
data: xData,
|
|
72
|
+
categoryPadding: xCategoryPadding,
|
|
73
|
+
domain: xDomain,
|
|
74
|
+
domainLimit: xDomainLimit,
|
|
75
|
+
range: xRange
|
|
76
|
+
} = _ref2,
|
|
77
|
+
xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
78
|
+
const _ref3 = yAxis || {},
|
|
79
|
+
{
|
|
80
|
+
scaleType: yScaleType,
|
|
81
|
+
data: yData,
|
|
82
|
+
categoryPadding: yCategoryPadding,
|
|
83
|
+
domain: yDomain,
|
|
84
|
+
domainLimit: yDomainLimit,
|
|
85
|
+
range: yRange,
|
|
86
|
+
id: yAxisId
|
|
87
|
+
} = _ref3,
|
|
88
|
+
yAxisVisualProps = _objectWithoutProperties(_ref3, _excluded3);
|
|
89
|
+
const xAxisConfig = {
|
|
90
|
+
scaleType: xScaleType,
|
|
91
|
+
data: xData,
|
|
92
|
+
categoryPadding: xCategoryPadding,
|
|
93
|
+
domain: xDomain,
|
|
94
|
+
domainLimit: xDomainLimit,
|
|
95
|
+
range: xRange
|
|
96
|
+
};
|
|
97
|
+
const hasNegativeValues = useMemo(() => {
|
|
98
|
+
if (!series) return false;
|
|
99
|
+
return series.some(s => {
|
|
100
|
+
var _s$data;
|
|
101
|
+
return (_s$data = s.data) === null || _s$data === void 0 ? void 0 : _s$data.some(value => typeof value === 'number' && value < 0 || Array.isArray(value) && value.some(v => typeof v === 'number' && v < 0));
|
|
102
|
+
});
|
|
103
|
+
}, [series]);
|
|
104
|
+
|
|
105
|
+
// Set default min domain to 0 for area chart, but only if there are no negative values
|
|
106
|
+
const yAxisConfig = {
|
|
107
|
+
scaleType: yScaleType,
|
|
108
|
+
data: yData,
|
|
109
|
+
categoryPadding: yCategoryPadding,
|
|
110
|
+
domain: hasNegativeValues ? yDomain : _objectSpread({
|
|
111
|
+
min: 0
|
|
112
|
+
}, yDomain),
|
|
113
|
+
domainLimit: yDomainLimit,
|
|
114
|
+
range: yRange
|
|
115
|
+
};
|
|
116
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
|
|
117
|
+
ref: ref,
|
|
118
|
+
inset: calculatedInset,
|
|
119
|
+
series: seriesToRender,
|
|
120
|
+
xAxis: xAxisConfig,
|
|
121
|
+
yAxis: yAxisConfig,
|
|
122
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
|
|
123
|
+
axisId: yAxisId
|
|
124
|
+
}, yAxisVisualProps)), series === null || series === void 0 ? void 0 : series.map(_ref4 => {
|
|
125
|
+
let {
|
|
126
|
+
id,
|
|
127
|
+
data,
|
|
128
|
+
label,
|
|
129
|
+
color,
|
|
130
|
+
yAxisId,
|
|
131
|
+
opacity,
|
|
132
|
+
LineComponent,
|
|
133
|
+
stackId,
|
|
134
|
+
transition: seriesTransition
|
|
135
|
+
} = _ref4,
|
|
136
|
+
areaPropsFromSeries = _objectWithoutProperties(_ref4, _excluded4);
|
|
137
|
+
return /*#__PURE__*/_jsx(Area, _objectSpread({
|
|
138
|
+
AreaComponent: AreaComponent,
|
|
139
|
+
connectNulls: connectNulls,
|
|
140
|
+
curve: curve,
|
|
141
|
+
fillOpacity: fillOpacity,
|
|
142
|
+
seriesId: id,
|
|
143
|
+
transition: seriesTransition !== null && seriesTransition !== void 0 ? seriesTransition : transition,
|
|
144
|
+
type: type
|
|
145
|
+
}, areaPropsFromSeries), id);
|
|
146
|
+
}), showLines && (series === null || series === void 0 ? void 0 : series.map(_ref5 => {
|
|
147
|
+
let {
|
|
148
|
+
id,
|
|
149
|
+
data,
|
|
150
|
+
label,
|
|
151
|
+
color,
|
|
152
|
+
yAxisId,
|
|
153
|
+
fill,
|
|
154
|
+
fillOpacity,
|
|
155
|
+
stackId,
|
|
156
|
+
type,
|
|
157
|
+
// Area type (don't pass to Line)
|
|
158
|
+
lineType: seriesLineType,
|
|
159
|
+
transition: seriesTransition
|
|
160
|
+
} = _ref5,
|
|
161
|
+
otherPropsFromSeries = _objectWithoutProperties(_ref5, _excluded5);
|
|
162
|
+
return /*#__PURE__*/_jsx(Line, _objectSpread({
|
|
163
|
+
LineComponent: LineComponent,
|
|
164
|
+
connectNulls: connectNulls,
|
|
165
|
+
curve: curve,
|
|
166
|
+
seriesId: id,
|
|
167
|
+
strokeWidth: strokeWidth,
|
|
168
|
+
transition: seriesTransition !== null && seriesTransition !== void 0 ? seriesTransition : transition,
|
|
169
|
+
type: seriesLineType !== null && seriesLineType !== void 0 ? seriesLineType : lineType
|
|
170
|
+
}, otherPropsFromSeries), id);
|
|
171
|
+
})), children]
|
|
172
|
+
}));
|
|
173
|
+
}));
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const _excluded = ["d", "fill", "patternSize", "dotSize", "peakOpacity", "baselineOpacity", "baseline", "yAxisId", "gradient", "animate", "transition"];
|
|
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, useMemo } from 'react';
|
|
10
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
11
|
+
import { Gradient } from '../gradient';
|
|
12
|
+
import { Path } from '../Path';
|
|
13
|
+
import { createGradient, getBaseline } from '../utils';
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
/**
|
|
16
|
+
* A customizable dotted area gradient component.
|
|
17
|
+
* When no gradient is provided, renders a default gradient based
|
|
18
|
+
* on the fill color and peak/baseline opacities.
|
|
19
|
+
*/
|
|
20
|
+
export const DottedArea = /*#__PURE__*/memo(_ref => {
|
|
21
|
+
let {
|
|
22
|
+
d,
|
|
23
|
+
fill = 'var(--color-fgPrimary)',
|
|
24
|
+
patternSize = 4,
|
|
25
|
+
dotSize = 1,
|
|
26
|
+
peakOpacity = 1,
|
|
27
|
+
baselineOpacity = 0,
|
|
28
|
+
baseline,
|
|
29
|
+
yAxisId,
|
|
30
|
+
gradient: gradientProp,
|
|
31
|
+
animate,
|
|
32
|
+
transition
|
|
33
|
+
} = _ref,
|
|
34
|
+
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
+
const {
|
|
36
|
+
getYAxis
|
|
37
|
+
} = useCartesianChartContext();
|
|
38
|
+
const patternId = useId();
|
|
39
|
+
const gradientId = useId();
|
|
40
|
+
const maskId = useId();
|
|
41
|
+
const dotCenterPosition = patternSize / 2;
|
|
42
|
+
const yAxisConfig = getYAxis(yAxisId);
|
|
43
|
+
const gradient = useMemo(() => {
|
|
44
|
+
if (gradientProp) return gradientProp;
|
|
45
|
+
if (!yAxisConfig) return;
|
|
46
|
+
const baselineValue = getBaseline(yAxisConfig.domain, baseline);
|
|
47
|
+
return createGradient(yAxisConfig.domain, baselineValue, fill, peakOpacity, baselineOpacity);
|
|
48
|
+
}, [gradientProp, yAxisConfig, fill, baseline, peakOpacity, baselineOpacity]);
|
|
49
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
50
|
+
children: [/*#__PURE__*/_jsxs("defs", {
|
|
51
|
+
children: [/*#__PURE__*/_jsx("pattern", {
|
|
52
|
+
height: patternSize,
|
|
53
|
+
id: patternId,
|
|
54
|
+
patternUnits: "userSpaceOnUse",
|
|
55
|
+
width: patternSize,
|
|
56
|
+
x: "0",
|
|
57
|
+
y: "0",
|
|
58
|
+
children: /*#__PURE__*/_jsx("circle", {
|
|
59
|
+
cx: dotCenterPosition,
|
|
60
|
+
cy: dotCenterPosition,
|
|
61
|
+
fill: "white",
|
|
62
|
+
r: dotSize
|
|
63
|
+
})
|
|
64
|
+
}), /*#__PURE__*/_jsx("mask", {
|
|
65
|
+
id: maskId,
|
|
66
|
+
children: /*#__PURE__*/_jsx(Path, {
|
|
67
|
+
animate: animate,
|
|
68
|
+
d: d,
|
|
69
|
+
fill: "url(#".concat(patternId, ")"),
|
|
70
|
+
transition: transition
|
|
71
|
+
})
|
|
72
|
+
}), gradient && /*#__PURE__*/_jsx(Gradient, {
|
|
73
|
+
animate: animate,
|
|
74
|
+
gradient: gradient,
|
|
75
|
+
id: gradientId,
|
|
76
|
+
transition: transition,
|
|
77
|
+
yAxisId: yAxisId
|
|
78
|
+
})]
|
|
79
|
+
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
80
|
+
animate: animate,
|
|
81
|
+
d: d,
|
|
82
|
+
fill: gradient ? "url(#".concat(gradientId, ")") : fill,
|
|
83
|
+
mask: "url(#".concat(maskId, ")"),
|
|
84
|
+
transition: transition
|
|
85
|
+
}, pathProps))]
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const _excluded = ["d", "fill", "fillOpacity", "peakOpacity", "baselineOpacity", "baseline", "yAxisId", "gradient", "animate", "transition"];
|
|
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, useMemo } from 'react';
|
|
10
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
11
|
+
import { Gradient } from '../gradient';
|
|
12
|
+
import { Path } from '../Path';
|
|
13
|
+
import { createGradient, getBaseline } from '../utils';
|
|
14
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
/**
|
|
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.
|
|
22
|
+
*/
|
|
23
|
+
export const GradientArea = /*#__PURE__*/memo(_ref => {
|
|
24
|
+
let {
|
|
25
|
+
d,
|
|
26
|
+
fill = 'var(--color-fgPrimary)',
|
|
27
|
+
fillOpacity = 1,
|
|
28
|
+
peakOpacity = 0.3,
|
|
29
|
+
baselineOpacity = 0,
|
|
30
|
+
baseline,
|
|
31
|
+
yAxisId,
|
|
32
|
+
gradient: gradientProp,
|
|
33
|
+
animate,
|
|
34
|
+
transition
|
|
35
|
+
} = _ref,
|
|
36
|
+
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
37
|
+
const {
|
|
38
|
+
getYAxis
|
|
39
|
+
} = useCartesianChartContext();
|
|
40
|
+
const patternId = useId();
|
|
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]);
|
|
48
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
49
|
+
children: [gradient && /*#__PURE__*/_jsx("defs", {
|
|
50
|
+
children: /*#__PURE__*/_jsx(Gradient, {
|
|
51
|
+
animate: animate,
|
|
52
|
+
gradient: gradient,
|
|
53
|
+
id: patternId,
|
|
54
|
+
transition: transition,
|
|
55
|
+
yAxisId: yAxisId
|
|
56
|
+
})
|
|
57
|
+
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
58
|
+
animate: animate,
|
|
59
|
+
d: d,
|
|
60
|
+
fill: gradient ? "url(#".concat(patternId, ")") : fill,
|
|
61
|
+
fillOpacity: fillOpacity,
|
|
62
|
+
transition: transition
|
|
63
|
+
}, pathProps))]
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const _excluded = ["d", "fill", "fillOpacity", "yAxisId", "animate", "transition", "gradient"];
|
|
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 { Gradient } from '../gradient';
|
|
11
|
+
import { Path } from '../Path';
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
export const SolidArea = /*#__PURE__*/memo(_ref => {
|
|
19
|
+
let {
|
|
20
|
+
d,
|
|
21
|
+
fill = 'var(--color-fgPrimary)',
|
|
22
|
+
fillOpacity = 1,
|
|
23
|
+
yAxisId,
|
|
24
|
+
animate,
|
|
25
|
+
transition,
|
|
26
|
+
gradient
|
|
27
|
+
} = _ref,
|
|
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
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { accessoryFadeTransitionDuration } from '../utils';
|
|
2
|
+
export const axisLineStyles = "\n stroke: var(--color-fg);\n stroke-linecap: square;\n stroke-width: 1px;\n";
|
|
3
|
+
export const axisTickMarkStyles = "\n stroke: var(--color-fg);\n stroke-linecap: square;\n stroke-width: 1px;\n";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Animation variants for axis elements - updates (used for both grid lines and tick labels)
|
|
7
|
+
*/
|
|
8
|
+
export const axisUpdateAnimationVariants = {
|
|
9
|
+
initial: {
|
|
10
|
+
opacity: 0
|
|
11
|
+
},
|
|
12
|
+
animate: {
|
|
13
|
+
opacity: 1,
|
|
14
|
+
transition: {
|
|
15
|
+
duration: accessoryFadeTransitionDuration,
|
|
16
|
+
delay: accessoryFadeTransitionDuration
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
exit: {
|
|
20
|
+
opacity: 0,
|
|
21
|
+
transition: {
|
|
22
|
+
duration: accessoryFadeTransitionDuration
|
|
23
|
+
}
|
|
24
|
+
}
|
|
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
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
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
|
+
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 { 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';
|
|
21
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
const AXIS_HEIGHT = 32;
|
|
23
|
+
const LABEL_SIZE = 20;
|
|
24
|
+
const axisTickMarkCss = "cds-axisTickMarkCss-a6j4s2q";
|
|
25
|
+
const axisLineCss = "cds-axisLineCss-a12llxjj";
|
|
26
|
+
export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
27
|
+
let {
|
|
28
|
+
position = 'bottom',
|
|
29
|
+
showGrid,
|
|
30
|
+
requestedTickCount,
|
|
31
|
+
ticks,
|
|
32
|
+
tickLabelFormatter,
|
|
33
|
+
TickLabelComponent = DefaultAxisTickLabel,
|
|
34
|
+
style,
|
|
35
|
+
className,
|
|
36
|
+
styles,
|
|
37
|
+
classNames,
|
|
38
|
+
GridLineComponent = DottedLine,
|
|
39
|
+
LineComponent = SolidLine,
|
|
40
|
+
TickMarkLineComponent = SolidLine,
|
|
41
|
+
tickMarkLabelGap = 2,
|
|
42
|
+
minTickLabelGap = 4,
|
|
43
|
+
showTickMarks,
|
|
44
|
+
showLine,
|
|
45
|
+
tickMarkSize = 4,
|
|
46
|
+
tickInterval = 32,
|
|
47
|
+
tickMinStep = 1,
|
|
48
|
+
tickMaxStep,
|
|
49
|
+
label,
|
|
50
|
+
labelGap = 4,
|
|
51
|
+
height = label ? AXIS_HEIGHT + LABEL_SIZE : AXIS_HEIGHT,
|
|
52
|
+
testID = 'x-axis'
|
|
53
|
+
} = _ref,
|
|
54
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
55
|
+
const registrationId = useId();
|
|
56
|
+
const {
|
|
57
|
+
animate,
|
|
58
|
+
getXScale,
|
|
59
|
+
getXAxis,
|
|
60
|
+
registerAxis,
|
|
61
|
+
unregisterAxis,
|
|
62
|
+
getAxisBounds
|
|
63
|
+
} = useCartesianChartContext();
|
|
64
|
+
const xScale = getXScale();
|
|
65
|
+
const xAxis = getXAxis();
|
|
66
|
+
const axisBounds = getAxisBounds(registrationId);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
registerAxis(registrationId, position, height);
|
|
69
|
+
return () => unregisterAxis(registrationId);
|
|
70
|
+
}, [registrationId, registerAxis, unregisterAxis, position, height]);
|
|
71
|
+
const formatTick = useCallback(value => {
|
|
72
|
+
var _tickLabelFormatter;
|
|
73
|
+
// If we have string labels and no custom formatter, use the labels
|
|
74
|
+
const axisData = xAxis === null || xAxis === void 0 ? void 0 : xAxis.data;
|
|
75
|
+
const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
|
|
76
|
+
let finalValue = value;
|
|
77
|
+
|
|
78
|
+
// For band scales with string data, value is an index
|
|
79
|
+
if (hasStringLabels && typeof value === 'number' && axisData[value] !== undefined) {
|
|
80
|
+
finalValue = axisData[value];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Use the formatter (if provided) or the value itself
|
|
84
|
+
return (_tickLabelFormatter = tickLabelFormatter === null || tickLabelFormatter === void 0 ? void 0 : tickLabelFormatter(finalValue)) !== null && _tickLabelFormatter !== void 0 ? _tickLabelFormatter : finalValue;
|
|
85
|
+
}, [xAxis === null || xAxis === void 0 ? void 0 : xAxis.data, tickLabelFormatter]);
|
|
86
|
+
const ticksData = useMemo(() => {
|
|
87
|
+
if (!xScale) return [];
|
|
88
|
+
|
|
89
|
+
// Check if we have string labels
|
|
90
|
+
const axisData = xAxis === null || xAxis === void 0 ? void 0 : xAxis.data;
|
|
91
|
+
const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
|
|
92
|
+
|
|
93
|
+
// For band scales, we need categories
|
|
94
|
+
let categories;
|
|
95
|
+
if (hasStringLabels) {
|
|
96
|
+
categories = axisData;
|
|
97
|
+
} else if (isCategoricalScale(xScale)) {
|
|
98
|
+
// For band scales without explicit string data, generate numeric categories
|
|
99
|
+
// based on the domain of the scale
|
|
100
|
+
const domain = xScale.domain();
|
|
101
|
+
categories = domain.map(String);
|
|
102
|
+
}
|
|
103
|
+
let possibleTickValues;
|
|
104
|
+
|
|
105
|
+
// If we have discrete data, we can use the indices as possible tick values
|
|
106
|
+
if (axisData && Array.isArray(axisData) && (typeof axisData[0] === 'string' || typeof axisData[0] === 'number' && isCategoricalScale(xScale))) possibleTickValues = Array.from({
|
|
107
|
+
length: axisData.length
|
|
108
|
+
}, (_, i) => i);
|
|
109
|
+
return getAxisTicksData({
|
|
110
|
+
scaleFunction: xScale,
|
|
111
|
+
ticks,
|
|
112
|
+
requestedTickCount,
|
|
113
|
+
categories,
|
|
114
|
+
possibleTickValues: axisData && Array.isArray(axisData) && typeof axisData[0] === 'string' ? Array.from({
|
|
115
|
+
length: axisData.length
|
|
116
|
+
}, (_, i) => i) : undefined,
|
|
117
|
+
tickInterval: tickInterval,
|
|
118
|
+
options: {
|
|
119
|
+
minStep: tickMinStep,
|
|
120
|
+
maxStep: tickMaxStep
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}, [ticks, xScale, requestedTickCount, tickInterval, tickMinStep, tickMaxStep, xAxis === null || xAxis === void 0 ? void 0 : xAxis.data]);
|
|
124
|
+
const chartTextData = useMemo(() => {
|
|
125
|
+
if (!axisBounds) return null;
|
|
126
|
+
return ticksData.map(tick => {
|
|
127
|
+
const tickOffset = tickMarkLabelGap + (showTickMarks ? tickMarkSize : 0);
|
|
128
|
+
const availableSpace = AXIS_HEIGHT - tickOffset;
|
|
129
|
+
const labelOffset = availableSpace / 2;
|
|
130
|
+
const baseY = position === 'top' && label ? axisBounds.y + LABEL_SIZE : axisBounds.y;
|
|
131
|
+
const labelY = position === 'top' ? baseY + labelOffset - tickOffset : baseY + labelOffset + tickOffset;
|
|
132
|
+
return {
|
|
133
|
+
x: tick.position,
|
|
134
|
+
y: labelY,
|
|
135
|
+
label: formatTick(tick.tick),
|
|
136
|
+
chartTextProps: {
|
|
137
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.tickLabel,
|
|
138
|
+
color: 'var(--color-fgMuted)',
|
|
139
|
+
verticalAlignment: 'middle',
|
|
140
|
+
style: styles === null || styles === void 0 ? void 0 : styles.tickLabel,
|
|
141
|
+
horizontalAlignment: 'center'
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
});
|
|
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;
|
|
149
|
+
return /*#__PURE__*/_jsxs("g", _objectSpread(_objectSpread({
|
|
150
|
+
className: cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root),
|
|
151
|
+
"data-axis": "x",
|
|
152
|
+
"data-position": position,
|
|
153
|
+
style: _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root)
|
|
154
|
+
}, props), {}, {
|
|
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));
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
}), chartTextData && /*#__PURE__*/_jsx(ChartTextGroup, {
|
|
176
|
+
prioritizeEndLabels: true,
|
|
177
|
+
LabelComponent: TickLabelComponent,
|
|
178
|
+
labels: chartTextData,
|
|
179
|
+
minGap: minTickLabelGap
|
|
180
|
+
}), axisBounds && showTickMarks && /*#__PURE__*/_jsx("g", {
|
|
181
|
+
"data-testid": "".concat(testID, "-tick-marks"),
|
|
182
|
+
children: ticksData.map((tick, index) => {
|
|
183
|
+
const tickY = position === 'bottom' ? axisBounds.y : axisBounds.y + axisBounds.height;
|
|
184
|
+
const tickY2 = position === 'bottom' ? tickY + tickMarkSize : tickY - tickMarkSize;
|
|
185
|
+
return /*#__PURE__*/_jsx(TickMarkLineComponent, {
|
|
186
|
+
animate: false,
|
|
187
|
+
className: cx(axisTickMarkCss, classNames === null || classNames === void 0 ? void 0 : classNames.tickMark),
|
|
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
|
|
194
|
+
}, "tick-mark-".concat(tick.tick, "-").concat(index));
|
|
195
|
+
})
|
|
196
|
+
}), showLine && /*#__PURE__*/_jsx(LineComponent, {
|
|
197
|
+
animate: false,
|
|
198
|
+
className: cx(axisLineCss, classNames === null || classNames === void 0 ? void 0 : classNames.line),
|
|
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
|
|
216
|
+
})]
|
|
217
|
+
}));
|
|
218
|
+
});
|
|
219
|
+
import "./XAxis.css";
|