{
let width = 480,
height = 640,
legendCircleRadius = 10,
legendSpacing = legendCircleRadius * 2.5,
legendX = 150,
legendY = 350,
legendWidth = 150;
let projection = d3.geoAlbers().scale(4500).translate([28, 900]);
let path = d3.geoPath(projection);
let svg = d3.create('svg').attr('width', width).attr('height', height);
svg.append('svg:g')
.append("path")
.attr("d", path(topojson.mesh(states, states.objects.states)))
.attr('fill', 'none')
.attr('stroke', 'gray');
let legendData = ['red', 'blue'];
let legendEntries = svg.append('svg:g')
.selectAll('g.legendRow')
.data(legendData)
.join('g')
.attr('transform', (d, i) => `translate(${width - legendX},${height - legendY + legendCircleRadius + i * legendSpacing})`);
legendEntries.append('rect')
.attr('x', -legendCircleRadius)
.attr('y', -legendCircleRadius)
.attr('width', legendWidth)
.attr('height', legendSpacing)
.attr('fill', 'white')
legendEntries.append('circle')
.attr('r', legendCircleRadius)
.attr('opacity', 0.5)
.attr('fill', d => d);
legendEntries.append('text')
.attr('x', legendCircleRadius * 2)
.attr('y', legendCircleRadius / 2)
.text(d => d);
return svg.node();
}