Fix transitioning styles to null (removal).

This commit is contained in:
Jason Davies 2011-10-05 22:35:19 +01:00
Родитель fe6128180e
Коммит 878d1c1c13
5 изменённых файлов: 36 добавлений и 5 удалений

15
d3.js поставляемый
Просмотреть файл

@ -1856,9 +1856,18 @@ function d3_transition(groups, id) {
return groups; return groups;
} }
function d3_transitionTweenNull() {
return d3_transitionTweenNullNull;
}
function d3_transitionTweenNullNull() {
return null;
}
function d3_transitionTween(b) { function d3_transitionTween(b) {
return typeof b === "function" return typeof b === "function"
? function(d, i, a) { var v = b.call(this, d, i) + ""; return a != v && d3.interpolate(a, v); } ? 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); }); : (b = b + "", function(d, i, a) { return a != b && d3.interpolate(a, b); });
} }
@ -1951,7 +1960,11 @@ d3_transitionPrototype.styleTween = function(name, tween, priority) {
return this.tween("style." + name, function(d, i) { return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name)); var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
return f && function(t) { 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);
}
}; };
}); });
}; };

4
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -8,7 +8,11 @@ d3_transitionPrototype.styleTween = function(name, tween, priority) {
return this.tween("style." + name, function(d, i) { return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name)); var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
return f && function(t) { 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);
}
}; };
}); });
}; };

Просмотреть файл

@ -85,9 +85,18 @@ function d3_transition(groups, id) {
return groups; return groups;
} }
function d3_transitionTweenNull() {
return d3_transitionTweenNullNull;
}
function d3_transitionTweenNullNull() {
return null;
}
function d3_transitionTween(b) { function d3_transitionTween(b) {
return typeof b === "function" return typeof b === "function"
? function(d, i, a) { var v = b.call(this, d, i) + ""; return a != v && d3.interpolate(a, v); } ? 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); }); : (b = b + "", function(d, i, a) { return a != b && d3.interpolate(a, b); });
} }

Просмотреть файл

@ -9,9 +9,11 @@ module.exports = {
var s = d3.select("body").append("div") var s = d3.select("body").append("div")
.style("background-color", "white") .style("background-color", "white")
.style("color", "red"); .style("color", "red")
.style("display", "none");
var t = s.transition() var t = s.transition()
.style("display", null)
.style("background-color", "green") .style("background-color", "green")
.style("background-color", "red") .style("background-color", "red")
.style("color", function() { return "green"; }, "important") .style("color", function() { return "green"; }, "important")
@ -34,5 +36,8 @@ module.exports = {
var style = result.selection.node().style; var style = result.selection.node().style;
assert.equal(style.getPropertyPriority("background-color"), ""); assert.equal(style.getPropertyPriority("background-color"), "");
assert.equal(style.getPropertyPriority("color"), "important"); assert.equal(style.getPropertyPriority("color"), "important");
},
"removes a style": function(result) {
assert.equal(result.selection.style("display"), "");
} }
}; };