Published
Edited
Aug 27, 2020
1 fork
Insert cell
Insert cell
map = {
let map = d3
.create("svg")
.attr("width", map_width)
.attr("height", map_height);
// .attr("viewBox", [0, 0, map_width, map_height]);

let county_group = map
.append("g")
.selectAll('path')
.data(counties.features)
.enter()
.append('path')
.attr('d', geoGenerator)
.style('stroke', 'black')
.style('stroke-width', '1px')
.style('fill', d => d3.interpolateBlues((d.properties.POP / M) ** 0.4))
.attr('title', function(d) {
console.log(d.properties);
return `${d.properties.NAMELSAD}: Population ${d.properties.POP}`;
});
// To use native tooltips, rather than TippyJS, use the following code:
// .append('title')
// .text(function(d) {
// console.log(d.properties);
// return `${d.properties.NAMELSAD}: Population ${d.properties.POP}`;
// });

county_group.nodes().forEach(tippy);

return map.node();
}
Insert cell
M = d3.max(counties.features.map(c => c.properties.POP))
Insert cell
geoGenerator = d3.geoPath().projection(projection)
Insert cell
projection = d3
.geoIdentity()
.reflectY(true)
.fitSize([map_width, map_height], counties)
Insert cell
counties = topojson.feature(nc, nc.objects.nc_counties)
Insert cell
nc = FileAttachment('county_pops.json').json()
Insert cell
map_height = 0.6 * map_width
Insert cell
map_width = 0.9 * width
Insert cell
tippy = require("https://unpkg.com/tippy.js@2.5.4/dist/tippy.all.min.js")
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require('d3@6')
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