@mui/x-charts 6.0.0-alpha.7 → 6.0.0-alpha.9

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.
Files changed (92) hide show
  1. package/BarChart/BarChart.d.ts +1 -0
  2. package/BarChart/BarChart.js +26 -13
  3. package/BarChart/BarPlot.js +25 -15
  4. package/BarChart/extremums.js +19 -3
  5. package/BarChart/formatter.js +3 -1
  6. package/CHANGELOG.md +212 -31
  7. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +3 -2
  8. package/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  9. package/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  10. package/LineChart/AreaElement.d.ts +1 -1
  11. package/LineChart/LineChart.d.ts +7 -2
  12. package/LineChart/LineChart.js +15 -3
  13. package/LineChart/LineElement.d.ts +1 -1
  14. package/LineChart/LineHighlightElement.d.ts +21 -0
  15. package/LineChart/LineHighlightElement.js +79 -0
  16. package/LineChart/LineHighlightPlot.d.ts +25 -0
  17. package/LineChart/LineHighlightPlot.js +99 -0
  18. package/LineChart/MarkElement.d.ts +1 -1
  19. package/LineChart/MarkElement.js +1 -4
  20. package/LineChart/MarkPlot.js +34 -15
  21. package/LineChart/index.d.ts +2 -0
  22. package/LineChart/index.js +20 -0
  23. package/PieChart/PieArc.d.ts +1 -1
  24. package/PieChart/PieArcLabel.d.ts +1 -1
  25. package/PieChart/PieChart.js +1 -1
  26. package/ScatterChart/ScatterChart.js +1 -1
  27. package/SparkLineChart/SparkLineChart.d.ts +3 -2
  28. package/SparkLineChart/SparkLineChart.js +7 -12
  29. package/context/CartesianContextProvider.js +4 -4
  30. package/esm/BarChart/BarChart.js +30 -17
  31. package/esm/BarChart/BarPlot.js +26 -16
  32. package/esm/BarChart/extremums.js +18 -2
  33. package/esm/BarChart/formatter.js +3 -1
  34. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  35. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  36. package/esm/LineChart/LineChart.js +15 -3
  37. package/esm/LineChart/LineHighlightElement.js +68 -0
  38. package/esm/LineChart/LineHighlightPlot.js +92 -0
  39. package/esm/LineChart/MarkElement.js +1 -4
  40. package/esm/LineChart/MarkPlot.js +34 -15
  41. package/esm/LineChart/index.js +3 -1
  42. package/esm/PieChart/PieChart.js +1 -1
  43. package/esm/ScatterChart/ScatterChart.js +1 -1
  44. package/esm/SparkLineChart/SparkLineChart.js +8 -13
  45. package/esm/context/CartesianContextProvider.js +4 -4
  46. package/esm/hooks/useAxisEvents.js +21 -38
  47. package/esm/hooks/useTicks.js +2 -2
  48. package/hooks/useAxisEvents.js +21 -38
  49. package/hooks/useTicks.js +2 -2
  50. package/index.js +1 -1
  51. package/internals/defaultizeColor.d.ts +3 -0
  52. package/legacy/BarChart/BarChart.js +35 -20
  53. package/legacy/BarChart/BarPlot.js +26 -16
  54. package/legacy/BarChart/extremums.js +22 -2
  55. package/legacy/BarChart/formatter.js +3 -1
  56. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  57. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  58. package/legacy/LineChart/LineChart.js +15 -3
  59. package/legacy/LineChart/LineHighlightElement.js +67 -0
  60. package/legacy/LineChart/LineHighlightPlot.js +85 -0
  61. package/legacy/LineChart/MarkElement.js +1 -4
  62. package/legacy/LineChart/MarkPlot.js +24 -6
  63. package/legacy/LineChart/index.js +3 -1
  64. package/legacy/PieChart/PieChart.js +1 -1
  65. package/legacy/ScatterChart/ScatterChart.js +1 -1
  66. package/legacy/SparkLineChart/SparkLineChart.js +8 -11
  67. package/legacy/context/CartesianContextProvider.js +4 -4
  68. package/legacy/hooks/useAxisEvents.js +21 -37
  69. package/legacy/hooks/useTicks.js +2 -2
  70. package/legacy/index.js +1 -1
  71. package/models/seriesType/bar.d.ts +6 -1
  72. package/models/seriesType/line.d.ts +33 -0
  73. package/modern/BarChart/BarChart.js +27 -14
  74. package/modern/BarChart/BarPlot.js +25 -15
  75. package/modern/BarChart/extremums.js +18 -2
  76. package/modern/BarChart/formatter.js +3 -1
  77. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  78. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  79. package/modern/LineChart/LineChart.js +15 -3
  80. package/modern/LineChart/LineHighlightElement.js +68 -0
  81. package/modern/LineChart/LineHighlightPlot.js +91 -0
  82. package/modern/LineChart/MarkElement.js +1 -4
  83. package/modern/LineChart/MarkPlot.js +34 -15
  84. package/modern/LineChart/index.js +3 -1
  85. package/modern/PieChart/PieChart.js +1 -1
  86. package/modern/ScatterChart/ScatterChart.js +1 -1
  87. package/modern/SparkLineChart/SparkLineChart.js +8 -13
  88. package/modern/context/CartesianContextProvider.js +4 -4
  89. package/modern/hooks/useAxisEvents.js +21 -38
  90. package/modern/hooks/useTicks.js +2 -2
  91. package/modern/index.js +1 -1
  92. package/package.json +4 -4
