-
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.
- Loading branch information
1 parent
1a4343a
commit 1a34650
Showing
13 changed files
with
4,013 additions
and
109 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,38 +1,84 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { useEffect, useState } from "react"; | ||
import { updateCountryInfo } from "../utils.js"; | ||
|
||
import Body from "../components/Body.js"; | ||
import Switch from "../components/Switch.js"; | ||
import Listing from "../components/Listing.js"; | ||
import Carousel from "../components/Carousel.js"; | ||
import Map from "../components/Map.js"; | ||
import Modal from "../components/Modal.js"; | ||
|
||
import cancerData from "../data.json"; | ||
|
||
// Part to select the data to represent | ||
function DataSelect({active, setActive}) { | ||
return( | ||
<div className="col text-center" > | ||
<h4>Type of Cancer</h4> | ||
<p>Select a type of cancer to learn about its statistics :</p> | ||
<Body active={active} setActive={setActive} /> | ||
</div> | ||
); | ||
} | ||
|
||
// Part to represent the data chosen | ||
function DataRepr({active}) { | ||
|
||
// Mode of representation (false: Graphs, true: Map) | ||
const [mode, setMode] = useState(false); | ||
// Information about the selected country | ||
const [countryInfo, setCountryInfo] = useState(null); | ||
|
||
// Updates the information on countries when the active cancer changes | ||
useEffect(() => { | ||
if (countryInfo != null) { | ||
updateCountryInfo(setCountryInfo, active, countryInfo.name, countryInfo.latlng) | ||
} | ||
}, [active]); | ||
|
||
return ( | ||
<div className="col text-center" style={{ "borderLeft": "1px solid #ddd" }}> | ||
<Modal countryInfo={countryInfo} /> | ||
<h4>Statistics {active == null ? "" : "on " + (active.type).toLowerCase() + " cancer"}</h4> | ||
<div className="switch-container text-center"> | ||
<div className="row align-items-center"> | ||
<div className="col"> | ||
Graphs | ||
</div> | ||
<div className="col"> | ||
<Switch state={mode} stateSetter={setMode} /> | ||
</div> | ||
<div className="col"> | ||
Map | ||
</div> | ||
</div> | ||
</div> | ||
{mode ? <Map setCountryInfo={setCountryInfo} currentCancer={active} /> : <Carousel currentCancer={active} />} | ||
</div> | ||
); | ||
} | ||
|
||
export default function Page() { | ||
|
||
const cancers = cancerData.cancers; | ||
// The current cancer that is displayed | ||
const [currentCancer, setCurrentCancer] = useState(null); | ||
const [mode, setMode] = useState(false); | ||
|
||
return ( | ||
<div className="menu-container row"> | ||
<div className="col text-center" style={{ "borderRight": "1px solid #ddd" }}> | ||
<> | ||
|
||
<h4>Type of Cancer</h4> | ||
<p>Select a type of cancer to learn about its statistics :</p> | ||
<Switch state={mode} stateSetter={setMode} /> | ||
{mode ? | ||
<Body active={currentCancer} setActive={setCurrentCancer} /> | ||
: | ||
<Listing cancers={cancers} active={currentCancer} setActive={setCurrentCancer} /> | ||
} | ||
</div> | ||
<div className="col text-center"> | ||
<h4>Cancer Stat Facts {currentCancer == null ? "" : ": " + currentCancer.type}</h4> | ||
{currentCancer == null ? null : <Carousel currentCancer={currentCancer} />} | ||
<nav className="navbar bg-body-tertiary"> | ||
<div className="container-fluid"> | ||
<a className="navbar-brand" href=""> | ||
TogetherAgainstCancer | ||
</a> | ||
</div> | ||
</nav> | ||
|
||
<div className="menu-container row"> | ||
<DataSelect active={currentCancer} setActive={setCurrentCancer} /> | ||
{currentCancer === null ? null : <DataRepr active={currentCancer} /> } | ||
</div> | ||
|
||
|
||
</> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { useState } from "react"; | ||
|
||
export default function Carousel({ currentCancer }) { | ||
|
||
const isProd = process.env.NODE_ENV === 'production'; | ||
|
||
const [activeImage, setActiveImage] = useState(0); | ||
|
||
return ( | ||
<div id="carouselGraphs" className="carousel carousel-fade slide"> | ||
<div className="carousel-inner"> | ||
<div className="carousel-item "> | ||
<img src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/daly.png"} className="d-block w-100" /> | ||
<div> | ||
{activeImage === 0 ? <img src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/daly.png"} className="d-block w-100" /> : null } | ||
{activeImage === 1 ? <img src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/hbar.png"} className="d-block w-100" /> : null } | ||
{activeImage === 2 ? <img src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/time_series.png"} className="d-block w-100" /> : null } | ||
{activeImage === 3 ? <img src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/vbar.png"} className="d-block w-100" /> : null } | ||
<div className="row m-2 p-1"> | ||
<div className={"p-1 col" + (activeImage === 0 ? " text-bg-primary" : "")}> | ||
<img onClick={() => setActiveImage(0)} src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/daly.png"} className="rounded mx-auto d-block w-100" /> | ||
</div> | ||
<div className="carousel-item active"> | ||
<img src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/hbar.png"} className="d-block w-100" /> | ||
<div className={"p-1 col" + (activeImage === 1 ? " text-bg-primary" : "")}> | ||
<img onClick={() => setActiveImage(1)} src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/hbar.png"} className="rounded mx-auto d-block w-100" /> | ||
</div> | ||
<div className="carousel-item active"> | ||
<img src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/time_series.png"} className="d-block w-100" /> | ||
<div className={"p-1 col" + (activeImage === 2 ? " text-bg-primary" : "")}> | ||
<img onClick={() => setActiveImage(2)} src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/time_series.png"} className="d-block w-100" /> | ||
</div> | ||
<div className="carousel-item active"> | ||
<img src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/vbar.png"} className="d-block w-100" /> | ||
<div className={"p-1 col" + (activeImage === 3 ? " text-bg-primary" : "")}> | ||
<img onClick={() => setActiveImage(3)} src={(isProd ? "/TogetherAgainstCancer" : "") + "/graphs/" + (currentCancer.type).toLowerCase() + "/vbar.png"} className="d-block w-100" /> | ||
</div> | ||
</div> | ||
<button className="carousel-control-prev" type="button" data-bs-target="#carouselGraphs" data-bs-slide="prev"> | ||
<span className="carousel-control-prev-icon" aria-hidden="true"></span> | ||
<span className="visually-hidden">Previous</span> | ||
</button> | ||
<button className="carousel-control-next" type="button" data-bs-target="#carouselGraphs" data-bs-slide="next"> | ||
<span className="carousel-control-next-icon" aria-hidden="true"></span> | ||
<span className="visually-hidden">Next</span> | ||
</button> | ||
</div> | ||
</div > | ||
); | ||
} |
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,34 @@ | ||
import { MapContainer, TileLayer, GeoJSON } from "react-leaflet"; | ||
import geoData from "../data/custom.geo.json"; | ||
import 'leaflet/dist/leaflet.css' | ||
import { updateCountryInfo } from "../utils"; | ||
|
||
|
||
// Map Component | ||
export default function Map({ setCountryInfo, currentCancer }) { | ||
|
||
// Central Europe position | ||
const position = [48.6908333333, 9.14055555556]; | ||
|
||
// Event Handler for each country | ||
const countryHandler = (feature, layer) => { | ||
layer.on({ | ||
click: (e) => { | ||
const country = feature.properties.name; | ||
updateCountryInfo(setCountryInfo, currentCancer, country, e.latlng); | ||
const modal = new bootstrap.Modal('#modalCountry', {}) | ||
modal.show() | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<MapContainer center={position} zoom={4} style={{ height: '400px', width: '100%' }}> | ||
<TileLayer | ||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | ||
/> | ||
<GeoJSON key={Math.random()} data={geoData} onEachFeature={countryHandler} /> | ||
</MapContainer> | ||
); | ||
} |
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,27 @@ | ||
export default function Modal({ countryInfo }) { | ||
|
||
if (countryInfo != null) { | ||
console.log(countryInfo.deathRateMen); | ||
} | ||
|
||
return ( | ||
<div className="modal fade" id="modalCountry" tabIndex="-1" aria-labelledby="modalCountryLabel" aria-hidden="true"> | ||
<div className="modal-dialog"> | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<h1 className="modal-title fs-5" id="exampleModalLabel">Death Rate in {countryInfo === null ? "Country Not Found" : countryInfo.name}</h1> | ||
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div className="modal-body"> | ||
{countryInfo === null || countryInfo.deathRateMen === null ? null : <p>Men ♂ : {countryInfo.deathRateMen.toFixed(2)} / 100,000</p>} | ||
{countryInfo === null ? null : <p>Women ♀ : {countryInfo.deathRateWomen.toFixed(2)} / 100,000</p>} | ||
<p><i>This metric represents a mean of numbers of deaths occurring in a population of 100,000 people from 1981 to 2019.</i></p> | ||
</div> | ||
<div className="modal-footer"> | ||
<button type="button" className="btn btn-secondary" data-bs-dismiss="modal">Close</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.