Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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