Public
Edited
Apr 3, 2022
4 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

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