@mui/x-charts 8.6.0 → 8.7.0

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 (140) hide show
  1. package/BarChart/BarPlot.js +11 -150
  2. package/BarChart/useBarPlotData.d.ts +8 -0
  3. package/BarChart/useBarPlotData.js +146 -0
  4. package/CHANGELOG.md +104 -1
  5. package/ChartContainer/ChartContainer.d.ts +1 -21
  6. package/ChartContainer/ChartContainer.js +0 -8
  7. package/ChartContainer/index.d.ts +8 -1
  8. package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  9. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
  10. package/ChartsReferenceLine/ChartsXReferenceLine.js +48 -1
  11. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
  12. package/ChartsReferenceLine/ChartsYReferenceLine.js +48 -1
  13. package/ChartsReferenceLine/index.d.ts +3 -1
  14. package/ChartsSurface/ChartsSurface.js +2 -1
  15. package/ChartsTooltip/ChartsTooltipContainer.js +6 -3
  16. package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  17. package/ChartsTooltip/utils.js +18 -29
  18. package/LineChart/AreaPlot.js +5 -115
  19. package/LineChart/LinePlot.js +5 -99
  20. package/LineChart/useAreaPlotData.d.ts +12 -0
  21. package/LineChart/useAreaPlotData.js +125 -0
  22. package/LineChart/useLinePlotData.d.ts +11 -0
  23. package/LineChart/useLinePlotData.js +108 -0
  24. package/ScatterChart/Scatter.js +22 -48
  25. package/ScatterChart/useScatterPlotData.d.ts +8 -0
  26. package/ScatterChart/useScatterPlotData.js +33 -0
  27. package/context/ChartApi.d.ts +22 -0
  28. package/context/ChartApi.js +5 -0
  29. package/context/ChartProvider/ChartContext.js +1 -0
  30. package/context/index.d.ts +2 -1
  31. package/context/useChartApiContext.d.ts +1 -1
  32. package/esm/BarChart/BarPlot.js +12 -152
  33. package/esm/BarChart/useBarPlotData.d.ts +8 -0
  34. package/esm/BarChart/useBarPlotData.js +139 -0
  35. package/esm/ChartContainer/ChartContainer.d.ts +1 -21
  36. package/esm/ChartContainer/ChartContainer.js +0 -8
  37. package/esm/ChartContainer/index.d.ts +8 -1
  38. package/esm/ChartContainer/index.js +6 -1
  39. package/esm/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  40. package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
  41. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +47 -0
  42. package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
  43. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +47 -0
  44. package/esm/ChartsReferenceLine/index.d.ts +3 -1
  45. package/esm/ChartsReferenceLine/index.js +2 -1
  46. package/esm/ChartsSurface/ChartsSurface.js +2 -1
  47. package/esm/ChartsTooltip/ChartsTooltipContainer.js +6 -3
  48. package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  49. package/esm/ChartsTooltip/utils.js +18 -29
  50. package/esm/LineChart/AreaPlot.js +5 -115
  51. package/esm/LineChart/LinePlot.js +5 -99
  52. package/esm/LineChart/useAreaPlotData.d.ts +12 -0
  53. package/esm/LineChart/useAreaPlotData.js +118 -0
  54. package/esm/LineChart/useLinePlotData.d.ts +11 -0
  55. package/esm/LineChart/useLinePlotData.js +101 -0
  56. package/esm/ScatterChart/Scatter.js +23 -49
  57. package/esm/ScatterChart/useScatterPlotData.d.ts +8 -0
  58. package/esm/ScatterChart/useScatterPlotData.js +26 -0
  59. package/esm/context/ChartApi.d.ts +22 -0
  60. package/esm/context/ChartApi.js +1 -0
  61. package/esm/context/ChartProvider/ChartContext.js +2 -0
  62. package/esm/context/index.d.ts +2 -1
  63. package/esm/context/useChartApiContext.d.ts +1 -1
  64. package/esm/hooks/useInteractionItemProps.d.ts +14 -9
  65. package/esm/hooks/useInteractionItemProps.js +28 -28
  66. package/esm/index.d.ts +2 -1
  67. package/esm/index.js +2 -2
  68. package/esm/internals/index.d.ts +5 -0
  69. package/esm/internals/index.js +5 -0
  70. package/esm/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
  71. package/esm/internals/plugins/corePlugins/corePlugins.js +2 -1
  72. package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
  73. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -29
  74. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
  75. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +0 -6
  76. package/esm/internals/plugins/corePlugins/useChartId/useChartId.js +2 -0
  77. package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  78. package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
  79. package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.js +1 -0
  80. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
  81. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +77 -0
  82. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
  83. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +1 -0
  84. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
  85. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
  86. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
  87. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
  88. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
  89. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
  90. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
  91. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +34 -34
  92. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
  93. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
  94. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +47 -30
  95. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
  96. package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
  97. package/esm/internals/store/useCharts.d.ts +1 -1
  98. package/esm/locales/elGR.d.ts +19 -0
  99. package/esm/locales/elGR.js +15 -0
  100. package/esm/locales/index.d.ts +1 -0
  101. package/esm/locales/index.js +1 -0
  102. package/hooks/useInteractionItemProps.d.ts +14 -9
  103. package/hooks/useInteractionItemProps.js +29 -28
  104. package/index.d.ts +2 -1
  105. package/index.js +37 -11
  106. package/internals/index.d.ts +5 -0
  107. package/internals/index.js +44 -0
  108. package/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
  109. package/internals/plugins/corePlugins/corePlugins.js +2 -1
  110. package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
  111. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -29
  112. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
  113. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +0 -6
  114. package/internals/plugins/corePlugins/useChartId/useChartId.js +1 -0
  115. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  116. package/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
  117. package/internals/plugins/corePlugins/useChartInteractionListener/index.js +12 -0
  118. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
  119. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +84 -0
  120. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
  121. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +5 -0
  122. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
  123. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
  124. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
  125. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
  126. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
  127. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
  128. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
  129. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +34 -34
  130. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
  131. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
  132. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +46 -30
  133. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
  134. package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
  135. package/internals/store/useCharts.d.ts +1 -1
  136. package/locales/elGR.d.ts +19 -0
  137. package/locales/elGR.js +21 -0
  138. package/locales/index.d.ts +1 -0
  139. package/locales/index.js +11 -0
  140. package/package.json +3 -2
