@mui/x-charts 8.11.1 → 8.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/BarChart/index.d.ts +1 -0
  2. package/BarChart/useBarChartProps.js +4 -3
  3. package/CHANGELOG.md +181 -0
  4. package/ChartsAxisHighlight/ChartsXAxisHighlight.js +4 -4
  5. package/ChartsAxisHighlight/ChartsYAxisHighlight.js +4 -4
  6. package/ChartsLegend/ChartsLegend.js +2 -1
  7. package/ChartsLegend/PiecewiseColorLegend.d.ts +2 -2
  8. package/ChartsLegend/PiecewiseColorLegend.js +32 -22
  9. package/ChartsLegend/piecewiseColorLegendClasses.d.ts +4 -0
  10. package/ChartsLegend/piecewiseColorLegendClasses.js +2 -2
  11. package/ChartsSurface/ChartsSurface.js +2 -1
  12. package/ChartsWrapper/ChartsWrapper.d.ts +4 -0
  13. package/ChartsWrapper/ChartsWrapper.js +73 -25
  14. package/ChartsXAxis/ChartsGroupedXAxisTicks.d.ts +8 -0
  15. package/ChartsXAxis/{ChartsGroupedXAxis.js → ChartsGroupedXAxisTicks.js} +11 -54
  16. package/ChartsXAxis/ChartsSingleXAxisTicks.d.ts +10 -0
  17. package/ChartsXAxis/{ChartsSingleXAxis.js → ChartsSingleXAxisTicks.js} +15 -51
  18. package/ChartsXAxis/ChartsXAxis.js +4 -6
  19. package/ChartsXAxis/ChartsXAxisImpl.d.ts +13 -0
  20. package/ChartsXAxis/ChartsXAxisImpl.js +117 -0
  21. package/ChartsXAxis/getVisibleLabels.js +5 -1
  22. package/ChartsXAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -496
  23. package/ChartsXAxis/{useAxisProps.js → useAxisTicksProps.js} +4 -31
  24. package/ChartsXAxis/utilities.d.ts +1 -2
  25. package/ChartsXAxis/utilities.js +1 -7
  26. package/{esm/ChartsYAxis/ChartsGroupedYAxis.d.ts → ChartsYAxis/ChartsGroupedYAxisTicks.d.ts} +2 -2
  27. package/ChartsYAxis/{ChartsGroupedYAxis.js → ChartsGroupedYAxisTicks.js} +11 -54
  28. package/ChartsYAxis/ChartsSingleYAxisTicks.d.ts +10 -0
  29. package/ChartsYAxis/{ChartsSingleYAxis.js → ChartsSingleYAxisTicks.js} +15 -50
  30. package/ChartsYAxis/ChartsYAxis.js +6 -8
  31. package/ChartsYAxis/ChartsYAxisImpl.d.ts +13 -0
  32. package/ChartsYAxis/ChartsYAxisImpl.js +133 -0
  33. package/ChartsYAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -504
  34. package/ChartsYAxis/{useAxisProps.js → useAxisTicksProps.js} +5 -44
  35. package/ChartsYAxis/utilities.d.ts +0 -1
  36. package/ChartsYAxis/utilities.js +1 -7
  37. package/LineChart/useAreaPlotData.js +2 -2
  38. package/LineChart/useLineChartProps.js +2 -1
  39. package/LineChart/useLinePlotData.js +2 -2
  40. package/PieChart/PieChart.js +1 -0
  41. package/RadarChart/RadarAxis/useRadarAxis.js +2 -2
  42. package/RadarChart/useRadarChartProps.js +2 -1
  43. package/ScatterChart/useScatterChartProps.js +2 -1
  44. package/Toolbar/Toolbar.js +2 -1
  45. package/esm/BarChart/index.d.ts +1 -0
  46. package/esm/BarChart/useBarChartProps.js +4 -3
  47. package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +4 -4
  48. package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +4 -4
  49. package/esm/ChartsLegend/ChartsLegend.js +2 -1
  50. package/esm/ChartsLegend/PiecewiseColorLegend.d.ts +2 -2
  51. package/esm/ChartsLegend/PiecewiseColorLegend.js +32 -22
  52. package/esm/ChartsLegend/piecewiseColorLegendClasses.d.ts +4 -0
  53. package/esm/ChartsLegend/piecewiseColorLegendClasses.js +2 -2
  54. package/esm/ChartsSurface/ChartsSurface.js +2 -1
  55. package/esm/ChartsWrapper/ChartsWrapper.d.ts +4 -0
  56. package/esm/ChartsWrapper/ChartsWrapper.js +73 -25
  57. package/esm/ChartsXAxis/ChartsGroupedXAxisTicks.d.ts +8 -0
  58. package/esm/ChartsXAxis/{ChartsGroupedXAxis.js → ChartsGroupedXAxisTicks.js} +12 -55
  59. package/esm/ChartsXAxis/ChartsSingleXAxisTicks.d.ts +10 -0
  60. package/esm/ChartsXAxis/{ChartsSingleXAxis.js → ChartsSingleXAxisTicks.js} +16 -54
  61. package/esm/ChartsXAxis/ChartsXAxis.js +4 -6
  62. package/esm/ChartsXAxis/ChartsXAxisImpl.d.ts +13 -0
  63. package/esm/ChartsXAxis/ChartsXAxisImpl.js +110 -0
  64. package/esm/ChartsXAxis/getVisibleLabels.js +5 -1
  65. package/esm/ChartsXAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -496
  66. package/esm/ChartsXAxis/{useAxisProps.js → useAxisTicksProps.js} +3 -29
  67. package/esm/ChartsXAxis/utilities.d.ts +1 -2
  68. package/esm/ChartsXAxis/utilities.js +0 -6
  69. package/{ChartsYAxis/ChartsGroupedYAxis.d.ts → esm/ChartsYAxis/ChartsGroupedYAxisTicks.d.ts} +2 -2
  70. package/esm/ChartsYAxis/{ChartsGroupedYAxis.js → ChartsGroupedYAxisTicks.js} +12 -55
  71. package/esm/ChartsYAxis/ChartsSingleYAxisTicks.d.ts +10 -0
  72. package/esm/ChartsYAxis/{ChartsSingleYAxis.js → ChartsSingleYAxisTicks.js} +16 -53
  73. package/esm/ChartsYAxis/ChartsYAxis.js +5 -7
  74. package/esm/ChartsYAxis/ChartsYAxisImpl.d.ts +13 -0
  75. package/esm/ChartsYAxis/ChartsYAxisImpl.js +126 -0
  76. package/esm/ChartsYAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -504
  77. package/esm/ChartsYAxis/{useAxisProps.js → useAxisTicksProps.js} +4 -42
  78. package/esm/ChartsYAxis/utilities.d.ts +0 -1
  79. package/esm/ChartsYAxis/utilities.js +0 -6
  80. package/esm/LineChart/useAreaPlotData.js +2 -2
  81. package/esm/LineChart/useLineChartProps.js +2 -1
  82. package/esm/LineChart/useLinePlotData.js +2 -2
  83. package/esm/PieChart/PieChart.js +1 -0
  84. package/esm/RadarChart/RadarAxis/useRadarAxis.js +2 -2
  85. package/esm/RadarChart/useRadarChartProps.js +2 -1
  86. package/esm/ScatterChart/useScatterChartProps.js +2 -1
  87. package/esm/Toolbar/Toolbar.js +2 -1
  88. package/esm/hooks/useInteractionItemProps.js +5 -4
  89. package/esm/hooks/useScale.js +2 -2
  90. package/esm/hooks/useTicks.js +10 -3
  91. package/esm/hooks/useTicksGrouped.js +2 -2
  92. package/esm/index.js +1 -1
  93. package/esm/internals/dateHelpers.d.ts +4 -2
  94. package/esm/internals/dateHelpers.js +5 -4
  95. package/esm/internals/defaultValueFormatters.js +5 -0
  96. package/esm/internals/index.d.ts +1 -1
  97. package/esm/internals/index.js +1 -1
  98. package/esm/internals/invertScale.js +2 -2
  99. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +5 -5
  100. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -3
  101. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
  102. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +2 -2
  103. package/esm/internals/scaleGuards.d.ts +4 -0
  104. package/esm/internals/scaleGuards.js +3 -0
  105. package/esm/locales/index.d.ts +2 -1
  106. package/esm/locales/index.js +1 -0
  107. package/esm/locales/svSE.d.ts +19 -0
  108. package/esm/locales/svSE.js +15 -0
  109. package/esm/models/axis.d.ts +3 -0
  110. package/hooks/useInteractionItemProps.js +6 -4
  111. package/hooks/useScale.js +2 -2
  112. package/hooks/useTicks.js +10 -3
  113. package/hooks/useTicksGrouped.js +2 -2
  114. package/index.js +1 -1
  115. package/internals/dateHelpers.d.ts +4 -2
  116. package/internals/dateHelpers.js +5 -4
  117. package/internals/defaultValueFormatters.js +5 -0
  118. package/internals/index.d.ts +1 -1
  119. package/internals/index.js +4 -4
  120. package/internals/invertScale.js +2 -2
  121. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +5 -5
  122. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -3
  123. package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
  124. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +2 -2
  125. package/internals/scaleGuards.d.ts +4 -0
  126. package/internals/{isBandScale.js → scaleGuards.js} +2 -2
  127. package/locales/index.d.ts +2 -1
  128. package/locales/index.js +11 -0
  129. package/locales/svSE.d.ts +19 -0
  130. package/locales/svSE.js +21 -0
  131. package/models/axis.d.ts +3 -0
  132. package/package.json +5 -5
  133. package/ChartsXAxis/ChartsGroupedXAxis.d.ts +0 -7
  134. package/ChartsXAxis/ChartsSingleXAxis.d.ts +0 -7
  135. package/ChartsYAxis/ChartsSingleYAxis.d.ts +0 -7
  136. package/esm/ChartsXAxis/ChartsGroupedXAxis.d.ts +0 -7
  137. package/esm/ChartsXAxis/ChartsSingleXAxis.d.ts +0 -7
  138. package/esm/ChartsYAxis/ChartsSingleYAxis.d.ts +0 -7
  139. package/esm/internals/isBandScale.d.ts +0 -5
  140. package/esm/internals/isBandScale.js +0 -3
  141. package/internals/isBandScale.d.ts +0 -5
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { area as d3Area } from '@mui/x-charts-vendor/d3-shape';
3
3
  import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
