Skip to content

Commit

Permalink
Switch between charts
Browse files Browse the repository at this point in the history
  • Loading branch information
cjwit committed Nov 19, 2020
1 parent 6e002ad commit 9c5ac25
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
6 changes: 3 additions & 3 deletions dist/assets/script.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ body {
margin-bottom: .4rem;
}

.chart {
display: none;
}

#cases {
display: block;
}

svg {
display: block;
margin: 0 auto;
Expand Down
20 changes: 10 additions & 10 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ <h1>COVID-19 cases by US state since their 100th reported case</h1>
Developed by <a href='https://cwitulski.com'>Christopher Witulski</a>.
</p>
<p>
<a href="index.html" class="btn btn-default">Total cases</a>
<a href='scaled_cases.html' class='btn btn-primary'>Cases by population</a>
<a href='deaths.html' class='btn btn-primary'>Total deaths</a>
<a href='averages.html' class='btn btn-primary'>Daily new cases</a>
<a href='scaled_averages.html' class='btn btn-primary'>Daily new cases per 100k</a>
<span id="casesButton" class="btn btn-default">Total cases</span>
<span id="casesScaledButton" class='btn btn-primary'>Cases by population</span>
<span id="deathsButton" class='btn btn-primary'>Total deaths</span>
<span id="dailyButton" class='btn btn-primary'>Daily new cases</span>
<span id="dailyScaledButton" class='btn btn-primary'>Daily new cases per 100k</span>
</p>
</div>

<div id="cases"></div>
<div id="casesScaled"></div>
<div id="deaths"></div>
<div id="daily"></div>
<div id="dailyScaled"></div>
<div id="cases" class="chart"></div>
<div id="casesScaled" class="chart"></div>
<div id="deaths" class="chart"></div>
<div id="daily" class="chart"></div>
<div id="dailyScaled" class="chart"></div>

<p>
This chart tracks cases of COVID-19 across the USA from the date when each state first had at least 100 reported
Expand Down
31 changes: 31 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,34 @@ window.CasesScaledChart = CasesScaledChart;
window.DeathsChart = DeathsChart;
window.DailyChart = DailyChart;
window.DailyScaledChart = DailyScaledChart;

var buttons = document.getElementsByClassName("btn");
var charts = document.getElementsByClassName("chart");

var buttonListener = function() {
console.log(this.id);
for (let i = 0; i < buttons.length; i++) {
buttons[i].classList.remove("btn-default");
buttons[i].classList.add("btn-primary");
this.classList.remove('btn-primary');
this.classList.add('btn-default');

if (charts[i].id + "Button" == this.id) {
charts[i].style.display = "block";
} else {
charts[i].style.display = "none";
}

}
}

for (let i = 0; i < buttons.length; i++) {
console.log(buttons[i]);
buttons[i].addEventListener("click", buttonListener);
}

var casesButton = document.getElementById("casesButton");
var casesScaledButton = document.getElementById("casesScaledButton");
var deathsButton = document.getElementById("deathsButton");
var dailyButton = document.getElementById("dailyButton");
var dailyScaledButton = document.getElementById("dailyScaledButton");
1 change: 0 additions & 1 deletion src/CasesScaledChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Chart } from "./Chart.js";

export default class CasesScaledChart extends Chart {
constructor(id, title, margin) {
console.log(id, margin);
super(id, title, margin);
}

Expand Down
1 change: 0 additions & 1 deletion src/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class Chart {
setRanges() {}

createSVG(id, margin) {
console.log(id)
return d3.select('#' + id)
.append('svg')
.attr('width', '100%')
Expand Down

0 comments on commit 9c5ac25

Please sign in to comment.