@mui/x-charts 7.7.1 → 7.8.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 (68) hide show
  1. package/BarChart/BarElement.d.ts +225 -228
  2. package/BarChart/BarLabel/BarLabel.d.ts +225 -228
  3. package/BarChart/BarLabel/getBarLabel.d.ts +1 -1
  4. package/BarChart/useBarChartProps.d.ts +20 -88
  5. package/CHANGELOG.md +100 -1
  6. package/ChartContainer/ChartContainer.d.ts +1 -1
  7. package/ChartContainer/useChartContainerHooks.d.ts +1 -1
  8. package/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
  9. package/ChartsReferenceLine/common.d.ts +0 -1
  10. package/ChartsTooltip/ChartsTooltipTable.d.ts +0 -1
  11. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
  12. package/ChartsYAxis/ChartsYAxis.js +3 -1
  13. package/Gauge/GaugeProvider.d.ts +1 -1
  14. package/LineChart/AnimatedArea.d.ts +225 -228
  15. package/LineChart/AnimatedLine.d.ts +225 -228
  16. package/LineChart/useLineChartProps.d.ts +26 -103
  17. package/LineChart/useLineChartProps.js +3 -3
  18. package/PieChart/PieArc.d.ts +0 -1
  19. package/PieChart/PieArcLabel.d.ts +0 -1
  20. package/PieChart/dataTransform/transition.d.ts +0 -1
  21. package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -2
  22. package/ScatterChart/useScatterChartProps.d.ts +20 -75
  23. package/context/CartesianProvider/computeValue.js +15 -0
  24. package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
  25. package/esm/BarChart/useBarChartProps.js +0 -1
  26. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
  27. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +1 -1
  28. package/esm/ChartsYAxis/ChartsYAxis.js +3 -1
  29. package/esm/LineChart/useLineChartProps.js +3 -3
  30. package/esm/context/CartesianProvider/computeValue.js +16 -1
  31. package/esm/hooks/useAxisEvents.js +5 -8
  32. package/esm/hooks/useScale.js +1 -1
  33. package/esm/hooks/useTicks.js +2 -1
  34. package/esm/internals/getSVGPoint.js +11 -0
  35. package/esm/internals/index.js +2 -0
  36. package/esm/internals/utils.js +0 -12
  37. package/hooks/useAxisEvents.js +6 -9
  38. package/hooks/useChartDimensions.d.ts +1 -1
  39. package/hooks/useColor.d.ts +1 -1
  40. package/hooks/useScale.js +1 -1
  41. package/hooks/useTicks.js +2 -1
  42. package/index.js +1 -1
  43. package/internals/components/AxisSharedComponents.d.ts +0 -1
  44. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +1 -1
  45. package/internals/defaultizeColor.d.ts +68 -68
  46. package/internals/getSVGPoint.d.ts +6 -0
  47. package/internals/getSVGPoint.js +17 -0
  48. package/internals/getWordsByLines.d.ts +0 -1
  49. package/internals/index.d.ts +2 -0
  50. package/internals/index.js +20 -0
  51. package/internals/useAnimatedPath.d.ts +0 -1
  52. package/internals/utils.d.ts +0 -6
  53. package/internals/utils.js +0 -13
  54. package/models/axis.d.ts +1 -2
  55. package/modern/BarChart/useBarChartProps.js +0 -1
  56. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
  57. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +1 -1
  58. package/modern/ChartsYAxis/ChartsYAxis.js +3 -1
  59. package/modern/LineChart/useLineChartProps.js +3 -3
  60. package/modern/context/CartesianProvider/computeValue.js +16 -1
  61. package/modern/hooks/useAxisEvents.js +5 -8
  62. package/modern/hooks/useScale.js +1 -1
  63. package/modern/hooks/useTicks.js +2 -1
  64. package/modern/index.js +1 -1
  65. package/modern/internals/getSVGPoint.js +11 -0
  66. package/modern/internals/index.js +2 -0
  67. package/modern/internals/utils.js +0 -12
  68. package/package.json +1 -1
