Skip to content

Commit

Permalink
Merge 'master' into stablize-data-source
Browse files Browse the repository at this point in the history
  • Loading branch information
MBilalShafi committed Feb 24, 2025
1 parent c39e277 commit e82a037
Show file tree
Hide file tree
Showing 94 changed files with 2,642 additions and 739 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
import * as React from 'react';
import Box from '@mui/material/Box';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';
Expand All @@ -19,20 +18,17 @@ const defaultXAxis = {
label: 'My axis',
tickSize: 6,
};
export default function AxisCustomizationNoSnap() {
export default function AxisCustomization() {
return (
<ChartsUsageDemo
componentName="Alert"
data={[
{ propName: 'disableLine', knob: 'switch', defaultValue: false },
{ propName: 'disableTicks', knob: 'switch', defaultValue: false },
{ propName: 'label', knob: 'input', defaultValue: 'my axis' },
{ propName: 'tickSize', knob: 'number', defaultValue: 6 },
]}
renderDemo={(
/** @type {{ disableLine: boolean; disableTicks: boolean; label: string; tickSize: number; }} */
props,
) => (
data={{
disableLine: { knob: 'switch', defaultValue: false },
disableTicks: { knob: 'switch', defaultValue: false },
label: { knob: 'input', defaultValue: 'my axis' },
tickSize: { knob: 'number', defaultValue: 6 },
}}
renderDemo={(props) => (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<ScatterChart
series={[
Expand All @@ -53,10 +49,9 @@ export default function AxisCustomizationNoSnap() {
/>
</Box>
)}
getCode={(
/** @type {{props: { disableLine: boolean; disableTicks: boolean; label: string; tickSize: number; }}} */
{ props },
) => `import { ScatterChart } from '@mui/x-charts/ScatterChart';
getCode={({
props,
}) => `import { ScatterChart } from '@mui/x-charts/ScatterChart';
<ScatterChart
// ...
Expand Down
68 changes: 68 additions & 0 deletions docs/data/charts/axis/AxisCustomization.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { Chance } from 'chance';

const chance = new Chance(42);

const data = Array.from({ length: 200 }, () => ({
x: chance.floating({ min: -25, max: 25 }),
y: chance.floating({ min: -25, max: 25 }),
})).map((d, index) => ({ ...d, id: index }));

const defaultXAxis = {
disableLine: false,
disableTicks: false,
fontSize: 12,
label: 'My axis',
tickSize: 6,
};
export default function AxisCustomization() {
return (
<ChartsUsageDemo
componentName="Alert"
data={{
disableLine: { knob: 'switch', defaultValue: false },
disableTicks: { knob: 'switch', defaultValue: false },
label: { knob: 'input', defaultValue: 'my axis' },
tickSize: { knob: 'number', defaultValue: 6 },
}}
renderDemo={(props) => (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<ScatterChart
series={[
{
type: 'scatter',
id: 'linear',
data,
},
]}
yAxis={[{ position: 'none' }]}
xAxis={[
{
...defaultXAxis,
...props,
},
]}
height={300}
/>
</Box>
)}
getCode={({
props,
}) => `import { ScatterChart } from '@mui/x-charts/ScatterChart';
<ScatterChart
// ...
xAxis={{
disableLine: ${props.disableLine},
disableTicks: ${props.disableTicks},
label: "${props.label}",
tickSize: ${props.tickSize},
}}
/>
`}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
import * as React from 'react';
import Box from '@mui/material/Box';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';
Expand All @@ -9,25 +8,21 @@ const chartSetting = {
height: 300,
};

export default function AxisTextCustomizationNoSnap() {
export default function AxisTextCustomization() {
return (
<ChartsUsageDemo
componentName="Alert"
data={[
{ propName: 'angle', knob: 'number', defaultValue: 45, min: -180, max: 180 },
{
propName: 'textAnchor',
data={{
angle: { knob: 'number', defaultValue: 45, min: -180, max: 180 },
textAnchor: {
knob: 'select',
defaultValue: 'start',
options: ['start', 'middle', 'end'],
},
{ propName: 'fontSize', knob: 'number', defaultValue: 12 },
{ propName: 'labelFontSize', knob: 'number', defaultValue: 14 },
]}
renderDemo={(
/** @type {{ labelFontSize: number; angle: number; textAnchor: 'start'| 'middle'| 'end'; fontSize: number; }} */
props,
) => (
fontSize: { knob: 'number', defaultValue: 12 },
labelFontSize: { knob: 'number', defaultValue: 14 },
}}
renderDemo={(props) => (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<BarChart
dataset={dataset}
Expand Down Expand Up @@ -59,10 +54,7 @@ export default function AxisTextCustomizationNoSnap() {
/>
</Box>
)}
getCode={(
/** @type {{props: { labelFontSize: number; angle: number; textAnchor: 'start'| 'middle'| 'end'; fontSize: number; }}} */
{ props },
) => `import { BarChart } from '@mui/x-charts/BarChart';
getCode={({ props }) => `import { BarChart } from '@mui/x-charts/BarChart';
<ScatterChart
// ...
Expand Down
78 changes: 78 additions & 0 deletions docs/data/charts/axis/AxisTextCustomization.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';
import { BarChart } from '@mui/x-charts/BarChart';
import { dataset, valueFormatter } from '../dataset/weather';

const chartSetting = {
height: 300,
};

export default function AxisTextCustomization() {
return (
<ChartsUsageDemo
componentName="Alert"
data={
{
angle: { knob: 'number', defaultValue: 45, min: -180, max: 180 },
textAnchor: {
knob: 'select',
defaultValue: 'start',
options: ['start', 'middle', 'end'],
},
fontSize: { knob: 'number', defaultValue: 12 },
labelFontSize: { knob: 'number', defaultValue: 14 },
} as const
}
renderDemo={(props) => (
<Box sx={{ width: '100%', maxWidth: 400 }}>
<BarChart
dataset={dataset}
xAxis={[
{
scaleType: 'band',
dataKey: 'month',
label: 'months',
height: 40,
labelStyle: {
fontSize: props.labelFontSize,
transform: `translateY(10px)`,
},
tickLabelStyle: {
angle: props.angle,
textAnchor: props.textAnchor,
fontSize: props.fontSize,
},
},
]}
series={[
{ dataKey: 'london', label: 'London', valueFormatter },
{ dataKey: 'paris', label: 'Paris', valueFormatter },
{ dataKey: 'newYork', label: 'New York', valueFormatter },
{ dataKey: 'seoul', label: 'Seoul', valueFormatter },
]}
margin={{ bottom: 30 }}
{...chartSetting}
/>
</Box>
)}
getCode={({ props }) => `import { BarChart } from '@mui/x-charts/BarChart';
<ScatterChart
// ...
xAxis={[
{
labelStyle: {
fontSize: ${props.labelFontSize},
},
tickLabelStyle: {
angle: ${props.angle},
textAnchor: '${props.textAnchor}',
fontSize: ${props.fontSize},
},
},
]}
/>`}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const dataset = [

const valueFormatter = (value) => `${value}mm`;

export default function FormatterDemoNoSnap() {
export default function FormatterDemo() {
return (
<BarChart
dataset={dataset}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const dataset = [

const valueFormatter = (value: number | null) => `${value}mm`;

export default function FormatterDemoNoSnap() {
export default function FormatterDemo() {
return (
<BarChart
dataset={dataset}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const series = [
{ type: 'bar', dataKey: 'precip', color: '#bfdbf7', yAxisId: 'rightAxis' },
];

export default function ReverseExampleNoSnap() {
export default function ReverseExample() {
const [reverseX, setReverseX] = React.useState(false);
const [reverseLeft, setReverseLeft] = React.useState(false);
const [reverseRight, setReverseRight] = React.useState(false);
Expand Down Expand Up @@ -88,9 +88,8 @@ export default function ReverseExampleNoSnap() {
<BarPlot />
<LinePlot />
<MarkPlot />

<ChartsXAxis />
<ChartsYAxis axisId="leftAxis" label="temerature (°C)" />
<ChartsYAxis axisId="leftAxis" label="temperature (°C)" />
<ChartsYAxis axisId="rightAxis" label="precipitation (mm)" />
<ChartsTooltip />
</ChartContainer>
Expand Down
100 changes: 100 additions & 0 deletions docs/data/charts/axis/ReverseExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import FormControlLabel from '@mui/material/FormControlLabel';
import Checkbox from '@mui/material/Checkbox';

import { ChartContainer } from '@mui/x-charts/ChartContainer';
import { LinePlot, MarkPlot } from '@mui/x-charts/LineChart';
import { BarPlot } from '@mui/x-charts/BarChart';
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';
import { ChartsGrid } from '@mui/x-charts/ChartsGrid';
import { ChartsTooltip } from '@mui/x-charts/ChartsTooltip';

const dataset = [
{ min: -12, max: -4, precip: 79, month: 'Jan' },
{ min: -11, max: -3, precip: 66, month: 'Feb' },
{ min: -6, max: 2, precip: 76, month: 'Mar' },
{ min: 1, max: 9, precip: 106, month: 'Apr' },
{ min: 8, max: 17, precip: 105, month: 'Mai' },
{ min: 15, max: 24, precip: 114, month: 'Jun' },
{ min: 18, max: 26, precip: 106, month: 'Jul' },
{ min: 17, max: 26, precip: 105, month: 'Aug' },
{ min: 13, max: 21, precip: 100, month: 'Sept' },
{ min: 6, max: 13, precip: 116, month: 'Oct' },
{ min: 0, max: 6, precip: 93, month: 'Nov' },
{ min: -8, max: -1, precip: 93, month: 'Dec' },
];

const series = [
{ type: 'line', dataKey: 'min', color: '#577399' },
{ type: 'line', dataKey: 'max', color: '#fe5f55' },
{ type: 'bar', dataKey: 'precip', color: '#bfdbf7', yAxisId: 'rightAxis' },
] as const;

export default function ReverseExample() {
const [reverseX, setReverseX] = React.useState(false);
const [reverseLeft, setReverseLeft] = React.useState(false);
const [reverseRight, setReverseRight] = React.useState(false);

return (
<Stack sx={{ width: '100%' }}>
<Stack direction="row">
<FormControlLabel
checked={reverseX}
control={
<Checkbox onChange={(event) => setReverseX(event.target.checked)} />
}
label="reverse x-axis"
labelPlacement="end"
/>
<FormControlLabel
checked={reverseLeft}
control={
<Checkbox onChange={(event) => setReverseLeft(event.target.checked)} />
}
label="reverse left axis"
labelPlacement="end"
/>
<FormControlLabel
checked={reverseRight}
control={
<Checkbox onChange={(event) => setReverseRight(event.target.checked)} />
}
label="reverse right axis"
labelPlacement="end"
/>
</Stack>
<Box sx={{ width: '100%' }}>
<ChartContainer
series={series}
xAxis={[
{
scaleType: 'band',
dataKey: 'month',
label: 'Month',
reverse: reverseX,
},
]}
yAxis={[
{ id: 'leftAxis', reverse: reverseLeft },
{ id: 'rightAxis', reverse: reverseRight, position: 'right' },
]}
dataset={dataset}
height={400}
>
<ChartsGrid horizontal />
<BarPlot />
<LinePlot />
<MarkPlot />

<ChartsXAxis />
<ChartsYAxis axisId="leftAxis" label="temperature (°C)" />
<ChartsYAxis axisId="rightAxis" label="precipitation (mm)" />
<ChartsTooltip />
</ChartContainer>
</Box>
</Stack>
);
}
Loading

0 comments on commit e82a037

Please sign in to comment.