4
- import { isBandScale } from "../internals/isBandScale.js";
4
+ import { isOrdinalScale } from "../internals/scaleGuards.js";
5
5
  import { getCurveFactory } from "../internals/getCurve.js";
6
6
  import { getValueToPositionMapper, useLineSeriesContext, useXAxes, useYAxes } from "../hooks/index.js";
7
7
  import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
@@ -52,7 +52,7 @@ export function useAreaPlotData(xAxes, yAxes) {
52
52
  throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
53
53
  }
54
54
  }
55
- const shouldExpand = curve?.includes('step') && !strictStepCurve && isBandScale(xScale);
55
+ const shouldExpand = curve?.includes('step') && !strictStepCurve && isOrdinalScale(xScale);
56
56
  const formattedData = xData?.flatMap((x, index) => {
57
57
  const nullData = data[index] == null;
58
58
  if (shouldExpand) {
@@ -119,7 +119,8 @@ export const useLineChartProps = props => {
119
119
  const chartsWrapperProps = {
120
120
  sx,
121
121
  legendPosition: props.slotProps?.legend?.position,
122
- legendDirection: props.slotProps?.legend?.direction
122
+ legendDirection: props.slotProps?.legend?.direction,
123
+ hideLegend: props.hideLegend ?? false
123
124
  };
124
125
  return {
125
126
  chartsWrapperProps,
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { warnOnce } from '@mui/x-internals/warning';
3
3
  import { line as d3Line } from '@mui/x-charts-vendor/d3-shape';
4
4
  import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
5
- import { isBandScale } from "../internals/isBandScale.js";
5
+ import { isOrdinalScale } from "../internals/scaleGuards.js";
6
6
  import { getCurveFactory } from "../internals/getCurve.js";
7
7
  import { getValueToPositionMapper, useLineSeriesContext, useXAxes, useYAxes } from "../hooks/index.js";
8
8
  import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
@@ -50,7 +50,7 @@ export function useLinePlotData(xAxes, yAxes) {
50
50
  warnOnce(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`, 'error');
51
51
  }
52
52
  }
53
- const shouldExpand = curve?.includes('step') && !strictStepCurve && isBandScale(xScale);
53
+ const shouldExpand = curve?.includes('step') && !strictStepCurve && isOrdinalScale(xScale);
54
54
  const formattedData = xData?.flatMap((x, index) => {
55
55
  const nullData = data[index] == null;
56
56
  if (shouldExpand) {
@@ -78,6 +78,7 @@ const PieChart = /*#__PURE__*/React.forwardRef(function PieChart(inProps, ref) {
78
78
  legendPosition: props.slotProps?.legend?.position,
79
79
  legendDirection: props.slotProps?.legend?.direction ?? 'vertical',
80
80
  sx: sx,
81
+ hideLegend: hideLegend ?? false,
81
82
  children: [showToolbar && Toolbar ? /*#__PURE__*/_jsx(Toolbar, _extends({}, props.slotProps?.toolbar)) : null, !hideLegend && /*#__PURE__*/_jsx(ChartsLegend, {
82
83
  direction: props.slotProps?.legend?.direction ?? 'vertical',
83
84
  slots: slots,
@@ -3,7 +3,7 @@ import { useRadiusAxes } from "../../hooks/useAxis.js";
3
3
  import { useRotationScale } from "../../hooks/useScale.js";
4
4
  import { useChartContext } from "../../context/ChartProvider/useChartContext.js";
5
5
  import { selectorChartPolarCenter } from "../../internals/plugins/featurePlugins/useChartPolarAxis/index.js";
6
- import { isBandScale } from "../../internals/isBandScale.js";
6
+ import { isOrdinalScale } from "../../internals/scaleGuards.js";
7
7
  import { degToRad } from "../../internals/degToRad.js";
8
8
  import { clampAngle } from "../../internals/clampAngle.js";
9
9
  import { useSelector } from "../../internals/store/useSelector.js";
@@ -42,7 +42,7 @@ export function useRadarAxis(params) {
42
42
  }, (_, index) => (index + 1) / divisions);
43
43
  const radiusScale = radiusAxis[metric].scale;
44
44
  const R = radiusScale.range()[1];
45
- if (isBandScale(radiusScale)) {
45
+ if (isOrdinalScale(radiusScale)) {
46
46
  if (process.env.NODE_ENV !== 'production') {
47
47
  console.error('MUI X Charts: Radar chart does not support ordinal axes');
48
48
  }
@@ -59,7 +59,8 @@ export const useRadarChartProps = props => {
59
59
  slotProps
60
60
  };
61
61
  const chartsWrapperProps = {
62
- sx
62
+ sx,
63
+ hideLegend: props.hideLegend ?? false
63
64
  };
64
65
  const radarGrid = {
65
66
  divisions,
@@ -88,7 +88,8 @@ export const useScatterChartProps = props => {
88
88
  const chartsWrapperProps = {
89
89
  sx,
90
90
  legendPosition: props.slotProps?.legend?.position,
91
- legendDirection: props.slotProps?.legend?.direction
91
+ legendDirection: props.slotProps?.legend?.direction,
92
+ hideLegend: props.hideLegend ?? false
92
93
  };
93
94
  return {
94
95
  chartsWrapperProps,
@@ -25,7 +25,8 @@ const ToolbarRoot = styled('div', {
25
25
  minHeight: 44,
26
26
  boxSizing: 'border-box',
27
27
  border: `1px solid ${(theme.vars || theme).palette.divider}`,
28
- borderRadius: 4
28
+ borderRadius: 4,
29
+ gridArea: 'toolbar'
29
30
  }));
30
31
  export const Toolbar = /*#__PURE__*/React.forwardRef(function Toolbar(_ref, ref) {
31
32
  let {
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
+ import useEventCallback from '@mui/utils/useEventCallback';
4
5
  import { useChartContext } from "../context/ChartProvider/index.js";
5
6
  function onPointerDown(event) {
6
7
  if ('hasPointerCapture' in event.currentTarget && event.currentTarget.hasPointerCapture(event.pointerId)) {
@@ -12,16 +13,16 @@ export const useInteractionItemProps = (data, skip) => {
12
13
  instance
13
14
  } = useChartContext();
14
15
  const interactionActive = React.useRef(false);
15
- const onPointerEnter = React.useCallback(() => {
16
+ const onPointerEnter = useEventCallback(() => {
16
17
  interactionActive.current = true;
17
18
  instance.setItemInteraction(data);
18
19
  instance.setHighlight(data);
19
- }, [instance, data]);
20
- const onPointerLeave = React.useCallback(() => {
20
+ });
21
+ const onPointerLeave = useEventCallback(() => {
21
22
  interactionActive.current = false;
22
23
  instance.removeItemInteraction(data);
23
24
  instance.clearHighlight();
24
- }, [instance, data]);
25
+ });
25
26
  React.useEffect(() => {
26
27
  return () => {
27
28
  /* Clean up state if this item is unmounted while active. */
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { isBandScale } from "../internals/isBandScale.js";
3
+ import { isOrdinalScale } from "../internals/scaleGuards.js";
4
4
  import { useRadiusAxis, useRotationAxis, useXAxis, useYAxis } from "./useAxis.js";
5
5
 
6
6
  /**
@@ -10,7 +10,7 @@ import { useRadiusAxis, useRotationAxis, useXAxis, useYAxis } from "./useAxis.js
10
10
  * @returns {(value: any) => number} A function that map value to their position
11
11
  */
12
12
  export function getValueToPositionMapper(scale) {
13
- if (isBandScale(scale)) {
13
+ if (isOrdinalScale(scale)) {
14
14
  return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
15
15
  }
16
16
  return value => scale(value);
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as React from 'react';
4
4
  import { useChartContext } from "../context/ChartProvider/index.js";
5
- import { isBandScale } from "../internals/isBandScale.js";
5
+ import { isOrdinalScale } from "../internals/scaleGuards.js";
6
6
  import { isInfinity } from "../internals/isInfinity.js";
7
7
  const offsetRatio = {
8
8
  start: 0,
@@ -22,7 +22,7 @@ export function getTicks(options) {
22
22
  } = options;
23
23
 
24
24
  // band scale
25
- if (isBandScale(scale)) {
25
+ if (isOrdinalScale(scale)) {
26
26
  const domain = scale.domain();
27
27
  const tickLabelPlacement = tickLabelPlacementProp ?? 'middle';
28
28
  if (scale.bandwidth() > 0) {
@@ -72,7 +72,7 @@ export function getTicks(options) {
72
72
  return [];
73
73
  }
74
74
  const tickLabelPlacement = tickLabelPlacementProp;
75
- const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
75
+ const ticks = typeof tickInterval === 'object' ? tickInterval : getDefaultTicks(scale, tickNumber);
76
76
 
77
77
  // Ticks inside the drawing area
78
78
  const visibleTicks = [];
@@ -102,6 +102,13 @@ export function getTicks(options) {
102
102
  }
103
103
  return visibleTicks;
104
104
  }
105
+ function getDefaultTicks(scale, tickNumber) {
106
+ const domain = scale.domain();
107
+ if (domain[0] === domain[1]) {
108
+ return [domain[0]];
109
+ }
110
+ return scale.ticks(tickNumber);
111
+ }
105
112
  export function useTicks(options) {
106
113
  const {
107
114
  scale,
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
- import { isBandScale } from "../internals/isBandScale.js";
4
+ import { isOrdinalScale } from "../internals/scaleGuards.js";
5
5
  const offsetRatio = {
6
6
  start: 0,
7
7
  extremities: 0,
@@ -62,7 +62,7 @@ function mapToGrouping(tickValues, groups, tickPlacement, tickLabelPlacement, sc
62
62
  if (isNew) {
63
63
  currentValueCount = 1;
64
64
  // Calculate tick offset
65
- const tickOffset = isBandScale(scale) ? scale(tickValue) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step() : scale(tickValue);
65
+ const tickOffset = isOrdinalScale(scale) ? scale(tickValue) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step() : scale(tickValue);
66
66
 
67
67
  // Calculate the label offset
68
68
  const labelOffset = scale.step() * currentValueCount * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement]);
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.11.1
2
+ * @mui/x-charts v8.11.3
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,3 +1,4 @@
1
+ import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
1
2
  import { AxisConfig } from "../models/index.js";
2
3
  import { ChartsAxisProps } from "../models/axis.js";
3
4
  /**
@@ -8,8 +9,9 @@ import { ChartsAxisProps } from "../models/axis.js";
8
9
  export declare const isDateData: (data?: readonly any[]) => data is Date[];
9
10
  /**
10
11
  * Creates a formatter function for date values.
11
- * @param axis The axis configuration.
12
+ * @param data The data array containing Date or NumberValue objects.
12
13
  * @param range The range for the time scale.
14
+ * @param tickNumber (Optional) The number of ticks for formatting.
13
15
  * @returns A formatter function for date values.
14
16
  */
15
- export declare function createDateFormatter(axis: AxisConfig<'band' | 'point', any, ChartsAxisProps>, range: number[]): AxisConfig<'band' | 'point', any, ChartsAxisProps>['valueFormatter'];
17
+ export declare function createDateFormatter(data: Iterable<Date | NumberValue>, range: number[], tickNumber?: number): AxisConfig<'band' | 'point', any, ChartsAxisProps>['valueFormatter'];
@@ -8,13 +8,14 @@ export const isDateData = data => data?.[0] instanceof Date;
8
8
 
9
9
  /**
10
10
  * Creates a formatter function for date values.
11
- * @param axis The axis configuration.
11
+ * @param data The data array containing Date or NumberValue objects.
12
12
  * @param range The range for the time scale.
13
+ * @param tickNumber (Optional) The number of ticks for formatting.
13
14
  * @returns A formatter function for date values.
14
15
  */
15
- export function createDateFormatter(axis, range) {
16
- const timeScale = scaleTime(axis.data, range);
16
+ export function createDateFormatter(data, range, tickNumber) {
17
+ const timeScale = scaleTime(data, range);
17
18
  return (v, {
18
19
  location
19
- }) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`;
20
+ }) => location === 'tick' ? timeScale.tickFormat(tickNumber)(v) : `${v.toLocaleString()}`;
20
21
  }
@@ -5,6 +5,11 @@
5
5
  export function createScalarFormatter(tickNumber, zoomScale) {
6
6
  return function defaultScalarValueFormatter(value, context) {
7
7
  if (context.location === 'tick') {
8
+ const domain = context.scale.domain();
9
+ const zeroSizeDomain = domain[0] === domain[1];
10
+ if (zeroSizeDomain) {
11
+ return context.scale.tickFormat(1)(value);
12
+ }
8
13
  return context.scale.tickFormat(tickNumber)(value);
9
14
  }
10
15
  if (context.location === 'zoom-slider-tooltip') {
@@ -52,7 +52,7 @@ export * from "./colorScale.js";
52
52
  export * from "./ticks.js";
53
53
  export * from "./dateHelpers.js";
54
54
  export * from "./invertScale.js";
55
- export * from "./isBandScale.js";
55
+ export * from "./scaleGuards.js";
56
56
  export * from "./findMinMax.js";
57
57
  export { getAxisExtremum } from "./plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.js";
58
58
  export * from "../context/ChartProvider/index.js";
@@ -62,7 +62,7 @@ export * from "./colorScale.js";
62
62
  export * from "./ticks.js";
63
63
  export * from "./dateHelpers.js";
64
64
  export * from "./invertScale.js";
65
- export * from "./isBandScale.js";
65
+ export * from "./scaleGuards.js";
66
66
  export * from "./findMinMax.js";
67
67
 
68
68
  // contexts
@@ -1,6 +1,6 @@
1
- import { isBandScale } from "./isBandScale.js";
1
+ import { isOrdinalScale } from "./scaleGuards.js";
2
2
  export function invertScale(scale, data, value) {
3
- if (isBandScale(scale)) {
3
+ if (isOrdinalScale(scale)) {
4
4
  const dataIndex = scale.bandwidth() === 0 ? Math.floor((value - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((value - Math.min(...scale.range())) / scale.step());
5
5
  return data[dataIndex];
6
6
  }
@@ -12,9 +12,9 @@ import { getAxisTriggerTooltip } from "./getAxisTriggerTooltip.js";
12
12
  import { getAxisDomainLimit } from "./getAxisDomainLimit.js";
13
13
  function getRange(drawingArea, axisDirection,
14
14
  // | 'rotation' | 'radius',
15
- axis) {
15
+ reverse) {
16
16
  const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
17
- return axis.reverse ? [range[1], range[0]] : range;
17
+ return reverse ? [range[1], range[0]] : range;
18
18
  }
19
19
  const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
20
20
  const DEFAULT_BAR_GAP_RATIO = 0.1;
@@ -42,7 +42,7 @@ export function computeAxisValue({
42
42
  const zoomOption = zoomOptions?.[axis.id];
43
43
  const zoom = zoomMap?.get(axis.id);
44
44
  const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
45
- const range = getRange(drawingArea, axisDirection, axis);
45
+ const range = getRange(drawingArea, axisDirection, axis.reverse ?? false);
46
46
  const [minData, maxData] = getAxisExtremum(axis, axisDirection, seriesConfig, axisIndex, formattedSeries, zoom === undefined && !zoomOption ? getFilters : undefined // Do not apply filtering if zoom is already defined.
47
47
  );
48
48
  const triggerTooltip = !axis.ignoreTooltip && axisIdsTriggeringTooltip.has(axis.id);
@@ -68,7 +68,7 @@ export function computeAxisValue({
68
68
  }, axis.colorMap)) : getColorScale(axis.colorMap))
69
69
  });
70
70
  if (isDateData(axis.data)) {
71
- const dateFormatter = createDateFormatter(axis, scaleRange);
71
+ const dateFormatter = createDateFormatter(axis.data, scaleRange, axis.tickNumber);
72
72
  completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
73
73
  }
74
74
  }
@@ -88,7 +88,7 @@ export function computeAxisValue({
88
88
  }, axis.colorMap)) : getColorScale(axis.colorMap))
89
89
  });
90
90
  if (isDateData(axis.data)) {
91
- const dateFormatter = createDateFormatter(axis, scaleRange);
91
+ const dateFormatter = createDateFormatter(axis.data, scaleRange, axis.tickNumber);
92
92
  completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
93
93
  }
94
94
  }
@@ -1,4 +1,4 @@
1
- import { isBandScale } from "../../../isBandScale.js";
1
+ import { isOrdinalScale } from "../../../scaleGuards.js";
2
2
  function getAsANumber(value) {
3
3
  return value instanceof Date ? value.getTime() : value;
4
4
  }
@@ -13,7 +13,7 @@ export function getAxisIndex(axisConfig, pointerValue) {
13
13
  data: axisData,
14
14
  reverse
15
15
  } = axisConfig;
16
- if (!isBandScale(scale)) {
16
+ if (!isOrdinalScale(scale)) {
17
17
  const value = scale.invert(pointerValue);
18
18
  if (axisData === undefined) {
19
19
  return -1;
@@ -51,7 +51,7 @@ export function getAxisValue(axisConfig, pointerValue, dataIndex) {
51
51
  scale,
52
52
  data: axisData
53
53
  } = axisConfig;
54
- if (!isBandScale(scale)) {
54
+ if (!isOrdinalScale(scale)) {
55
55
  if (dataIndex === null) {
56
56
  return scale.invert(pointerValue);
57
57
  }
@@ -63,7 +63,7 @@ export function computeAxisValue({
63
63
  }, axis.colorMap)) : getColorScale(axis.colorMap))
64
64
  });
65
65
  if (isDateData(axis.data)) {
66
- const dateFormatter = createDateFormatter(axis, range);
66
+ const dateFormatter = createDateFormatter(axis.data, range, axis.tickNumber);
67
67
  completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
68
68
  }
69
69
  }
@@ -80,7 +80,7 @@ export function computeAxisValue({
80
80
  }, axis.colorMap)) : getColorScale(axis.colorMap))
81
81
  });
