@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/BarChart/BarChart.d.ts +2 -1
  2. package/BarChart/BarChart.js +23 -4
  3. package/BarChart/BarElement.d.ts +1 -1
  4. package/BarChart/BarElement.js +6 -3
  5. package/BarChart/BarPlot.d.ts +8 -1
  6. package/BarChart/BarPlot.js +19 -5
  7. package/BarChart/formatter.js +1 -1
  8. package/CHANGELOG.md +247 -0
  9. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
  10. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
  11. package/ChartsOnAxisClickHandler/index.d.ts +1 -0
  12. package/ChartsOnAxisClickHandler/index.js +16 -0
  13. package/ChartsOnAxisClickHandler/package.json +6 -0
  14. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  15. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  17. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -4
  18. package/ChartsTooltip/utils.d.ts +3 -1
  19. package/ChartsTooltip/utils.js +8 -0
  20. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
  21. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  22. package/LineChart/AnimatedArea.d.ts +1361 -0
  23. package/LineChart/AnimatedArea.js +111 -0
  24. package/LineChart/AnimatedLine.d.ts +1361 -0
  25. package/LineChart/AnimatedLine.js +113 -0
  26. package/LineChart/AreaElement.d.ts +17 -17
  27. package/LineChart/AreaElement.js +17 -34
  28. package/LineChart/AreaPlot.d.ts +12 -7
  29. package/LineChart/AreaPlot.js +91 -58
  30. package/LineChart/LineChart.d.ts +13 -4
  31. package/LineChart/LineChart.js +35 -6
  32. package/LineChart/LineElement.d.ts +17 -17
  33. package/LineChart/LineElement.js +16 -36
  34. package/LineChart/LineHighlightElement.js +3 -2
  35. package/LineChart/LinePlot.d.ts +12 -7
  36. package/LineChart/LinePlot.js +89 -56
  37. package/LineChart/MarkElement.d.ts +5 -2
  38. package/LineChart/MarkElement.js +26 -13
  39. package/LineChart/MarkPlot.d.ts +8 -1
  40. package/LineChart/MarkPlot.js +80 -51
  41. package/LineChart/formatter.js +1 -1
  42. package/LineChart/index.d.ts +2 -0
  43. package/LineChart/index.js +22 -0
  44. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  45. package/PieChart/PieArcLabelPlot.js +1 -1
  46. package/PieChart/PieArcPlot.d.ts +2 -2
  47. package/PieChart/PieArcPlot.js +6 -6
  48. package/PieChart/PieChart.d.ts +1 -1
  49. package/PieChart/PieChart.js +4 -4
  50. package/PieChart/PiePlot.d.ts +1 -1
  51. package/PieChart/PiePlot.js +4 -4
  52. package/ScatterChart/Scatter.d.ts +7 -1
  53. package/ScatterChart/Scatter.js +17 -3
  54. package/ScatterChart/ScatterChart.d.ts +8 -2
  55. package/ScatterChart/ScatterChart.js +11 -2
  56. package/ScatterChart/ScatterPlot.d.ts +1 -1
  57. package/ScatterChart/ScatterPlot.js +10 -2
  58. package/SparkLineChart/SparkLineChart.js +2 -0
  59. package/context/DrawingProvider.d.ts +6 -1
  60. package/context/DrawingProvider.js +9 -2
  61. package/context/InteractionProvider.d.ts +3 -3
  62. package/esm/BarChart/BarChart.js +23 -4
  63. package/esm/BarChart/BarElement.js +6 -3
  64. package/esm/BarChart/BarPlot.js +19 -5
  65. package/esm/BarChart/formatter.js +1 -1
  66. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
  67. package/esm/ChartsOnAxisClickHandler/index.js +1 -0
  68. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  69. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  70. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  71. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -4
  72. package/esm/ChartsTooltip/utils.js +6 -0
  73. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  74. package/esm/LineChart/AnimatedArea.js +103 -0
  75. package/esm/LineChart/AnimatedLine.js +105 -0
  76. package/esm/LineChart/AreaElement.js +16 -33
  77. package/esm/LineChart/AreaPlot.js +92 -59
  78. package/esm/LineChart/LineChart.js +35 -6
  79. package/esm/LineChart/LineElement.js +16 -35
  80. package/esm/LineChart/LineHighlightElement.js +3 -2
  81. package/esm/LineChart/LinePlot.js +90 -57
  82. package/esm/LineChart/MarkElement.js +26 -13
  83. package/esm/LineChart/MarkPlot.js +80 -51
  84. package/esm/LineChart/formatter.js +1 -1
  85. package/esm/LineChart/index.js +2 -0
  86. package/esm/PieChart/PieArcLabelPlot.js +1 -1
  87. package/esm/PieChart/PieArcPlot.js +6 -6
  88. package/esm/PieChart/PieChart.js +4 -4
  89. package/esm/PieChart/PiePlot.js +4 -4
  90. package/esm/ScatterChart/Scatter.js +17 -3
  91. package/esm/ScatterChart/ScatterChart.js +11 -2
  92. package/esm/ScatterChart/ScatterPlot.js +10 -2
  93. package/esm/SparkLineChart/SparkLineChart.js +2 -0
  94. package/esm/context/DrawingProvider.js +9 -2
  95. package/esm/hooks/useDrawingArea.js +7 -3
  96. package/esm/index.js +1 -0
  97. package/esm/internals/geometry.js +1 -1
  98. package/esm/internals/useAnimatedPath.js +29 -0
  99. package/esm/internals/utils.js +7 -0
  100. package/hooks/useDrawingArea.d.ts +2 -0
  101. package/hooks/useDrawingArea.js +7 -3
  102. package/index.d.ts +1 -0
  103. package/index.js +12 -1
  104. package/internals/geometry.js +1 -1
  105. package/internals/useAnimatedPath.d.ts +1 -0
  106. package/internals/useAnimatedPath.js +38 -0
  107. package/internals/utils.d.ts +4 -0
  108. package/internals/utils.js +8 -0
  109. package/legacy/BarChart/BarChart.js +23 -4
  110. package/legacy/BarChart/BarElement.js +5 -2
  111. package/legacy/BarChart/BarPlot.js +18 -4
  112. package/legacy/BarChart/formatter.js +1 -1
  113. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  114. package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
  115. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  116. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  117. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
  118. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -4
  119. package/legacy/ChartsTooltip/utils.js +6 -0
  120. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
  121. package/legacy/LineChart/AnimatedArea.js +102 -0
  122. package/legacy/LineChart/AnimatedLine.js +104 -0
  123. package/legacy/LineChart/AreaElement.js +15 -35
  124. package/legacy/LineChart/AreaPlot.js +102 -66
  125. package/legacy/LineChart/LineChart.js +35 -6
  126. package/legacy/LineChart/LineElement.js +15 -37
  127. package/legacy/LineChart/LineHighlightElement.js +3 -2
  128. package/legacy/LineChart/LinePlot.js +97 -63
  129. package/legacy/LineChart/MarkElement.js +29 -12
  130. package/legacy/LineChart/MarkPlot.js +83 -53
  131. package/legacy/LineChart/formatter.js +1 -1
  132. package/legacy/LineChart/index.js +2 -0
  133. package/legacy/PieChart/PieArcLabelPlot.js +1 -1
  134. package/legacy/PieChart/PieArcPlot.js +6 -6
  135. package/legacy/PieChart/PieChart.js +4 -4
  136. package/legacy/PieChart/PiePlot.js +4 -4
  137. package/legacy/ScatterChart/Scatter.js +19 -3
  138. package/legacy/ScatterChart/ScatterChart.js +11 -2
  139. package/legacy/ScatterChart/ScatterPlot.js +10 -2
  140. package/legacy/SparkLineChart/SparkLineChart.js +2 -0
  141. package/legacy/context/DrawingProvider.js +11 -2
  142. package/legacy/hooks/useDrawingArea.js +7 -3
  143. package/legacy/index.js +2 -1
  144. package/legacy/internals/geometry.js +1 -1
  145. package/legacy/internals/useAnimatedPath.js +32 -0
  146. package/legacy/internals/utils.js +7 -0
  147. package/modern/BarChart/BarChart.js +23 -4
  148. package/modern/BarChart/BarElement.js +6 -3
  149. package/modern/BarChart/BarPlot.js +19 -5
  150. package/modern/BarChart/formatter.js +1 -1
  151. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  152. package/modern/ChartsOnAxisClickHandler/index.js +1 -0
  153. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  154. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  155. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  156. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -4
  157. package/modern/ChartsTooltip/utils.js +6 -0
  158. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  159. package/modern/LineChart/AnimatedArea.js +103 -0
  160. package/modern/LineChart/AnimatedLine.js +105 -0
  161. package/modern/LineChart/AreaElement.js +16 -33
  162. package/modern/LineChart/AreaPlot.js +91 -58
  163. package/modern/LineChart/LineChart.js +35 -6
  164. package/modern/LineChart/LineElement.js +16 -35
  165. package/modern/LineChart/LineHighlightElement.js +3 -2
  166. package/modern/LineChart/LinePlot.js +89 -56
  167. package/modern/LineChart/MarkElement.js +26 -13
  168. package/modern/LineChart/MarkPlot.js +80 -51
  169. package/modern/LineChart/formatter.js +1 -1
  170. package/modern/LineChart/index.js +2 -0
  171. package/modern/PieChart/PieArcLabelPlot.js +1 -1
  172. package/modern/PieChart/PieArcPlot.js +6 -6
  173. package/modern/PieChart/PieChart.js +4 -4
  174. package/modern/PieChart/PiePlot.js +4 -4
  175. package/modern/ScatterChart/Scatter.js +17 -3
  176. package/modern/ScatterChart/ScatterChart.js +11 -2
  177. package/modern/ScatterChart/ScatterPlot.js +10 -2
  178. package/modern/SparkLineChart/SparkLineChart.js +2 -0
  179. package/modern/context/DrawingProvider.js +9 -2
  180. package/modern/hooks/useDrawingArea.js +7 -3
  181. package/modern/index.js +2 -1
  182. package/modern/internals/geometry.js +1 -1
  183. package/modern/internals/useAnimatedPath.js +29 -0
  184. package/modern/internals/utils.js +7 -0
  185. package/package.json +6 -5
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { SlotComponentProps } from '@mui/base/utils';
3
2
  import { HighlightScope } from '../context/HighlightProvider';
