Published
Edited
Dec 20, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
json_from_github = d3.json(
"https://raw.githubusercontent.com/hodcroftlab/covariants/master/web/data/perCountryData.json"
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mapper = (d) => {
/* Provide a count for each of the five variants we are interested in and other */
let { cluster_counts, week, total_sequences } = d;

let myObject = {};
myObject.week = week;

let total_counted = Object.values(cluster_counts).reduce(
(previousValue, currentValue) => {
return previousValue + currentValue;
},
0
);

let counts = {};

counts.alpha = 0;
counts.beta = 0;
counts.gamma = 0;
counts.delta = 0;
counts.omicron = 0;
counts.other = total_sequences - total_counted;

Object.keys(cluster_counts).forEach((key) => {
switch (key) {
case "20I (Alpha, V1)":
counts.alpha += cluster_counts[key];
break;
case "20H (Beta, V2)":
counts.beta += cluster_counts[key];
break;
case "20J (Gamma, V3)":
counts.gamma += cluster_counts[key];
break;
case "21A (Delta)":
case "21I (Delta)":
case "21J (Delta)":
counts.delta += cluster_counts[key];
break;
case "21K (Omicron)":
counts.omicron += cluster_counts[key];
default:
counts.other += cluster_counts[key];
}
});

myObject.counts = counts;

return myObject;
}
Insert cell
reducer = (previousValue, currentValue) => {
/* Create a flat array of objects, each containing variant, count and week values */
let { week, counts } = currentValue;

Object.keys(counts).forEach((key) => {
let myObject = {};
myObject.variant = key;
myObject.count = counts[key];
myObject.week = new Date(week);

previousValue.push(myObject);
});

return previousValue;
}
Insert cell
Insert cell
Insert cell
import { swatches as Swatches } from "@d3/color-legend"
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