82
82
  if (isDateData(axis.data)) {
83
- const dateFormatter = createDateFormatter(axis, range);
83
+ const dateFormatter = createDateFormatter(axis.data, range, axis.tickNumber);
84
84
  completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
85
85
  }
86
86
  }
@@ -1,4 +1,4 @@
1
- import { isBandScale } from "../../../isBandScale.js";
1
+ import { isOrdinalScale } from "../../../scaleGuards.js";
2
2
  import { clampAngleRad } from "../../../clampAngle.js";
3
3
 
4
4
  /**
@@ -11,7 +11,7 @@ export function getAxisIndex(axisConfig, pointerValue) {
11
11
  data: axisData,
12
12
  reverse
13
13
  } = axisConfig;
14
- if (!isBandScale(scale)) {
14
+ if (!isOrdinalScale(scale)) {
15
15
  throw new Error('MUI X Charts: getAxisValue is not implemented for polare continuous axes.');
16
16
  }
17
17
  if (!axisData) {
@@ -0,0 +1,4 @@
1
+ import { D3OrdinalScale, D3Scale } from "../models/axis.js";
2
+ export declare function isOrdinalScale<T extends {
3
+ toString(): string;
4
+ }>(scale: D3Scale<T>): scale is D3OrdinalScale<T>;
@@ -0,0 +1,3 @@
1
+ export function isOrdinalScale(scale) {
2
+ return scale.bandwidth !== undefined;
3
+ }
@@ -3,4 +3,5 @@ export * from "./elGR.js";
3
3
  export * from "./enUS.js";
4
4
  export * from "./frFR.js";
5
5
  export * from "./ptBR.js";
6
- export * from "./ptPT.js";
6
+ export * from "./ptPT.js";
7
+ export * from "./svSE.js";
@@ -3,4 +3,5 @@ export * from "./enUS.js";
3
3
  export * from "./frFR.js";
4
4
  export * from "./ptBR.js";
5
5
  export * from "./ptPT.js";
6
+ export * from "./svSE.js";
6
7
  export {};
@@ -0,0 +1,19 @@
1
+ import { ChartsLocaleText } from "./utils/chartsLocaleTextApi.js";
2
+ export declare const svSELocaleText: ChartsLocaleText;
3
+ export declare const svSE: {
4
+ components: {
5
+ MuiChartsLocalizationProvider: {
6
+ defaultProps: {
7
+ localeText: {
8
+ loading?: string | undefined;
9
+ noData?: string | undefined;
10
+ zoomIn?: string | undefined;
11
+ zoomOut?: string | undefined;
12
+ toolbarExport?: string | undefined;
13
+ toolbarExportPrint?: string | undefined;
14
+ toolbarExportImage?: ((mimeType: import("./utils/imageMimeTypes.js").ChartImageExportMimeType | (string & {})) => string) | undefined;
15
+ };
16
+ };
17
+ };
18
+ };
19
+ };
@@ -0,0 +1,15 @@
1
+ import { imageMimeTypes } from "./utils/imageMimeTypes.js";
2
+ import { getChartsLocalization } from "./utils/getChartsLocalization.js";
3
+ export const svSELocaleText = {
4
+ // Overlay
5
+ loading: 'Laddar data…',
6
+ noData: 'Inga data att visa',
7
+ // Toolbar
8
+ zoomIn: 'Zooma in',
9
+ zoomOut: 'Zooma ut',
10
+ toolbarExport: 'Exportera',
11
+ // Toolbar Export Menu
12
+ toolbarExportPrint: 'Skriv ut',
13
+ toolbarExportImage: mimeType => `Exportera som ${imageMimeTypes[mimeType] ?? mimeType}`
14
+ };
15
+ export const svSE = getChartsLocalization(svSELocaleText);
@@ -11,6 +11,9 @@ export type D3Scale<Domain extends {
11
11
  toString(): string;
12
12
  } = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleSymLog<Range, Output> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
13
13
  export type D3ContinuousScale<Range = number, Output = number> = ScaleSymLog<Range, Output> | ScaleLogarithmic<Range, Output> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
14
+ export type D3OrdinalScale<Domain extends {
15
+ toString(): string;
16
+ } = number | Date | string> = ScaleBand<Domain> | ScalePoint<Domain>;
14
17
  export interface ChartsAxisSlots {
15
18
  /**
16
19
  * Custom component for the axis main line.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  'use client';
3
3
 
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
5
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
6
  Object.defineProperty(exports, "__esModule", {
6
7
  value: true
@@ -8,6 +9,7 @@ Object.defineProperty(exports, "__esModule", {
8
9
  exports.getInteractionItemProps = getInteractionItemProps;
9
10
  exports.useInteractionItemProps = exports.useInteractionAllItemProps = void 0;
10
11
  var React = _interopRequireWildcard(require("react"));
12
+ var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
11
13
  var _ChartProvider = require("../context/ChartProvider");
12
14
  function onPointerDown(event) {
13
15
  if ('hasPointerCapture' in event.currentTarget && event.currentTarget.hasPointerCapture(event.pointerId)) {
@@ -19,16 +21,16 @@ const useInteractionItemProps = (data, skip) => {
19
21
  instance
20
22
  } = (0, _ChartProvider.useChartContext)();
21
23
  const interactionActive = React.useRef(false);
22
- const onPointerEnter = React.useCallback(() => {
24
+ const onPointerEnter = (0, _useEventCallback.default)(() => {
23
25
  interactionActive.current = true;
24
26
  instance.setItemInteraction(data);
25
27
  instance.setHighlight(data);
26
- }, [instance, data]);
27
- const onPointerLeave = React.useCallback(() => {
28
+ });
29
+ const onPointerLeave = (0, _useEventCallback.default)(() => {
28
30
  interactionActive.current = false;
29
31
  instance.removeItemInteraction(data);
30
32
  instance.clearHighlight();
31
- }, [instance, data]);
33
+ });
32
34
  React.useEffect(() => {
33
35
  return () => {
34
36
  /* Clean up state if this item is unmounted while active. */
