Last active
October 9, 2017 18:47
-
-
Save classiemilio/7a9f01ae64c38205e43c7267442aef18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const d3SelectionProto = Object.assign({}, d3.selection.prototype); | |
const D3TestUtils = { | |
stubAndForceTransitions() { | |
d3.selection.prototype.transition = function() { | |
return this; | |
}; | |
d3.selection.prototype.duration = function() { | |
return this; | |
}; | |
d3.selection.prototype.delay = function() { | |
return this; | |
}; | |
d3.selection.prototype.ease = function() { | |
return this; | |
}; | |
d3.selection.prototype.on = function(event, callback) { | |
if (event === 'start' || event === 'end') { | |
this.each(callback); | |
return this; | |
} else { | |
return d3SelectionProto.on.apply(this, arguments); | |
} | |
}; | |
d3.selection.prototype.tween = function(_name, tweenFn) { | |
this.each(function(datum, index) { | |
tweenFn.call(this, datum, index)(1); | |
}); | |
return this; | |
}; | |
d3.selection.prototype.attrTween = function(attr, tweenFn) { | |
this.each(function(datum, index) { | |
d3.select(this).attr(attr, tweenFn.call(this, datum, index)(1)); | |
}); | |
return this; | |
}; | |
d3.selection.prototype.styleTween = function(style, tweenFn) { | |
this.each(function(datum, index) { | |
d3.select(this).style(style, tweenFn.call(this, datum, index)(1)); | |
}); | |
return this; | |
}; | |
}, | |
restoreTransitions() { | |
d3.selection.prototype = Object.assign({}, d3SelectionProto); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment