@mui/x-charts 6.0.0-alpha.2 → 6.0.0-alpha.3

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 (90) hide show
  1. package/BarChart/BarChart.d.ts +1 -4
  2. package/BarChart/BarChart.js +5 -3
  3. package/BarChart/BarPlot.js +42 -8
  4. package/CHANGELOG.md +232 -114
  5. package/ChartContainer/index.d.ts +3 -1
  6. package/ChartContainer/index.js +10 -6
  7. package/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  8. package/LineChart/LineChart.d.ts +1 -4
  9. package/LineChart/LineChart.js +5 -3
  10. package/ResponsiveChartContainer/index.d.ts +1 -1
  11. package/ResponsiveChartContainer/index.js +11 -9
  12. package/ScatterChart/Scatter.d.ts +1 -1
  13. package/ScatterChart/ScatterChart.d.ts +1 -4
  14. package/ScatterChart/ScatterChart.js +5 -3
  15. package/context/CartesianContextProvider.js +31 -20
  16. package/context/SeriesContextProvider.js +2 -2
  17. package/esm/BarChart/BarChart.js +3 -2
  18. package/esm/BarChart/BarPlot.js +44 -8
  19. package/esm/ChartContainer/index.js +7 -5
  20. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  21. package/esm/LineChart/LineChart.js +3 -2
  22. package/esm/ResponsiveChartContainer/index.js +9 -8
  23. package/esm/ScatterChart/ScatterChart.js +3 -2
  24. package/esm/context/CartesianContextProvider.js +31 -18
  25. package/esm/context/SeriesContextProvider.js +2 -2
  26. package/esm/hooks/index.js +2 -0
  27. package/esm/hooks/useAxisEvents.js +12 -7
  28. package/esm/hooks/useDrawingArea.js +16 -0
  29. package/esm/hooks/useScale.js +19 -21
  30. package/esm/hooks/useTicks.js +26 -13
  31. package/esm/index.js +1 -0
  32. package/esm/internals/getScale.js +17 -0
  33. package/esm/internals/isBandScale.js +3 -0
  34. package/esm/models/axis.js +6 -1
  35. package/hooks/index.d.ts +2 -0
  36. package/hooks/index.js +27 -0
  37. package/hooks/package.json +6 -0
  38. package/hooks/useAxisEvents.js +14 -9
  39. package/hooks/useDrawingArea.d.ts +6 -0
  40. package/hooks/useDrawingArea.js +24 -0
  41. package/hooks/useScale.d.ts +3 -6
  42. package/hooks/useScale.js +24 -24
  43. package/hooks/useTicks.d.ts +1 -1
  44. package/hooks/useTicks.js +19 -9
  45. package/index.d.ts +1 -0
  46. package/index.js +12 -1
  47. package/internals/getScale.d.ts +2 -0
  48. package/internals/getScale.js +23 -0
  49. package/internals/isBandScale.d.ts +3 -0
  50. package/internals/isBandScale.js +9 -0
  51. package/legacy/BarChart/BarChart.js +3 -2
  52. package/legacy/BarChart/BarPlot.js +44 -10
  53. package/legacy/ChartContainer/index.js +7 -5
  54. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  55. package/legacy/LineChart/LineChart.js +3 -2
  56. package/legacy/ResponsiveChartContainer/index.js +9 -8
  57. package/legacy/ScatterChart/ScatterChart.js +3 -2
  58. package/legacy/context/CartesianContextProvider.js +31 -18
  59. package/legacy/context/SeriesContextProvider.js +2 -2
  60. package/legacy/hooks/index.js +2 -0
  61. package/legacy/hooks/useAxisEvents.js +12 -7
  62. package/legacy/hooks/useDrawingArea.js +17 -0
  63. package/legacy/hooks/useScale.js +17 -21
  64. package/legacy/hooks/useTicks.js +26 -13
  65. package/legacy/index.js +2 -1
  66. package/legacy/internals/getScale.js +17 -0
  67. package/legacy/internals/isBandScale.js +3 -0
  68. package/legacy/models/axis.js +6 -1
  69. package/models/axis.d.ts +25 -12
  70. package/models/axis.js +9 -1
  71. package/models/seriesType/pie.d.ts +2 -2
  72. package/modern/BarChart/BarChart.js +3 -2
  73. package/modern/BarChart/BarPlot.js +44 -8
  74. package/modern/ChartContainer/index.js +7 -5
  75. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  76. package/modern/LineChart/LineChart.js +3 -2
  77. package/modern/ResponsiveChartContainer/index.js +9 -8
  78. package/modern/ScatterChart/ScatterChart.js +3 -2
  79. package/modern/context/CartesianContextProvider.js +29 -18
  80. package/modern/context/SeriesContextProvider.js +2 -2
  81. package/modern/hooks/index.js +2 -0
  82. package/modern/hooks/useAxisEvents.js +12 -7
  83. package/modern/hooks/useDrawingArea.js +16 -0
  84. package/modern/hooks/useScale.js +19 -21
  85. package/modern/hooks/useTicks.js +18 -8
  86. package/modern/index.js +2 -1
  87. package/modern/internals/getScale.js +17 -0
  88. package/modern/internals/isBandScale.js +3 -0
  89. package/modern/models/axis.js +6 -1
  90. package/package.json +1 -1
