Published
Edited
May 30, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cases = d3.csvParse(
`date,local,imported,source
2021-01-20,0,9,https://www.shine.cn/news/metro/2101213536/
2021-01-21,6,3,https://www.shine.cn/news/metro/2101213552/
2021-01-22,3,8,https://www.shine.cn/news/metro/2101233648/
2021-01-23,3,3,https://www.shine.cn/news/metro/2101243681/
2021-01-24,1,2,https://www.shine.cn/news/metro/2101253732/
2021-01-25,2,8,https://www.shine.cn/news/metro/2101263806/
2021-01-26,1,5,https://www.shine.cn/news/metro/2101273891/
2021-01-27,0,7,https://www.shine.cn/news/metro/2101283970/
2021-01-28,0,9,https://www.shine.cn/news/metro/2101294033/
2021-01-29,2,9,https://www.shine.cn/news/metro/2101304076/
2021-01-30,0,7,https://www.shine.cn/news/metro/2101314100/
2021-01-31,0,4,https://www.shine.cn/news/metro/2102014132/
`,
createRowConverter({ local: Number, imported: Number })
)
Insert cell
cumulativeLocal = addCumulativeProperty(cases, 'local', 'cumulative_local')
Insert cell
Insert cell
addCumulativeProperty = (data, countProperty, cumulativeProperty) =>
data.reduce(
([acc, total], rec) => {
const totalʹ = total + Number(rec[countProperty]);
return [[...acc, { ...rec, [cumulativeProperty]: totalʹ }], totalʹ];
},
[[], 0]
)[0]
Insert cell
createRowConverter = typeMap => data =>
Object.fromEntries(
Object.entries(data).map(([k, v]) => [k, (typeMap[k] || (v => v))(v)])
)
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell
import {table} from "@tmcw/tables@513"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more