Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
feat(components:charts): add SubmissionsOvertimeChart component
Browse files Browse the repository at this point in the history
  ## what
  - add `SubmissionsOvertimeChart` component

  ## how
  - takes prop
    - data of type `SubmisionsOvertimeType[]`
  - use Recharts `AreaChart` component
  - use custom tooltip from `./src/components/charts/Tooltip`
  - use linear gradient for color the area chart

  ## why
  - this will be used to display submissions overtime of a problem using
    area chart

  ## where
  - ./src/components/charts/SubmissionsOvertimeChart.tsx

  ## usage
  • Loading branch information
Clumsy-Coder committed Jan 8, 2024
1 parent 6c559ee commit c67a0fd
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/components/charts/SubmissionsOvertimeChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
Area,
AreaChart,
CartesianGrid,
ResponsiveContainer,
Tooltip,
XAxis,
} from "recharts";

import { getResponseType as SubmissionOvertimeType } from "@/app/api/submissions/overtime/[problemNum]/route";
import ChartTooltip from "@/components/charts/Tooltip";

type Props = {
data: SubmissionOvertimeType[];
};

const SubmissionsOvertimeChart = ({ data }: Props) => {
return (
<ResponsiveContainer>
<AreaChart data={data}>
<XAxis dataKey="time" />
<CartesianGrid strokeDasharray="3 3" vertical={false} opacity={0.3} />
<Tooltip
cursor={{ fill: "#d1d5db", opacity: "0.15" }}
isAnimationActive={false}
content={({ active, payload, label }) => (
<ChartTooltip
active={active}
payload={payload}
label={label}
valueFormatter={(number: number) =>
`${new Intl.NumberFormat("us").format(number).toString()}`
}
// labelFormatter={(payload) => payload[0].payload.tooltipTitle}
/>
)}
/>
{/* linear gradient */}
{/* obtained from https://www.youtube.com/watch?v=e4en8kRqwe8 */}
<defs>
<linearGradient id="color" x1={0} y1={0} x2={0} y2={1}>
<stop offset="0%" stopColor="#2451B7" stopOpacity={1.0} />
<stop offset="95%" stopColor="#2451B7" stopOpacity={0.05} />
</linearGradient>
</defs>
<Area
type="monotone"
dataKey="submissions"
stroke="#2451B7"
strokeWidth={3}
fill="url(#color)"
/>
</AreaChart>
</ResponsiveContainer>
);
};

export default SubmissionsOvertimeChart;

0 comments on commit c67a0fd

Please sign in to comment.