d = svg.selectAll(".legend")
                .data(keysall)
                .enter().append("g")
                .attr("class", "legend")
                .attr("transform", function(d, i) { return "translate(" + (innerWidth + 130) + "," + (i * 20 + 140) + ")"; });
			
            // draw legend colored rectangles
            legend.append("rect")
            .data(keysall) 
            .attr("x", 0)
            .attr("y", 0)
            .attr("width", 30)
            .attr("height", 15)
            .style("