@@ -36,7 +36,8 @@ const ChartsSurfaceStyles = (0, _styles.styled)('svg', {
36
36
  overflow: 'hidden',
37
37
  // This prevents default touch actions when using the svg on mobile devices.
38
38
  // For example, prevent page scroll & zoom.
39
- touchAction: 'none'
39
+ touchAction: 'pan-y',
40
+ userSelect: 'none'
40
41
  }));
41
42
 
42
43
  /**
@@ -16,7 +16,7 @@ var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
16
16
  var _styles = require("@mui/material/styles");
17
17
  var _Popper = _interopRequireDefault(require("@mui/material/Popper"));
18
18
  var _NoSsr = _interopRequireDefault(require("@mui/material/NoSsr"));
19
- var _useSvgRef = require("../hooks/useSvgRef");
19
+ var _rafThrottle = require("@mui/x-internals/rafThrottle");
20
20
  var _utils = require("./utils");
21
21
  var _chartsTooltipClasses = require("./chartsTooltipClasses");
22
22
  var _useSelector = require("../internals/store/useSelector");
@@ -25,6 +25,7 @@ var _useChartInteraction = require("../internals/plugins/featurePlugins/useChart
25
25
  var _useChartCartesianAxis = require("../internals/plugins/featurePlugins/useChartCartesianAxis");
26
26
  var _useChartPolarInteraction = require("../internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors");
27
27
  var _useAxisSystem = require("../hooks/useAxisSystem");
28
+ var _hooks = require("../hooks");
28
29
  var _jsxRuntime = require("react/jsx-runtime");
29
30
  const _excluded = ["trigger", "classes", "children"];
30
31
  const noAxis = () => false;
@@ -58,8 +59,8 @@ function ChartsTooltipContainer(inProps) {
58
59
  children
59
60
  } = props,
60
61
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
62
+ const svgRef = (0, _hooks.useSvgRef)();
61
63
  const classes = (0, _chartsTooltipClasses.useUtilityClasses)(propClasses);
62
- const svgRef = (0, _useSvgRef.useSvgRef)();
63
64
  const pointerType = (0, _utils.usePointerType)();
64
65
  const isFineMainPointer = (0, _utils.useIsFineMainPointer)();
65
66
  const popperRef = React.useRef(null);
@@ -75,19 +76,21 @@ function ChartsTooltipContainer(inProps) {
75
76
  if (element === null) {
76
77
  return () => {};
77
78
  }
79
+ const update = (0, _rafThrottle.rafThrottle)(() => popperRef.current?.update());
78
80
  const handlePointerEvent = event => {
79
81
  // eslint-disable-next-line react-compiler/react-compiler
80
82
  positionRef.current = {
81
83
  x: event.clientX,
82
84
  y: event.clientY
83
85
  };
84
- popperRef.current?.update();
86
+ update();
85
87
  };
86
88
  element.addEventListener('pointerdown', handlePointerEvent);
87
89
  element.addEventListener('pointermove', handlePointerEvent);
88
90
  return () => {
89
91
  element.removeEventListener('pointerdown', handlePointerEvent);
90
92
  element.removeEventListener('pointermove', handlePointerEvent);
93
+ update.clear();
91
94
  };
92
95
  }, [svgRef, positionRef]);
93
96
  const anchorEl = React.useMemo(() => ({
@@ -13,6 +13,6 @@ export declare const ChartsTooltipRow: import("@emotion/styled").StyledComponent
13
13
  /**
14
14
  * @ignore - internal component.
15
15
  */
