Published
Edited
Jan 3, 2021
Fork of Testen
Insert cell
Insert cell
{
const bars = vl.markBar().encode(
vl.y(vl.fieldN("WEEK")).title(null).axis({labels: false, ticks: false, offset: -25}),
vl.x(vl.fieldQ("TESTS_ALL")).title(null),
vl.color(vl.fieldN("WEEK")).legend(null)
);
const text = vl.markText({color: "white", dy: 1}).encode(
vl.y(vl.fieldN("WEEK")),
vl.x(vl.value(33)),
vl.text(vl.fieldN("DATE"))
);
return vl.layer(bars, text)
.facet({field: 'DAY', sort: ["Ma", "Di", "Wo"], title: null, header: {labelOrient: "left", labelAngle: 0, labelAlign: "left"}}).columns(1)
.data(tests.filter(d => new Date(d.DATE) >= new Date("2020-11-30")).filter(d => new Date(d.DATE) <= new Date("2021-01-01")))
//.resolve({axis: {x: "independent"}})
//.title("Aantal uitgevoerde testen per dag")
.config({view: {stroke: null}})
.render();
}
Insert cell
vl.markCircle({opacity: 1}).encode(
vl.x(vl.fieldT("DATE")).title(null).axis({tickCount: 5}),
vl.y(vl.fieldQ("RATIO")).axis({format: "%", tickCount: 10}).title("Positiviteitsratio"),
vl.color(vl.fieldN("WEEK")).legend(null)
)
.data(tests.filter(d => new Date(d.DATE) >= new Date("2020-11-30")).filter(d => new Date(d.DATE) <= new Date("2021-01-01")))
.config({view: {stroke: null}})
.width(350)
.height(250)
.render();
Insert cell
Insert cell
tests.map((d, i) => {return {date: d.DATE, diff: 1-d.TESTS_ALL/tests[Math.max(0,i - 7)].TESTS_ALL}}).slice(-30)
Insert cell
Insert cell
tests_raw = (await(await fetch("https://epistat.sciensano.be/Data/COVID19BE_tests.json")).json())
Insert cell
tests = {
const results = [];
d3.rollup((await (await fetch("https://epistat.sciensano.be/Data/COVID19BE_tests.json")).json()),
v => {return {TESTS_ALL : d3.sum(v, d => d.TESTS_ALL), TESTS_ALL_POS : d3.sum(v, d => d.TESTS_ALL_POS)}}, d => d.DATE)
.forEach((tests, date) => {results.push({DATE: date, DAY: d3.timeFormat("%a")(new Date(date)), WEEK: d3.timeFormat("%G%V")(new Date(date)), TESTS_ALL: tests.TESTS_ALL, TESTS_ALL_POS: tests.TESTS_ALL_POS, RATIO: tests.TESTS_ALL_POS / tests.TESTS_ALL})
})
results.forEach(d => {
if (d.DAY === "Mon") d.DAY = "Ma";
if (d.DAY === "Tue") d.DAY = "Di";
if (d.DAY === "Wed") d.DAY = "Wo";
if (d.DAY === "Thu") d.DAY = "Do";
if (d.DAY === "Fri") d.DAY = "Vr";
if (d.DAY === "Sat") d.DAY = "Za";
if (d.DAY === "Sun") d.DAY = "Zo";
})
return results;
}
Insert cell
Insert cell
old.slice(-10);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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