Published
Edited
May 7, 2019
1 fork
Insert cell
Insert cell
world_topo = d3.json("https://gist.githubusercontent.com/jk979/730705d49dc4d57eb3d2af0443c17027/raw/69b92aaf06c0399b94e3b8a3af083f33f73ba0d6/world_topojson.json")
Insert cell
//countries = topojson.feature(world_topo, world_topo.objects.world_map_geojson).geometries
Insert cell
Insert cell
Insert cell
Insert cell
{
let svg = d3.select(DOM.svg(width, height));

let value = null;

let g = svg.append("g");

var countries = topojson.feature(world_topo, world_topo.objects.world_map_geojson).features

const outline = svg.append("path")
.attr("fill", "green")
.attr("stroke", "green")
.attr("stroke-width", "3px")
.attr("stroke-linejoin", "round")
.attr("pointer-events", "none");
svg.selectAll(".country")
.data(countries)

.enter().insert("path", ".graticule")
.attr("class", function(d) { return "country " + "code" + d.id; })
.attr("d", geoPath)
.style("fill", "lightgrey")
//d => color(neigh[d.properties.OBJECTID]))
.on("mouseover", d => {
const node = svg.node();
node.value = value = value === d.properties.ADMIN ? null : d.properties.ADMIN;
node.dispatchEvent(new CustomEvent("input"));
outline.attr("d", value ? geoPath(d) : null);
})
.on("click", d => {
const node = svg.node();
node.value = value = value === d.properties.OBJECTID ? null : d.properties.OBJECTID;
node.dispatchEvent(new CustomEvent("input"));
outline.attr("d", value ? path(d) : null);
});
svg.append("g");

return Object.assign(svg.node(), {value: null});

}

Insert cell
width = 700
Insert cell
height = 600
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