@mui/x-charts 7.5.1 → 7.6.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.js +18 -1
- package/BarChart/BarElement.d.ts +0 -3
- package/BarChart/BarElement.js +7 -18
- package/BarChart/BarLabel/BarLabelItem.js +5 -16
- package/BarChart/BarLabel/BarLabelPlot.js +0 -4
- package/BarChart/BarPlot.js +4 -30
- package/BarChart/checkScaleErrors.d.ts +11 -0
- package/BarChart/checkScaleErrors.js +33 -0
- package/BarChart/types.d.ts +0 -2
- package/CHANGELOG.md +112 -1
- package/ChartContainer/ChartContainer.d.ts +3 -2
- package/ChartContainer/ChartContainer.js +19 -2
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +13 -1
- package/LineChart/AreaElement.d.ts +0 -2
- package/LineChart/AreaElement.js +7 -17
- package/LineChart/AreaPlot.js +0 -2
- package/LineChart/LineChart.js +18 -1
- package/LineChart/LineElement.d.ts +0 -2
- package/LineChart/LineElement.js +7 -17
- package/LineChart/LinePlot.js +0 -2
- package/LineChart/MarkElement.d.ts +0 -2
- package/LineChart/MarkElement.js +10 -17
- package/LineChart/MarkPlot.js +0 -1
- package/PieChart/PieArc.d.ts +4 -1
- package/PieChart/PieArc.js +7 -3
- package/PieChart/PieArcLabelPlot.d.ts +1 -1
- package/PieChart/PieArcLabelPlot.js +1 -7
- package/PieChart/PieArcPlot.d.ts +1 -1
- package/PieChart/PieArcPlot.js +5 -7
- package/PieChart/PieChart.js +18 -1
- package/PieChart/PiePlot.js +2 -6
- package/PieChart/dataTransform/useTransformData.d.ts +1 -1
- package/PieChart/dataTransform/useTransformData.js +10 -25
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +13 -0
- package/ScatterChart/Scatter.js +14 -10
- package/ScatterChart/ScatterChart.js +18 -1
- package/SparkLineChart/SparkLineChart.js +13 -0
- package/context/HighlightedProvider/HighlightedContext.d.ts +65 -0
- package/context/HighlightedProvider/HighlightedContext.js +36 -0
- package/context/HighlightedProvider/HighlightedProvider.d.ts +20 -0
- package/context/HighlightedProvider/HighlightedProvider.js +97 -0
- package/context/HighlightedProvider/createIsFaded.d.ts +2 -0
- package/context/HighlightedProvider/createIsFaded.js +19 -0
- package/context/HighlightedProvider/createIsHighlighted.d.ts +2 -0
- package/context/HighlightedProvider/createIsHighlighted.js +19 -0
- package/context/HighlightedProvider/index.d.ts +4 -0
- package/context/HighlightedProvider/index.js +49 -0
- package/context/HighlightedProvider/useHighlighted.d.ts +9 -0
- package/context/HighlightedProvider/useHighlighted.js +24 -0
- package/context/HighlightedProvider/useItemHighlighted.d.ts +21 -0
- package/context/HighlightedProvider/useItemHighlighted.js +37 -0
- package/context/index.d.ts +1 -1
- package/context/index.js +15 -0
- package/esm/BarChart/BarChart.js +18 -1
- package/esm/BarChart/BarElement.js +8 -19
- package/esm/BarChart/BarLabel/BarLabelItem.js +5 -16
- package/esm/BarChart/BarLabel/BarLabelPlot.js +0 -4
- package/esm/BarChart/BarPlot.js +4 -30
- package/esm/BarChart/checkScaleErrors.js +27 -0
- package/esm/ChartContainer/ChartContainer.js +19 -2
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +13 -1
- package/esm/LineChart/AreaElement.js +8 -18
- package/esm/LineChart/AreaPlot.js +0 -2
- package/esm/LineChart/LineChart.js +18 -1
- package/esm/LineChart/LineElement.js +8 -18
- package/esm/LineChart/LinePlot.js +0 -2
- package/esm/LineChart/MarkElement.js +11 -18
- package/esm/LineChart/MarkPlot.js +0 -1
- package/esm/PieChart/PieArc.js +7 -3
- package/esm/PieChart/PieArcLabelPlot.js +1 -7
- package/esm/PieChart/PieArcPlot.js +5 -7
- package/esm/PieChart/PieChart.js +18 -1
- package/esm/PieChart/PiePlot.js +2 -6
- package/esm/PieChart/dataTransform/useTransformData.js +10 -25
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +13 -0
- package/esm/ScatterChart/Scatter.js +15 -11
- package/esm/ScatterChart/ScatterChart.js +18 -1
- package/esm/SparkLineChart/SparkLineChart.js +13 -0
- package/esm/context/HighlightedProvider/HighlightedContext.js +29 -0
- package/esm/context/HighlightedProvider/HighlightedProvider.js +89 -0
- package/esm/context/HighlightedProvider/createIsFaded.js +12 -0
- package/esm/context/HighlightedProvider/createIsHighlighted.js +12 -0
- package/esm/context/HighlightedProvider/index.js +4 -0
- package/esm/context/HighlightedProvider/useHighlighted.js +17 -0
- package/esm/context/HighlightedProvider/useItemHighlighted.js +29 -0
- package/esm/context/index.js +1 -0
- package/esm/hooks/useInteractionItemProps.js +9 -41
- package/hooks/useInteractionItemProps.d.ts +1 -4
- package/hooks/useInteractionItemProps.js +11 -45
- package/index.js +1 -1
- package/internals/colorScale.d.ts +1 -1
- package/internals/defaultizeColor.d.ts +13 -13
- package/models/seriesType/common.d.ts +4 -1
- package/modern/BarChart/BarChart.js +18 -1
- package/modern/BarChart/BarElement.js +8 -19
- package/modern/BarChart/BarLabel/BarLabelItem.js +5 -16
- package/modern/BarChart/BarLabel/BarLabelPlot.js +0 -4
- package/modern/BarChart/BarPlot.js +4 -30
- package/modern/BarChart/checkScaleErrors.js +27 -0
- package/modern/ChartContainer/ChartContainer.js +19 -2
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +13 -1
- package/modern/LineChart/AreaElement.js +8 -18
- package/modern/LineChart/AreaPlot.js +0 -2
- package/modern/LineChart/LineChart.js +18 -1
- package/modern/LineChart/LineElement.js +8 -18
- package/modern/LineChart/LinePlot.js +0 -2
- package/modern/LineChart/MarkElement.js +11 -18
- package/modern/LineChart/MarkPlot.js +0 -1
- package/modern/PieChart/PieArc.js +7 -3
- package/modern/PieChart/PieArcLabelPlot.js +1 -7
- package/modern/PieChart/PieArcPlot.js +5 -7
- package/modern/PieChart/PieChart.js +18 -1
- package/modern/PieChart/PiePlot.js +2 -6
- package/modern/PieChart/dataTransform/useTransformData.js +10 -25
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +13 -0
- package/modern/ScatterChart/Scatter.js +15 -11
- package/modern/ScatterChart/ScatterChart.js +18 -1
- package/modern/SparkLineChart/SparkLineChart.js +13 -0
- package/modern/context/HighlightedProvider/HighlightedContext.js +29 -0
- package/modern/context/HighlightedProvider/HighlightedProvider.js +89 -0
- package/modern/context/HighlightedProvider/createIsFaded.js +12 -0
- package/modern/context/HighlightedProvider/createIsHighlighted.js +12 -0
- package/modern/context/HighlightedProvider/index.js +4 -0
- package/modern/context/HighlightedProvider/useHighlighted.js +17 -0
- package/modern/context/HighlightedProvider/useItemHighlighted.js +29 -0
- package/modern/context/index.js +1 -0
- package/modern/hooks/useInteractionItemProps.js +9 -41
- package/modern/index.js +1 -1
- package/package.json +3 -3
- package/context/HighlightProvider.d.ts +0 -45
- package/context/HighlightProvider.js +0 -60
- package/esm/context/HighlightProvider.js +0 -51
- package/modern/context/HighlightProvider.js +0 -51
|
@@ -56,7 +56,9 @@ const ScatterChart = exports.ScatterChart = /*#__PURE__*/React.forwardRef(functi
|
|
|
56
56
|
children,
|
|
57
57
|
slots,
|
|
58
58
|
slotProps,
|
|
59
|
-
loading
|
|
59
|
+
loading,
|
|
60
|
+
highlightedItem,
|
|
61
|
+
onHighlightChange
|
|
60
62
|
} = props;
|
|
61
63
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ResponsiveChartContainer.ResponsiveChartContainer, {
|
|
62
64
|
ref: ref,
|
|
@@ -70,6 +72,8 @@ const ScatterChart = exports.ScatterChart = /*#__PURE__*/React.forwardRef(functi
|
|
|
70
72
|
xAxis: xAxis,
|
|
71
73
|
yAxis: yAxis,
|
|
72
74
|
sx: sx,
|
|
75
|
+
highlightedItem: highlightedItem,
|
|
76
|
+
onHighlightChange: onHighlightChange,
|
|
73
77
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ZAxisContextProvider.ZAxisContextProvider, {
|
|
74
78
|
zAxis: zAxis,
|
|
75
79
|
children: [!disableVoronoi && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsVoronoiHandler.ChartsVoronoiHandler, {
|
|
@@ -159,6 +163,13 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
159
163
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
160
164
|
*/
|
|
161
165
|
height: _propTypes.default.number,
|
|
166
|
+
/**
|
|
167
|
+
* The item currently highlighted. Turns highlighting into a controlled prop.
|
|
168
|
+
*/
|
|
169
|
+
highlightedItem: _propTypes.default.shape({
|
|
170
|
+
dataIndex: _propTypes.default.number,
|
|
171
|
+
seriesId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
172
|
+
}),
|
|
162
173
|
/**
|
|
163
174
|
* Indicate which axis to display the left of the charts.
|
|
164
175
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -196,6 +207,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
196
207
|
right: _propTypes.default.number,
|
|
197
208
|
top: _propTypes.default.number
|
|
198
209
|
}),
|
|
210
|
+
/**
|
|
211
|
+
* The callback fired when the highlighted item changes.
|
|
212
|
+
*
|
|
213
|
+
* @param {HighlightItemData | null} highlightedItem The newly highlighted item.
|
|
214
|
+
*/
|
|
215
|
+
onHighlightChange: _propTypes.default.func,
|
|
199
216
|
/**
|
|
200
217
|
* Callback fired when clicking on a scatter item.
|
|
201
218
|
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element if using Voronoi cells. Or the Mouse event from the scatter element, when `disableVoronoi=true`.
|
|
@@ -156,6 +156,13 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
156
156
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
157
157
|
*/
|
|
158
158
|
height: _propTypes.default.number,
|
|
159
|
+
/**
|
|
160
|
+
* The item currently highlighted. Turns highlighting into a controlled prop.
|
|
161
|
+
*/
|
|
162
|
+
highlightedItem: _propTypes.default.shape({
|
|
163
|
+
dataIndex: _propTypes.default.number,
|
|
164
|
+
seriesId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
165
|
+
}),
|
|
159
166
|
/**
|
|
160
167
|
* The margin between the SVG and the drawing area.
|
|
161
168
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
@@ -173,6 +180,12 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
173
180
|
right: _propTypes.default.number,
|
|
174
181
|
top: _propTypes.default.number
|
|
175
182
|
}),
|
|
183
|
+
/**
|
|
184
|
+
* The callback fired when the highlighted item changes.
|
|
185
|
+
*
|
|
186
|
+
* @param {HighlightItemData | null} highlightedItem The newly highlighted item.
|
|
187
|
+
*/
|
|
188
|
+
onHighlightChange: _propTypes.default.func,
|
|
176
189
|
/**
|
|
177
190
|
* Type of plot used.
|
|
178
191
|
* @default 'line'
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SeriesId } from '../../models/seriesType/common';
|
|
3
|
+
/**
|
|
4
|
+
* The data of the highlighted item.
|
|
5
|
+
* To highlight an item, you need to provide the series id and the item id.
|
|
6
|
+
* If targeting the whole series, you can omit the item id.
|
|
7
|
+
* To clear the highlight, set the value to an empty object.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Highlight the item with the series id 'london' and the item id 0.
|
|
11
|
+
* { seriesId: 'london', dataIndex: 0 }
|
|
12
|
+
*
|
|
13
|
+
* // Highlight the whole series with the series id 'london'.
|
|
14
|
+
* { seriesId: 'london' }
|
|
15
|
+
*
|
|
16
|
+
* // Clear the highlight.
|
|
17
|
+
* {}
|
|
18
|
+
*/
|
|
19
|
+
export type HighlightItemData = {
|
|
20
|
+
/**
|
|
21
|
+
* The series id of the highlighted item.
|
|
22
|
+
*/
|
|
23
|
+
seriesId?: SeriesId;
|
|
24
|
+
/**
|
|
25
|
+
* The index of the item in series data.
|
|
26
|
+
*/
|
|
27
|
+
dataIndex?: number;
|
|
28
|
+
};
|
|
29
|
+
export type HighlightOptions = 'none' | 'item' | 'series';
|
|
30
|
+
export type FadeOptions = 'none' | 'series' | 'global';
|
|
31
|
+
export type HighlightScope = {
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use `highlight` instead.
|
|
34
|
+
*/
|
|
35
|
+
highlighted?: HighlightOptions;
|
|
36
|
+
/**
|
|
37
|
+
* The scope of highlighted elements.
|
|
38
|
+
* - 'none': no highlight.
|
|
39
|
+
* - 'item': only highlight the item.
|
|
40
|
+
* - 'series': highlight all elements of the same series.
|
|
41
|
+
* @default 'none'
|
|
42
|
+
*/
|
|
43
|
+
highlight?: HighlightOptions;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use `fade` instead.
|
|
46
|
+
*/
|
|
47
|
+
faded?: FadeOptions;
|
|
48
|
+
/**
|
|
49
|
+
* The scope of faded elements.
|
|
50
|
+
* - 'none': no fading.
|
|
51
|
+
* - 'series': only fade element of the same series.
|
|
52
|
+
* - 'global': fade all elements that are not highlighted.
|
|
53
|
+
* @default 'none'
|
|
54
|
+
*/
|
|
55
|
+
fade?: FadeOptions;
|
|
56
|
+
};
|
|
57
|
+
export type HighlightedState = {
|
|
58
|
+
highlightScope?: Partial<HighlightScope>;
|
|
59
|
+
highlightedItem: HighlightItemData | null;
|
|
60
|
+
setHighlighted: (item: HighlightItemData) => void;
|
|
61
|
+
clearHighlighted: () => void;
|
|
62
|
+
isHighlighted: (input: HighlightItemData) => boolean;
|
|
63
|
+
isFaded: (input: HighlightItemData) => boolean;
|
|
64
|
+
};
|
|
65
|
+
export declare const HighlightedContext: React.Context<HighlightedState>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.HighlightedContext = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
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); }
|
|
9
|
+
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 && {}.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; }
|
|
10
|
+
/**
|
|
11
|
+
* The data of the highlighted item.
|
|
12
|
+
* To highlight an item, you need to provide the series id and the item id.
|
|
13
|
+
* If targeting the whole series, you can omit the item id.
|
|
14
|
+
* To clear the highlight, set the value to an empty object.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Highlight the item with the series id 'london' and the item id 0.
|
|
18
|
+
* { seriesId: 'london', dataIndex: 0 }
|
|
19
|
+
*
|
|
20
|
+
* // Highlight the whole series with the series id 'london'.
|
|
21
|
+
* { seriesId: 'london' }
|
|
22
|
+
*
|
|
23
|
+
* // Clear the highlight.
|
|
24
|
+
* {}
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const HighlightedContext = exports.HighlightedContext = /*#__PURE__*/React.createContext({
|
|
28
|
+
highlightedItem: null,
|
|
29
|
+
setHighlighted: () => {},
|
|
30
|
+
clearHighlighted: () => {},
|
|
31
|
+
isHighlighted: () => false,
|
|
32
|
+
isFaded: () => false
|
|
33
|
+
});
|
|
34
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
35
|
+
HighlightedContext.displayName = 'HighlightedContext';
|
|
36
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { HighlightItemData } from './HighlightedContext';
|
|
3
|
+
export type HighlightedProviderProps = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/**
|
|
6
|
+
* The item currently highlighted. Turns highlighting into a controlled prop.
|
|
7
|
+
*/
|
|
8
|
+
highlightedItem?: HighlightItemData | null;
|
|
9
|
+
/**
|
|
10
|
+
* The callback fired when the highlighted item changes.
|
|
11
|
+
*
|
|
12
|
+
* @param {HighlightItemData | null} highlightedItem The newly highlighted item.
|
|
13
|
+
*/
|
|
14
|
+
onHighlightChange?: (highlightedItem: HighlightItemData | null) => void;
|
|
15
|
+
};
|
|
16
|
+
declare function HighlightedProvider({ children, highlightedItem: highlightedItemProps, onHighlightChange, }: HighlightedProviderProps): React.JSX.Element;
|
|
17
|
+
declare namespace HighlightedProvider {
|
|
18
|
+
var propTypes: any;
|
|
19
|
+
}
|
|
20
|
+
export { HighlightedProvider };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.HighlightedProvider = HighlightedProvider;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
|
+
var _useControlled = _interopRequireDefault(require("@mui/utils/useControlled"));
|
|
13
|
+
var _HighlightedContext = require("./HighlightedContext");
|
|
14
|
+
var _createIsFaded = require("./createIsFaded");
|
|
15
|
+
var _createIsHighlighted = require("./createIsHighlighted");
|
|
16
|
+
var _useSeries = require("../../hooks/useSeries");
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
const _excluded = ["highlighted", "faded"];
|
|
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); }
|
|
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 && {}.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
|
+
const mergeDeprecatedOptions = options => {
|
|
22
|
+
const _ref = options ?? {},
|
|
23
|
+
{
|
|
24
|
+
highlighted,
|
|
25
|
+
faded
|
|
26
|
+
} = _ref,
|
|
27
|
+
rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
|
|
28
|
+
return (0, _extends2.default)({
|
|
29
|
+
highlight: highlighted,
|
|
30
|
+
fade: faded
|
|
31
|
+
}, rest);
|
|
32
|
+
};
|
|
33
|
+
function HighlightedProvider({
|
|
34
|
+
children,
|
|
35
|
+
highlightedItem: highlightedItemProps,
|
|
36
|
+
onHighlightChange
|
|
37
|
+
}) {
|
|
38
|
+
const [highlightedItem, setHighlightedItem] = (0, _useControlled.default)({
|
|
39
|
+
controlled: highlightedItemProps,
|
|
40
|
+
default: null,
|
|
41
|
+
name: 'HighlightedProvider',
|
|
42
|
+
state: 'highlightedItem'
|
|
43
|
+
});
|
|
44
|
+
const series = (0, _useSeries.useSeries)();
|
|
45
|
+
const seriesById = React.useMemo(() => {
|
|
46
|
+
const map = new Map();
|
|
47
|
+
Object.keys(series).forEach(seriesType => {
|
|
48
|
+
const seriesData = series[seriesType];
|
|
49
|
+
Object.keys(seriesData?.series ?? {}).forEach(seriesId => {
|
|
50
|
+
const seriesItem = seriesData?.series[seriesId];
|
|
51
|
+
map.set(seriesId, mergeDeprecatedOptions(seriesItem?.highlightScope));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return map;
|
|
55
|
+
}, [series]);
|
|
56
|
+
const highlightScope = highlightedItem && highlightedItem.seriesId ? seriesById.get(highlightedItem.seriesId) ?? undefined : undefined;
|
|
57
|
+
const providerValue = React.useMemo(() => {
|
|
58
|
+
return {
|
|
59
|
+
highlightScope,
|
|
60
|
+
highlightedItem,
|
|
61
|
+
setHighlighted: itemData => {
|
|
62
|
+
setHighlightedItem(itemData);
|
|
63
|
+
onHighlightChange?.(itemData);
|
|
64
|
+
},
|
|
65
|
+
clearHighlighted: () => {
|
|
66
|
+
setHighlightedItem(null);
|
|
67
|
+
onHighlightChange?.(null);
|
|
68
|
+
},
|
|
69
|
+
isHighlighted: (0, _createIsHighlighted.createIsHighlighted)(highlightScope, highlightedItem),
|
|
70
|
+
isFaded: (0, _createIsFaded.createIsFaded)(highlightScope, highlightedItem)
|
|
71
|
+
};
|
|
72
|
+
}, [highlightedItem, highlightScope, setHighlightedItem, onHighlightChange]);
|
|
73
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_HighlightedContext.HighlightedContext.Provider, {
|
|
74
|
+
value: providerValue,
|
|
75
|
+
children: children
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
process.env.NODE_ENV !== "production" ? HighlightedProvider.propTypes = {
|
|
79
|
+
// ----------------------------- Warning --------------------------------
|
|
80
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
81
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
82
|
+
// ----------------------------------------------------------------------
|
|
83
|
+
children: _propTypes.default.node,
|
|
84
|
+
/**
|
|
85
|
+
* The item currently highlighted. Turns highlighting into a controlled prop.
|
|
86
|
+
*/
|
|
87
|
+
highlightedItem: _propTypes.default.shape({
|
|
88
|
+
dataIndex: _propTypes.default.number,
|
|
89
|
+
seriesId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
90
|
+
}),
|
|
91
|
+
/**
|
|
92
|
+
* The callback fired when the highlighted item changes.
|
|
93
|
+
*
|
|
94
|
+
* @param {HighlightItemData | null} highlightedItem The newly highlighted item.
|
|
95
|
+
*/
|
|
96
|
+
onHighlightChange: _propTypes.default.func
|
|
97
|
+
} : void 0;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createIsFaded = void 0;
|
|
7
|
+
const createIsFaded = (highlightScope, highlightedItem) => input => {
|
|
8
|
+
if (!highlightScope) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (highlightScope.fade === 'series') {
|
|
12
|
+
return input.seriesId === highlightedItem?.seriesId && input.dataIndex !== highlightedItem?.dataIndex;
|
|
13
|
+
}
|
|
14
|
+
if (highlightScope.fade === 'global') {
|
|
15
|
+
return input.seriesId !== highlightedItem?.seriesId || input.dataIndex !== highlightedItem?.dataIndex;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
exports.createIsFaded = createIsFaded;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createIsHighlighted = void 0;
|
|
7
|
+
const createIsHighlighted = (highlightScope, highlightedItem) => input => {
|
|
8
|
+
if (!highlightScope) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (highlightScope.highlight === 'series') {
|
|
12
|
+
return input.seriesId === highlightedItem?.seriesId;
|
|
13
|
+
}
|
|
14
|
+
if (highlightScope.highlight === 'item') {
|
|
15
|
+
return input.dataIndex === highlightedItem?.dataIndex && input.seriesId === highlightedItem?.seriesId;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
exports.createIsHighlighted = createIsHighlighted;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _HighlightedProvider = require("./HighlightedProvider");
|
|
7
|
+
Object.keys(_HighlightedProvider).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _HighlightedProvider[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _HighlightedProvider[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _HighlightedContext = require("./HighlightedContext");
|
|
18
|
+
Object.keys(_HighlightedContext).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _HighlightedContext[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _HighlightedContext[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _useHighlighted = require("./useHighlighted");
|
|
29
|
+
Object.keys(_useHighlighted).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _useHighlighted[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _useHighlighted[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _useItemHighlighted = require("./useItemHighlighted");
|
|
40
|
+
Object.keys(_useItemHighlighted).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _useItemHighlighted[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _useItemHighlighted[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HighlightedState } from './HighlightedContext';
|
|
2
|
+
/**
|
|
3
|
+
* A hook to get the highlighted state of the chart.
|
|
4
|
+
*
|
|
5
|
+
* Please consider using the `useItemHighlighted` hook if you need to check the state of a specific item.
|
|
6
|
+
*
|
|
7
|
+
* @returns {HighlightedState} the state of the chart
|
|
8
|
+
*/
|
|
9
|
+
export declare function useHighlighted(): HighlightedState;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useHighlighted = useHighlighted;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _HighlightedContext = require("./HighlightedContext");
|
|
9
|
+
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); }
|
|
10
|
+
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 && {}.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; }
|
|
11
|
+
/**
|
|
12
|
+
* A hook to get the highlighted state of the chart.
|
|
13
|
+
*
|
|
14
|
+
* Please consider using the `useItemHighlighted` hook if you need to check the state of a specific item.
|
|
15
|
+
*
|
|
16
|
+
* @returns {HighlightedState} the state of the chart
|
|
17
|
+
*/
|
|
18
|
+
function useHighlighted() {
|
|
19
|
+
const highlighted = React.useContext(_HighlightedContext.HighlightedContext);
|
|
20
|
+
if (highlighted === undefined) {
|
|
21
|
+
throw new Error(['MUI X: Could not find the highlighted ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
22
|
+
}
|
|
23
|
+
return highlighted;
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HighlightItemData } from './HighlightedContext';
|
|
2
|
+
export type ItemHighlightedState = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether the item is highlighted.
|
|
5
|
+
*/
|
|
6
|
+
isHighlighted: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the item is faded.
|
|
9
|
+
*/
|
|
10
|
+
isFaded: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A hook to check the highlighted state of the item.
|
|
14
|
+
* This function already calculates that an item is not faded if it is highlighted.
|
|
15
|
+
*
|
|
16
|
+
* If you need fine control over the state, use the `useHighlighted` hook instead.
|
|
17
|
+
*
|
|
18
|
+
* @param {HighlightItemData} item is the item to check
|
|
19
|
+
* @returns {ItemHighlightedState} the state of the item
|
|
20
|
+
*/
|
|
21
|
+
export declare function useItemHighlighted(item: HighlightItemData | null): ItemHighlightedState;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useItemHighlighted = useItemHighlighted;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _HighlightedContext = require("./HighlightedContext");
|
|
9
|
+
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); }
|
|
10
|
+
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 && {}.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; }
|
|
11
|
+
/**
|
|
12
|
+
* A hook to check the highlighted state of the item.
|
|
13
|
+
* This function already calculates that an item is not faded if it is highlighted.
|
|
14
|
+
*
|
|
15
|
+
* If you need fine control over the state, use the `useHighlighted` hook instead.
|
|
16
|
+
*
|
|
17
|
+
* @param {HighlightItemData} item is the item to check
|
|
18
|
+
* @returns {ItemHighlightedState} the state of the item
|
|
19
|
+
*/
|
|
20
|
+
function useItemHighlighted(item) {
|
|
21
|
+
const highlighted = React.useContext(_HighlightedContext.HighlightedContext);
|
|
22
|
+
if (highlighted === undefined) {
|
|
23
|
+
throw new Error(['MUI X: Could not find the highlighted ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
24
|
+
}
|
|
25
|
+
if (!item) {
|
|
26
|
+
return {
|
|
27
|
+
isHighlighted: false,
|
|
28
|
+
isFaded: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const isHighlighted = highlighted.isHighlighted(item);
|
|
32
|
+
const isFaded = !isHighlighted && highlighted.isFaded(item);
|
|
33
|
+
return {
|
|
34
|
+
isHighlighted,
|
|
35
|
+
isFaded
|
|
36
|
+
};
|
|
37
|
+
}
|
package/context/index.d.ts
CHANGED
package/context/index.js
CHANGED
|
@@ -3,10 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
ZAxisContextProvider: true
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "ZAxisContextProvider", {
|
|
7
10
|
enumerable: true,
|
|
8
11
|
get: function () {
|
|
9
12
|
return _ZAxisContextProvider.ZAxisContextProvider;
|
|
10
13
|
}
|
|
11
14
|
});
|
|
15
|
+
var _HighlightedProvider = require("./HighlightedProvider");
|
|
16
|
+
Object.keys(_HighlightedProvider).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _HighlightedProvider[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _HighlightedProvider[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
12
27
|
var _ZAxisContextProvider = require("./ZAxisContextProvider");
|
package/esm/BarChart/BarChart.js
CHANGED
|
@@ -53,7 +53,9 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
53
53
|
slots,
|
|
54
54
|
slotProps,
|
|
55
55
|
loading,
|
|
56
|
-
barLabel
|
|
56
|
+
barLabel,
|
|
57
|
+
highlightedItem,
|
|
58
|
+
onHighlightChange
|
|
57
59
|
} = props;
|
|
58
60
|
const id = useId();
|
|
59
61
|
const clipPathId = `${id}-clip-path`;
|
|
@@ -89,6 +91,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
89
91
|
dataset: dataset,
|
|
90
92
|
sx: sx,
|
|
91
93
|
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
|
|
94
|
+
highlightedItem: highlightedItem,
|
|
95
|
+
onHighlightChange: onHighlightChange,
|
|
92
96
|
children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
|
|
93
97
|
onAxisClick: onAxisClick
|
|
94
98
|
}), grid && /*#__PURE__*/_jsx(ChartsGrid, {
|
|
@@ -188,6 +192,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
188
192
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
189
193
|
*/
|
|
190
194
|
height: PropTypes.number,
|
|
195
|
+
/**
|
|
196
|
+
* The item currently highlighted. Turns highlighting into a controlled prop.
|
|
197
|
+
*/
|
|
198
|
+
highlightedItem: PropTypes.shape({
|
|
199
|
+
dataIndex: PropTypes.number,
|
|
200
|
+
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
201
|
+
}),
|
|
191
202
|
/**
|
|
192
203
|
* The direction of the bar elements.
|
|
193
204
|
* @default 'vertical'
|
|
@@ -237,6 +248,12 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
237
248
|
* @param {null | AxisData} data The data about the clicked axis and items associated with it.
|
|
238
249
|
*/
|
|
239
250
|
onAxisClick: PropTypes.func,
|
|
251
|
+
/**
|
|
252
|
+
* The callback fired when the highlighted item changes.
|
|
253
|
+
*
|
|
254
|
+
* @param {HighlightItemData | null} highlightedItem The newly highlighted item.
|
|
255
|
+
*/
|
|
256
|
+
onHighlightChange: PropTypes.func,
|
|
240
257
|
/**
|
|
241
258
|
* Callback fired when a bar item is clicked.
|
|
242
259
|
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
@@ -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", "
|
|
3
|
+
const _excluded = ["id", "dataIndex", "classes", "color", "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';
|
|
@@ -10,8 +10,8 @@ import { styled } from '@mui/material/styles';
|
|
|
10
10
|
import { color as d3Color } from 'd3-color';
|
|
11
11
|
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
12
12
|
import { animated } from '@react-spring/web';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
14
|
+
import { useItemHighlighted } from '../context';
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
export function getBarElementUtilityClass(slot) {
|
|
17
17
|
return generateUtilityClass('MuiBarElement', slot);
|
|
@@ -45,27 +45,20 @@ function BarElement(props) {
|
|
|
45
45
|
dataIndex,
|
|
46
46
|
classes: innerClasses,
|
|
47
47
|
color,
|
|
48
|
-
highlightScope,
|
|
49
48
|
slots,
|
|
50
49
|
slotProps,
|
|
51
50
|
style,
|
|
52
51
|
onClick
|
|
53
52
|
} = props,
|
|
54
53
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
55
|
-
const getInteractionItemProps = useInteractionItemProps(
|
|
54
|
+
const getInteractionItemProps = useInteractionItemProps();
|
|
56
55
|
const {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
type: 'bar',
|
|
61
|
-
seriesId: id,
|
|
62
|
-
dataIndex
|
|
63
|
-
}, highlightScope);
|
|
64
|
-
const isFaded = !isHighlighted && getIsFaded(item, {
|
|
65
|
-
type: 'bar',
|
|
56
|
+
isFaded,
|
|
57
|
+
isHighlighted
|
|
58
|
+
} = useItemHighlighted({
|
|
66
59
|
seriesId: id,
|
|
67
60
|
dataIndex
|
|
68
|
-
}
|
|
61
|
+
});
|
|
69
62
|
const ownerState = {
|
|
70
63
|
id,
|
|
71
64
|
dataIndex,
|
|
@@ -101,10 +94,6 @@ process.env.NODE_ENV !== "production" ? BarElement.propTypes = {
|
|
|
101
94
|
// ----------------------------------------------------------------------
|
|
102
95
|
classes: PropTypes.object,
|
|
103
96
|
dataIndex: PropTypes.number.isRequired,
|
|
104
|
-
highlightScope: PropTypes.shape({
|
|
105
|
-
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
106
|
-
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
107
|
-
}),
|
|
108
97
|
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
109
98
|
/**
|
|
110
99
|
* The props used for each component slot.
|