var legend = function(accessor){ return function(selection){ //Draw the legend for the map var legend = selection.append("g"); var legendText = accessor.title; var numSquares = accessor.elements; var xLegend = 0; var yLegend = 0; var widthLegend = 400; var title_g = legend.append("g"); var values_g = legend.append("g"); var legendTitle = title_g.append("text") .text("Legend") .attr("font-family", "sans-serif") .attr("font-size", "18px") .attr("fill", "black"); var bbox = legendTitle.node().getBBox(); legendTitle.attr("x", xLegend + widthLegend/2 - bbox.width/2); legendTitle.attr("y", yLegend + 20); var legendTextEl = title_g.append("text") .text(legendText) .attr("y", yLegend + 75) .attr("font-family", "sans-serif") .attr("font-size", "14px") .attr("fill", "black"); var bbox = legendTextEl.node().getBBox(); legendTextEl.attr("x", xLegend + widthLegend/2 - bbox.width/2); for (i=0; i