3
+ import { AnimatedLineProps } from './AnimatedLine';
4
4
  export interface LineElementClasses {
5
5
  /** Styles applied to the root element. */
6
6
  root: string;
@@ -10,7 +10,7 @@ export interface LineElementClasses {
10
10
  faded: string;
11
11
  }
12
12
  export type LineElementClassKey = keyof LineElementClasses;
13
- interface LineElementOwnerState {
13
+ export interface LineElementOwnerState {
14
14
  id: string;
15
15
  color: string;
16
16
  isFaded: boolean;
@@ -19,30 +19,30 @@ interface LineElementOwnerState {
19
19
  }
20
20
  export declare function getLineElementUtilityClass(slot: string): string;
21
21
  export declare const lineElementClasses: LineElementClasses;
22
- export declare const LineElementPath: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
23
- ownerState: LineElementOwnerState;
24
- }, Pick<React.SVGProps<SVGPathElement>, keyof React.SVGProps<SVGPathElement>>, {}>;
25
- export type LineElementProps = Omit<LineElementOwnerState, 'isFaded' | 'isHighlighted'> & React.ComponentPropsWithoutRef<'path'> & {
22
+ export interface LineElementSlots {
23
+ /**
24
+ * The component that renders the line.
25
+ * @default LineElementPath
26
+ */
27
+ line?: React.JSXElementConstructor<AnimatedLineProps>;
28
+ }
29
+ export interface LineElementSlotProps {
30
+ line?: AnimatedLineProps;
31
+ }
32
+ export interface LineElementProps extends Omit<LineElementOwnerState, 'isFaded' | 'isHighlighted'>, Pick<AnimatedLineProps, 'skipAnimation'>, Omit<React.ComponentPropsWithoutRef<'path'>, 'color' | 'id'> {
33
+ d: string;
26
34
  highlightScope?: Partial<HighlightScope>;
27
35
  /**
28
36
  * The props used for each component slot.
29
37
  * @default {}
30
38
  */
31
- slotProps?: {
32
- line?: SlotComponentProps<'path', {}, LineElementOwnerState>;
33
- };
39
+ slotProps?: LineElementSlotProps;
34
40
  /**
35
41
  * Overridable component slots.
36
42
  * @default {}
37
43
  */
38
- slots?: {
39
- /**
40
- * The component that renders the root.
41
- * @default LineElementPath
42
- */
43
- line?: React.ElementType;
44
- };
45
- };
44
+ slots?: LineElementSlots;
45
+ }
46
46
  /**
47
47
  * Demos:
48
48
  *
@@ -5,23 +5,21 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.LineElement = LineElement;
8
- exports.LineElementPath = void 0;
9
8
  exports.getLineElementUtilityClass = getLineElementUtilityClass;
10
9
  exports.lineElementClasses = void 0;
11
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
11
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
13
12
  var React = _interopRequireWildcard(require("react"));
14
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
15
- var _d3Color = require("d3-color");
16
14
  var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
17
15
  var _utils = require("@mui/base/utils");
18
16
  var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
19
- var _styles = require("@mui/material/styles");
20
17
  var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
21
18
  var _InteractionProvider = require("../context/InteractionProvider");
22
19
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
20
+ var _AnimatedLine = require("./AnimatedLine");
23
21
  var _jsxRuntime = require("react/jsx-runtime");
24
- const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps"];
22
+ const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps", "onClick"];
25
23
  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); }
26
24
  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; }
27
25
  function getLineElementUtilityClass(slot) {
@@ -40,35 +38,6 @@ const useUtilityClasses = ownerState => {
40
38
  };
41
39
  return (0, _composeClasses.default)(slots, getLineElementUtilityClass, classes);
42
40
  };
43
- const LineElementPath = exports.LineElementPath = (0, _styles.styled)('path', {
44
- name: 'MuiLineElement',
45
- slot: 'Root',
46
- overridesResolver: (_, styles) => styles.root
47
- })(({
48
- ownerState
49
- }) => ({
50
- strokeWidth: 2,
51
- strokeLinejoin: 'round',
52
- fill: 'none',
53
- stroke: ownerState.isHighlighted ? (0, _d3Color.color)(ownerState.color).brighter(0.5).formatHex() : ownerState.color,
54
- transition: 'opacity 0.2s ease-in, stroke 0.2s ease-in',
55
- opacity: ownerState.isFaded ? 0.3 : 1
56
- }));
57
- LineElementPath.propTypes = {
58
- // ----------------------------- Warning --------------------------------
59
- // | These PropTypes are generated from the TypeScript type definitions |
60
- // | To update them edit the TypeScript types and run "yarn proptypes" |
61
- // ----------------------------------------------------------------------
62
- as: _propTypes.default.elementType,
63
- ownerState: _propTypes.default.shape({
64
- classes: _propTypes.default.object,
65
- color: _propTypes.default.string.isRequired,
66
- id: _propTypes.default.string.isRequired,
67
- isFaded: _propTypes.default.bool.isRequired,
68
- isHighlighted: _propTypes.default.bool.isRequired
69
- }).isRequired,
70
- sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
71
- };
72
41
  /**
73
42
  * Demos:
74
43
  *
@@ -86,7 +55,8 @@ function LineElement(props) {
86
55
  color,
87
56
  highlightScope,
88
57
  slots,
89
- slotProps
58
+ slotProps,
59
+ onClick
90
60
  } = props,
91
61
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
92
62
  const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope);
@@ -109,7 +79,7 @@ function LineElement(props) {
109
79
  isHighlighted
110
80
  };
111
81
  const classes = useUtilityClasses(ownerState);
112
- const Line = slots?.line ?? LineElementPath;
82
+ const Line = slots?.line ?? _AnimatedLine.AnimatedLine;
113
83
  const lineProps = (0, _utils.useSlotProps)({
114
84
  elementType: Line,
115
85
  externalSlotProps: slotProps?.line,
@@ -117,7 +87,9 @@ function LineElement(props) {
117
87
  type: 'line',
118
88
  seriesId: id
119
89
  }), {
120
- className: classes.root
90
+ className: classes.root,
91
+ onClick,
92
+ cursor: onClick ? 'pointer' : 'unset'
121
93
  }),
122
94
  ownerState
123
95
  });
@@ -129,10 +101,18 @@ process.env.NODE_ENV !== "production" ? LineElement.propTypes = {
129
101
  // | To update them edit the TypeScript types and run "yarn proptypes" |
130
102
  // ----------------------------------------------------------------------
131
103
  classes: _propTypes.default.object,
104
+ color: _propTypes.default.string.isRequired,
105
+ d: _propTypes.default.string.isRequired,
132
106
  highlightScope: _propTypes.default.shape({
133
107
  faded: _propTypes.default.oneOf(['global', 'none', 'series']),
134
108
  highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
135
109
  }),
110
+ id: _propTypes.default.string.isRequired,
111
+ /**
112
+ * If `true`, animations are skipped.
113
+ * @default false
114
+ */
115
+ skipAnimation: _propTypes.default.bool,
136
116
  /**
137
117
  * The props used for each component slot.
138
118
  * @default {}
@@ -71,13 +71,14 @@ function LineHighlightElement(props) {
71
71
  y
72
72
  };
73
73
  const classes = useUtilityClasses(ownerState);
74
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(HighlightElement, (0, _extends2.default)({}, other, {
74
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(HighlightElement, (0, _extends2.default)({
75
+ pointerEvents: "none",
75
76
  ownerState: ownerState,
76
77
  className: classes.root,
77
78
  cx: 0,
78
79
  cy: 0,
79
80
  r: other.r === undefined ? 5 : other.r
80
- }));
81
+ }, other));
81
82
  }
82
83
  process.env.NODE_ENV !== "production" ? LineHighlightElement.propTypes = {
83
84
  // ----------------------------- Warning --------------------------------
@@ -1,12 +1,17 @@
1
1
  import * as React from 'react';
2
- import { LineElementProps } from './LineElement';
3
- export interface LinePlotSlots {
4
- line?: React.JSXElementConstructor<LineElementProps>;
2
+ import { LineElementProps, LineElementSlotProps, LineElementSlots } from './LineElement';
3
+ import { LineItemIdentifier } from '../models/seriesType/line';
4
+ export interface LinePlotSlots extends LineElementSlots {
5
5
  }
6
- export interface LinePlotSlotProps {
7
- line?: Partial<LineElementProps>;
6
+ export interface LinePlotSlotProps extends LineElementSlotProps {
8
7
  }
9
- export interface LinePlotProps extends React.SVGAttributes<SVGSVGElement>, Pick<LineElementProps, 'slots' | 'slotProps'> {
8
+ export interface LinePlotProps extends React.SVGAttributes<SVGSVGElement>, Pick<LineElementProps, 'slots' | 'slotProps' | 'skipAnimation'> {
9
+ /**
10
+ * Callback fired when a line item is clicked.
11
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
12
+ * @param {LineItemIdentifier} lineItemIdentifier The line item identifier.
13
+ */
14
+ onItemClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, lineItemIdentifier: LineItemIdentifier) => void;
10
15
  }
