Published
Edited
Apr 14, 2020
Insert cell
Insert cell
wtf = require('wtf_wikipedia')
Insert cell
tables = {
//grab and parse the wiki article
let doc = await wtf.fetch('Template:2019–20 coronavirus outbreak data/WHO situation reports')
// grab each table, and convert it to json
return doc.tables().map(t => t.json())
}
Insert cell
Insert cell
Insert cell
casesByCountry = {
let byCountry = []
// grab one country's data from each table
tables.forEach(rows => {
rows.forEach(row => {
row.Date=row.Date||{}
let str = row.Date.text || '' // normalize the country name
str = str.toLowerCase()
// this row is about the country
if (str.includes(country)) {
// add each column of our row
Object.keys(row).forEach(date => {
//cleanup the data format a little bit
if (date !== 'Date' && date !== 'First reported case') {
byCountry.push([date.replace(/-/g,' '), row[date].number || 0])
}
})
}
})
})
return byCountry
}
Insert cell
Insert cell
somehow = require('somehow-graph')
Insert cell
{
let world = somehow({
aspect: 'golden' // set x/y ratio of svg
})

// create a shape
let line = world.line()

// feed it some data..
line.set(casesByCountry)

//automatically set size of x/y axis
world.fit()

// throw it into the page
return html`${world.build()}`
}
Insert cell
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