-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ExtraInfo.tsx): add graph to dispaly courses taken by other over…
… the years Relates #81
- Loading branch information
Showing
6 changed files
with
102 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
import { Radar, RadarChart, PolarGrid, Legend, PolarAngleAxis, PolarRadiusAxis } from 'recharts'; | ||
|
||
function CoursesChart({ soc }) { | ||
const [courses, setCourses] = useState({}); | ||
const [error, setError] = useState(false); | ||
useEffect(() => { | ||
axios | ||
.get(`http://api.lmiforall.org.uk/api/v1/hesa/courses/${soc}`) | ||
.then((res) => { | ||
setCourses(res); | ||
}) | ||
.catch(() => { | ||
setError(true); | ||
}); | ||
}, [setCourses, soc, setError]); | ||
|
||
const processedData = []; | ||
const fakeData = courses?.data.years; | ||
|
||
const keys = []; | ||
const subjects = []; | ||
const subjectPercentageByYear = []; | ||
|
||
fakeData.map((e) => { | ||
keys.push(e.year); | ||
const sortedCourses = e.courses | ||
.sort((a, b) => { | ||
return b.percentage - a.percentage; | ||
}) | ||
.slice(0, 6); | ||
sortedCourses.map((a) => { | ||
subjectPercentageByYear.push({ name: a.name, [e.year]: a.percentage }); | ||
return !subjects.includes(a.name) ? subjects.push(a.name) : 1; | ||
}); | ||
}); | ||
subjects.map((e) => { | ||
const dataEntry = keys.reduce( | ||
(a, b) => { | ||
// eslint-disable-next-line no-return-assign | ||
return (a[b] = 0), a; | ||
}, | ||
{ | ||
subject: e.replace(/\(\w+\)\s+/gi, ``), | ||
fullMark: 100, | ||
}, | ||
); | ||
processedData.push(dataEntry); | ||
}); | ||
|
||
processedData.map((e) => { | ||
const filteredYears = subjectPercentageByYear.filter((a) => { | ||
return a.name.replace(/\(\w+\)\s+/gi, ``) === e.subject; | ||
}); | ||
filteredYears.map((a) => { | ||
e[Object.keys(a)[1]] = a[Object.keys(a)[1]]; | ||
}); | ||
return filteredYears; | ||
}); | ||
|
||
if (error) { | ||
return <></>; | ||
} | ||
return ( | ||
<RadarChart outerRadius={90} width={730} height={250} data={processedData}> | ||
<PolarGrid /> | ||
<PolarAngleAxis dataKey="subject" /> | ||
<PolarRadiusAxis angle={30} domain={[0, 0]} /> | ||
<Radar name="2011/12" dataKey="2011/12" stroke="#8884d8" fill="#8884d8" fillOpacity={0.6} /> | ||
<Radar name="2012/13" dataKey="2012/13" stroke="#82ca9d" fill="#82ca9d" fillOpacity={0.6} /> | ||
<Radar name="2013/14" dataKey="2013/14" stroke="#ff2122" fill="#8884d8" fillOpacity={0.6} /> | ||
<Radar name="2014/15" dataKey="2014/15" stroke="#879012" fill="#82ca9d" fillOpacity={0.6} /> | ||
<Legend /> | ||
</RadarChart> | ||
); | ||
} | ||
|
||
export default CoursesChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import WorkingFuturesReplacemendDemand from './WorkingFuturesReplacementDemand'; | ||
// import CoursesChart from './CoursesChart'; | ||
|
||
function ExtraInfo({ soc, name, color }) { | ||
return ( | ||
<div> | ||
<h2>courses taken by others</h2> | ||
{/* <CoursesChart soc={soc} /> */} | ||
<WorkingFuturesReplacemendDemand soc={soc} name={name} color={color} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default ExtraInfo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.