11
16
  /**
12
17
  * Demos:
@@ -18,7 +23,7 @@ export interface LinePlotProps extends React.SVGAttributes<SVGSVGElement>, Pick<
18
23
  *
19
24
  * - [LinePlot API](https://mui.com/x/api/charts/line-plot/)
20
25
  */
21
- declare function LinePlot(props: LinePlotProps): React.JSX.Element | null;
26
+ declare function LinePlot(props: LinePlotProps): React.JSX.Element;
22
27
  declare namespace LinePlot {
23
28
  var propTypes: any;
24
29
  }
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.LinePlot = LinePlot;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
8
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var React = _interopRequireWildcard(require("react"));
11
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
12
12
  var _d3Shape = require("d3-shape");
@@ -17,29 +17,14 @@ var _useScale = require("../hooks/useScale");
17
17
  var _getCurve = _interopRequireDefault(require("../internals/getCurve"));
18
18
  var _constants = require("../constants");
19
19
  var _jsxRuntime = require("react/jsx-runtime");
20
- const _excluded = ["slots", "slotProps"];
20
+ const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
21
21
  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); }
22
22
  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; }
23
- /**
24
- * Demos:
25
- *
26
- * - [Lines](https://mui.com/x/react-charts/lines/)
27
- * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
28
- *
29
- * API:
30
- *
31
- * - [LinePlot API](https://mui.com/x/api/charts/line-plot/)
32
- */
33
- function LinePlot(props) {
34
- const {
35
- slots,
36
- slotProps
37
- } = props,
38
- other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
23
+ const useAggregatedData = () => {
39
24
  const seriesData = React.useContext(_SeriesContextProvider.SeriesContext).line;
40
25
  const axisData = React.useContext(_CartesianContextProvider.CartesianContext);
41
26
  if (seriesData === undefined) {
42
- return null;
27
+ return [];
43
28
  }
44
29
  const {
45
30
  series,
@@ -53,45 +38,82 @@ function LinePlot(props) {
53
38
  } = axisData;
54
39
  const defaultXAxisId = xAxisIds[0];
55
40
  const defaultYAxisId = yAxisIds[0];
56
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", (0, _extends2.default)({}, other, {
57
- children: stackingGroups.flatMap(({
58
- ids: groupIds
59
- }) => {
60
- return groupIds.flatMap(seriesId => {
61
- const {
62
- xAxisKey = defaultXAxisId,
63
- yAxisKey = defaultYAxisId,
64
- stackedData,
65
- data,
66
- connectNulls
67
- } = series[seriesId];
68
- const xScale = (0, _useScale.getValueToPositionMapper)(xAxis[xAxisKey].scale);
69
- const yScale = yAxis[yAxisKey].scale;
70
- const xData = xAxis[xAxisKey].data;
71
- if (process.env.NODE_ENV !== 'production') {
72
- if (xData === undefined) {
73
- throw new Error(`MUI X Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
74
- }
75
- if (xData.length < stackedData.length) {
76
- throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
77
- }
41
+ return stackingGroups.flatMap(({
42
+ ids: groupIds
43
+ }) => {
44
+ return groupIds.flatMap(seriesId => {
45
+ const {
46
+ xAxisKey = defaultXAxisId,
47
+ yAxisKey = defaultYAxisId,
48
+ stackedData,
49
+ data,
50
+ connectNulls
51
+ } = series[seriesId];
52
+ const xScale = (0, _useScale.getValueToPositionMapper)(xAxis[xAxisKey].scale);
53
+ const yScale = yAxis[yAxisKey].scale;
54
+ const xData = xAxis[xAxisKey].data;
55
+ if (process.env.NODE_ENV !== 'production') {
56
+ if (xData === undefined) {
57
+ throw new Error(`MUI X Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
78
58
  }
79
- const linePath = (0, _d3Shape.line)().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y(d => yScale(d.y[1]));
80
- const curve = (0, _getCurve.default)(series[seriesId].curve);
81
- const formattedData = xData?.map((x, index) => ({
82
- x,
83
- y: stackedData[index]
84
- })) ?? [];
85
- const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
86
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LineElement.LineElement, {
87
- id: seriesId,
88
- d: linePath.curve(curve)(d3Data) || undefined,
89
- color: series[seriesId].color,
90
- highlightScope: series[seriesId].highlightScope,
91
- slots: slots,
92
- slotProps: slotProps
93
- }, seriesId);
59
+ if (xData.length < stackedData.length) {
60
+ throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
61
+ }
62
+ }
63
+ const linePath = (0, _d3Shape.line)().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y(d => yScale(d.y[1]));
64
+ const formattedData = xData?.map((x, index) => ({
65
+ x,
66
+ y: stackedData[index]
67
+ })) ?? [];
68
+ const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
69
+ const d = linePath.curve((0, _getCurve.default)(series[seriesId].curve))(d3Data) || '';
70
+ return (0, _extends2.default)({}, series[seriesId], {
71
+ d,
72
+ seriesId
94
73
  });
74
+ });
75
+ });
76
+ };
77
+
78
+ /**
79
+ * Demos:
80
+ *
81
+ * - [Lines](https://mui.com/x/react-charts/lines/)
82
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
83
+ *
84
+ * API:
85
+ *
86
+ * - [LinePlot API](https://mui.com/x/api/charts/line-plot/)
87
+ */
88
+ function LinePlot(props) {
89
+ const {
90
+ slots,
91
+ slotProps,
92
+ skipAnimation,
93
+ onItemClick
94
+ } = props,
95
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
96
+ const completedData = useAggregatedData();
97
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", (0, _extends2.default)({}, other, {
98
+ children: completedData.map(({
99
+ d,
100
+ seriesId,
101
+ color,
102
+ highlightScope
103
+ }) => {
104
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LineElement.LineElement, {
105
+ id: seriesId,
106
+ d: d,
107
+ color: color,
108
+ highlightScope: highlightScope,
109
+ skipAnimation: skipAnimation,
110
+ slots: slots,
111
+ slotProps: slotProps,
112
+ onClick: onItemClick && (event => onItemClick(event, {
113
+ type: 'line',
114
+ seriesId
115
+ }))
116
+ }, seriesId);
95
117
  })
96
118
  }));
