-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[charts] Add Gauge component (#11996)
Signed-off-by: Alexandre Fauquette <[email protected]> Co-authored-by: Danilo Leal <[email protected]> Co-authored-by: Lukas <[email protected]>
- Loading branch information
1 parent
a534543
commit d246a1f
Showing
41 changed files
with
1,780 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
})} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
})} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
})} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> |
Oops, something went wrong.