@coinbase/cds-web-visualization 0.0.0 → 3.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +3 -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 +3 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/sparkline/Counter.d.ts +8 -0
- package/dts/sparkline/Counter.d.ts.map +1 -0
- package/dts/sparkline/Sparkline.d.ts +67 -0
- package/dts/sparkline/Sparkline.d.ts.map +1 -0
- package/dts/sparkline/SparklineArea.d.ts +15 -0
- package/dts/sparkline/SparklineArea.d.ts.map +1 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts +14 -0
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -0
- package/dts/sparkline/SparklineGradient.d.ts +23 -0
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -0
- package/dts/sparkline/SparklinePath.d.ts +12 -0
- package/dts/sparkline/SparklinePath.d.ts.map +1 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +2 -0
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +1 -0
- package/dts/sparkline/generateSparklineWithId.d.ts +11 -0
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -0
- package/dts/sparkline/index.d.ts +6 -0
- package/dts/sparkline/index.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +199 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +26 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +5 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +8 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +17 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +25 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +30 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +18 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +31 -0
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts +3 -0
- package/dts/sparkline/sparkline-interactive/fade.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +13 -0
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +112 -0
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +1 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +2 -0
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +1 -0
- 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 -0
- package/esm/sparkline/Counter.css +3 -0
- package/esm/sparkline/Counter.js +35 -0
- package/esm/sparkline/Sparkline.js +164 -0
- package/esm/sparkline/SparklineArea.js +18 -0
- package/esm/sparkline/SparklineAreaPattern.js +37 -0
- package/esm/sparkline/SparklineGradient.js +30 -0
- package/esm/sparkline/SparklinePath.js +19 -0
- package/esm/sparkline/__figma__/Sparkline.figma.js +24 -0
- package/esm/sparkline/generateSparklineWithId.js +7 -0
- package/esm/sparkline/index.js +5 -0
- package/esm/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.js +21 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +317 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +108 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +26 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.css +2 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.js +24 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.css +4 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +65 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.css +1 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +80 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +56 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +70 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +45 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.css +5 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.js +199 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.js +39 -0
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +92 -0
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +89 -0
- package/esm/sparkline/sparkline-interactive/fade.css +2 -0
- package/esm/sparkline/sparkline-interactive/fade.js +14 -0
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +28 -0
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +225 -0
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +108 -0
- package/package.json +68 -6
- package/index.js +0 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
const _excluded = ["dataX", "dataY", "yAxisId", "fill", "radius", "opacity", "onClick", "onScrubberEnter", "className", "style", "classNames", "styles", "stroke", "strokeWidth", "accessibilityLabel", "label", "labelProps", "testID", "pixelCoordinates", "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 React, { memo, useEffect, useMemo } from 'react';
|
|
10
|
+
import { cx } from '@coinbase/cds-web';
|
|
11
|
+
import { m as motion } from 'framer-motion';
|
|
12
|
+
import { useCartesianChartContext } from './ChartProvider';
|
|
13
|
+
import { ChartText } from './text';
|
|
14
|
+
import { projectPoint, useScrubberContext } from './utils';
|
|
15
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
const containerCss = "cds-containerCss-c137x6qr";
|
|
17
|
+
const innerPointCss = "cds-innerPointCss-i1qyub1f";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Parameters passed to renderPoints callback function.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Shared configuration for point appearance and behavior.
|
|
25
|
+
* Used by line-associated points rendered via Line/LineChart components.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export const Point = /*#__PURE__*/memo(_ref => {
|
|
29
|
+
let {
|
|
30
|
+
dataX,
|
|
31
|
+
dataY,
|
|
32
|
+
yAxisId,
|
|
33
|
+
fill = 'var(--color-fgPrimary)',
|
|
34
|
+
radius = 4,
|
|
35
|
+
opacity,
|
|
36
|
+
onClick,
|
|
37
|
+
onScrubberEnter,
|
|
38
|
+
className,
|
|
39
|
+
style,
|
|
40
|
+
classNames,
|
|
41
|
+
styles,
|
|
42
|
+
stroke = 'var(--color-bg)',
|
|
43
|
+
strokeWidth = 2,
|
|
44
|
+
accessibilityLabel,
|
|
45
|
+
label,
|
|
46
|
+
labelProps,
|
|
47
|
+
testID,
|
|
48
|
+
pixelCoordinates,
|
|
49
|
+
animate
|
|
50
|
+
} = _ref,
|
|
51
|
+
svgProps = _objectWithoutProperties(_ref, _excluded);
|
|
52
|
+
const {
|
|
53
|
+
getXScale,
|
|
54
|
+
getYScale,
|
|
55
|
+
animate: animationEnabled
|
|
56
|
+
} = useCartesianChartContext();
|
|
57
|
+
const {
|
|
58
|
+
scrubberPosition
|
|
59
|
+
} = useScrubberContext();
|
|
60
|
+
const xScale = getXScale();
|
|
61
|
+
const yScale = getYScale(yAxisId);
|
|
62
|
+
const isScrubberHighlighted = scrubberPosition !== undefined && scrubberPosition === dataX;
|
|
63
|
+
const pixelCoordinate = useMemo(() => {
|
|
64
|
+
if (pixelCoordinates) {
|
|
65
|
+
return pixelCoordinates;
|
|
66
|
+
}
|
|
67
|
+
if (!xScale || !yScale) {
|
|
68
|
+
return {
|
|
69
|
+
x: 0,
|
|
70
|
+
y: 0
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return projectPoint({
|
|
74
|
+
x: dataX,
|
|
75
|
+
y: dataY,
|
|
76
|
+
xScale,
|
|
77
|
+
yScale
|
|
78
|
+
});
|
|
79
|
+
}, [xScale, yScale, dataX, dataY, pixelCoordinates]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (isScrubberHighlighted && onScrubberEnter) {
|
|
82
|
+
onScrubberEnter({
|
|
83
|
+
x: pixelCoordinate.x,
|
|
84
|
+
y: pixelCoordinate.y
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}, [isScrubberHighlighted, onScrubberEnter, pixelCoordinate.x, pixelCoordinate.y]);
|
|
88
|
+
const innerPoint = useMemo(() => {
|
|
89
|
+
const mergedStyles = _objectSpread(_objectSpread({
|
|
90
|
+
cursor: onClick !== undefined ? 'pointer' : undefined
|
|
91
|
+
}, style), styles === null || styles === void 0 ? void 0 : styles.point);
|
|
92
|
+
|
|
93
|
+
// interaction animations to scale radius of point
|
|
94
|
+
const variants = {
|
|
95
|
+
hovered: {
|
|
96
|
+
r: radius * 1.2
|
|
97
|
+
},
|
|
98
|
+
pressed: {
|
|
99
|
+
r: radius * 0.9
|
|
100
|
+
},
|
|
101
|
+
default: {
|
|
102
|
+
r: radius
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const handleKeyDown = onClick ? event => {
|
|
106
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
onClick(event, {
|
|
109
|
+
dataX,
|
|
110
|
+
dataY,
|
|
111
|
+
x: pixelCoordinate.x,
|
|
112
|
+
y: pixelCoordinate.y
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
} : undefined;
|
|
116
|
+
|
|
117
|
+
// Use the animate prop if provided, otherwise fall back to chart context
|
|
118
|
+
const shouldAnimateInteractions = animate !== null && animate !== void 0 ? animate : animationEnabled;
|
|
119
|
+
const shouldAnimatePosition = animate !== null && animate !== void 0 ? animate : animationEnabled;
|
|
120
|
+
return /*#__PURE__*/_jsx(motion.circle, _objectSpread({
|
|
121
|
+
animate: shouldAnimatePosition ? {
|
|
122
|
+
cx: pixelCoordinate.x,
|
|
123
|
+
cy: pixelCoordinate.y
|
|
124
|
+
} : undefined,
|
|
125
|
+
"aria-label": accessibilityLabel,
|
|
126
|
+
className: cx(innerPointCss, className, classNames === null || classNames === void 0 ? void 0 : classNames.point),
|
|
127
|
+
cx: pixelCoordinate.x,
|
|
128
|
+
cy: pixelCoordinate.y,
|
|
129
|
+
fill: fill,
|
|
130
|
+
initial: false,
|
|
131
|
+
onClick: onClick ? event => onClick(event, {
|
|
132
|
+
dataX,
|
|
133
|
+
dataY,
|
|
134
|
+
x: pixelCoordinate.x,
|
|
135
|
+
y: pixelCoordinate.y
|
|
136
|
+
}) : undefined,
|
|
137
|
+
onKeyDown: handleKeyDown,
|
|
138
|
+
r: radius,
|
|
139
|
+
role: onClick ? 'button' : undefined,
|
|
140
|
+
stroke: stroke,
|
|
141
|
+
strokeWidth: strokeWidth,
|
|
142
|
+
style: mergedStyles,
|
|
143
|
+
tabIndex: onClick ? 0 : -1,
|
|
144
|
+
transition: {
|
|
145
|
+
duration: 0.3,
|
|
146
|
+
ease: 'easeInOut'
|
|
147
|
+
},
|
|
148
|
+
variants: variants,
|
|
149
|
+
whileHover: shouldAnimateInteractions && onClick ? 'hovered' : 'default',
|
|
150
|
+
whileTap: shouldAnimateInteractions && onClick ? 'pressed' : 'default'
|
|
151
|
+
}, svgProps));
|
|
152
|
+
}, [style, styles === null || styles === void 0 ? void 0 : styles.point, classNames === null || classNames === void 0 ? void 0 : classNames.point, fill, animate, animationEnabled, radius, className, onClick, stroke, strokeWidth, svgProps, dataX, dataY, pixelCoordinate.x, pixelCoordinate.y, accessibilityLabel]);
|
|
153
|
+
if (!xScale || !yScale) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
157
|
+
children: [/*#__PURE__*/_jsx("g", {
|
|
158
|
+
className: cx(containerCss, classNames === null || classNames === void 0 ? void 0 : classNames.container),
|
|
159
|
+
"data-testid": testID,
|
|
160
|
+
opacity: opacity,
|
|
161
|
+
style: styles === null || styles === void 0 ? void 0 : styles.container,
|
|
162
|
+
children: innerPoint
|
|
163
|
+
}), label && /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({
|
|
164
|
+
x: pixelCoordinate.x,
|
|
165
|
+
y: pixelCoordinate.y
|
|
166
|
+
}, labelProps), {}, {
|
|
167
|
+
children: label
|
|
168
|
+
}))]
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
import "./Point.css";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React, { memo, useMemo } from 'react';
|
|
2
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
3
|
+
import { getAreaPath } from '../utils';
|
|
4
|
+
import { DottedArea } from './DottedArea';
|
|
5
|
+
import { GradientArea } from './GradientArea';
|
|
6
|
+
import { SolidArea } from './SolidArea';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export const Area = /*#__PURE__*/memo(_ref => {
|
|
9
|
+
var _ref2;
|
|
10
|
+
let {
|
|
11
|
+
seriesId,
|
|
12
|
+
curve = 'linear',
|
|
13
|
+
type = 'solid',
|
|
14
|
+
AreaComponent: SelectedAreaComponent,
|
|
15
|
+
fill: specifiedFill,
|
|
16
|
+
fillOpacity = 1,
|
|
17
|
+
stroke,
|
|
18
|
+
strokeWidth,
|
|
19
|
+
baseline
|
|
20
|
+
} = _ref;
|
|
21
|
+
const {
|
|
22
|
+
getSeries,
|
|
23
|
+
getSeriesData,
|
|
24
|
+
getXScale,
|
|
25
|
+
getYScale,
|
|
26
|
+
getXAxis
|
|
27
|
+
} = useCartesianChartContext();
|
|
28
|
+
|
|
29
|
+
// Get sourceData from series (using stacked data if available)
|
|
30
|
+
const matchedSeries = useMemo(() => getSeries(seriesId), [seriesId, getSeries]);
|
|
31
|
+
|
|
32
|
+
// Check for stacked data first, then fall back to raw data
|
|
33
|
+
const sourceData = useMemo(() => {
|
|
34
|
+
const stackedData = getSeriesData(seriesId);
|
|
35
|
+
if (stackedData) {
|
|
36
|
+
return stackedData;
|
|
37
|
+
}
|
|
38
|
+
return getSeriesData(seriesId) || null;
|
|
39
|
+
}, [seriesId, getSeriesData]);
|
|
40
|
+
|
|
41
|
+
// Get scales and axes for this series
|
|
42
|
+
const xAxis = getXAxis();
|
|
43
|
+
const xScale = getXScale();
|
|
44
|
+
const yScale = getYScale(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId);
|
|
45
|
+
const area = useMemo(() => {
|
|
46
|
+
if (!sourceData || sourceData.length === 0 || !xScale || !yScale) return '';
|
|
47
|
+
|
|
48
|
+
// Get numeric x-axis data if available
|
|
49
|
+
const xData = xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
50
|
+
return getAreaPath({
|
|
51
|
+
data: sourceData,
|
|
52
|
+
xScale,
|
|
53
|
+
yScale,
|
|
54
|
+
curve,
|
|
55
|
+
xData
|
|
56
|
+
});
|
|
57
|
+
}, [sourceData, xScale, yScale, curve, xAxis === null || xAxis === void 0 ? void 0 : xAxis.data]);
|
|
58
|
+
const AreaComponent = useMemo(() => {
|
|
59
|
+
if (SelectedAreaComponent) {
|
|
60
|
+
return SelectedAreaComponent;
|
|
61
|
+
}
|
|
62
|
+
switch (type) {
|
|
63
|
+
case 'solid':
|
|
64
|
+
return SolidArea;
|
|
65
|
+
case 'dotted':
|
|
66
|
+
return DottedArea;
|
|
67
|
+
case 'gradient':
|
|
68
|
+
default:
|
|
69
|
+
return GradientArea;
|
|
70
|
+
}
|
|
71
|
+
}, [SelectedAreaComponent, type]);
|
|
72
|
+
if (!xScale || !yScale || !sourceData || !area) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const fill = (_ref2 = specifiedFill !== null && specifiedFill !== void 0 ? specifiedFill : matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.color) !== null && _ref2 !== void 0 ? _ref2 : 'var(--color-fgPrimary)';
|
|
76
|
+
return /*#__PURE__*/_jsx(AreaComponent, {
|
|
77
|
+
baseline: baseline,
|
|
78
|
+
d: area,
|
|
79
|
+
fill: fill,
|
|
80
|
+
fillOpacity: fillOpacity,
|
|
81
|
+
stroke: stroke,
|
|
82
|
+
strokeWidth: strokeWidth,
|
|
83
|
+
yAxisId: matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const _excluded = ["series", "stacked", "AreaComponent", "curve", "fillOpacity", "type", "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"],
|
|
5
|
+
_excluded5 = ["id", "data", "label", "color", "yAxisId", "fill", "fillOpacity", "stackId"];
|
|
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
|
+
LineComponent,
|
|
29
|
+
strokeWidth,
|
|
30
|
+
showXAxis,
|
|
31
|
+
showYAxis,
|
|
32
|
+
showLines,
|
|
33
|
+
lineType = 'solid',
|
|
34
|
+
xAxis,
|
|
35
|
+
yAxis,
|
|
36
|
+
inset: userInset,
|
|
37
|
+
children
|
|
38
|
+
} = _ref,
|
|
39
|
+
chartProps = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
+
const calculatedInset = useMemo(() => getChartInset(userInset, defaultChartInset), [userInset]);
|
|
41
|
+
|
|
42
|
+
// Convert AreaSeries to Series for Chart context
|
|
43
|
+
const chartSeries = useMemo(() => {
|
|
44
|
+
return series === null || series === void 0 ? void 0 : series.map(s => ({
|
|
45
|
+
id: s.id,
|
|
46
|
+
data: s.data,
|
|
47
|
+
label: s.label,
|
|
48
|
+
color: s.color,
|
|
49
|
+
yAxisId: s.yAxisId,
|
|
50
|
+
stackId: s.stackId
|
|
51
|
+
}));
|
|
52
|
+
}, [series]);
|
|
53
|
+
const transformedSeries = useMemo(() => {
|
|
54
|
+
if (!stacked || !chartSeries) return chartSeries;
|
|
55
|
+
return chartSeries.map(s => {
|
|
56
|
+
var _s$stackId;
|
|
57
|
+
return _objectSpread(_objectSpread({}, s), {}, {
|
|
58
|
+
stackId: (_s$stackId = s.stackId) !== null && _s$stackId !== void 0 ? _s$stackId : defaultStackId
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}, [chartSeries, stacked]);
|
|
62
|
+
const seriesToRender = transformedSeries !== null && transformedSeries !== void 0 ? transformedSeries : chartSeries;
|
|
63
|
+
|
|
64
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
65
|
+
const _ref2 = xAxis || {},
|
|
66
|
+
{
|
|
67
|
+
scaleType: xScaleType,
|
|
68
|
+
data: xData,
|
|
69
|
+
categoryPadding: xCategoryPadding,
|
|
70
|
+
domain: xDomain,
|
|
71
|
+
domainLimit: xDomainLimit,
|
|
72
|
+
range: xRange
|
|
73
|
+
} = _ref2,
|
|
74
|
+
xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
75
|
+
const _ref3 = yAxis || {},
|
|
76
|
+
{
|
|
77
|
+
scaleType: yScaleType,
|
|
78
|
+
data: yData,
|
|
79
|
+
categoryPadding: yCategoryPadding,
|
|
80
|
+
domain: yDomain,
|
|
81
|
+
domainLimit: yDomainLimit,
|
|
82
|
+
range: yRange,
|
|
83
|
+
id: yAxisId
|
|
84
|
+
} = _ref3,
|
|
85
|
+
yAxisVisualProps = _objectWithoutProperties(_ref3, _excluded3);
|
|
86
|
+
const xAxisConfig = {
|
|
87
|
+
scaleType: xScaleType,
|
|
88
|
+
data: xData,
|
|
89
|
+
categoryPadding: xCategoryPadding,
|
|
90
|
+
domain: xDomain,
|
|
91
|
+
domainLimit: xDomainLimit,
|
|
92
|
+
range: xRange
|
|
93
|
+
};
|
|
94
|
+
const hasNegativeValues = useMemo(() => {
|
|
95
|
+
if (!series) return false;
|
|
96
|
+
return series.some(s => {
|
|
97
|
+
var _s$data;
|
|
98
|
+
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));
|
|
99
|
+
});
|
|
100
|
+
}, [series]);
|
|
101
|
+
|
|
102
|
+
// Set default min domain to 0 for area chart, but only if there are no negative values
|
|
103
|
+
const yAxisConfig = {
|
|
104
|
+
scaleType: yScaleType,
|
|
105
|
+
data: yData,
|
|
106
|
+
categoryPadding: yCategoryPadding,
|
|
107
|
+
domain: hasNegativeValues ? yDomain : _objectSpread({
|
|
108
|
+
min: 0
|
|
109
|
+
}, yDomain),
|
|
110
|
+
domainLimit: yDomainLimit,
|
|
111
|
+
range: yRange
|
|
112
|
+
};
|
|
113
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
|
|
114
|
+
ref: ref,
|
|
115
|
+
inset: calculatedInset,
|
|
116
|
+
series: seriesToRender,
|
|
117
|
+
xAxis: xAxisConfig,
|
|
118
|
+
yAxis: yAxisConfig,
|
|
119
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
|
|
120
|
+
axisId: yAxisId
|
|
121
|
+
}, yAxisVisualProps)), series === null || series === void 0 ? void 0 : series.map(_ref4 => {
|
|
122
|
+
let {
|
|
123
|
+
id,
|
|
124
|
+
data,
|
|
125
|
+
label,
|
|
126
|
+
color,
|
|
127
|
+
yAxisId,
|
|
128
|
+
opacity,
|
|
129
|
+
LineComponent,
|
|
130
|
+
stackId
|
|
131
|
+
} = _ref4,
|
|
132
|
+
areaPropsFromSeries = _objectWithoutProperties(_ref4, _excluded4);
|
|
133
|
+
return /*#__PURE__*/_jsx(Area, _objectSpread({
|
|
134
|
+
AreaComponent: AreaComponent,
|
|
135
|
+
curve: curve,
|
|
136
|
+
fillOpacity: fillOpacity,
|
|
137
|
+
seriesId: id,
|
|
138
|
+
type: type
|
|
139
|
+
}, areaPropsFromSeries), id);
|
|
140
|
+
}), showLines && (series === null || series === void 0 ? void 0 : series.map(_ref5 => {
|
|
141
|
+
let {
|
|
142
|
+
id,
|
|
143
|
+
data,
|
|
144
|
+
label,
|
|
145
|
+
color,
|
|
146
|
+
yAxisId,
|
|
147
|
+
fill,
|
|
148
|
+
fillOpacity,
|
|
149
|
+
stackId
|
|
150
|
+
} = _ref5,
|
|
151
|
+
linePropsFromSeries = _objectWithoutProperties(_ref5, _excluded5);
|
|
152
|
+
return /*#__PURE__*/_jsx(Line, _objectSpread({
|
|
153
|
+
LineComponent: LineComponent,
|
|
154
|
+
curve: curve,
|
|
155
|
+
seriesId: id // Line component now handles stacked data automatically
|
|
156
|
+
,
|
|
157
|
+
stroke: color // Default to series color
|
|
158
|
+
,
|
|
159
|
+
strokeWidth: strokeWidth,
|
|
160
|
+
type: lineType
|
|
161
|
+
}, linePropsFromSeries), "".concat(id, "-line"));
|
|
162
|
+
})), children]
|
|
163
|
+
}));
|
|
164
|
+
}));
|
|
@@ -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
|
+
});
|