97
119
  }
@@ -100,6 +122,17 @@ process.env.NODE_ENV !== "production" ? LinePlot.propTypes = {
100
122
  // | These PropTypes are generated from the TypeScript type definitions |
101
123
  // | To update them edit the TypeScript types and run "yarn proptypes" |
102
124
  // ----------------------------------------------------------------------
125
+ /**
126
+ * Callback fired when a line item is clicked.
127
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
128
+ * @param {LineItemIdentifier} lineItemIdentifier The line item identifier.
129
+ */
130
+ onItemClick: _propTypes.default.func,
131
+ /**
132
+ * If `true`, animations are skipped.
133
+ * @default false
134
+ */
135
+ skipAnimation: _propTypes.default.bool,
103
136
  /**
104
137
  * The props used for each component slot.
105
138
  * @default {}
@@ -14,13 +14,16 @@ interface MarkElementOwnerState {
14
14
  color: string;
15
15
  isFaded: boolean;
16
16
  isHighlighted: boolean;
17
- x: number;
18
- y: number;
19
17
  classes?: Partial<MarkElementClasses>;
20
18
  }
21
19
  export declare function getMarkElementUtilityClass(slot: string): string;
22
20
  export declare const markElementClasses: MarkElementClasses;
23
21
  export type MarkElementProps = Omit<MarkElementOwnerState, 'isFaded' | 'isHighlighted'> & React.ComponentPropsWithoutRef<'path'> & {
22
+ /**
23
+ * If `true`, animations are skipped.
24
+ * @default false
25
+ */
26
+ skipAnimation?: boolean;
24
27
  /**
25
28
  * The shape of the marker.
26
29
  */
@@ -16,11 +16,12 @@ var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateU
16
16
  var _styles = require("@mui/material/styles");
17
17
  var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
18
18
  var _d3Shape = require("d3-shape");
19
+ var _web = require("@react-spring/web");
19
20
  var _utils = require("../internals/utils");
20
21
  var _InteractionProvider = require("../context/InteractionProvider");
21
22
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
22
23
  var _jsxRuntime = require("react/jsx-runtime");
23
- const _excluded = ["x", "y", "id", "classes", "color", "shape", "dataIndex", "highlightScope"];
24
+ const _excluded = ["x", "y", "id", "classes", "color", "shape", "dataIndex", "highlightScope", "onClick", "skipAnimation"];
24
25
  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); }
