@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,132 @@
|
|
|
1
|
+
const _excluded = ["series", "showArea", "areaType", "type", "onPointClick", "LineComponent", "AreaComponent", "curve", "points", "strokeWidth", "strokeOpacity", "connectNulls", "transition", "opacity", "showXAxis", "showYAxis", "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"];
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
13
|
+
import { XAxis } from '../axis/XAxis';
|
|
14
|
+
import { YAxis } from '../axis/YAxis';
|
|
15
|
+
import { CartesianChart } from '../CartesianChart';
|
|
16
|
+
import { defaultChartInset, getChartInset } from '../utils';
|
|
17
|
+
import { Line } from './Line';
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
20
|
+
let {
|
|
21
|
+
series,
|
|
22
|
+
showArea,
|
|
23
|
+
areaType,
|
|
24
|
+
type,
|
|
25
|
+
onPointClick,
|
|
26
|
+
LineComponent,
|
|
27
|
+
AreaComponent,
|
|
28
|
+
curve,
|
|
29
|
+
points,
|
|
30
|
+
strokeWidth,
|
|
31
|
+
strokeOpacity,
|
|
32
|
+
connectNulls,
|
|
33
|
+
transition,
|
|
34
|
+
opacity,
|
|
35
|
+
showXAxis,
|
|
36
|
+
showYAxis,
|
|
37
|
+
xAxis,
|
|
38
|
+
yAxis,
|
|
39
|
+
inset,
|
|
40
|
+
children
|
|
41
|
+
} = _ref,
|
|
42
|
+
chartProps = _objectWithoutProperties(_ref, _excluded);
|
|
43
|
+
const calculatedInset = useMemo(() => getChartInset(inset, defaultChartInset), [inset]);
|
|
44
|
+
|
|
45
|
+
// Convert LineSeries to Series for Chart context
|
|
46
|
+
const chartSeries = useMemo(() => {
|
|
47
|
+
return series === null || series === void 0 ? void 0 : series.map(s => ({
|
|
48
|
+
id: s.id,
|
|
49
|
+
data: s.data,
|
|
50
|
+
label: s.label,
|
|
51
|
+
color: s.color,
|
|
52
|
+
yAxisId: s.yAxisId,
|
|
53
|
+
stackId: s.stackId,
|
|
54
|
+
gradient: s.gradient
|
|
55
|
+
}));
|
|
56
|
+
}, [series]);
|
|
57
|
+
|
|
58
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
59
|
+
const _ref2 = xAxis || {},
|
|
60
|
+
{
|
|
61
|
+
scaleType: xScaleType,
|
|
62
|
+
data: xData,
|
|
63
|
+
categoryPadding: xCategoryPadding,
|
|
64
|
+
domain: xDomain,
|
|
65
|
+
domainLimit: xDomainLimit,
|
|
66
|
+
range: xRange
|
|
67
|
+
} = _ref2,
|
|
68
|
+
xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
69
|
+
const _ref3 = yAxis || {},
|
|
70
|
+
{
|
|
71
|
+
scaleType: yScaleType,
|
|
72
|
+
data: yData,
|
|
73
|
+
categoryPadding: yCategoryPadding,
|
|
74
|
+
domain: yDomain,
|
|
75
|
+
domainLimit: yDomainLimit,
|
|
76
|
+
range: yRange,
|
|
77
|
+
id: yAxisId
|
|
78
|
+
} = _ref3,
|
|
79
|
+
yAxisVisualProps = _objectWithoutProperties(_ref3, _excluded3);
|
|
80
|
+
const xAxisConfig = {
|
|
81
|
+
scaleType: xScaleType,
|
|
82
|
+
data: xData,
|
|
83
|
+
categoryPadding: xCategoryPadding,
|
|
84
|
+
domain: xDomain,
|
|
85
|
+
domainLimit: xDomainLimit,
|
|
86
|
+
range: xRange
|
|
87
|
+
};
|
|
88
|
+
const yAxisConfig = {
|
|
89
|
+
scaleType: yScaleType,
|
|
90
|
+
data: yData,
|
|
91
|
+
categoryPadding: yCategoryPadding,
|
|
92
|
+
domain: yDomain,
|
|
93
|
+
domainLimit: yDomainLimit,
|
|
94
|
+
range: yRange
|
|
95
|
+
};
|
|
96
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
|
|
97
|
+
ref: ref,
|
|
98
|
+
inset: calculatedInset,
|
|
99
|
+
series: chartSeries,
|
|
100
|
+
xAxis: xAxisConfig,
|
|
101
|
+
yAxis: yAxisConfig,
|
|
102
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
|
|
103
|
+
axisId: yAxisId
|
|
104
|
+
}, yAxisVisualProps)), series === null || series === void 0 ? void 0 : series.map(_ref4 => {
|
|
105
|
+
var _linePropsFromSeries$;
|
|
106
|
+
let {
|
|
107
|
+
id,
|
|
108
|
+
data,
|
|
109
|
+
label,
|
|
110
|
+
color,
|
|
111
|
+
yAxisId
|
|
112
|
+
} = _ref4,
|
|
113
|
+
linePropsFromSeries = _objectWithoutProperties(_ref4, _excluded4);
|
|
114
|
+
return /*#__PURE__*/_jsx(Line, _objectSpread({
|
|
115
|
+
AreaComponent: AreaComponent,
|
|
116
|
+
LineComponent: LineComponent,
|
|
117
|
+
areaType: areaType,
|
|
118
|
+
connectNulls: connectNulls,
|
|
119
|
+
curve: curve,
|
|
120
|
+
onPointClick: onPointClick,
|
|
121
|
+
opacity: opacity,
|
|
122
|
+
points: points,
|
|
123
|
+
seriesId: id,
|
|
124
|
+
showArea: showArea,
|
|
125
|
+
strokeOpacity: strokeOpacity,
|
|
126
|
+
strokeWidth: strokeWidth,
|
|
127
|
+
transition: (_linePropsFromSeries$ = linePropsFromSeries.transition) !== null && _linePropsFromSeries$ !== void 0 ? _linePropsFromSeries$ : transition,
|
|
128
|
+
type: type
|
|
129
|
+
}, linePropsFromSeries), id);
|
|
130
|
+
}), children]
|
|
131
|
+
}));
|
|
132
|
+
}));
|
|
@@ -0,0 +1,140 @@
|
|
|
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 React, { memo } from 'react';
|
|
7
|
+
import { cx } from '@coinbase/cds-web';
|
|
8
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
9
|
+
import { getPointOnScale } from '../utils';
|
|
10
|
+
import { DefaultReferenceLineLabel } from './DefaultReferenceLineLabel';
|
|
11
|
+
import { DottedLine } from './DottedLine';
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
export const ReferenceLine = /*#__PURE__*/memo(_ref => {
|
|
14
|
+
let {
|
|
15
|
+
dataX,
|
|
16
|
+
dataY,
|
|
17
|
+
yAxisId,
|
|
18
|
+
label,
|
|
19
|
+
labelPosition = dataY !== undefined ? 'right' : 'top',
|
|
20
|
+
testID,
|
|
21
|
+
LineComponent = DottedLine,
|
|
22
|
+
LabelComponent = DefaultReferenceLineLabel,
|
|
23
|
+
labelElevated,
|
|
24
|
+
labelFont,
|
|
25
|
+
labelDx,
|
|
26
|
+
labelDy,
|
|
27
|
+
labelHorizontalAlignment,
|
|
28
|
+
labelVerticalAlignment,
|
|
29
|
+
labelBoundsInset,
|
|
30
|
+
stroke = 'var(--color-bgLine)',
|
|
31
|
+
opacity,
|
|
32
|
+
className,
|
|
33
|
+
style,
|
|
34
|
+
classNames,
|
|
35
|
+
styles
|
|
36
|
+
} = _ref;
|
|
37
|
+
const {
|
|
38
|
+
getXScale,
|
|
39
|
+
getYScale,
|
|
40
|
+
drawingArea
|
|
41
|
+
} = useCartesianChartContext();
|
|
42
|
+
|
|
43
|
+
// Combine root classNames
|
|
44
|
+
const rootClassName = cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root);
|
|
45
|
+
// Combine root styles
|
|
46
|
+
const rootStyle = _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root);
|
|
47
|
+
|
|
48
|
+
// Horizontal reference line logic
|
|
49
|
+
if (dataY !== undefined) {
|
|
50
|
+
const yScale = getYScale(yAxisId);
|
|
51
|
+
|
|
52
|
+
// Don't render if we don't have a scale
|
|
53
|
+
if (!yScale) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const yPixel = yScale(dataY);
|
|
57
|
+
if (yPixel === undefined) return null;
|
|
58
|
+
let labelX;
|
|
59
|
+
if (labelPosition === 'left') {
|
|
60
|
+
labelX = drawingArea.x;
|
|
61
|
+
} else if (labelPosition === 'center') {
|
|
62
|
+
labelX = drawingArea.x + drawingArea.width / 2;
|
|
63
|
+
} else {
|
|
64
|
+
labelX = drawingArea.x + drawingArea.width;
|
|
65
|
+
}
|
|
66
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
67
|
+
className: rootClassName,
|
|
68
|
+
"data-testid": testID,
|
|
69
|
+
style: rootStyle,
|
|
70
|
+
children: [/*#__PURE__*/_jsx(LineComponent, {
|
|
71
|
+
animate: false,
|
|
72
|
+
d: "M".concat(drawingArea.x, ",").concat(yPixel, " L").concat(drawingArea.x + drawingArea.width, ",").concat(yPixel),
|
|
73
|
+
stroke: stroke,
|
|
74
|
+
strokeOpacity: opacity
|
|
75
|
+
}), label && /*#__PURE__*/_jsx(LabelComponent, {
|
|
76
|
+
boundsInset: labelBoundsInset,
|
|
77
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.label,
|
|
78
|
+
dx: labelDx,
|
|
79
|
+
dy: labelDy,
|
|
80
|
+
elevated: labelElevated,
|
|
81
|
+
font: labelFont,
|
|
82
|
+
horizontalAlignment: labelHorizontalAlignment,
|
|
83
|
+
opacity: opacity,
|
|
84
|
+
style: styles === null || styles === void 0 ? void 0 : styles.label,
|
|
85
|
+
testID: testID,
|
|
86
|
+
verticalAlignment: labelVerticalAlignment !== null && labelVerticalAlignment !== void 0 ? labelVerticalAlignment : 'middle',
|
|
87
|
+
x: labelX,
|
|
88
|
+
y: yPixel,
|
|
89
|
+
children: label
|
|
90
|
+
})]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Vertical reference line logic
|
|
95
|
+
if (dataX !== undefined) {
|
|
96
|
+
const xScale = getXScale();
|
|
97
|
+
|
|
98
|
+
// Don't render if we don't have scales
|
|
99
|
+
if (!xScale) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const xPixel = getPointOnScale(dataX, xScale);
|
|
103
|
+
if (xPixel === undefined) return null;
|
|
104
|
+
let labelY;
|
|
105
|
+
if (labelPosition === 'top') {
|
|
106
|
+
labelY = drawingArea.y;
|
|
107
|
+
} else if (labelPosition === 'middle') {
|
|
108
|
+
labelY = drawingArea.y + drawingArea.height / 2;
|
|
109
|
+
} else {
|
|
110
|
+
labelY = drawingArea.y + drawingArea.height;
|
|
111
|
+
}
|
|
112
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
113
|
+
className: rootClassName,
|
|
114
|
+
"data-testid": testID,
|
|
115
|
+
style: rootStyle,
|
|
116
|
+
children: [/*#__PURE__*/_jsx(LineComponent, {
|
|
117
|
+
animate: false,
|
|
118
|
+
d: "M".concat(xPixel, ",").concat(drawingArea.y, " L").concat(xPixel, ",").concat(drawingArea.y + drawingArea.height),
|
|
119
|
+
stroke: stroke,
|
|
120
|
+
strokeOpacity: opacity
|
|
121
|
+
}), label && /*#__PURE__*/_jsx(LabelComponent, {
|
|
122
|
+
boundsInset: labelBoundsInset,
|
|
123
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.label,
|
|
124
|
+
dx: labelDx,
|
|
125
|
+
dy: labelDy,
|
|
126
|
+
elevated: labelElevated,
|
|
127
|
+
font: labelFont,
|
|
128
|
+
horizontalAlignment: labelHorizontalAlignment !== null && labelHorizontalAlignment !== void 0 ? labelHorizontalAlignment : 'center',
|
|
129
|
+
opacity: opacity,
|
|
130
|
+
style: styles === null || styles === void 0 ? void 0 : styles.label,
|
|
131
|
+
testID: testID,
|
|
132
|
+
verticalAlignment: labelVerticalAlignment,
|
|
133
|
+
x: xPixel,
|
|
134
|
+
y: labelY,
|
|
135
|
+
children: label
|
|
136
|
+
})]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "strokeLinecap", "strokeLinejoin", "strokeOpacity", "strokeWidth", "gradient", "yAxisId", "animate", "transition", "d"];
|
|
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 line component.
|
|
15
|
+
* Supports gradient for gradient effects and smooth data transitions.
|
|
16
|
+
*/
|
|
17
|
+
export const SolidLine = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
fill = 'none',
|
|
20
|
+
stroke = 'var(--color-fgPrimary)',
|
|
21
|
+
strokeLinecap = 'round',
|
|
22
|
+
strokeLinejoin = 'round',
|
|
23
|
+
strokeOpacity = 1,
|
|
24
|
+
strokeWidth = 2,
|
|
25
|
+
gradient,
|
|
26
|
+
yAxisId,
|
|
27
|
+
animate,
|
|
28
|
+
transition,
|
|
29
|
+
d
|
|
30
|
+
} = _ref,
|
|
31
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
32
|
+
const gradientId = useId();
|
|
33
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
34
|
+
children: [gradient && /*#__PURE__*/_jsx("defs", {
|
|
35
|
+
children: /*#__PURE__*/_jsx(Gradient, {
|
|
36
|
+
animate: animate,
|
|
37
|
+
gradient: gradient,
|
|
38
|
+
id: gradientId,
|
|
39
|
+
transition: transition,
|
|
40
|
+
yAxisId: yAxisId
|
|
41
|
+
})
|
|
42
|
+
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
43
|
+
animate: animate,
|
|
44
|
+
clipOffset: strokeWidth,
|
|
45
|
+
d: d,
|
|
46
|
+
fill: fill,
|
|
47
|
+
stroke: gradient ? "url(#".concat(gradientId, ")") : stroke,
|
|
48
|
+
strokeLinecap: strokeLinecap,
|
|
49
|
+
strokeLinejoin: strokeLinejoin,
|
|
50
|
+
strokeOpacity: strokeOpacity,
|
|
51
|
+
strokeWidth: strokeWidth,
|
|
52
|
+
transition: transition
|
|
53
|
+
}, props))]
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// codegen:start {preset: barrel, include: ./*.tsx, exclude: ./__stories__/*.tsx}
|
|
2
|
+
export * from './DefaultReferenceLineLabel';
|
|
3
|
+
export * from './DottedLine';
|
|
4
|
+
export * from './Line';
|
|
5
|
+
export * from './LineChart';
|
|
6
|
+
export * from './ReferenceLine';
|
|
7
|
+
export * from './SolidLine';
|
|
8
|
+
// codegen:end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const _excluded = ["x", "y", "position", "offset", "children"];
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
9
|
+
import { memo, useMemo } from 'react';
|
|
10
|
+
import { ChartText } from '../text';
|
|
11
|
+
import { getAlignmentFromPosition, getLabelCoordinates } from '../utils/point';
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* DefaultPointLabel is the default label component for point labels.
|
|
15
|
+
* It renders text at the specified position relative to the point.
|
|
16
|
+
*/
|
|
17
|
+
export const DefaultPointLabel = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
x,
|
|
20
|
+
y,
|
|
21
|
+
position = 'center',
|
|
22
|
+
offset,
|
|
23
|
+
children
|
|
24
|
+
} = _ref,
|
|
25
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
26
|
+
const {
|
|
27
|
+
horizontalAlignment,
|
|
28
|
+
verticalAlignment
|
|
29
|
+
} = useMemo(() => getAlignmentFromPosition(position), [position]);
|
|
30
|
+
const labelCoordinates = useMemo(() => {
|
|
31
|
+
if (offset === undefined) return {
|
|
32
|
+
x,
|
|
33
|
+
y
|
|
34
|
+
};
|
|
35
|
+
return getLabelCoordinates(x, y, position, offset);
|
|
36
|
+
}, [x, y, position, offset]);
|
|
37
|
+
return /*#__PURE__*/_jsx(ChartText, _objectSpread(_objectSpread({}, props), {}, {
|
|
38
|
+
horizontalAlignment: horizontalAlignment,
|
|
39
|
+
verticalAlignment: verticalAlignment,
|
|
40
|
+
x: labelCoordinates.x,
|
|
41
|
+
y: labelCoordinates.y,
|
|
42
|
+
children: children
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
const _excluded = ["dataX", "dataY", "yAxisId", "fill", "radius", "opacity", "onClick", "className", "style", "classNames", "styles", "stroke", "strokeWidth", "accessibilityLabel", "label", "LabelComponent", "labelPosition", "labelOffset", "labelFont", "testID", "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 React, { memo, 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 { projectPoint } from '../utils';
|
|
14
|
+
import { DefaultPointLabel } from './DefaultPointLabel';
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
const containerCss = "cds-containerCss-ckemp0e";
|
|
17
|
+
const innerPointCss = "cds-innerPointCss-ik8duli";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Props for point label components.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export const Point = /*#__PURE__*/memo(_ref => {
|
|
24
|
+
let {
|
|
25
|
+
dataX,
|
|
26
|
+
dataY,
|
|
27
|
+
yAxisId,
|
|
28
|
+
fill = 'var(--color-fgPrimary)',
|
|
29
|
+
radius = 5,
|
|
30
|
+
opacity,
|
|
31
|
+
onClick,
|
|
32
|
+
className,
|
|
33
|
+
style,
|
|
34
|
+
classNames,
|
|
35
|
+
styles,
|
|
36
|
+
stroke = 'var(--color-bg)',
|
|
37
|
+
strokeWidth = 2,
|
|
38
|
+
accessibilityLabel,
|
|
39
|
+
label,
|
|
40
|
+
LabelComponent = DefaultPointLabel,
|
|
41
|
+
labelPosition = 'center',
|
|
42
|
+
labelOffset = radius * 2,
|
|
43
|
+
labelFont,
|
|
44
|
+
testID,
|
|
45
|
+
animate: animateProp,
|
|
46
|
+
transition
|
|
47
|
+
} = _ref,
|
|
48
|
+
svgProps = _objectWithoutProperties(_ref, _excluded);
|
|
49
|
+
const {
|
|
50
|
+
getXScale,
|
|
51
|
+
getYScale,
|
|
52
|
+
animate: animationEnabled,
|
|
53
|
+
drawingArea
|
|
54
|
+
} = useCartesianChartContext();
|
|
55
|
+
const animate = animateProp !== null && animateProp !== void 0 ? animateProp : animationEnabled;
|
|
56
|
+
const xScale = getXScale();
|
|
57
|
+
const yScale = getYScale(yAxisId);
|
|
58
|
+
const pixelCoordinate = useMemo(() => {
|
|
59
|
+
if (!xScale || !yScale) {
|
|
60
|
+
return {
|
|
61
|
+
x: 0,
|
|
62
|
+
y: 0
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return projectPoint({
|
|
66
|
+
x: dataX,
|
|
67
|
+
y: dataY,
|
|
68
|
+
xScale,
|
|
69
|
+
yScale
|
|
70
|
+
});
|
|
71
|
+
}, [xScale, yScale, dataX, dataY]);
|
|
72
|
+
const isWithinDrawingArea = useMemo(() => {
|
|
73
|
+
if (!pixelCoordinate) return false;
|
|
74
|
+
return pixelCoordinate.x >= drawingArea.x && pixelCoordinate.x <= drawingArea.x + drawingArea.width && pixelCoordinate.y >= drawingArea.y && pixelCoordinate.y <= drawingArea.y + drawingArea.height;
|
|
75
|
+
}, [pixelCoordinate, drawingArea]);
|
|
76
|
+
const innerPoint = useMemo(() => {
|
|
77
|
+
const mergedStyles = _objectSpread(_objectSpread({
|
|
78
|
+
cursor: onClick !== undefined ? 'pointer' : undefined
|
|
79
|
+
}, style), styles === null || styles === void 0 ? void 0 : styles.point);
|
|
80
|
+
|
|
81
|
+
// interaction animations to scale radius of point
|
|
82
|
+
const variants = {
|
|
83
|
+
hovered: {
|
|
84
|
+
r: radius * 1.2
|
|
85
|
+
},
|
|
86
|
+
pressed: {
|
|
87
|
+
r: radius * 0.9
|
|
88
|
+
},
|
|
89
|
+
default: {
|
|
90
|
+
r: radius
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const handleKeyDown = onClick ? event => {
|
|
94
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
onClick(event, {
|
|
97
|
+
dataX,
|
|
98
|
+
dataY,
|
|
99
|
+
x: pixelCoordinate.x,
|
|
100
|
+
y: pixelCoordinate.y
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
} : undefined;
|
|
104
|
+
if (!animate) {
|
|
105
|
+
return /*#__PURE__*/_jsx("circle", _objectSpread({
|
|
106
|
+
"aria-label": accessibilityLabel,
|
|
107
|
+
className: cx(innerPointCss, className, classNames === null || classNames === void 0 ? void 0 : classNames.point),
|
|
108
|
+
cx: pixelCoordinate.x,
|
|
109
|
+
cy: pixelCoordinate.y,
|
|
110
|
+
fill: fill,
|
|
111
|
+
onClick: onClick ? event => onClick(event, {
|
|
112
|
+
dataX,
|
|
113
|
+
dataY,
|
|
114
|
+
x: pixelCoordinate.x,
|
|
115
|
+
y: pixelCoordinate.y
|
|
116
|
+
}) : undefined,
|
|
117
|
+
onKeyDown: handleKeyDown,
|
|
118
|
+
r: radius,
|
|
119
|
+
role: onClick ? 'button' : undefined,
|
|
120
|
+
stroke: stroke,
|
|
121
|
+
strokeWidth: strokeWidth,
|
|
122
|
+
style: mergedStyles,
|
|
123
|
+
tabIndex: onClick ? 0 : -1
|
|
124
|
+
}, svgProps));
|
|
125
|
+
}
|
|
126
|
+
return /*#__PURE__*/_jsx(motion.circle, _objectSpread({
|
|
127
|
+
animate: {
|
|
128
|
+
cx: pixelCoordinate.x,
|
|
129
|
+
cy: pixelCoordinate.y
|
|
130
|
+
},
|
|
131
|
+
"aria-label": accessibilityLabel,
|
|
132
|
+
className: cx(innerPointCss, className, classNames === null || classNames === void 0 ? void 0 : classNames.point),
|
|
133
|
+
cx: pixelCoordinate.x,
|
|
134
|
+
cy: pixelCoordinate.y,
|
|
135
|
+
fill: fill,
|
|
136
|
+
initial: false,
|
|
137
|
+
onClick: onClick ? event => onClick(event, {
|
|
138
|
+
dataX,
|
|
139
|
+
dataY,
|
|
140
|
+
x: pixelCoordinate.x,
|
|
141
|
+
y: pixelCoordinate.y
|
|
142
|
+
}) : undefined,
|
|
143
|
+
onKeyDown: handleKeyDown,
|
|
144
|
+
r: radius,
|
|
145
|
+
role: onClick ? 'button' : undefined,
|
|
146
|
+
stroke: stroke,
|
|
147
|
+
strokeWidth: strokeWidth,
|
|
148
|
+
style: mergedStyles,
|
|
149
|
+
tabIndex: onClick ? 0 : -1,
|
|
150
|
+
transition: transition,
|
|
151
|
+
variants: variants,
|
|
152
|
+
whileHover: onClick ? 'hovered' : 'default',
|
|
153
|
+
whileTap: onClick ? 'pressed' : 'default'
|
|
154
|
+
}, svgProps));
|
|
155
|
+
}, [style, styles === null || styles === void 0 ? void 0 : styles.point, classNames === null || classNames === void 0 ? void 0 : classNames.point, fill, animate, radius, className, onClick, stroke, strokeWidth, svgProps, dataX, dataY, pixelCoordinate.x, pixelCoordinate.y, accessibilityLabel, transition]);
|
|
156
|
+
if (!xScale || !yScale) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
160
|
+
opacity: isWithinDrawingArea ? 1 : 0,
|
|
161
|
+
children: [/*#__PURE__*/_jsx("g", {
|
|
162
|
+
className: cx(containerCss, classNames === null || classNames === void 0 ? void 0 : classNames.root),
|
|
163
|
+
"data-testid": testID,
|
|
164
|
+
opacity: opacity,
|
|
165
|
+
style: styles === null || styles === void 0 ? void 0 : styles.root,
|
|
166
|
+
children: innerPoint
|
|
167
|
+
}), label && /*#__PURE__*/_jsx(LabelComponent, {
|
|
168
|
+
dataX: dataX,
|
|
169
|
+
dataY: dataY,
|
|
170
|
+
fill: fill,
|
|
171
|
+
font: labelFont,
|
|
172
|
+
offset: labelOffset,
|
|
173
|
+
position: labelPosition,
|
|
174
|
+
x: pixelCoordinate.x,
|
|
175
|
+
y: pixelCoordinate.y,
|
|
176
|
+
children: label
|
|
177
|
+
})]
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
import "./Point.css";
|