Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/components/ThreatGauge.jsx
Browse files- frontend/src/components/ThreatGauge.jsx +101 -103
frontend/src/components/ThreatGauge.jsx
CHANGED
|
@@ -1,103 +1,101 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
const
|
| 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 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
);
|
| 103 |
-
};
|
|
|
|
| 1 |
+
export const ThreatGauge = ({ score }) => {
|
| 2 |
+
// Score styling color bounds
|
| 3 |
+
let color = 'var(--low)';
|
| 4 |
+
let label = 'SECURE';
|
| 5 |
+
|
| 6 |
+
if (score < 40) {
|
| 7 |
+
color = 'var(--critical)';
|
| 8 |
+
label = 'CRITICAL RISK';
|
| 9 |
+
} else if (score < 60) {
|
| 10 |
+
color = 'var(--high)';
|
| 11 |
+
label = 'HIGH RISK';
|
| 12 |
+
} else if (score < 80) {
|
| 13 |
+
color = 'var(--medium)';
|
| 14 |
+
label = 'MEDIUM WARNING';
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
// Radial calculation (semi circle, SVG path)
|
| 18 |
+
const radius = 80;
|
| 19 |
+
const strokeWidth = 10;
|
| 20 |
+
const normalizedScore = Math.min(100, Math.max(0, score || 0));
|
| 21 |
+
|
| 22 |
+
// Circumference for a full circle is 2 * pi * r. For semi-circle it's half.
|
| 23 |
+
// We use strokeDasharray to fill the arc.
|
| 24 |
+
const circumference = radius * Math.PI;
|
| 25 |
+
const strokeDashoffset = circumference - (normalizedScore / 100) * circumference;
|
| 26 |
+
|
| 27 |
+
return (
|
| 28 |
+
<div style={{
|
| 29 |
+
display: 'flex',
|
| 30 |
+
flexDirection: 'column',
|
| 31 |
+
alignItems: 'center',
|
| 32 |
+
justifyContent: 'center',
|
| 33 |
+
padding: 'var(--space-md)'
|
| 34 |
+
}}>
|
| 35 |
+
<div style={{ position: 'relative', width: '200px', height: '110px' }}>
|
| 36 |
+
<svg width="200" height="110" style={{ transform: 'rotate(180deg)' }}>
|
| 37 |
+
{/* Base Gauge Arch (Unfilled) */}
|
| 38 |
+
<circle
|
| 39 |
+
cx="100"
|
| 40 |
+
cy="10"
|
| 41 |
+
r={radius}
|
| 42 |
+
fill="none"
|
| 43 |
+
stroke="var(--outline-variant)"
|
| 44 |
+
strokeWidth={strokeWidth}
|
| 45 |
+
strokeDasharray={circumference}
|
| 46 |
+
strokeLinecap="round"
|
| 47 |
+
style={{ transform: 'translate(0, 100px)' }}
|
| 48 |
+
/>
|
| 49 |
+
{/* Filled Gauge Arch */}
|
| 50 |
+
<circle
|
| 51 |
+
cx="100"
|
| 52 |
+
cy="10"
|
| 53 |
+
r={radius}
|
| 54 |
+
fill="none"
|
| 55 |
+
stroke={color}
|
| 56 |
+
strokeWidth={strokeWidth}
|
| 57 |
+
strokeDasharray={circumference}
|
| 58 |
+
strokeDashoffset={strokeDashoffset}
|
| 59 |
+
strokeLinecap="round"
|
| 60 |
+
style={{
|
| 61 |
+
transform: 'translate(0, 100px)',
|
| 62 |
+
transition: 'stroke-dashoffset 1s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.5s ease'
|
| 63 |
+
}}
|
| 64 |
+
/>
|
| 65 |
+
</svg>
|
| 66 |
+
|
| 67 |
+
{/* Score & Label inside circle */}
|
| 68 |
+
<div style={{
|
| 69 |
+
position: 'absolute',
|
| 70 |
+
bottom: '0',
|
| 71 |
+
left: '0',
|
| 72 |
+
right: '0',
|
| 73 |
+
display: 'flex',
|
| 74 |
+
flexDirection: 'column',
|
| 75 |
+
alignItems: 'center',
|
| 76 |
+
justifyContent: 'center'
|
| 77 |
+
}}>
|
| 78 |
+
<span style={{
|
| 79 |
+
fontSize: '36px',
|
| 80 |
+
fontWeight: 700,
|
| 81 |
+
letterSpacing: '-0.02em',
|
| 82 |
+
color: 'var(--on-surface)',
|
| 83 |
+
lineHeight: '1.0'
|
| 84 |
+
}}>
|
| 85 |
+
{score !== null && score !== undefined ? score : '--'}
|
| 86 |
+
</span>
|
| 87 |
+
<span style={{
|
| 88 |
+
fontSize: '11px',
|
| 89 |
+
fontFamily: 'JetBrains Mono',
|
| 90 |
+
fontWeight: 600,
|
| 91 |
+
color: color,
|
| 92 |
+
marginTop: '4px',
|
| 93 |
+
letterSpacing: '0.05em'
|
| 94 |
+
}}>
|
| 95 |
+
{label}
|
| 96 |
+
</span>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
);
|
| 101 |
+
};
|
|
|
|
|
|