Skip to content

Commit

Permalink
Use ternary ? happy : unhappy.
Browse files Browse the repository at this point in the history
Using the comma operator isn't so bad, and I added it to removeAttribute
for good measure in case there's an implementation out there that
returns something.
  • Loading branch information
jasondavies committed Oct 6, 2011
1 parent 037493c commit 6b83af4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -1942,14 +1942,15 @@ d3_transitionPrototype.attrTween = function(nameNS, tween) {

function attrTween(d, i) {
var f = tween.call(this, d, i, this.getAttribute(name));
return f === d3_transitionRemove ? this.removeAttribute(name)
return f === d3_transitionRemove
? (this.removeAttribute(name), null)
: f && function(t) { this.setAttribute(name, f(t)); };
}

function attrTweenNS(d, i) {
var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
return f === d3_transitionRemove
? (this.removeAttributeNS(name.space, name.local), null) // TODO remove workaround for JSDOM
? (this.removeAttributeNS(name.space, name.local), null)
: f && function(t) { this.setAttributeNS(name.space, name.local, f(t)); };
}

Expand All @@ -1964,10 +1965,9 @@ d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
if (f !== d3_transitionRemove) {
return f && function(t) { this.style.setProperty(name, f(t), priority); };
}
this.style.removeProperty(name);
return f === d3_transitionRemove
? (this.style.removeProperty(name), null)
: f && function(t) { this.style.setProperty(name, f(t), priority); };
});
};
d3_transitionPrototype.text = function(value) {
Expand Down
2 changes: 1 addition & 1 deletion d3.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/core/transition-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ d3_transitionPrototype.attrTween = function(nameNS, tween) {

function attrTween(d, i) {
var f = tween.call(this, d, i, this.getAttribute(name));
return f === d3_transitionRemove ? this.removeAttribute(name)
return f === d3_transitionRemove
? (this.removeAttribute(name), null)
: f && function(t) { this.setAttribute(name, f(t)); };
}

function attrTweenNS(d, i) {
var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
return f === d3_transitionRemove
? (this.removeAttributeNS(name.space, name.local), null) // TODO remove workaround for JSDOM
? (this.removeAttributeNS(name.space, name.local), null)
: f && function(t) { this.setAttributeNS(name.space, name.local, f(t)); };
}

Expand Down
7 changes: 3 additions & 4 deletions src/core/transition-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
if (f !== d3_transitionRemove) {
return f && function(t) { this.style.setProperty(name, f(t), priority); };
}
this.style.removeProperty(name);
return f === d3_transitionRemove
? (this.style.removeProperty(name), null)
: f && function(t) { this.style.setProperty(name, f(t), priority); };
});
};

0 comments on commit 6b83af4

Please sign in to comment.