@mui/x-charts 7.0.0-alpha.9 → 7.0.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/BarChart/BarChart.d.ts +2 -1
- package/BarChart/BarChart.js +24 -23
- package/BarChart/BarElement.d.ts +1 -1
- package/BarChart/BarElement.js +6 -3
- package/BarChart/BarPlot.d.ts +8 -1
- package/BarChart/BarPlot.js +19 -5
- package/BarChart/formatter.js +1 -1
- package/CHANGELOG.md +386 -38
- package/ChartContainer/ChartContainer.d.ts +12 -0
- package/ChartContainer/ChartContainer.js +197 -0
- package/ChartContainer/index.d.ts +1 -11
- package/ChartContainer/index.js +9 -63
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
- package/ChartsOnAxisClickHandler/index.d.ts +1 -0
- package/ChartsOnAxisClickHandler/index.js +16 -0
- package/ChartsOnAxisClickHandler/package.json +6 -0
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
- package/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -58
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
- package/ChartsTooltip/utils.d.ts +3 -1
- package/ChartsTooltip/utils.js +8 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/LineChart/AnimatedArea.d.ts +1361 -0
- package/LineChart/AnimatedArea.js +111 -0
- package/LineChart/AnimatedLine.d.ts +1361 -0
- package/LineChart/AnimatedLine.js +113 -0
- package/LineChart/AreaElement.d.ts +17 -17
- package/LineChart/AreaElement.js +17 -34
- package/LineChart/AreaPlot.d.ts +12 -7
- package/LineChart/AreaPlot.js +91 -58
- package/LineChart/LineChart.d.ts +13 -4
- package/LineChart/LineChart.js +36 -29
- package/LineChart/LineElement.d.ts +17 -17
- package/LineChart/LineElement.js +16 -36
- package/LineChart/LineHighlightElement.js +3 -2
- package/LineChart/LinePlot.d.ts +12 -7
- package/LineChart/LinePlot.js +89 -56
- package/LineChart/MarkElement.d.ts +5 -2
- package/LineChart/MarkElement.js +26 -13
- package/LineChart/MarkPlot.d.ts +8 -1
- package/LineChart/MarkPlot.js +80 -51
- package/LineChart/formatter.js +1 -1
- package/LineChart/index.d.ts +2 -0
- package/LineChart/index.js +22 -0
- package/PieChart/PieArcLabelPlot.d.ts +1 -1
- package/PieChart/PieArcLabelPlot.js +1 -1
- package/PieChart/PieArcPlot.d.ts +2 -2
- package/PieChart/PieArcPlot.js +6 -6
- package/PieChart/PieChart.d.ts +1 -1
- package/PieChart/PieChart.js +5 -50
- package/PieChart/PiePlot.d.ts +1 -1
- package/PieChart/PiePlot.js +4 -4
- package/README.md +2 -2
- package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +16 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +250 -0
- package/ResponsiveChartContainer/index.d.ts +1 -15
- package/ResponsiveChartContainer/index.js +8 -113
- package/ScatterChart/Scatter.d.ts +7 -1
- package/ScatterChart/Scatter.js +18 -23
- package/ScatterChart/ScatterChart.d.ts +8 -2
- package/ScatterChart/ScatterChart.js +12 -22
- package/ScatterChart/ScatterPlot.d.ts +1 -1
- package/ScatterChart/ScatterPlot.js +10 -2
- package/SparkLineChart/SparkLineChart.js +2 -0
- package/context/DrawingProvider.d.ts +6 -1
- package/context/DrawingProvider.js +9 -2
- package/context/InteractionProvider.d.ts +3 -3
- package/esm/BarChart/BarChart.js +24 -23
- package/esm/BarChart/BarElement.js +6 -3
- package/esm/BarChart/BarPlot.js +19 -5
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartContainer/ChartContainer.js +189 -0
- package/esm/ChartContainer/index.js +1 -61
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
- package/esm/ChartsOnAxisClickHandler/index.js +1 -0
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +9 -58
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
- package/esm/ChartsTooltip/utils.js +6 -0
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/esm/LineChart/AnimatedArea.js +103 -0
- package/esm/LineChart/AnimatedLine.js +105 -0
- package/esm/LineChart/AreaElement.js +16 -33
- package/esm/LineChart/AreaPlot.js +92 -59
- package/esm/LineChart/LineChart.js +36 -29
- package/esm/LineChart/LineElement.js +16 -35
- package/esm/LineChart/LineHighlightElement.js +3 -2
- package/esm/LineChart/LinePlot.js +90 -57
- package/esm/LineChart/MarkElement.js +26 -13
- package/esm/LineChart/MarkPlot.js +80 -51
- package/esm/LineChart/formatter.js +1 -1
- package/esm/LineChart/index.js +2 -0
- package/esm/PieChart/PieArcLabelPlot.js +1 -1
- package/esm/PieChart/PieArcPlot.js +6 -6
- package/esm/PieChart/PieChart.js +5 -50
- package/esm/PieChart/PiePlot.js +4 -4
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +245 -0
- package/esm/ResponsiveChartContainer/index.js +1 -115
- package/esm/ScatterChart/Scatter.js +18 -23
- package/esm/ScatterChart/ScatterChart.js +12 -22
- package/esm/ScatterChart/ScatterPlot.js +10 -2
- package/esm/SparkLineChart/SparkLineChart.js +2 -0
- package/esm/context/DrawingProvider.js +9 -2
- package/esm/hooks/useDrawingArea.js +7 -3
- package/esm/index.js +1 -0
- package/esm/internals/geometry.js +1 -1
- package/esm/internals/useAnimatedPath.js +29 -0
- package/esm/internals/utils.js +7 -0
- package/hooks/useDrawingArea.d.ts +2 -0
- package/hooks/useDrawingArea.js +7 -3
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/geometry.js +1 -1
- package/internals/useAnimatedPath.d.ts +1 -0
- package/internals/useAnimatedPath.js +38 -0
- package/internals/utils.d.ts +4 -0
- package/internals/utils.js +8 -0
- package/legacy/BarChart/BarChart.js +24 -23
- package/legacy/BarChart/BarElement.js +5 -2
- package/legacy/BarChart/BarPlot.js +18 -4
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartContainer/ChartContainer.js +187 -0
- package/legacy/ChartContainer/index.js +1 -59
- package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +8 -61
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +9 -58
- package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
- package/legacy/ChartsTooltip/utils.js +6 -0
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
- package/legacy/LineChart/AnimatedArea.js +102 -0
- package/legacy/LineChart/AnimatedLine.js +104 -0
- package/legacy/LineChart/AreaElement.js +15 -35
- package/legacy/LineChart/AreaPlot.js +102 -66
- package/legacy/LineChart/LineChart.js +36 -29
- package/legacy/LineChart/LineElement.js +15 -37
- package/legacy/LineChart/LineHighlightElement.js +3 -2
- package/legacy/LineChart/LinePlot.js +97 -63
- package/legacy/LineChart/MarkElement.js +29 -12
- package/legacy/LineChart/MarkPlot.js +83 -53
- package/legacy/LineChart/formatter.js +1 -1
- package/legacy/LineChart/index.js +2 -0
- package/legacy/PieChart/PieArcLabelPlot.js +1 -1
- package/legacy/PieChart/PieArcPlot.js +6 -6
- package/legacy/PieChart/PieChart.js +5 -50
- package/legacy/PieChart/PiePlot.js +4 -4
- package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +253 -0
- package/legacy/ResponsiveChartContainer/index.js +1 -123
- package/legacy/ScatterChart/Scatter.js +20 -23
- package/legacy/ScatterChart/ScatterChart.js +12 -22
- package/legacy/ScatterChart/ScatterPlot.js +10 -2
- package/legacy/SparkLineChart/SparkLineChart.js +2 -0
- package/legacy/context/DrawingProvider.js +11 -2
- package/legacy/hooks/useDrawingArea.js +7 -3
- package/legacy/index.js +2 -1
- package/legacy/internals/geometry.js +1 -1
- package/legacy/internals/useAnimatedPath.js +32 -0
- package/legacy/internals/utils.js +7 -0
- package/modern/BarChart/BarChart.js +24 -23
- package/modern/BarChart/BarElement.js +6 -3
- package/modern/BarChart/BarPlot.js +19 -5
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartContainer/ChartContainer.js +189 -0
- package/modern/ChartContainer/index.js +1 -61
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/modern/ChartsOnAxisClickHandler/index.js +1 -0
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -58
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
- package/modern/ChartsTooltip/utils.js +6 -0
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/modern/LineChart/AnimatedArea.js +103 -0
- package/modern/LineChart/AnimatedLine.js +105 -0
- package/modern/LineChart/AreaElement.js +16 -33
- package/modern/LineChart/AreaPlot.js +91 -58
- package/modern/LineChart/LineChart.js +36 -29
- package/modern/LineChart/LineElement.js +16 -35
- package/modern/LineChart/LineHighlightElement.js +3 -2
- package/modern/LineChart/LinePlot.js +89 -56
- package/modern/LineChart/MarkElement.js +26 -13
- package/modern/LineChart/MarkPlot.js +80 -51
- package/modern/LineChart/formatter.js +1 -1
- package/modern/LineChart/index.js +2 -0
- package/modern/PieChart/PieArcLabelPlot.js +1 -1
- package/modern/PieChart/PieArcPlot.js +6 -6
- package/modern/PieChart/PieChart.js +5 -50
- package/modern/PieChart/PiePlot.js +4 -4
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +242 -0
- package/modern/ResponsiveChartContainer/index.js +1 -112
- package/modern/ScatterChart/Scatter.js +18 -23
- package/modern/ScatterChart/ScatterChart.js +12 -22
- package/modern/ScatterChart/ScatterPlot.js +10 -2
- package/modern/SparkLineChart/SparkLineChart.js +2 -0
- package/modern/context/DrawingProvider.js +9 -2
- package/modern/hooks/useDrawingArea.js +7 -3
- package/modern/index.js +2 -1
- package/modern/internals/geometry.js +1 -1
- package/modern/internals/useAnimatedPath.js +29 -0
- package/modern/internals/utils.js +7 -0
- package/package.json +6 -5
|
@@ -10,6 +10,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
10
10
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
11
11
|
var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
|
|
12
12
|
var _ChartsTooltipTable = require("./ChartsTooltipTable");
|
|
13
|
+
var _utils = require("./utils");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -41,14 +42,15 @@ function DefaultChartsAxisTooltipContent(props) {
|
|
|
41
42
|
})
|
|
42
43
|
})
|
|
43
44
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("tbody", {
|
|
44
|
-
children: series.map(({
|
|
45
|
+
children: series.filter(_utils.isCartesianSeries).map(({
|
|
45
46
|
color,
|
|
46
47
|
id,
|
|
47
48
|
label,
|
|
48
49
|
valueFormatter,
|
|
49
50
|
data
|
|
50
51
|
}) => {
|
|
51
|
-
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
const formattedValue = valueFormatter(data[dataIndex] ?? null);
|
|
52
54
|
if (formattedValue == null) {
|
|
53
55
|
return null;
|
|
54
56
|
}
|
|
@@ -88,48 +90,18 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
|
|
|
88
90
|
/**
|
|
89
91
|
* The properties of the triggered axis.
|
|
90
92
|
*/
|
|
91
|
-
axis: _propTypes.default.
|
|
92
|
-
axisId: _propTypes.default.string,
|
|
93
|
-
classes: _propTypes.default.object,
|
|
94
|
-
data: _propTypes.default.array,
|
|
95
|
-
dataKey: _propTypes.default.string,
|
|
96
|
-
disableLine: _propTypes.default.bool,
|
|
97
|
-
disableTicks: _propTypes.default.bool,
|
|
98
|
-
fill: _propTypes.default.string,
|
|
99
|
-
hideTooltip: _propTypes.default.bool,
|
|
100
|
-
id: _propTypes.default.string.isRequired,
|
|
101
|
-
label: _propTypes.default.string,
|
|
102
|
-
labelFontSize: _propTypes.default.number,
|
|
103
|
-
labelStyle: _propTypes.default.object,
|
|
104
|
-
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
105
|
-
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
106
|
-
position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
|
|
107
|
-
scale: _propTypes.default.func.isRequired,
|
|
108
|
-
scaleType: _propTypes.default.oneOf(['time']).isRequired,
|
|
109
|
-
slotProps: _propTypes.default.object,
|
|
110
|
-
slots: _propTypes.default.object,
|
|
111
|
-
stroke: _propTypes.default.string,
|
|
112
|
-
tickFontSize: _propTypes.default.number,
|
|
113
|
-
tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
|
|
114
|
-
tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
|
|
115
|
-
tickLabelStyle: _propTypes.default.object,
|
|
116
|
-
tickMaxStep: _propTypes.default.number,
|
|
117
|
-
tickMinStep: _propTypes.default.number,
|
|
118
|
-
tickNumber: _propTypes.default.number.isRequired,
|
|
119
|
-
tickSize: _propTypes.default.number,
|
|
120
|
-
valueFormatter: _propTypes.default.func
|
|
121
|
-
}).isRequired,
|
|
93
|
+
axis: _propTypes.default.object.isRequired,
|
|
122
94
|
/**
|
|
123
95
|
* Data identifying the triggered axis.
|
|
124
96
|
*/
|
|
125
97
|
axisData: _propTypes.default.shape({
|
|
126
98
|
x: _propTypes.default.shape({
|
|
127
99
|
index: _propTypes.default.number,
|
|
128
|
-
value: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired
|
|
100
|
+
value: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired
|
|
129
101
|
}),
|
|
130
102
|
y: _propTypes.default.shape({
|
|
131
103
|
index: _propTypes.default.number,
|
|
132
|
-
value: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired
|
|
104
|
+
value: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired
|
|
133
105
|
})
|
|
134
106
|
}).isRequired,
|
|
135
107
|
/**
|
|
@@ -147,28 +119,6 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
|
|
|
147
119
|
/**
|
|
148
120
|
* The series linked to the triggered axis.
|
|
149
121
|
*/
|
|
150
|
-
series: _propTypes.default.arrayOf(_propTypes.default.
|
|
151
|
-
area: _propTypes.default.bool,
|
|
152
|
-
color: _propTypes.default.string.isRequired,
|
|
153
|
-
connectNulls: _propTypes.default.bool,
|
|
154
|
-
curve: _propTypes.default.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
155
|
-
data: _propTypes.default.arrayOf(_propTypes.default.number).isRequired,
|
|
156
|
-
dataKey: _propTypes.default.string,
|
|
157
|
-
disableHighlight: _propTypes.default.bool,
|
|
158
|
-
highlightScope: _propTypes.default.shape({
|
|
159
|
-
faded: _propTypes.default.oneOf(['global', 'none', 'series']),
|
|
160
|
-
highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
|
|
161
|
-
}),
|
|
162
|
-
id: _propTypes.default.string.isRequired,
|
|
163
|
-
label: _propTypes.default.string,
|
|
164
|
-
showMark: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.bool]),
|
|
165
|
-
stack: _propTypes.default.string,
|
|
166
|
-
stackOffset: _propTypes.default.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
|
|
167
|
-
stackOrder: _propTypes.default.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
|
|
168
|
-
type: _propTypes.default.oneOf(['line']).isRequired,
|
|
169
|
-
valueFormatter: _propTypes.default.func.isRequired,
|
|
170
|
-
xAxisKey: _propTypes.default.string,
|
|
171
|
-
yAxisKey: _propTypes.default.string
|
|
172
|
-
})).isRequired,
|
|
122
|
+
series: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
|
|
173
123
|
sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
|
|
174
124
|
} : void 0;
|
|
@@ -82,16 +82,6 @@ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propType
|
|
|
82
82
|
/**
|
|
83
83
|
* The series linked to the triggered axis.
|
|
84
84
|
*/
|
|
85
|
-
series: _propTypes.default.
|
|
86
|
-
color: _propTypes.default.string,
|
|
87
|
-
data: _propTypes.default.arrayOf(_propTypes.default.number).isRequired,
|
|
88
|
-
highlightScope: _propTypes.default.shape({
|
|
89
|
-
faded: _propTypes.default.oneOf(['global', 'none', 'series']),
|
|
90
|
-
highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
|
|
91
|
-
}),
|
|
92
|
-
id: _propTypes.default.string.isRequired,
|
|
93
|
-
type: _propTypes.default.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
|
|
94
|
-
valueFormatter: _propTypes.default.func.isRequired
|
|
95
|
-
}).isRequired,
|
|
85
|
+
series: _propTypes.default.object.isRequired,
|
|
96
86
|
sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
|
|
97
87
|
} : void 0;
|
package/ChartsTooltip/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxisInteractionData, ItemInteractionData } from '../context/InteractionProvider';
|
|
2
|
-
import { ChartSeriesType } from '../models/seriesType/config';
|
|
2
|
+
import { CartesianChartSeriesType, ChartSeriesDefaultized, ChartSeriesType } from '../models/seriesType/config';
|
|
3
3
|
export declare function generateVirtualElement(mousePosition: {
|
|
4
4
|
x: number;
|
|
5
5
|
y: number;
|
|
@@ -22,3 +22,5 @@ export declare function useMouseTracker(): {
|
|
|
22
22
|
} | null;
|
|
23
23
|
export type TriggerOptions = 'item' | 'axis' | 'none';
|
|
24
24
|
export declare function getTooltipHasData(trigger: TriggerOptions, displayedData: null | AxisInteractionData | ItemInteractionData<ChartSeriesType>): boolean;
|
|
25
|
+
export declare function isCartesianSeriesType(seriesType: string): seriesType is CartesianChartSeriesType;
|
|
26
|
+
export declare function isCartesianSeries(series: ChartSeriesDefaultized<ChartSeriesType>): series is ChartSeriesDefaultized<CartesianChartSeriesType>;
|
package/ChartsTooltip/utils.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.generateVirtualElement = generateVirtualElement;
|
|
7
7
|
exports.getTooltipHasData = getTooltipHasData;
|
|
8
|
+
exports.isCartesianSeries = isCartesianSeries;
|
|
9
|
+
exports.isCartesianSeriesType = isCartesianSeriesType;
|
|
8
10
|
exports.useMouseTracker = useMouseTracker;
|
|
9
11
|
var React = _interopRequireWildcard(require("react"));
|
|
10
12
|
var _DrawingProvider = require("../context/DrawingProvider");
|
|
@@ -88,4 +90,10 @@ function getTooltipHasData(trigger, displayedData) {
|
|
|
88
90
|
const hasAxisXData = displayedData.x !== null;
|
|
89
91
|
const hasAxisYData = displayedData.y !== null;
|
|
90
92
|
return hasAxisXData || hasAxisYData;
|
|
93
|
+
}
|
|
94
|
+
function isCartesianSeriesType(seriesType) {
|
|
95
|
+
return ['bar', 'line', 'scatter'].includes(seriesType);
|
|
96
|
+
}
|
|
97
|
+
function isCartesianSeries(series) {
|
|
98
|
+
return isCartesianSeriesType(series.type);
|
|
91
99
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { ScatterItemIdentifier } from '../models';
|
|
2
3
|
export type ChartsVoronoiHandlerProps = {
|
|
3
4
|
/**
|
|
4
5
|
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
@@ -6,6 +7,12 @@ export type ChartsVoronoiHandlerProps = {
|
|
|
6
7
|
* @default undefined
|
|
7
8
|
*/
|
|
8
9
|
voronoiMaxRadius?: number | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Callback fired when clicking on a scatter item.
|
|
12
|
+
* @param {MouseEvent} event Mouse event catched at the svg level
|
|
13
|
+
* @param {ScatterItemIdentifier} scatterItemIdentifier Identify whihc item got clicked
|
|
14
|
+
*/
|
|
15
|
+
onItemClick?: (event: MouseEvent, scatterItemIdentifier: ScatterItemIdentifier) => void;
|
|
9
16
|
};
|
|
10
17
|
declare function ChartsVoronoiHandler(props: ChartsVoronoiHandlerProps): React.JSX.Element;
|
|
11
18
|
declare namespace ChartsVoronoiHandler {
|
|
@@ -20,7 +20,8 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
20
20
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
21
|
function ChartsVoronoiHandler(props) {
|
|
22
22
|
const {
|
|
23
|
-
voronoiMaxRadius
|
|
23
|
+
voronoiMaxRadius,
|
|
24
|
+
onItemClick
|
|
24
25
|
} = props;
|
|
25
26
|
const svgRef = React.useContext(_DrawingProvider.SVGContext);
|
|
26
27
|
const {
|
|
@@ -58,6 +59,8 @@ function ChartsVoronoiHandler(props) {
|
|
|
58
59
|
};
|
|
59
60
|
}, [dispatch]);
|
|
60
61
|
(0, _useEnhancedEffect.default)(() => {
|
|
62
|
+
// This effect generate and store the Delaunay object that's used to map coordinate to closest point.
|
|
63
|
+
|
|
61
64
|
if (seriesOrder === undefined || series === undefined) {
|
|
62
65
|
// If there is no scatter chart series
|
|
63
66
|
return;
|
|
@@ -91,80 +94,125 @@ function ChartsVoronoiHandler(props) {
|
|
|
91
94
|
if (element === null) {
|
|
92
95
|
return undefined;
|
|
93
96
|
}
|
|
94
|
-
const handleMouseOut = () => {
|
|
95
|
-
dispatch({
|
|
96
|
-
type: 'exitChart'
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
97
|
|
|
100
98
|
// TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
|
|
101
|
-
|
|
99
|
+
function getClosestPoint(event) {
|
|
102
100
|
// Get mouse coordinate in global SVG space
|
|
103
101
|
const svgPoint = (0, _utils.getSVGPoint)(svgRef.current, event);
|
|
104
102
|
const outsideX = svgPoint.x < left || svgPoint.x > left + width;
|
|
105
103
|
const outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
106
104
|
if (outsideX || outsideY) {
|
|
107
|
-
|
|
108
|
-
type: 'exitChart'
|
|
109
|
-
});
|
|
110
|
-
return;
|
|
105
|
+
return 'outside-chart';
|
|
111
106
|
}
|
|
112
107
|
if (!voronoiRef.current.delauney) {
|
|
113
|
-
return;
|
|
108
|
+
return 'no-point-found';
|
|
114
109
|
}
|
|
115
110
|
const closestPointIndex = voronoiRef.current.delauney?.find(svgPoint.x, svgPoint.y);
|
|
116
|
-
if (closestPointIndex
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return
|
|
122
|
-
});
|
|
123
|
-
if (seriesId === undefined) {
|
|
124
|
-
return;
|
|
111
|
+
if (closestPointIndex === undefined) {
|
|
112
|
+
return 'no-point-found';
|
|
113
|
+
}
|
|
114
|
+
const seriesId = Object.keys(voronoiRef.current).find(id => {
|
|
115
|
+
if (id === 'delauney') {
|
|
116
|
+
return false;
|
|
125
117
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
118
|
+
return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
|
|
119
|
+
});
|
|
120
|
+
if (seriesId === undefined) {
|
|
121
|
+
return 'no-point-found';
|
|
122
|
+
}
|
|
123
|
+
const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
|
|
124
|
+
if (voronoiMaxRadius !== undefined) {
|
|
125
|
+
const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
|
|
126
|
+
const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
|
|
127
|
+
const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
|
|
128
|
+
if (dist2 > voronoiMaxRadius ** 2) {
|
|
129
|
+
// The closest point is too far to be considered.
|
|
130
|
+
return 'outside-voronoi-max-radius';
|
|
143
131
|
}
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
seriesId,
|
|
135
|
+
dataIndex
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const handleMouseOut = () => {
|
|
139
|
+
dispatch({
|
|
140
|
+
type: 'exitChart'
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
const handleMouseMove = event => {
|
|
144
|
+
const closestPoint = getClosestPoint(event);
|
|
145
|
+
if (closestPoint === 'outside-chart') {
|
|
146
|
+
dispatch({
|
|
147
|
+
type: 'exitChart'
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (closestPoint === 'outside-voronoi-max-radius' || closestPoint === 'no-point-found') {
|
|
144
152
|
dispatch({
|
|
145
|
-
type: '
|
|
153
|
+
type: 'leaveItem',
|
|
146
154
|
data: {
|
|
147
|
-
type: 'scatter'
|
|
148
|
-
seriesId,
|
|
149
|
-
dataIndex
|
|
155
|
+
type: 'scatter'
|
|
150
156
|
}
|
|
151
157
|
});
|
|
158
|
+
return;
|
|
152
159
|
}
|
|
160
|
+
const {
|
|
161
|
+
seriesId,
|
|
162
|
+
dataIndex
|
|
163
|
+
} = closestPoint;
|
|
164
|
+
dispatch({
|
|
165
|
+
type: 'enterItem',
|
|
166
|
+
data: {
|
|
167
|
+
type: 'scatter',
|
|
168
|
+
seriesId,
|
|
169
|
+
dataIndex
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const handleMouseClick = event => {
|
|
174
|
+
if (!onItemClick) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const closestPoint = getClosestPoint(event);
|
|
178
|
+
if (typeof closestPoint === 'string') {
|
|
179
|
+
// No point fond for any reason
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const {
|
|
183
|
+
seriesId,
|
|
184
|
+
dataIndex
|
|
185
|
+
} = closestPoint;
|
|
186
|
+
onItemClick(event, {
|
|
187
|
+
type: 'scatter',
|
|
188
|
+
seriesId,
|
|
189
|
+
dataIndex
|
|
190
|
+
});
|
|
153
191
|
};
|
|
154
192
|
element.addEventListener('mouseout', handleMouseOut);
|
|
155
193
|
element.addEventListener('mousemove', handleMouseMove);
|
|
194
|
+
element.addEventListener('click', handleMouseClick);
|
|
156
195
|
return () => {
|
|
157
196
|
element.removeEventListener('mouseout', handleMouseOut);
|
|
158
197
|
element.removeEventListener('mousemove', handleMouseMove);
|
|
198
|
+
element.removeEventListener('click', handleMouseClick);
|
|
159
199
|
};
|
|
160
|
-
}, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
|
|
161
|
-
|
|
200
|
+
}, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius, onItemClick]);
|
|
201
|
+
|
|
202
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
203
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {});
|
|
162
204
|
}
|
|
163
205
|
process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
|
|
164
206
|
// ----------------------------- Warning --------------------------------
|
|
165
207
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
166
208
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
167
209
|
// ----------------------------------------------------------------------
|
|
210
|
+
/**
|
|
211
|
+
* Callback fired when clicking on a scatter item.
|
|
212
|
+
* @param {MouseEvent} event Mouse event catched at the svg level
|
|
213
|
+
* @param {ScatterItemIdentifier} scatterItemIdentifier Identify whihc item got clicked
|
|
214
|
+
*/
|
|
215
|
+
onItemClick: _propTypes.default.func,
|
|
168
216
|
/**
|
|
169
217
|
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
170
218
|
* If `undefined`, the radius is assumed to be infinite.
|