@mui/x-charts-premium 8.23.0 → 8.24.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 (122) hide show
  1. package/BarChartPremium/BarChartPremium.d.ts +16 -1
  2. package/BarChartPremium/BarChartPremium.js +44 -1
  3. package/BarChartPremium/RangeBar/AnimatedRangeBarElement.d.ts +3 -0
  4. package/BarChartPremium/RangeBar/AnimatedRangeBarElement.js +28 -0
  5. package/BarChartPremium/RangeBar/RangeBarPlot.d.ts +46 -0
  6. package/BarChartPremium/RangeBar/RangeBarPlot.js +141 -0
  7. package/BarChartPremium/RangeBar/seriesConfig/extrema.d.ts +3 -0
  8. package/BarChartPremium/RangeBar/seriesConfig/extrema.js +85 -0
  9. package/BarChartPremium/RangeBar/seriesConfig/getColor.d.ts +3 -0
  10. package/BarChartPremium/RangeBar/seriesConfig/getColor.js +43 -0
  11. package/BarChartPremium/RangeBar/seriesConfig/getSeriesWithDefaultValues.d.ts +19 -0
  12. package/BarChartPremium/RangeBar/seriesConfig/getSeriesWithDefaultValues.js +14 -0
  13. package/BarChartPremium/RangeBar/seriesConfig/index.d.ts +2 -0
  14. package/BarChartPremium/RangeBar/seriesConfig/index.js +29 -0
  15. package/BarChartPremium/RangeBar/seriesConfig/legend.d.ts +3 -0
  16. package/BarChartPremium/RangeBar/seriesConfig/legend.js +29 -0
  17. package/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.d.ts +3 -0
  18. package/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.js +54 -0
  19. package/BarChartPremium/RangeBar/seriesConfig/tooltip.d.ts +4 -0
  20. package/BarChartPremium/RangeBar/seriesConfig/tooltip.js +44 -0
  21. package/BarChartPremium/RangeBar/seriesConfig/tooltipPosition.d.ts +3 -0
  22. package/BarChartPremium/RangeBar/seriesConfig/tooltipPosition.js +59 -0
  23. package/BarChartPremium/RangeBar/types.d.ts +22 -0
  24. package/BarChartPremium/RangeBar/types.js +5 -0
  25. package/BarChartPremium/RangeBar/useRangeBarPlotData.d.ts +12 -0
  26. package/BarChartPremium/RangeBar/useRangeBarPlotData.js +112 -0
  27. package/BarChartPremium/RangeBar/useUtilityClasses.d.ts +12 -0
  28. package/BarChartPremium/RangeBar/useUtilityClasses.js +24 -0
  29. package/BarChartPremium/index.d.ts +3 -1
  30. package/BarChartPremium/index.js +25 -1
  31. package/BarChartPremium/useBarChartPremiumProps.d.ts +5 -1
  32. package/BarChartPremium/useBarChartPremiumProps.js +19 -1
  33. package/CHANGELOG.md +111 -1
  34. package/ChartDataProviderPremium/ChartDataProviderPremium.d.ts +3 -2
  35. package/ChartDataProviderPremium/ChartDataProviderPremium.js +9 -1
  36. package/ChartDataProviderPremium/index.d.ts +1 -1
  37. package/ChartDataProviderPremium/index.js +7 -11
  38. package/ChartZoomSlider/internals/previews/RangeBarPreviewPlot.d.ts +2 -0
  39. package/ChartZoomSlider/internals/previews/RangeBarPreviewPlot.js +59 -0
  40. package/esm/BarChartPremium/BarChartPremium.d.ts +16 -1
  41. package/esm/BarChartPremium/BarChartPremium.js +45 -2
  42. package/esm/BarChartPremium/RangeBar/AnimatedRangeBarElement.d.ts +3 -0
  43. package/esm/BarChartPremium/RangeBar/AnimatedRangeBarElement.js +21 -0
  44. package/esm/BarChartPremium/RangeBar/RangeBarPlot.d.ts +46 -0
  45. package/esm/BarChartPremium/RangeBar/RangeBarPlot.js +135 -0
  46. package/esm/BarChartPremium/RangeBar/seriesConfig/extrema.d.ts +3 -0
  47. package/esm/BarChartPremium/RangeBar/seriesConfig/extrema.js +77 -0
  48. package/esm/BarChartPremium/RangeBar/seriesConfig/getColor.d.ts +3 -0
  49. package/esm/BarChartPremium/RangeBar/seriesConfig/getColor.js +37 -0
  50. package/esm/BarChartPremium/RangeBar/seriesConfig/getSeriesWithDefaultValues.d.ts +19 -0
  51. package/esm/BarChartPremium/RangeBar/seriesConfig/getSeriesWithDefaultValues.js +7 -0
  52. package/esm/BarChartPremium/RangeBar/seriesConfig/index.d.ts +2 -0
  53. package/esm/BarChartPremium/RangeBar/seriesConfig/index.js +21 -0
  54. package/esm/BarChartPremium/RangeBar/seriesConfig/legend.d.ts +3 -0
  55. package/esm/BarChartPremium/RangeBar/seriesConfig/legend.js +23 -0
  56. package/esm/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.d.ts +3 -0
  57. package/esm/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.js +47 -0
  58. package/esm/BarChartPremium/RangeBar/seriesConfig/tooltip.d.ts +4 -0
  59. package/esm/BarChartPremium/RangeBar/seriesConfig/tooltip.js +37 -0
  60. package/esm/BarChartPremium/RangeBar/seriesConfig/tooltipPosition.d.ts +3 -0
  61. package/esm/BarChartPremium/RangeBar/seriesConfig/tooltipPosition.js +53 -0
  62. package/esm/BarChartPremium/RangeBar/types.d.ts +22 -0
  63. package/esm/BarChartPremium/RangeBar/types.js +1 -0
  64. package/esm/BarChartPremium/RangeBar/useRangeBarPlotData.d.ts +12 -0
  65. package/esm/BarChartPremium/RangeBar/useRangeBarPlotData.js +105 -0
  66. package/esm/BarChartPremium/RangeBar/useUtilityClasses.d.ts +12 -0
  67. package/esm/BarChartPremium/RangeBar/useUtilityClasses.js +15 -0
  68. package/esm/BarChartPremium/index.d.ts +3 -1
  69. package/esm/BarChartPremium/index.js +3 -1
  70. package/esm/BarChartPremium/useBarChartPremiumProps.d.ts +5 -1
  71. package/esm/BarChartPremium/useBarChartPremiumProps.js +18 -1
  72. package/esm/ChartDataProviderPremium/ChartDataProviderPremium.d.ts +3 -2
  73. package/esm/ChartDataProviderPremium/ChartDataProviderPremium.js +8 -1
  74. package/esm/ChartDataProviderPremium/index.d.ts +1 -1
  75. package/esm/ChartDataProviderPremium/index.js +1 -1
  76. package/esm/ChartZoomSlider/internals/previews/RangeBarPreviewPlot.d.ts +2 -0
  77. package/esm/ChartZoomSlider/internals/previews/RangeBarPreviewPlot.js +53 -0
  78. package/esm/hooks/animation/index.d.ts +1 -0
  79. package/esm/hooks/animation/index.js +1 -0
  80. package/esm/hooks/animation/useAnimateRangeBar.d.ts +18 -0
  81. package/esm/hooks/animation/useAnimateRangeBar.js +51 -0
  82. package/esm/hooks/index.d.ts +3 -1
  83. package/esm/hooks/index.js +4 -1
  84. package/esm/hooks/useRangeBarSeries.d.ts +34 -0
  85. package/esm/hooks/useRangeBarSeries.js +40 -0
  86. package/esm/index.d.ts +4 -1
  87. package/esm/index.js +5 -4
  88. package/esm/models/index.d.ts +2 -1
  89. package/esm/models/index.js +3 -1
  90. package/esm/models/seriesType/index.d.ts +1 -0
  91. package/esm/models/seriesType/index.js +1 -0
  92. package/esm/models/seriesType/rangeBar.d.ts +43 -0
  93. package/esm/models/seriesType/rangeBar.js +1 -0
  94. package/esm/moduleAugmentation/rangeBarOnClick.d.ts +8 -0
  95. package/esm/moduleAugmentation/rangeBarOnClick.js +2 -0
  96. package/esm/typeOverloads/index.d.ts +1 -0
  97. package/esm/typeOverloads/index.js +1 -0
  98. package/esm/typeOverloads/modules.d.ts +22 -0
  99. package/esm/typeOverloads/modules.js +1 -0
  100. package/hooks/animation/index.d.ts +1 -0
  101. package/hooks/animation/index.js +16 -0
  102. package/hooks/animation/useAnimateRangeBar.d.ts +18 -0
  103. package/hooks/animation/useAnimateRangeBar.js +57 -0
  104. package/hooks/index.d.ts +3 -1
  105. package/hooks/index.js +22 -0
  106. package/hooks/useRangeBarSeries.d.ts +34 -0
  107. package/hooks/useRangeBarSeries.js +45 -0
  108. package/index.d.ts +4 -1
  109. package/index.js +26 -1
  110. package/models/index.d.ts +2 -1
  111. package/models/index.js +11 -0
  112. package/models/seriesType/index.d.ts +1 -0
  113. package/models/seriesType/index.js +16 -0
  114. package/models/seriesType/rangeBar.d.ts +43 -0
  115. package/models/seriesType/rangeBar.js +5 -0
  116. package/moduleAugmentation/rangeBarOnClick.d.ts +8 -0
  117. package/moduleAugmentation/rangeBarOnClick.js +8 -0
  118. package/package.json +16 -6
  119. package/typeOverloads/index.d.ts +1 -0
  120. package/typeOverloads/index.js +6 -0
  121. package/typeOverloads/modules.d.ts +22 -0
  122. package/typeOverloads/modules.js +5 -0
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RangeBarPreviewPlot = RangeBarPreviewPlot;
7
+ var _internals = require("@mui/x-charts/internals");
8
+ var _BarChart = require("@mui/x-charts/BarChart");
9
+ var _useRangeBarPlotData = require("../../../BarChartPremium/RangeBar/useRangeBarPlotData");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function RangeBarPreviewPlot(props) {
12
+ const drawingArea = {
13
+ left: props.x,
14
+ top: props.y,
15
+ width: props.width,
16
+ height: props.height,
17
+ right: props.x + props.width,
18
+ bottom: props.y + props.height
19
+ };
20
+ const completedData = useBarPreviewData(props.axisId, drawingArea);
21
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
22
+ children: completedData.map(({
23
+ seriesId,
24
+ layout,
25
+ xOrigin,
26
+ yOrigin,
27
+ data
28
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
29
+ children: data.map(({
30
+ dataIndex,
31
+ color,
32
+ x,
33
+ y,
34
+ width,
35
+ height
36
+ }) => {
37
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarChart.BarElement, {
38
+ id: seriesId,
39
+ dataIndex: dataIndex,
40
+ color: color,
41
+ skipAnimation: true,
42
+ layout: layout ?? 'vertical',
43
+ x: x,
44
+ xOrigin: xOrigin,
45
+ y: y,
46
+ yOrigin: yOrigin,
47
+ width: width,
48
+ height: height
49
+ }, dataIndex);
50
+ })
51
+ }, seriesId))
52
+ });
53
+ }
54
+ function useBarPreviewData(axisId, drawingArea) {
55
+ const store = (0, _internals.useStore)();
56
+ const xAxes = store.use(_internals.selectorChartPreviewComputedXAxis, axisId);
57
+ const yAxes = store.use(_internals.selectorChartPreviewComputedYAxis, axisId);
58
+ return (0, _useRangeBarPlotData.useRangeBarPlotData)(drawingArea, xAxes, yAxes);
59
+ }
@@ -1,6 +1,21 @@
1
1
  import * as React from 'react';
