Skip to content

Commit

Permalink
Adding a piece of pie into the oven.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xantier committed Mar 13, 2020
1 parent 4437ff3 commit 47c473b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'react-tabs/style/react-tabs.css';
import isoCodes from './isoCodes.json';
import './App.css';
import Table from './Table';
import Viz from './Viz';
import Viz from './viz';

moment.locale('FI');
const headers = (showInfectionInfo) => [
Expand Down
32 changes: 13 additions & 19 deletions src/Viz.js → src/viz/Line.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
import React from 'react';
import { XYPlot, XAxis, YAxis, VerticalGridLines, HorizontalGridLines, LineSeries } from 'react-vis';
import '../node_modules/react-vis/dist/style.css';
import { HorizontalGridLines, LineSeries, makeVisFlexible, VerticalGridLines, XAxis, XYPlot, YAxis } from 'react-vis';
import moment from 'moment';
import groupBy from 'lodash/groupBy';
import orderBy from 'lodash/orderBy';
import {isMobile} from 'react-device-detect';


const formattedDate = (it) => moment(it.date).format('MM/DD/YYYY'); // Murica
const mmdd = (it) => moment(it).format('DD-MM'); // Murica
const mmdd = (it) => moment(it).format('DD-MM');

const FlexXYPlot = makeVisFlexible(XYPlot);

const Chart = ({ data }) => {
const orderedData = orderBy(data, it => moment(it.date).format('YYYYMMDD'), ['asc']);
const dataArr = Object.entries(
groupBy(orderedData, it => formattedDate(it)))
const Line = ({ data }) => {
const orderedbyDateData = orderBy(data, it => moment(it.date).format('YYYYMMDD'), ['asc']);
const dataArr = Object.entries(groupBy(orderedbyDateData, it => formattedDate(it)))
.reduce((acc, [date, data]) => {
acc.push({
x: new Date(date),
y: acc.length > 0 ? acc[acc.length - 1].y + data.length : 1
});
return acc;
}, []);



console.log(dataArr)
return (
<XYPlot
xType="time"
width={isMobile ? 400 : 800}
height={500}>
<FlexXYPlot
margin={{ bottom: 50 }}
xType="time">
<HorizontalGridLines/>

<VerticalGridLines/>
Expand All @@ -38,8 +33,7 @@ const Chart = ({ data }) => {
/>
<YAxis title="Todetut tapaukset"/>
<LineSeries color={'red'} data={dataArr}/>
</XYPlot>

</FlexXYPlot>
);
};
export default Chart;
export default Line;
37 changes: 37 additions & 0 deletions src/viz/Pie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { makeVisFlexible, RadialChart } from 'react-vis';
import groupBy from 'lodash/groupBy';

import isoCodes from '../isoCodes.json';

const colors = [
'#F66D44',
'#FEAE65',
'#E6F69D',
'#AADEA7',
'#64C2A6',
'#2D87BB',
];

const FlexRadialChart = makeVisFlexible(RadialChart);

const Pie = ({ data }) => {
const groupedBySourceCountry = Object.entries(groupBy(data, 'infectionSourceCountry'))
.reduce((acc, [country, data], idx) => {
acc.push({
angle: data.length + 1,
label: isoCodes[country] ? isoCodes[country] : 'Tuntematon',
...isoCodes[country] ? { color: colors[idx] } : { color: 'red' }
});
return acc;
}, []);
return (
<FlexRadialChart

colorType="literal"
data={groupedBySourceCountry}
showLabels={true}
/>
);
};
export default Pie;
19 changes: 19 additions & 0 deletions src/viz/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import '../../node_modules/react-vis/dist/style.css';

import Line from './Line';
import Pie from './Pie';

const Chart = ({ data }) => {
return (
<div>
<div style={{ height: '50vh' }}>
<Line data={data}/>
</div>
<div style={{ height: '50vh' }}>
<Pie data={data}/>
</div>
</div>
);
};
export default Chart;

0 comments on commit 47c473b

Please sign in to comment.