Skip to content

Commit

Permalink
Fix transitioning styles to null (removal).
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondavies committed Oct 5, 2011
1 parent fe61281 commit 878d1c1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
15 changes: 14 additions & 1 deletion d3.js
Expand Up @@ -1856,9 +1856,18 @@ function d3_transition(groups, id) {
return groups;
}

function d3_transitionTweenNull() {
return d3_transitionTweenNullNull;
}

function d3_transitionTweenNullNull() {
return null;
}

function d3_transitionTween(b) {
return typeof b === "function"
? function(d, i, a) { var v = b.call(this, d, i) + ""; return a != v && d3.interpolate(a, v); }
: b == null ? d3_transitionTweenNull
: (b = b + "", function(d, i, a) { return a != b && d3.interpolate(a, b); });
}

Expand Down Expand Up @@ -1951,7 +1960,11 @@ d3_transitionPrototype.styleTween = function(name, tween, priority) {
return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
return f && function(t) {
this.style.setProperty(name, f(t), priority);
if ((t = f(t))) {
this.style.setProperty(name, t, priority);
} else {
this.style.removeProperty(name);
}
};
});
};
Expand Down
4 changes: 2 additions & 2 deletions d3.min.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/core/transition-style.js
Expand Up @@ -8,7 +8,11 @@ d3_transitionPrototype.styleTween = function(name, tween, priority) {
return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
return f && function(t) {
this.style.setProperty(name, f(t), priority);
if ((t = f(t))) {
this.style.setProperty(name, t, priority);
} else {
this.style.removeProperty(name);
}
};
});
};
9 changes: 9 additions & 0 deletions src/core/transition.js
Expand Up @@ -85,9 +85,18 @@ function d3_transition(groups, id) {
return groups;
}

function d3_transitionTweenNull() {
return d3_transitionTweenNullNull;
}

function d3_transitionTweenNullNull() {
return null;
}

function d3_transitionTween(b) {
return typeof b === "function"
? function(d, i, a) { var v = b.call(this, d, i) + ""; return a != v && d3.interpolate(a, v); }
: b == null ? d3_transitionTweenNull
: (b = b + "", function(d, i, a) { return a != b && d3.interpolate(a, b); });
}

Expand Down
7 changes: 6 additions & 1 deletion test/core/transition-test-style.js
Expand Up @@ -9,9 +9,11 @@ module.exports = {

var s = d3.select("body").append("div")
.style("background-color", "white")
.style("color", "red");
.style("color", "red")
.style("display", "none");

var t = s.transition()
.style("display", null)
.style("background-color", "green")
.style("background-color", "red")
.style("color", function() { return "green"; }, "important")
Expand All @@ -34,5 +36,8 @@ module.exports = {
var style = result.selection.node().style;
assert.equal(style.getPropertyPriority("background-color"), "");
assert.equal(style.getPropertyPriority("color"), "important");
},
"removes a style": function(result) {
assert.equal(result.selection.style("display"), "");
}
};

0 comments on commit 878d1c1

Please sign in to comment.