implmented the legend for d3