package/hooks/useScale.js CHANGED
@@ -9,7 +9,7 @@ exports.useRadiusScale = useRadiusScale;
9
9
  exports.useRotationScale = useRotationScale;
10
10
  exports.useXScale = useXScale;
11
11
  exports.useYScale = useYScale;
12
- var _isBandScale = require("../internals/isBandScale");
12
+ var _scaleGuards = require("../internals/scaleGuards");
13
13
  var _useAxis = require("./useAxis");
14
14
  /**
15
15
  * For a given scale return a function that map value to their position.
@@ -18,7 +18,7 @@ var _useAxis = require("./useAxis");
18
18
  * @returns {(value: any) => number} A function that map value to their position
19
19
  */
20
20
  function getValueToPositionMapper(scale) {
21
- if ((0, _isBandScale.isBandScale)(scale)) {
21
+ if ((0, _scaleGuards.isOrdinalScale)(scale)) {
22
22
  return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
23
23
  }
24
24
  return value => scale(value);
package/hooks/useTicks.js CHANGED
@@ -9,7 +9,7 @@ exports.getTicks = getTicks;
9
9
  exports.useTicks = useTicks;
10
10
  var React = _interopRequireWildcard(require("react"));
11
11
  var _ChartProvider = require("../context/ChartProvider");
12
- var _isBandScale = require("../internals/isBandScale");
12
+ var _scaleGuards = require("../internals/scaleGuards");
13
13
  var _isInfinity = require("../internals/isInfinity");
14
14
  const offsetRatio = {
15
15
  start: 0,
@@ -29,7 +29,7 @@ function getTicks(options) {
29
29
  } = options;
30
30
 
31
31
  // band scale
32
- if ((0, _isBandScale.isBandScale)(scale)) {
32
+ if ((0, _scaleGuards.isOrdinalScale)(scale)) {
33
33
  const domain = scale.domain();
34
34
  const tickLabelPlacement = tickLabelPlacementProp ?? 'middle';
35
35
  if (scale.bandwidth() > 0) {
@@ -79,7 +79,7 @@ function getTicks(options) {
79
79
  return [];
80
80
  }
81
81
  const tickLabelPlacement = tickLabelPlacementProp;
82
- const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
82
+ const ticks = typeof tickInterval === 'object' ? tickInterval : getDefaultTicks(scale, tickNumber);
83
83
 
84
84
  // Ticks inside the drawing area
85
85
  const visibleTicks = [];
@@ -109,6 +109,13 @@ function getTicks(options) {
109
109
  }
110
110
  return visibleTicks;
111
111
  }
112
+ function getDefaultTicks(scale, tickNumber) {
113
+ const domain = scale.domain();
114
+ if (domain[0] === domain[1]) {
115
+ return [domain[0]];
116
+ }
117
+ return scale.ticks(tickNumber);
118
+ }
112
119
  function useTicks(options) {
113
120
  const {
114
121
  scale,
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.useTicksGrouped = useTicksGrouped;
9
9
  var React = _interopRequireWildcard(require("react"));
10
- var _isBandScale = require("../internals/isBandScale");
10
+ var _scaleGuards = require("../internals/scaleGuards");
11
11
  const offsetRatio = {
12
12
  start: 0,
13
13
  extremities: 0,
@@ -68,7 +68,7 @@ function mapToGrouping(tickValues, groups, tickPlacement, tickLabelPlacement, sc
68
68
  if (isNew) {
69
69
  currentValueCount = 1;
70
70
  // Calculate tick offset
71
- const tickOffset = (0, _isBandScale.isBandScale)(scale) ? scale(tickValue) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step() : scale(tickValue);
71
+ const tickOffset = (0, _scaleGuards.isOrdinalScale)(scale) ? scale(tickValue) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step() : scale(tickValue);
72
72
 
73
73
  // Calculate the label offset
74
74
  const labelOffset = scale.step() * currentValueCount * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement]);
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.11.1
2
+ * @mui/x-charts v8.11.3
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,3 +1,4 @@
1
+ import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
1
2
  import { AxisConfig } from "../models/index.js";
2
3
  import { ChartsAxisProps } from "../models/axis.js";
3
4
  /**
@@ -8,8 +9,9 @@ import { ChartsAxisProps } from "../models/axis.js";
8
9
  export declare const isDateData: (data?: readonly any[]) => data is Date[];
9
10
  /**
10
11
  * Creates a formatter function for date values.
11
- * @param axis The axis configuration.
12
+ * @param data The data array containing Date or NumberValue objects.
12
13
  * @param range The range for the time scale.
14
+ * @param tickNumber (Optional) The number of ticks for formatting.
13
15
  * @returns A formatter function for date values.
14
16
  */
15
- export declare function createDateFormatter(axis: AxisConfig<'band' | 'point', any, ChartsAxisProps>, range: number[]): AxisConfig<'band' | 'point', any, ChartsAxisProps>['valueFormatter'];
17
+ export declare function createDateFormatter(data: Iterable<Date | NumberValue>, range: number[], tickNumber?: number): AxisConfig<'band' | 'point', any, ChartsAxisProps>['valueFormatter'];