Published
Edited
May 12, 2020
Fork of Choropleth
Insert cell
Insert cell
us
Insert cell
html `<svg height = 600 width = ${width}>
${topojson.feature(us, us.objects.counties).features.map(d => {
return `<path d = ${path(d)} style = "stroke:red"></path>`;
})}
</svg>`
Insert cell
basic_map = {
const svg = d3.create("svg")
.attr("width", width)
.attr("height", 600);
const paths = svg.selectAll("path").data(topojson.feature(us, us.objects.nation).features)
.join("path")
.style("stroke", "red")
.attr("fill", "none")
.attr("d", d => path(d));
return svg.node();
}
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, 975, 610]);

svg.append("g")
.attr("transform", "translate(610,20)")
.append(() => legend({color, title: data.title, width: 260}));

svg.append("g")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.join("path")
.attr("fill", d => color(data.get(d.id)))
.attr("d", path)
.append("title")
.text(d => `${d.properties.name}, ${states.get(d.id.slice(0, 2)).name}
${format(data.get(d.id))}`);

// svg.append("path")
// .datum(topojson.mesh(us, us.objects.states, (a, b) => a !== b))
// .attr("fill", "none")
// .attr("stroke", "white")
// .attr("stroke-linejoin", "round")
// .attr("d", path);

return svg.node();
}
Insert cell
data = Object.assign(new Map(d3.csvParse(await FileAttachment("unemployment-x.csv").text(), ({id, rate}) => [id, +rate])), {title: "Unemployment rate (%)"})
Insert cell
color = d3.scaleQuantize([1, 10], d3.schemeBlues[9])
Insert cell
path = d3.geoPath()
Insert cell
format = d => `${d}%`
Insert cell
states = new Map(us.objects.states.geometries.map(d => [d.id, d.properties]))
Insert cell
us = FileAttachment("counties-albers-10m.json").json()
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
Insert cell
import {legend} from "@d3/color-legend"
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