-
Notifications
You must be signed in to change notification settings - Fork 3
/
BulletGauge.tsx
85 lines (81 loc) · 2.03 KB
/
BulletGauge.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { BulletGaugeProps } from "./BulletGauge.types";
import Plotly from "react-plotly.js";
import React from "react";
import { useTheme } from "@mui/material";
/**
* This component displays a bullet gauge progress indicator.
*/
const BulletGauge = ({ title, value, suffix }: BulletGaugeProps) => {
// theme hook
const theme = useTheme();
// Limit value to 100
const limitedValue = Math.min(value, 100);
return (
<Plotly
data={[
{
domain: { x: [0, 1], y: [0, 1] },
gauge: {
axis: {
range: [null, 100],
tickfont: {
color: theme.palette.mode === "light" ? "black" : "white",
size: 12
}
},
bar: {
color:
limitedValue < 30
? theme.palette.error.main
: value > 70
? theme.palette.success.main
: theme.palette.warning.main
},
shape: "bullet"
},
mode: "gauge+number",
number: {
font: {
color: theme.palette.mode === "light" ? "black" : "white",
size: 20
},
suffix: suffix || ""
},
type: "indicator",
value: limitedValue
}
]}
layout={{
font: {
family: "Montserrat, sans-serif",
size: 16
},
height: 80,
margin: { b: 25, l: 8, r: 0, t: 25 },
paper_bgcolor: "rgba(0,0,0,0)",
plot_bgcolor: "rgba(0,0,0,0)",
title: {
font: {
color:
theme.palette.mode === "light" ? "rgba(0, 0, 0, 0.54)" : "white",
size: 12
},
pad: {
l: 8,
t: 3
},
text: title,
x: 0,
xanchor: "left",
y: 1,
yanchor: "top"
},
width: 300
}}
config={{
displayModeBar: false
}}
/>
);
};
export default BulletGauge;