@@ -33,6 +33,7 @@ function ChartsAxisHighlight(props) {
33
33
  axis
34
34
  } = React.useContext(_InteractionProvider.InteractionContext);
35
35
  const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
36
+ const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
36
37
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
37
38
  children: [xAxisHighlight === 'band' && axis.x !== null && (0, _isBandScale.isBandScale)(xScale) && /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
38
39
  d: `M ${xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2} ${yScale.range()[0]} l ${xScale.step()} 0 l 0 ${yScale.range()[1] - yScale.range()[0]} l ${-xScale.step()} 0 Z`,
@@ -41,15 +42,22 @@ function ChartsAxisHighlight(props) {
41
42
  style: {
42
43
  pointerEvents: 'none'
43
44
  }
45
+ }), yAxisHighlight === 'band' && axis.y !== null && (0, _isBandScale.isBandScale)(yScale) && /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
46
+ d: `M ${xScale.range()[0]} ${yScale(axis.y.value) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${xScale.range()[1] - xScale.range()[0]} 0 l 0 ${-yScale.step()} Z`,
47
+ fill: "gray",
48
+ fillOpacity: 0.1,
49
+ style: {
50
+ pointerEvents: 'none'
51
+ }
44
52
  }), xAxisHighlight === 'line' && axis.x !== null && /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
45
- d: `M ${getXPosition(axis.x.value)} ${yScale(yScale.domain()[0])} L ${getXPosition(axis.x.value)} ${yScale(yScale.domain().at(-1))}`,
53
+ d: `M ${getXPosition(axis.x.value)} ${yScale.range()[0]} L ${getXPosition(axis.x.value)} ${yScale.range()[1]}`,
46
54
  stroke: "black",
47
55
  strokeDasharray: "5 2",
48
56
  style: {
49
57
  pointerEvents: 'none'
50
58
  }
51
59
  }), yAxisHighlight === 'line' && axis.y !== null && /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
52
- d: `M ${xScale.range()[0]} ${yScale(axis.y.value)} L ${xScale.range()[1]} ${yScale(axis.y.value)}`,
60
+ d: `M ${xScale.range()[0]} ${getYPosition(axis.y.value)} L ${xScale.range()[1]} ${getYPosition(axis.y.value)}`,
53
61
  stroke: "black",
54
62
  strokeDasharray: "5 2",