2
2
  import { type BarChartProProps } from '@mui/x-charts-pro/BarChartPro';
3
- export interface BarChartPremiumProps extends BarChartProProps {}
3
+ import { type BarSeries } from '@mui/x-charts/BarChart';
4
+ import { type BarItemIdentifier, type RangeBarItemIdentifier, type RangeBarSeriesType } from "../models/index.js";
5
+ export type RangeBarSeries = RangeBarSeriesType;
6
+ export interface BarChartPremiumProps extends Omit<BarChartProProps, 'series' | 'onItemClick'> {
7
+ /**
8
+ * Callback fired when a bar or range bar item is clicked.
9
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
10
+ * @param {BarItemIdentifier | RangeBarItemIdentifier} itemIdentifier The item identifier.
11
+ */
12
+ onItemClick?(event: React.MouseEvent<SVGElement, MouseEvent>, itemIdentifier: BarItemIdentifier | RangeBarItemIdentifier): void;
13
+ /**
14
+ * The series to display in the bar chart.
15
+ * An array of [[BarSeries]] or [[RangeBarSeries]] objects.
16
+ */
17
+ series: ReadonlyArray<BarSeries | RangeBarSeries>;
18
+ }
4
19
  /**
5
20
  * Demos:
6
21
  *
@@ -19,11 +19,14 @@ import { ChartsAxis } from '@mui/x-charts/ChartsAxis';
19
19
  import { ChartZoomSlider } from '@mui/x-charts-pro/ChartZoomSlider';
20
20
  import { ChartsBrushOverlay } from '@mui/x-charts/ChartsBrushOverlay';
21
21
  import { ChartsClipPath } from '@mui/x-charts/ChartsClipPath';
22
- import { useChartContainerProProps } from '@mui/x-charts-pro/internals';
22
+ import { seriesPreviewPlotMap, useChartContainerProProps } from '@mui/x-charts-pro/internals';
23
23
  import { useBarChartPremiumProps } from "./useBarChartPremiumProps.js";
24
24
  import { BAR_CHART_PREMIUM_PLUGINS } from "./BarChartPremium.plugins.js";
25
25
  import { ChartDataProviderPremium } from "../ChartDataProviderPremium/index.js";
26
+ import { RangeBarPlot } from "./RangeBar/RangeBarPlot.js";
27
+ import { RangeBarPreviewPlot } from "../ChartZoomSlider/internals/previews/RangeBarPreviewPlot.js";
26
28
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
29
+ seriesPreviewPlotMap.set('rangeBar', RangeBarPreviewPlot);
27
30
  /**
28
31
  * Demos:
29
32
  *
@@ -52,6 +55,7 @@ const BarChartPremium = /*#__PURE__*/React.forwardRef(function BarChartPremium(i
52
55
  chartsWrapperProps,
53
56
  chartContainerProps,
54
57
  barPlotProps,
58
+ rangeBarPlotProps,
55
59
  gridProps,
56
60
  clipPathProps,
57
61
  clipPathGroupProps,
@@ -77,7 +81,7 @@ const BarChartPremium = /*#__PURE__*/React.forwardRef(function BarChartPremium(i
77
81
  children: /*#__PURE__*/_jsxs(ChartsWrapper, _extends({}, chartsWrapperProps, {
78
82
  children: [showToolbar ? /*#__PURE__*/_jsx(Toolbar, _extends({}, props.slotProps?.toolbar)) : null, !props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
79
83
  children: [/*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
80
- children: [/*#__PURE__*/_jsx(BarPlot, _extends({}, barPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps))]
84
+ children: [/*#__PURE__*/_jsx(BarPlot, _extends({}, barPlotProps)), /*#__PURE__*/_jsx(RangeBarPlot, _extends({}, rangeBarPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps))]
81
85
  })), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartZoomSlider, {}), /*#__PURE__*/_jsx(ChartsBrushOverlay, {}), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
82
86
  })), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props.slotProps?.tooltip))]
