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

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 (65) hide show
  1. package/BarChart/BarChart.d.ts +1 -0
  2. package/BarChart/BarChart.js +26 -13
  3. package/BarChart/BarPlot.js +25 -15
  4. package/BarChart/extremums.js +19 -3
  5. package/BarChart/formatter.js +3 -1
  6. package/CHANGELOG.md +154 -31
  7. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +3 -2
  8. package/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  9. package/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  10. package/LineChart/LineChart.js +1 -1
  11. package/LineChart/MarkPlot.js +7 -4
  12. package/PieChart/PieChart.js +1 -1
  13. package/ScatterChart/ScatterChart.js +1 -1
  14. package/SparkLineChart/SparkLineChart.js +1 -1
  15. package/context/CartesianContextProvider.js +4 -4
  16. package/esm/BarChart/BarChart.js +30 -17
  17. package/esm/BarChart/BarPlot.js +26 -16
  18. package/esm/BarChart/extremums.js +18 -2
  19. package/esm/BarChart/formatter.js +3 -1
  20. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  21. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  22. package/esm/LineChart/LineChart.js +1 -1
  23. package/esm/LineChart/MarkPlot.js +7 -4
  24. package/esm/PieChart/PieChart.js +1 -1
  25. package/esm/ScatterChart/ScatterChart.js +1 -1
  26. package/esm/SparkLineChart/SparkLineChart.js +1 -1
  27. package/esm/context/CartesianContextProvider.js +4 -4
  28. package/esm/hooks/useAxisEvents.js +21 -38
  29. package/esm/hooks/useTicks.js +2 -2
  30. package/hooks/useAxisEvents.js +21 -38
  31. package/hooks/useTicks.js +2 -2
  32. package/index.js +1 -1
  33. package/internals/defaultizeColor.d.ts +1 -0
  34. package/legacy/BarChart/BarChart.js +35 -20
  35. package/legacy/BarChart/BarPlot.js +26 -16
  36. package/legacy/BarChart/extremums.js +22 -2
  37. package/legacy/BarChart/formatter.js +3 -1
  38. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  39. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  40. package/legacy/LineChart/LineChart.js +1 -1
  41. package/legacy/LineChart/MarkPlot.js +5 -2
  42. package/legacy/PieChart/PieChart.js +1 -1
  43. package/legacy/ScatterChart/ScatterChart.js +1 -1
  44. package/legacy/SparkLineChart/SparkLineChart.js +1 -1
  45. package/legacy/context/CartesianContextProvider.js +4 -4
  46. package/legacy/hooks/useAxisEvents.js +21 -37
  47. package/legacy/hooks/useTicks.js +2 -2
  48. package/legacy/index.js +1 -1
  49. package/models/seriesType/bar.d.ts +6 -1
  50. package/modern/BarChart/BarChart.js +27 -14
  51. package/modern/BarChart/BarPlot.js +25 -15
  52. package/modern/BarChart/extremums.js +18 -2
  53. package/modern/BarChart/formatter.js +3 -1
  54. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  55. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  56. package/modern/LineChart/LineChart.js +1 -1
  57. package/modern/LineChart/MarkPlot.js +7 -4
  58. package/modern/PieChart/PieChart.js +1 -1
  59. package/modern/ScatterChart/ScatterChart.js +1 -1
  60. package/modern/SparkLineChart/SparkLineChart.js +1 -1
  61. package/modern/context/CartesianContextProvider.js +4 -4
  62. package/modern/hooks/useAxisEvents.js +21 -38
  63. package/modern/hooks/useTicks.js +2 -2
  64. package/modern/index.js +1 -1
  65. package/package.json +4 -4