@@ -6,4 +6,6 @@ import { CartesianContextProviderProps } from '../context/CartesianContextProvid
6
6
  export type ChartContainerProps = Omit<ChartsSurfaceProps & SeriesContextProviderProps & Omit<DrawingProviderProps, 'svgRef'> & CartesianContextProviderProps, 'children'> & {
7
7
  children?: React.ReactNode;
8
8
  };
9
- export declare function ChartContainer(props: ChartContainerProps): React.JSX.Element;
9
+ export declare const ChartContainer: React.ForwardRefExoticComponent<Omit<ChartsSurfaceProps & SeriesContextProviderProps & Omit<DrawingProviderProps, "svgRef"> & CartesianContextProviderProps, "children"> & {
10
+ children?: React.ReactNode;
11
+ } & React.RefAttributes<unknown>>;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.ChartContainer = ChartContainer;
7
+ exports.ChartContainer = void 0;
7
8
  var React = _interopRequireWildcard(require("react"));
9
+ var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
8
10
  var _DrawingProvider = require("../context/DrawingProvider");
9
11
  var _SeriesContextProvider = require("../context/SeriesContextProvider");
10
12
  var _InteractionProvider = require("../context/InteractionProvider");
@@ -14,7 +16,7 @@ var _HighlightProvider = require("../context/HighlightProvider");
14
16
  var _jsxRuntime = require("react/jsx-runtime");
15
17
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
- function ChartContainer(props) {
19
+ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
18
20
  const {
19
21
  width,
20
22
  height,
@@ -29,12 +31,13 @@ function ChartContainer(props) {
29
31
  disableAxisListener,
30
32
  children
31
33
  } = props;
32
- const ref = React.useRef(null);
34
+ const svgRef = React.useRef(null);
35
+ const handleRef = (0, _useForkRef.default)(ref, svgRef);
33
36
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DrawingProvider.DrawingProvider, {
34
37
  width: width,
35
38
  height: height,
36
39
  margin: margin,
37
- svgRef: ref,
40
+ svgRef: svgRef,
38
41
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SeriesContextProvider.SeriesContextProvider, {
39
42
  series: series,
40
43
  colors: colors,
@@ -46,7 +49,7 @@ function ChartContainer(props) {
46
49
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsSurface.ChartsSurface, {
47
50
  width: width,
48
51
  height: height,
49
- ref: ref,
52
+ ref: handleRef,
50
53
  sx: sx,
51
54
  title: title,
52
55
  desc: desc,
@@ -58,4 +61,5 @@ function ChartContainer(props) {
58
61
  })
59
62
  })
60
63
  });
61
- }
64
+ });
65
+ exports.ChartContainer = ChartContainer;
@@ -10,6 +10,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
10
10
  var _InteractionProvider = require("../context/InteractionProvider");
11
11
  var _CartesianContextProvider = require("../context/CartesianContextProvider");
12
12
  var _useScale = require("../hooks/useScale");
13
+ var _isBandScale = require("../internals/isBandScale");
13
14
  var _jsxRuntime = require("react/jsx-runtime");
14
15
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -33,8 +34,8 @@ function ChartsAxisHighlight(props) {
33
34
  } = React.useContext(_InteractionProvider.InteractionContext);
34
35
  const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
35
36
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
36
- children: [xAxisHighlight === 'band' && axis.x !== null && (0, _useScale.isBandScale)(xScale) && /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
37
- d: `M ${xScale(axis.x.value)} ${yScale.range()[0]} L ${xScale(axis.x.value) + xScale.bandwidth()} ${yScale.range()[0]} L ${xScale(axis.x.value) + xScale.bandwidth()} ${yScale.range()[1]} L ${xScale(axis.x.value)} ${yScale.range()[1]} Z`,
37
+ children: [xAxisHighlight === 'band' && axis.x !== null && (0, _isBandScale.isBandScale)(xScale) && /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
38
+ d: `M ${xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2} ${yScale.range()[0]} l ${xScale.step()} 0 l 0 ${yScale.range()[1] - yScale.range()[0]} l ${-xScale.step()} 0 Z`,
38
39
  fill: "gray",
39
40
  fillOpacity: 0.1,
40
41
  style: {
@@ -12,8 +12,5 @@ export interface LineChartProps extends Omit<ResponsiveChartContainerProps, 'ser
12
12
  axisHighlight?: ChartsAxisHighlightProps;
13
13
  legend?: ChartsLegendProps;
14
14
  }
15
- declare function LineChart(props: LineChartProps): React.JSX.Element;
16
- declare namespace LineChart {
17
- var propTypes: any;
18
- }
15
+ declare const LineChart: React.ForwardRefExoticComponent<LineChartProps & React.RefAttributes<unknown>>;
19
16
  export { LineChart };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.LineChart = LineChart;
7
+ exports.LineChart = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var React = _interopRequireWildcard(require("react"));
10
10
  var _useId = _interopRequireDefault(require("@mui/utils/useId"));
@@ -22,7 +22,7 @@ var _ChartsClipPath = require("../ChartsClipPath");
22
22
  var _jsxRuntime = require("react/jsx-runtime");
23
23
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
24
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
- function LineChart(props) {
25
+ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
26
26
  const {
27
27
  xAxis,
28
28
  yAxis,
@@ -46,6 +46,7 @@ function LineChart(props) {
46
46
  const id = (0, _useId.default)();
47
47
  const clipPathId = `${id}-clip-path`;
48
48
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, {
49
+ ref: ref,
49
50
  series: series.map(s => (0, _extends2.default)({
50
51
  type: 'line'
51
52
  }, s)),
@@ -75,7 +76,8 @@ function LineChart(props) {
75
76
  id: clipPathId
76
77
  }), children]
77
78
  });
78
- }
79
+ });
80
+ exports.LineChart = LineChart;
79
81
  process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
80
82
  // ----------------------------- Warning --------------------------------
81
83
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -2,4 +2,4 @@ import * as React from 'react';
2
2
  import { ChartContainerProps } from '../ChartContainer';
3
3
  import { MakeOptional } from '../models/helpers';
4
4
  export type ResponsiveChartContainerProps = MakeOptional<ChartContainerProps, 'width' | 'height'>;
5
- export declare function ResponsiveChartContainer(props: ResponsiveChartContainerProps): React.JSX.Element;
5
+ export declare const ResponsiveChartContainer: React.ForwardRefExoticComponent<Omit<ChartContainerProps, "height" | "width"> & Partial<Pick<ChartContainerProps, "height" | "width">> & React.RefAttributes<unknown>>;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.ResponsiveChartContainer = ResponsiveChartContainer;
7
+ exports.ResponsiveChartContainer = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
10
  var React = _interopRequireWildcard(require("react"));