25
26
  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; }
26
27
  function getMarkElementUtilityClass(slot) {
@@ -39,7 +40,7 @@ const useUtilityClasses = ownerState => {
39
40
  };
40
41
  return (0, _composeClasses.default)(slots, getMarkElementUtilityClass, classes);
41
42
  };
42
- const MarkElementPath = (0, _styles.styled)('path', {
43
+ const MarkElementPath = (0, _styles.styled)(_web.animated.path, {
43
44
  name: 'MuiMarkElement',
44
45
  slot: 'Root',
45
46
  overridesResolver: (_, styles) => styles.root
@@ -47,8 +48,6 @@ const MarkElementPath = (0, _styles.styled)('path', {
47
48
  ownerState,
48
49
  theme
49
50
  }) => ({
50
- transform: `translate(${ownerState.x}px, ${ownerState.y}px)`,
51
- transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
52
51
  fill: (theme.vars || theme).palette.background.paper,
53
52
  stroke: ownerState.color,
54
53
  strokeWidth: 2
@@ -64,9 +63,7 @@ MarkElementPath.propTypes = {
64
63
  color: _propTypes.default.string.isRequired,
65
64
  id: _propTypes.default.string.isRequired,
66
65
  isFaded: _propTypes.default.bool.isRequired,
67
- isHighlighted: _propTypes.default.bool.isRequired,
68
- x: _propTypes.default.number.isRequired,
69
- y: _propTypes.default.number.isRequired
66
+ isHighlighted: _propTypes.default.bool.isRequired
70
67
  }).isRequired,
71
68
  sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
72
69
  };
@@ -89,7 +86,9 @@ function MarkElement(props) {
89
86
  color,
90
87
  shape,
91
88
  dataIndex,
92
- highlightScope
89
+ highlightScope,
90
+ onClick,
91
+ skipAnimation
93
92
  } = props,
94
93
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
95
94
  const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope);
@@ -105,20 +104,29 @@ function MarkElement(props) {
105
104
  type: 'line',
106
105
  seriesId: id
107
106
  }, highlightScope);
107
+ const position = (0, _web.useSpring)({
108
+ x,
109
+ y,
110
+ immediate: skipAnimation
111
+ });
108
112
  const ownerState = {
109
113
  id,
110
114
  classes: innerClasses,
111
115
  isHighlighted,
112
116
  isFaded,
113
- color,
114
- x,
115
- y
117
+ color
116
118
  };
117
119
  const classes = useUtilityClasses(ownerState);
118
120
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(MarkElementPath, (0, _extends2.default)({}, other, {
121
+ style: {
122
+ transform: (0, _web.to)([position.x, position.y], (pX, pY) => `translate(${pX}px, ${pY}px)`),
123
+ transformOrigin: (0, _web.to)([position.x, position.y], (pX, pY) => `${pX}px ${pY}px`)
124
+ },
119
125
  ownerState: ownerState,
120
126
  className: classes.root,
121
- d: (0, _d3Shape.symbol)(_d3Shape.symbolsFill[(0, _utils.getSymbol)(shape)])()
127
+ d: (0, _d3Shape.symbol)(_d3Shape.symbolsFill[(0, _utils.getSymbol)(shape)])(),
128
+ onClick: onClick,
129
+ cursor: onClick ? 'pointer' : 'unset'
122
130
  }, getInteractionItemProps({
123
131
  type: 'line',
124
132
  seriesId: id,
@@ -142,5 +150,10 @@ process.env.NODE_ENV !== "production" ? MarkElement.propTypes = {
142
150
  /**
143
151
  * The shape of the marker.
144
152
  */
145
- shape: _propTypes.default.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']).isRequired
153
+ shape: _propTypes.default.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']).isRequired,
154
+ /**
155
+ * If `true`, animations are skipped.
156
+ * @default false
157
+ */
158
+ skipAnimation: _propTypes.default.bool
146
159
  } : void 0;
@@ -1,12 +1,13 @@
1
1
  import * as React from 'react';
2
2
  import { MarkElementProps } from './MarkElement';
3
+ import { LineItemIdentifier } from '../models/seriesType/line';
3
4
  export interface MarkPlotSlots {
4
5
  mark?: React.JSXElementConstructor<MarkElementProps>;
5
6
  }
6
7
  export interface MarkPlotSlotProps {
7
8
  mark?: Partial<MarkElementProps>;
8
9
  }
9
- export interface MarkPlotProps extends React.SVGAttributes<SVGSVGElement> {
10
+ export interface MarkPlotProps extends React.SVGAttributes<SVGSVGElement>, Pick<MarkElementProps, 'skipAnimation'> {
10
11
  /**
11
12
  * Overridable component slots.
12
13
  * @default {}
@@ -17,6 +18,12 @@ export interface MarkPlotProps extends React.SVGAttributes<SVGSVGElement> {
17
18
  * @default {}
18
19
  */
19
20
  slotProps?: MarkPlotSlotProps;
21
+ /**
22
+ * Callback fired when a line mark item is clicked.
23
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
24
+ * @param {LineItemIdentifier} lineItemIdentifier The line mark item identifier.
25
+ */
26
+ onItemClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, lineItemIdentifier: LineItemIdentifier) => void;
20
27
  }
21
28
  /**
22
29
  * Demos: