Published
Edited
Mar 31, 2020
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = cntry_data_raw.concat(us_state_data).filter(d => selected_regions.includes(d.region)).map(function(d) {
d.confirmed = add_past_week_number(d.confirmed);
d.deaths = add_past_week_number(d.deaths);
return d;
})
Insert cell
function add_past_week_number(a) {
var new_array = [[a[0][0], a[0][1], a[0][1]]];
var curr_sum = 0;
var min_idx = 0;
for (var i = 1; i < a.length; i++) {
min_idx = d3.max([0, i-7]);
if (min_idx != 0) {
curr_sum = a[i][1] - a[min_idx][1];
} else {
curr_sum = a[i][1];
}
new_array.push([ a[i][0], a[i][1], curr_sum ])
}
return new_array;
}
Insert cell
Insert cell
us_state_data = us_state_data_raw.map(d => ({
'country_code': d.code,
'country_name': d.name,
'region': "US States",
'confirmed': d.confirmed,
'deaths': d.deaths,
}))
Insert cell
us_state_data_raw = d3.json("https://raw.githubusercontent.com/covid19-data/covid19-data/master/output/us_state_nyt.json")
Insert cell
cntry_data_raw = d3.json("https://raw.githubusercontent.com/covid19-data/covid19-data/master/output/cntry_stat_owid.json")
Insert cell
Insert cell
import {autoSelect} from "@jashkenas/inputs"

Insert cell
import {swatches} from "@d3/color-legend"
Insert cell
import {Scrubber} from "@mbostock/scrubber"
Insert cell
import {checkbox} from "@jashkenas/inputs"

Insert cell
import {radio} from "@jashkenas/inputs"
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more