16
- export declare const ChartsTooltipCell: import("@emotion/styled").StyledComponent<Pick<import("@mui/material/Typography").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "p" | "style" | "typography" | "zIndex" | "classes" | "border" | "boxShadow" | "fontWeight" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "color" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "marginBlock" | "marginInline" | "overflow" | "padding" | "paddingBlock" | "paddingInline" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "displayPrint" | "className" | "children" | "sx" | "align" | "variant" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping">, "p" | "slot" | "style" | "title" | "ref" | "typography" | "zIndex" | "classes" | "border" | "boxShadow" | "fontWeight" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "color" | "columnGap" | "content" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "translate" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "marginBlock" | "marginInline" | "overflow" | "padding" | "paddingBlock" | "paddingInline" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "displayPrint" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "autoCapitalize" | "autoFocus" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "enterKeyHint" | "hidden" | "id" | "lang" | "nonce" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "popover" | "popoverTargetAction" | "popoverTarget" | "inert" | "inputMode" | "is" | "exportparts" | "part" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onScrollEnd" | "onScrollEndCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onToggle" | "onBeforeToggle" | "onTransitionCancel" | "onTransitionCancelCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "onTransitionRun" | "onTransitionRunCapture" | "onTransitionStart" | "onTransitionStartCapture" | "sx" | "align" | "variant" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
16
+ export declare const ChartsTooltipCell: import("@emotion/styled").StyledComponent<Pick<import("@mui/material/Typography").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "p" | "style" | "typography" | "zIndex" | "classes" | "border" | "boxShadow" | "fontWeight" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "color" | "columnGap" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "marginBlock" | "marginInline" | "overflow" | "padding" | "paddingBlock" | "paddingInline" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "displayPrint" | "className" | "children" | "sx" | "align" | "variant" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping">, "p" | "slot" | "style" | "title" | "ref" | "typography" | "zIndex" | "classes" | "border" | "boxShadow" | "fontWeight" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "color" | "columnGap" | "content" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "order" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "translate" | "visibility" | "whiteSpace" | "width" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "marginBlock" | "marginInline" | "overflow" | "padding" | "paddingBlock" | "paddingInline" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "displayPrint" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "autoCapitalize" | "autoFocus" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "enterKeyHint" | "hidden" | "id" | "lang" | "nonce" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "popover" | "popoverTargetAction" | "popoverTarget" | "inert" | "inputMode" | "is" | "exportparts" | "part" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onScrollEnd" | "onScrollEndCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onToggle" | "onBeforeToggle" | "onTransitionCancel" | "onTransitionCancelCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "onTransitionRun" | "onTransitionRunCapture" | "onTransitionStart" | "onTransitionStartCapture" | "sx" | "align" | "variant" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
17
17
  component?: React.ElementType;
18
18
  }, {}, {}>;
@@ -12,55 +12,44 @@ exports.usePointerType = usePointerType;
12
12
  exports.utcFormatter = utcFormatter;
13
13
  var React = _interopRequireWildcard(require("react"));
14
14
  var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
15
+ var _ChartProvider = require("../context/ChartProvider");
15
16
  var _hooks = require("../hooks");
16
17
  /**
17
18
  * @deprecated We recommend using vanilla JS to let popper track mouse position.
18
19
  */
19
20
  function useMouseTracker() {
20
- const svgRef = (0, _hooks.useSvgRef)();
21
+ const {
22
+ instance
23
+ } = (0, _ChartProvider.useChartContext)();
21
24
 
22
25
  // Use a ref to avoid rerendering on every mousemove event.
23
26
  const [mousePosition, setMousePosition] = React.useState(null);
24
27
  React.useEffect(() => {
25
- const element = svgRef.current;
26
- if (element === null) {
27
- return () => {};
28
- }
29
- const controller = new AbortController();
30
- const handleOut = event => {
31
- if (event.pointerType !== 'mouse') {
28
+ const moveEndHandler = instance.addInteractionListener('moveEnd', event => {
29
+ if (!event.detail.activeGestures.pan) {
32
30
  setMousePosition(null);
33
31
  }
34
- };
35
- const handleMove = event => {
32
+ });
33
+ const gestureHandler = event => {
36
34
  setMousePosition({
37
- x: event.clientX,
38
- y: event.clientY,
39
- height: event.height,
40
- pointerType: event.pointerType
35
+ x: event.detail.centroid.x,
36
+ y: event.detail.centroid.y,
37
+ height: event.detail.srcEvent.height,
38
+ pointerType: event.detail.srcEvent.pointerType
41
39
  });
42
40
  };
43
- element.addEventListener('pointerdown', handleMove, {
44
- signal: controller.signal
45
- });
46
- element.addEventListener('pointermove', handleMove, {
47
- signal: controller.signal
48
- });
49
- element.addEventListener('pointerup', handleOut, {
50
- signal: controller.signal
51
- });
41
+ const moveHandler = instance.addInteractionListener('move', gestureHandler);
42
+ const panHandler = instance.addInteractionListener('pan', gestureHandler);
52
43
  return () => {
53
- // Calling `.abort()` removes ALL event listeners
54
- // For more info, see https://kettanaito.com/blog/dont-sleep-on-abort-controller
55
- controller.abort();
44
+ moveHandler.cleanup();
45
+ panHandler.cleanup();
46
+ moveEndHandler.cleanup();
56
47
  };
57
- }, [svgRef]);
48
+ }, [instance]);
58
49
  return mousePosition;
59
50
  }
60
51
  function usePointerType() {
61
52
  const svgRef = (0, _hooks.useSvgRef)();
62
-
63
- // Use a ref to avoid rerendering on every mousemove event.
64
53
  const [pointerType, setPointerType] = React.useState(null);
65
54
  React.useEffect(() => {
66
55
  const element = svgRef.current;
@@ -7,22 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  value: true
8
8
  });
9
9
  exports.AreaPlot = AreaPlot;
10
- var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _styles = require("@mui/material/styles");
15
- var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
16
15
  var _AreaElement = require("./AreaElement");
17
- var _useScale = require("../hooks/useScale");
18
- var _getCurve = require("../internals/getCurve");
19
- var _isBandScale = require("../internals/isBandScale");
20
- var _constants = require("../constants");
21
- var _useLineSeries = require("../hooks/useLineSeries");
22
16
  var _useSkipAnimation = require("../hooks/useSkipAnimation");
23
- var _useChartGradientId = require("../hooks/useChartGradientId");
24
17
  var _useAxis = require("../hooks/useAxis");
25
18
  var _useInternalIsZoomInteracting = require("../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting");
19
+ var _useAreaPlotData = require("./useAreaPlotData");
26
20
  var _jsxRuntime = require("react/jsx-runtime");
27
21
  const _excluded = ["slots", "slotProps", "onItemClick", "skipAnimation"];
28
22
  const AreaPlotRoot = (0, _styles.styled)('g', {
@@ -34,117 +28,13 @@ const AreaPlotRoot = (0, _styles.styled)('g', {
34
28
  }
35
29
  });
36
30
  const useAggregatedData = () => {
37
- const seriesData = (0, _useLineSeries.useLineSeriesContext)();
38
31
  const {
39
- xAxis,
40
- xAxisIds
32
+ xAxis: xAxes
41
33
  } = (0, _useAxis.useXAxes)();
42
34
  const {
43
- yAxis,
44
- yAxisIds
35
+ yAxis: yAxes
45
36
  } = (0, _useAxis.useYAxes)();
46
- const getGradientId = (0, _useChartGradientId.useChartGradientIdBuilder)();
47
-
48
- // This memo prevents odd line chart behavior when hydrating.
49
- const allData = React.useMemo(() => {
50
- if (seriesData === undefined) {
51
- return [];
52
- }
53
- const {
54
- series,
55
- stackingGroups
56
- } = seriesData;
57
- const defaultXAxisId = xAxisIds[0];
58
- const defaultYAxisId = yAxisIds[0];
59
- return stackingGroups.flatMap(({
60
- ids: groupIds
61
- }) => {
62
- return [...groupIds].reverse() // Revert stacked area for a more pleasant animation
63
- .map(seriesId => {
64
- const {
65
- xAxisId = defaultXAxisId,
66
- yAxisId = defaultYAxisId,
67
- stackedData,
68
- data,
69
- connectNulls,
70
- baseline,
71
- curve,
72
- strictStepCurve
73
- } = series[seriesId];
74
- const xScale = xAxis[xAxisId].scale;
75
- const xPosition = (0, _useScale.getValueToPositionMapper)(xScale);
76
- const yScale = yAxis[yAxisId].scale;
77
- const xData = xAxis[xAxisId].data;
78
- const gradientId = yAxis[yAxisId].colorScale && getGradientId(yAxisId) || xAxis[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
79
- if (process.env.NODE_ENV !== 'production') {
80
- if (xData === undefined) {
81
- throw new Error(`MUI X Charts: ${xAxisId === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
82
- }
83
- if (xData.length < stackedData.length) {
84
- 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).`);
85
- }
86
- }
87
- const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _isBandScale.isBandScale)(xScale);
88
- const formattedData = xData?.flatMap((x, index) => {
89
- const nullData = data[index] == null;
90
- if (shouldExpand) {
91
- const rep = [{
92
- x,
93
- y: stackedData[index],
94
- nullData,
95
- isExtension: false
96
- }];
97
- if (!nullData && (index === 0 || data[index - 1] == null)) {
98
- rep.unshift({
99
- x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
100
- y: stackedData[index],
101
- nullData,
102
- isExtension: true
103
- });
104
- }
105
- if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
106
- rep.push({
107
- x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
108
- y: stackedData[index],
109
- nullData,
110
- isExtension: true
111
- });
112
- }
113
- return rep;
114
- }
115
- return {
116
- x,
117
- y: stackedData[index],
118
- nullData
119
- };
120
- }) ?? [];
121
- const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
122
- const areaPath = (0, _d3Shape.area)().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y0(d => {
123
- if (typeof baseline === 'number') {
124
- return yScale(baseline);
125
- }
126
- if (baseline === 'max') {
127
- return yScale.range()[1];
128
- }
129
- if (baseline === 'min') {
130
- return yScale.range()[0];
131
- }
132
- const value = d.y && yScale(d.y[0]);
133
- if (Number.isNaN(value)) {
134
- return yScale.range()[0];
135
- }
136
- return value;
137
- }).y1(d => d.y && yScale(d.y[1]));
138
- const d = areaPath.curve((0, _getCurve.getCurveFactory)(curve))(d3Data) || '';
139
- return (0, _extends2.default)({}, series[seriesId], {
140
- gradientId,
141
- d,
142
- seriesId
143
- });
144
- });
145
- });
146
- }, [seriesData, xAxisIds, yAxisIds, xAxis, yAxis, getGradientId]);
147
- return allData;
37
+ return (0, _useAreaPlotData.useAreaPlotData)(xAxes, yAxes);
148
38
  };
149
39
 
150
40
  /**
@@ -7,23 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  value: true
8
8
  });
9
9
  exports.LinePlot = LinePlot;
10
- var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _styles = require("@mui/material/styles");
15
- var _warning = require("@mui/x-internals/warning");
16
- var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
17
15
  var _LineElement = require("./LineElement");
18
- var _useScale = require("../hooks/useScale");
19
- var _getCurve = require("../internals/getCurve");
20
- var _isBandScale = require("../internals/isBandScale");
21
- var _constants = require("../constants");
22
- var _useLineSeries = require("../hooks/useLineSeries");
23
16
  var _useSkipAnimation = require("../hooks/useSkipAnimation");
24
- var _useChartGradientId = require("../hooks/useChartGradientId");
25
17
  var _hooks = require("../hooks");
26
18
  var _useInternalIsZoomInteracting = require("../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting");
19
+ var _useLinePlotData = require("./useLinePlotData");
27
20
  var _jsxRuntime = require("react/jsx-runtime");
28
21
  const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
29
22
  const LinePlotRoot = (0, _styles.styled)('g', {
@@ -35,100 +28,13 @@ const LinePlotRoot = (0, _styles.styled)('g', {
35
28
  }
36
29
  });
37
30
  const useAggregatedData = () => {
38
- const seriesData = (0, _useLineSeries.useLineSeriesContext)();
39
31
  const {
40
- xAxis,
41
- xAxisIds
32
+ xAxis: xAxes
42
33
  } = (0, _hooks.useXAxes)();
43
34
  const {
44
- yAxis,
45
- yAxisIds
35
+ yAxis: yAxes
46
36
  } = (0, _hooks.useYAxes)();
47
- const getGradientId = (0, _useChartGradientId.useChartGradientIdBuilder)();
48
-
49
- // This memo prevents odd line chart behavior when hydrating.
50
- const allData = React.useMemo(() => {
51
- if (seriesData === undefined) {
52
- return [];
53
- }
54
- const {
55
- series,
56
- stackingGroups
57
- } = seriesData;
58
- const defaultXAxisId = xAxisIds[0];
59
- const defaultYAxisId = yAxisIds[0];
60
- return stackingGroups.flatMap(({
61
- ids: groupIds
62
- }) => {
63
- return groupIds.flatMap(seriesId => {
64
- const {
65
- xAxisId = defaultXAxisId,
66
- yAxisId = defaultYAxisId,
67
- stackedData,
68
- data,
69
- connectNulls,
70
- curve,
71
- strictStepCurve
72
- } = series[seriesId];
73
- const xScale = xAxis[xAxisId].scale;
74
- const xPosition = (0, _useScale.getValueToPositionMapper)(xScale);
75
- const yScale = yAxis[yAxisId].scale;
76
- const xData = xAxis[xAxisId].data;
77
- const gradientId = yAxis[yAxisId].colorScale && getGradientId(yAxisId) || xAxis[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
78
- if (process.env.NODE_ENV !== 'production') {
79
- if (xData === undefined) {
80
- throw new Error(`MUI X Charts: ${xAxisId === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
81
- }
82
- if (xData.length < stackedData.length) {
83
- (0, _warning.warnOnce)(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`, 'error');
84
- }
85
- }
86
- const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _isBandScale.isBandScale)(xScale);
87
- const formattedData = xData?.flatMap((x, index) => {
88
- const nullData = data[index] == null;
89
- if (shouldExpand) {
90
- const rep = [{
91
- x,
92
- y: stackedData[index],
93
- nullData,
94
- isExtension: false
95
- }];
96
- if (!nullData && (index === 0 || data[index - 1] == null)) {
97
- rep.unshift({
98
- x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
99
- y: stackedData[index],
100
- nullData,
101
- isExtension: true
102
- });
103
- }
104
- if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
105
- rep.push({
106
- x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
107
- y: stackedData[index],
108
- nullData,
109
- isExtension: true
110
- });
111
- }
112
- return rep;
113
- }
114
- return {
115
- x,
116
- y: stackedData[index],
117
- nullData
118
- };
119
- }) ?? [];
120
- const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
121
- const linePath = (0, _d3Shape.line)().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y(d => yScale(d.y[1]));
122
- const d = linePath.curve((0, _getCurve.getCurveFactory)(curve))(d3Data) || '';
123
- return (0, _extends2.default)({}, series[seriesId], {
124
- gradientId,
125
- d,
126
- seriesId
127
- });
128
- });
129
- });
130
- }, [seriesData, xAxisIds, yAxisIds, xAxis, yAxis, getGradientId]);
131
- return allData;
37
+ return (0, _useLinePlotData.useLinePlotData)(xAxes, yAxes);
132
38
  };
133
39
 
134
40
  /**
@@ -0,0 +1,12 @@
1
+ import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
2
+ import { ChartsXAxisProps, ChartsYAxisProps } from "../models/index.js";
3
+ import { SeriesId } from "../models/seriesType/common.js";
4
+ interface AreaPlotDataPoint {
5
+ d: string;
6
+ seriesId: SeriesId;
7
+ color: string;
8
+ area?: boolean;
9
+ gradientId?: string;
10
+ }
11
+ export declare function useAreaPlotData(xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): AreaPlotDataPoint[];
12
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useAreaPlotData = useAreaPlotData;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
10
+ var _useChartGradientId = require("../hooks/useChartGradientId");
11
+ var _isBandScale = require("../internals/isBandScale");
12
+ var _getCurve = require("../internals/getCurve");
13
+ var _hooks = require("../hooks");
14
+ var _constants = require("../constants");
15
+ function useAreaPlotData(xAxes, yAxes) {
16
+ const seriesData = (0, _hooks.useLineSeriesContext)();
17
+ const defaultXAxisId = (0, _hooks.useXAxes)().xAxisIds[0];
18
+ const defaultYAxisId = (0, _hooks.useYAxes)().yAxisIds[0];
19
+ const getGradientId = (0, _useChartGradientId.useChartGradientIdBuilder)();
20
+
21
+ // This memo prevents odd line chart behavior when hydrating.
22
+ const allData = React.useMemo(() => {
23
+ if (seriesData === undefined) {
24
+ return [];
25
+ }
26
+ const {
27
+ series,
28
+ stackingGroups
29
+ } = seriesData;
30
+ const areaPlotData = [];
31
+ for (const stackingGroup of stackingGroups) {
32
+ const groupIds = stackingGroup.ids;
33
+ for (let i = groupIds.length - 1; i >= 0; i -= 1) {
34
+ const seriesId = groupIds[i];
35
+ const {
36
+ xAxisId = defaultXAxisId,
37
+ yAxisId = defaultYAxisId,
38
+ stackedData,
39
+ data,
40
+ connectNulls,
41
+ baseline,
42
+ curve,
43
+ strictStepCurve
44
+ } = series[seriesId];
45
+ if (!(xAxisId in xAxes) || !(yAxisId in yAxes)) {
46
+ continue;
47
+ }
48
+ const xScale = xAxes[xAxisId].scale;
49
+ const xPosition = (0, _hooks.getValueToPositionMapper)(xScale);
50
+ const yScale = yAxes[yAxisId].scale;
51
+ const xData = xAxes[xAxisId].data;
52
+ const gradientId = yAxes[yAxisId].colorScale && getGradientId(yAxisId) || xAxes[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
53
+ if (process.env.NODE_ENV !== 'production') {
54
+ if (xData === undefined) {
55
+ throw new Error(`MUI X Charts: ${xAxisId === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
56
+ }
57
+ if (xData.length < stackedData.length) {
58
+ 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).`);
59
+ }
60
+ }
61
+ const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _isBandScale.isBandScale)(xScale);
62
+ const formattedData = xData?.flatMap((x, index) => {
63
+ const nullData = data[index] == null;
64
+ if (shouldExpand) {
65
+ const rep = [{
66
+ x,
67
+ y: stackedData[index],
68
+ nullData,
69
+ isExtension: false
70
+ }];
71
+ if (!nullData && (index === 0 || data[index - 1] == null)) {
72
+ rep.unshift({
73
+ x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
74
+ y: stackedData[index],
75
+ nullData,
76
+ isExtension: true
77
+ });
78
+ }
79
+ if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
80
+ rep.push({
81
+ x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
82
+ y: stackedData[index],
83
+ nullData,
84
+ isExtension: true
85
+ });
86
+ }
87
+ return rep;
88
+ }
89
+ return {
90
+ x,
91
+ y: stackedData[index],
92
+ nullData
93
+ };
94
+ }) ?? [];
95
+ const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
96
+ const areaPath = (0, _d3Shape.area)().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y0(d => {
97
+ if (typeof baseline === 'number') {
98
+ return yScale(baseline);
99
+ }
100
+ if (baseline === 'max') {
101
+ return yScale.range()[1];
102
+ }
103
+ if (baseline === 'min') {
104
+ return yScale.range()[0];
105
+ }
106
+ const value = d.y && yScale(d.y[0]);
107
+ if (Number.isNaN(value)) {
108
+ return yScale.range()[0];
109
+ }
110
+ return value;
111
+ }).y1(d => d.y && yScale(d.y[1]));
112
+ const d = areaPath.curve((0, _getCurve.getCurveFactory)(curve))(d3Data) || '';
113
+ areaPlotData.push({
114
+ area: series[seriesId].area,
115
+ color: series[seriesId].color,
116
+ gradientId,
117
+ d,
118
+ seriesId
119
+ });
120
+ }
121
+ }
122
+ return areaPlotData;
123
+ }, [seriesData, defaultXAxisId, defaultYAxisId, xAxes, yAxes, getGradientId]);
124
+ return allData;
125
+ }
@@ -0,0 +1,11 @@
1
+ import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
2
+ import { ChartsXAxisProps, ChartsYAxisProps } from "../models/index.js";
3
+ import { SeriesId } from "../models/seriesType/common.js";
4
+ interface LinePlotDataPoint {
5
+ d: string;
6
+ seriesId: SeriesId;
7
+ color: string;
8
+ gradientId?: string;
9
+ }
10
+ export declare function useLinePlotData(xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): LinePlotDataPoint[];
11
+ export {};