Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[charts] Do not document the usage of DEFAULT_X_AXIS_KEY and DEFAULT_Y_AXIS_KEY #12780

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/data/charts/axis/AxisCustomizationNoSnap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';
import { DEFAULT_X_AXIS_KEY } from '@mui/x-charts/constants';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { Chance } from 'chance';

Expand Down Expand Up @@ -41,7 +40,6 @@ export default function AxisCustomizationNoSnap() {
]}
leftAxis={null}
bottomAxis={{
axisId: DEFAULT_X_AXIS_KEY,
...defaultXAxis,
...props,
}}
Expand Down
5 changes: 2 additions & 3 deletions docs/data/charts/axis/ModifyAxisPosition.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '@mui/x-charts/constants';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { Chance } from 'chance';

Expand All @@ -22,8 +21,8 @@ export default function ModifyAxisPosition() {
{...params}
leftAxis={null}
bottomAxis={null}
topAxis={DEFAULT_X_AXIS_KEY}
rightAxis={DEFAULT_Y_AXIS_KEY}
topAxis={{}}
rightAxis={{}}
margin={{ top: 30, bottom: 10 }}
/>
</Box>
Expand Down
5 changes: 2 additions & 3 deletions docs/data/charts/axis/ModifyAxisPosition.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '@mui/x-charts/constants';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { Chance } from 'chance';

Expand All @@ -22,8 +21,8 @@ export default function ModifyAxisPosition() {
{...params}
leftAxis={null}
bottomAxis={null}
topAxis={DEFAULT_X_AXIS_KEY}
rightAxis={DEFAULT_Y_AXIS_KEY}
topAxis={{}}
rightAxis={{}}
margin={{ top: 30, bottom: 10 }}
/>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/axis/ModifyAxisPosition.tsx.preview
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{...params}
leftAxis={null}
bottomAxis={null}
topAxis={DEFAULT_X_AXIS_KEY}
rightAxis={DEFAULT_Y_AXIS_KEY}
topAxis={{}}
rightAxis={{}}
margin={{ top: 30, bottom: 10 }}
/>
4 changes: 3 additions & 1 deletion docs/data/charts/axis/axis.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ Those pros can accept three type of value:

- `null` to not display the axis
- `string` which should correspond to the id of a `xAxis` for top and bottom. Or to the id of a `yAxis` for left and right.
- `object` which will be passed as props to `<XAxis />` or `<YAxis />`. It allows to specify which axis should be represent, and to customize the design of the axis.
- `object` which will be passed as props to `<XAxis />` or `<YAxis />`. It allows to specify which axis should be represent with the `axisId` property, and to customize the design of the axis.

The demo below uses `leftAxis={null}` to remove the left axis, and `rightAxis={{}}` to set a right axis without overriding the default y-axis configuration.

{{"demo": "ModifyAxisPosition.js"}}

Expand Down
7 changes: 3 additions & 4 deletions docs/data/charts/styling/MarginNoSnap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';
import { BarChart } from '@mui/x-charts/BarChart';
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '@mui/x-charts/constants';

const data = ['left', 'right', 'top', 'bottom'].map((propName) => ({
propName,
Expand Down Expand Up @@ -29,13 +28,13 @@ export default function MarginNoSnap() {
}}
xAxis={[
{
id: DEFAULT_X_AXIS_KEY,
id: 'x-axis',
scaleType: 'band',
data: ['Page 1', 'Page 2', 'Page 3'],
},
]}
topAxis={DEFAULT_X_AXIS_KEY}
rightAxis={DEFAULT_Y_AXIS_KEY}
topAxis="x-axis"
rightAxis={{}}
/>
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions docs/translations/api-docs/charts/bar-chart/bar-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
"description": "The width of the chart in px. If not defined, it takes the width of the parent element."
},
"xAxis": {
"description": "The configuration of the x-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_X_AXIS_KEY</code>."
"description": "The configuration of the x-axes. If not provided, a default axis config is used."
},
"yAxis": {
"description": "The configuration of the y-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_Y_AXIS_KEY</code>."
"description": "The configuration of the y-axes. If not provided, a default axis config is used."
}
},
"classDescriptions": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
},
"width": { "description": "The width of the chart in px." },
"xAxis": {
"description": "The configuration of the x-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_X_AXIS_KEY</code>."
"description": "The configuration of the x-axes. If not provided, a default axis config is used."
},
"yAxis": {
"description": "The configuration of the y-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_Y_AXIS_KEY</code>."
"description": "The configuration of the y-axes. If not provided, a default axis config is used."
}
},
"classDescriptions": {}
Expand Down
4 changes: 2 additions & 2 deletions docs/translations/api-docs/charts/line-chart/line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"description": "The width of the chart in px. If not defined, it takes the width of the parent element."
},
"xAxis": {
"description": "The configuration of the x-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_X_AXIS_KEY</code>."
"description": "The configuration of the x-axes. If not provided, a default axis config is used."
},
"yAxis": {
"description": "The configuration of the y-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_Y_AXIS_KEY</code>."
"description": "The configuration of the y-axes. If not provided, a default axis config is used."
}
},
"classDescriptions": {},
Expand Down
4 changes: 2 additions & 2 deletions docs/translations/api-docs/charts/pie-chart/pie-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"description": "The width of the chart in px. If not defined, it takes the width of the parent element."
},
"xAxis": {
"description": "The configuration of the x-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_X_AXIS_KEY</code>."
"description": "The configuration of the x-axes. If not provided, a default axis config is used."
},
"yAxis": {
"description": "The configuration of the y-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_Y_AXIS_KEY</code>."
"description": "The configuration of the y-axes. If not provided, a default axis config is used."
}
},
"classDescriptions": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"description": "The width of the chart in px. If not defined, it takes the width of the parent element."
},
"xAxis": {
"description": "The configuration of the x-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_X_AXIS_KEY</code>."
"description": "The configuration of the x-axes. If not provided, a default axis config is used."
},
"yAxis": {
"description": "The configuration of the y-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_Y_AXIS_KEY</code>."
"description": "The configuration of the y-axes. If not provided, a default axis config is used."
}
},
"classDescriptions": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
"description": "The width of the chart in px. If not defined, it takes the width of the parent element."
},
"xAxis": {
"description": "The configuration of the x-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_X_AXIS_KEY</code>."
"description": "The configuration of the x-axes. If not provided, a default axis config is used."
},
"yAxis": {
"description": "The configuration of the y-axes. If not provided, a default axis config is used with id set to <code>DEFAULT_Y_AXIS_KEY</code>."
"description": "The configuration of the y-axes. If not provided, a default axis config is used."
}
},
"classDescriptions": {},
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ BarChart.propTypes = {
width: PropTypes.number,
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
xAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down Expand Up @@ -555,7 +555,7 @@ BarChart.propTypes = {
),
/**
* The configuration of the y-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
yAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/ChartContainer/ChartContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ ChartContainer.propTypes = {
width: PropTypes.number.isRequired,
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
xAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down Expand Up @@ -206,7 +206,7 @@ ChartContainer.propTypes = {
),
/**
* The configuration of the y-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
yAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
7 changes: 4 additions & 3 deletions packages/x-charts/src/ChartsAxis/ChartsAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ export interface ChartsAxisProps {

const getAxisId = (
propsValue: undefined | null | string | ChartsXAxisProps | ChartsYAxisProps,
defaultAxisId?: string,
): AxisId | null => {
if (propsValue == null) {
return null;
}
if (typeof propsValue === 'object') {
return propsValue.axisId ?? null;
return propsValue.axisId ?? defaultAxisId ?? null;
}
return propsValue;
};
Expand Down Expand Up @@ -92,8 +93,8 @@ function ChartsAxis(props: ChartsAxisProps) {

const leftId = getAxisId(leftAxis === undefined ? yAxisIds[0] : leftAxis);
const bottomId = getAxisId(bottomAxis === undefined ? xAxisIds[0] : bottomAxis);
const topId = getAxisId(topAxis);
const rightId = getAxisId(rightAxis);
const topId = getAxisId(topAxis, xAxisIds[0]);
const rightId = getAxisId(rightAxis, yAxisIds[0]);

if (topId !== null && !xAxis[topId]) {
throw Error(
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ LineChart.propTypes = {
width: PropTypes.number,
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
xAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down Expand Up @@ -589,7 +589,7 @@ LineChart.propTypes = {
),
/**
* The configuration of the y-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
yAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/PieChart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ PieChart.propTypes = {
width: PropTypes.number,
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
xAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down Expand Up @@ -520,7 +520,7 @@ PieChart.propTypes = {
),
/**
* The configuration of the y-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
yAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ResponsiveChartContainer.propTypes = {
width: PropTypes.number,
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
xAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down Expand Up @@ -184,7 +184,7 @@ ResponsiveChartContainer.propTypes = {
),
/**
* The configuration of the y-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
yAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/ScatterChart/ScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ ScatterChart.propTypes = {
width: PropTypes.number,
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
xAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down Expand Up @@ -515,7 +515,7 @@ ScatterChart.propTypes = {
),
/**
* The configuration of the y-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
yAxis: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/context/CartesianContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import { getColorScale, getOrdinalColorScale } from '../internals/colorScale';
export type CartesianContextProviderProps = {
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
xAxis?: MakeOptional<AxisConfig, 'id'>[];
/**
* The configuration of the y-axes.
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
* If not provided, a default axis config is used.
*/
yAxis?: MakeOptional<AxisConfig, 'id'>[];
/**
Expand Down