Skip to content

Commit 37fdaeb

Browse files
committed
implemented results page
1 parent 8ed8078 commit 37fdaeb

File tree

14 files changed

+1199
-863
lines changed

14 files changed

+1199
-863
lines changed

package-lock.json

Lines changed: 123 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"react-hook-form": "^7.57.0",
6363
"react-markdown": "^9.0.3",
6464
"react-use-measure": "^2.1.7",
65+
"recharts": "^2.15.4",
6566
"remark-gemoji": "^8.0.0",
6667
"remark-gfm": "^4.0.1",
6768
"remark-mdx-disable-explicit-jsx": "^0.1.0",
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import React from 'react'
2+
import { Label, Pie, PieChart } from 'recharts'
3+
import { cn } from '@/lib/utils'
4+
import { ChartContainer } from '@/components/ui/chart'
5+
6+
interface OverallScoreGaugeProps {
7+
score: number
8+
maxScore?: number
9+
}
10+
11+
function getScoreLabel(score: number): string {
12+
if (score >= 8) return 'Excellent'
13+
if (score >= 6) return 'Good'
14+
if (score >= 4) return 'Fair'
15+
if (score >= 2) return 'Poor'
16+
return 'Critical'
17+
}
18+
19+
function getScoreLabelColor(score: number): string {
20+
if (score >= 7) return 'text-green-400'
21+
if (score >= 4) return 'text-yellow-400'
22+
return 'text-red-400'
23+
}
24+
25+
function getScoreFill(score: number): string {
26+
if (score >= 7) return '#4ade80'
27+
if (score >= 4) return '#facc15'
28+
return '#f87171'
29+
}
30+
31+
export default function OverallScoreGauge({
32+
score,
33+
maxScore = 10,
34+
}: OverallScoreGaugeProps) {
35+
const data = [
36+
{
37+
name: 'Score',
38+
value: score,
39+
fill: getScoreFill(score),
40+
},
41+
{
42+
name: 'Remaining',
43+
value: maxScore - score,
44+
fill: 'hsl(var(--secondary))',
45+
},
46+
]
47+
48+
return (
49+
<div className="flex flex-col items-center">
50+
<h3 className="mb-2 text-base font-semibold text-white">
51+
Overall Score
52+
</h3>
53+
<div className="h-[154px] w-[154px]">
54+
<ChartContainer config={{}} className="aspect-square w-full">
55+
<PieChart>
56+
<Pie
57+
data={data}
58+
startAngle={-270}
59+
dataKey="value"
60+
nameKey="name"
61+
innerRadius={42}
62+
strokeWidth={2}
63+
>
64+
<Label
65+
content={({ viewBox }) => {
66+
if (
67+
viewBox &&
68+
'cx' in viewBox &&
69+
'cy' in viewBox
70+
) {
71+
return (
72+
<text
73+
x={viewBox.cx}
74+
y={viewBox.cy}
75+
textAnchor="middle"
76+
dominantBaseline="middle"
77+
>
78+
<tspan
79+
x={viewBox.cx}
80+
y={viewBox.cy}
81+
className="fill-foreground text-3xl font-bold"
82+
>
83+
{score.toFixed(1)}
84+
</tspan>
85+
<tspan
86+
x={viewBox.cx}
87+
y={(viewBox.cy || 0) + 19}
88+
className="fill-muted-foreground text-sm"
89+
>
90+
/ {maxScore}
91+
</tspan>
92+
</text>
93+
)
94+
}
95+
}}
96+
/>
97+
</Pie>
98+
</PieChart>
99+
</ChartContainer>
100+
</div>
101+
<span
102+
className={cn(
103+
'mt-2 text-base font-semibold',
104+
getScoreLabelColor(score),
105+
)}
106+
>
107+
{getScoreLabel(score)}
108+
</span>
109+
</div>
110+
)
111+
}

0 commit comments

Comments
 (0)