83
87
  }))
@@ -158,6 +162,31 @@ process.env.NODE_ENV !== "production" ? BarChartPremium.propTypes = {
158
162
  * The height of the chart in px. If not defined, it takes the height of the parent element.
159
163
  */
160
164
  height: PropTypes.number,
165
+ /**
166
+ * List of hidden series and/or items.
167
+ *
168
+ * Different chart types use different keys.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * [
173
+ * {
174
+ * type: 'pie',
175
+ * seriesId: 'series-1',
176
+ * dataIndex: 3,
177
+ * },
178
+ * {
179
+ * type: 'line',
180
+ * seriesId: 'series-2',
181
+ * }
182
+ * ]
183
+ * ```
184
+ */
185
+ hiddenItems: PropTypes.arrayOf(PropTypes.shape({
186
+ dataIndex: PropTypes.number,
187
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
188
+ type: PropTypes.oneOf(['bar']).isRequired
189
+ })),
161
190
  /**
162
191
  * If `true`, the legend is not rendered.
163
192
  */
@@ -225,6 +254,11 @@ process.env.NODE_ENV !== "production" ? BarChartPremium.propTypes = {
225
254
  * @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
226
255
  */
227
256
  onAxisClick: PropTypes.func,
257
+ /**
258
+ * Callback fired when any hidden identifiers change.
259
+ * @param {VisibilityIdentifier[]} hiddenItems The new list of hidden identifiers.
260
+ */
261
+ onHiddenItemsChange: PropTypes.func,
228
262
  /**
229
263
  * The callback fired when the highlighted item changes.
230
264
  *
@@ -251,6 +285,15 @@ process.env.NODE_ENV !== "production" ? BarChartPremium.propTypes = {
251
285
  * @param {ZoomData[]} zoomData Updated zoom data.
252
286
  */
253
287
  onZoomChange: PropTypes.func,
288
+ /**
289
+ * The type of renderer to use for the bar plot.
290
+ * - `svg-single`: Renders every bar in a `<rect />` element.
291
+ * - `svg-batch`: Batch renders bars in `<path />` elements for better performance with large datasets, at the cost of some limitations.
292
+ * Read more: https://mui.com/x/react-charts/bars/#performance
293
+ *
294
+ * @default 'svg-single'
295
+ */
296
+ renderer: PropTypes.oneOf(['svg-batch', 'svg-single']),
254
297
  /**
255
298
  * The series to display in the bar chart.
256
299
  * An array of [[BarSeries]] or [[RangeBarSeries]] objects.
@@ -0,0 +1,3 @@
1
+ import { type BarProps } from '@mui/x-charts/BarChart';
2
+ export interface AnimatedRangeBarElementProps extends BarProps {}
3
+ export declare function AnimatedRangeBarElement(props: AnimatedRangeBarElementProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,21 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
+ const _excluded = ["ownerState", "skipAnimation", "id", "dataIndex", "xOrigin", "yOrigin"];
6
+ import * as React from 'react';
7
+ import { useAnimateRangeBar } from "../../hooks/animation/useAnimateRangeBar.js";
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ export function AnimatedRangeBarElement(props) {
10
+ const {
11
+ ownerState
12
+ } = props,
13
+ other = _objectWithoutPropertiesLoose(props, _excluded);
14
+ const animatedProps = useAnimateRangeBar(props);
15
+ return /*#__PURE__*/_jsx("rect", _extends({}, other, {
16
+ filter: ownerState.isHighlighted ? 'brightness(120%)' : undefined,
17
+ opacity: ownerState.isFaded ? 0.3 : 1,
18
+ "data-highlighted": ownerState.isHighlighted || undefined,
19
+ "data-faded": ownerState.isFaded || undefined
20
+ }, animatedProps));
21
+ }
@@ -0,0 +1,46 @@
1
+ import * as React from 'react';
2
+ import { type BarElementSlotProps, type BarElementSlots, type BarLabelSlots, type BarLabelSlotProps } from '@mui/x-charts/BarChart';
3
+ import { type RangeBarItemIdentifier } from "../../models/index.js";
4
+ export interface RangeBarPlotSlots extends BarElementSlots, BarLabelSlots {}
5
+ export interface RangeBarPlotSlotProps extends BarElementSlotProps, BarLabelSlotProps {}
6
+ export interface RangeBarPlotProps {
7
+ /**
8
+ * If `true`, animations are skipped.
9
+ * @default undefined
10
+ */
11
+ skipAnimation?: boolean;
12
+ /**
13
+ * Callback fired when a bar item is clicked.
14
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
15
+ * @param {RangeBarItemIdentifier} barItemIdentifier The range bar item identifier.
16
+ */
17
+ onItemClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, barItemIdentifier: RangeBarItemIdentifier) => void;
18
+ /**
19
+ * Defines the border radius of the bar element.
20
+ */
21
+ borderRadius?: number;
22
+ /**
23
+ * The props used for each component slot.
24
+ * @default {}
25
+ */
26
+ slotProps?: RangeBarPlotSlotProps;
27
+ /**
28
+ * Overridable component slots.
29
+ * @default {}
30
+ */
31
+ slots?: RangeBarPlotSlots;
32
+ }
33
+ /**
34
+ * Demos:
35
+ *
36
+ * - [Range Bar](https://mui.com/x/react-charts/range-bar/)
37
+ *
38
+ * API:
39
+ *
40
+ * - [RangeBarPlot API](https://mui.com/x/api/charts/range-bar-plot/)
41
+ */
42
+ declare function RangeBarPlot(props: RangeBarPlotProps): React.JSX.Element;
43
+ declare namespace RangeBarPlot {
44
+ var propTypes: any;
45
+ }
46
+ export { RangeBarPlot };
@@ -0,0 +1,135 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
+ const _excluded = ["skipAnimation", "onItemClick", "borderRadius"];
6
+ import * as React from 'react';
7
+ import PropTypes from 'prop-types';
8
+ import { styled } from '@mui/material/styles';
9
+ import { useSkipAnimation } from '@mui/x-charts/internals';
10
+ import { BarElement, barElementClasses } from '@mui/x-charts/BarChart';
11
+ import { useDrawingArea, useXAxes, useYAxes } from '@mui/x-charts/hooks';
12
+ import { useIsZoomInteracting } from '@mui/x-charts-pro/hooks';
13
+ import { useUtilityClasses } from "./useUtilityClasses.js";
14
+ import { useRangeBarPlotData } from "./useRangeBarPlotData.js";
15
+ import { AnimatedRangeBarElement } from "./AnimatedRangeBarElement.js";
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ const RangeBarPlotRoot = styled('g', {
18
+ name: 'MuiRangeBarPlot',
19
+ slot: 'Root'
20
+ })({
21
+ [`& .${barElementClasses.root}`]: {
22
+ transition: 'opacity 0.2s ease-in, fill 0.2s ease-in'
23
+ }
24
+ });
25
+
26
+ /**
27
+ * Demos:
28
+ *
29
+ * - [Range Bar](https://mui.com/x/react-charts/range-bar/)
30
+ *
31
+ * API:
32
+ *
33
+ * - [RangeBarPlot API](https://mui.com/x/api/charts/range-bar-plot/)
34
+ */
35
+ function RangeBarPlot(props) {
36
+ const {
37
+ skipAnimation: inSkipAnimation,
38
+ onItemClick,
39
+ borderRadius
40
+ } = props,
41
+ other = _objectWithoutPropertiesLoose(props, _excluded);
42
+ const isZoomInteracting = useIsZoomInteracting();
43
+ const skipAnimation = useSkipAnimation(isZoomInteracting || inSkipAnimation);
44
+ const {
45
+ xAxis: xAxes
46
+ } = useXAxes();
47
+ const {
48
+ yAxis: yAxes
49
+ } = useYAxes();
50
+ const completedData = useRangeBarPlotData(useDrawingArea(), xAxes, yAxes);
51
+ const classes = useUtilityClasses();
52
+ const slots = _extends({}, props.slots, {
53
+ bar: props.slots?.bar ?? AnimatedRangeBarElement
54
+ });
55
+ return /*#__PURE__*/_jsx(RangeBarPlotRoot, {
56
+ className: classes.root,
57
+ children: completedData.map(({
58
+ seriesId,
59
+ layout,
60
+ xOrigin,
61
+ yOrigin,
62
+ data
63
+ }) => {
64
+ return /*#__PURE__*/_jsx("g", {
65
+ "data-series": seriesId,
66
+ className: classes.series,
67
+ children: data.map(({
68
+ dataIndex,
69
+ color,
70
+ x,
71
+ y,
72
+ width,
73
+ height
74
+ }) => {
75
+ return /*#__PURE__*/_jsx(BarElement, _extends({
76
+ id: seriesId,
77
+ dataIndex: dataIndex,
78
+ color: color,
79
+ skipAnimation: skipAnimation ?? false,
80
+ layout: layout ?? 'vertical',
81
+ x: x,
82
+ xOrigin: xOrigin,
83
+ y: y,
84
+ yOrigin: yOrigin,
85
+ width: width,
86
+ height: height,
87
+ rx: borderRadius,
88
+ ry: borderRadius
89
+ }, other, {
90
+ slots: slots,
91
+ onClick: onItemClick && (event => {
92
+ onItemClick(event, {
93
+ type: 'rangeBar',
94
+ seriesId,
95
+ dataIndex
96
+ });
97
+ })
98
+ }), dataIndex);
99
+ })
100
+ }, seriesId);
101
+ })
102
+ });
103
+ }
104
+ process.env.NODE_ENV !== "production" ? RangeBarPlot.propTypes = {
105
+ // ----------------------------- Warning --------------------------------
106
+ // | These PropTypes are generated from the TypeScript type definitions |
107
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
108
+ // ----------------------------------------------------------------------
109
+ /**
110
+ * Defines the border radius of the bar element.
111
+ */
112
+ borderRadius: PropTypes.number,
113
+ /**
114
+ * Callback fired when a bar item is clicked.
115
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
116
+ * @param {RangeBarItemIdentifier} barItemIdentifier The range bar item identifier.
117
+ */
118
+ onItemClick: PropTypes.func,
119
+ /**
120
+ * If `true`, animations are skipped.
121
+ * @default undefined
122
+ */
123
+ skipAnimation: PropTypes.bool,
124
+ /**
125
+ * The props used for each component slot.
126
+ * @default {}
127
+ */
128
+ slotProps: PropTypes.object,
129
+ /**
130
+ * Overridable component slots.
131
+ * @default {}
132
+ */
133
+ slots: PropTypes.object
134
+ } : void 0;
135
+ export { RangeBarPlot };
@@ -0,0 +1,3 @@
1
+ import { type CartesianExtremumGetter } from '@mui/x-charts/internals';
2
+ export declare const getExtremumX: CartesianExtremumGetter<'rangeBar'>;
3
+ export declare const getExtremumY: CartesianExtremumGetter<'rangeBar'>;
@@ -0,0 +1,77 @@
1
+ import { findMinMax } from '@mui/x-charts/internals';
2
+ const createResult = (data, direction) => {
3
+ if (direction === 'x') {
4
+ return {
5
+ x: data,
6
+ y: null
7
+ };
8
+ }
9
+ return {
10
+ x: null,
11
+ y: data
12
+ };
13
+ };
14
+ const getBaseExtremum = params => {
15
+ const {
16
+ axis,
17
+ getFilters,
18
+ isDefaultAxis
19
+ } = params;
20
+ const filter = getFilters?.({
21
+ currentAxisId: axis.id,
22
+ isDefaultAxis
23
+ });
24
+ const data = filter ? axis.data?.filter((_, i) => filter({
25
+ x: null,
26
+ y: null
27
+ }, i)) : axis.data;
28
+ return findMinMax(data ?? []);
29
+ };
30
+ const getValueExtremum = direction => params => {
31
+ const {
32
+ series,
33
+ axis,
34
+ getFilters,
35
+ isDefaultAxis
36
+ } = params;
37
+ return Object.keys(series).filter(seriesId => {
38
+ const axisId = direction === 'x' ? series[seriesId].xAxisId : series[seriesId].yAxisId;
39
+ return axisId === axis.id || isDefaultAxis && axisId === undefined;
40
+ }).reduce((acc, seriesId) => {
41
+ const {
42
+ data
43
+ } = series[seriesId];
44
+ const filter = getFilters?.({
45
+ currentAxisId: axis.id,
46
+ isDefaultAxis,
47
+ seriesXAxisId: series[seriesId].xAxisId,
48
+ seriesYAxisId: series[seriesId].yAxisId
49
+ });
50
+ const [seriesMin, seriesMax] = data?.reduce((seriesAcc, values, index) => {
51
+ if (values == null) {
52
+ return seriesAcc;
53
+ }
54
+ if (filter && (!filter(createResult(values[0], direction), index) || !filter(createResult(values[1], direction), index))) {
55
+ return seriesAcc;
56
+ }
57
+ return [Math.min(values[0], values[1], seriesAcc[0]), Math.max(values[0], values[1], seriesAcc[1])];
58
+ }, [Infinity, -Infinity]) ?? [Infinity, -Infinity];
59
+ return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
60
+ }, [Infinity, -Infinity]);
61
+ };
62
+ export const getExtremumX = params => {
63
+ // Notice that bar should be all horizontal or all vertical.
64
+ // Don't think it's a problem for now
65
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
66
+ if (isHorizontal) {
67
+ return getValueExtremum('x')(params);
68
+ }
69
+ return getBaseExtremum(params);
70
+ };
71
+ export const getExtremumY = params => {
72
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
73
+ if (isHorizontal) {
74
+ return getBaseExtremum(params);
75
+ }
76
+ return getValueExtremum('y')(params);
77
+ };
@@ -0,0 +1,3 @@
1
+ import { type ColorProcessor } from '@mui/x-charts/internals';
2
+ declare const getColor: ColorProcessor<'rangeBar'>;
3
+ export default getColor;
@@ -0,0 +1,37 @@
1
+ import { getSeriesColorFn } from '@mui/x-charts/internals';
2
+ const getColor = (series, xAxis, yAxis) => {
3
+ const verticalLayout = series.layout === 'vertical';
4
+ const bandColorScale = verticalLayout ? xAxis?.colorScale : yAxis?.colorScale;
5
+ const bandValues = verticalLayout ? xAxis?.data : yAxis?.data;
6
+ const getSeriesColor = getSeriesColorFn(series);
7
+ if (bandColorScale && bandValues) {
8
+ return dataIndex => {
9
+ if (dataIndex === undefined) {
10
+ return series.color;
11
+ }
12
+ const value = bandValues[dataIndex];
13
+ const color = value === null ? getSeriesColor({
14
+ value,
15
+ dataIndex
16
+ }) : bandColorScale(value);
17
+ if (color === null) {
18
+ return getSeriesColor({
19
+ value,
20
+ dataIndex
21
+ });
22
+ }
23
+ return color;
24
+ };
25
+ }
26
+ return dataIndex => {
27
+ if (dataIndex === undefined) {
28
+ return series.color;
29
+ }
30
+ const value = series.data[dataIndex];
31
+ return getSeriesColor({
32
+ value,
33
+ dataIndex
34
+ });
35
+ };
36
+ };
37
+ export default getColor;
@@ -0,0 +1,19 @@
1
+ import { type AllSeriesType } from '@mui/x-charts/models';
2
+ export declare function getSeriesWithDefaultValues(seriesData: AllSeriesType<'rangeBar'>, seriesIndex: number, colors: readonly string[]): {
3
+ id: import("@mui/x-charts").SeriesId;
4
+ color: string;
5
+ type: "rangeBar";
6
+ data?: ReadonlyArray<import("../../../index.js").RangeBarValueType | null>;
7
+ datasetKeys?: {
8
+ start: string;
9
+ end: string;
10
+ };
11
+ label?: string | ((location: "tooltip" | "legend") => string);
12
+ layout?: "horizontal" | "vertical";
13
+ valueFormatter?: import("@mui/x-charts/internals").SeriesValueFormatter<import("../../../index.js").RangeBarValueType | null> | undefined;
14
+ highlightScope?: import("@mui/x-charts").HighlightScope;
15
+ labelMarkType?: import("@mui/x-charts/internals").ChartsLabelMarkType;
16
+ colorGetter?: ((data: import("@mui/x-charts/internals").ColorCallbackValue<import("../../../index.js").RangeBarValueType | null>) => string) | undefined;
17
+ xAxisId?: import("@mui/x-charts/internals").AxisId;
18
+ yAxisId?: import("@mui/x-charts/internals").AxisId;
19
+ };
@@ -0,0 +1,7 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ export function getSeriesWithDefaultValues(seriesData, seriesIndex, colors) {
3
+ return _extends({}, seriesData, {
4
+ id: seriesData.id ?? `auto-generated-id-${seriesIndex}`,
5
+ color: seriesData.color ?? colors[seriesIndex % colors.length]
6
+ });
7
+ }
@@ -0,0 +1,2 @@
1
+ import { type ChartSeriesTypeConfig } from '@mui/x-charts/internals';
2
+ export declare const rangeBarSeriesConfig: ChartSeriesTypeConfig<'rangeBar'>;
@@ -0,0 +1,21 @@
1
+ import { cartesianSeriesTypes, identifierSerializerSeriesIdDataIndex } from '@mui/x-charts/internals';
2
+ import { getExtremumX, getExtremumY } from "./extrema.js";
3
+ import tooltipGetter, { axisTooltipGetter } from "./tooltip.js";
4
+ import seriesProcessor from "./seriesProcessor.js";
5
+ import getColor from "./getColor.js";
6
+ import legendGetter from "./legend.js";
7
+ import tooltipItemPositionGetter from "./tooltipPosition.js";
8
+ import { getSeriesWithDefaultValues } from "./getSeriesWithDefaultValues.js";
9
+ export const rangeBarSeriesConfig = {
10
+ seriesProcessor,
11
+ colorProcessor: getColor,
12
+ legendGetter,
13
+ tooltipGetter,
14
+ tooltipItemPositionGetter,
15
+ axisTooltipGetter,
16
+ xExtremumGetter: getExtremumX,
17
+ yExtremumGetter: getExtremumY,
18
+ getSeriesWithDefaultValues,
19
+ identifierSerializer: identifierSerializerSeriesIdDataIndex
20
+ };
21
+ cartesianSeriesTypes.addType('rangeBar');
@@ -0,0 +1,3 @@
1
+ import { type LegendGetter } from '@mui/x-charts/internals';
2
+ declare const legendGetter: LegendGetter<'rangeBar'>;
3
+ export default legendGetter;
@@ -0,0 +1,23 @@
1
+ import { getLabel } from '@mui/x-charts/internals';
2
+ const legendGetter = params => {
3
+ const {
4
+ seriesOrder,
5
+ series
6
+ } = params;
7
+ return seriesOrder.reduce((acc, seriesId) => {
8
+ const formattedLabel = getLabel(series[seriesId].label, 'legend');
9
+ if (formattedLabel === undefined) {
10
+ return acc;
11
+ }
12
+ acc.push({
13
+ type: 'rangeBar',
14
+ markType: series[seriesId].labelMarkType,
15
+ id: seriesId,
16
+ seriesId,
17
+ color: series[seriesId].color,
18
+ label: formattedLabel
19
+ });
20
+ return acc;
21
+ }, []);
22
+ };
23
+ export default legendGetter;
@@ -0,0 +1,3 @@
1
+ import { type SeriesProcessor } from '@mui/x-charts/internals';
2
+ declare const seriesProcessor: SeriesProcessor<'rangeBar'>;
3
+ export default seriesProcessor;
@@ -0,0 +1,47 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { warnOnce } from '@mui/x-internals/warning';
3
+ const rangeBarValueFormatter = v => v == null ? '' : `[${v[0]}, ${v[1]}]`;
4
+ const seriesProcessor = (params, dataset) => {
5
+ const {
6
+ seriesOrder,
7
+ series
8
+ } = params;
9
+ const completedSeries = {};
10
+ for (const id of seriesOrder) {
11
+ const seriesData = series[id];
12
+ const datasetKeys = seriesData?.datasetKeys;
13
+ if (seriesData.data === undefined && dataset === undefined && process.env.NODE_ENV !== 'production') {
14
+ throw new Error([`MUI X Charts: range bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
15
+ }
16
+ const missingKeys = ['start', 'end'].filter(key => typeof datasetKeys?.[key] !== 'string');
17
+ if (datasetKeys && missingKeys.length > 0) {
18
+ throw new Error([`MUI X Charts: range bar series with id='${id}' has incomplete datasetKeys.`, `Properties ${missingKeys.map(key => `"${key}"`).join(', ')} are missing.`].join('\n'));
19
+ }
20
+ completedSeries[id] = _extends({
21
+ layout: 'vertical'
22
+ }, series[id], {
23
+ valueFormatter: series[id].valueFormatter ?? rangeBarValueFormatter,
24
+ data: datasetKeys ? dataset.map(data => {
25
+ const start = data[datasetKeys.start];
26
+ const end = data[datasetKeys.end];
27
+ if (typeof start !== 'number' || typeof end !== 'number') {
28
+ if (process.env.NODE_ENV !== 'production') {
29
+ if (start !== null) {
30
+ warnOnce([`MUI X Charts: Your dataset key "start" is used for plotting an range bar, but contains nonnumerical elements.`, 'Range bars only support numbers.']);
31
+ }
32
+ if (end !== null) {
33
+ warnOnce([`MUI X Charts: Your dataset key "end" is used for plotting an range bar, but contains nonnumerical elements.`, 'Range bars only support numbers.']);
34
+ }
35
+ }
36
+ return null;
37
+ }
38
+ return [start, end];
39
+ }) : series[id].data
40
+ });
41
+ }
42
+ return {
43
+ seriesOrder,
44
+ series: completedSeries
45
+ };
46
+ };
47
+ export default seriesProcessor;
@@ -0,0 +1,4 @@
1
+ import { type AxisTooltipGetter, type TooltipGetter } from '@mui/x-charts/internals';
2
+ declare const tooltipGetter: TooltipGetter<'rangeBar'>;
3
+ export declare const axisTooltipGetter: AxisTooltipGetter<'rangeBar', 'x' | 'y'>;
4
+ export default tooltipGetter;