Skip to content

Commit 35f4ce6

Browse files
authored
Merge pull request #4 from NextStepFinalProject/NXD-6-additional-improvements
Add Gauge Gradient Color Transitions
2 parents 9e100ce + 6d0b632 commit 35f4ce6

3 files changed

Lines changed: 64 additions & 33 deletions

File tree

nextstep-frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@mui/icons-material": "^6.4.7",
1616
"@mui/joy": "^5.0.0-beta.51",
1717
"@mui/material": "^6.4.3",
18+
"@mui/x-charts": "^7.28.0",
1819
"@types/axios": "^0.9.36",
1920
"@types/react-router-dom": "^5.3.3",
2021
"axios": "^1.7.9",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as React from 'react';
2+
import { Gauge, gaugeClasses } from '@mui/x-charts/Gauge';
3+
import { Box } from '@mui/material';
4+
5+
interface ScoreGaugeProps {
6+
score: number;
7+
width?: number;
8+
height?: number;
9+
}
10+
11+
const ScoreGauge: React.FC<ScoreGaugeProps> = ({ score, width = 200, height = 200 }) => {
12+
const getGradientColor = (value: number) => {
13+
// Clamp value between 0 and 100
14+
value = Math.max(0, Math.min(100, value));
15+
16+
let r, g, b;
17+
18+
if (value <= 50) {
19+
// Red (255, 0, 0) to Yellow (255, 215, 0)
20+
const ratio = value / 50;
21+
r = 255;
22+
g = Math.round(215 * ratio);
23+
b = 0;
24+
} else {
25+
// Yellow (255, 215, 0) to Green (82, 178, 2)
26+
const ratio = (value - 50) / 50;
27+
r = Math.round(255 + (82 - 255) * ratio); // Decrease red
28+
g = Math.round(215 + (178 - 215) * ratio); // Shift green
29+
b = Math.round(0 + (2 - 0) * ratio); // Increase blue a little
30+
}
31+
32+
return `rgb(${r}, ${g}, ${b})`;
33+
};
34+
35+
return (
36+
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
37+
<Gauge
38+
width={width}
39+
height={height}
40+
value={score}
41+
cornerRadius="50%"
42+
sx={(theme) => ({
43+
[`& .${gaugeClasses.valueText}`]: {
44+
fontSize: 30,
45+
fontWeight: 'bold',
46+
},
47+
[`& .${gaugeClasses.valueArc}`]: {
48+
fill: getGradientColor(score),
49+
transition: 'fill 1s ease-in-out',
50+
},
51+
[`& .${gaugeClasses.referenceArc}`]: {
52+
fill: theme.palette.text.disabled,
53+
},
54+
})}
55+
/>
56+
</Box>
57+
);
58+
};
59+
60+
export default ScoreGauge;

nextstep-frontend/src/pages/Resume.tsx

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { config } from '../config';
55
import api from '../serverApi';
66
import ReactMarkdown from 'react-markdown';
77
import remarkGfm from 'remark-gfm';
8+
import ScoreGauge from '../components/ScoreGauge';
89

910
const UploadBox = styled(Box)(({ theme }) => ({
1011
border: '2px dashed #ccc',
@@ -17,35 +18,6 @@ const UploadBox = styled(Box)(({ theme }) => ({
1718
},
1819
}));
1920

20-
const ScoreGauge = styled(Box)<{ score: number }>(({ theme }) => ({
21-
width: '200px',
22-
height: '200px',
23-
borderRadius: '50%',
24-
display: 'flex',
25-
alignItems: 'center',
26-
justifyContent: 'center',
27-
background: `conic-gradient(
28-
${theme.palette.error.main} 0% 33%,
29-
${theme.palette.warning.main} 33% 66%,
30-
${theme.palette.success.main} 66% 100%
31-
)`,
32-
position: 'relative',
33-
'&::before': {
34-
content: '""',
35-
position: 'absolute',
36-
width: '180px',
37-
height: '180px',
38-
borderRadius: '50%',
39-
background: theme.palette.background.paper,
40-
},
41-
}));
42-
43-
const ScoreText = styled(Typography)({
44-
position: 'absolute',
45-
fontSize: '2.5rem',
46-
fontWeight: 'bold',
47-
});
48-
4921
const FeedbackContainer = styled(Box)(({ theme }) => ({
5022
maxHeight: '60vh',
5123
overflowY: 'auto',
@@ -243,10 +215,8 @@ const Resume: React.FC = () => {
243215
)}
244216

245217
{score !== null && (
246-
<Box sx={{ display: 'flex', justifyContent: 'center', mb: 3 }}>
247-
<ScoreGauge score={score}>
248-
<ScoreText>{score}</ScoreText>
249-
</ScoreGauge>
218+
<Box sx={{ mb: 3 }}>
219+
<ScoreGauge score={score} />
250220
</Box>
251221
)}
252222
</Box>

0 commit comments

Comments
 (0)