Skip to content

Commit 7b24feb

Browse files
Add map and change on hover
1 parent 0872413 commit 7b24feb

File tree

4 files changed

+118
-13
lines changed

4 files changed

+118
-13
lines changed

src/components/CovidApp.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import React, { Component } from "react";
22
import Overview from "./Overview";
33
import { withStyles } from "@material-ui/styles";
44
import colors from "../constants/colors";
5-
import "../styles/DarkModeButton.css";
65
import Charts from "./Charts";
7-
import Map from "./Map/Map";
86
import DisplayTable from "./DisplayTable";
97
import TinyCharts from "./TinyCharts";
108
import styles from "../styles/CovidAppStyles";
119
import axios from "axios";
1210
import stateCodes from "../constants/stateCodes";
1311
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
1412
import { faSyncAlt } from "@fortawesome/free-solid-svg-icons";
13+
import "../styles/DarkModeButton.css";
14+
import MapSection from "./MapSection";
1515

1616
class CovidApp extends Component {
1717
constructor(props) {
@@ -95,7 +95,7 @@ class CovidApp extends Component {
9595

9696
render() {
9797
const { classes, setDarkMode, isDarkMode } = this.props;
98-
const { mapData, tableData, isLoading } = this.state;
98+
const { mapData, tableData, isLoading, data } = this.state;
9999

100100
if (isLoading) {
101101
return (
@@ -133,7 +133,12 @@ class CovidApp extends Component {
133133
<div className={classes.content}>
134134
<div className={classes.contentArea}>
135135
<div className={classes.mapArea}>
136-
<Map mapData={mapData} />
136+
{/* <Map mapData={mapData} /> */}
137+
<MapSection
138+
mapData={mapData}
139+
data={data}
140+
isDarkMode={isDarkMode}
141+
/>
137142
</div>
138143
<div></div>
139144
</div>

src/components/Map/Map.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ class Map extends Component {
6060

6161
onMouseEnter = (geo, current = { value: "NA" }) => {
6262
return () => {
63-
this.setState({
64-
tooltipContent: `${geo.properties.name}: ${current.value}`,
65-
});
63+
this.setState(
64+
{
65+
tooltipContent: `${geo.properties.name}: ${current.value}`,
66+
},
67+
() => this.props.currentLocation(geo.properties.name)
68+
);
6669
};
6770
};
6871

@@ -84,7 +87,7 @@ class Map extends Component {
8487
.range(COLOR_RANGE);
8588

8689
return (
87-
<div className="container">
90+
<div>
8891
<ReactTooltip>{this.state.tooltipContent}</ReactTooltip>
8992
<ComposableMap
9093
projectionConfig={PROJECTION_CONFIG}

src/components/MapSection.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import React, { Component } from "react";
2+
import DisplayPanels from "./DisplayPanels";
3+
import Map from "./Map/Map";
4+
import { withStyles } from "@material-ui/styles";
5+
6+
const styles = {
7+
container: {
8+
backgroundColor: "rgba(129, 124, 155, 0.05)",
9+
display: "flex",
10+
justifyContent: "center",
11+
alignItems: "center",
12+
padding: "2rem 3rem",
13+
},
14+
mapContainer: {
15+
flex: "1",
16+
},
17+
panelsContainer: {
18+
display: "flex",
19+
flex: "0 0 25%",
20+
justifyContent: "center",
21+
flexWrap: "wrap",
22+
alignItems: "center",
23+
},
24+
};
25+
26+
class MapSection extends Component {
27+
constructor(props) {
28+
super(props);
29+
this.state = {
30+
confirmed: null,
31+
deaths: null,
32+
recovered: null,
33+
active: null,
34+
};
35+
this.currentLocation = this.currentLocation.bind(this);
36+
}
37+
38+
currentLocation(location) {
39+
const stateName = location.replace(" & ", " and ");
40+
const data = this.props.data.slice(-1)[0].regional;
41+
const updatedData = data.filter((el) => el.loc === stateName);
42+
if (updatedData[0]) {
43+
this.setState({
44+
confirmed: updatedData[0].totalConfirmed,
45+
deaths: updatedData[0].deaths,
46+
recovered: updatedData[0].discharged,
47+
active:
48+
updatedData[0].totalConfirmed -
49+
(updatedData[0].discharged + updatedData[0].deaths),
50+
});
51+
} else {
52+
this.setState({
53+
confirmed: "NA",
54+
deaths: "NA",
55+
recovered: "NA",
56+
active: "NA",
57+
});
58+
}
59+
}
60+
61+
render() {
62+
const { classes, mapData, isDarkMode } = this.props;
63+
const { confirmed, deaths, recovered, active } = this.state;
64+
return (
65+
<div className={classes.container}>
66+
<div className={classes.panelsContainer}>
67+
<DisplayPanels
68+
title="Confirmed"
69+
number={confirmed}
70+
isDarkMode={isDarkMode}
71+
dataChange={4}
72+
/>
73+
<DisplayPanels
74+
title="Active"
75+
number={active}
76+
isDarkMode={isDarkMode}
77+
dataChange={4}
78+
/>
79+
<DisplayPanels
80+
title="Recovered"
81+
number={recovered}
82+
isDarkMode={isDarkMode}
83+
dataChange={4}
84+
/>
85+
<DisplayPanels
86+
title="Deceased"
87+
number={deaths}
88+
isDarkMode={isDarkMode}
89+
dataChange={4}
90+
/>
91+
</div>
92+
<div className={classes.mapContainer}>
93+
<Map mapData={mapData} currentLocation={this.currentLocation} />
94+
</div>
95+
</div>
96+
);
97+
}
98+
}
99+
100+
export default withStyles(styles)(MapSection);

src/styles/CovidAppStyles.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,28 @@ export default {
4545
textAlign: "center",
4646
margin: "4rem 0",
4747
fontSize: "3rem",
48-
// textTransform: "uppercase",
4948
},
5049

5150
tinyChartArea: {
5251
display: "flex",
5352
flexWrap: "wrap",
5453
padding: "2rem",
55-
// flexDirection: "column",
5654
justifyContent: "space-around",
5755
alignItems: "center",
5856
marginTop: "3rem",
5957
},
58+
6059
tinyChart: {
6160
margin: "2rem",
62-
// padding: "2rem",
6361
"& h3": {
6462
textTransform: "capitalize",
6563
fontWeight: 500,
6664

6765
textAlign: "center",
6866
},
6967
},
68+
7069
tinych: {
71-
// backgroundColor: "rgba(129, 124, 155, 0.05)",
7270
borderRadius: "2rem",
7371
marginBottom: "2rem",
7472
padding: "2rem",
@@ -106,7 +104,6 @@ export default {
106104
borderRadius: "10rem",
107105
fontFamily: "inherit",
108106
fontSize: "1.6rem",
109-
// marginTop: "6rem",
110107
marginLeft: "2rem",
111108
transition: "all .4s",
112109
boxShadow: "0 .5rem 1rem rgba(0,0,0,.2)",

0 commit comments

Comments
 (0)