@mui/x-charts 8.5.3 → 8.6.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 (104) hide show
  1. package/BarChart/AnimatedBarElement.js +3 -1
  2. package/BarChart/BarLabel/BarLabelPlot.d.ts +2 -2
  3. package/BarChart/BarLabel/BarLabelPlot.js +33 -25
  4. package/BarChart/BarPlot.js +55 -40
  5. package/BarChart/barClasses.d.ts +12 -0
  6. package/BarChart/barClasses.js +25 -0
  7. package/BarChart/index.d.ts +3 -1
  8. package/BarChart/index.js +23 -1
  9. package/BarChart/types.d.ts +5 -1
  10. package/CHANGELOG.md +107 -0
  11. package/ChartsLegend/ChartsLegend.js +1 -0
  12. package/ChartsXAxis/ChartsXAxis.js +4 -108
  13. package/ChartsXAxis/getVisibleLabels.d.ts +14 -0
  14. package/ChartsXAxis/getVisibleLabels.js +71 -0
  15. package/ChartsXAxis/shortenLabels.d.ts +4 -0
  16. package/ChartsXAxis/shortenLabels.js +48 -0
  17. package/ChartsYAxis/ChartsYAxis.js +2 -39
  18. package/ChartsYAxis/shortenLabels.d.ts +4 -0
  19. package/ChartsYAxis/shortenLabels.js +46 -0
  20. package/LineChart/AnimatedArea.js +4 -1
  21. package/LineChart/AnimatedLine.js +4 -1
  22. package/LineChart/CircleMarkElement.js +4 -1
  23. package/LineChart/MarkElement.js +4 -1
  24. package/LineChart/MarkPlot.js +1 -0
  25. package/PieChart/PieArc.js +3 -1
  26. package/PieChart/PiePlot.js +6 -0
  27. package/PieChart/index.d.ts +3 -1
  28. package/PieChart/index.js +18 -1
  29. package/PieChart/pieClasses.d.ts +12 -0
  30. package/PieChart/pieClasses.js +24 -0
  31. package/Toolbar/ToolbarButton.js +2 -0
  32. package/esm/BarChart/AnimatedBarElement.js +3 -1
  33. package/esm/BarChart/BarLabel/BarLabelPlot.d.ts +2 -2
  34. package/esm/BarChart/BarLabel/BarLabelPlot.js +33 -25
  35. package/esm/BarChart/BarPlot.js +55 -40
  36. package/esm/BarChart/barClasses.d.ts +12 -0
  37. package/esm/BarChart/barClasses.js +15 -0
  38. package/esm/BarChart/index.d.ts +3 -1
  39. package/esm/BarChart/index.js +2 -1
  40. package/esm/BarChart/types.d.ts +5 -1
  41. package/esm/ChartsLegend/ChartsLegend.js +1 -0
  42. package/esm/ChartsXAxis/ChartsXAxis.js +2 -106
  43. package/esm/ChartsXAxis/getVisibleLabels.d.ts +14 -0
  44. package/esm/ChartsXAxis/getVisibleLabels.js +67 -0
  45. package/esm/ChartsXAxis/shortenLabels.d.ts +4 -0
  46. package/esm/ChartsXAxis/shortenLabels.js +42 -0
  47. package/esm/ChartsYAxis/ChartsYAxis.js +1 -38
  48. package/esm/ChartsYAxis/shortenLabels.d.ts +4 -0
  49. package/esm/ChartsYAxis/shortenLabels.js +41 -0
  50. package/esm/LineChart/AnimatedArea.js +4 -1
  51. package/esm/LineChart/AnimatedLine.js +4 -1
  52. package/esm/LineChart/CircleMarkElement.js +4 -1
  53. package/esm/LineChart/MarkElement.js +4 -1
  54. package/esm/LineChart/MarkPlot.js +1 -0
  55. package/esm/PieChart/PieArc.js +3 -1
  56. package/esm/PieChart/PiePlot.js +6 -0
  57. package/esm/PieChart/index.d.ts +3 -1
  58. package/esm/PieChart/index.js +2 -1
  59. package/esm/PieChart/pieClasses.d.ts +12 -0
  60. package/esm/PieChart/pieClasses.js +15 -0
  61. package/esm/Toolbar/ToolbarButton.js +2 -0
  62. package/esm/index.js +1 -1
  63. package/esm/internals/components/NotRendered.d.ts +9 -0
  64. package/esm/internals/components/NotRendered.js +10 -0
  65. package/esm/internals/index.d.ts +1 -0
  66. package/esm/internals/index.js +1 -0
  67. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +30 -2
  68. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +8 -2
  69. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +20 -4
  70. package/esm/locales/enUS.d.ts +3 -0
  71. package/esm/locales/enUS.js +8 -2
  72. package/esm/locales/frFR.d.ts +3 -0
  73. package/esm/locales/frFR.js +7 -0
  74. package/esm/locales/ptBR.d.ts +3 -0
  75. package/esm/locales/ptBR.js +7 -1
  76. package/esm/locales/ptPT.d.ts +3 -0
  77. package/esm/locales/ptPT.js +7 -1
  78. package/esm/locales/utils/chartsLocaleTextApi.d.ts +17 -0
  79. package/esm/locales/utils/getChartsLocalization.d.ts +3 -0
  80. package/esm/locales/utils/imageMimeTypes.d.ts +2 -0
  81. package/esm/locales/utils/imageMimeTypes.js +5 -0
  82. package/esm/models/slots/chartsBaseSlotProps.d.ts +4 -0
  83. package/index.js +1 -1
  84. package/internals/components/NotRendered.d.ts +9 -0
  85. package/internals/components/NotRendered.js +16 -0
  86. package/internals/index.d.ts +1 -0
  87. package/internals/index.js +12 -0
  88. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +30 -2
  89. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +8 -2
  90. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +20 -4
  91. package/locales/enUS.d.ts +3 -0
  92. package/locales/enUS.js +8 -2
  93. package/locales/frFR.d.ts +3 -0
  94. package/locales/frFR.js +7 -0
  95. package/locales/ptBR.d.ts +3 -0
  96. package/locales/ptBR.js +7 -1
  97. package/locales/ptPT.d.ts +3 -0
  98. package/locales/ptPT.js +7 -1
  99. package/locales/utils/chartsLocaleTextApi.d.ts +17 -0
  100. package/locales/utils/getChartsLocalization.d.ts +3 -0
  101. package/locales/utils/imageMimeTypes.d.ts +2 -0
  102. package/locales/utils/imageMimeTypes.js +11 -0
  103. package/models/slots/chartsBaseSlotProps.d.ts +4 -0
  104. package/package.json +2 -2
