@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarChart.d.ts +2 -1
- package/BarChart/BarChart.js +33 -12
- package/BarChart/BarElement.d.ts +20 -13
- package/BarChart/BarElement.js +7 -3
- package/BarChart/BarPlot.d.ts +11 -6
- package/BarChart/BarPlot.js +28 -15
- package/BarChart/formatter.js +1 -1
- package/CHANGELOG.md +406 -1
- package/ChartContainer/ChartContainer.js +6 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +5 -54
- package/ChartsLegend/ChartsLegend.js +2 -307
- package/ChartsLegend/DefaultChartsLegend.d.ts +60 -0
- package/ChartsLegend/DefaultChartsLegend.js +294 -0
- package/ChartsLegend/index.d.ts +1 -0
- package/ChartsLegend/index.js +11 -0
- 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/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +2 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/ChartsTooltip/utils.d.ts +4 -1
- package/ChartsTooltip/utils.js +15 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/ChartsXAxis/ChartsXAxis.js +13 -9
- package/ChartsYAxis/ChartsYAxis.js +1 -1
- 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 +19 -18
- 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 +45 -14
- package/LineChart/LineElement.d.ts +19 -18
- package/LineChart/LineElement.js +16 -36
- package/LineChart/LineHighlightElement.d.ts +3 -2
- package/LineChart/LineHighlightElement.js +5 -3
- package/LineChart/LinePlot.d.ts +12 -7
- package/LineChart/LinePlot.js +89 -56
- package/LineChart/MarkElement.d.ts +8 -4
- package/LineChart/MarkElement.js +27 -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/PieArc.d.ts +3 -2
- package/PieChart/PieArc.js +1 -0
- package/PieChart/PieArcLabel.d.ts +3 -2
- package/PieChart/PieArcLabel.js +1 -0
- package/PieChart/PieArcLabelPlot.d.ts +1 -1
- package/PieChart/PieArcLabelPlot.js +2 -2
- package/PieChart/PieArcPlot.d.ts +2 -2
- package/PieChart/PieArcPlot.js +7 -7
- package/PieChart/PieChart.d.ts +1 -1
- package/PieChart/PieChart.js +14 -12
- package/PieChart/PiePlot.d.ts +1 -1
- package/PieChart/PiePlot.js +4 -4
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/ScatterChart/Scatter.d.ts +7 -1
- package/ScatterChart/Scatter.js +17 -3
- package/ScatterChart/ScatterChart.d.ts +8 -2
- package/ScatterChart/ScatterChart.js +21 -10
- package/ScatterChart/ScatterPlot.d.ts +1 -1
- package/ScatterChart/ScatterPlot.js +10 -2
- package/SparkLineChart/SparkLineChart.d.ts +1 -1
- package/SparkLineChart/SparkLineChart.js +7 -4
- package/context/CartesianContextProvider.js +8 -6
- 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 +33 -12
- package/esm/BarChart/BarElement.js +7 -3
- package/esm/BarChart/BarPlot.js +27 -15
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartContainer/ChartContainer.js +6 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -307
- package/esm/ChartsLegend/DefaultChartsLegend.js +286 -0
- package/esm/ChartsLegend/index.js +1 -0
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
- package/esm/ChartsOnAxisClickHandler/index.js +1 -0
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/esm/ChartsTooltip/utils.js +12 -0
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/esm/ChartsXAxis/ChartsXAxis.js +13 -9
- package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
- 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 +45 -14
- package/esm/LineChart/LineElement.js +16 -35
- package/esm/LineChart/LineHighlightElement.js +5 -3
- package/esm/LineChart/LinePlot.js +90 -57
- package/esm/LineChart/MarkElement.js +27 -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/PieArc.js +1 -0
- package/esm/PieChart/PieArcLabel.js +1 -0
- package/esm/PieChart/PieArcLabelPlot.js +2 -2
- package/esm/PieChart/PieArcPlot.js +7 -7
- package/esm/PieChart/PieChart.js +14 -12
- package/esm/PieChart/PiePlot.js +4 -4
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/esm/ScatterChart/Scatter.js +17 -3
- package/esm/ScatterChart/ScatterChart.js +21 -10
- package/esm/ScatterChart/ScatterPlot.js +10 -2
- package/esm/SparkLineChart/SparkLineChart.js +7 -4
- package/esm/context/CartesianContextProvider.js +8 -6
- 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/defaultizeColor.d.ts +16 -16
- package/internals/defaultizeValueFormatter.d.ts +4 -7
- package/internals/geometry.js +1 -1
- package/internals/stackSeries.d.ts +4 -7
- 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 +33 -12
- package/legacy/BarChart/BarElement.js +6 -2
- package/legacy/BarChart/BarPlot.js +28 -14
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartContainer/ChartContainer.js +6 -4
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +2 -323
- package/legacy/ChartsLegend/DefaultChartsLegend.js +302 -0
- package/legacy/ChartsLegend/index.js +1 -0
- package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
- package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/legacy/ChartsTooltip/utils.js +12 -0
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
- package/legacy/ChartsXAxis/ChartsXAxis.js +12 -8
- package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
- 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 +45 -14
- package/legacy/LineChart/LineElement.js +15 -37
- package/legacy/LineChart/LineHighlightElement.js +5 -3
- package/legacy/LineChart/LinePlot.js +97 -63
- package/legacy/LineChart/MarkElement.js +30 -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/PieArc.js +1 -0
- package/legacy/PieChart/PieArcLabel.js +1 -0
- package/legacy/PieChart/PieArcLabelPlot.js +2 -2
- package/legacy/PieChart/PieArcPlot.js +7 -7
- package/legacy/PieChart/PieChart.js +14 -12
- package/legacy/PieChart/PiePlot.js +4 -4
- package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/legacy/ScatterChart/Scatter.js +19 -3
- package/legacy/ScatterChart/ScatterChart.js +21 -10
- package/legacy/ScatterChart/ScatterPlot.js +10 -2
- package/legacy/SparkLineChart/SparkLineChart.js +8 -5
- package/legacy/context/CartesianContextProvider.js +8 -6
- 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/models/axis.d.ts +7 -2
- package/models/seriesType/common.d.ts +2 -1
- package/models/seriesType/config.d.ts +7 -12
- package/models/seriesType/line.d.ts +2 -2
- package/models/seriesType/pie.d.ts +7 -3
- package/models/seriesType/scatter.d.ts +5 -2
- package/modern/BarChart/BarChart.js +33 -12
- package/modern/BarChart/BarElement.js +7 -3
- package/modern/BarChart/BarPlot.js +27 -15
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartContainer/ChartContainer.js +6 -4
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +2 -307
- package/modern/ChartsLegend/DefaultChartsLegend.js +286 -0
- package/modern/ChartsLegend/index.js +1 -0
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
- package/modern/ChartsOnAxisClickHandler/index.js +1 -0
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/modern/ChartsTooltip/utils.js +12 -0
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
- package/modern/ChartsXAxis/ChartsXAxis.js +13 -9
- package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
- 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 +45 -14
- package/modern/LineChart/LineElement.js +16 -35
- package/modern/LineChart/LineHighlightElement.js +5 -3
- package/modern/LineChart/LinePlot.js +89 -56
- package/modern/LineChart/MarkElement.js +27 -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/PieArc.js +1 -0
- package/modern/PieChart/PieArcLabel.js +1 -0
- package/modern/PieChart/PieArcLabelPlot.js +2 -2
- package/modern/PieChart/PieArcPlot.js +7 -7
- package/modern/PieChart/PieChart.js +14 -12
- package/modern/PieChart/PiePlot.js +4 -4
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
- package/modern/ScatterChart/Scatter.js +17 -3
- package/modern/ScatterChart/ScatterChart.js +21 -10
- package/modern/ScatterChart/ScatterPlot.js +10 -2
- package/modern/SparkLineChart/SparkLineChart.js +7 -4
- package/modern/context/CartesianContextProvider.js +8 -6
- 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
package/esm/BarChart/BarChart.js
CHANGED
|
@@ -10,6 +10,7 @@ import { ChartsTooltip } from '../ChartsTooltip';
|
|
|
10
10
|
import { ChartsLegend } from '../ChartsLegend';
|
|
11
11
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
12
12
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
13
|
+
import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
16
|
/**
|
|
@@ -43,6 +44,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
43
44
|
rightAxis,
|
|
44
45
|
bottomAxis,
|
|
45
46
|
skipAnimation,
|
|
47
|
+
onItemClick,
|
|
48
|
+
onAxisClick,
|
|
46
49
|
children,
|
|
47
50
|
slots,
|
|
48
51
|
slotProps
|
|
@@ -83,13 +86,16 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
83
86
|
colors: colors,
|
|
84
87
|
dataset: dataset,
|
|
85
88
|
sx: sx,
|
|
86
|
-
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
87
|
-
children: [/*#__PURE__*/_jsx(
|
|
89
|
+
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none' && !onAxisClick,
|
|
90
|
+
children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
|
|
91
|
+
onAxisClick: onAxisClick
|
|
92
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
88
93
|
clipPath: `url(#${clipPathId})`,
|
|
89
94
|
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
90
95
|
slots: slots,
|
|
91
96
|
slotProps: slotProps,
|
|
92
|
-
skipAnimation: skipAnimation
|
|
97
|
+
skipAnimation: skipAnimation,
|
|
98
|
+
onItemClick: onItemClick
|
|
93
99
|
})
|
|
94
100
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
95
101
|
topAxis: topAxis,
|
|
@@ -131,7 +137,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
131
137
|
* @default xAxisIds[0] The id of the first provided axis
|
|
132
138
|
*/
|
|
133
139
|
bottomAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
134
|
-
axisId: PropTypes.string,
|
|
140
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
135
141
|
classes: PropTypes.object,
|
|
136
142
|
disableLine: PropTypes.bool,
|
|
137
143
|
disableTicks: PropTypes.bool,
|
|
@@ -182,7 +188,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
182
188
|
* @default yAxisIds[0] The id of the first provided axis
|
|
183
189
|
*/
|
|
184
190
|
leftAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
185
|
-
axisId: PropTypes.string,
|
|
191
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
186
192
|
classes: PropTypes.object,
|
|
187
193
|
disableLine: PropTypes.bool,
|
|
188
194
|
disableTicks: PropTypes.bool,
|
|
@@ -229,13 +235,26 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
229
235
|
right: PropTypes.number,
|
|
230
236
|
top: PropTypes.number
|
|
231
237
|
}),
|
|
238
|
+
/**
|
|
239
|
+
* The function called for onClick events.
|
|
240
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
241
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
242
|
+
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
243
|
+
*/
|
|
244
|
+
onAxisClick: PropTypes.func,
|
|
245
|
+
/**
|
|
246
|
+
* Callback fired when a bar item is clicked.
|
|
247
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
248
|
+
* @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
|
|
249
|
+
*/
|
|
250
|
+
onItemClick: PropTypes.func,
|
|
232
251
|
/**
|
|
233
252
|
* Indicate which axis to display the right of the charts.
|
|
234
253
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
235
254
|
* @default null
|
|
236
255
|
*/
|
|
237
256
|
rightAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
238
|
-
axisId: PropTypes.string,
|
|
257
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
239
258
|
classes: PropTypes.object,
|
|
240
259
|
disableLine: PropTypes.bool,
|
|
241
260
|
disableTicks: PropTypes.bool,
|
|
@@ -258,7 +277,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
258
277
|
}), PropTypes.string]),
|
|
259
278
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
260
279
|
/**
|
|
261
|
-
* If `true`, animations are
|
|
280
|
+
* If `true`, animations are skipped.
|
|
262
281
|
* @default false
|
|
263
282
|
*/
|
|
264
283
|
skipAnimation: PropTypes.bool,
|
|
@@ -288,7 +307,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
288
307
|
* @default null
|
|
289
308
|
*/
|
|
290
309
|
topAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
291
|
-
axisId: PropTypes.string,
|
|
310
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
292
311
|
classes: PropTypes.object,
|
|
293
312
|
disableLine: PropTypes.bool,
|
|
294
313
|
disableTicks: PropTypes.bool,
|
|
@@ -325,7 +344,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
325
344
|
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
|
|
326
345
|
*/
|
|
327
346
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
328
|
-
axisId: PropTypes.string,
|
|
347
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
329
348
|
classes: PropTypes.object,
|
|
330
349
|
data: PropTypes.array,
|
|
331
350
|
dataKey: PropTypes.string,
|
|
@@ -333,13 +352,14 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
333
352
|
disableTicks: PropTypes.bool,
|
|
334
353
|
fill: PropTypes.string,
|
|
335
354
|
hideTooltip: PropTypes.bool,
|
|
336
|
-
id: PropTypes.string,
|
|
355
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
337
356
|
label: PropTypes.string,
|
|
338
357
|
labelFontSize: PropTypes.number,
|
|
339
358
|
labelStyle: PropTypes.object,
|
|
340
359
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
341
360
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
342
361
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
362
|
+
reverse: PropTypes.bool,
|
|
343
363
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
344
364
|
slotProps: PropTypes.object,
|
|
345
365
|
slots: PropTypes.object,
|
|
@@ -359,7 +379,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
359
379
|
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
|
|
360
380
|
*/
|
|
361
381
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
362
|
-
axisId: PropTypes.string,
|
|
382
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
363
383
|
classes: PropTypes.object,
|
|
364
384
|
data: PropTypes.array,
|
|
365
385
|
dataKey: PropTypes.string,
|
|
@@ -367,13 +387,14 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
367
387
|
disableTicks: PropTypes.bool,
|
|
368
388
|
fill: PropTypes.string,
|
|
369
389
|
hideTooltip: PropTypes.bool,
|
|
370
|
-
id: PropTypes.string,
|
|
390
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
371
391
|
label: PropTypes.string,
|
|
372
392
|
labelFontSize: PropTypes.number,
|
|
373
393
|
labelStyle: PropTypes.object,
|
|
374
394
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
375
395
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
376
396
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
397
|
+
reverse: PropTypes.bool,
|
|
377
398
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
378
399
|
slotProps: PropTypes.object,
|
|
379
400
|
slots: PropTypes.object,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style"];
|
|
3
|
+
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style", "onClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import composeClasses from '@mui/utils/composeClasses';
|
|
@@ -50,7 +50,8 @@ function BarElement(props) {
|
|
|
50
50
|
highlightScope,
|
|
51
51
|
slots,
|
|
52
52
|
slotProps,
|
|
53
|
-
style
|
|
53
|
+
style,
|
|
54
|
+
onClick
|
|
54
55
|
} = props,
|
|
55
56
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
56
57
|
const getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
@@ -86,7 +87,9 @@ function BarElement(props) {
|
|
|
86
87
|
dataIndex
|
|
87
88
|
}), {
|
|
88
89
|
style,
|
|
89
|
-
className: classes.root
|
|
90
|
+
className: classes.root,
|
|
91
|
+
onClick,
|
|
92
|
+
cursor: onClick ? 'pointer' : 'unset'
|
|
90
93
|
}),
|
|
91
94
|
ownerState
|
|
92
95
|
});
|
|
@@ -103,6 +106,7 @@ process.env.NODE_ENV !== "production" ? BarElement.propTypes = {
|
|
|
103
106
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
104
107
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
105
108
|
}),
|
|
109
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
106
110
|
/**
|
|
107
111
|
* The props used for each component slot.
|
|
108
112
|
* @default {}
|
package/esm/BarChart/BarPlot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["skipAnimation"];
|
|
3
|
+
const _excluded = ["skipAnimation", "onItemClick"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { useTransition } from '@react-spring/web';
|
|
@@ -9,7 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
|
|
|
9
9
|
import { BarElement } from './BarElement';
|
|
10
10
|
import { isBandScaleConfig } from '../models/axis';
|
|
11
11
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
12
|
-
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
/**
|
|
14
14
|
* Solution of the equations
|
|
15
15
|
* W = barWidth * N + offset * (N-1)
|
|
@@ -19,7 +19,6 @@ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
|
19
19
|
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
20
20
|
* @returns The bar width and the offset between bars.
|
|
21
21
|
*/
|
|
22
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
22
|
function getBandSize({
|
|
24
23
|
bandWidth: W,
|
|
25
24
|
numberOfGroups: N,
|
|
@@ -38,7 +37,7 @@ function getBandSize({
|
|
|
38
37
|
offset
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
|
-
const
|
|
40
|
+
const useAggregatedData = () => {
|
|
42
41
|
var _React$useContext$bar;
|
|
43
42
|
const seriesData = (_React$useContext$bar = React.useContext(SeriesContext).bar) != null ? _React$useContext$bar : {
|
|
44
43
|
series: {},
|
|
@@ -104,20 +103,19 @@ const useCompletedData = () => {
|
|
|
104
103
|
} = series[seriesId];
|
|
105
104
|
return stackedData.map((values, dataIndex) => {
|
|
106
105
|
var _xAxis$xAxisKey$data, _yAxis$yAxisKey$data;
|
|
107
|
-
const
|
|
108
|
-
const
|
|
106
|
+
const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
|
|
107
|
+
const minValueCoord = Math.min(...valueCoordinates);
|
|
108
|
+
const maxValueCoord = Math.max(...valueCoordinates);
|
|
109
109
|
return {
|
|
110
|
-
bottom,
|
|
111
|
-
top,
|
|
112
110
|
seriesId,
|
|
113
111
|
dataIndex,
|
|
114
112
|
layout: series[seriesId].layout,
|
|
115
|
-
x: verticalLayout ? xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + barOffset :
|
|
116
|
-
y: verticalLayout ?
|
|
113
|
+
x: verticalLayout ? xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + barOffset : minValueCoord,
|
|
114
|
+
y: verticalLayout ? minValueCoord : yScale((_yAxis$yAxisKey$data = yAxis[yAxisKey].data) == null ? void 0 : _yAxis$yAxisKey$data[dataIndex]) + barOffset,
|
|
117
115
|
xOrigin: xScale(0),
|
|
118
116
|
yOrigin: yScale(0),
|
|
119
|
-
height: verticalLayout ?
|
|
120
|
-
width: verticalLayout ? barWidth :
|
|
117
|
+
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
|
|
118
|
+
width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
|
|
121
119
|
color,
|
|
122
120
|
highlightScope: series[seriesId].highlightScope
|
|
123
121
|
};
|
|
@@ -169,9 +167,10 @@ const getInStyle = ({
|
|
|
169
167
|
* - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
|
|
170
168
|
*/
|
|
171
169
|
function BarPlot(props) {
|
|
172
|
-
const completedData =
|
|
170
|
+
const completedData = useAggregatedData();
|
|
173
171
|
const {
|
|
174
|
-
skipAnimation
|
|
172
|
+
skipAnimation,
|
|
173
|
+
onItemClick
|
|
175
174
|
} = props,
|
|
176
175
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
177
176
|
const transition = useTransition(completedData, {
|
|
@@ -194,6 +193,13 @@ function BarPlot(props) {
|
|
|
194
193
|
highlightScope: highlightScope,
|
|
195
194
|
color: color
|
|
196
195
|
}, other, {
|
|
196
|
+
onClick: onItemClick && (event => {
|
|
197
|
+
onItemClick(event, {
|
|
198
|
+
type: 'bar',
|
|
199
|
+
seriesId,
|
|
200
|
+
dataIndex
|
|
201
|
+
});
|
|
202
|
+
}),
|
|
197
203
|
style: style
|
|
198
204
|
})))
|
|
199
205
|
});
|
|
@@ -204,7 +210,13 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
|
|
|
204
210
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
205
211
|
// ----------------------------------------------------------------------
|
|
206
212
|
/**
|
|
207
|
-
*
|
|
213
|
+
* Callback fired when a bar item is clicked.
|
|
214
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
215
|
+
* @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
|
|
216
|
+
*/
|
|
217
|
+
onItemClick: PropTypes.func,
|
|
218
|
+
/**
|
|
219
|
+
* If `true`, animations are skipped.
|
|
208
220
|
* @default false
|
|
209
221
|
*/
|
|
210
222
|
skipAnimation: PropTypes.bool,
|
|
@@ -69,7 +69,7 @@ const formatter = (params, dataset) => {
|
|
|
69
69
|
return {
|
|
70
70
|
seriesOrder,
|
|
71
71
|
stackingGroups,
|
|
72
|
-
series: defaultizeValueFormatter(completedSeries, v => v
|
|
72
|
+
series: defaultizeValueFormatter(completedSeries, v => v == null ? '' : v.toLocaleString())
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
export default formatter;
|
|
@@ -122,7 +122,7 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
|
|
|
122
122
|
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
|
|
123
123
|
*/
|
|
124
124
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
125
|
-
axisId: PropTypes.string,
|
|
125
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
126
126
|
classes: PropTypes.object,
|
|
127
127
|
data: PropTypes.array,
|
|
128
128
|
dataKey: PropTypes.string,
|
|
@@ -130,13 +130,14 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
|
|
|
130
130
|
disableTicks: PropTypes.bool,
|
|
131
131
|
fill: PropTypes.string,
|
|
132
132
|
hideTooltip: PropTypes.bool,
|
|
133
|
-
id: PropTypes.string,
|
|
133
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
134
134
|
label: PropTypes.string,
|
|
135
135
|
labelFontSize: PropTypes.number,
|
|
136
136
|
labelStyle: PropTypes.object,
|
|
137
137
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
138
138
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
139
139
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
140
|
+
reverse: PropTypes.bool,
|
|
140
141
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
141
142
|
slotProps: PropTypes.object,
|
|
142
143
|
slots: PropTypes.object,
|
|
@@ -156,7 +157,7 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
|
|
|
156
157
|
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
|
|
157
158
|
*/
|
|
158
159
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
159
|
-
axisId: PropTypes.string,
|
|
160
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
160
161
|
classes: PropTypes.object,
|
|
161
162
|
data: PropTypes.array,
|
|
162
163
|
dataKey: PropTypes.string,
|
|
@@ -164,13 +165,14 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
|
|
|
164
165
|
disableTicks: PropTypes.bool,
|
|
165
166
|
fill: PropTypes.string,
|
|
166
167
|
hideTooltip: PropTypes.bool,
|
|
167
|
-
id: PropTypes.string,
|
|
168
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
168
169
|
label: PropTypes.string,
|
|
169
170
|
labelFontSize: PropTypes.number,
|
|
170
171
|
labelStyle: PropTypes.object,
|
|
171
172
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
172
173
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
173
174
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
175
|
+
reverse: PropTypes.bool,
|
|
174
176
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
175
177
|
slotProps: PropTypes.object,
|
|
176
178
|
slots: PropTypes.object,
|
|
@@ -101,7 +101,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
101
101
|
* @default xAxisIds[0] The id of the first provided axis
|
|
102
102
|
*/
|
|
103
103
|
bottomAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
104
|
-
axisId: PropTypes.string,
|
|
104
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
105
105
|
classes: PropTypes.object,
|
|
106
106
|
disableLine: PropTypes.bool,
|
|
107
107
|
disableTicks: PropTypes.bool,
|
|
@@ -128,7 +128,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
128
128
|
* @default yAxisIds[0] The id of the first provided axis
|
|
129
129
|
*/
|
|
130
130
|
leftAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
131
|
-
axisId: PropTypes.string,
|
|
131
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
132
132
|
classes: PropTypes.object,
|
|
133
133
|
disableLine: PropTypes.bool,
|
|
134
134
|
disableTicks: PropTypes.bool,
|
|
@@ -155,7 +155,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
155
155
|
* @default null
|
|
156
156
|
*/
|
|
157
157
|
rightAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
158
|
-
axisId: PropTypes.string,
|
|
158
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
159
159
|
classes: PropTypes.object,
|
|
160
160
|
disableLine: PropTypes.bool,
|
|
161
161
|
disableTicks: PropTypes.bool,
|
|
@@ -192,7 +192,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
192
192
|
* @default null
|
|
193
193
|
*/
|
|
194
194
|
topAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
195
|
-
axisId: PropTypes.string,
|
|
195
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
196
196
|
classes: PropTypes.object,
|
|
197
197
|
disableLine: PropTypes.bool,
|
|
198
198
|
disableTicks: PropTypes.bool,
|