Published
Edited
Nov 14, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
color = d3.scaleSequentialLog(d3.interpolateInferno).domain([1, 100])
Insert cell
ages = d3.range(80, -10, -10)
Insert cell
getLatestDate(patients)
Insert cell
weeks = d3.range(-33, 1).map(d => {
const originDate = new Date(getLatestDate(patients).getTime()); //new Date('2020-11-01');

return new Date(originDate.setDate(originDate.getDate() + d * 7));
})
Insert cell
patientsRollup.keys().next()
Insert cell
{
for (const munic of patientsRollup) {
console.log(munic);
}
}
Insert cell
inpatientsRollup = {
const rollup = d3.rollup(inpatients, v => v.length, d => d.居住地);
return sortMap(rollup);
}
Insert cell
patientsRollup = {
const rollup = d3.rollup(patients, v => v.length, d => d.居住地);
return sortMap(rollup);
}
Insert cell
patientsRollups = Array.from(
d3.rollups(patients, v => v.length, d => d.居住地),
([key, value]) => ({
key,
value
})
)
.sort((a, b) => b.value - a.value)
.map(d => ({
inpatients: patients.filter(
e => e.居住地 === d.key && e['退院・解除'] !== '○'
).length,
...d
}))
Insert cell
groups = d3
.groups(patients, d => d.居住地)
.sort((a, b) => b[1].length - a[1].length)
Insert cell
group = Array.from(d3.group(patients, d => d.居住地), ([key, value]) => ({
key,
value
}))
Insert cell
inpatients = patients.filter(d => d['退院・解除'] !== '○')
Insert cell
getAges(patientsOfWeek(new Date('2020-11-01')))
Insert cell
getAges = patients =>
Array.from(
d3.groups(patients.filter(d => d.age >= 0), d => d.age),
([key, value]) => ({ key, value })
).sort((a, b) => b.key - a.key)
Insert cell
patientsOfWeek(new Date('2020-11-01'))
Insert cell
patientsOfWeek = date => {
const fromDate = new Date(date).setDate(date.getDate() - 7);
return patients.filter(d => d.報道提供日 > fromDate && d.報道提供日 <= date);
}
Insert cell
getLatestDate(patients)
Insert cell
getLatestDate = data => d3.max(data, d => d.報道提供日)
Insert cell
d3.group(patients, d => d.年代)
Insert cell
d3.group(patients, d => d.age)
Insert cell
d3.group(_patients, d => d.age)
Insert cell
patients = getCases('Osaka', 80)
Insert cell
_patients = d3.csvParse(csvString, d3.autoType).map(d => ({
age:
d.年代 === '未就学児' || d.年代 === '就学児'
? 0
: d.年代 === 90 || d.年代 === 100
? 80
: +d.年代,
...d
}))
Insert cell
csvString = iconv.decode(arrayData, 'Shift_JIS')
Insert cell
arrayData = new Uint8Array(
// await d3.buffer(`https://cors-anywhere.herokuapp.com/${uri}`)
await d3.buffer(`https://sugi2000cors.herokuapp.com/${uri}`)
)
Insert cell
Insert cell
md`#### 人口データ
大阪府 市区町村別,年齢(5歳階級)別推計人口 令和2年9月1日現在
http://www.pref.osaka.lg.jp/toukei/jinkou/jinkou-xlslist.html
`
Insert cell
Insert cell
agePops = d3.tsvParse(agePopsData)
Insert cell
agePopsData = `市 区 町 村 総 数 0~4歳 5~9歳 10~14歳 15~19歳 20~24歳 25~29歳 30~34歳 35~39歳 40~44歳 45~49歳 50~54歳 55~59歳 60~64歳 65~69歳 70~74歳 75~79歳 80~84歳 85歳以上
大阪府 8,820,028 326,450 350,750 370,045 404,803 487,948 484,889 489,793 524,355 597,001 728,987 653,874 547,753 461,688 516,958 619,294 518,930 377,313 359,195`
Insert cell
sortMap = map => new Map([...map.entries()].sort((a, b) => b[1] - a[1]))
Insert cell
import { getCases, getPrefectureData } from "@sugi2000/covid-19-data-in-japan"
Insert cell
iconv = require('https://bundle.run/iconv-lite@0.6.2')
Insert cell
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