@@ -8,7 +8,7 @@ var React = _interopRequireWildcard(require("react"));
8
8
  var _InteractionProvider = require("../context/InteractionProvider");
9
9
  var _CartesianProvider = require("../context/CartesianProvider");
10
10
  var _isBandScale = require("../internals/isBandScale");
11
- var _utils = require("../internals/utils");
11
+ var _getSVGPoint = require("../internals/getSVGPoint");
12
12
  var _useSvgRef = require("./useSvgRef");
13
13
  var _useDrawingArea = require("./useDrawingArea");
14
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -46,10 +46,7 @@ const useAxisEvents = disableAxisListener => {
46
46
  if (element === null || disableAxisListener) {
47
47
  return () => {};
48
48
  }
49
- const getUpdate = (axisConfig, mouseValue) => {
50
- if (usedXAxis === null) {
51
- return null;
52
- }
49
+ function getNewAxisState(axisConfig, mouseValue) {
53
50
  const {
54
51
  scale,
55
52
  data: axisData,
@@ -97,7 +94,7 @@ const useAxisEvents = disableAxisListener => {
97
94
  index: dataIndex,
98
95
  value: axisData[dataIndex]
99
96
  };
100
- };
97
+ }
101
98
  const handleOut = () => {
102
99
  mousePosition.current = {
103
100
  x: -1,
@@ -109,7 +106,7 @@ const useAxisEvents = disableAxisListener => {
109
106
  };
110
107
  const handleMove = event => {
111
108
  const target = 'targetTouches' in event ? event.targetTouches[0] : event;
112
- const svgPoint = (0, _utils.getSVGPoint)(svgRef.current, target);
109
+ const svgPoint = (0, _getSVGPoint.getSVGPoint)(svgRef.current, target);
113
110
  mousePosition.current = {
114
111
  x: svgPoint.x,
115
112
  y: svgPoint.y
@@ -122,8 +119,8 @@ const useAxisEvents = disableAxisListener => {
122
119
  });
123
120
  return;
124
121
  }
125
- const newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
126
- const newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
122
+ const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
123
+ const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
127
124
  dispatch({
128
125
  type: 'updateAxis',
129
126
  data: {
@@ -1,5 +1,5 @@
1
1
  import { LayoutConfig } from '../models/layout';
2
- declare const useChartDimensions: (width: number, height: number, margin: LayoutConfig['margin']) => {
2
+ declare const useChartDimensions: (width: number, height: number, margin: LayoutConfig["margin"]) => {
3
3
  left: number;
4
4
  top: number;
5
5
  right: number;
@@ -1,4 +1,4 @@
1
- import { ChartSeriesType } from '../internals';
1
+ import { ChartSeriesType } from '../models/seriesType/config';
2
2
  import { ColorProcessorsConfig } from '../models/plugin';
3
3
  export declare function useColorProcessor<T extends ChartSeriesType>(seriesType: T): ColorProcessorsConfig<ChartSeriesType>;
4
4
  export declare function useColorProcessor(): ColorProcessorsConfig<ChartSeriesType>;
package/hooks/useScale.js CHANGED
@@ -16,7 +16,7 @@ var _isBandScale = require("../internals/isBandScale");
16
16
  */
17
17
  function getValueToPositionMapper(scale) {
18
18
  if ((0, _isBandScale.isBandScale)(scale)) {
19
- return value => scale(value) + scale.bandwidth() / 2;
19
+ return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
20
20
  }
21
21
  return value => scale(value);
22
22
  }
package/hooks/useTicks.js CHANGED
@@ -43,7 +43,8 @@ function useTicks(options) {
43
43
  const domain = scale.domain();
44
44
  if (scale.bandwidth() > 0) {
45
45
  // scale type = 'band'
46
- return [...domain.map(value => ({
46
+ const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
47
+ return [...filteredDomain.map(value => ({
47
48
  value,
48
49
  formattedValue: valueFormatter?.(value, {
49
50
  location: 'tick'
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.7.1
2
+ * @mui/x-charts v7.8.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
1
  export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
@@ -1,4 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { AxisId } from '../../../models/axis';
3
- export declare function useChartGradient(): (axisId: AxisId, direction: 'x' | 'y') => string;
3
+ export declare function useChartGradient(): (axisId: AxisId, direction: "x" | "y") => string;
4
4
  export declare function ChartsAxesGradients(): React.JSX.Element;
@@ -2,92 +2,92 @@ import { AllSeriesType } from '../models/seriesType';
2
2
  export declare function defaultizeColor(series: AllSeriesType, seriesIndex: number, colors?: string[]): {
3
3
  data: {
4
4
  color: string;
5
- label?: string | ((location: "tooltip" | "legend" | "arc") => string) | undefined;
5
+ label?: string | ((location: "tooltip" | "legend" | "arc") => string);
6
6
  value: number;
7
7
  id?: import("../models/seriesType").PieItemId | undefined;
8
8
  }[];
9
9
  type: "pie";
10
- innerRadius?: string | number | undefined;
11
- outerRadius?: string | number | undefined;
12
- arcLabelRadius?: string | number | undefined;
13
- cornerRadius?: number | undefined;
14
- startAngle?: number | undefined;
15
- endAngle?: number | undefined;
16
- paddingAngle?: number | undefined;
17
- sortingValues?: import("../models/seriesType").ChartsPieSorting | undefined;
18
- arcLabel?: "label" | "value" | "formattedValue" | ((item: Omit<import("../models/seriesType").DefaultizedPieValueType, "label"> & {
19
- label?: string | undefined;
20
- }) => string) | undefined;
21
- arcLabelMinAngle?: number | undefined;
22
- cx?: string | number | undefined;
23
- cy?: string | number | undefined;
10
+ innerRadius?: number | string;
11
+ outerRadius?: number | string;
12
+ arcLabelRadius?: number | string;
13
+ cornerRadius?: number;
14
+ startAngle?: number;
15
+ endAngle?: number;
16
+ paddingAngle?: number;
17
+ sortingValues?: import("../models/seriesType").ChartsPieSorting;
18
+ arcLabel?: "formattedValue" | "label" | "value" | ((item: Omit<import("../models/seriesType").DefaultizedPieValueType, "label"> & {
19
+ label?: string;
20
+ }) => string);
21
+ arcLabelMinAngle?: number;
22
+ cx?: number | string;
23
+ cy?: number | string;
24
24
  highlighted?: {
25
- additionalRadius?: number | undefined;
26
- innerRadius?: number | undefined;
27
- outerRadius?: number | undefined;
28
- cornerRadius?: number | undefined;
29
- paddingAngle?: number | undefined;
30
- arcLabelRadius?: number | undefined;
31
- color?: string | undefined;
32
- } | undefined;
25
+ additionalRadius?: number;
26
+ innerRadius?: number;
27
+ outerRadius?: number;
28
+ cornerRadius?: number;
29
+ paddingAngle?: number;
30
+ arcLabelRadius?: number;
31
+ color?: string;
32
+ };
33
33
  faded?: {
34
- additionalRadius?: number | undefined;
35
- innerRadius?: number | undefined;
36
- outerRadius?: number | undefined;
37
- cornerRadius?: number | undefined;
38
- paddingAngle?: number | undefined;
39
- arcLabelRadius?: number | undefined;
40
- color?: string | undefined;
41
- } | undefined;
42
- id?: import(".").SeriesId | undefined;
43
- color?: string | undefined;
34
+ additionalRadius?: number;
35
+ innerRadius?: number;
36
+ outerRadius?: number;
37
+ cornerRadius?: number;
38
+ paddingAngle?: number;
39
+ arcLabelRadius?: number;
40
+ color?: string;
41
+ };
42
+ id?: import(".").SeriesId;
43
+ color?: string;
44
44
  valueFormatter?: import(".").SeriesValueFormatter<import(".").MakeOptional<import("../models/seriesType").PieValueType, "id">> | undefined;
45
- highlightScope?: Partial<import("..").HighlightScope> | undefined;
45
+ highlightScope?: Partial<import("..").HighlightScope>;
46
46
  } | {
47
47
  type: "bar";
48
- data?: (number | null)[] | undefined;
49
- dataKey?: string | undefined;
50
- label?: string | ((location: "tooltip" | "legend") => string) | undefined;
51
- layout?: "horizontal" | "vertical" | undefined;
52
- stackOffset?: import("..").StackOffsetType | undefined;
53
- id?: import(".").SeriesId | undefined;
48
+ data?: (number | null)[];
49
+ dataKey?: string;
50
+ label?: string | ((location: "tooltip" | "legend") => string);
51
+ layout?: "horizontal" | "vertical";
52
+ stackOffset?: import("..").StackOffsetType;
53
+ id?: import(".").SeriesId;
54
54
  color: string;
55
55
  valueFormatter?: import(".").SeriesValueFormatter<number | null> | undefined;
56
- highlightScope?: Partial<import("..").HighlightScope> | undefined;
57
- xAxisKey?: string | undefined;
58
- yAxisKey?: string | undefined;
59
- stack?: string | undefined;
60
- stackOrder?: import("..").StackOrderType | undefined;
56
+ highlightScope?: Partial<import("..").HighlightScope>;
57
+ xAxisKey?: string;
58
+ yAxisKey?: string;
59
+ stack?: string;
60
+ stackOrder?: import("..").StackOrderType;
61
61
  } | {
62
62
  type: "line";
63
- data?: (number | null)[] | undefined;
64
- dataKey?: string | undefined;
65
- stack?: string | undefined;
66
- area?: boolean | undefined;
67
- label?: string | ((location: "tooltip" | "legend") => string) | undefined;
68
- curve?: import("../models/seriesType").CurveType | undefined;
69
- showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams<number | Date>) => boolean) | undefined;
70
- disableHighlight?: boolean | undefined;
71
- connectNulls?: boolean | undefined;
72
- stackOffset?: import("..").StackOffsetType | undefined;
73
- id?: import(".").SeriesId | undefined;
63
+ data?: (number | null)[];
64
+ dataKey?: string;
65
+ stack?: string;
66
+ area?: boolean;
67
+ label?: string | ((location: "tooltip" | "legend") => string);
68
+ curve?: import("../models/seriesType").CurveType;
69
+ showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams) => boolean);
70
+ disableHighlight?: boolean;
71
+ connectNulls?: boolean;
72
+ stackOffset?: import("..").StackOffsetType;
73
+ id?: import(".").SeriesId;
74
74
  color: string;
75
75
  valueFormatter?: import(".").SeriesValueFormatter<number | null> | undefined;
76
- highlightScope?: Partial<import("..").HighlightScope> | undefined;
77
- xAxisKey?: string | undefined;
78
- yAxisKey?: string | undefined;
79
- stackOrder?: import("..").StackOrderType | undefined;
76
+ highlightScope?: Partial<import("..").HighlightScope>;
77
+ xAxisKey?: string;
78
+ yAxisKey?: string;
79
+ stackOrder?: import("..").StackOrderType;
80
80
  } | {
81
81
  type: "scatter";
82
82
  data: import("../models/seriesType").ScatterValueType[];
83
- markerSize?: number | undefined;
84
- label?: string | ((location: "tooltip" | "legend") => string) | undefined;
85
- disableHover?: boolean | undefined;
86
- zAxisKey?: string | undefined;
87
- id?: import(".").SeriesId | undefined;
83
+ markerSize?: number;
84
+ label?: string | ((location: "tooltip" | "legend") => string);
85
+ disableHover?: boolean;
86
+ zAxisKey?: string;
87
+ id?: import(".").SeriesId;
88
88
  color: string;
89
89
  valueFormatter?: import(".").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
90
- highlightScope?: Partial<import("..").HighlightScope> | undefined;
91
- xAxisKey?: string | undefined;
92
- yAxisKey?: string | undefined;
90
+ highlightScope?: Partial<import("..").HighlightScope>;
91
+ xAxisKey?: string;
92
+ yAxisKey?: string;
93
93
  };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Transform mouse event position to coordinates inside the SVG.
3
+ * @param svg The SVG element
4
+ * @param event The mouseEvent to transform
5
+ */
6
+ export declare function getSVGPoint(svg: SVGSVGElement, event: Pick<MouseEvent, 'clientX' | 'clientY'>): DOMPoint;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSVGPoint = getSVGPoint;
7
+ /**
8
+ * Transform mouse event position to coordinates inside the SVG.
9
+ * @param svg The SVG element
10
+ * @param event The mouseEvent to transform
11
+ */
12
+ function getSVGPoint(svg, event) {
13
+ const pt = svg.createSVGPoint();
14
+ pt.x = event.clientX;
15
+ pt.y = event.clientY;
16
+ return pt.matrixTransform(svg.getScreenCTM().inverse());
17
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export type ChartsTextBaseline = 'hanging' | 'central' | 'auto';
3
2
  export interface ChartsTextStyle extends React.CSSProperties {
4
3
  angle?: number;
@@ -3,12 +3,14 @@ export * from '../ResponsiveChartContainer/useChartContainerDimensions';
3
3
  export * from '../ResponsiveChartContainer/ResizableContainer';
4
4
  export { useReducedMotion } from '../hooks/useReducedMotion';
5
5
  export { useSeries } from '../hooks/useSeries';
6
+ export { useDrawingArea } from '../hooks/useDrawingArea';
6
7
  export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
7
8
  export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
8
9
  export { useLineChartProps } from '../LineChart/useLineChartProps';
9
10
  export { useBarChartProps } from '../BarChart/useBarChartProps';
10
11
  export * from './defaultizeValueFormatter';
11
12
  export * from './configInit';
13
+ export * from './getSVGPoint';
12
14
  export * from '../context/CartesianProvider';
13
15
  export * from '../context/DrawingProvider';
14
16
  export * from '../context/ColorProvider';
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  var _exportNames = {
7
7
  useReducedMotion: true,
8
8
  useSeries: true,
9
+ useDrawingArea: true,
9
10
  useChartContainerHooks: true,
10
11
  useScatterChartProps: true,
11
12
  useLineChartProps: true,
@@ -23,6 +24,12 @@ Object.defineProperty(exports, "useChartContainerHooks", {
23
24
  return _useChartContainerHooks.useChartContainerHooks;
24
25
  }
25
26
  });
27
+ Object.defineProperty(exports, "useDrawingArea", {
28
+ enumerable: true,
29
+ get: function () {
30
+ return _useDrawingArea.useDrawingArea;
31
+ }
32
+ });
26
33
  Object.defineProperty(exports, "useLineChartProps", {
27
34
  enumerable: true,
28
35
  get: function () {
@@ -85,6 +92,7 @@ Object.keys(_ResizableContainer).forEach(function (key) {
85
92
  });
86
93
  var _useReducedMotion = require("../hooks/useReducedMotion");
87
94
  var _useSeries = require("../hooks/useSeries");
95
+ var _useDrawingArea = require("../hooks/useDrawingArea");
88
96
  var _useChartContainerHooks = require("../ChartContainer/useChartContainerHooks");
89
97
  var _useScatterChartProps = require("../ScatterChart/useScatterChartProps");
90
98
  var _useLineChartProps = require("../LineChart/useLineChartProps");
@@ -113,6 +121,18 @@ Object.keys(_configInit).forEach(function (key) {
113
121
  }
114
122
  });
115
123
  });
124
+ var _getSVGPoint = require("./getSVGPoint");
125
+ Object.keys(_getSVGPoint).forEach(function (key) {
126
+ if (key === "default" || key === "__esModule") return;
127
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
128
+ if (key in exports && exports[key] === _getSVGPoint[key]) return;
129
+ Object.defineProperty(exports, key, {
130
+ enumerable: true,
131
+ get: function () {
132
+ return _getSVGPoint[key];
133
+ }
134
+ });
135
+ });
116
136
  var _CartesianProvider = require("../context/CartesianProvider");
117
137
  Object.keys(_CartesianProvider).forEach(function (key) {
118
138
  if (key === "default" || key === "__esModule") return;
@@ -1,2 +1 @@
1
- /// <reference types="@react-spring/core" />
2
1
  export declare const useAnimatedPath: (path: string, skipAnimation?: boolean) => import("@react-spring/core").Interpolation<string, any>;
@@ -4,12 +4,6 @@ type Without<T, U> = {
4
4
  [P in Exclude<keyof T, keyof U>]?: never;
5
5
  };
6
6
  export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
7
- /**
8
- * Transform mouse event position to coordinates inside the SVG.
9
- * @param svg The SVG element
10
- * @param event The mouseEvent to transform
11
- */
12
- export declare function getSVGPoint(svg: SVGSVGElement, event: Pick<MouseEvent, 'clientX' | 'clientY'>): DOMPoint;
13
7
  /**
14
8
  * Helper that converts values and percentages into values.
15
9
  * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
@@ -5,25 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.cleanId = cleanId;
7
7
  exports.getPercentageValue = getPercentageValue;
8
- exports.getSVGPoint = getSVGPoint;
9
8
  exports.getSymbol = getSymbol;
10
9
  // Returns the index of a defined shape
11
10
  function getSymbol(shape) {
12
11
  const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
13
12
  return symbolNames.indexOf(shape) || 0;
14
13
  }
15
- /**
16
- * Transform mouse event position to coordinates inside the SVG.
17
- * @param svg The SVG element
18
- * @param event The mouseEvent to transform
19
- */
20
- function getSVGPoint(svg, event) {
21
- const pt = svg.createSVGPoint();
22
- pt.x = event.clientX;
23
- pt.y = event.clientY;
24
- return pt.matrixTransform(svg.getScreenCTM().inverse());
25
- }
26
-
27
14
  /**
28
15
  * Helper that converts values and percentages into values.
29
16
  * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
package/models/axis.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint, ScaleOrdinal, ScaleSequential, ScaleThreshold } from 'd3-scale';
3
2
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
4
3
  import type { TickParams } from '../hooks/useTicks';
@@ -126,7 +125,7 @@ export interface ChartsXAxisProps extends ChartsAxisProps {
126
125
  */
127
126
  position?: 'top' | 'bottom';
128
127
  }
129
- export type ScaleName = 'linear' | 'band' | 'point' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
128
+ export type ScaleName = keyof AxisScaleConfig;
130
129
  export type ContinuousScaleName = 'linear' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
131
130
  export interface AxisScaleConfig {
132
131
  band: {
@@ -1,7 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import useId from '@mui/utils/useId';
3
3
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
4
-
5
4
  /**
6
5
  * A helper function that extracts BarChartProps from the input props
7
6
  * and returns an object with props for the children components of BarChart.
@@ -66,15 +66,30 @@ function ChartsAxisHighlight(props) {
66
66
  } = React.useContext(InteractionContext);
67
67
  const getXPosition = getValueToPositionMapper(xScale);
68
68
  const getYPosition = getValueToPositionMapper(yScale);
69
+ const axisX = axis.x;
70
+ const axisY = axis.y;
71
+ const isBandScaleX = xAxisHighlight === 'band' && axisX !== null && isBandScale(xScale);
72
+ const isBandScaleY = yAxisHighlight === 'band' && axisY !== null && isBandScale(yScale);
73
+ if (process.env.NODE_ENV !== 'production') {
74
+ const isXError = isBandScaleX && xScale(axisX.value) === undefined;
75
+ const isYError = isBandScaleY && yScale(axisY.value) === undefined;
76
+ if (isXError || isYError) {
77
+ console.error([`MUI X Charts: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
78
+ }
79
+ }
69
80
  return /*#__PURE__*/_jsxs(React.Fragment, {
70
- children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
71
- 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`,
81
+ children: [isBandScaleX && xScale(axisX.value) !== undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath
82
+ // @ts-expect-error, xScale value is checked in the statement above
83
+ , {
84
+ d: `M ${xScale(axisX.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`,
72
85
  className: classes.root,
73
86
  ownerState: {
74
87
  axisHighlight: 'band'
75
88
  }
76
- }), yAxisHighlight === 'band' && axis.y !== null && isBandScale(yScale) && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
77
- d: `M ${xScale.range()[0]} ${yScale(axis.y.value) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${xScale.range()[1] - xScale.range()[0]} 0 l 0 ${-yScale.step()} Z`,
89
+ }), isBandScaleY && yScale(axisY.value) === undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
90
+ d: `M ${xScale.range()[0]} ${
91
+ // @ts-expect-error, yScale value is checked in the statement above
92
+ yScale(axisY.value) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${xScale.range()[1] - xScale.range()[0]} 0 l 0 ${-yScale.step()} Z`,
78
93
  className: classes.root,
79
94
  ownerState: {
80
95
  axisHighlight: 'band'
@@ -5,7 +5,7 @@ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
5
  import { InteractionContext } from '../context/InteractionProvider';
6
6
  import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { getValueToPositionMapper } from '../hooks/useScale';
8
- import { getSVGPoint } from '../internals/utils';
8
+ import { getSVGPoint } from '../internals/getSVGPoint';
9
9
  import { useDrawingArea, useSvgRef } from '../hooks';
10
10
  import { useHighlighted } from '../context';
11
11
  import { useScatterSeries } from '../hooks/useSeries';
@@ -81,6 +81,7 @@ function ChartsYAxis(inProps) {
81
81
  tickLabelInterval
82
82
  } = defaultizedProps;
83
83
  const theme = useTheme();
84
+ const isRTL = theme.direction === 'rtl';
84
85
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
85
86
  theme
86
87
  }));
@@ -108,13 +109,14 @@ function ChartsYAxis(inProps) {
108
109
  const Tick = slots?.axisTick ?? 'line';
109
110
  const TickLabel = slots?.axisTickLabel ?? ChartsText;
110
111
  const Label = slots?.axisLabel ?? ChartsText;
112
+ const revertAnchor = !isRTL && position === 'right' || isRTL && position !== 'right';
111
113
  const axisTickLabelProps = useSlotProps({
112
114
  elementType: TickLabel,
113
115
  externalSlotProps: slotProps?.axisTickLabel,
114
116
  additionalProps: {
115
117
  style: _extends({
116
118
  fontSize: tickFontSize,
117
- textAnchor: position === 'right' ? 'start' : 'end',
119
+ textAnchor: revertAnchor ? 'start' : 'end',
118
120
  dominantBaseline: 'central'
119
121
  }, tickLabelStyle)
120
122
  },
@@ -81,19 +81,19 @@ export const useLineChartProps = props => {
81
81
  const areaPlotProps = {
82
82
  slots,
83
83
  slotProps,
84
- onAreaClick,
84
+ onItemClick: onAreaClick,
85
85
  skipAnimation
86
86
  };
87
87
  const linePlotProps = {
88
88
  slots,
89
89
  slotProps,
90
- onLineClick,
90
+ onItemClick: onLineClick,
91
91
  skipAnimation
92
92
  };
93
93
  const markPlotProps = {
94
94
  slots,
95
95
  slotProps,
96
- onMarkClick,
96
+ onItemClick: onMarkClick,
97
97
  skipAnimation
98
98
  };
99
99
  const overlayProps = {
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { scaleBand, scalePoint } from 'd3-scale';
2
+ import { scaleBand, scalePoint, scaleTime } from 'd3-scale';
3
3
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
4
4
  import { isBandScaleConfig, isPointScaleConfig } from '../../models/axis';
5
5
  import { getColorScale, getOrdinalColorScale } from '../../internals/colorScale';
@@ -10,6 +10,13 @@ const getRange = (drawingArea, axisName, isReverse) => {
10
10
  const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
11
11
  return isReverse ? range.reverse() : range;
12
12
  };
13
+ const isDateData = data => data?.[0] instanceof Date;
14
+ function createDateFormatter(axis, range) {
15
+ const timeScale = scaleTime(axis.data, range);
16
+ return (v, {
17
+ location
18
+ }) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`;
19
+ }
13
20
  const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
14
21
  const DEFAULT_BAR_GAP_RATIO = 0.1;
15
22
  export function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName) {
@@ -42,6 +49,10 @@ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGette
42
49
  values: axis.data
43
50
  }, axis.colorMap)) : getColorScale(axis.colorMap))
44
51
  });
52
+ if (isDateData(axis.data)) {
53
+ const dateFormatter = createDateFormatter(axis, scaleRange);
54
+ completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
55
+ }
45
56
  }
46
57
  if (isPointScaleConfig(axis)) {
47
58
  const scaleRange = axisName === 'x' ? range : [...range].reverse();
@@ -52,6 +63,10 @@ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGette
52
63
  values: axis.data
53
64
  }, axis.colorMap)) : getColorScale(axis.colorMap))
54
65
  });
66
+ if (isDateData(axis.data)) {
67
+ const dateFormatter = createDateFormatter(axis, scaleRange);
68
+ completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
69
+ }
55
70
  }
56
71
  if (axis.scaleType === 'band' || axis.scaleType === 'point') {
57
72
  // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { InteractionContext } from '../context/InteractionProvider';
3
3
  import { useCartesianContext } from '../context/CartesianProvider';
4
4
  import { isBandScale } from '../internals/isBandScale';
5
- import { getSVGPoint } from '../internals/utils';
5
+ import { getSVGPoint } from '../internals/getSVGPoint';
6
6
  import { useSvgRef } from './useSvgRef';
7
7
  import { useDrawingArea } from './useDrawingArea';
8
8
  function getAsANumber(value) {
@@ -38,10 +38,7 @@ export const useAxisEvents = disableAxisListener => {
38
38
  if (element === null || disableAxisListener) {
39
39
  return () => {};
40
40
  }
41
- const getUpdate = (axisConfig, mouseValue) => {
42
- if (usedXAxis === null) {
43
- return null;
44
- }
41
+ function getNewAxisState(axisConfig, mouseValue) {
45
42
  const {
46
43
  scale,
47
44
  data: axisData,
@@ -89,7 +86,7 @@ export const useAxisEvents = disableAxisListener => {
89
86
  index: dataIndex,
90
87
  value: axisData[dataIndex]
91
88
  };
92
- };
89
+ }
93
90
  const handleOut = () => {
94
91
  mousePosition.current = {
95
92
  x: -1,
@@ -114,8 +111,8 @@ export const useAxisEvents = disableAxisListener => {
114
111
  });
115
112
  return;
116
113
  }
117
- const newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
118
- const newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
114
+ const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
115
+ const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
119
116
  dispatch({
120
117
  type: 'updateAxis',
121
118
  data: {
@@ -8,7 +8,7 @@ import { isBandScale } from '../internals/isBandScale';
8
8
  */
9
9
  export function getValueToPositionMapper(scale) {
10
10
  if (isBandScale(scale)) {
11
- return value => scale(value) + scale.bandwidth() / 2;
11
+ return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
12
12
  }
13
13
  return value => scale(value);
14
14
  }
@@ -34,7 +34,8 @@ export 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 => ({
37
+ const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
38
+ return [...filteredDomain.map(value => ({
38
39
  value,
39
40
  formattedValue: valueFormatter?.(value, {
40
41
  location: 'tick'
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.7.1
2
+ * @mui/x-charts v7.8.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the