Published
Edited
Dec 6, 2018
2 forks
3 stars
Also listed in…
SF Bay Area Jobs Viz
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof svg = {
const svg = d3.select(DOM.svg(width, height))
.style("width", "100%")
.style("height", "auto")
.call(zoom)
// background
svg.append("rect")
.attr("width", width)
.attr("height", height)
.attr("x", 0)
.attr("y", 0)
.attr("fill", "hsl(0, 0%, 96%)")
// choropleth
const g = svg.append("g")
.classed("map-layers", true)
g.selectAll("path")
.data(geojson.features)
.enter().append("path")
.attr("class", d => quantile(d.properties[category]))
.attr("d", path)
.append("title")
.text(d => `${format(d.properties[category])} / sq meter`)
g.append("path")
.datum(topojson.mesh(tractsTopoJSON, tractsTopoJSON.objects.tracts_jobs_2002_wgs84))
.attr("fill", "none")
.attr("stroke-width", 0.05)
.attr("stroke", "purple")
.attr("stroke-linejoin", "round")
.attr("d", path);
// legend
const legend = svg.append("g")
.classed("legend", true)
.attr("transform", `translate(20, ${height - 60})`)
legend.selectAll("rect")
.data(quantile.range())
.enter().append("rect")
.attr("height", 8)
.attr("width", x.bandwidth())
.attr("x", d => x(d))
.attr("class", d => d)
legend.append("g")
.attr("transform", "translate(0, 5)")
.call(d3.axisBottom(x))
legend.select(".domain").remove()
legend.selectAll(".tick > line").remove()
return svg.node()
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function zoom (s) {
s.call(d3.zoom()
.on("zoom", () => s.select(".map-layers").attr("transform", d3.event.transform))
.scaleExtent([1, 18])
.translateExtent([[0, 0], [width, height]]))
}
Insert cell
Insert cell
Insert cell
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