Skip to content

Commit

Permalink
Format points up to one decimal digit at most
Browse files Browse the repository at this point in the history
  • Loading branch information
sealexan committed Sep 29, 2023
1 parent 46b92e3 commit 038ec35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/Statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react'
import {
Area, AreaChart, Bar, BarChart, Cell, Label, Pie, PieChart, ResponsiveContainer, Tooltip, XAxis, YAxis
} from 'recharts'
import { formatPoints } from '../components/Util'

const green = '#46dba4'
const purple = '#9576ff'
Expand Down Expand Up @@ -44,7 +45,7 @@ export const ScorePie = ({ value = 0, max = 1 }) =>
data={[{ value }, { value: (max || 1) - value }]}>
<Cell key='cell-0' color={green} fill='currentColor' />
<Cell key='cell-1' opacity={0.15} />
<Label value={`${value} / ${max}`} color='inherit' fill='currentColor' dy={-5} position='center' />
<Label value={`${formatPoints(value)} / ${formatPoints(max)}`} color='inherit' fill='currentColor' dy={-5} position='center' />
<Label value={`${toPercent(value, max)}%`} color={green} fill='currentColor'
fontSize='80%' position='centerTop' dy={10} />
</Pie>
Expand Down Expand Up @@ -95,7 +96,7 @@ export const HScores = ({ value = 0, max = 1, avg = 0 }) =>

export const ScoreBar = ({ value = 0, max = 1, h = 10 }) =>
<Stack align='end' justify='end' spacing={0}>
<Text textAlign='end' px={2} fontSize='sm'>{`${isNull(value) ? '?' : value} / ${max} Points`}</Text>
<Text textAlign='end' px={2} fontSize='sm'>{`${isNull(value) ? '?' : formatPoints(value)} / ${formatPoints(max)} Points`}</Text>
<ResponsiveContainer height={h + 2}>
<BarChart data={[{ value, name: 'Score' }]} margin={{}} barSize={h} layout='vertical'>
<XAxis hide type='number' dataKey='value' domain={[0, max || 1]} />
Expand Down
5 changes: 5 additions & 0 deletions src/components/Util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ export function formatTaskCount(n: number): string {
if (n === 1) { return "1 task" }
else { return `${n} tasks` }
}

export function formatPoints(num: number): string {
const rounded = Math.round(num * 100) / 100;
return rounded === Math.floor(rounded) ? `${Math.floor(rounded)}` : rounded.toFixed(1);
}
1 change: 1 addition & 0 deletions src/pages/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { FcFile, FcInspection, FcTimeline, FcTodoList } from 'react-icons/fc'
import { ActionButton, ActionTab, NextAttemptAt, TooltipIconButton } from '../components/Buttons'
import { useCodeEditor, useTask } from '../components/Hooks'
import { TaskController } from './Supervisor'
import { formatPoints } from '../components/Util'

export default function Task() {
const editor = useCodeEditor()
Expand Down

0 comments on commit 038ec35

Please sign in to comment.