55
63
  style: {
@@ -64,5 +72,5 @@ process.env.NODE_ENV !== "production" ? ChartsAxisHighlight.propTypes = {
64
72
  // | To update them edit the TypeScript types and run "yarn proptypes" |
65
73
  // ----------------------------------------------------------------------
66
74
  x: _propTypes.default.oneOf(['band', 'line', 'none']),
67
- y: _propTypes.default.oneOf(['line', 'none'])
75
+ y: _propTypes.default.oneOf(['band', 'line', 'none'])
68
76
  } : void 0;
@@ -80,29 +80,33 @@ function ChartsAxisTooltipContent(props) {
80
80
  sx,
81
81
  classes
82
82
  } = props;
83
- const dataIndex = axisData.x && axisData.x.index;
84
- const axisValue = axisData.x && axisData.x.value;
83
+ const isXaxis = (axisData.x && axisData.x.index) !== undefined;
84
+ const dataIndex = isXaxis ? axisData.x && axisData.x.index : axisData.y && axisData.y.index;
85
+ const axisValue = isXaxis ? axisData.x && axisData.x.value : axisData.y && axisData.y.value;
85
86
  const {
86
87
  xAxisIds,
87
- xAxis
88
+ xAxis,
89
+ yAxisIds,
90
+ yAxis
88
91
  } = React.useContext(_CartesianContextProvider.CartesianContext);
89
92
  const series = React.useContext(_SeriesContextProvider.SeriesContext);
90
- const USED_X_AXIS_ID = xAxisIds[0];
93
+ const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
91
94
  const relevantSeries = React.useMemo(() => {
92
95
  const rep = [];
93
96
  Object.keys(series).filter(seriesType => ['bar', 'line', 'scatter'].includes(seriesType)).forEach(seriesType => {
94
97
  series[seriesType].seriesOrder.forEach(seriesId => {
95
- const axisKey = series[seriesType].series[seriesId].xAxisKey;
96
- if (axisKey === undefined || axisKey === USED_X_AXIS_ID) {
98
+ const item = series[seriesType].series[seriesId];
99
+ const axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
100
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
97
101
  rep.push(series[seriesType].series[seriesId]);
98
102
  }
99
103
  });
100
104
  });
101
105
  return rep;
102
- }, [USED_X_AXIS_ID, series]);
106
+ }, [USED_AXIS_ID, isXaxis, series]);
103
107
  const relevantAxis = React.useMemo(() => {
104
- return xAxis[USED_X_AXIS_ID];
105
- }, [USED_X_AXIS_ID, xAxis]);
108
+ return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
109
+ }, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
106
110
  const Content = content ?? DefaultChartsAxisContent;