@@ -99,22 +99,24 @@ const ResizableContainer = (0, _styles.styled)('div', {
99
99
  height: '100%'
100
100
  }
101
101
  }));
102
- function ResponsiveChartContainer(props) {
102
+ const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
103
103
  const {
104
- width: propsWidth,
105
- height: propsHeight
104
+ width: inWidth,
105
+ height: inHeight
106
106
  } = props,
107
107
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
108
- const [containerRef, width, height] = useChartDimensions(propsWidth, propsHeight);
108
+ const [containerRef, width, height] = useChartDimensions(inWidth, inHeight);
109
109
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ResizableContainer, {
110
110
  ref: containerRef,
111
111
  ownerState: {
112
- width: props.width,
113
- height: props.height
112
+ width: inWidth,
113
+ height: inHeight
114
114
  },
115
115
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartContainer.ChartContainer, (0, _extends2.default)({}, other, {
116
116
  width: width,
117
- height: height
117
+ height: height,
118
+ ref: ref
118
119
  }))
119
120
  });
120
- }
121
+ });
122
+ exports.ResponsiveChartContainer = ResponsiveChartContainer;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { DefaultizedScatterSeriesType } from '../models/seriesType/scatter';
3
- import { D3Scale } from '../hooks/useScale';
3
+ import { D3Scale } from '../models/axis';
4
4
  export interface ScatterProps {
5
5
  series: DefaultizedScatterSeriesType;
6
6
  xScale: D3Scale;
@@ -12,8 +12,5 @@ export interface ScatterChartProps extends Omit<ResponsiveChartContainerProps, '
12
12
  axisHighlight?: ChartsAxisHighlightProps;
13
13
  legend?: ChartsLegendProps;
14
14
  }
15
- declare function ScatterChart(props: ScatterChartProps): React.JSX.Element;
16
- declare namespace ScatterChart {
17
- var propTypes: any;
18
- }
15
+ declare const ScatterChart: React.ForwardRefExoticComponent<ScatterChartProps & React.RefAttributes<unknown>>;
19
16
  export { ScatterChart };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.ScatterChart = ScatterChart;
7
+ exports.ScatterChart = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var React = _interopRequireWildcard(require("react"));
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -17,7 +17,7 @@ var _ChartsAxisHighlight = require("../ChartsAxisHighlight");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
19
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
- function ScatterChart(props) {
20
+ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
21
21
  const {
22
22
  xAxis,
23
23
  yAxis,
@@ -37,6 +37,7 @@ function ScatterChart(props) {
37
37
  children
38
38
  } = props;
39
39
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, {
40
+ ref: ref,
40
41
  series: series.map(s => (0, _extends2.default)({
41
42
  type: 'scatter'
42
43
  }, s)),
@@ -59,7 +60,8 @@ function ScatterChart(props) {
59
60
  trigger: "item"
60
61
  }, tooltip)), children]
61
62
  });
62
- }
63
+ });
64
+ exports.ScatterChart = ScatterChart;
63
65
  process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
64
66
  // ----------------------------- Warning --------------------------------
65
67
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -13,7 +13,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
  var _extremums = require("../BarChart/extremums");
14
14
  var _extremums2 = require("../ScatterChart/extremums");
15
15
  var _extremums3 = require("../LineChart/extremums");
16
- var _useScale = require("../hooks/useScale");
16
+ var _axis = require("../models/axis");
17
+ var _getScale = require("../internals/getScale");
17
18
  var _DrawingProvider = require("./DrawingProvider");
18
19
  var _SeriesContextProvider = require("./SeriesContextProvider");
19
20
  var _constants = require("../constants");
@@ -21,6 +22,8 @@ var _useTicks = require("../hooks/useTicks");
21
22
  var _jsxRuntime = require("react/jsx-runtime");
