,
@@ -193,7 +191,7 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
externalSlotProps: slotProps?.axisLabel,
additionalProps: {
style: {
- fontSize: labelFontSize ?? 14,
+ fontSize: 14,
textAnchor: 'middle',
dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
...labelStyle,
@@ -290,12 +288,6 @@ ChartsXAxis.propTypes = {
* The label of the axis.
*/
label: PropTypes.string,
- /**
- * The font size of the axis label.
- * @default 14
- * @deprecated Consider using `labelStyle.fontSize` instead.
- */
- labelFontSize: PropTypes.number,
/**
* The style applied to the axis label.
*/
@@ -324,12 +316,6 @@ ChartsXAxis.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- /**
- * The font size of the axis ticks text.
- * @default 12
- * @deprecated Consider using `tickLabelStyle.fontSize` instead.
- */
- tickFontSize: PropTypes.number,
/**
* Defines which ticks are displayed.
* Its value can be:
diff --git a/packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx b/packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx
index f3f626018140..0c79475fd09e 100644
--- a/packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx
+++ b/packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx
@@ -39,8 +39,6 @@ const defaultProps = {
position: 'left',
disableLine: false,
disableTicks: false,
- tickFontSize: 12,
- labelFontSize: 14,
tickSize: 6,
} as const;
@@ -68,9 +66,7 @@ function ChartsYAxis(inProps: ChartsYAxisProps) {
position,
disableLine,
disableTicks,
- tickFontSize,
label,
- labelFontSize,
labelStyle,
tickLabelStyle,
tickSize: tickSizeProp,
@@ -104,6 +100,8 @@ function ChartsYAxis(inProps: ChartsYAxisProps) {
const positionSign = position === 'right' ? 1 : -1;
+ const tickFontSize = typeof tickLabelStyle?.fontSize === 'number' ? tickLabelStyle.fontSize : 12;
+
const labelRefPoint = {
x: positionSign * (tickFontSize + tickSize + 10),
y: top + height / 2,
@@ -135,7 +133,7 @@ function ChartsYAxis(inProps: ChartsYAxisProps) {
externalSlotProps: slotProps?.axisLabel,
additionalProps: {
style: {
- fontSize: labelFontSize,
+ fontSize: 14,
angle: positionSign * 90,
textAnchor: 'middle',
dominantBaseline: 'auto',
@@ -248,12 +246,6 @@ ChartsYAxis.propTypes = {
* The label of the axis.
*/
label: PropTypes.string,
- /**
- * The font size of the axis label.
- * @default 14
- * @deprecated Consider using `labelStyle.fontSize` instead.
- */
- labelFontSize: PropTypes.number,
/**
* The style applied to the axis label.
*/
@@ -282,12 +274,6 @@ ChartsYAxis.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- /**
- * The font size of the axis ticks text.
- * @default 12
- * @deprecated Consider using `tickLabelStyle.fontSize` instead.
- */
- tickFontSize: PropTypes.number,
/**
* Defines which ticks are displayed.
* Its value can be:
diff --git a/packages/x-charts/src/LineChart/LineChart.tsx b/packages/x-charts/src/LineChart/LineChart.tsx
index 6b36690dca8c..80fa8dc68667 100644
--- a/packages/x-charts/src/LineChart/LineChart.tsx
+++ b/packages/x-charts/src/LineChart/LineChart.tsx
@@ -373,7 +373,6 @@ LineChart.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -388,7 +387,6 @@ LineChart.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([
PropTypes.oneOf(['auto']),
PropTypes.array,
@@ -449,7 +447,6 @@ LineChart.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -464,7 +461,6 @@ LineChart.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([
PropTypes.oneOf(['auto']),
PropTypes.array,
diff --git a/packages/x-charts/src/PieChart/PieChart.tsx b/packages/x-charts/src/PieChart/PieChart.tsx
index 77bd0de044ae..4af810a6ed04 100644
--- a/packages/x-charts/src/PieChart/PieChart.tsx
+++ b/packages/x-charts/src/PieChart/PieChart.tsx
@@ -274,7 +274,6 @@ PieChart.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -289,7 +288,6 @@ PieChart.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([
PropTypes.oneOf(['auto']),
PropTypes.array,
@@ -350,7 +348,6 @@ PieChart.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -365,7 +362,6 @@ PieChart.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([
PropTypes.oneOf(['auto']),
PropTypes.array,
diff --git a/packages/x-charts/src/ScatterChart/ScatterChart.tsx b/packages/x-charts/src/ScatterChart/ScatterChart.tsx
index 3ccd27d56903..65d5e8bc460e 100644
--- a/packages/x-charts/src/ScatterChart/ScatterChart.tsx
+++ b/packages/x-charts/src/ScatterChart/ScatterChart.tsx
@@ -333,7 +333,6 @@ ScatterChart.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -348,7 +347,6 @@ ScatterChart.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([
PropTypes.oneOf(['auto']),
PropTypes.array,
@@ -409,7 +407,6 @@ ScatterChart.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -424,7 +421,6 @@ ScatterChart.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([
PropTypes.oneOf(['auto']),
PropTypes.array,
diff --git a/packages/x-charts/src/SparkLineChart/SparkLineChart.tsx b/packages/x-charts/src/SparkLineChart/SparkLineChart.tsx
index 0499352f5132..2b7024ace288 100644
--- a/packages/x-charts/src/SparkLineChart/SparkLineChart.tsx
+++ b/packages/x-charts/src/SparkLineChart/SparkLineChart.tsx
@@ -397,7 +397,6 @@ SparkLineChart.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -412,7 +411,6 @@ SparkLineChart.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
@@ -464,7 +462,6 @@ SparkLineChart.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -479,7 +476,6 @@ SparkLineChart.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
diff --git a/packages/x-charts/src/context/ChartDataProvider/ChartDataProvider.tsx b/packages/x-charts/src/context/ChartDataProvider/ChartDataProvider.tsx
index a75f2d7060b5..829f9e9ae3e7 100644
--- a/packages/x-charts/src/context/ChartDataProvider/ChartDataProvider.tsx
+++ b/packages/x-charts/src/context/ChartDataProvider/ChartDataProvider.tsx
@@ -209,7 +209,6 @@ ChartDataProvider.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -224,7 +223,6 @@ ChartDataProvider.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([
PropTypes.oneOf(['auto']),
PropTypes.array,
@@ -285,7 +283,6 @@ ChartDataProvider.propTypes = {
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
- labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -300,7 +297,6 @@ ChartDataProvider.propTypes = {
PropTypes.func,
PropTypes.object,
]),
- tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([
PropTypes.oneOf(['auto']),
PropTypes.array,
diff --git a/packages/x-charts/src/models/axis.ts b/packages/x-charts/src/models/axis.ts
index b8394900048e..3888d645d94d 100644
--- a/packages/x-charts/src/models/axis.ts
+++ b/packages/x-charts/src/models/axis.ts
@@ -86,12 +86,6 @@ export interface ChartsAxisProps extends TickParams {
* @default 'currentColor'
*/
fill?: string;
- /**
- * The font size of the axis ticks text.
- * @default 12
- * @deprecated Consider using `tickLabelStyle.fontSize` instead.
- */
- tickFontSize?: number;
/**
* The style applied to ticks text.
*/
@@ -111,12 +105,6 @@ export interface ChartsAxisProps extends TickParams {
* The label of the axis.
*/
label?: string;
- /**
- * The font size of the axis label.
- * @default 14
- * @deprecated Consider using `labelStyle.fontSize` instead.
- */
- labelFontSize?: number;
/**
* The stroke color of the axis line.
* @default 'currentColor'
diff --git a/packages/x-codemod/README.md b/packages/x-codemod/README.md
index 1537575f518e..2044b38e332e 100644
--- a/packages/x-codemod/README.md
+++ b/packages/x-codemod/README.md
@@ -136,6 +136,7 @@ The list includes these transformers
- [`rename-legend-to-slots-legend`](#rename-legend-to-slots-legend)
- [`rename-responsive-chart-container`](#rename-responsive-chart-container)
+- [`rename-label-and-tick-font-size`](#rename-label-and-tick-font-size)
#### `rename-legend-to-slots-legend`
@@ -175,6 +176,23 @@ Verify the git diff to remove the duplicate.
:::
+#### `rename-label-and-tick-font-size`
+
+Renames `labelFontSize` and `tickFontSize` props to the corresponding `xxxStyle` prop.
+
+```diff
+
+```
+
## v7.0.0
### 🚀 `preset-safe` for v7.0.0
diff --git a/packages/x-codemod/src/v8.0.0/charts/preset-safe/actual.spec.tsx b/packages/x-codemod/src/v8.0.0/charts/preset-safe/actual.spec.tsx
index 40aecf34651a..849585a97e2f 100644
--- a/packages/x-codemod/src/v8.0.0/charts/preset-safe/actual.spec.tsx
+++ b/packages/x-codemod/src/v8.0.0/charts/preset-safe/actual.spec.tsx
@@ -3,6 +3,7 @@ import * as React from 'react';
import { PieChart } from '@mui/x-charts/PieChart';
import { BarPlot } from '@mui/x-charts/BarChart';
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
+import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
// prettier-ignore
@@ -11,4 +12,17 @@ import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer
+
+
+
;
diff --git a/packages/x-codemod/src/v8.0.0/charts/preset-safe/expected.spec.tsx b/packages/x-codemod/src/v8.0.0/charts/preset-safe/expected.spec.tsx
index 6f80f49b4e3a..139cad04ca12 100644
--- a/packages/x-codemod/src/v8.0.0/charts/preset-safe/expected.spec.tsx
+++ b/packages/x-codemod/src/v8.0.0/charts/preset-safe/expected.spec.tsx
@@ -3,6 +3,7 @@ import * as React from 'react';
import { PieChart } from '@mui/x-charts/PieChart';
import { BarPlot } from '@mui/x-charts/BarChart';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
+import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
// prettier-ignore
@@ -18,4 +19,29 @@ import { ChartContainer } from '@mui/x-charts/ChartContainer';
+
+
+
;
diff --git a/packages/x-codemod/src/v8.0.0/charts/preset-safe/index.ts b/packages/x-codemod/src/v8.0.0/charts/preset-safe/index.ts
index e862d1d084a2..3fdc6150db55 100644
--- a/packages/x-codemod/src/v8.0.0/charts/preset-safe/index.ts
+++ b/packages/x-codemod/src/v8.0.0/charts/preset-safe/index.ts
@@ -1,11 +1,13 @@
import transformLegendToSlots from '../rename-legend-to-slots-legend';
import transformRemoveResponsiveContainer from '../rename-responsive-chart-container';
+import transformRenameLabelAndTickFontSize from '../rename-label-and-tick-font-size';
import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types';
export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) {
file.source = transformLegendToSlots(file, api, options);
file.source = transformRemoveResponsiveContainer(file, api, options);
+ file.source = transformRenameLabelAndTickFontSize(file, api, options);
return file.source;
}
diff --git a/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/actual.spec.tsx b/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/actual.spec.tsx
new file mode 100644
index 000000000000..0bf12b0e855d
--- /dev/null
+++ b/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/actual.spec.tsx
@@ -0,0 +1,20 @@
+// @ts-nocheck
+import * as React from 'react';
+import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
+
+// prettier-ignore
+
+
+
+
+
;
diff --git a/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/expected.spec.tsx b/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/expected.spec.tsx
new file mode 100644
index 000000000000..6ff9ea963b5d
--- /dev/null
+++ b/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/expected.spec.tsx
@@ -0,0 +1,32 @@
+// @ts-nocheck
+import * as React from 'react';
+import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
+
+// prettier-ignore
+
+
+
+
+
;
diff --git a/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/index.ts b/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/index.ts
new file mode 100644
index 000000000000..cc8380692d07
--- /dev/null
+++ b/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/index.ts
@@ -0,0 +1,92 @@
+import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types';
+import { transformNestedProp } from '../../../util/addComponentsSlots';
+/**
+ * @param {import('jscodeshift').FileInfo} file
+ * @param {import('jscodeshift').API} api
+ */
+export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) {
+ const j = api.jscodeshift;
+
+ const printOptions = options.printOptions;
+
+ const root = j(file.source);
+
+ root
+ .find(j.ImportDeclaration)
+ .filter(({ node }) => {
+ return typeof node.source.value === 'string' && node.source.value.startsWith('@mui/x-charts');
+ })
+ .forEach((path) => {
+ path.node.specifiers?.forEach((node) => {
+ root.findJSXElements(node.local?.name).forEach((elementPath) => {
+ if (elementPath.node.type !== 'JSXElement') {
+ return;
+ }
+
+ ['label', 'tick'].forEach((attributeName) => {
+ const attributeValue = elementPath.node.openingElement.attributes?.find(
+ (elementNode) =>
+ elementNode.type === 'JSXAttribute' &&
+ elementNode.name.name === `${attributeName}FontSize`,
+ );
+
+ if (!attributeValue) {
+ return;
+ }
+
+ const attributeStyle = elementPath.node.openingElement.attributes?.find(
+ (elementNode) =>
+ elementNode.type === 'JSXAttribute' &&
+ elementNode.name.name === `${attributeName}Style`,
+ );
+
+ // @ts-ignore receives an object.
+ const styleValue = attributeStyle?.value.expression.properties.find(
+ (prop) => prop.key.name === 'fontSize',
+ );
+
+ if (attributeStyle === null) {
+ // We create a new "style" object
+ elementPath.node.openingElement.attributes?.push(
+ j.jsxAttribute(
+ j.jsxIdentifier(`${attributeName}Style`),
+ j.jsxExpressionContainer(
+ j.objectExpression([
+ j.objectProperty(
+ j.identifier('fontSize'),
+ // @ts-ignore receives an object.
+ attributeValue.value.expression,
+ ),
+ ]),
+ ),
+ ),
+ );
+ } else {
+ transformNestedProp(
+ elementPath,
+ `${attributeName}Style`,
+ 'fontSize',
+ // @ts-ignore receives an object.
+ styleValue?.value ?? attributeValue.value.expression,
+ j,
+ );
+ }
+ });
+
+ // Remove the legend prop
+ j(elementPath)
+ .find(j.JSXAttribute)
+ .filter(
+ (a) => a.value.name.name === 'labelFontSize' || a.value.name.name === 'tickFontSize',
+ )
+ .forEach((pathToRemove) => {
+ j(pathToRemove).remove();
+ });
+ });
+ });
+ });
+
+ const transformed = root.findJSXElements();
+
+ return transformed.toSource(printOptions);
+}
diff --git a/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/rename-label-and-tick-font-size.test.ts b/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/rename-label-and-tick-font-size.test.ts
new file mode 100644
index 000000000000..0d3f4daddffa
--- /dev/null
+++ b/packages/x-codemod/src/v8.0.0/charts/rename-label-and-tick-font-size/rename-label-and-tick-font-size.test.ts
@@ -0,0 +1,38 @@
+import path from 'path';
+import { expect } from 'chai';
+import jscodeshift from 'jscodeshift';
+import transform from '.';
+import readFile from '../../../util/readFile';
+
+function read(fileName) {
+ return readFile(path.join(__dirname, fileName));
+}
+
+describe('v8.0.0/charts', () => {
+ describe('rename-label-and-tick-font-size.test', () => {
+ const actualPath = `./actual.spec.tsx`;
+ const expectedPath = `./expected.spec.tsx`;
+
+ it('transforms imports as needed', () => {
+ const actual = transform(
+ { source: read(actualPath) },
+ { jscodeshift: jscodeshift.withParser('tsx') },
+ {},
+ );
+
+ const expected = read(expectedPath);
+ expect(actual).to.equal(expected, 'The transformed version should be correct');
+ });
+
+ it('should be idempotent', () => {
+ const actual = transform(
+ { source: read(expectedPath) },
+ { jscodeshift: jscodeshift.withParser('tsx') },
+ {},
+ );
+
+ const expected = read(expectedPath);
+ expect(actual).to.equal(expected, 'The transformed version should be correct');
+ });
+ });
+});