107
111
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Content, {
108
112
  axisData: axisData,
@@ -10,7 +10,7 @@ export interface AreaElementClasses {
10
10
  faded: string;
11
11
  }
12
12
  export type AreaElementClassKey = keyof AreaElementClasses;
13
- export interface AreaElementOwnerState {
13
+ interface AreaElementOwnerState {
14
14
  id: string;
15
15
  color: string;
16
16
  isFaded: boolean;
@@ -10,15 +10,20 @@ import { ChartsTooltipProps } from '../ChartsTooltip';
10
10
  import { ChartsLegendProps, ChartsLegendSlotComponentProps, ChartsLegendSlotsComponent } from '../ChartsLegend';
11
11
  import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
12
12
  import { ChartsAxisSlotComponentProps, ChartsAxisSlotsComponent } from '../models/axis';
13
- export interface LineChartSlotsComponent extends ChartsAxisSlotsComponent, AreaPlotSlotsComponent, LinePlotSlotsComponent, MarkPlotSlotsComponent, ChartsLegendSlotsComponent {
13
+ import { LineHighlightPlotSlotsComponent, LineHighlightPlotSlotComponentProps } from './LineHighlightPlot';
14
+ export interface LineChartSlotsComponent extends ChartsAxisSlotsComponent, AreaPlotSlotsComponent, LinePlotSlotsComponent, MarkPlotSlotsComponent, LineHighlightPlotSlotsComponent, ChartsLegendSlotsComponent {
14
15
  }
15
- export interface LineChartSlotComponentProps extends ChartsAxisSlotComponentProps, AreaPlotSlotComponentProps, LinePlotSlotComponentProps, MarkPlotSlotComponentProps, ChartsLegendSlotComponentProps {
16
+ export interface LineChartSlotComponentProps extends ChartsAxisSlotComponentProps, AreaPlotSlotComponentProps, LinePlotSlotComponentProps, MarkPlotSlotComponentProps, LineHighlightPlotSlotComponentProps, ChartsLegendSlotComponentProps {
16
17
  }
17
18
  export interface LineChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'> {
18
19
  series: MakeOptional<LineSeriesType, 'type'>[];
19
20
  tooltip?: ChartsTooltipProps;
20
21
  axisHighlight?: ChartsAxisHighlightProps;
21
22
  legend?: ChartsLegendProps;
23
+ /**
24
+ * If `true`, render the line highlight item.
25
+ */
26
+ disableLineItemHighlight?: boolean;
22
27
  /**
23
28
  * Overridable component slots.
24
29
  * @default {}
@@ -19,6 +19,7 @@ var _ChartsTooltip = require("../ChartsTooltip");
19
19
  var _ChartsLegend = require("../ChartsLegend");
20
20
  var _ChartsAxisHighlight = require("../ChartsAxisHighlight");
21
21
  var _ChartsClipPath = require("../ChartsClipPath");
22
+ var _LineHighlightPlot = require("./LineHighlightPlot");
22
23
  var _jsxRuntime = require("react/jsx-runtime");
23
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -37,6 +38,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
37
38
  axisHighlight = {
38
39
  x: 'line'
39
40
  },
41
+ disableLineItemHighlight,
40
42
  legend,
41
43
  topAxis,
42
44
  leftAxis,
@@ -51,6 +53,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
51
53
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, {
52
54
  ref: ref,
53
55
  series: series.map(s => (0, _extends2.default)({
56
+ disableHighlight: !!disableLineItemHighlight,
54
57
  type: 'line'
55
58
  }, s)),
56
59
  width: width,
@@ -84,13 +87,16 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
84
87
  bottomAxis: bottomAxis,
85
88
  slots: slots,
86
89
  slotProps: slotProps
87
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_MarkPlot.MarkPlot, {
90
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, axisHighlight)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_MarkPlot.MarkPlot, {
91
+ slots: slots,
92
+ slotProps: slotProps
93
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_LineHighlightPlot.LineHighlightPlot, {
88
94
  slots: slots,
89
95
  slotProps: slotProps
90
96
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, (0, _extends2.default)({}, legend, {
91
97
  slots: slots,
92
98
  slotProps: slotProps
93
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, axisHighlight)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsClipPath.ChartsClipPath, {
99
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsClipPath.ChartsClipPath, {
94
100
  id: clipPathId
95
101
  }), children]
96
102
  });
@@ -103,7 +109,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
103
109
  // ----------------------------------------------------------------------
104
110
  axisHighlight: _propTypes.default.shape({
105
111
  x: _propTypes.default.oneOf(['band', 'line', 'none']),
106
- y: _propTypes.default.oneOf(['line', 'none'])
112
+ y: _propTypes.default.oneOf(['band', 'line', 'none'])
107
113
  }),
108
114
  /**
109
115
  * Indicate which axis to display the bottom of the charts.
@@ -137,6 +143,10 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
137
143
  dataset: _propTypes.default.arrayOf(_propTypes.default.object),
138
144
  desc: _propTypes.default.string,
139
145
  disableAxisListener: _propTypes.default.bool,
146
+ /**
147
+ * If `true`, render the line highlight item.
148
+ */
149
+ disableLineItemHighlight: _propTypes.default.bool,
140
150
  height: _propTypes.default.number,
141
151
  /**
142
152
  * Indicate which axis to display the left of the charts.
@@ -214,12 +224,14 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
214
224
  curve: _propTypes.default.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
215
225
  data: _propTypes.default.arrayOf(_propTypes.default.number),
216
226
  dataKey: _propTypes.default.string,
227
+ disableHighlight: _propTypes.default.bool,
217
228
  highlightScope: _propTypes.default.shape({
218
229
  faded: _propTypes.default.oneOf(['global', 'none', 'series']),
219
230
  highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
220
231
  }),
221
232
  id: _propTypes.default.string,
222
233
  label: _propTypes.default.string,
234
+ showMark: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.bool]),
223
235
  stack: _propTypes.default.string,
224
236
  stackOffset: _propTypes.default.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
225
237
  stackOrder: _propTypes.default.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
@@ -10,7 +10,7 @@ export interface LineElementClasses {
10
10
  faded: string;
11
11
  }
12
12
  export type LineElementClassKey = keyof LineElementClasses;
13
- export interface LineElementOwnerState {
13
+ interface LineElementOwnerState {
14
14
  id: string;
15
15
  color: string;
16
16
  isFaded: boolean;
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ export interface LineHighlightElementClasses {
3
+ /** Styles applied to the root element. */
4
+ root: string;
5
+ }
6
+ export type HighlightElementClassKey = keyof LineHighlightElementClasses;
7
+ interface LineHighlightElementOwnerState {
8
+ id: string;
9
+ color: string;
10
+ x: number;
11
+ y: number;
12
+ classes?: Partial<LineHighlightElementClasses>;
13
+ }
14
+ export declare function getHighlightElementUtilityClass(slot: string): string;
15
+ export declare const lineHighlightElementClasses: LineHighlightElementClasses;
16
+ export type LineHighlightElementProps = LineHighlightElementOwnerState & React.ComponentPropsWithoutRef<'circle'> & {};
17
+ declare function LineHighlightElement(props: LineHighlightElementProps): React.JSX.Element;
18
+ declare namespace LineHighlightElement {
19
+ var propTypes: any;
20
+ }
21
+ export { LineHighlightElement };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.LineHighlightElement = LineHighlightElement;
8
+ exports.getHighlightElementUtilityClass = getHighlightElementUtilityClass;
9
+ exports.lineHighlightElementClasses = void 0;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
+ var React = _interopRequireWildcard(require("react"));
13
+ var _propTypes = _interopRequireDefault(require("prop-types"));
14
+ var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
15
+ var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
16
+ var _styles = require("@mui/material/styles");
17
+ var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ const _excluded = ["x", "y", "id", "classes", "color"];
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
+ function getHighlightElementUtilityClass(slot) {
23
+ return (0, _generateUtilityClass.default)('MuiHighlightElement', slot);
24
+ }
25
+ const lineHighlightElementClasses = (0, _generateUtilityClasses.default)('MuiHighlightElement', ['root']);
26
+ exports.lineHighlightElementClasses = lineHighlightElementClasses;
27
+ const useUtilityClasses = ownerState => {
28
+ const {
29
+ classes,
30
+ id
31
+ } = ownerState;
32
+ const slots = {
33
+ root: ['root', `series-${id}`]
34
+ };
35
+ return (0, _composeClasses.default)(slots, getHighlightElementUtilityClass, classes);
36
+ };
37
+ const HighlightElement = (0, _styles.styled)('circle', {
38
+ name: 'MuiHighlightElement',
39
+ slot: 'Root',
40
+ overridesResolver: (_, styles) => styles.root
41
+ })(({
42
+ ownerState
43
+ }) => ({
44
+ transform: `translate(${ownerState.x}px, ${ownerState.y}px)`,
45
+ transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
46
+ fill: ownerState.color
47
+ }));
48
+ function LineHighlightElement(props) {
49
+ const {
50
+ x,
51
+ y,
52
+ id,
53
+ classes: innerClasses,
54
+ color
55
+ } = props,
56
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
57
+ const ownerState = {
58
+ id,
59
+ classes: innerClasses,
60
+ color,
61
+ x,
62
+ y
63
+ };
64
+ const classes = useUtilityClasses(ownerState);
65
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(HighlightElement, (0, _extends2.default)({}, other, {
66
+ ownerState: ownerState,
67
+ className: classes.root,
68
+ cx: 0,
69
+ cy: 0,
70
+ r: other.r === undefined ? 5 : other.r
71
+ }));
72
+ }
73
+ process.env.NODE_ENV !== "production" ? LineHighlightElement.propTypes = {
74
+ // ----------------------------- Warning --------------------------------
75
+ // | These PropTypes are generated from the TypeScript type definitions |
76
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
77
+ // ----------------------------------------------------------------------
78
+ classes: _propTypes.default.object
79
+ } : void 0;
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ import { LineHighlightElementProps } from './LineHighlightElement';
3
+ export interface LineHighlightPlotSlotsComponent {
4
+ lineHighlight?: React.JSXElementConstructor<LineHighlightElementProps>;
5
+ }
6
+ export interface LineHighlightPlotSlotComponentProps {
7
+ lineHighlight?: Partial<LineHighlightElementProps>;
8
+ }
9
+ export interface LineHighlightPlotProps extends React.SVGAttributes<SVGSVGElement> {
10
+ /**
11
+ * Overridable component slots.
12
+ * @default {}
13
+ */
14
+ slots?: LineHighlightPlotSlotsComponent;
15
+ /**
16
+ * The props used for each component slot.
17
+ * @default {}
18
+ */
19
+ slotProps?: LineHighlightPlotSlotComponentProps;
20
+ }
21
+ declare function LineHighlightPlot(props: LineHighlightPlotProps): React.JSX.Element | null;
22
+ declare namespace LineHighlightPlot {
23
+ var propTypes: any;
24
+ }
25
+ export { LineHighlightPlot };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.LineHighlightPlot = LineHighlightPlot;
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 _SeriesContextProvider = require("../context/SeriesContextProvider");
13
+ var _CartesianContextProvider = require("../context/CartesianContextProvider");
14
+ var _LineHighlightElement = require("./LineHighlightElement");
15
+ var _useScale = require("../hooks/useScale");
16
+ var _InteractionProvider = require("../context/InteractionProvider");
17
+ var _jsxRuntime = require("react/jsx-runtime");
18
+ const _excluded = ["slots", "slotProps"];
19
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+ function LineHighlightPlot(props) {
22
+ const {
23
+ slots,
24
+ slotProps
25
+ } = props,
26
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
27
+ const seriesData = React.useContext(_SeriesContextProvider.SeriesContext).line;
28
+ const axisData = React.useContext(_CartesianContextProvider.CartesianContext);
29
+ const {
30
+ axis
31
+ } = React.useContext(_InteractionProvider.InteractionContext);
32
+ const highlightedIndex = axis.x?.index;
33
+ if (highlightedIndex === undefined) {
34
+ return null;
35
+ }
36
+ if (seriesData === undefined) {
37
+ return null;
38
+ }
39
+ const {
40
+ series,
41
+ stackingGroups
42
+ } = seriesData;
43
+ const {
44
+ xAxis,
45
+ yAxis,
46
+ xAxisIds,
47
+ yAxisIds
48
+ } = axisData;
49
+ const defaultXAxisId = xAxisIds[0];
50
+ const defaultYAxisId = yAxisIds[0];
51
+ const Element = slots?.lineHighlight ?? _LineHighlightElement.LineHighlightElement;
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", (0, _extends2.default)({}, other, {
53
+ children: stackingGroups.flatMap(({
54
+ ids: groupIds
55
+ }) => {
56
+ return groupIds.flatMap(seriesId => {
57
+ const {
58
+ xAxisKey = defaultXAxisId,
59
+ yAxisKey = defaultYAxisId,
60
+ stackedData,
61
+ disableHighlight
62
+ } = series[seriesId];
63
+ if (disableHighlight) {
64
+ return null;
65
+ }
66
+ const xScale = (0, _useScale.getValueToPositionMapper)(xAxis[xAxisKey].scale);
67
+ const yScale = yAxis[yAxisKey].scale;
68
+ const xData = xAxis[xAxisKey].data;
69
+ if (xData === undefined) {
70
+ throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
71
+ }
72
+ const x = xScale(xData[highlightedIndex]);
73
+ const y = yScale(stackedData[highlightedIndex][1]);
74
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Element, (0, _extends2.default)({
75
+ id: seriesId,
76
+ color: series[seriesId].color,
77
+ x: x,
78
+ y: y
79
+ }, slotProps?.lineHighlight), `${seriesId}`);
80
+ });
81
+ })
82
+ }));
83
+ }
84
+ process.env.NODE_ENV !== "production" ? LineHighlightPlot.propTypes = {
85
+ // ----------------------------- Warning --------------------------------
86
+ // | These PropTypes are generated from the TypeScript type definitions |
87
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
88
+ // ----------------------------------------------------------------------
89
+ /**
90
+ * The props used for each component slot.
91
+ * @default {}
92
+ */
93
+ slotProps: _propTypes.default.object,
94
+ /**
95
+ * Overridable component slots.
96
+ * @default {}
97
+ */
98
+ slots: _propTypes.default.object
99
+ } : void 0;
@@ -9,7 +9,7 @@ export interface MarkElementClasses {
9
9
  faded: string;
10
10
  }