22
23
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
24
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+ const DEFAULT_CATEGORY_GAP_RATIO = 0.1;
26
+
24
27
  // TODO: those might be better placed in a distinct file
25
28
  const xExtremumGetters = {
26
29
  bar: _extremums.getExtremumX,
@@ -82,29 +85,33 @@ function CartesianContextProvider({
82
85
  allXAxis.forEach((axis, axisIndex) => {
83
86
  const isDefaultAxis = axisIndex === 0;
84
87
  const [minData, maxData] = getAxisExtremum(axis, xExtremumGetters, isDefaultAxis);
85
- const scaleType = axis.scaleType ?? 'linear';
86
88
  const range = [drawingArea.left, drawingArea.left + drawingArea.width];
87
- if (scaleType === 'band') {
88
- completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
89
- scaleType,
90
- scale: (0, _d3Scale.scaleBand)(axis.data, range),
89
+ if ((0, _axis.isBandScaleConfig)(axis)) {
90
+ const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
91
+ completedXAxis[axis.id] = (0, _extends2.default)({
92
+ categoryGapRatio,
93
+ barGapRatio: 0
94
+ }, axis, {
95
+ scale: (0, _d3Scale.scaleBand)(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
91
96
  ticksNumber: axis.data.length
92
97
  });
93
- return;
94
98
  }
95
- if (scaleType === 'point') {
99
+ if ((0, _axis.isPointScaleConfig)(axis)) {
96
100
  completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
97
- scaleType,
98
101
  scale: (0, _d3Scale.scalePoint)(axis.data, range),
99
102
  ticksNumber: axis.data.length
100
103
  });
104
+ }
105
+ if (axis.scaleType === 'band' || axis.scaleType === 'point') {
106
+ // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
101
107
  return;
102
108
  }
109
+ const scaleType = axis.scaleType ?? 'linear';
103
110
  const extremums = [axis.min ?? minData, axis.max ?? maxData];
104
111
  const ticksNumber = (0, _useTicks.getTicksNumber)((0, _extends2.default)({}, axis, {
105
112
  range
106
113
  }));
107
- const niceScale = (0, _useScale.getScale)(scaleType, extremums, range).nice(ticksNumber);
114
+ const niceScale = (0, _getScale.getScale)(scaleType, extremums, range).nice(ticksNumber);
108
115
  const niceDomain = niceScale.domain();
109
116
  const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
110
117
  completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
@@ -126,28 +133,32 @@ function CartesianContextProvider({
126
133
  const isDefaultAxis = axisIndex === 0;
127
134
  const [minData, maxData] = getAxisExtremum(axis, yExtremumGetters, isDefaultAxis);
128
135
  const range = [drawingArea.top + drawingArea.height, drawingArea.top];
129
- const scaleType = axis.scaleType ?? 'linear';
130
- if (scaleType === 'band') {
131
- completedYAxis[axis.id] = (0, _extends2.default)({}, axis, {
132
- scaleType,
133
- scale: (0, _d3Scale.scaleBand)(axis.data, range),
136
+ if ((0, _axis.isBandScaleConfig)(axis)) {
137
+ const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
138
+ completedXAxis[axis.id] = (0, _extends2.default)({
139
+ categoryGapRatio,
140
+ barGapRatio: 0
141
+ }, axis, {
142
+ scale: (0, _d3Scale.scaleBand)(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
134
143
  ticksNumber: axis.data.length
135
144
  });
136
- return;
137
145
  }
138
- if (scaleType === 'point') {
139
- completedYAxis[axis.id] = (0, _extends2.default)({}, axis, {
140
- scaleType,
146
+ if ((0, _axis.isPointScaleConfig)(axis)) {
147
+ completedXAxis[axis.id] = (0, _extends2.default)({}, axis, {
141
148
  scale: (0, _d3Scale.scalePoint)(axis.data, range),
142
149
  ticksNumber: axis.data.length
143
150
  });
151
+ }
152
+ if (axis.scaleType === 'band' || axis.scaleType === 'point') {
153
+ // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
144
154
  return;
145
155
  }
156
+ const scaleType = axis.scaleType ?? 'linear';
146
157
  const extremums = [axis.min ?? minData, axis.max ?? maxData];
147
158
  const ticksNumber = (0, _useTicks.getTicksNumber)((0, _extends2.default)({}, axis, {
148
159
  range
149
160
  }));
150
- const niceScale = (0, _useScale.getScale)(scaleType, extremums, range).nice(ticksNumber);
161
+ const niceScale = (0, _getScale.getScale)(scaleType, extremums, range).nice(ticksNumber);
151
162
  const niceDomain = niceScale.domain();
152
163
  const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
153
164
  completedYAxis[axis.id] = (0, _extends2.default)({}, axis, {
@@ -27,8 +27,8 @@ const seriesTypeFormatter = {
27
27
  pie: _formatter4.default
28
28
  };
29
29
  /**
30
- * This methods is the interface between what the developper is providing and what compoenents receives
31
- * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if soe line data are modified
30
+ * This methods is the interface between what the developer is providing and what components receives
31
+ * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
32
32
  * It also add defaultized values such as the ids, colors
33
33
  * @param series The array of series provided by devs
34
34
  * @param colors The color palette used to defaultize series colors
@@ -12,7 +12,7 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
12
12
  import { ChartsClipPath } from '../ChartsClipPath';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
- function BarChart(props) {
15
+ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
16
16
  const {
17
17
  xAxis,
18
18
  yAxis,
@@ -34,6 +34,7 @@ function BarChart(props) {
34
34
  const id = useId();
35
35
  const clipPathId = `${id}-clip-path`;
36
36
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
37
+ ref: ref,
37
38
  series: series.map(s => _extends({
38
39
  type: 'bar'
39
40
  }, s)),
@@ -65,7 +66,7 @@ function BarChart(props) {
65
66
  id: clipPathId
66
67
  }), children]
67
68
  });
68
- }
69
+ });
69
70
  process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
70
71
  // ----------------------------- Warning --------------------------------
71
72
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -1,9 +1,37 @@
1
1
  import * as React from 'react';
2
2
  import { SeriesContext } from '../context/SeriesContextProvider';
3
3
  import { CartesianContext } from '../context/CartesianContextProvider';
4
- import { isBandScale } from '../hooks/useScale';
5
4
  import { BarElement } from './BarElement';
5
+ import { isBandScaleConfig } from '../models/axis';
6
+
7
+ /**
8
+ * Solution of the equations
9
+ * W = barWidth * N + offset * (N-1)
10
+ * offset / (offset + barWidth) = r
11
+ * @param bandWidth The width available to place bars.
12
+ * @param numberOfGroups The number of bars to place in that space.
13
+ * @param gapRatio The ratio of the gap between bars over the bar width.
14
+ * @returns The bar width and the offset between bars.
15
+ */
6
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
+ function getBandSize({
18
+ bandWidth: W,
19
+ numberOfGroups: N,
20
+ gapRatio: r
21
+ }) {
22
+ if (r === 0) {
23
+ return {
24
+ barWidth: W / N,
25
+ offset: 0
26
+ };
27
+ }
28
+ const barWidth = W / (N + (N - 1) * r);
29
+ const offset = r * barWidth;
30
+ return {
31
+ barWidth,
32
+ offset
33
+ };
34
+ }
7
35
  export function BarPlot() {
8
36
  const seriesData = React.useContext(SeriesContext).bar;
9
37
  const axisData = React.useContext(CartesianContext);
@@ -30,19 +58,27 @@ export function BarPlot() {
30
58
  var _series$seriesId$xAxi, _series$seriesId$yAxi;
31
59
  const xAxisKey = (_series$seriesId$xAxi = series[seriesId].xAxisKey) != null ? _series$seriesId$xAxi : defaultXAxisId;
32
60
  const yAxisKey = (_series$seriesId$yAxi = series[seriesId].yAxisKey) != null ? _series$seriesId$yAxi : defaultYAxisId;
33
- const xScale = xAxis[xAxisKey].scale;
34
- const yScale = yAxis[yAxisKey].scale;
35
- if (!isBandScale(xScale)) {
36
- throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series ${stackingGroups}`);
61
+ const xAxisConfig = xAxis[xAxisKey];
62
+ const yAxisConfig = yAxis[yAxisKey];
63
+ if (!isBandScaleConfig(xAxisConfig)) {
64
+ throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
37
65
  }
38
66
  if (xAxis[xAxisKey].data === undefined) {
39
67
  throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
40
68
  }
69
+ const xScale = xAxisConfig.scale;
70
+ const yScale = yAxisConfig.scale;
41
71
 
42
72
  // Currently assuming all bars are vertical
43
73
  const bandWidth = xScale.bandwidth();
44
- const barWidth = 0.9 * bandWidth / stackingGroups.length;
45
- const offset = 0.05 * bandWidth;
74
+ const {
75
+ barWidth,
76
+ offset
77
+ } = getBandSize({
78
+ bandWidth,
79
+ numberOfGroups: stackingGroups.length,
80
+ gapRatio: xAxisConfig.barGapRatio
81
+ });
46
82
 
47
83
  // @ts-ignore TODO: fix when adding a correct API for customisation
48
84
  const {
@@ -56,7 +92,7 @@ export function BarPlot() {
56
92
  return /*#__PURE__*/_jsx(BarElement, {
57
93
  id: seriesId,
58
94
  dataIndex: dataIndex,
59
- x: xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + groupIndex * barWidth + offset,
95
+ x: xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + groupIndex * (barWidth + offset),
60
96
  y: yScale(value),
61
97
  height: yScale(baseline) - yScale(value),
62
98
  width: barWidth,
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import useForkRef from '@mui/utils/useForkRef';
2
3
  import { DrawingProvider } from '../context/DrawingProvider';
3
4
  import { SeriesContextProvider } from '../context/SeriesContextProvider';
4
5
  import { InteractionProvider } from '../context/InteractionProvider';
@@ -6,7 +7,7 @@ import { ChartsSurface } from '../ChartsSurface';
6
7
  import { CartesianContextProvider } from '../context/CartesianContextProvider';
7
8
  import { HighlightProvider } from '../context/HighlightProvider';
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
- export function ChartContainer(props) {
10
+ export const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
10
11
  const {
11
12
  width,
12
13
  height,
@@ -21,12 +22,13 @@ export function ChartContainer(props) {
21
22
  disableAxisListener,
22
23
  children
23
24
  } = props;
24
- const ref = React.useRef(null);
25
+ const svgRef = React.useRef(null);
26
+ const handleRef = useForkRef(ref, svgRef);
25
27
  return /*#__PURE__*/_jsx(DrawingProvider, {
26
28
  width: width,
27
29
  height: height,
28
30
  margin: margin,
29
- svgRef: ref,
31
+ svgRef: svgRef,
30
32
  children: /*#__PURE__*/_jsx(SeriesContextProvider, {
31
33
  series: series,
32
34
  colors: colors,
@@ -38,7 +40,7 @@ export function ChartContainer(props) {
38
40
  children: /*#__PURE__*/_jsx(ChartsSurface, {
39
41
  width: width,
40
42
  height: height,
41
- ref: ref,
43
+ ref: handleRef,
42
44
  sx: sx,
43
45
  title: title,
44
46
  desc: desc,
@@ -50,4 +52,4 @@ export function ChartContainer(props) {
50
52
  })
51
53
  })
52
54
  });
53
- }
55
+ });
@@ -2,7 +2,8 @@ import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { InteractionContext } from '../context/InteractionProvider';
4
4
  import { CartesianContext } from '../context/CartesianContextProvider';
5
- import { getValueToPositionMapper, isBandScale } from '../hooks/useScale';
5
+ import { getValueToPositionMapper } from '../hooks/useScale';
6
+ import { isBandScale } from '../internals/isBandScale';
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
7
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
9
  function ChartsAxisHighlight(props) {
@@ -26,7 +27,7 @@ function ChartsAxisHighlight(props) {
26
27
  const getXPosition = getValueToPositionMapper(xScale);
27
28
  return /*#__PURE__*/_jsxs(React.Fragment, {
28
29
  children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx("path", {
29
- d: `M ${xScale(axis.x.value)} ${yScale.range()[0]} L ${xScale(axis.x.value) + xScale.bandwidth()} ${yScale.range()[0]} L ${xScale(axis.x.value) + xScale.bandwidth()} ${yScale.range()[1]} L ${xScale(axis.x.value)} ${yScale.range()[1]} Z`,
30
+ d: `M ${xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2} ${yScale.range()[0]} l ${xScale.step()} 0 l 0 ${yScale.range()[1] - yScale.range()[0]} l ${-xScale.step()} 0 Z`,
30
31
  fill: "gray",
31
32
  fillOpacity: 0.1,
32
33
  style: {
@@ -14,7 +14,7 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
14
14
  import { ChartsClipPath } from '../ChartsClipPath';
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
- function LineChart(props) {
17
+ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
18
18
  const {
19
19
  xAxis,
20
20
  yAxis,
@@ -38,6 +38,7 @@ function LineChart(props) {
38
38
  const id = useId();
39
39
  const clipPathId = `${id}-clip-path`;
40
40
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
41
+ ref: ref,
41
42
  series: series.map(s => _extends({
42
43
  type: 'line'
43
44
  }, s)),
@@ -67,7 +68,7 @@ function LineChart(props) {
67
68
  id: clipPathId
68
69
  }), children]
69
70
  });
70
- }
71
+ });
71
72
  process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
72
73
  // ----------------------------- Warning --------------------------------
73
74
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -93,22 +93,23 @@ const ResizableContainer = styled('div', {
93
93
  }
94
94
  };
95
95
  });
96
- export function ResponsiveChartContainer(props) {
96
+ export const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
97
97
  const {
98
- width: propsWidth,
99
- height: propsHeight
98
+ width: inWidth,
99
+ height: inHeight
100
100
  } = props,
101
101
  other = _objectWithoutPropertiesLoose(props, _excluded);
102
- const [containerRef, width, height] = useChartDimensions(propsWidth, propsHeight);
102
+ const [containerRef, width, height] = useChartDimensions(inWidth, inHeight);
103
103
  return /*#__PURE__*/_jsx(ResizableContainer, {
104
104
  ref: containerRef,
105
105
  ownerState: {
106
- width: props.width,
107
- height: props.height
106
+ width: inWidth,
107
+ height: inHeight
108
108
  },
109
109
  children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
110
110
  width: width,
111
- height: height
111
+ height: height,
112
+ ref: ref
112
113
  }))
113
114
  });
114
- }
115
+ });
@@ -9,7 +9,7 @@ import { ChartsLegend } from '../ChartsLegend';
9
9
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
- function ScatterChart(props) {
12
+ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
13
13
  const {
14
14
  xAxis,
15
15
  yAxis,
@@ -29,6 +29,7 @@ function ScatterChart(props) {
29
29
  children
30
30
  } = props;
31
31
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
32
+ ref: ref,
32
33
  series: series.map(s => _extends({
33
34
  type: 'scatter'
34
35
  }, s)),
@@ -51,7 +52,7 @@ function ScatterChart(props) {
51
52
  trigger: "item"
52
53
  }, tooltip)), children]
53
54
  });
54
- }
55
+ });
55
56
  process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
56
57
  // ----------------------------- Warning --------------------------------
57
58
  // | These PropTypes are generated from the TypeScript type definitions |