- Move styles to theme
- Use different color for above and below 50%
This commit is contained in:
1 parent
09ba21245c
commit
5e54f5c757
3 files changed
+42
-27
No files matched your search
@@ -2,30 +2,17 @@ import React from "react";
|
|||||||
import { RadialBarChart, RadialBar, ResponsiveContainer } from "recharts";
|
import { RadialBarChart, RadialBar, ResponsiveContainer } from "recharts";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const data = [{ value: 100 }];
|
||||||
|
const commonRadialBarProps = {
|
||||||
|
minAngle: 15,
|
||||||
|
clockWise: true,
|
||||||
|
dataKey: "value",
|
||||||
|
cornerRadius: 0
|
||||||
|
};
|
||||||
|
|
||||||
const Gauge = ({ progressValue, displayText, theme }) => {
|
const Gauge = ({ progressValue, displayText, theme }) => {
|
||||||
const BASE_TEXT_STYLE = {
|
|
||||||
textAnchor: "middle",
|
|
||||||
dominantBaseline: "middle",
|
|
||||||
};
|
|
||||||
const getStyles = (theme) => ({
|
|
||||||
text: {
|
|
||||||
...BASE_TEXT_STYLE,
|
|
||||||
style: { fontSize: "11px", fontWeight: 400, fill: theme.palette.text.tertiary
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const data = [{ value: 100 }];
|
|
||||||
const commonRadialBarProps = {
|
|
||||||
minAngle: 15,
|
|
||||||
clockWise: true,
|
|
||||||
dataKey: "value",
|
|
||||||
cornerRadius: 0
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<ResponsiveContainer
|
<ResponsiveContainer>
|
||||||
width="100%"
|
|
||||||
height={150}
|
|
||||||
>
|
|
||||||
<RadialBarChart
|
<RadialBarChart
|
||||||
cx="50%"
|
cx="50%"
|
||||||
cy="50%"
|
cy="50%"
|
||||||
@@ -37,8 +24,12 @@ const Gauge = ({ progressValue, displayText, theme }) => {
|
|||||||
>
|
>
|
||||||
<RadialBar
|
<RadialBar
|
||||||
{...commonRadialBarProps}
|
{...commonRadialBarProps}
|
||||||
fill="#1570EF"
|
fill={
|
||||||
background={{ fill: "#CDE2FF" }}
|
progressValue > 50
|
||||||
|
? theme.palette.primary.main
|
||||||
|
: theme.palette.percentage.uptimePoor
|
||||||
|
}
|
||||||
|
background={{ fill: theme.palette.background.fill }}
|
||||||
data={[{ value: progressValue }]}
|
data={[{ value: progressValue }]}
|
||||||
/>
|
/>
|
||||||
<RadialBar
|
<RadialBar
|
||||||
@@ -54,15 +45,14 @@ const Gauge = ({ progressValue, displayText, theme }) => {
|
|||||||
<text
|
<text
|
||||||
x="50%"
|
x="50%"
|
||||||
y="45%"
|
y="45%"
|
||||||
{...getStyles(theme).text}
|
style={theme.palette.gaugePercentageText}
|
||||||
>
|
>
|
||||||
{`${progressValue}%`}
|
{`${progressValue}%`}
|
||||||
</text>
|
</text>
|
||||||
<text
|
<text
|
||||||
x="50%"
|
x="50%"
|
||||||
y="55%"
|
y="55%"
|
||||||
{...getStyles(theme).text}
|
style={theme.palette.gaugeDisplayText}
|
||||||
style={{fontSize: 9 }}
|
|
||||||
>
|
>
|
||||||
{`${displayText}`}
|
{`${displayText}`}
|
||||||
</text>
|
</text>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { createTheme } from "@mui/material";
|
import { createTheme } from "@mui/material";
|
||||||
|
import { gaugeText } from "./lightTheme"
|
||||||
|
|
||||||
const text = {
|
const text = {
|
||||||
primary: "#fafafa",
|
primary: "#fafafa",
|
||||||
@@ -34,6 +35,14 @@ const darkTheme = createTheme({
|
|||||||
primary: { main: "#1570ef" },
|
primary: { main: "#1570ef" },
|
||||||
secondary: { main: "#2D2D33" },
|
secondary: { main: "#2D2D33" },
|
||||||
text: text,
|
text: text,
|
||||||
|
gaugePercentageText: {
|
||||||
|
...gaugeText,
|
||||||
|
fontSize: "11px"
|
||||||
|
},
|
||||||
|
gaugeDisplayText: {
|
||||||
|
...gaugeText,
|
||||||
|
fontSize: "9px"
|
||||||
|
},
|
||||||
background: background,
|
background: background,
|
||||||
border: border,
|
border: border,
|
||||||
info: {
|
info: {
|
||||||
|
|||||||
@@ -12,6 +12,14 @@ const background = {
|
|||||||
fill: "#F4F4F4",
|
fill: "#F4F4F4",
|
||||||
accent: "#f9fafb",
|
accent: "#f9fafb",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const gaugeText = {
|
||||||
|
fontWeight: 400,
|
||||||
|
fill: text.tertiary,
|
||||||
|
textAnchor: "middle",
|
||||||
|
dominantBaseline: "middle",
|
||||||
|
}
|
||||||
|
|
||||||
const border = { light: "#eaecf0", dark: "#d0d5dd" };
|
const border = { light: "#eaecf0", dark: "#d0d5dd" };
|
||||||
|
|
||||||
const fontFamilyDefault =
|
const fontFamilyDefault =
|
||||||
@@ -32,6 +40,14 @@ const lightTheme = createTheme({
|
|||||||
primary: { main: "#1570EF" },
|
primary: { main: "#1570EF" },
|
||||||
secondary: { main: "#F4F4F4", dark: "#e3e3e3", contrastText: "#475467" },
|
secondary: { main: "#F4F4F4", dark: "#e3e3e3", contrastText: "#475467" },
|
||||||
text: text,
|
text: text,
|
||||||
|
gaugePercentageText: {
|
||||||
|
...gaugeText,
|
||||||
|
fontSize: "11px"
|
||||||
|
},
|
||||||
|
gaugeDisplayText: {
|
||||||
|
...gaugeText,
|
||||||
|
fontSize: "9px"
|
||||||
|
},
|
||||||
background: background,
|
background: background,
|
||||||
border: border,
|
border: border,
|
||||||
info: {
|
info: {
|
||||||
|
|||||||
Reference in new issue
Block a user