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] Add Gauge component #11996

Merged
merged 22 commits into from
Feb 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.link-check-errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Broken links found by `yarn docs:link-check` that exist:
- https://mui.com/system/styles/api/#serverstylesheets
- https://mui.com/system/styles/api/#stylesprovider
- https://mui.com/system/styles/api/#themeprovider
- https://mui.com/x/api/charts/gauge/#classes
- https://mui.com/x/api/data-grid/data-grid/#DataGrid-prop-filterDebounceMs
- https://mui.com/x/api/data-grid/data-grid/#props
- https://mui.com/x/api/data-grid/data-grid/#slots
Expand Down
8 changes: 8 additions & 0 deletions docs/data/charts-component-api-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ const apiPages: MuiPage[] = [
pathname: '/x/api/charts/default-charts-legend',
title: 'DefaultChartsLegend',
},
{
pathname: '/x/api/charts/gauge',
title: 'Gauge',
},
{
pathname: '/x/api/charts/gauge-container',
title: 'GaugeContainer',
},
{
pathname: '/x/api/charts/line-chart',
title: 'LineChart',
Expand Down
28 changes: 28 additions & 0 deletions docs/data/charts/gauge/ArcDesign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { Gauge, gaugeClasses } from '@mui/x-charts/Gauge';

const settings = {
width: 200,
height: 200,
value: 60,
};

export default function ArcDesign() {
return (
<Gauge
{...settings}
cornerRadius="50%"
sx={(theme) => ({
[`& .${gaugeClasses.valueText}`]: {
fontSize: 40,
},
[`& .${gaugeClasses.valueArc}`]: {
fill: '#52b202',
},
[`& .${gaugeClasses.referenceArc}`]: {
fill: theme.palette.text.disabled,
},
})}
/>
);
}
28 changes: 28 additions & 0 deletions docs/data/charts/gauge/ArcDesign.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { Gauge, gaugeClasses } from '@mui/x-charts/Gauge';

const settings = {
width: 200,
height: 200,
value: 60,
};

export default function ArcDesign() {
return (
<Gauge
{...settings}
cornerRadius="50%"
sx={(theme) => ({
[`& .${gaugeClasses.valueText}`]: {
fontSize: 40,
},
[`& .${gaugeClasses.valueArc}`]: {
fill: '#52b202',
},
[`& .${gaugeClasses.referenceArc}`]: {
fill: theme.palette.text.disabled,
},
})}
/>
);
}
15 changes: 15 additions & 0 deletions docs/data/charts/gauge/ArcDesign.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Gauge
{...settings}
cornerRadius="50%"
sx={(theme) => ({
[`& .${gaugeClasses.valueText}`]: {
fontSize: 40,
},
[`& .${gaugeClasses.valueArc}`]: {
fill: '#52b202',
},
[`& .${gaugeClasses.referenceArc}`]: {
fill: theme.palette.text.disabled,
},
})}
/>
90 changes: 90 additions & 0 deletions docs/data/charts/gauge/ArcPlaygroundNoSnap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as React from 'react';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';
import Paper from '@mui/material/Paper';
import { Gauge, gaugeClasses } from '@mui/x-charts/Gauge';

export default function ArcPlaygroundNoSnap() {
return (
<ChartsUsageDemo
componentName="Gauge"
data={[
{
propName: `value`,
knob: 'number',
defaultValue: 75,
step: 1,
min: 0,
max: 100,
},
{
propName: `startAngle`,
knob: 'number',
defaultValue: 0,
step: 1,
min: -360,
max: 360,
},
{
propName: `endAngle`,
knob: 'number',
defaultValue: 360,
step: 1,
min: -360,
max: 360,
},
{
propName: `innerRadius`,
knob: 'number',
defaultValue: 80,
step: 1,
min: 0,
max: 100,
},
{
propName: `outerRadius`,
knob: 'number',
defaultValue: 100,
step: 1,
min: 0,
max: 100,
},
]}
renderDemo={(props) => (
<Paper
sx={{
width: 200,
height: 200,
margin: 'auto',
}}
>
<Gauge
sx={{
[`& .${gaugeClasses.valueText}`]: {
fontSize: 45,
},
}}
{...props}
innerRadius={`${props.innerRadius}%`}
outerRadius={`${props.outerRadius}%`}
/>
</Paper>
)}
getCode={({ props }) => {
const { innerRadius, outerRadius, ...numberProps } = props;
return [
`import { Gauge } from '@mui/x-charts/Gauge';`,
'',
`<Gauge`,
` // ...`,
...Object.entries(numberProps).map(
([name, value]) => ` ${name}={${value}}`,
),
...Object.entries({ innerRadius, outerRadius }).map(
([name, value]) => ` ${name}="${value}%"`,
),
'/>',
].join('\n');
}}
/>
);
}
12 changes: 12 additions & 0 deletions docs/data/charts/gauge/BasicGauges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { Gauge } from '@mui/x-charts/Gauge';

export default function BasicGauges() {
return (
<Stack direction={{ xs: 'column', md: 'row' }} spacing={{ xs: 1, md: 3 }}>
<Gauge width={100} height={100} value={60} />
<Gauge width={100} height={100} value={60} startAngle={-90} endAngle={90} />
</Stack>
);
}
12 changes: 12 additions & 0 deletions docs/data/charts/gauge/BasicGauges.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { Gauge } from '@mui/x-charts/Gauge';

export default function BasicGauges() {
return (
<Stack direction={{ xs: 'column', md: 'row' }} spacing={{ xs: 1, md: 3 }}>
<Gauge width={100} height={100} value={60} />
<Gauge width={100} height={100} value={60} startAngle={-90} endAngle={90} />
</Stack>
);
}
2 changes: 2 additions & 0 deletions docs/data/charts/gauge/BasicGauges.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Gauge width={100} height={100} value={60} />
<Gauge width={100} height={100} value={60} startAngle={-90} endAngle={90} />
47 changes: 47 additions & 0 deletions docs/data/charts/gauge/CompositionExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import {
GaugeContainer,
GaugeValueArc,
GaugeReferenceArc,
useGaugeState,
} from '@mui/x-charts/Gauge';

function GaugePointer() {
const { valueAngle, outerRadius, cx, cy } = useGaugeState();

if (valueAngle === null) {
// No value to display
return null;
}

const target = {
x: cx + outerRadius * Math.sin(valueAngle),
y: cy - outerRadius * Math.cos(valueAngle),
};
return (
<g>
<circle cx={cx} cy={cy} r={5} fill="red" />
<path
d={`M ${cx} ${cy} L ${target.x} ${target.y}`}
stroke="red"
strokeWidth={3}
/>
</g>
);
}

export default function CompositionExample() {
return (
<GaugeContainer
width={200}
height={200}
startAngle={-110}
endAngle={110}
value={30}
>
<GaugeReferenceArc />
<GaugeValueArc />
<GaugePointer />
</GaugeContainer>
);
}
47 changes: 47 additions & 0 deletions docs/data/charts/gauge/CompositionExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import {
GaugeContainer,
GaugeValueArc,
GaugeReferenceArc,
useGaugeState,
} from '@mui/x-charts/Gauge';

function GaugePointer() {
const { valueAngle, outerRadius, cx, cy } = useGaugeState();

if (valueAngle === null) {
// No value to display
return null;
}

const target = {
x: cx + outerRadius * Math.sin(valueAngle),
y: cy - outerRadius * Math.cos(valueAngle),
};
return (
<g>
<circle cx={cx} cy={cy} r={5} fill="red" />
<path
d={`M ${cx} ${cy} L ${target.x} ${target.y}`}
stroke="red"
strokeWidth={3}
/>
</g>
);
}

export default function CompositionExample() {
return (
<GaugeContainer
width={200}
height={200}
startAngle={-110}
endAngle={110}
value={30}
>
<GaugeReferenceArc />
<GaugeValueArc />
<GaugePointer />
</GaugeContainer>
);
}
11 changes: 11 additions & 0 deletions docs/data/charts/gauge/CompositionExample.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<GaugeContainer
width={200}
height={200}
startAngle={-110}
endAngle={110}
value={30}
>
<GaugeReferenceArc />
<GaugeValueArc />
<GaugePointer />
</GaugeContainer>
12 changes: 12 additions & 0 deletions docs/data/charts/gauge/GaugeValueRangeNoSnap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { Gauge } from '@mui/x-charts/Gauge';

export default function GaugeValueRangeNoSnap() {
return (
<Stack direction={{ xs: 'column', md: 'row' }} spacing={{ xs: 1, md: 3 }}>
<Gauge width={100} height={100} value={50} />
<Gauge width={100} height={100} value={50} valueMin={10} valueMax={60} />
</Stack>
);
}
12 changes: 12 additions & 0 deletions docs/data/charts/gauge/GaugeValueRangeNoSnap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { Gauge } from '@mui/x-charts/Gauge';

export default function GaugeValueRangeNoSnap() {
return (
<Stack direction={{ xs: 'column', md: 'row' }} spacing={{ xs: 1, md: 3 }}>
<Gauge width={100} height={100} value={50} />
<Gauge width={100} height={100} value={50} valueMin={10} valueMax={60} />
</Stack>
);
}
2 changes: 2 additions & 0 deletions docs/data/charts/gauge/GaugeValueRangeNoSnap.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Gauge width={100} height={100} value={50} />
<Gauge width={100} height={100} value={50} valueMin={10} valueMax={60} />
Loading
Loading