Public
Edited
Apr 3, 2022
5 forks
Insert cell
Insert cell
Insert cell
viewof year = Inputs.range([1961, 2011], {label: "Year", step:1, value:1994})
Insert cell
map = d3.select(mapContainer)
Insert cell
import {getMapData, drawMapLayer} from "@emfielduva/dvlib_maps"
Insert cell
world = getMapData("world110m")
Insert cell
mapLayers = {
let mapLayers = [];
mapLayers["countries"] = drawMapLayer(map,"countries",world.features,world.idField);
return mapLayers;
}
Insert cell
<style>
#countries path {fill: #eeeeee; stroke: #ccc}
</style>
Insert cell
Insert cell
Insert cell
gdp = FileAttachment("world-gdp-growth.csv").csv()
Insert cell
Insert cell
import {colorByID, toNum} from "@emfielduva/dvlib"
Insert cell
Insert cell
colorScale = d3.scaleLinear().domain([-25,0,25]).range(["red","gray","green"])
Insert cell
Insert cell
//year = "1994" // this is commented out to use the range slider at the top to define year
Insert cell
Now invoke the colorByID function imported.
This connects the "Country Code" in the gdp dataset to the "id" in the geographic map data.
The syntax of this command is:
Insert cell
colorByID
Insert cell
Insert cell
colorByID(mapLayers["countries"],gdp,"id","Country Code",year,'',colorScale)
Insert cell
Insert cell
Insert cell
// data.forEach(d => {
// objectSet.filter(o=>o[objectIDfield] == d[dataIDfield])
// .style("fill",colorScale(toNum(d[dataValueField])))
// })
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