Published
Edited
Mar 13, 2022
Importers
2 stars
Also listed in…
featured
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
legend = g => {
const legend = g.append("g")
.attr("id", "legend")
.attr("transform", `translate(75, ${height - 80})`)
const items = legend.selectAll("g.item")
.data([5000, 35000, 100000])
.join("g")
.classed("item", true);
items.append("circle")
.attr("r", d => radius(d))
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("stroke-width", 1)
.attr("cy", d => -radius(d));
items.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "-0.4em")
.text((d, i) => {
d = d.toLocaleString();
return i === 2 ? `>= ${d}` : d;
})
legend.append("text")
.classed("title", true)
.attr("y", 20)
.attr("dy", "-0.4em")
.text("Persons Affected")
const colorLegend = g.append("g")
.attr("id", "color-legend")
.attr("transform", `translate(12, ${height - 45})`);
colorLegend.append("image")
.attr("width", 125)
.attr("height", 10)
.attr("preserveAspectRatio", "none")
.attr("xlink:href", ramp(color.interpolator()).toDataURL());
colorLegend.append("g")
.attr("transform", `translate(0, 10)`)
.call(d3.axisBottom(xScale)
.tickValues(color.domain()))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick line").attr("y1", -10))
.call(g => g.append("text")
.classed("title", true)
.attr("x", 20)
.attr("y", 18)
.attr("text-anchor", "middle")
.text("Months Unresolved"))
}
Insert cell
Insert cell
styles = html`<style>
.map-container {
position: relative;
}

text {
font-family: sans-serif;
font-size: 14px;
fill: #777;
}

#legend text,
#color-legend text {
font-size: 10px;
font-weight: 500;
text-anchor: middle;
}

#color-legend .tick line {
stroke: #777;
}

#color-legend .title {
text-anchor: start;
}

.map-tooltip {
position: absolute;
display: none;

height: auto;
max-width: 250px;
padding: 6px;
border: 1px solid #333;
border-radius: 5px;
background: #fff;

font-family: sans-serif;
color: #333;
}

.map-tooltip > p {
font-size: 12px;
margin: 0;
}

.map-tooltip > p > .name {
font-weight: bold;
}

.map-tooltip > p.months > .value {
padding: 2px 6px;
font-weight: bold;
}
</style>`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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