11
11
  export type MarkElementClassKey = keyof MarkElementClasses;
12
- export interface MarkElementOwnerState {
12
+ interface MarkElementOwnerState {
13
13
  id: string;
14
14
  color: string;
15
15
  isFaded: boolean;
@@ -52,10 +52,7 @@ const MarkElementPath = (0, _styles.styled)('path', {
52
52
  transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
53
53
  fill: theme.palette.background.paper,
54
54
  stroke: ownerState.color,
55
- strokeWidth: 2,
56
- '&.MuiMarkElement-highlighted': {
57
- fill: ownerState.color
58
- }
55
+ strokeWidth: 2
59
56
  }));
60
57
  MarkElementPath.propTypes = {
61
58
  // ----------------------------- Warning --------------------------------
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.MarkPlot = MarkPlot;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
10
  var React = _interopRequireWildcard(require("react"));
10
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
12
  var _SeriesContextProvider = require("../context/SeriesContextProvider");
@@ -13,13 +14,15 @@ var _CartesianContextProvider = require("../context/CartesianContextProvider");
13
14
  var _MarkElement = require("./MarkElement");
14
15
  var _useScale = require("../hooks/useScale");
15
16
  var _jsxRuntime = require("react/jsx-runtime");
17
+ const _excluded = ["slots", "slotProps"];
16
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
19
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
20
  function MarkPlot(props) {
19
21
  const {
20
- slots,
21
- slotProps
22
- } = props;
22
+ slots,
23
+ slotProps
24
+ } = props,
25
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
23
26
  const seriesData = React.useContext(_SeriesContextProvider.SeriesContext).line;
24
27
  const axisData = React.useContext(_CartesianContextProvider.CartesianContext);
25
28
  const Mark = slots?.mark ?? _MarkElement.MarkElement;
@@ -38,7 +41,7 @@ function MarkPlot(props) {
38
41
  } = axisData;
39
42
  const defaultXAxisId = xAxisIds[0];
40
43
  const defaultYAxisId = yAxisIds[0];
41
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", (0, _extends2.default)({}, props, {
44
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", (0, _extends2.default)({}, other, {
42
45
  children: stackingGroups.flatMap(({
43
46
  ids: groupIds
44
47
  }) => {
@@ -46,8 +49,12 @@ function MarkPlot(props) {
46
49
  const {
47
50
  xAxisKey = defaultXAxisId,
48
51
  yAxisKey = defaultYAxisId,
49
- stackedData
52
+ stackedData,
53
+ showMark = true
50
54
  } = series[seriesId];
55
+ if (showMark === false) {
56
+ return null;
57
+ }
51
58
  const xScale = (0, _useScale.getValueToPositionMapper)(xAxis[xAxisKey].scale);
52
59
  const yScale = yAxis[yAxisKey].scale;
53
60
  const xData = xAxis[xAxisKey].data;
@@ -73,21 +80,33 @@ function MarkPlot(props) {
73
80
  return {
74
81
  x: xScale(x),
75
82
  y: yScale(y),
83
+ position: x,
84
+ value: y,
76
85
  index
77
86
  };
78
87
  }).filter(isInRange).map(({
79
88
  x,
80
89
  y,
81
- index
82
- }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(Mark, (0, _extends2.default)({
83
- id: seriesId,
84
- dataIndex: index,
85
- shape: "circle",
86
- color: series[seriesId].color,
87
- x: x,
88
- y: y,
89
- highlightScope: series[seriesId].highlightScope
90
- }, slotProps?.mark), `${seriesId}-${index}`));
90
+ index,
91
+ position,
92
+ value
93
+ }) => {
94
+ return showMark === true || showMark({
95
+ x,
96
+ y,
97
+ index,
98
+ position,
99
+ value
100
+ }) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Mark, (0, _extends2.default)({
101
+ id: seriesId,
102
+ dataIndex: index,
103
+ shape: "circle",
104
+ color: series[seriesId].color,
105
+ x: x,
106
+ y: y,
107
+ highlightScope: series[seriesId].highlightScope
108
+ }, slotProps?.mark), `${seriesId}-${index}`) : null;
109
+ });
91
110
  });
