Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions checkers-app/src/components/vote/VotingTagChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { PieChart, Pie, ResponsiveContainer, Cell, Legend } from "recharts";
import { AssessedInfo } from "../../types";
import { Typography } from "@material-tailwind/react";

interface VotingTagChartProps {
assessedInfo: AssessedInfo | null;
}
export default function VotingTagChart(Props: VotingTagChartProps) {

const assessedInfo = Props.assessedInfo;
console.log(assessedInfo)
const totalResponse = Props.assessedInfo?.responseCount
const Incorrect_Tag_Data =
assessedInfo && totalResponse
? [
{ name: 'Tagged as Incorrect', value: assessedInfo.tagCounts.incorrect },
{
name: 'Not Tagged as Incorrect',
value: totalResponse - assessedInfo.tagCounts.incorrect,
},
]
: [];

const Generated_Tag_Data =
assessedInfo && totalResponse
? [
{name: 'Tagged as Generated', value: assessedInfo.tagCounts.generated},
{
name: 'Not Tagged as Generated',
value: totalResponse - assessedInfo.tagCounts.generated
}
]
: [];


const COLORS = ['#FFBB28', '#FF8042'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change these 2 hex color codes to a more readable const? example, 'orange' or 'reddishOrange' etc


return (
<div>
{Incorrect_Tag_Data.length > 0 && Incorrect_Tag_Data[1].value !== totalResponse &&
<div>
<Typography
className="text-primary-color3 dark:text-white"
variant="h5"
>
Incorrect Tag Analysis:
</Typography>
<ResponsiveContainer width="100%" height={200}>
<PieChart width={500} height={200}>
<Pie
data={Incorrect_Tag_Data}
cy = {120}
startAngle={180}
endAngle={0}
innerRadius={60}
outerRadius={80}
fill="#8884d8"
dataKey="value"
label={({ value }) =>
value === 0 ? null : `${value}`
}
labelLine = {false}
>
{Incorrect_Tag_Data.map((entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
<Legend />
</PieChart>
</ResponsiveContainer>
</div>}

{Generated_Tag_Data.length > 0 && Generated_Tag_Data[1].value !== totalResponse &&
<div>
<Typography
className="text-primary-color3 dark:text-white"
variant="h5"
>
AI Generated Tag Analysis:
</Typography>
<ResponsiveContainer width="100%" height={200}>
<PieChart width={500} height={200}>
<Pie
data={Generated_Tag_Data}
cy = {120}
startAngle={180}
endAngle={0}
innerRadius={60}
outerRadius={80}
fill="#8884d8"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8884d8 is duplicated. So can extract it out into it's own const

dataKey="value"
label={({ value }) =>
value === 0 ? null : `${value}`
}
labelLine = {false}
>
{Generated_Tag_Data.map((entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
<Legend />
</PieChart>
</ResponsiveContainer>
</div>}
</div>
)
}

2 changes: 2 additions & 0 deletions checkers-app/src/components/vote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CategoryRationalisation from "./Rationalisation";
import VoteResult from "./VoteResult";
import VotingChart from "./VotingChart";
import CustomReply from "./CustomReply";
import VotingTagChart from "./VotingTagChart";

export default function VotePage() {
const { checkerDetails } = useUser();
Expand Down Expand Up @@ -105,6 +106,7 @@ export default function VotePage() {
</div>
</div>
<VotingChart assessedInfo={vote.finalStats} />
{(vote.finalStats?.tags ?? []).length > 0 && <VotingTagChart assessedInfo={vote.finalStats}/>}
<CategoryRationalisation
rationalisation={vote.finalStats?.rationalisation ?? null}
/>
Expand Down
Loading