Skip to content

Commit

Permalink
Preserve tick ordering when updating axis.
Browse files Browse the repository at this point in the history
Fixes d3#1748.
mbostock committed Mar 24, 2014
1 parent b86e4e4 commit abbe1c7
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion d3.js
Original file line number Diff line number Diff line change
@@ -8686,7 +8686,7 @@
g.each(function() {
var g = d3.select(this);
var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickTransform;
var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
d3.transition(path));
tickEnter.append("line");
2 changes: 1 addition & 1 deletion d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/svg/axis.js
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ d3.svg.axis = function() {
tick = g.selectAll(".tick").data(ticks, scale1),
tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε),
tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(),
tickUpdate = d3.transition(tick).style("opacity", 1),
tickUpdate = d3.transition(tick.order()).style("opacity", 1),
tickTransform;

// Domain.
9 changes: 9 additions & 0 deletions test/svg/axis-test.js
Original file line number Diff line number Diff line change
@@ -486,6 +486,15 @@ suite.addBatch({
assert.isFalse(t.select("text").empty());
assert.equal(t.select("text").text(), tickFormat(ticks[i]));
});
},
"maintains the order of tick marks": function(d3) {
var a = d3.svg.axis(),
g = d3.select("body").html("").append("g").call(a),
x = d3.scale.linear().domain([1, 1.5]);
a.scale().domain(x.domain());
g.call(a.ticks(10));
g.call(a.ticks(20));
assert.deepEqual(g.selectAll(".tick").data(), x.ticks(20));
}
}
}

0 comments on commit abbe1c7

Please sign in to comment.