92
111
  })
93
112
  }));
@@ -1,7 +1,9 @@
1
1
  export { LinePlot } from './LinePlot';
2
2
  export { AreaPlot } from './AreaPlot';
3
3
  export { MarkPlot } from './MarkPlot';
4
+ export { LineHighlightPlot } from './LineHighlightPlot';
4
5
  export { LineChart } from './LineChart';
5
6
  export * from './AreaElement';
6
7
  export * from './LineElement';
7
8
  export * from './MarkElement';
9
+ export * from './LineHighlightElement';
@@ -7,6 +7,7 @@ var _exportNames = {
7
7
  LinePlot: true,
8
8
  AreaPlot: true,
9
9
  MarkPlot: true,
10
+ LineHighlightPlot: true,
10
11
  LineChart: true
11
12
  };
12
13
  Object.defineProperty(exports, "AreaPlot", {
@@ -21,6 +22,12 @@ Object.defineProperty(exports, "LineChart", {
21
22
  return _LineChart.LineChart;
22
23
  }
23
24
  });
25
+ Object.defineProperty(exports, "LineHighlightPlot", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _LineHighlightPlot.LineHighlightPlot;
29
+ }
30
+ });
24
31
  Object.defineProperty(exports, "LinePlot", {
25
32
  enumerable: true,
26
33
  get: function () {
@@ -36,6 +43,7 @@ Object.defineProperty(exports, "MarkPlot", {
36
43
  var _LinePlot = require("./LinePlot");
37
44
  var _AreaPlot = require("./AreaPlot");
38
45
  var _MarkPlot = require("./MarkPlot");
46
+ var _LineHighlightPlot = require("./LineHighlightPlot");
39
47
  var _LineChart = require("./LineChart");
40
48
  var _AreaElement = require("./AreaElement");
41
49
  Object.keys(_AreaElement).forEach(function (key) {
@@ -72,4 +80,16 @@ Object.keys(_MarkElement).forEach(function (key) {
72
80
  return _MarkElement[key];
73
81
  }
74
82
  });
83
+ });
84
+ var _LineHighlightElement = require("./LineHighlightElement");
85
+ Object.keys(_LineHighlightElement).forEach(function (key) {
86
+ if (key === "default" || key === "__esModule") return;
87
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
88
+ if (key in exports && exports[key] === _LineHighlightElement[key]) return;
89
+ Object.defineProperty(exports, key, {
90
+ enumerable: true,
91
+ get: function () {
92
+ return _LineHighlightElement[key];
93
+ }
94
+ });
75
95
  });
@@ -11,7 +11,7 @@ export interface PieArcClasses {
11
11
  faded: string;
12
12
  }
13
13
  export type PieArcClassKey = keyof PieArcClasses;
14
- export interface PieArcOwnerState {
14
+ interface PieArcOwnerState {
15
15
  id: string;
16
16
  dataIndex: number;
17
17
  color: string;
@@ -11,7 +11,7 @@ export interface PieArcLabelClasses {
11
11
  faded: string;
12
12
  }
13
13
  export type PieArcLabelClassKey = keyof PieArcLabelClasses;
14
- export interface PieArcLabelOwnerState {
14
+ interface PieArcLabelOwnerState {
15
15
  id: string;
16
16
  dataIndex: number;
17
17
  color: string;
@@ -96,7 +96,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
96
96
  // ----------------------------------------------------------------------
97
97
  axisHighlight: _propTypes.default.shape({
98
98
  x: _propTypes.default.oneOf(['band', 'line', 'none']),
99
- y: _propTypes.default.oneOf(['line', 'none'])
99
+ y: _propTypes.default.oneOf(['band', 'line', 'none'])
100
100
  }),
101
101
  /**
102
102
  * Indicate which axis to display the bottom of the charts.
@@ -79,7 +79,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
79
79
  // ----------------------------------------------------------------------
80
80
  axisHighlight: _propTypes.default.shape({
81
81
  x: _propTypes.default.oneOf(['band', 'line', 'none']),
82
- y: _propTypes.default.oneOf(['line', 'none'])
82
+ y: _propTypes.default.oneOf(['band', 'line', 'none'])
83
83
  }),
84
84
  /**
85
85
  * Indicate which axis to display the bottom of the charts.