@@ -9,6 +9,7 @@ import { getPieCoordinates } from "./getPieCoordinates.js";
9
9
  import { usePieSeriesContext } from "../hooks/usePieSeries.js";
10
10
  import { useSkipAnimation } from "../hooks/useSkipAnimation.js";
11
11
  import { useDrawingArea } from "../hooks/index.js";
12
+ import { useUtilityClasses } from "./pieClasses.js";
12
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
14
  /**
14
15
  * Demos:
@@ -35,6 +36,7 @@ function PiePlot(props) {
35
36
  height
36
37
  } = useDrawingArea();
37
38
  const skipAnimation = useSkipAnimation(inSkipAnimation);
39
+ const classes = useUtilityClasses();
38
40
  if (seriesData === undefined) {
39
41
  return null;
40
42
  }
@@ -69,7 +71,9 @@ function PiePlot(props) {
69
71
  const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
70
72
  const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
71
73
  return /*#__PURE__*/_jsx("g", {
74
+ className: classes.series,
72
75
  transform: `translate(${left + cx}, ${top + cy})`,
76
+ "data-series": seriesId,
73
77
  children: /*#__PURE__*/_jsx(PieArcPlot, {
74
78
  innerRadius: innerRadius,
75
79
  outerRadius: outerRadius,
@@ -113,7 +117,9 @@ function PiePlot(props) {
113
117
  const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
114
118
  const arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : getPercentageValue(arcLabelRadiusParam, availableRadius);
115
119
  return /*#__PURE__*/_jsx("g", {
120
+ className: classes.seriesLabels,
116
121
  transform: `translate(${left + cx}, ${top + cy})`,
122
+ "data-series": seriesId,
117
123
  children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
118
124
  innerRadius: innerRadius,
119
125
  outerRadius: outerRadius ?? availableRadius,
@@ -4,4 +4,6 @@ export * from "./PieArcPlot.js";
4
4
  export * from "./PieArcLabelPlot.js";
5
5
  export * from "./PieArc.js";
6
6
  export * from "./PieArcLabel.js";
7
- export * from "./getPieCoordinates.js";
7
+ export * from "./getPieCoordinates.js";
8
+ export { pieClasses } from "./pieClasses.js";
9
+ export type { PieClasses, PieClassKey } from "./pieClasses.js";
@@ -4,4 +4,5 @@ export * from "./PieArcPlot.js";
4
4
  export * from "./PieArcLabelPlot.js";
5
5
  export * from "./PieArc.js";
6
6
  export * from "./PieArcLabel.js";
7
- export * from "./getPieCoordinates.js";
7
+ export * from "./getPieCoordinates.js";
8
+ export { pieClasses } from "./pieClasses.js";
@@ -0,0 +1,12 @@
1
+ export interface PieClasses {
2
+ /** Styles applied to the root element. */
3
+ root: string;
4
+ /** Styles applied to the `g` element that contains all pie arcs of a series. */
5
+ series: string;
6
+ /** Styles applied to the `g` element that contains all pie arc labels of a series. */
7
+ seriesLabels: string;
8
+ }
9
+ export type PieClassKey = keyof PieClasses;
10
+ export declare function getPieUtilityClass(slot: string): string;
11
+ export declare const pieClasses: PieClasses;
12
+ export declare const useUtilityClasses: (classes?: Partial<PieClasses>) => Record<"root" | "series" | "seriesLabels", string>;
@@ -0,0 +1,15 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import composeClasses from '@mui/utils/composeClasses';
3
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
4
+ export function getPieUtilityClass(slot) {
5
+ return generateUtilityClass('MuiPieChart', slot);
6
+ }
7
+ export const pieClasses = generateUtilityClasses('MuiPieChart', ['root', 'series', 'seriesLabels']);
8
+ export const useUtilityClasses = classes => {
9
+ const slots = {
10
+ root: ['root'],
11
+ series: ['series'],
12
+ seriesLabels: ['seriesLabels']
13
+ };
14
+ return composeClasses(slots, getPieUtilityClass, classes);
15
+ };
@@ -44,10 +44,12 @@ process.env.NODE_ENV !== "production" ? ToolbarButton.propTypes = {
44
44
  // ----------------------------------------------------------------------
45
45
  className: PropTypes.string,
46
46
  disabled: PropTypes.bool,
47
+ id: PropTypes.string,
47
48
  /**
48
49
  * A function to customize the rendering of the component.
49
50
  */
50
51
  render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
52
+ size: PropTypes.oneOf(['large', 'medium', 'small']),
51
53
  style: PropTypes.object,
52
54
  tabIndex: PropTypes.number
53
55
  } : void 0;
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.5.3
2
+ * @mui/x-charts v8.6.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * This component is used to assert that a certain component should not be rendered.
4
+ * It is used in cases where we want to apply styles to a component that is not rendered because we use the `as` prop (introduced by `styled`) to replace the rendered component.
5
+ * We need it because we don't know the component that will be rendered at the time of writing the styles.
6
+ *
7
+ * @param _props Not used
8
+ */
9
+ export declare function NotRendered<T>(_props: T): React.ReactNode;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This component is used to assert that a certain component should not be rendered.
3
+ * It is used in cases where we want to apply styles to a component that is not rendered because we use the `as` prop (introduced by `styled`) to replace the rendered component.
4
+ * We need it because we don't know the component that will be rendered at the time of writing the styles.
5
+ *
6
+ * @param _props Not used
7
+ */
8
+ export function NotRendered(_props) {
9
+ throw new Error('Failed assertion: should not be rendered');
10
+ }
@@ -1,6 +1,7 @@
1
1
  export * from "./components/ChartsAxesGradients/index.js";
2
2
  export * from "./components/ChartsWrapper/index.js";
3
3
  export * from "../ChartsLabel/ChartsLabelMark.js";
4
+ export * from "./components/NotRendered.js";
4
5
  export { useSeries } from "../hooks/useSeries.js";
5
6
  export { useInteractionItemProps } from "../hooks/useInteractionItemProps.js";
6
7
  export { useDrawingArea } from "../hooks/useDrawingArea.js";
@@ -2,6 +2,7 @@
2
2
  export * from "./components/ChartsAxesGradients/index.js";
3
3
  export * from "./components/ChartsWrapper/index.js";
4
4
  export * from "../ChartsLabel/ChartsLabelMark.js";
5
+ export * from "./components/NotRendered.js";
5
6
 
6
7
  // hooks
7
8
  export { useSeries } from "../hooks/useSeries.js";
@@ -8,6 +8,7 @@ import { useSelector } from "../../../store/useSelector.js";
8
8
  import { DEFAULT_MARGINS } from "../../../../constants/index.js";
9
9
  import { selectorChartDrawingArea } from "./useChartDimensions.selectors.js";
10
10
  import { defaultizeMargin } from "../../../defaultizeMargin.js";
11
+ import { getSVGPoint } from "../../../getSVGPoint.js";
11
12
  const MAX_COMPUTE_RUN = 10;
12
13
  export const useChartDimensions = ({
13
14
  params,
@@ -149,16 +150,43 @@ export const useChartDimensions = ({
149
150
  const isYInside = React.useCallback(y => y >= drawingArea.top - 1 && y <= drawingArea.top + drawingArea.height, [drawingArea.height, drawingArea.top]);
150
151
  const isPointInside = React.useCallback((x, y, targetElement) => {
151
152
  // For element allowed to overflow, wrapping them in <g data-drawing-container /> make them fully part of the drawing area.
152
- if (targetElement && targetElement.closest('[data-drawing-container]')) {
153
+ if (targetElement && 'closest' in targetElement && targetElement.closest('[data-drawing-container]')) {
153
154
  return true;
154
155
  }
155
156
  return isXInside(x) && isYInside(y);
156
157
  }, [isXInside, isYInside]);
158
+ const isElementInside = React.useCallback(element => {
159
+ const svgElement = svgRef.current;
160
+ if (!element || !(element instanceof Element) || !svgElement) {
161
+ return false;
162
+ }
163
+ // For element allowed to overflow, wrapping them in <g data-drawing-container /> make them fully part of the drawing area.
164
+ if (element.closest('[data-drawing-container]')) {
165
+ return true;
166
+ }
167
+ const rect = element.getBoundingClientRect();
168
+ const {
169
+ x: left,
170
+ y: top
171
+ } = getSVGPoint(svgElement, {
172
+ clientX: rect.left,
173
+ clientY: rect.top
174
+ });
175
+ const {
176
+ x: right,
177
+ y: bottom
178
+ } = getSVGPoint(svgElement, {
179
+ clientX: rect.right,
180
+ clientY: rect.bottom
181
+ });
182
+ return isXInside(left) && isXInside(right) && isYInside(top) && isYInside(bottom);
183
+ }, [isXInside, isYInside, svgRef]);
157
184
  return {
158
185
  instance: {
159
186
  isPointInside,
160
187
  isXInside,
161
- isYInside
188
+ isYInside,
189
+ isElementInside
162
190
  }
163
191
  };
164
192
  };
@@ -63,14 +63,20 @@ export interface UseChartDimensionsState {
63
63
  };
64
64
  }
65
65
  export interface UseChartDimensionsInstance {
66
+ /**
67
+ * Checks if an element is inside the drawing area.
68
+ * @param {Element | EventTarget | null} element The element to check.
69
+ * @returns {boolean} `true` if the element is inside the drawing area, `false` otherwise.
70
+ */
71
+ isElementInside: (element: Element | EventTarget | null | undefined) => boolean;
66
72
  /**
67
73
  * Checks if a point is inside the drawing area.
68
74
  * @param {number} x The x coordinate of the point.
69
75
  * @param {number} y The y coordinate of the point.
70
- * @param {Element} targetElement The element to check if it is allowed to overflow the drawing area.
76
+ * @param {Element | EventTarget | null} targetElement The element to check if it is allowed to overflow the drawing area.
71
77
  * @returns {boolean} `true` if the point is inside the drawing area, `false` otherwise.
72
78
  */
73
- isPointInside: (x: number, y: number, targetElement?: Element) => boolean;
79
+ isPointInside: (x: number, y: number, targetElement?: Element | EventTarget | null) => boolean;
74
80
  /**
75
81
  * Checks if the x coordinate is inside the drawing area.
76
82
  * @param {number} x The x coordinate of the point.
@@ -91,10 +91,26 @@ export const useChartPolarAxis = ({
91
91
  instance.cleanInteraction?.();
92
92
  };
93
93
  const handleMove = event => {
94
- const target = 'targetTouches' in event ? event.targetTouches[0] : event;
95
- const svgPoint = getSVGPoint(element, target);
96
- mousePosition.current.x = svgPoint.x;
97
- mousePosition.current.y = svgPoint.y;
94
+ const srcEvent = event;
95
+
96
+ // On touch, we want to allow user to interact with the entire svg area in
97
+ // order to better display the tooltip.
98
+ if (event.pointerType === 'touch') {
99
+ const svgRect = element.getBoundingClientRect();
100
+ if (srcEvent.clientX < svgRect.left || srcEvent.clientX > svgRect.right || srcEvent.clientY < svgRect.top || srcEvent.clientY > svgRect.bottom) {
101
+ mousePosition.current.isInChart = false;
102
+ instance.cleanInteraction();
103
+ return;
104
+ }
105
+ const svgPoint = getSVGPoint(element, srcEvent);
106
+ mousePosition.current.isInChart = true;
107
+ instance.setPointerCoordinate(svgPoint);
108
+ return;
109
+ }
110
+
111
+ // On mouse, we want to restrict the interaction to the drawing area and radar circle.
112
+
113
+ const svgPoint = getSVGPoint(element, srcEvent);
98
114
 
99
115
  // Test if it's in the drawing area
100
116
  if (!instance.isPointInside(svgPoint.x, svgPoint.y, event.target)) {
@@ -10,6 +10,9 @@ export declare const enUS: {
10
10
  noData?: string | undefined;
11
11
  zoomIn?: string | undefined;
12
12
  zoomOut?: string | undefined;
13
+ toolbarExport?: string | undefined;
14
+ toolbarExportPrint?: string | undefined;
15
+ toolbarExportImage?: ((mimeType: import("./utils/imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
13
16
  };
14
17
  };
15
18
  };
@@ -1,13 +1,19 @@
1
+ import { imageMimeTypes } from "./utils/imageMimeTypes.js";
1
2
  import { getChartsLocalization } from "./utils/getChartsLocalization.js";
2
3
 
3
4
  // This object is not Partial<ChartsLocaleText> because it is the default values
4
5
 
5
6
  export const enUSLocaleText = {
6
- // Overlay
7
+ /* Overlay */
7
8
  loading: 'Loading data…',
8
9
  noData: 'No data to display',
10
+ /* Toolbar */
9
11
  zoomIn: 'Zoom in',
10
- zoomOut: 'Zoom out'
12
+ zoomOut: 'Zoom out',
13
+ toolbarExport: 'Export',
14
+ /* Toolbar Export Menu */
15
+ toolbarExportPrint: 'Print',
16
+ toolbarExportImage: mimeType => `Export as ${imageMimeTypes[mimeType] ?? mimeType}`
11
17
  };
12
18
  export const DEFAULT_LOCALE = enUSLocaleText;
13
19
  export const enUS = getChartsLocalization(enUSLocaleText);
@@ -9,6 +9,9 @@ export declare const frFR: {
9
9
  noData?: string | undefined;
10
10
  zoomIn?: string | undefined;
11
11
  zoomOut?: string | undefined;
12
+ toolbarExport?: string | undefined;
13
+ toolbarExportPrint?: string | undefined;
14
+ toolbarExportImage?: ((mimeType: import("./utils/imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
12
15
  };
13
16
  };
14
17
  };
@@ -3,7 +3,14 @@ export const frFRLocalText = {
3
3
  // Overlay
4
4
  loading: 'Chargement…',
5
5
  noData: 'Pas de données'
6
+
7
+ // Toolbar
6
8
  // zoomIn: 'Zoom in',
7
9
  // zoomOut: 'Zoom out',
10
+ // toolbarExport: 'Export',
11
+
12
+ // Toolbar Export Menu
13
+ // toolbarExportPrint: 'Print',
14
+ // toolbarExportImage: mimeType => `Export as ${imageMimeTypes[mimeType] ?? mimeType}`,
8
15
  };
9
16
  export const frFR = getChartsLocalization(frFRLocalText);
@@ -9,6 +9,9 @@ export declare const ptBR: {
9
9
  noData?: string | undefined;
10
10
  zoomIn?: string | undefined;
11
11
  zoomOut?: string | undefined;
12
+ toolbarExport?: string | undefined;
13
+ toolbarExportPrint?: string | undefined;
14
+ toolbarExportImage?: ((mimeType: import("./utils/imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
12
15
  };
13
16
  };
14
17
  };
@@ -1,9 +1,15 @@
1
+ import { imageMimeTypes } from "./utils/imageMimeTypes.js";
1
2
  import { getChartsLocalization } from "./utils/getChartsLocalization.js";
2
3
  export const ptBRLocaleText = {
3
4
  // Overlay
4
5
  loading: 'Carregando dados…',
5
6
  noData: 'Sem dados para exibir',
7
+ // Toolbar
6
8
  zoomIn: 'Aumentar zoom',
7
- zoomOut: 'Diminuir zoom'
9
+ zoomOut: 'Diminuir zoom',
10
+ toolbarExport: 'Exportar',
11
+ // Toolbar Export Menu
12
+ toolbarExportPrint: 'Imprimir',
13
+ toolbarExportImage: mimeType => `Exportar como ${imageMimeTypes[mimeType] ?? mimeType}`
8
14
  };
9
15
  export const ptBR = getChartsLocalization(ptBRLocaleText);
@@ -9,6 +9,9 @@ export declare const ptPT: {
9
9
  noData?: string | undefined;
10
10
  zoomIn?: string | undefined;
11
11
  zoomOut?: string | undefined;
12
+ toolbarExport?: string | undefined;
13
+ toolbarExportPrint?: string | undefined;
14
+ toolbarExportImage?: ((mimeType: import("./utils/imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
12
15
  };
13
16
  };
14
17
  };
@@ -1,9 +1,15 @@
1
+ import { imageMimeTypes } from "./utils/imageMimeTypes.js";
1
2
  import { getChartsLocalization } from "./utils/getChartsLocalization.js";
2
3
  export const ptPTLocaleText = {
3
4
  // Overlay
4
5
  loading: 'Carregando dados…',
5
6
  noData: 'Sem dados para mostrar',
7
+ // Toolbar
6
8
  zoomIn: 'Aumentar zoom',
7
- zoomOut: 'Diminuir zoom'
9
+ zoomOut: 'Diminuir zoom',
10
+ toolbarExport: 'Exportar',
11
+ // Toolbar Export Menu
12
+ toolbarExportPrint: 'Imprimir',
13
+ toolbarExportImage: mimeType => `Exportar como ${imageMimeTypes[mimeType] ?? mimeType}`
8
14
  };
9
15
  export const ptPT = getChartsLocalization(ptPTLocaleText);
@@ -1,3 +1,4 @@
1
+ import { ChartImageExportMimeType } from "./imageMimeTypes.js";
1
2
  export interface ChartsLocaleText {
2
3
  /**
3
4
  * Title displayed in the overlay if `loading` is `true`.
@@ -15,5 +16,21 @@ export interface ChartsLocaleText {
15
16
  * Tooltip text shown when hovering over the zoom out button.
16
17
  */
17
18
  zoomOut: string;
19
+ /**
20
+ * Text for the export button tooltip in the toolbar.
21
+ */
22
+ toolbarExport: string;
23
+ /**
24
+ * Text for the print button in the toolbar's export menu.
25
+ */
26
+ toolbarExportPrint: string;
27
+ /**
28
+ * Text for an "Export as {image type}" button in the toolbar's export menu.
29
+ * The only format supported in all browsers is 'image/png'.
30
+ *
31
+ * @param {string} mimeType The MIME type of the image to export, e.g., 'image/png'.
32
+ * @returns {string} The localized string for an export image button.
33
+ */
34
+ toolbarExportImage: (mimeType: ChartImageExportMimeType | (string & {})) => string;
18
35
  }
19
36
  export type ChartsTranslationKeys = keyof ChartsLocaleText;
@@ -13,6 +13,9 @@ export declare const getChartsLocalization: (chartsTranslations: Partial<ChartsL
13
13
  noData?: string | undefined;
14
14
  zoomIn?: string | undefined;
15
15
  zoomOut?: string | undefined;
16
+ toolbarExport?: string | undefined;
17
+ toolbarExportPrint?: string | undefined;
18
+ toolbarExportImage?: ((mimeType: import("./imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
16
19
  };
17
20
  };
18
21
  };
@@ -0,0 +1,2 @@
1
+ export declare const imageMimeTypes: Record<string, string | undefined>;
2
+ export type ChartImageExportMimeType = 'image/png' | 'image/jpeg' | 'image/webp';
@@ -0,0 +1,5 @@
1
+ export const imageMimeTypes = {
2
+ 'image/png': 'PNG',
3
+ 'image/jpeg': 'JPEG',
4
+ 'image/webp': 'WebP'
5
+ };
@@ -7,14 +7,18 @@ export type ChartBaseCommonProps<T = HTMLElement> = React.DOMAttributes<T> & {
7
7
  };
8
8
  export type ChartBaseIconProps = ChartBaseCommonProps<SVGSVGElement> & {
9
9
  titleAccess?: string;
10
+ fontSize?: 'small' | 'medium' | 'large' | 'inherit';
10
11
  };
11
12
  export type ChartBaseButtonProps = ChartBaseCommonProps & {
12
13
  ref?: React.Ref<HTMLButtonElement>;
14
+ id?: string;
13
15
  disabled?: boolean;
14
16
  tabIndex?: number;
15
17
  };
16
18
  export type ChartBaseIconButtonProps = ChartBaseCommonProps & {
17
19
  ref?: React.Ref<HTMLButtonElement>;
20
+ id?: string;
18
21
  disabled?: boolean;
19
22
  tabIndex?: number;
23
+ size?: 'small' | 'medium' | 'large';
20
24
  };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.5.3
2
+ * @mui/x-charts v8.6.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * This component is used to assert that a certain component should not be rendered.
4
+ * It is used in cases where we want to apply styles to a component that is not rendered because we use the `as` prop (introduced by `styled`) to replace the rendered component.
5
+ * We need it because we don't know the component that will be rendered at the time of writing the styles.
6
+ *
7
+ * @param _props Not used
8
+ */
9
+ export declare function NotRendered<T>(_props: T): React.ReactNode;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NotRendered = NotRendered;
7
+ /**
8
+ * This component is used to assert that a certain component should not be rendered.
9
+ * It is used in cases where we want to apply styles to a component that is not rendered because we use the `as` prop (introduced by `styled`) to replace the rendered component.
10
+ * We need it because we don't know the component that will be rendered at the time of writing the styles.
11
+ *
12
+ * @param _props Not used
13
+ */
14
+ function NotRendered(_props) {
15
+ throw new Error('Failed assertion: should not be rendered');
16
+ }
@@ -1,6 +1,7 @@
1
1
  export * from "./components/ChartsAxesGradients/index.js";
2
2
  export * from "./components/ChartsWrapper/index.js";
3
3
  export * from "../ChartsLabel/ChartsLabelMark.js";
4
+ export * from "./components/NotRendered.js";
4
5
  export { useSeries } from "../hooks/useSeries.js";
5
6
  export { useInteractionItemProps } from "../hooks/useInteractionItemProps.js";
6
7
  export { useDrawingArea } from "../hooks/useDrawingArea.js";
@@ -111,6 +111,18 @@ Object.keys(_ChartsLabelMark).forEach(function (key) {
111
111
  }
112
112
  });
113
113
  });
114
+ var _NotRendered = require("./components/NotRendered");
115
+ Object.keys(_NotRendered).forEach(function (key) {
116
+ if (key === "default" || key === "__esModule") return;
117
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
118
+ if (key in exports && exports[key] === _NotRendered[key]) return;
119
+ Object.defineProperty(exports, key, {
120
+ enumerable: true,
121
+ get: function () {
122
+ return _NotRendered[key];
123
+ }
124
+ });
125
+ });
114
126
  var _useSeries = require("../hooks/useSeries");
115
127
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
116
128
  var _useDrawingArea = require("../hooks/useDrawingArea");
@@ -15,6 +15,7 @@ var _useSelector = require("../../../store/useSelector");
15
15
  var _constants = require("../../../../constants");
16
16
  var _useChartDimensions = require("./useChartDimensions.selectors");
17
17
  var _defaultizeMargin = require("../../../defaultizeMargin");
18
+ var _getSVGPoint = require("../../../getSVGPoint");
18
19
  const MAX_COMPUTE_RUN = 10;
19
20
  const useChartDimensions = ({
20
21
  params,
@@ -156,16 +157,43 @@ const useChartDimensions = ({
156
157
  const isYInside = React.useCallback(y => y >= drawingArea.top - 1 && y <= drawingArea.top + drawingArea.height, [drawingArea.height, drawingArea.top]);
157
158
  const isPointInside = React.useCallback((x, y, targetElement) => {
158
159
  // For element allowed to overflow, wrapping them in <g data-drawing-container /> make them fully part of the drawing area.
159
- if (targetElement && targetElement.closest('[data-drawing-container]')) {
160
+ if (targetElement && 'closest' in targetElement && targetElement.closest('[data-drawing-container]')) {
160
161
  return true;
161
162
  }
162
163
  return isXInside(x) && isYInside(y);
163
164
  }, [isXInside, isYInside]);
165
+ const isElementInside = React.useCallback(element => {
166
+ const svgElement = svgRef.current;
167
+ if (!element || !(element instanceof Element) || !svgElement) {
168
+ return false;
169
+ }
170
+ // For element allowed to overflow, wrapping them in <g data-drawing-container /> make them fully part of the drawing area.
171
+ if (element.closest('[data-drawing-container]')) {
172
+ return true;
173
+ }
174
+ const rect = element.getBoundingClientRect();
175
+ const {
176
+ x: left,
177
+ y: top
178
+ } = (0, _getSVGPoint.getSVGPoint)(svgElement, {
179
+ clientX: rect.left,
180
+ clientY: rect.top
181
+ });
182
+ const {
183
+ x: right,
184
+ y: bottom
185
+ } = (0, _getSVGPoint.getSVGPoint)(svgElement, {
186
+ clientX: rect.right,
187
+ clientY: rect.bottom
188
+ });
189
+ return isXInside(left) && isXInside(right) && isYInside(top) && isYInside(bottom);
190
+ }, [isXInside, isYInside, svgRef]);
164
191
  return {
165
192
  instance: {
166
193
  isPointInside,
167
194
  isXInside,
168
- isYInside
195
+ isYInside,
196
+ isElementInside
169
197
  }
170
198
  };
171
199
  };
@@ -63,14 +63,20 @@ export interface UseChartDimensionsState {
63
63
  };
64
64
  }
65
65
  export interface UseChartDimensionsInstance {
66
+ /**
67
+ * Checks if an element is inside the drawing area.
68
+ * @param {Element | EventTarget | null} element The element to check.
69
+ * @returns {boolean} `true` if the element is inside the drawing area, `false` otherwise.
70
+ */
71
+ isElementInside: (element: Element | EventTarget | null | undefined) => boolean;
66
72
  /**
67
73
  * Checks if a point is inside the drawing area.
68
74
  * @param {number} x The x coordinate of the point.
69
75
  * @param {number} y The y coordinate of the point.
70
- * @param {Element} targetElement The element to check if it is allowed to overflow the drawing area.
76
+ * @param {Element | EventTarget | null} targetElement The element to check if it is allowed to overflow the drawing area.
71
77
  * @returns {boolean} `true` if the point is inside the drawing area, `false` otherwise.
72
78
  */
73
- isPointInside: (x: number, y: number, targetElement?: Element) => boolean;
79
+ isPointInside: (x: number, y: number, targetElement?: Element | EventTarget | null) => boolean;
74
80
  /**
75
81
  * Checks if the x coordinate is inside the drawing area.
76
82
  * @param {number} x The x coordinate of the point.
@@ -98,10 +98,26 @@ const useChartPolarAxis = ({
98
98
  instance.cleanInteraction?.();
99
99
  };
100
100
  const handleMove = event => {
101
- const target = 'targetTouches' in event ? event.targetTouches[0] : event;
102
- const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, target);
103
- mousePosition.current.x = svgPoint.x;
104
- mousePosition.current.y = svgPoint.y;
101
+ const srcEvent = event;
102
+
103
+ // On touch, we want to allow user to interact with the entire svg area in
104
+ // order to better display the tooltip.
105
+ if (event.pointerType === 'touch') {
106
+ const svgRect = element.getBoundingClientRect();
107
+ if (srcEvent.clientX < svgRect.left || srcEvent.clientX > svgRect.right || srcEvent.clientY < svgRect.top || srcEvent.clientY > svgRect.bottom) {
108
+ mousePosition.current.isInChart = false;
109
+ instance.cleanInteraction();
110
+ return;
111
+ }
112
+ const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, srcEvent);
113
+ mousePosition.current.isInChart = true;
114
+ instance.setPointerCoordinate(svgPoint);
115
+ return;
116
+ }
117
+
118
+ // On mouse, we want to restrict the interaction to the drawing area and radar circle.
119
+
120
+ const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, srcEvent);
105
121
 
106
122
  // Test if it's in the drawing area
107
123
  if (!instance.isPointInside(svgPoint.x, svgPoint.y, event.target)) {
package/locales/enUS.d.ts CHANGED
@@ -10,6 +10,9 @@ export declare const enUS: {
10
10
  noData?: string | undefined;
11
11
  zoomIn?: string | undefined;
12
12
  zoomOut?: string | undefined;
13
+ toolbarExport?: string | undefined;
14
+ toolbarExportPrint?: string | undefined;
15
+ toolbarExportImage?: ((mimeType: import("./utils/imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
13
16
  };
14
17
  };
15
18
  };