@mui/x-charts 7.0.0-alpha.3 → 7.0.0-alpha.5
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/BarPlot.js +7 -6
- package/BarChart/formatter.js +15 -3
- package/CHANGELOG.md +465 -0
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +1 -1
- package/ChartsLegend/ChartsLegend.js +3 -2
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsText/ChartsText.d.ts +17 -0
- package/{internals/components → ChartsText}/ChartsText.js +32 -17
- package/ChartsText/index.d.ts +3 -0
- package/ChartsText/index.js +12 -0
- package/ChartsText/package.json +6 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +14 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +174 -0
- package/ChartsVoronoiHandler/index.d.ts +1 -0
- package/ChartsVoronoiHandler/index.js +16 -0
- package/ChartsVoronoiHandler/package.json +6 -0
- package/ChartsXAxis/ChartsXAxis.js +3 -2
- package/ChartsYAxis/ChartsYAxis.js +1 -1
- package/LineChart/AreaPlot.js +3 -2
- package/LineChart/LineHighlightPlot.js +2 -1
- package/LineChart/LinePlot.js +3 -2
- package/LineChart/MarkPlot.js +2 -1
- package/LineChart/formatter.js +14 -2
- package/PieChart/PieArcLabelPlot.d.ts +2 -3
- package/PieChart/PieArcLabelPlot.js +0 -1
- package/PieChart/PieArcPlot.d.ts +2 -3
- package/PieChart/PieArcPlot.js +0 -1
- package/PieChart/PieChart.js +4 -4
- package/PieChart/PiePlot.js +20 -15
- package/PieChart/dataTransform/useTransformData.d.ts +2 -3
- package/ResponsiveChartContainer/index.js +2 -2
- package/ScatterChart/Scatter.js +14 -5
- package/ScatterChart/ScatterChart.d.ts +7 -1
- package/ScatterChart/ScatterChart.js +18 -1
- package/SparkLineChart/SparkLineChart.js +1 -0
- package/context/CartesianContextProvider.js +2 -2
- package/context/InteractionProvider.d.ts +10 -0
- package/context/InteractionProvider.js +21 -1
- package/context/SeriesContextProvider.js +1 -1
- package/esm/BarChart/BarPlot.js +7 -5
- package/esm/BarChart/formatter.js +20 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
- package/esm/ChartsText/index.js +1 -0
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +168 -0
- package/esm/ChartsVoronoiHandler/index.js +1 -0
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
- package/esm/LineChart/AreaPlot.js +3 -2
- package/esm/LineChart/LineHighlightPlot.js +2 -1
- package/esm/LineChart/LinePlot.js +3 -2
- package/esm/LineChart/MarkPlot.js +2 -1
- package/esm/LineChart/formatter.js +16 -3
- package/esm/PieChart/PieArcLabelPlot.js +0 -1
- package/esm/PieChart/PieArcPlot.js +0 -1
- package/esm/PieChart/PieChart.js +4 -4
- package/esm/PieChart/PiePlot.js +20 -15
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/ScatterChart/Scatter.js +14 -5
- package/esm/ScatterChart/ScatterChart.js +18 -1
- package/esm/SparkLineChart/SparkLineChart.js +1 -0
- package/esm/context/CartesianContextProvider.js +2 -2
- package/esm/context/InteractionProvider.js +21 -1
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/hooks/useAxisEvents.js +20 -27
- package/esm/hooks/useInteractionItemProps.js +4 -1
- package/esm/index.js +2 -0
- package/esm/internals/getWordsByLines.js +14 -0
- package/esm/internals/utils.js +40 -0
- package/hooks/useAxisEvents.js +20 -27
- package/hooks/useInteractionItemProps.d.ts +2 -2
- package/hooks/useInteractionItemProps.js +4 -1
- package/index.d.ts +2 -0
- package/index.js +23 -1
- package/internals/defaultizeColor.d.ts +5 -4
- package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
- package/internals/getWordsByLines.js +21 -0
- package/internals/utils.d.ts +13 -0
- package/internals/utils.js +42 -0
- package/legacy/BarChart/BarPlot.js +7 -5
- package/legacy/BarChart/formatter.js +23 -9
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +2 -1
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
- package/legacy/ChartsText/index.js +1 -0
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +162 -0
- package/legacy/ChartsVoronoiHandler/index.js +1 -0
- package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
- package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
- package/legacy/LineChart/AreaPlot.js +3 -2
- package/legacy/LineChart/LineHighlightPlot.js +2 -1
- package/legacy/LineChart/LinePlot.js +3 -2
- package/legacy/LineChart/MarkPlot.js +2 -1
- package/legacy/LineChart/formatter.js +19 -8
- package/legacy/PieChart/PieArcLabelPlot.js +0 -1
- package/legacy/PieChart/PieArcPlot.js +0 -1
- package/legacy/PieChart/PieChart.js +4 -4
- package/legacy/PieChart/PiePlot.js +20 -15
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/ScatterChart/Scatter.js +17 -6
- package/legacy/ScatterChart/ScatterChart.js +18 -1
- package/legacy/SparkLineChart/SparkLineChart.js +1 -0
- package/legacy/context/CartesianContextProvider.js +2 -2
- package/legacy/context/InteractionProvider.js +21 -1
- package/legacy/context/SeriesContextProvider.js +1 -1
- package/legacy/hooks/useAxisEvents.js +20 -27
- package/legacy/hooks/useInteractionItemProps.js +6 -1
- package/legacy/index.js +3 -1
- package/legacy/internals/getWordsByLines.js +15 -0
- package/legacy/internals/utils.js +40 -0
- package/models/axis.d.ts +1 -1
- package/models/seriesType/config.d.ts +4 -3
- package/models/seriesType/pie.d.ts +29 -7
- package/models/seriesType/scatter.d.ts +5 -0
- package/modern/BarChart/BarPlot.js +7 -5
- package/modern/BarChart/formatter.js +15 -3
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +2 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
- package/modern/ChartsText/index.js +1 -0
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +166 -0
- package/modern/ChartsVoronoiHandler/index.js +1 -0
- package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
- package/modern/LineChart/AreaPlot.js +3 -2
- package/modern/LineChart/LineHighlightPlot.js +2 -1
- package/modern/LineChart/LinePlot.js +3 -2
- package/modern/LineChart/MarkPlot.js +2 -1
- package/modern/LineChart/formatter.js +14 -2
- package/modern/PieChart/PieArcLabelPlot.js +0 -1
- package/modern/PieChart/PieArcPlot.js +0 -1
- package/modern/PieChart/PieChart.js +4 -4
- package/modern/PieChart/PiePlot.js +20 -15
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/ScatterChart/Scatter.js +14 -5
- package/modern/ScatterChart/ScatterChart.js +18 -1
- package/modern/SparkLineChart/SparkLineChart.js +1 -0
- package/modern/context/CartesianContextProvider.js +2 -2
- package/modern/context/InteractionProvider.js +21 -1
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/hooks/useAxisEvents.js +20 -27
- package/modern/hooks/useInteractionItemProps.js +4 -1
- package/modern/index.js +3 -1
- package/modern/internals/getWordsByLines.js +14 -0
- package/modern/internals/utils.js +40 -0
- package/package.json +6 -4
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DefaultizedPieSeriesType, DefaultizedPieValueType } from '../../models/seriesType/pie';
|
|
2
|
-
import { DefaultizedProps } from '../../models/helpers';
|
|
1
|
+
import { ComputedPieRadius, DefaultizedPieSeriesType, DefaultizedPieValueType } from '../../models/seriesType/pie';
|
|
3
2
|
export interface AnimatedObject {
|
|
4
3
|
innerRadius: number;
|
|
5
4
|
outerRadius: number;
|
|
@@ -12,4 +11,4 @@ export interface ValueWithHighlight extends DefaultizedPieValueType, AnimatedObj
|
|
|
12
11
|
isFaded: boolean;
|
|
13
12
|
isHighlighted: boolean;
|
|
14
13
|
}
|
|
15
|
-
export declare function useTransformData(series:
|
|
14
|
+
export declare function useTransformData(series: Pick<DefaultizedPieSeriesType, 'cornerRadius' | 'paddingAngle' | 'id' | 'highlightScope' | 'highlighted' | 'faded' | 'data'> & ComputedPieRadius): ValueWithHighlight[];
|
|
@@ -69,11 +69,11 @@ const useChartDimensions = (inWidth, inHeight) => {
|
|
|
69
69
|
}, [computeSize, inHeight, inWidth]);
|
|
70
70
|
if (process.env.NODE_ENV !== 'production') {
|
|
71
71
|
if (displayError.current && inWidth === undefined && width === 0) {
|
|
72
|
-
console.error(`MUI:
|
|
72
|
+
console.error(`MUI-X-Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
|
|
73
73
|
displayError.current = false;
|
|
74
74
|
}
|
|
75
75
|
if (displayError.current && inHeight === undefined && height === 0) {
|
|
76
|
-
console.error(`MUI:
|
|
76
|
+
console.error(`MUI-X-Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
|
|
77
77
|
displayError.current = false;
|
|
78
78
|
}
|
|
79
79
|
}
|
package/ScatterChart/Scatter.js
CHANGED
|
@@ -32,10 +32,16 @@ function Scatter(props) {
|
|
|
32
32
|
color,
|
|
33
33
|
markerSize
|
|
34
34
|
} = props;
|
|
35
|
+
const highlightScope = React.useMemo(() => (0, _extends2.default)({
|
|
36
|
+
highlighted: 'item',
|
|
37
|
+
faded: 'global'
|
|
38
|
+
}, series.highlightScope), [series.highlightScope]);
|
|
35
39
|
const {
|
|
36
|
-
item
|
|
40
|
+
item,
|
|
41
|
+
useVoronoiInteraction
|
|
37
42
|
} = React.useContext(_InteractionProvider.InteractionContext);
|
|
38
|
-
const
|
|
43
|
+
const skipInteractionHandlers = useVoronoiInteraction || series.disableHover;
|
|
44
|
+
const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope, skipInteractionHandlers);
|
|
39
45
|
const cleanData = React.useMemo(() => {
|
|
40
46
|
const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
|
|
41
47
|
const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
|
|
@@ -57,22 +63,24 @@ function Scatter(props) {
|
|
|
57
63
|
dataIndex: i
|
|
58
64
|
};
|
|
59
65
|
if (isInRange) {
|
|
66
|
+
const isHighlighted = (0, _useInteractionItemProps.getIsHighlighted)(item, pointCtx, highlightScope);
|
|
60
67
|
temp.push({
|
|
61
68
|
x,
|
|
62
69
|
y,
|
|
63
|
-
|
|
70
|
+
isHighlighted,
|
|
71
|
+
isFaded: !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(item, pointCtx, highlightScope),
|
|
64
72
|
interactionProps: getInteractionItemProps(pointCtx),
|
|
65
73
|
id: scatterPoint.id
|
|
66
74
|
});
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
return temp;
|
|
70
|
-
}, [
|
|
78
|
+
}, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps]);
|
|
71
79
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
72
80
|
children: cleanData.map(dataPoint => /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", (0, _extends2.default)({
|
|
73
81
|
cx: 0,
|
|
74
82
|
cy: 0,
|
|
75
|
-
r: markerSize,
|
|
83
|
+
r: (dataPoint.isHighlighted ? 1.2 : 1) * markerSize,
|
|
76
84
|
transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
|
|
77
85
|
fill: color,
|
|
78
86
|
opacity: dataPoint.isFaded && 0.3 || 1
|
|
@@ -93,6 +101,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
|
|
|
93
101
|
x: _propTypes.default.number.isRequired,
|
|
94
102
|
y: _propTypes.default.number.isRequired
|
|
95
103
|
})).isRequired,
|
|
104
|
+
disableHover: _propTypes.default.bool,
|
|
96
105
|
highlightScope: _propTypes.default.shape({
|
|
97
106
|
faded: _propTypes.default.oneOf(['global', 'none', 'series']),
|
|
98
107
|
highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
|
|
@@ -8,14 +8,20 @@ import { ChartsTooltipProps, ChartsTooltipSlotProps, ChartsTooltipSlots } from '
|
|
|
8
8
|
import { ChartsLegendProps, ChartsLegendSlotProps, ChartsLegendSlots } from '../ChartsLegend';
|
|
9
9
|
import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
|
|
10
10
|
import { ChartsAxisSlots, ChartsAxisSlotProps } from '../models/axis';
|
|
11
|
+
import { ChartsVoronoiHandlerProps } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
|
|
11
12
|
export interface ScatterChartSlots extends ChartsAxisSlots, ScatterPlotSlots, ChartsLegendSlots, ChartsTooltipSlots {
|
|
12
13
|
}
|
|
13
14
|
export interface ScatterChartSlotProps extends ChartsAxisSlotProps, ScatterPlotSlotProps, ChartsLegendSlotProps, ChartsTooltipSlotProps {
|
|
14
15
|
}
|
|
15
|
-
export interface ScatterChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'
|
|
16
|
+
export interface ScatterChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, ChartsVoronoiHandlerProps {
|
|
16
17
|
series: MakeOptional<ScatterSeriesType, 'type'>[];
|
|
17
18
|
tooltip?: ChartsTooltipProps;
|
|
18
19
|
axisHighlight?: ChartsAxisHighlightProps;
|
|
20
|
+
/**
|
|
21
|
+
* If true, the interaction will not use the Voronoi cell and fall back to hover events.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disableVoronoi?: boolean;
|
|
19
25
|
/**
|
|
20
26
|
* @deprecated Consider using `slotProps.legend` instead.
|
|
21
27
|
*/
|
|
@@ -14,6 +14,7 @@ var _ChartsAxis = require("../ChartsAxis");
|
|
|
14
14
|
var _ChartsTooltip = require("../ChartsTooltip");
|
|
15
15
|
var _ChartsLegend = require("../ChartsLegend");
|
|
16
16
|
var _ChartsAxisHighlight = require("../ChartsAxisHighlight");
|
|
17
|
+
var _ChartsVoronoiHandler = require("../ChartsVoronoiHandler/ChartsVoronoiHandler");
|
|
17
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
19
|
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); }
|
|
19
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; }
|
|
@@ -34,6 +35,8 @@ const ScatterChart = exports.ScatterChart = /*#__PURE__*/React.forwardRef(functi
|
|
|
34
35
|
series,
|
|
35
36
|
tooltip,
|
|
36
37
|
axisHighlight,
|
|
38
|
+
voronoiMaxRadius,
|
|
39
|
+
disableVoronoi,
|
|
37
40
|
legend,
|
|
38
41
|
width,
|
|
39
42
|
height,
|
|
@@ -60,7 +63,9 @@ const ScatterChart = exports.ScatterChart = /*#__PURE__*/React.forwardRef(functi
|
|
|
60
63
|
xAxis: xAxis,
|
|
61
64
|
yAxis: yAxis,
|
|
62
65
|
sx: sx,
|
|
63
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
66
|
+
children: [!disableVoronoi && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsVoronoiHandler.ChartsVoronoiHandler, {
|
|
67
|
+
voronoiMaxRadius: voronoiMaxRadius
|
|
68
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, {
|
|
64
69
|
topAxis: topAxis,
|
|
65
70
|
leftAxis: leftAxis,
|
|
66
71
|
rightAxis: rightAxis,
|
|
@@ -134,6 +139,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
134
139
|
* @default false
|
|
135
140
|
*/
|
|
136
141
|
disableAxisListener: _propTypes.default.bool,
|
|
142
|
+
/**
|
|
143
|
+
* If true, the interaction will not use the Voronoi cell and fall back to hover events.
|
|
144
|
+
* @default false
|
|
145
|
+
*/
|
|
146
|
+
disableVoronoi: _propTypes.default.bool,
|
|
137
147
|
/**
|
|
138
148
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
139
149
|
* @default undefined
|
|
@@ -226,6 +236,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
226
236
|
x: _propTypes.default.number.isRequired,
|
|
227
237
|
y: _propTypes.default.number.isRequired
|
|
228
238
|
})).isRequired,
|
|
239
|
+
disableHover: _propTypes.default.bool,
|
|
229
240
|
highlightScope: _propTypes.default.shape({
|
|
230
241
|
faded: _propTypes.default.oneOf(['global', 'none', 'series']),
|
|
231
242
|
highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
|
|
@@ -291,6 +302,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
291
302
|
x: _propTypes.default.number,
|
|
292
303
|
y: _propTypes.default.number
|
|
293
304
|
}),
|
|
305
|
+
/**
|
|
306
|
+
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
|
|
307
|
+
* If `undefined`, the radius is assumed to be infinite.
|
|
308
|
+
* @default undefined
|
|
309
|
+
*/
|
|
310
|
+
voronoiMaxRadius: _propTypes.default.number,
|
|
294
311
|
/**
|
|
295
312
|
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
296
313
|
* @default undefined
|
|
@@ -86,6 +86,7 @@ const SparkLineChart = exports.SparkLineChart = /*#__PURE__*/React.forwardRef(fu
|
|
|
86
86
|
sx: sx,
|
|
87
87
|
disableAxisListener: (!showTooltip || tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
88
88
|
children: [plotType === 'bar' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarChart.BarPlot, {
|
|
89
|
+
skipAnimation: true,
|
|
89
90
|
slots: slots,
|
|
90
91
|
slotProps: slotProps,
|
|
91
92
|
sx: {
|
|
@@ -62,7 +62,7 @@ function CartesianContextProvider({
|
|
|
62
62
|
return axisConfig;
|
|
63
63
|
}
|
|
64
64
|
if (dataset === undefined) {
|
|
65
|
-
throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
65
|
+
throw Error('MUI-X-Charts: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
66
66
|
}
|
|
67
67
|
return (0, _extends2.default)({}, axisConfig, {
|
|
68
68
|
data: dataset.map(d => d[dataKey])
|
|
@@ -74,7 +74,7 @@ function CartesianContextProvider({
|
|
|
74
74
|
return axisConfig;
|
|
75
75
|
}
|
|
76
76
|
if (dataset === undefined) {
|
|
77
|
-
throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
77
|
+
throw Error('MUI-X-Charts: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
78
78
|
}
|
|
79
79
|
return (0, _extends2.default)({}, axisConfig, {
|
|
80
80
|
data: dataset.map(d => d[dataKey])
|
|
@@ -20,6 +20,11 @@ type InteractionActions<T extends ChartSeriesType = ChartSeriesType> = {
|
|
|
20
20
|
} | {
|
|
21
21
|
type: 'leaveItem';
|
|
22
22
|
data: ItemInteractionData<T>;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'exitChart';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'updateVoronoiUsage';
|
|
27
|
+
useVoronoiInteraction: boolean;
|
|
23
28
|
} | {
|
|
24
29
|
type: 'updateAxis';
|
|
25
30
|
data: AxisInteractionData;
|
|
@@ -33,6 +38,11 @@ type InteractionState = {
|
|
|
33
38
|
* The x- and y-axes currently interacting.
|
|
34
39
|
*/
|
|
35
40
|
axis: AxisInteractionData;
|
|
41
|
+
/**
|
|
42
|
+
* Set to `true` when `VoronoiHandler` is active.
|
|
43
|
+
* Used to prevent collision with mouseEnter events.
|
|
44
|
+
*/
|
|
45
|
+
useVoronoiInteraction: boolean;
|
|
36
46
|
dispatch: React.Dispatch<InteractionActions>;
|
|
37
47
|
};
|
|
38
48
|
export declare const InteractionContext: React.Context<InteractionState>;
|
|
@@ -17,6 +17,7 @@ const InteractionContext = exports.InteractionContext = /*#__PURE__*/React.creat
|
|
|
17
17
|
x: null,
|
|
18
18
|
y: null
|
|
19
19
|
},
|
|
20
|
+
useVoronoiInteraction: false,
|
|
20
21
|
dispatch: () => null
|
|
21
22
|
});
|
|
22
23
|
const dataReducer = (prevState, action) => {
|
|
@@ -25,6 +26,21 @@ const dataReducer = (prevState, action) => {
|
|
|
25
26
|
return (0, _extends2.default)({}, prevState, {
|
|
26
27
|
item: action.data
|
|
27
28
|
});
|
|
29
|
+
case 'exitChart':
|
|
30
|
+
if (prevState.item === null && prevState.axis.x === null && prevState.axis.y === null) {
|
|
31
|
+
return prevState;
|
|
32
|
+
}
|
|
33
|
+
return (0, _extends2.default)({}, prevState, {
|
|
34
|
+
axis: {
|
|
35
|
+
x: null,
|
|
36
|
+
y: null
|
|
37
|
+
},
|
|
38
|
+
item: null
|
|
39
|
+
});
|
|
40
|
+
case 'updateVoronoiUsage':
|
|
41
|
+
return (0, _extends2.default)({}, prevState, {
|
|
42
|
+
useVoronoiInteraction: action.useVoronoiInteraction
|
|
43
|
+
});
|
|
28
44
|
case 'leaveItem':
|
|
29
45
|
if (prevState.item === null || Object.keys(action.data).some(key => action.data[key] !== prevState.item[key])) {
|
|
30
46
|
// The item is already something else
|
|
@@ -34,6 +50,9 @@ const dataReducer = (prevState, action) => {
|
|
|
34
50
|
item: null
|
|
35
51
|
});
|
|
36
52
|
case 'updateAxis':
|
|
53
|
+
if (action.data.x === prevState.axis.x && action.data.y === prevState.axis.y) {
|
|
54
|
+
return prevState;
|
|
55
|
+
}
|
|
37
56
|
return (0, _extends2.default)({}, prevState, {
|
|
38
57
|
axis: action.data
|
|
39
58
|
});
|
|
@@ -49,7 +68,8 @@ function InteractionProvider({
|
|
|
49
68
|
axis: {
|
|
50
69
|
x: null,
|
|
51
70
|
y: null
|
|
52
|
-
}
|
|
71
|
+
},
|
|
72
|
+
useVoronoiInteraction: false
|
|
53
73
|
});
|
|
54
74
|
const value = React.useMemo(() => (0, _extends2.default)({}, data, {
|
|
55
75
|
dispatch
|
|
@@ -49,7 +49,7 @@ const formatSeries = (series, colors, dataset) => {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
if (seriesGroups[type]?.series[id] !== undefined) {
|
|
52
|
-
throw new Error(`MUI: series' id "${id}" is not unique`);
|
|
52
|
+
throw new Error(`MUI-X-Charts: series' id "${id}" is not unique`);
|
|
53
53
|
}
|
|
54
54
|
seriesGroups[type].series[id] = (0, _extends2.default)({
|
|
55
55
|
id
|
package/esm/BarChart/BarPlot.js
CHANGED
|
@@ -8,7 +8,8 @@ import { SeriesContext } from '../context/SeriesContextProvider';
|
|
|
8
8
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
9
|
import { BarElement } from './BarElement';
|
|
10
10
|
import { isBandScaleConfig } from '../models/axis';
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Solution of the equations
|
|
14
15
|
* W = barWidth * N + offset * (N-1)
|
|
@@ -18,6 +19,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
18
19
|
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
19
20
|
* @returns The bar width and the offset between bars.
|
|
20
21
|
*/
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
23
|
function getBandSize({
|
|
22
24
|
bandWidth: W,
|
|
23
25
|
numberOfGroups: N,
|
|
@@ -69,18 +71,18 @@ const useCompletedData = () => {
|
|
|
69
71
|
let baseScaleConfig;
|
|
70
72
|
if (verticalLayout) {
|
|
71
73
|
if (!isBandScaleConfig(xAxisConfig)) {
|
|
72
|
-
throw new Error(`
|
|
74
|
+
throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}"`);
|
|
73
75
|
}
|
|
74
76
|
if (xAxis[xAxisKey].data === undefined) {
|
|
75
|
-
throw new Error(`
|
|
77
|
+
throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property`);
|
|
76
78
|
}
|
|
77
79
|
baseScaleConfig = xAxisConfig;
|
|
78
80
|
} else {
|
|
79
81
|
if (!isBandScaleConfig(yAxisConfig)) {
|
|
80
|
-
throw new Error(`
|
|
82
|
+
throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}"`);
|
|
81
83
|
}
|
|
82
84
|
if (yAxis[yAxisKey].data === undefined) {
|
|
83
|
-
throw new Error(`
|
|
85
|
+
throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property`);
|
|
84
86
|
}
|
|
85
87
|
baseScaleConfig = yAxisConfig;
|
|
86
88
|
}
|
|
@@ -2,7 +2,9 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { stack as d3Stack } from 'd3-shape';
|
|
3
3
|
import { getStackingGroups } from '../internals/stackSeries';
|
|
4
4
|
import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
|
|
5
|
+
let warnOnce = false;
|
|
5
6
|
const formatter = (params, dataset) => {
|
|
7
|
+
var _ref;
|
|
6
8
|
const {
|
|
7
9
|
seriesOrder,
|
|
8
10
|
series
|
|
@@ -10,7 +12,7 @@ const formatter = (params, dataset) => {
|
|
|
10
12
|
const stackingGroups = getStackingGroups(params);
|
|
11
13
|
|
|
12
14
|
// Create a data set with format adapted to d3
|
|
13
|
-
const d3Dataset = dataset != null ?
|
|
15
|
+
const d3Dataset = (_ref = dataset) != null ? _ref : [];
|
|
14
16
|
seriesOrder.forEach(id => {
|
|
15
17
|
const data = series[id].data;
|
|
16
18
|
if (data !== undefined) {
|
|
@@ -24,7 +26,7 @@ const formatter = (params, dataset) => {
|
|
|
24
26
|
}
|
|
25
27
|
});
|
|
26
28
|
} else if (dataset === undefined) {
|
|
27
|
-
throw new Error([`MUI: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
29
|
+
throw new Error([`MUI-X-Charts: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
28
30
|
}
|
|
29
31
|
});
|
|
30
32
|
const completedSeries = {};
|
|
@@ -39,13 +41,27 @@ const formatter = (params, dataset) => {
|
|
|
39
41
|
// Use dataKey if needed and available
|
|
40
42
|
const dataKey = series[id].dataKey;
|
|
41
43
|
return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
|
|
42
|
-
})).
|
|
44
|
+
})).value((d, key) => {
|
|
45
|
+
var _d$key;
|
|
46
|
+
return (_d$key = d[key]) != null ? _d$key : 0;
|
|
47
|
+
}) // defaultize null value to 0
|
|
48
|
+
.order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
43
49
|
ids.forEach((id, index) => {
|
|
44
50
|
const dataKey = series[id].dataKey;
|
|
45
51
|
completedSeries[id] = _extends({
|
|
46
52
|
layout: 'vertical'
|
|
47
53
|
}, series[id], {
|
|
48
|
-
data: dataKey ? dataset.map(
|
|
54
|
+
data: dataKey ? dataset.map(data => {
|
|
55
|
+
const value = data[dataKey];
|
|
56
|
+
if (typeof value !== 'number') {
|
|
57
|
+
if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
|
|
58
|
+
warnOnce = true;
|
|
59
|
+
console.error([`MUI-X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
}) : series[id].data,
|
|
49
65
|
stackedData: stackedSeries[index].map(([a, b]) => [a, b])
|
|
50
66
|
});
|
|
51
67
|
});
|
|
@@ -59,16 +59,16 @@ function ChartsAxis(props) {
|
|
|
59
59
|
const topId = getAxisId(topAxis);
|
|
60
60
|
const rightId = getAxisId(rightAxis);
|
|
61
61
|
if (topId !== null && !xAxis[topId]) {
|
|
62
|
-
throw Error(`MUI: id used for top axis "${topId}" is not defined`);
|
|
62
|
+
throw Error([`MUI-X-Charts: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
|
|
63
63
|
}
|
|
64
64
|
if (leftId !== null && !yAxis[leftId]) {
|
|
65
|
-
throw Error(`MUI: id used for left axis "${leftId}" is not defined`);
|
|
65
|
+
throw Error([`MUI-X-Charts: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
|
|
66
66
|
}
|
|
67
67
|
if (rightId !== null && !yAxis[rightId]) {
|
|
68
|
-
throw Error(`MUI: id used for right axis "${rightId}" is not defined`);
|
|
68
|
+
throw Error([`MUI-X-Charts: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
|
|
69
69
|
}
|
|
70
70
|
if (bottomId !== null && !xAxis[bottomId]) {
|
|
71
|
-
throw Error(`MUI: id used for bottom axis "${bottomId}" is not defined`);
|
|
71
|
+
throw Error([`MUI-X-Charts: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
|
|
72
72
|
}
|
|
73
73
|
const topAxisProps = mergeProps(topAxis, slots, slotProps);
|
|
74
74
|
const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
|
|
@@ -12,7 +12,8 @@ import { DrawingContext } from '../context/DrawingProvider';
|
|
|
12
12
|
import { getSeriesToDisplay } from './utils';
|
|
13
13
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
14
14
|
import { getLegendUtilityClass } from './chartsLegendClasses';
|
|
15
|
-
import { ChartsText
|
|
15
|
+
import { ChartsText } from '../ChartsText';
|
|
16
|
+
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
16
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
const useUtilityClasses = ownerState => {
|
|
@@ -6,10 +6,10 @@ import { ChartsYReferenceLine } from './ChartsYReferenceLine';
|
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
function ChartsReferenceLine(props) {
|
|
8
8
|
if (props.x !== undefined && props.y !== undefined) {
|
|
9
|
-
throw new Error('MUI-X: The ChartsReferenceLine can not have both `x` and `y` props set.');
|
|
9
|
+
throw new Error('MUI-X-Charts: The ChartsReferenceLine can not have both `x` and `y` props set.');
|
|
10
10
|
}
|
|
11
11
|
if (props.x === undefined && props.y === undefined) {
|
|
12
|
-
throw new Error('MUI-X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
|
|
12
|
+
throw new Error('MUI-X-Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.');
|
|
13
13
|
}
|
|
14
14
|
if (props.x !== undefined) {
|
|
15
15
|
return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import composeClasses from '@mui/utils/composeClasses';
|
|
4
4
|
import { useDrawingArea, useXScale } from '../hooks';
|
|
5
5
|
import { ReferenceLineRoot } from './common';
|
|
6
|
-
import { ChartsText } from '../
|
|
6
|
+
import { ChartsText } from '../ChartsText';
|
|
7
7
|
import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import composeClasses from '@mui/utils/composeClasses';
|
|
4
4
|
import { useDrawingArea, useYScale } from '../hooks';
|
|
5
5
|
import { ReferenceLineRoot } from './common';
|
|
6
|
-
import { ChartsText } from '../
|
|
6
|
+
import { ChartsText } from '../ChartsText';
|
|
7
7
|
import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
const _excluded = ["x", "y", "style", "text", "ownerState"],
|
|
4
4
|
_excluded2 = ["angle", "textAnchor", "dominantBaseline"];
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}) {
|
|
13
|
-
return text.split('\n').map(subText => _extends({
|
|
14
|
-
text: subText
|
|
15
|
-
}, needsComputation ? getStringSize(subText, style) : {
|
|
16
|
-
width: 0,
|
|
17
|
-
height: 0
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
export function ChartsText(props) {
|
|
9
|
+
/**
|
|
10
|
+
* Helper component to manage multiline text in SVG
|
|
11
|
+
*/
|
|
12
|
+
function ChartsText(props) {
|
|
21
13
|
const {
|
|
22
14
|
x,
|
|
23
15
|
y,
|
|
@@ -74,4 +66,29 @@ export function ChartsText(props) {
|
|
|
74
66
|
children: line.text
|
|
75
67
|
}, index))
|
|
76
68
|
}));
|
|
77
|
-
}
|
|
69
|
+
}
|
|
70
|
+
process.env.NODE_ENV !== "production" ? ChartsText.propTypes = {
|
|
71
|
+
// ----------------------------- Warning --------------------------------
|
|
72
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
73
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
74
|
+
// ----------------------------------------------------------------------
|
|
75
|
+
/**
|
|
76
|
+
* Height of a text line (in `em`).
|
|
77
|
+
*/
|
|
78
|
+
lineHeight: PropTypes.number,
|
|
79
|
+
/**
|
|
80
|
+
* If `true`, the line width is computed.
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
needsComputation: PropTypes.bool,
|
|
84
|
+
ownerState: PropTypes.any,
|
|
85
|
+
/**
|
|
86
|
+
* Style applied to text elements.
|
|
87
|
+
*/
|
|
88
|
+
style: PropTypes.object,
|
|
89
|
+
/**
|
|
90
|
+
* Text displayed.
|
|
91
|
+
*/
|
|
92
|
+
text: PropTypes.string.isRequired
|
|
93
|
+
} : void 0;
|
|
94
|
+
export { ChartsText };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChartsText } from './ChartsText';
|