@@ -25,11 +25,11 @@ function useTicks(options) {
25
25
  const domain = scale.domain();
26
26
  if (scale.bandwidth() > 0) {
27
27
  // scale type = 'band'
28
- return [...domain.map((value, index) => {
28
+ return [...domain.map(value => {
29
29
  var _valueFormatter;
30
30
  return {
31
31
  formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : value,
32
- offset: index === 0 ? scale.range()[0] : scale(value) - (scale.step() - scale.bandwidth()) / 2,
32
+ offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
33
33
  labelOffset: scale.step() / 2
34
34
  };
35
35
  }), {
@@ -41,66 +41,49 @@ const useAxisEvents = disableAxisListener => {
41
41
  if (element === null || disableAxisListener) {
42
42
  return () => {};
43
43
  }
44
- const getUpdateY = y => {
45
- if (usedYAxis === null) {
46
- return null;
47
- }
48
- const {
49
- scale: yScale,
50
- data: yAxisData
51
- } = yAxis[usedYAxis];
52
- if (!(0, _isBandScale.isBandScale)(yScale)) {
53
- return {
54
- value: yScale.invert(y)
55
- };
56
- }
57
- const dataIndex = Math.floor((y - yScale.range()[0]) / yScale.step());
58
- if (dataIndex < 0 || dataIndex >= yAxisData.length) {
59
- return null;
60
- }
61
- return {
62
- index: dataIndex,
63
- value: yAxisData[dataIndex]
64
- };
65
- };
66
- const getUpdateX = x => {
44
+ const getUpdate = (axisConfig, mouseValue) => {
67
45
  if (usedXAxis === null) {
68
46
  return null;
69
47
  }
70
48
  const {
71
- scale: xScale,
72
- data: xAxisData
73
- } = xAxis[usedXAxis];
74
- if (!(0, _isBandScale.isBandScale)(xScale)) {
75
- const value = xScale.invert(x);
76
- const closestIndex = xAxisData?.findIndex((v, index) => {
49
+ scale,
50
+ data: axisData
51
+ } = axisConfig;
52
+ if (!(0, _isBandScale.isBandScale)(scale)) {
53
+ const value = scale.invert(mouseValue);
54
+ if (axisData === undefined) {
55
+ return {
56
+ value
57
+ };
58
+ }
59
+ const closestIndex = axisData?.findIndex((v, index) => {
77
60
  if (v > value) {
78
61
  // @ts-ignore
79
- if (index === 0 || Math.abs(value - v) <= Math.abs(value - xAxisData[index - 1])) {
62
+ if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
80
63
  return true;
81
64
  }
82
65
  }
83
66
  if (v <= value) {
84
- if (index === xAxisData.length - 1 ||
67
+ if (index === axisData.length - 1 ||
85
68
  // @ts-ignore
86
- Math.abs(value - v) < Math.abs(value - xAxisData[index + 1])) {
69
+ Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
87
70
  return true;
88
71
  }
89
72
  }
90
73
  return false;
91
74
  });
92
75
  return {
93
- value: closestIndex !== undefined && closestIndex >= 0 ? xAxisData[closestIndex] : value,
76
+ value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
94
77
  index: closestIndex
95
78
  };
96
79
  }
97
- const dataIndex = xScale.bandwidth() === 0 ? Math.floor((x - xScale.range()[0] + xScale.step() / 2) / xScale.step()) : Math.floor((x - xScale.range()[0]) / xScale.step());
98
- if (dataIndex < 0 || dataIndex >= xAxisData.length) {
80
+ const dataIndex = scale.bandwidth() === 0 ? Math.floor((mouseValue - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((mouseValue - Math.min(...scale.range())) / scale.step());
81
+ if (dataIndex < 0 || dataIndex >= axisData.length) {
99
82
  return null;
100
83
  }
101
84
  return {
102
85
  index: dataIndex,
103
- value: xAxisData[dataIndex]
86
+ value: axisData[dataIndex]
104
87
  };
105
88
  };
106
89
  const handleMouseOut = () => {
@@ -138,8 +121,8 @@ const useAxisEvents = disableAxisListener => {
138
121
  });
139
122
  return;
140
123
  }
141
- const newStateX = getUpdateX(svgPt.x);
142
- const newStateY = getUpdateY(svgPt.y);
124
+ const newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
125
+ const newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
143
126
  dispatch({
144
127
  type: 'updateAxis',
145
128
  data: {
package/hooks/useTicks.js CHANGED
@@ -34,9 +34,9 @@ function useTicks(options) {
34
34
  const domain = scale.domain();
35
35
  if (scale.bandwidth() > 0) {
36
36
  // scale type = 'band'
37
- return [...domain.map((value, index) => ({
37
+ return [...domain.map(value => ({
38
38
  formattedValue: valueFormatter?.(value) ?? value,
39
- offset: index === 0 ? scale.range()[0] : scale(value) - (scale.step() - scale.bandwidth()) / 2,
39
+ offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
40
40
  labelOffset: scale.step() / 2
41
41
  })), {
42
42
  formattedValue: undefined,
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.7
2
+ * @mui/x-charts v6.0.0-alpha.8
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -39,6 +39,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
39
39
  data?: number[] | undefined;
40
40
  dataKey?: string | undefined;
41
41
  label?: string | undefined;
42
+ layout?: "horizontal" | "vertical" | undefined;
42
43
  id?: string | undefined;
43
44
  color: string;
44
45
  valueFormatter?: ((value: number) => string) | undefined;
@@ -1,12 +1,12 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import * as React from 'react';
4
4
  import useId from '@mui/utils/useId';
5
5
  import PropTypes from 'prop-types';
6
6
  import { BarPlot } from './BarPlot';
7
7
  import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
8
8
  import { ChartsAxis } from '../ChartsAxis';
9
- import { DEFAULT_X_AXIS_KEY } from '../constants';
9
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
10
10
  import { ChartsTooltip } from '../ChartsTooltip';
11
11
  import { ChartsLegend } from '../ChartsLegend';
12
12
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
@@ -23,6 +23,7 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
23
23
  colors = props.colors,
24
24
  dataset = props.dataset,
25
25
  sx = props.sx,
26
+ layout = props.layout,
26
27
  tooltip = props.tooltip,
27
28
  axisHighlight = props.axisHighlight,
28
29
  legend = props.legend,
@@ -35,29 +36,43 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
35
36
  slotProps = props.slotProps;
36
37
  var id = useId();
37
38
  var clipPathId = "".concat(id, "-clip-path");
39
+ var hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(function (item) {
40
+ return item.layout === 'horizontal';
41
+ });
42
+ var defaultAxisConfig = {
43
+ scaleType: 'band',
44
+ data: Array.from({
45
+ length: Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
46
+ var _ref, _s$data;
47
+ return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
48
+ })))
49
+ }, function (_, index) {
50
+ return index;
51
+ })
52
+ };
53
+ var defaultizedAxisHighlight = _extends({}, hasHorizontalSeries ? {
54
+ y: 'band'
55
+ } : {
56
+ x: 'band'
57
+ }, axisHighlight);
38
58
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
39
59
  ref: ref,
40
60
  series: series.map(function (s) {
41
61
  return _extends({
42
62
  type: 'bar'
43
- }, s);
63
+ }, s, {
64
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
65
+ });
44
66
  }),
45
67
  width: width,
46
68
  height: height,
47
69
  margin: margin,
48
- xAxis: xAxis != null ? xAxis : [{
49
- id: DEFAULT_X_AXIS_KEY,
50
- scaleType: 'band',
51
- data: Array.from({
52
- length: Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
53
- var _ref, _s$data;
54
- return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
55
- })))
56
- }, function (_, index) {
57
- return index;
58
- })
59
- }],
60
- yAxis: yAxis,
70
+ xAxis: xAxis != null ? xAxis : hasHorizontalSeries ? undefined : [_extends({
71
+ id: DEFAULT_X_AXIS_KEY
72
+ }, defaultAxisConfig)],
73
+ yAxis: yAxis != null ? yAxis : hasHorizontalSeries ? [_extends({
74
+ id: DEFAULT_Y_AXIS_KEY
75
+ }, defaultAxisConfig)] : undefined,
61
76
  colors: colors,
62
77
  dataset: dataset,
63
78
  sx: sx,
@@ -78,9 +93,7 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
78
93
  }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
79
94
  slots: slots,
80
95
  slotProps: slotProps
81
- })), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
82
- x: "band"
83
- }, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
96
+ })), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, defaultizedAxisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
84
97
  slots: slots,
85
98
  slotProps: slotProps
86
99
  })), /*#__PURE__*/_jsx(ChartsClipPath, {
@@ -95,7 +108,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
95
108
  // ----------------------------------------------------------------------
96
109
  axisHighlight: PropTypes.shape({
97
110
  x: PropTypes.oneOf(['band', 'line', 'none']),
98
- y: PropTypes.oneOf(['line', 'none'])
111
+ y: PropTypes.oneOf(['band', 'line', 'none'])
99
112
  }),
100
113
  /**
101
114
  * Indicate which axis to display the bottom of the charts.
@@ -130,6 +143,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
130
143
  desc: PropTypes.string,
131
144
  disableAxisListener: PropTypes.bool,
132
145
  height: PropTypes.number,
146
+ layout: PropTypes.oneOf(['horizontal', 'vertical']),
133
147
  /**
134
148
  * Indicate which axis to display the left of the charts.
135
149
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -210,6 +224,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
210
224
  }),
211
225
  id: PropTypes.string,
212
226
  label: PropTypes.string,
227
+ layout: PropTypes.oneOf(['horizontal', 'vertical']),
213
228
  stack: PropTypes.string,
214
229
  stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
215
230
  stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
@@ -57,40 +57,50 @@ function BarPlot(props) {
57
57
  var yAxisKey = (_series$seriesId$yAxi = series[seriesId].yAxisKey) != null ? _series$seriesId$yAxi : defaultYAxisId;
58
58
  var xAxisConfig = xAxis[xAxisKey];
59
59
  var yAxisConfig = yAxis[yAxisKey];
60
- if (!isBandScaleConfig(xAxisConfig)) {
61
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
62
- }
63
- if (xAxis[xAxisKey].data === undefined) {
64
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
60
+ var verticalLayout = series[seriesId].layout === 'vertical';
61
+ var baseScaleConfig;
62
+ if (verticalLayout) {
63
+ if (!isBandScaleConfig(xAxisConfig)) {
64
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
65
+ }
66
+ if (xAxis[xAxisKey].data === undefined) {
67
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
68
+ }
69
+ baseScaleConfig = xAxisConfig;
70
+ } else {
71
+ if (!isBandScaleConfig(yAxisConfig)) {
72
+ throw new Error("Axis with id \"".concat(yAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
73
+ }
74
+ if (yAxis[yAxisKey].data === undefined) {
75
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
76
+ }
77
+ baseScaleConfig = yAxisConfig;
65
78
  }
66
79
  var xScale = xAxisConfig.scale;
67
80
  var yScale = yAxisConfig.scale;
68
-
69
- // Currently assuming all bars are vertical
70
- var bandWidth = xScale.bandwidth();
81
+ var bandWidth = baseScaleConfig.scale.bandwidth();
71
82
  var _getBandSize = getBandSize({
72
83
  bandWidth: bandWidth,
73
84
  numberOfGroups: stackingGroups.length,
74
- gapRatio: xAxisConfig.barGapRatio
85
+ gapRatio: baseScaleConfig.barGapRatio
75
86
  }),
76
87
  barWidth = _getBandSize.barWidth,
77
88
  offset = _getBandSize.offset;
78
-
79
- // @ts-ignore TODO: fix when adding a correct API for customisation
89
+ var barOffset = groupIndex * (barWidth + offset);
80
90
  var _series$seriesId = series[seriesId],
81
91
  stackedData = _series$seriesId.stackedData,
82
92
  color = _series$seriesId.color;
83
93
  return stackedData.map(function (values, dataIndex) {
84
- var _xAxis$xAxisKey$data;
94
+ var _xAxis$xAxisKey$data, _yAxis$yAxisKey$data;
85
95
  var baseline = Math.min.apply(Math, _toConsumableArray(values));
86
96
  var value = Math.max.apply(Math, _toConsumableArray(values));
87
97
  return /*#__PURE__*/_jsx(BarElement, _extends({
88
98
  id: seriesId,
89
99
  dataIndex: dataIndex,
90
- x: xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + groupIndex * (barWidth + offset),
91
- y: yScale(value),
92
- height: yScale(baseline) - yScale(value),
93
- width: barWidth,
100
+ x: verticalLayout ? xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + barOffset : xScale(baseline),
101
+ y: verticalLayout ? yScale(value) : yScale((_yAxis$yAxisKey$data = yAxis[yAxisKey].data) == null ? void 0 : _yAxis$yAxisKey$data[dataIndex]) + barOffset,
102
+ height: verticalLayout ? Math.abs(yScale(baseline) - yScale(value)) : barWidth,
103
+ width: verticalLayout ? barWidth : Math.abs(xScale(baseline) - xScale(value)),
94
104
  color: color,
95
105
  highlightScope: series[seriesId].highlightScope
96
106
  }, props), "".concat(seriesId, "-").concat(dataIndex));
@@ -1,13 +1,13 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- export var getExtremumX = function getExtremumX(params) {
3
+ var getBaseExtremum = function getBaseExtremum(params) {
4
4
  var _axis$data, _axis$data2;
5
5
  var axis = params.axis;
6
6
  var minX = Math.min.apply(Math, _toConsumableArray((_axis$data = axis.data) != null ? _axis$data : []));
7
7
  var maxX = Math.max.apply(Math, _toConsumableArray((_axis$data2 = axis.data) != null ? _axis$data2 : []));
8
8
  return [minX, maxX];
9
9
  };
10
- export var getExtremumY = function getExtremumY(params) {
10
+ var getValueExtremum = function getValueExtremum(params) {
11
11
  var series = params.series,
12
12
  axis = params.axis,
13
13
  isDefaultAxis = params.isDefaultAxis;
@@ -22,4 +22,24 @@ export var getExtremumY = function getExtremumY(params) {
22
22
  seriesMax = _series$seriesId$stac2[1];
23
23
  return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
24
24
  }, [null, null]);
25
+ };
26
+ export var getExtremumX = function getExtremumX(params) {
27
+ // Notice that bar should be all horizontal or all vertical.
28
+ // Don't think it's a problem for now
29
+ var isHorizontal = Object.keys(params.series).some(function (seriesId) {
30
+ return params.series[seriesId].layout === 'horizontal';
31
+ });
32
+ if (isHorizontal) {
33
+ return getValueExtremum(params);
34
+ }
35
+ return getBaseExtremum(params);
36
+ };
37
+ export var getExtremumY = function getExtremumY(params) {
38
+ var isHorizontal = Object.keys(params.series).some(function (seriesId) {
39
+ return params.series[seriesId].layout === 'horizontal';
40
+ });
41
+ if (isHorizontal) {
42
+ return getBaseExtremum(params);
43
+ }
44
+ return getValueExtremum(params);
25
45
  };
@@ -38,7 +38,9 @@ var formatter = function formatter(params, dataset) {
38
38
  })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
39
39
  ids.forEach(function (id, index) {
40
40
  var dataKey = series[id].dataKey;
41
- completedSeries[id] = _extends({}, series[id], {
41
+ completedSeries[id] = _extends({
42
+ layout: 'vertical'
43
+ }, series[id], {
42
44
  data: dataKey ? dataset.map(function (d) {
43
45
  return d[dataKey];
44
46
  }) : series[id].data,
@@ -21,6 +21,7 @@ function ChartsAxisHighlight(props) {
21
21
  var _React$useContext2 = React.useContext(InteractionContext),
22
22
  axis = _React$useContext2.axis;
23
23
  var getXPosition = getValueToPositionMapper(xScale);
24
+ var getYPosition = getValueToPositionMapper(yScale);
24
25
  return /*#__PURE__*/_jsxs(React.Fragment, {
25
26
  children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx("path", {
26
27
  d: "M ".concat(xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2, " ").concat(yScale.range()[0], " l ").concat(xScale.step(), " 0 l 0 ").concat(yScale.range()[1] - yScale.range()[0], " l ").concat(-xScale.step(), " 0 Z"),
@@ -29,15 +30,22 @@ function ChartsAxisHighlight(props) {
29
30
  style: {
30
31
  pointerEvents: 'none'
31
32
  }
33
+ }), yAxisHighlight === 'band' && axis.y !== null && isBandScale(yScale) && /*#__PURE__*/_jsx("path", {
34
+ d: "M ".concat(xScale.range()[0], " ").concat(yScale(axis.y.value) - (yScale.step() - yScale.bandwidth()) / 2, " l 0 ").concat(yScale.step(), " l ").concat(xScale.range()[1] - xScale.range()[0], " 0 l 0 ").concat(-yScale.step(), " Z"),
35
+ fill: "gray",
36
+ fillOpacity: 0.1,
37
+ style: {
38
+ pointerEvents: 'none'
39
+ }
32
40
  }), xAxisHighlight === 'line' && axis.x !== null && /*#__PURE__*/_jsx("path", {
33
- d: "M ".concat(getXPosition(axis.x.value), " ").concat(yScale(yScale.domain()[0]), " L ").concat(getXPosition(axis.x.value), " ").concat(yScale(yScale.domain().at(-1))),
41
+ d: "M ".concat(getXPosition(axis.x.value), " ").concat(yScale.range()[0], " L ").concat(getXPosition(axis.x.value), " ").concat(yScale.range()[1]),
34
42
  stroke: "black",
35
43
  strokeDasharray: "5 2",
36
44
  style: {
37
45
  pointerEvents: 'none'
38
46
  }
39
47
  }), yAxisHighlight === 'line' && axis.y !== null && /*#__PURE__*/_jsx("path", {
40
- d: "M ".concat(xScale.range()[0], " ").concat(yScale(axis.y.value), " L ").concat(xScale.range()[1], " ").concat(yScale(axis.y.value)),
48
+ d: "M ".concat(xScale.range()[0], " ").concat(getYPosition(axis.y.value), " L ").concat(xScale.range()[1], " ").concat(getYPosition(axis.y.value)),
41
49
  stroke: "black",
42
50
  strokeDasharray: "5 2",
43
51
  style: {
@@ -52,6 +60,6 @@ process.env.NODE_ENV !== "production" ? ChartsAxisHighlight.propTypes = {
52
60
  // | To update them edit the TypeScript types and run "yarn proptypes" |
53
61
  // ----------------------------------------------------------------------
54
62
  x: PropTypes.oneOf(['band', 'line', 'none']),
55
- y: PropTypes.oneOf(['line', 'none'])
63
+ y: PropTypes.oneOf(['band', 'line', 'none'])
56
64
  } : void 0;
57
65
  export { ChartsAxisHighlight };
@@ -71,30 +71,34 @@ export function ChartsAxisTooltipContent(props) {
71
71
  axisData = props.axisData,
72
72
  sx = props.sx,
73
73
  classes = props.classes;
74
- var dataIndex = axisData.x && axisData.x.index;
75
- var axisValue = axisData.x && axisData.x.value;
74
+ var isXaxis = (axisData.x && axisData.x.index) !== undefined;
75
+ var dataIndex = isXaxis ? axisData.x && axisData.x.index : axisData.y && axisData.y.index;
76
+ var axisValue = isXaxis ? axisData.x && axisData.x.value : axisData.y && axisData.y.value;
76
77
  var _React$useContext = React.useContext(CartesianContext),
77
78
  xAxisIds = _React$useContext.xAxisIds,
78
- xAxis = _React$useContext.xAxis;
79
+ xAxis = _React$useContext.xAxis,
80
+ yAxisIds = _React$useContext.yAxisIds,
81
+ yAxis = _React$useContext.yAxis;
79
82
  var series = React.useContext(SeriesContext);
80
- var USED_X_AXIS_ID = xAxisIds[0];
83
+ var USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
81
84
  var relevantSeries = React.useMemo(function () {
82
85
  var rep = [];
83
86
  Object.keys(series).filter(function (seriesType) {
84
87
  return ['bar', 'line', 'scatter'].includes(seriesType);
85
88
  }).forEach(function (seriesType) {
86
89
  series[seriesType].seriesOrder.forEach(function (seriesId) {
87
- var axisKey = series[seriesType].series[seriesId].xAxisKey;
88
- if (axisKey === undefined || axisKey === USED_X_AXIS_ID) {
90
+ var item = series[seriesType].series[seriesId];
91
+ var axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
92
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
89
93
  rep.push(series[seriesType].series[seriesId]);
90
94
  }
91
95
  });
92
96
  });
93
97
  return rep;
94
- }, [USED_X_AXIS_ID, series]);
98
+ }, [USED_AXIS_ID, isXaxis, series]);
95
99
  var relevantAxis = React.useMemo(function () {
96
- return xAxis[USED_X_AXIS_ID];
97
- }, [USED_X_AXIS_ID, xAxis]);
100
+ return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
101
+ }, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
98
102
  var Content = content != null ? content : DefaultChartsAxisContent;
99
103
  return /*#__PURE__*/_jsx(Content, {
100
104
  axisData: axisData,
@@ -101,7 +101,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
101
101
  // ----------------------------------------------------------------------
102
102
  axisHighlight: PropTypes.shape({
103
103
  x: PropTypes.oneOf(['band', 'line', 'none']),
104
- y: PropTypes.oneOf(['line', 'none'])
104
+ y: PropTypes.oneOf(['band', 'line', 'none'])
105
105
  }),
106
106
  /**
107
107
  * Indicate which axis to display the bottom of the charts.
@@ -1,5 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ var _excluded = ["slots", "slotProps"];
3
5
  import * as React from 'react';
4
6
  import PropTypes from 'prop-types';
5
7
  import { SeriesContext } from '../context/SeriesContextProvider';
@@ -10,7 +12,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
10
12
  function MarkPlot(props) {
11
13
  var _slots$mark;
12
14
  var slots = props.slots,
13
- slotProps = props.slotProps;
15
+ slotProps = props.slotProps,
16
+ other = _objectWithoutProperties(props, _excluded);
14
17
  var seriesData = React.useContext(SeriesContext).line;
15
18
  var axisData = React.useContext(CartesianContext);
16
19
  var Mark = (_slots$mark = slots == null ? void 0 : slots.mark) != null ? _slots$mark : MarkElement;
@@ -25,7 +28,7 @@ function MarkPlot(props) {
25
28
  yAxisIds = axisData.yAxisIds;
26
29
  var defaultXAxisId = xAxisIds[0];
27
30
  var defaultYAxisId = yAxisIds[0];
28
- return /*#__PURE__*/_jsx("g", _extends({}, props, {
31
+ return /*#__PURE__*/_jsx("g", _extends({}, other, {
29
32
  children: stackingGroups.flatMap(function (_ref) {
30
33
  var groupIds = _ref.ids;
31
34
  return groupIds.flatMap(function (seriesId) {
@@ -100,7 +100,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
100
100
  // ----------------------------------------------------------------------
101
101
  axisHighlight: PropTypes.shape({
102
102
  x: PropTypes.oneOf(['band', 'line', 'none']),
103
- y: PropTypes.oneOf(['line', 'none'])
103
+ y: PropTypes.oneOf(['band', 'line', 'none'])
104
104
  }),
105
105
  /**
106
106
  * Indicate which axis to display the bottom of the charts.
@@ -70,7 +70,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
70
70
  // ----------------------------------------------------------------------
71
71
  axisHighlight: PropTypes.shape({
72
72
  x: PropTypes.oneOf(['band', 'line', 'none']),
73
- y: PropTypes.oneOf(['line', 'none'])
73
+ y: PropTypes.oneOf(['band', 'line', 'none'])
74
74
  }),
75
75
  /**
76
76
  * Indicate which axis to display the bottom of the charts.
@@ -106,7 +106,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
106
106
  area: PropTypes.bool,
107
107
  axisHighlight: PropTypes.shape({
108
108
  x: PropTypes.oneOf(['band', 'line', 'none']),
109
- y: PropTypes.oneOf(['line', 'none'])
109
+ y: PropTypes.oneOf(['band', 'line', 'none'])
110
110
  }),
111
111
  children: PropTypes.node,
112
112
  className: PropTypes.string,
@@ -182,17 +182,17 @@ function CartesianContextProvider(_ref) {
182
182
  if (isBandScaleConfig(axis)) {
183
183
  var _axis$categoryGapRati2;
184
184
  var categoryGapRatio = (_axis$categoryGapRati2 = axis.categoryGapRatio) != null ? _axis$categoryGapRati2 : DEFAULT_CATEGORY_GAP_RATIO;
185
- completedXAxis[axis.id] = _extends({
185
+ completedYAxis[axis.id] = _extends({
186
186
  categoryGapRatio: categoryGapRatio,
187
187
  barGapRatio: 0
188
188
  }, axis, {
189
- scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
189
+ scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
190
190
  ticksNumber: axis.data.length
191
191
  });
192
192
  }
193
193
  if (isPointScaleConfig(axis)) {
194
- completedXAxis[axis.id] = _extends({}, axis, {
195
- scale: scalePoint(axis.data, range),
194
+ completedYAxis[axis.id] = _extends({}, axis, {
195
+ scale: scalePoint(axis.data, [range[1], range[0]]),
196
196
  ticksNumber: axis.data.length
197
197
  });
198
198
  }