function makeBarLegend(root, height, max) { var band = 6; var scale = d3.scale.linear() .domain([0, max]) .range([height, 0]); var axis = d3.svg.axis() .scale(scale) .ticks(8) .tickSize(6) .orient('right'); var group = root.append('g'); root.append('g') .attr('transform', 'translate(6,0)') .attr('class', 'axis') .call(axis); function update(event, duration) { var r = group.selectAll('rect') .data(event); r.enter().append('rect') .attr('width', band) .attr('height', 0) .attr('y', height) .style('fill', function (d) { return d.color; }); r.exit().remove(); group.selectAll('rect').transition().duration(duration) .attr('y', function (d) { return scale(d.y1); }) .attr('height', function (d) { return scale(d.y0) - scale(d.y1); }) .style('fill', function (d) { return d.color; }); } return { update: update }; }