Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the number of days to look back configurable #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div id="header">

<div id="explainer">
<p>This interactive charts the <b><i>new</i></b> {{selectedData.toLowerCase()}} of COVID-19 in the past week vs. the <b><i>total</i></b> {{selectedData.toLowerCase()}} to date. When plotted in this way, exponential growth is represented as a straight line that slopes upwards. Notice that almost all countries follow a very similar path of exponential growth. <i>We're all in this together.</i> <span v-if="isHidden"><a @click="toggleHide">Learn more.</a></span></p>
<p>This interactive charts the <b><i>new</i></b> {{selectedData.toLowerCase()}} of COVID-19 in the past {{slopeDays}} days vs. the <b><i>total</i></b> {{selectedData.toLowerCase()}} to date. When plotted in this way, exponential growth is represented as a straight line that slopes upwards. Notice that almost all countries follow a very similar path of exponential growth. <i>We're all in this together.</i> <span v-if="isHidden"><a @click="toggleHide">Learn more.</a></span></p>

<span v-if="!isHidden">

Expand Down Expand Up @@ -112,6 +112,8 @@ <h2>Customize</h2>
</option>
</select>

<br><br>Days to look back: {{slopeDays}} <input style="width:100%" type="range" min="1" max="14" value="7" class="slider" v-model="slopeDays">

</div>

<div id="countries">
Expand Down
16 changes: 12 additions & 4 deletions vue-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Vue.component('graph', {
color: 'rgba(0,0,0,0.15)'
},
hoverinfo:'x+y+text',
hovertemplate: '%{text}<br>Total ' + this.selectedData +': %{x:,}<br>Weekly ' + this.selectedData +': %{y:,}<extra></extra>',
hovertemplate: '%{text}<br>Total ' + this.selectedData +': %{x:,}<br>Last ' + this.$parent.$data.slopeDays + ' days ' + this.selectedData +': %{y:,}<extra></extra>',
})
);

Expand All @@ -104,7 +104,7 @@ Vue.component('graph', {
size: 6,
color: 'rgba(254, 52, 110, 1)'
},
hovertemplate: '%{data.text}<br>Total ' + this.selectedData +': %{x:,}<br>Weekly ' + this.selectedData +': %{y:,}<extra></extra>',
hovertemplate: '%{data.text}<br>Total ' + this.selectedData +': %{x:,}<br>Last ' + this.$parent.$data.slopeDays + ' days ' + this.selectedData +': %{y:,}<extra></extra>',

})
);
Expand Down Expand Up @@ -140,7 +140,7 @@ Vue.component('graph', {
},
},
yaxis: {
title: 'New ' + this.selectedData + ' (in the Past Week)',
title: 'New ' + this.selectedData + ' (in the Past ' + this.$parent.$data.slopeDays + ' days)',
type: this.scale == 'Logarithmic Scale' ? 'log' : 'linear',
range: this.yrange,
titlefont: {
Expand Down Expand Up @@ -388,6 +388,12 @@ let app = new Vue({
}
},

slopeDays() {
if (!this.firstLoad) {
this.pullData(this.selectedData, this.selectedRegion, /*updateSelectedCountries*/ false);
}
},

minDay() {
if (this.day < this.minDay) {
this.day = this.minDay;
Expand Down Expand Up @@ -530,7 +536,7 @@ let app = new Vue({
for (let date of dates) {
arr.push(row[date]);
}
let slope = arr.map((e,i,a) => e - a[i - 7]);
let slope = arr.map((e,i,a) => e - a[i - this.slopeDays]);
let region = row.region

if (Object.keys(renames).includes(region)) {
Expand Down Expand Up @@ -758,6 +764,8 @@ let app = new Vue({

day: 7,

slopeDays: 7,

icon: 'icons/play.svg',

scale: ['Logarithmic Scale', 'Linear Scale'],
Expand Down