Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wharton Dashboard fixes #752

Merged
merged 2 commits into from
Jan 13, 2025
Merged
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
85 changes: 70 additions & 15 deletions frontend/components/Settings/WhartonApplicationStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactElement, useState } from 'react'
import { DiscreteColorLegend, Hint, RadialChart } from 'react-vis'
import { Hint, RadialChart } from 'react-vis'
import styled from 'styled-components'

import { WHITE } from '~/constants/colors'
import { ApplicationStatus } from '~/types'
Expand Down Expand Up @@ -29,24 +30,44 @@ const colors = {

function parseStatuses(statuses: ApplicationStatus[]): PieChartData {
const applicationsTotal = {}
const applicationCommittees = {}
const applicationsGrouped: PieChartData = {}
statuses.forEach((status) => {
if (!(status.name in applicationsGrouped)) {
if (!(status.club in applicationCommittees)) {
const total = {}
Object.keys(colors).forEach((status) => (total[status] = 0))
applicationsTotal[status.name] = total
applicationsTotal[status.club] = total

const grouped = {}
grouped[status.committee] = []
applicationsGrouped[status.name] = grouped
} else if (!(status.committee in applicationsGrouped[status.name])) {
applicationsGrouped[status.name][status.committee] = []
applicationCommittees[status.club] = {}
}
applicationsTotal[status.name][status.status] += status.count
applicationsGrouped[status.name][status.committee].push({
angle: status.count,
label: status.status,
color: colors[status.status],
if (!(status.committee in applicationCommittees[status.club])) {
applicationCommittees[status.club][status.committee] = {}
}
if (
!(status.status in applicationCommittees[status.club][status.committee])
) {
applicationCommittees[status.club][status.committee][status.status] = 0
}
applicationsTotal[status.club][status.status] += status.count
applicationCommittees[status.club][status.committee][status.status] +=
status.count
})

Object.keys(applicationCommittees).forEach((club) => {
Object.keys(applicationCommittees[club]).forEach((committee) => {
Object.keys(applicationCommittees[club][committee]).forEach((status) => {
if (!(club in applicationsGrouped)) {
applicationsGrouped[club] = {}
}
if (!(committee in applicationsGrouped[club])) {
applicationsGrouped[club][committee] = []
}
applicationsGrouped[club][committee].push({
angle: applicationCommittees[club][committee][status],
label: status,
color: colors[status],
})
})
})
})

Expand All @@ -67,6 +88,41 @@ function parseStatuses(statuses: ApplicationStatus[]): PieChartData {
return applicationsGrouped
}

const LegendContainer = styled.div`
height: 130px;
display: grid;
rowGap: "0.5rem",
alignItems: "center"
`

const LegendColor = styled.div<{ color: string }>`
background-color: ${(props) => props.color};
`
const LegendRow = styled.div`
display: grid;
grid-template-columns: 20px auto;
gap: 6px;
`

interface LegendProps {
items: {
color: string
title: string
}[]
}
const Legend: React.FC<LegendProps> = ({ items }) => {
return (
<LegendContainer>
{items.map((item, index) => (
<LegendRow>
<LegendColor key={index} color={item.color} />
<div style={{ alignSelf: 'center' }}>{item.title}</div>
</LegendRow>
))}
</LegendContainer>
)
}

function StatusCard({
application,
pieData,
Expand Down Expand Up @@ -203,10 +259,9 @@ const WhartonApplicationStatus = ({
Download Data
</button>
<div className="column">
<DiscreteColorLegend
<Legend
items={Object.keys(colors).map((label) => ({
title: label,
strokeWidth: 100,
color: colors[label],
}))}
/>
Expand Down
Loading