Permalink
Browse files

Name all selections in bar chart

Explicitly assigning these selections to variables gives other
developers a clearer path to modification.
  • Loading branch information...
jugglinmike committed Mar 2, 2013
1 parent a4d13f5 commit 9f671eaefc5e8ed7a8c9e6d21efe0d00c7e383eb
Showing with 11 additions and 5 deletions.
  1. +11 −5 scripts/bar-chart.js
View
@@ -20,21 +20,27 @@ window.BarChart = function(options) {
var rect = svg.selectAll("rect")
.data(data, function(d) { return d.time; });
var entering = rect.enter().insert("rect", "line");
var enteringTrans = entering.transition();
var exiting = rect.exit();
var trans = rect.transition();
var exitingTrans = exiting.transition();
rect.enter().insert("rect", "line")
entering
.attr("x", function(d, i) { return x(i + 1) - .5; })
.attr("y", function(d) { return h - y(d.value) - .5; })
.attr("width", w / data.length)
.attr("height", function(d) { return y(d.value); })
.transition()
.attr("height", function(d) { return y(d.value); });
enteringTrans
.duration(1000)
.attr("x", function(d, i) { return x(i) - .5; });
rect.transition()
trans
.duration(1000)
.attr("x", function(d, i) { return x(i) - .5; });
rect.exit().transition()
exitingTrans
.duration(1000)
.attr("x", function(d, i) { return x(i - 1) - .5; })
.remove();

0 comments on commit 9f671ea

Please sign in to comment.