map = () => {
const svg = d3.create("svg")
.attr("width", mapwidth)
.attr("height", mapheight)
.style("overflow", "visible");
svg.append("style").html(css);
svg.append("path")
.datum(statesInner)
.attr("class", "inner")
.attr("d", path);
svg.append("path")
.datum(statesOuter)
.attr("class", "outer")
.attr("d", path);
svg.selectAll(".circle")
.data(statesData)
.join("circle")
.attr("fill", colors.lighter)
.attr("r", d => r(d.barrels))
.attr("stroke", colors.darker)
.attr("transform", d => `translate(${projection(d.centroid)})`)
const annotation = svg.selectAll(".annotation")
.data(annotations)
.join("g")
.attr("class", "annotation")
.attr("transform", d => {
const mid = projection(d.centroid);
const edge = geometric.pointTranslate(mid, d.angle, r(d.barrels))
return `translate(${edge})`;
});
annotation.append("polyline")
.attr("points", d => [[0, 0], [d.x, d.y]])
.attr("stroke", "black")
annotation.append("text")
.attr("class", "bg state")
.attr("dx", d => d.dx)
.attr("dy", d => d.dy)
.attr("text-anchor", d => d.textAnchor)
.attr("x", d => d.x)
.attr("y", d => d.y)
.text(d => d.state);
annotation.append("text")
.attr("class", "fg state")
.attr("dx", d => d.dx)
.attr("dy", d => d.dy)
.attr("text-anchor", d => d.textAnchor)
.attr("x", d => d.x)
.attr("y", d => d.y)
.text(d => d.state);
annotation.append("text")
.attr("class", "bg value")
.attr("dx", d => d.dx)
.attr("dy", d => d.dy + 18)
.attr("text-anchor", d => d.textAnchor)
.attr("x", d => d.x)
.attr("y", d => d.y)
.text(d => `${formatNumber(d.barrels)} barrels`);
annotation.append("text")
.attr("class", "fg value")
.attr("dx", d => d.dx)
.attr("dy", d => d.dy + 18)
.attr("text-anchor", d => d.textAnchor)
.attr("x", d => d.x)
.attr("y", d => d.y)
.text(d => `${formatNumber(d.barrels)} barrels`);
return svg.node()
}