Public
Edited
Apr 17, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//DOM.download(() => serialize1(svg), undefined, "Save as SVG")
Insert cell
Insert cell
regionColor = function(region) {
var colors = {
"Middle East": "#596F7E",
"America": "#168B98",
"East Asia": "#ED5B67",
"Africa": "#fd8f24",
"Western Europe": "#919c4c"
};
return colors[region];
}
Insert cell
//colors = ["red", "orange", "green", "blue"]
Insert cell
colorScale = d3.scaleOrdinal()
.domain(["Middle East", "America", "East Asia", "Africa"])
.range(["#596F7E", "#168B98", "#ED5B67", "#fd8f24"]);
Insert cell
function colorHierarchy(hierarchy) {
if(hierarchy.depth === 0) {
hierarchy.color = 'black';
} else if(hierarchy.depth === 1){
hierarchy.color = regionColor(hierarchy.data.key);
} else {
hierarchy.color = hierarchy.parent.color;
}
if(hierarchy.children) {
hierarchy.children.forEach( child => colorHierarchy(child))
}
}
Insert cell
Insert cell
Insert cell
Insert cell
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