From a5d05db93017d6bc6727c7bc11deb4a555de315a Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Sat, 14 Nov 2020 14:21:44 -0500 Subject: add History and totalstudent cases graph --- src/App.js | 48 +++++++++++++++++++++++++++-------------- src/History.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 src/History.js (limited to 'src') diff --git a/src/App.js b/src/App.js index e456b5c..b1d1dd1 100644 --- a/src/App.js +++ b/src/App.js @@ -1,6 +1,8 @@ import useSWR from "swr"; import { DateTime } from "luxon"; +import { BrowserRouter, Route, Switch } from "react-router-dom"; import MainPage from "./MainPage"; +import History from "./History"; import "./App.css"; const url = "https://rcpoller.galenguyer.com/api/v0/history"; @@ -29,22 +31,36 @@ function App() { const lastUpdate = DateTime.fromSQL(latest.last_updated, { zone: "UTC" }).setZone(local); return ( -
-

RIT Covid Dashboard

-

- Last Updated:{" "} - {lastUpdate.toLocaleString({ - weekday: "long", - month: "long", - day: "2-digit", - hour: "2-digit", - minute: "2-digit", - })} -

-
-
- -
+ +
+

RIT Covid Dashboard

+

+ Last Updated:{" "} + {lastUpdate.toLocaleString({ + weekday: "long", + month: "long", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + })} +

+
+
+ + + {" "} + + + { + return { value: d.total_students, date: d.last_updated }; + })} + /> + + +
+
); } diff --git a/src/History.js b/src/History.js new file mode 100644 index 0000000..1fd39a3 --- /dev/null +++ b/src/History.js @@ -0,0 +1,67 @@ +import { React, PureComponent } from "react"; +import { DateTime } from "luxon"; +import { LineChart, Line, CartesianGrid, XAxis, YAxis, Tooltip, ResponsiveContainer, Label } from "recharts"; + +const History = (props) => { + const offset = DateTime.fromSQL(props.data[0].date, { zone: "UTC" }).setZone(DateTime.local().zoneName).toSeconds(); + const data = props.data.map((d) => { + return { + value: d.value, + date: DateTime.fromSQL(d.date, { zone: "UTC" }).setZone(DateTime.local().zoneName).toSeconds(), + }; + }); + + return ( + <> +

{props.name}

+ + + + } + height={90} + /> + + + + + ); +}; + +class CustomizedAxisTick extends PureComponent { + render() { + const { x, y, payload } = this.props; + + return ( + + + {DateTime.fromSeconds(payload.value).toLocaleString()} + + + ); + } +} + +const CustomTooltip = ({ active, payload, label }) => { + if (active) { + return ( +
+

{DateTime.fromSeconds(label).toLocaleString()}

+

{payload[0].value}

+
+ ); + } + return null; +}; + +export default History; -- cgit v1.2.3