d3-transition
Advanced tools
Comparing version 1.1.3 to 1.2.0
@@ -1,2 +0,2 @@ | ||
// https://d3js.org/d3-transition/ v1.1.3 Copyright 2018 Mike Bostock | ||
// https://d3js.org/d3-transition/ v1.2.0 Copyright 2019 Mike Bostock | ||
(function (global, factory) { | ||
@@ -8,3 +8,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-dispatch'), require('d3-timer'), require('d3-color'), require('d3-interpolate'), require('d3-selection'), require('d3-ease')) : | ||
var emptyOn = d3Dispatch.dispatch("start", "end", "interrupt"); | ||
var emptyOn = d3Dispatch.dispatch("start", "end", "cancel", "interrupt"); | ||
var emptyTween = []; | ||
@@ -47,3 +47,3 @@ | ||
var schedule = get(node, id); | ||
if (schedule.state > STARTING) throw new Error("too late; already started"); | ||
if (schedule.state > STARTED) throw new Error("too late; already running"); | ||
return schedule; | ||
@@ -91,3 +91,2 @@ } | ||
// Interrupt the active transition, if any. | ||
// Dispatch the interrupt event. | ||
if (o.state === RUNNING) { | ||
@@ -100,8 +99,7 @@ o.state = ENDED; | ||
// Cancel any pre-empted transitions. No interrupt event is dispatched | ||
// because the cancelled transitions never started. Note that this also | ||
// removes this transition from the pending list! | ||
// Cancel any pre-empted transitions. | ||
else if (+i < id) { | ||
o.state = ENDED; | ||
o.timer.stop(); | ||
o.on.call("cancel", node, node.__data__, o.index, o.group); | ||
delete schedules[i]; | ||
@@ -146,3 +144,3 @@ } | ||
while (++i < n) { | ||
tween[i].call(null, t); | ||
tween[i].call(node, t); | ||
} | ||
@@ -182,3 +180,3 @@ | ||
schedule$$1.timer.stop(); | ||
if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group); | ||
schedule$$1.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule$$1.index, schedule$$1.group); | ||
delete schedules[i]; | ||
@@ -297,9 +295,10 @@ } | ||
function attrConstant(name, interpolate$$1, value1) { | ||
var value00, | ||
var string00, | ||
string1 = value1 + "", | ||
interpolate0; | ||
return function() { | ||
var value0 = this.getAttribute(name); | ||
return value0 === value1 ? null | ||
: value0 === value00 ? interpolate0 | ||
: interpolate0 = interpolate$$1(value00 = value0, value1); | ||
var string0 = this.getAttribute(name); | ||
return string0 === string1 ? null | ||
: string0 === string00 ? interpolate0 | ||
: interpolate0 = interpolate$$1(string00 = string0, value1); | ||
}; | ||
@@ -309,9 +308,10 @@ } | ||
function attrConstantNS(fullname, interpolate$$1, value1) { | ||
var value00, | ||
var string00, | ||
string1 = value1 + "", | ||
interpolate0; | ||
return function() { | ||
var value0 = this.getAttributeNS(fullname.space, fullname.local); | ||
return value0 === value1 ? null | ||
: value0 === value00 ? interpolate0 | ||
: interpolate0 = interpolate$$1(value00 = value0, value1); | ||
var string0 = this.getAttributeNS(fullname.space, fullname.local); | ||
return string0 === string1 ? null | ||
: string0 === string00 ? interpolate0 | ||
: interpolate0 = interpolate$$1(string00 = string0, value1); | ||
}; | ||
@@ -321,12 +321,13 @@ } | ||
function attrFunction(name, interpolate$$1, value) { | ||
var value00, | ||
value10, | ||
var string00, | ||
string10, | ||
interpolate0; | ||
return function() { | ||
var value0, value1 = value(this); | ||
var string0, value1 = value(this), string1; | ||
if (value1 == null) return void this.removeAttribute(name); | ||
value0 = this.getAttribute(name); | ||
return value0 === value1 ? null | ||
: value0 === value00 && value1 === value10 ? interpolate0 | ||
: interpolate0 = interpolate$$1(value00 = value0, value10 = value1); | ||
string0 = this.getAttribute(name); | ||
string1 = value1 + ""; | ||
return string0 === string1 ? null | ||
: string0 === string00 && string1 === string10 ? interpolate0 | ||
: (string10 = string1, interpolate0 = interpolate$$1(string00 = string0, value1)); | ||
}; | ||
@@ -336,12 +337,13 @@ } | ||
function attrFunctionNS(fullname, interpolate$$1, value) { | ||
var value00, | ||
value10, | ||
var string00, | ||
string10, | ||
interpolate0; | ||
return function() { | ||
var value0, value1 = value(this); | ||
var string0, value1 = value(this), string1; | ||
if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local); | ||
value0 = this.getAttributeNS(fullname.space, fullname.local); | ||
return value0 === value1 ? null | ||
: value0 === value00 && value1 === value10 ? interpolate0 | ||
: interpolate0 = interpolate$$1(value00 = value0, value10 = value1); | ||
string0 = this.getAttributeNS(fullname.space, fullname.local); | ||
string1 = value1 + ""; | ||
return string0 === string1 ? null | ||
: string0 === string00 && string1 === string10 ? interpolate0 | ||
: (string10 = string1, interpolate0 = interpolate$$1(string00 = string0, value1)); | ||
}; | ||
@@ -355,11 +357,23 @@ } | ||
: value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname) | ||
: (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value + "")); | ||
: (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value)); | ||
} | ||
function attrInterpolate(name, i) { | ||
return function(t) { | ||
this.setAttribute(name, i(t)); | ||
}; | ||
} | ||
function attrInterpolateNS(fullname, i) { | ||
return function(t) { | ||
this.setAttributeNS(fullname.space, fullname.local, i(t)); | ||
}; | ||
} | ||
function attrTweenNS(fullname, value) { | ||
var t0, i0; | ||
function tween() { | ||
var node = this, i = value.apply(node, arguments); | ||
return i && function(t) { | ||
node.setAttributeNS(fullname.space, fullname.local, i(t)); | ||
}; | ||
var i = value.apply(this, arguments); | ||
if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i); | ||
return t0; | ||
} | ||
@@ -371,7 +385,7 @@ tween._value = value; | ||
function attrTween(name, value) { | ||
var t0, i0; | ||
function tween() { | ||
var node = this, i = value.apply(node, arguments); | ||
return i && function(t) { | ||
node.setAttribute(name, i(t)); | ||
}; | ||
var i = value.apply(this, arguments); | ||
if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i); | ||
return t0; | ||
} | ||
@@ -573,16 +587,16 @@ tween._value = value; | ||
function styleRemove(name, interpolate$$1) { | ||
var value00, | ||
value10, | ||
function styleNull(name, interpolate$$1) { | ||
var string00, | ||
string10, | ||
interpolate0; | ||
return function() { | ||
var value0 = d3Selection.style(this, name), | ||
value1 = (this.style.removeProperty(name), d3Selection.style(this, name)); | ||
return value0 === value1 ? null | ||
: value0 === value00 && value1 === value10 ? interpolate0 | ||
: interpolate0 = interpolate$$1(value00 = value0, value10 = value1); | ||
var string0 = d3Selection.style(this, name), | ||
string1 = (this.style.removeProperty(name), d3Selection.style(this, name)); | ||
return string0 === string1 ? null | ||
: string0 === string00 && string1 === string10 ? interpolate0 | ||
: interpolate0 = interpolate$$1(string00 = string0, string10 = string1); | ||
}; | ||
} | ||
function styleRemoveEnd(name) { | ||
function styleRemove(name) { | ||
return function() { | ||
@@ -594,9 +608,10 @@ this.style.removeProperty(name); | ||
function styleConstant(name, interpolate$$1, value1) { | ||
var value00, | ||
var string00, | ||
string1 = value1 + "", | ||
interpolate0; | ||
return function() { | ||
var value0 = d3Selection.style(this, name); | ||
return value0 === value1 ? null | ||
: value0 === value00 ? interpolate0 | ||
: interpolate0 = interpolate$$1(value00 = value0, value1); | ||
var string0 = d3Selection.style(this, name); | ||
return string0 === string1 ? null | ||
: string0 === string00 ? interpolate0 | ||
: interpolate0 = interpolate$$1(string00 = string0, value1); | ||
}; | ||
@@ -606,31 +621,57 @@ } | ||
function styleFunction(name, interpolate$$1, value) { | ||
var value00, | ||
value10, | ||
var string00, | ||
string10, | ||
interpolate0; | ||
return function() { | ||
var value0 = d3Selection.style(this, name), | ||
value1 = value(this); | ||
if (value1 == null) value1 = (this.style.removeProperty(name), d3Selection.style(this, name)); | ||
return value0 === value1 ? null | ||
: value0 === value00 && value1 === value10 ? interpolate0 | ||
: interpolate0 = interpolate$$1(value00 = value0, value10 = value1); | ||
var string0 = d3Selection.style(this, name), | ||
value1 = value(this), | ||
string1 = value1 + ""; | ||
if (value1 == null) string1 = value1 = (this.style.removeProperty(name), d3Selection.style(this, name)); | ||
return string0 === string1 ? null | ||
: string0 === string00 && string1 === string10 ? interpolate0 | ||
: (string10 = string1, interpolate0 = interpolate$$1(string00 = string0, value1)); | ||
}; | ||
} | ||
function styleMaybeRemove(id, name) { | ||
var on0, on1, listener0, key = "style." + name, event = "end." + key, remove; | ||
return function() { | ||
var schedule$$1 = set(this, id), | ||
on = schedule$$1.on, | ||
listener = schedule$$1.value[key] == null ? remove || (remove = styleRemove(name)) : undefined; | ||
// If this node shared a dispatch with the previous node, | ||
// just assign the updated shared dispatch and we’re done! | ||
// Otherwise, copy-on-write. | ||
if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener); | ||
schedule$$1.on = on1; | ||
}; | ||
} | ||
function transition_style(name, value, priority) { | ||
var i = (name += "") === "transform" ? d3Interpolate.interpolateTransformCss : interpolate; | ||
return value == null ? this | ||
.styleTween(name, styleRemove(name, i)) | ||
.on("end.style." + name, styleRemoveEnd(name)) | ||
: this.styleTween(name, typeof value === "function" | ||
? styleFunction(name, i, tweenValue(this, "style." + name, value)) | ||
: styleConstant(name, i, value + ""), priority); | ||
.styleTween(name, styleNull(name, i)) | ||
.on("end.style." + name, styleRemove(name)) | ||
: typeof value === "function" ? this | ||
.styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value))) | ||
.each(styleMaybeRemove(this._id, name)) | ||
: this | ||
.styleTween(name, styleConstant(name, i, value), priority) | ||
.on("end.style." + name, null); | ||
} | ||
function styleInterpolate(name, i, priority) { | ||
return function(t) { | ||
this.style.setProperty(name, i(t), priority); | ||
}; | ||
} | ||
function styleTween(name, value, priority) { | ||
var t, i0; | ||
function tween() { | ||
var node = this, i = value.apply(node, arguments); | ||
return i && function(t) { | ||
node.style.setProperty(name, i(t), priority); | ||
}; | ||
var i = value.apply(this, arguments); | ||
if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority); | ||
return t; | ||
} | ||
@@ -690,2 +731,27 @@ tween._value = value; | ||
function transition_end() { | ||
var on0, on1, that = this, id = that._id, size = that.size(); | ||
return new Promise(function(resolve, reject) { | ||
var cancel = {value: reject}, | ||
end = {value: function() { if (--size === 0) resolve(); }}; | ||
that.each(function() { | ||
var schedule$$1 = set(this, id), | ||
on = schedule$$1.on; | ||
// If this node shared a dispatch with the previous node, | ||
// just assign the updated shared dispatch and we’re done! | ||
// Otherwise, copy-on-write. | ||
if (on !== on0) { | ||
on1 = (on0 = on).copy(); | ||
on1._.cancel.push(cancel); | ||
on1._.interrupt.push(cancel); | ||
on1._.end.push(end); | ||
} | ||
schedule$$1.on = on1; | ||
}); | ||
}); | ||
} | ||
var id = 0; | ||
@@ -734,3 +800,4 @@ | ||
duration: transition_duration, | ||
ease: transition_ease | ||
ease: transition_ease, | ||
end: transition_end | ||
}; | ||
@@ -737,0 +804,0 @@ |
@@ -1,2 +0,2 @@ | ||
// https://d3js.org/d3-transition/ v1.1.3 Copyright 2018 Mike Bostock | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-dispatch"),require("d3-timer"),require("d3-color"),require("d3-interpolate"),require("d3-selection"),require("d3-ease")):"function"==typeof define&&define.amd?define(["exports","d3-dispatch","d3-timer","d3-color","d3-interpolate","d3-selection","d3-ease"],n):n(t.d3=t.d3||{},t.d3,t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,n,e,r,i,o,a){"use strict";var u=n.dispatch("start","end","interrupt"),s=[],l=0,f=1,c=2,h=3,d=4,_=5,p=6;function v(t,n,r,i,o,a){var v=t.__transition;if(v){if(r in v)return}else t.__transition={};!function(t,n,r){var i,o=t.__transition;function a(l){var _,v,y,m;if(r.state!==f)return s();for(_ in o)if((m=o[_]).name===r.name){if(m.state===h)return e.timeout(a);m.state===d?(m.state=p,m.timer.stop(),m.on.call("interrupt",t,t.__data__,m.index,m.group),delete o[_]):+_<n&&(m.state=p,m.timer.stop(),delete o[_])}if(e.timeout(function(){r.state===h&&(r.state=d,r.timer.restart(u,r.delay,r.time),u(l))}),r.state=c,r.on.call("start",t,t.__data__,r.index,r.group),r.state===c){for(r.state=h,i=new Array(y=r.tween.length),_=0,v=-1;_<y;++_)(m=r.tween[_].value.call(t,t.__data__,r.index,r.group))&&(i[++v]=m);i.length=v+1}}function u(n){for(var e=n<r.duration?r.ease.call(null,n/r.duration):(r.timer.restart(s),r.state=_,1),o=-1,a=i.length;++o<a;)i[o].call(null,e);r.state===_&&(r.on.call("end",t,t.__data__,r.index,r.group),s())}function s(){for(var e in r.state=p,r.timer.stop(),delete o[n],o)return;delete t.__transition}o[n]=r,r.timer=e.timer(function(t){r.state=f,r.timer.restart(a,r.delay,r.time),r.delay<=t&&a(t-r.delay)},0,r.time)}(t,r,{name:n,index:i,group:o,on:u,tween:s,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:l})}function y(t,n){var e=w(t,n);if(e.state>l)throw new Error("too late; already scheduled");return e}function m(t,n){var e=w(t,n);if(e.state>c)throw new Error("too late; already started");return e}function w(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function g(t,n){var e,r,i,o=t.__transition,a=!0;if(o){for(i in n=null==n?null:n+"",o)(e=o[i]).name===n?(r=e.state>c&&e.state<_,e.state=p,e.timer.stop(),r&&e.on.call("interrupt",t,t.__data__,e.index,e.group),delete o[i]):a=!1;a&&delete t.__transition}}function b(t,n,e){var r=t._id;return t.each(function(){var t=m(this,r);(t.value||(t.value={}))[n]=e.apply(this,arguments)}),function(t){return w(t,r).value[n]}}function A(t,n){var e;return("number"==typeof n?i.interpolateNumber:n instanceof r.color?i.interpolateRgb:(e=r.color(n))?(n=e,i.interpolateRgb):i.interpolateString)(t,n)}var x=o.selection.prototype.constructor;var E=0;function N(t,n,e,r){this._groups=t,this._parents=n,this._name=e,this._id=r}function S(t){return o.selection().transition(t)}function T(){return++E}var q=o.selection.prototype;N.prototype=S.prototype={constructor:N,select:function(t){var n=this._name,e=this._id;"function"!=typeof t&&(t=o.selector(t));for(var r=this._groups,i=r.length,a=new Array(i),u=0;u<i;++u)for(var s,l,f=r[u],c=f.length,h=a[u]=new Array(c),d=0;d<c;++d)(s=f[d])&&(l=t.call(s,s.__data__,d,f))&&("__data__"in s&&(l.__data__=s.__data__),h[d]=l,v(h[d],n,e,d,h,w(s,e)));return new N(a,this._parents,n,e)},selectAll:function(t){var n=this._name,e=this._id;"function"!=typeof t&&(t=o.selectorAll(t));for(var r=this._groups,i=r.length,a=[],u=[],s=0;s<i;++s)for(var l,f=r[s],c=f.length,h=0;h<c;++h)if(l=f[h]){for(var d,_=t.call(l,l.__data__,h,f),p=w(l,e),y=0,m=_.length;y<m;++y)(d=_[y])&&v(d,n,e,y,_,p);a.push(_),u.push(l)}return new N(a,u,n,e)},filter:function(t){"function"!=typeof t&&(t=o.matcher(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var a,u=n[i],s=u.length,l=r[i]=[],f=0;f<s;++f)(a=u[f])&&t.call(a,a.__data__,f,u)&&l.push(a);return new N(r,this._parents,this._name,this._id)},merge:function(t){if(t._id!==this._id)throw new Error;for(var n=this._groups,e=t._groups,r=n.length,i=e.length,o=Math.min(r,i),a=new Array(r),u=0;u<o;++u)for(var s,l=n[u],f=e[u],c=l.length,h=a[u]=new Array(c),d=0;d<c;++d)(s=l[d]||f[d])&&(h[d]=s);for(;u<r;++u)a[u]=n[u];return new N(a,this._parents,this._name,this._id)},selection:function(){return new x(this._groups,this._parents)},transition:function(){for(var t=this._name,n=this._id,e=T(),r=this._groups,i=r.length,o=0;o<i;++o)for(var a,u=r[o],s=u.length,l=0;l<s;++l)if(a=u[l]){var f=w(a,n);v(a,t,e,l,u,{time:f.time+f.delay+f.duration,delay:0,duration:f.duration,ease:f.ease})}return new N(r,this._parents,t,e)},call:q.call,nodes:q.nodes,node:q.node,size:q.size,empty:q.empty,each:q.each,on:function(t,n){var e=this._id;return arguments.length<2?w(this.node(),e).on.on(t):this.each(function(t,n,e){var r,i,o=function(t){return(t+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||"start"===t})}(n)?y:m;return function(){var a=o(this,t),u=a.on;u!==r&&(i=(r=u).copy()).on(n,e),a.on=i}}(e,t,n))},attr:function(t,n){var e=o.namespace(t),r="transform"===e?i.interpolateTransformSvg:A;return this.attrTween(t,"function"==typeof n?(e.local?function(t,n,e){var r,i,o;return function(){var a,u=e(this);if(null!=u)return(a=this.getAttributeNS(t.space,t.local))===u?null:a===r&&u===i?o:o=n(r=a,i=u);this.removeAttributeNS(t.space,t.local)}}:function(t,n,e){var r,i,o;return function(){var a,u=e(this);if(null!=u)return(a=this.getAttribute(t))===u?null:a===r&&u===i?o:o=n(r=a,i=u);this.removeAttribute(t)}})(e,r,b(this,"attr."+t,n)):null==n?(e.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}})(e):(e.local?function(t,n,e){var r,i;return function(){var o=this.getAttributeNS(t.space,t.local);return o===e?null:o===r?i:i=n(r=o,e)}}:function(t,n,e){var r,i;return function(){var o=this.getAttribute(t);return o===e?null:o===r?i:i=n(r=o,e)}})(e,r,n+""))},attrTween:function(t,n){var e="attr."+t;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(null==n)return this.tween(e,null);if("function"!=typeof n)throw new Error;var r=o.namespace(t);return this.tween(e,(r.local?function(t,n){function e(){var e=this,r=n.apply(e,arguments);return r&&function(n){e.setAttributeNS(t.space,t.local,r(n))}}return e._value=n,e}:function(t,n){function e(){var e=this,r=n.apply(e,arguments);return r&&function(n){e.setAttribute(t,r(n))}}return e._value=n,e})(r,n))},style:function(t,n,e){var r="transform"==(t+="")?i.interpolateTransformCss:A;return null==n?this.styleTween(t,function(t,n){var e,r,i;return function(){var a=o.style(this,t),u=(this.style.removeProperty(t),o.style(this,t));return a===u?null:a===e&&u===r?i:i=n(e=a,r=u)}}(t,r)).on("end.style."+t,function(t){return function(){this.style.removeProperty(t)}}(t)):this.styleTween(t,"function"==typeof n?function(t,n,e){var r,i,a;return function(){var u=o.style(this,t),s=e(this);return null==s&&(this.style.removeProperty(t),s=o.style(this,t)),u===s?null:u===r&&s===i?a:a=n(r=u,i=s)}}(t,r,b(this,"style."+t,n)):function(t,n,e){var r,i;return function(){var a=o.style(this,t);return a===e?null:a===r?i:i=n(r=a,e)}}(t,r,n+""),e)},styleTween:function(t,n,e){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==n)return this.tween(r,null);if("function"!=typeof n)throw new Error;return this.tween(r,function(t,n,e){function r(){var r=this,i=n.apply(r,arguments);return i&&function(n){r.style.setProperty(t,i(n),e)}}return r._value=n,r}(t,n,null==e?"":e))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var n=t(this);this.textContent=null==n?"":n}}(b(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},remove:function(){return this.on("end.remove",(t=this._id,function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}));var t},tween:function(t,n){var e=this._id;if(t+="",arguments.length<2){for(var r,i=w(this.node(),e).tween,o=0,a=i.length;o<a;++o)if((r=i[o]).name===t)return r.value;return null}return this.each((null==n?function(t,n){var e,r;return function(){var i=m(this,t),o=i.tween;if(o!==e)for(var a=0,u=(r=e=o).length;a<u;++a)if(r[a].name===n){(r=r.slice()).splice(a,1);break}i.tween=r}}:function(t,n,e){var r,i;if("function"!=typeof e)throw new Error;return function(){var o=m(this,t),a=o.tween;if(a!==r){i=(r=a).slice();for(var u={name:n,value:e},s=0,l=i.length;s<l;++s)if(i[s].name===n){i[s]=u;break}s===l&&i.push(u)}o.tween=i}})(e,t,n))},delay:function(t){var n=this._id;return arguments.length?this.each(("function"==typeof t?function(t,n){return function(){y(this,t).delay=+n.apply(this,arguments)}}:function(t,n){return n=+n,function(){y(this,t).delay=n}})(n,t)):w(this.node(),n).delay},duration:function(t){var n=this._id;return arguments.length?this.each(("function"==typeof t?function(t,n){return function(){m(this,t).duration=+n.apply(this,arguments)}}:function(t,n){return n=+n,function(){m(this,t).duration=n}})(n,t)):w(this.node(),n).duration},ease:function(t){var n=this._id;return arguments.length?this.each(function(t,n){if("function"!=typeof n)throw new Error;return function(){m(this,t).ease=n}}(n,t)):w(this.node(),n).ease}};var C={time:null,delay:0,duration:250,ease:a.easeCubicInOut};function P(t,n){for(var r;!(r=t.__transition)||!(r=r[n]);)if(!(t=t.parentNode))return C.time=e.now(),C;return r}o.selection.prototype.interrupt=function(t){return this.each(function(){g(this,t)})},o.selection.prototype.transition=function(t){var n,r;t instanceof N?(n=t._id,t=t._name):(n=T(),(r=C).time=e.now(),t=null==t?null:t+"");for(var i=this._groups,o=i.length,a=0;a<o;++a)for(var u,s=i[a],l=s.length,f=0;f<l;++f)(u=s[f])&&v(u,t,n,f,s,r||P(u,n));return new N(i,this._parents,t,n)};var O=[null];t.transition=S,t.active=function(t,n){var e,r,i=t.__transition;if(i)for(r in n=null==n?null:n+"",i)if((e=i[r]).state>f&&e.name===n)return new N([[t]],O,n,+r);return null},t.interrupt=g,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
// https://d3js.org/d3-transition/ v1.2.0 Copyright 2019 Mike Bostock | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-dispatch"),require("d3-timer"),require("d3-color"),require("d3-interpolate"),require("d3-selection"),require("d3-ease")):"function"==typeof define&&define.amd?define(["exports","d3-dispatch","d3-timer","d3-color","d3-interpolate","d3-selection","d3-ease"],n):n(t.d3=t.d3||{},t.d3,t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,n,e,r,i,o,a){"use strict";var u=n.dispatch("start","end","cancel","interrupt"),s=[],l=0,f=1,c=2,h=3,d=4,_=5,p=6;function v(t,n,r,i,o,a){var v=t.__transition;if(v){if(r in v)return}else t.__transition={};!function(t,n,r){var i,o=t.__transition;function a(l){var _,v,y,m;if(r.state!==f)return s();for(_ in o)if((m=o[_]).name===r.name){if(m.state===h)return e.timeout(a);m.state===d?(m.state=p,m.timer.stop(),m.on.call("interrupt",t,t.__data__,m.index,m.group),delete o[_]):+_<n&&(m.state=p,m.timer.stop(),m.on.call("cancel",t,t.__data__,m.index,m.group),delete o[_])}if(e.timeout(function(){r.state===h&&(r.state=d,r.timer.restart(u,r.delay,r.time),u(l))}),r.state=c,r.on.call("start",t,t.__data__,r.index,r.group),r.state===c){for(r.state=h,i=new Array(y=r.tween.length),_=0,v=-1;_<y;++_)(m=r.tween[_].value.call(t,t.__data__,r.index,r.group))&&(i[++v]=m);i.length=v+1}}function u(n){for(var e=n<r.duration?r.ease.call(null,n/r.duration):(r.timer.restart(s),r.state=_,1),o=-1,a=i.length;++o<a;)i[o].call(t,e);r.state===_&&(r.on.call("end",t,t.__data__,r.index,r.group),s())}function s(){for(var e in r.state=p,r.timer.stop(),delete o[n],o)return;delete t.__transition}o[n]=r,r.timer=e.timer(function(t){r.state=f,r.timer.restart(a,r.delay,r.time),r.delay<=t&&a(t-r.delay)},0,r.time)}(t,r,{name:n,index:i,group:o,on:u,tween:s,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:l})}function y(t,n){var e=w(t,n);if(e.state>l)throw new Error("too late; already scheduled");return e}function m(t,n){var e=w(t,n);if(e.state>h)throw new Error("too late; already running");return e}function w(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function g(t,n){var e,r,i,o=t.__transition,a=!0;if(o){for(i in n=null==n?null:n+"",o)(e=o[i]).name===n?(r=e.state>c&&e.state<_,e.state=p,e.timer.stop(),e.on.call(r?"interrupt":"cancel",t,t.__data__,e.index,e.group),delete o[i]):a=!1;a&&delete t.__transition}}function b(t,n,e){var r=t._id;return t.each(function(){var t=m(this,r);(t.value||(t.value={}))[n]=e.apply(this,arguments)}),function(t){return w(t,r).value[n]}}function A(t,n){var e;return("number"==typeof n?i.interpolateNumber:n instanceof r.color?i.interpolateRgb:(e=r.color(n))?(n=e,i.interpolateRgb):i.interpolateString)(t,n)}var x=o.selection.prototype.constructor;function E(t){return function(){this.style.removeProperty(t)}}var N=0;function T(t,n,e,r){this._groups=t,this._parents=n,this._name=e,this._id=r}function S(t){return o.selection().transition(t)}function q(){return++N}var P=o.selection.prototype;T.prototype=S.prototype={constructor:T,select:function(t){var n=this._name,e=this._id;"function"!=typeof t&&(t=o.selector(t));for(var r=this._groups,i=r.length,a=new Array(i),u=0;u<i;++u)for(var s,l,f=r[u],c=f.length,h=a[u]=new Array(c),d=0;d<c;++d)(s=f[d])&&(l=t.call(s,s.__data__,d,f))&&("__data__"in s&&(l.__data__=s.__data__),h[d]=l,v(h[d],n,e,d,h,w(s,e)));return new T(a,this._parents,n,e)},selectAll:function(t){var n=this._name,e=this._id;"function"!=typeof t&&(t=o.selectorAll(t));for(var r=this._groups,i=r.length,a=[],u=[],s=0;s<i;++s)for(var l,f=r[s],c=f.length,h=0;h<c;++h)if(l=f[h]){for(var d,_=t.call(l,l.__data__,h,f),p=w(l,e),y=0,m=_.length;y<m;++y)(d=_[y])&&v(d,n,e,y,_,p);a.push(_),u.push(l)}return new T(a,u,n,e)},filter:function(t){"function"!=typeof t&&(t=o.matcher(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var a,u=n[i],s=u.length,l=r[i]=[],f=0;f<s;++f)(a=u[f])&&t.call(a,a.__data__,f,u)&&l.push(a);return new T(r,this._parents,this._name,this._id)},merge:function(t){if(t._id!==this._id)throw new Error;for(var n=this._groups,e=t._groups,r=n.length,i=e.length,o=Math.min(r,i),a=new Array(r),u=0;u<o;++u)for(var s,l=n[u],f=e[u],c=l.length,h=a[u]=new Array(c),d=0;d<c;++d)(s=l[d]||f[d])&&(h[d]=s);for(;u<r;++u)a[u]=n[u];return new T(a,this._parents,this._name,this._id)},selection:function(){return new x(this._groups,this._parents)},transition:function(){for(var t=this._name,n=this._id,e=q(),r=this._groups,i=r.length,o=0;o<i;++o)for(var a,u=r[o],s=u.length,l=0;l<s;++l)if(a=u[l]){var f=w(a,n);v(a,t,e,l,u,{time:f.time+f.delay+f.duration,delay:0,duration:f.duration,ease:f.ease})}return new T(r,this._parents,t,e)},call:P.call,nodes:P.nodes,node:P.node,size:P.size,empty:P.empty,each:P.each,on:function(t,n){var e=this._id;return arguments.length<2?w(this.node(),e).on.on(t):this.each(function(t,n,e){var r,i,o=function(t){return(t+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||"start"===t})}(n)?y:m;return function(){var a=o(this,t),u=a.on;u!==r&&(i=(r=u).copy()).on(n,e),a.on=i}}(e,t,n))},attr:function(t,n){var e=o.namespace(t),r="transform"===e?i.interpolateTransformSvg:A;return this.attrTween(t,"function"==typeof n?(e.local?function(t,n,e){var r,i,o;return function(){var a,u,s=e(this);if(null!=s)return(a=this.getAttributeNS(t.space,t.local))===(u=s+"")?null:a===r&&u===i?o:(i=u,o=n(r=a,s));this.removeAttributeNS(t.space,t.local)}}:function(t,n,e){var r,i,o;return function(){var a,u,s=e(this);if(null!=s)return(a=this.getAttribute(t))===(u=s+"")?null:a===r&&u===i?o:(i=u,o=n(r=a,s));this.removeAttribute(t)}})(e,r,b(this,"attr."+t,n)):null==n?(e.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}})(e):(e.local?function(t,n,e){var r,i,o=e+"";return function(){var a=this.getAttributeNS(t.space,t.local);return a===o?null:a===r?i:i=n(r=a,e)}}:function(t,n,e){var r,i,o=e+"";return function(){var a=this.getAttribute(t);return a===o?null:a===r?i:i=n(r=a,e)}})(e,r,n))},attrTween:function(t,n){var e="attr."+t;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(null==n)return this.tween(e,null);if("function"!=typeof n)throw new Error;var r=o.namespace(t);return this.tween(e,(r.local?function(t,n){var e,r;function i(){var i=n.apply(this,arguments);return i!==r&&(e=(r=i)&&function(t,n){return function(e){this.setAttributeNS(t.space,t.local,n(e))}}(t,i)),e}return i._value=n,i}:function(t,n){var e,r;function i(){var i=n.apply(this,arguments);return i!==r&&(e=(r=i)&&function(t,n){return function(e){this.setAttribute(t,n(e))}}(t,i)),e}return i._value=n,i})(r,n))},style:function(t,n,e){var r="transform"==(t+="")?i.interpolateTransformCss:A;return null==n?this.styleTween(t,function(t,n){var e,r,i;return function(){var a=o.style(this,t),u=(this.style.removeProperty(t),o.style(this,t));return a===u?null:a===e&&u===r?i:i=n(e=a,r=u)}}(t,r)).on("end.style."+t,E(t)):"function"==typeof n?this.styleTween(t,function(t,n,e){var r,i,a;return function(){var u=o.style(this,t),s=e(this),l=s+"";return null==s&&(this.style.removeProperty(t),l=s=o.style(this,t)),u===l?null:u===r&&l===i?a:(i=l,a=n(r=u,s))}}(t,r,b(this,"style."+t,n))).each(function(t,n){var e,r,i,o,a="style."+n,u="end."+a;return function(){var s=m(this,t),l=s.on,f=null==s.value[a]?o||(o=E(n)):void 0;l===e&&i===f||(r=(e=l).copy()).on(u,i=f),s.on=r}}(this._id,t)):this.styleTween(t,function(t,n,e){var r,i,a=e+"";return function(){var u=o.style(this,t);return u===a?null:u===r?i:i=n(r=u,e)}}(t,r,n),e).on("end.style."+t,null)},styleTween:function(t,n,e){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==n)return this.tween(r,null);if("function"!=typeof n)throw new Error;return this.tween(r,function(t,n,e){var r,i;function o(){var o=n.apply(this,arguments);return o!==i&&(r=(i=o)&&function(t,n,e){return function(r){this.style.setProperty(t,n(r),e)}}(t,o,e)),r}return o._value=n,o}(t,n,null==e?"":e))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var n=t(this);this.textContent=null==n?"":n}}(b(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},remove:function(){return this.on("end.remove",(t=this._id,function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}));var t},tween:function(t,n){var e=this._id;if(t+="",arguments.length<2){for(var r,i=w(this.node(),e).tween,o=0,a=i.length;o<a;++o)if((r=i[o]).name===t)return r.value;return null}return this.each((null==n?function(t,n){var e,r;return function(){var i=m(this,t),o=i.tween;if(o!==e)for(var a=0,u=(r=e=o).length;a<u;++a)if(r[a].name===n){(r=r.slice()).splice(a,1);break}i.tween=r}}:function(t,n,e){var r,i;if("function"!=typeof e)throw new Error;return function(){var o=m(this,t),a=o.tween;if(a!==r){i=(r=a).slice();for(var u={name:n,value:e},s=0,l=i.length;s<l;++s)if(i[s].name===n){i[s]=u;break}s===l&&i.push(u)}o.tween=i}})(e,t,n))},delay:function(t){var n=this._id;return arguments.length?this.each(("function"==typeof t?function(t,n){return function(){y(this,t).delay=+n.apply(this,arguments)}}:function(t,n){return n=+n,function(){y(this,t).delay=n}})(n,t)):w(this.node(),n).delay},duration:function(t){var n=this._id;return arguments.length?this.each(("function"==typeof t?function(t,n){return function(){m(this,t).duration=+n.apply(this,arguments)}}:function(t,n){return n=+n,function(){m(this,t).duration=n}})(n,t)):w(this.node(),n).duration},ease:function(t){var n=this._id;return arguments.length?this.each(function(t,n){if("function"!=typeof n)throw new Error;return function(){m(this,t).ease=n}}(n,t)):w(this.node(),n).ease},end:function(){var t,n,e=this,r=e._id,i=e.size();return new Promise(function(o,a){var u={value:a},s={value:function(){0==--i&&o()}};e.each(function(){var e=m(this,r),i=e.on;i!==t&&((n=(t=i).copy())._.cancel.push(u),n._.interrupt.push(u),n._.end.push(s)),e.on=n})})}};var C={time:null,delay:0,duration:250,ease:a.easeCubicInOut};function z(t,n){for(var r;!(r=t.__transition)||!(r=r[n]);)if(!(t=t.parentNode))return C.time=e.now(),C;return r}o.selection.prototype.interrupt=function(t){return this.each(function(){g(this,t)})},o.selection.prototype.transition=function(t){var n,r;t instanceof T?(n=t._id,t=t._name):(n=q(),(r=C).time=e.now(),t=null==t?null:t+"");for(var i=this._groups,o=i.length,a=0;a<o;++a)for(var u,s=i[a],l=s.length,f=0;f<l;++f)(u=s[f])&&v(u,t,n,f,s,r||z(u,n));return new T(i,this._parents,t,n)};var O=[null];t.transition=S,t.active=function(t,n){var e,r,i=t.__transition;if(i)for(r in n=null==n?null:n+"",i)if((e=i[r]).state>f&&e.name===n)return new T([[t]],O,n,+r);return null},t.interrupt=g,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "d3-transition", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "Animated transitions for D3 selections.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -19,3 +19,3 @@ # d3-transition | ||
If you use NPM, `npm install d3-transition`. Otherwise, download the [latest release](https://github.com/d3/d3-transition/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-transition.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: | ||
If you use NPM, `npm install d3-transition`. Otherwise, download the [latest release](https://github.com/d3/d3-transition/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-transition.v1.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: | ||
@@ -311,5 +311,5 @@ ```html | ||
transition.tween("attr.fill", function() { | ||
var node = this, i = d3.interpolateRgb(node.getAttribute("fill"), "blue"); | ||
var i = d3.interpolateRgb(this.getAttribute("fill"), "blue"); | ||
return function(t) { | ||
node.setAttribute("fill", i(t)); | ||
this.setAttribute("fill", i(t)); | ||
}; | ||
@@ -362,2 +362,3 @@ }); | ||
* `interrupt` - when the transition is interrupted. | ||
* `cancel` - when the transition is cancelled. | ||
@@ -426,3 +427,3 @@ See [The Life of a Transition](#the-life-of-a-transition) for more. Note that these are *not* native DOM events as implemented by [*selection*.on](https://github.com/d3/d3-selection#selection_on) and [*selection*.dispatch](https://github.com/d3/d3-selection#selection_dispatch), but transition events! | ||
When the transition subsequently starts, it interrupts the active transition of the same name on the same element, if any, dispatching an `interrupt` event to registered listeners. (Note that interrupts happen on start, not creation, and thus even a zero-delay transition will not immediately interrupt the active transition: the old transition is given a final frame. Use [*selection*.interrupt](#selection_interrupt) to interrupt immediately.) The starting transition also cancels any pending transitions of the same name on the same element that were created before the starting transition. The transition then dispatches a `start` event to registered listeners. This is the last moment at which the transition may be modified: after starting, the transition’s timing, tweens, and listeners may no longer be changed; attempting to do so throws an error with the message “too late: already started” (or if the transition has ended, “transition not found”). The transition initializes its tweens immediately after starting. | ||
When the transition subsequently starts, it interrupts the active transition of the same name on the same element, if any, dispatching an `interrupt` event to registered listeners. (Note that interrupts happen on start, not creation, and thus even a zero-delay transition will not immediately interrupt the active transition: the old transition is given a final frame. Use [*selection*.interrupt](#selection_interrupt) to interrupt immediately.) The starting transition also cancels any pending transitions of the same name on the same element that were created before the starting transition. The transition then dispatches a `start` event to registered listeners. This is the last moment at which the transition may be modified: the transition’s timing, tweens, and listeners may not be changed when it is running; attempting to do so throws an error with the message “too late: already running” (or if the transition has ended, “transition not found”). The transition initializes its tweens immediately after starting. | ||
@@ -429,0 +430,0 @@ During the frame the transition starts, but *after* all transitions starting this frame have been started, the transition invokes its tweens for the first time. Batching tween initialization, which typically involves reading from the DOM, improves performance by avoiding interleaved DOM reads and writes. |
@@ -19,3 +19,3 @@ import {STARTING, ENDING, ENDED} from "./transition/schedule"; | ||
schedule.timer.stop(); | ||
if (active) schedule.on.call("interrupt", node, node.__data__, schedule.index, schedule.group); | ||
schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group); | ||
delete schedules[i]; | ||
@@ -22,0 +22,0 @@ } |
@@ -19,9 +19,10 @@ import {interpolateTransformSvg as interpolateTransform} from "d3-interpolate"; | ||
function attrConstant(name, interpolate, value1) { | ||
var value00, | ||
var string00, | ||
string1 = value1 + "", | ||
interpolate0; | ||
return function() { | ||
var value0 = this.getAttribute(name); | ||
return value0 === value1 ? null | ||
: value0 === value00 ? interpolate0 | ||
: interpolate0 = interpolate(value00 = value0, value1); | ||
var string0 = this.getAttribute(name); | ||
return string0 === string1 ? null | ||
: string0 === string00 ? interpolate0 | ||
: interpolate0 = interpolate(string00 = string0, value1); | ||
}; | ||
@@ -31,9 +32,10 @@ } | ||
function attrConstantNS(fullname, interpolate, value1) { | ||
var value00, | ||
var string00, | ||
string1 = value1 + "", | ||
interpolate0; | ||
return function() { | ||
var value0 = this.getAttributeNS(fullname.space, fullname.local); | ||
return value0 === value1 ? null | ||
: value0 === value00 ? interpolate0 | ||
: interpolate0 = interpolate(value00 = value0, value1); | ||
var string0 = this.getAttributeNS(fullname.space, fullname.local); | ||
return string0 === string1 ? null | ||
: string0 === string00 ? interpolate0 | ||
: interpolate0 = interpolate(string00 = string0, value1); | ||
}; | ||
@@ -43,12 +45,13 @@ } | ||
function attrFunction(name, interpolate, value) { | ||
var value00, | ||
value10, | ||
var string00, | ||
string10, | ||
interpolate0; | ||
return function() { | ||
var value0, value1 = value(this); | ||
var string0, value1 = value(this), string1; | ||
if (value1 == null) return void this.removeAttribute(name); | ||
value0 = this.getAttribute(name); | ||
return value0 === value1 ? null | ||
: value0 === value00 && value1 === value10 ? interpolate0 | ||
: interpolate0 = interpolate(value00 = value0, value10 = value1); | ||
string0 = this.getAttribute(name); | ||
string1 = value1 + ""; | ||
return string0 === string1 ? null | ||
: string0 === string00 && string1 === string10 ? interpolate0 | ||
: (string10 = string1, interpolate0 = interpolate(string00 = string0, value1)); | ||
}; | ||
@@ -58,12 +61,13 @@ } | ||
function attrFunctionNS(fullname, interpolate, value) { | ||
var value00, | ||
value10, | ||
var string00, | ||
string10, | ||
interpolate0; | ||
return function() { | ||
var value0, value1 = value(this); | ||
var string0, value1 = value(this), string1; | ||
if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local); | ||
value0 = this.getAttributeNS(fullname.space, fullname.local); | ||
return value0 === value1 ? null | ||
: value0 === value00 && value1 === value10 ? interpolate0 | ||
: interpolate0 = interpolate(value00 = value0, value10 = value1); | ||
string0 = this.getAttributeNS(fullname.space, fullname.local); | ||
string1 = value1 + ""; | ||
return string0 === string1 ? null | ||
: string0 === string00 && string1 === string10 ? interpolate0 | ||
: (string10 = string1, interpolate0 = interpolate(string00 = string0, value1)); | ||
}; | ||
@@ -77,3 +81,3 @@ } | ||
: value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname) | ||
: (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value + "")); | ||
: (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value)); | ||
} |
import {namespace} from "d3-selection"; | ||
function attrInterpolate(name, i) { | ||
return function(t) { | ||
this.setAttribute(name, i(t)); | ||
}; | ||
} | ||
function attrInterpolateNS(fullname, i) { | ||
return function(t) { | ||
this.setAttributeNS(fullname.space, fullname.local, i(t)); | ||
}; | ||
} | ||
function attrTweenNS(fullname, value) { | ||
var t0, i0; | ||
function tween() { | ||
var node = this, i = value.apply(node, arguments); | ||
return i && function(t) { | ||
node.setAttributeNS(fullname.space, fullname.local, i(t)); | ||
}; | ||
var i = value.apply(this, arguments); | ||
if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i); | ||
return t0; | ||
} | ||
@@ -15,7 +27,7 @@ tween._value = value; | ||
function attrTween(name, value) { | ||
var t0, i0; | ||
function tween() { | ||
var node = this, i = value.apply(node, arguments); | ||
return i && function(t) { | ||
node.setAttribute(name, i(t)); | ||
}; | ||
var i = value.apply(this, arguments); | ||
if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i); | ||
return t0; | ||
} | ||
@@ -22,0 +34,0 @@ tween._value = value; |
@@ -19,2 +19,3 @@ import {selection} from "d3-selection"; | ||
import transition_tween from "./tween"; | ||
import transition_end from "./end"; | ||
@@ -64,3 +65,4 @@ var id = 0; | ||
duration: transition_duration, | ||
ease: transition_ease | ||
ease: transition_ease, | ||
end: transition_end | ||
}; |
import {dispatch} from "d3-dispatch"; | ||
import {timer, timeout} from "d3-timer"; | ||
var emptyOn = dispatch("start", "end", "interrupt"); | ||
var emptyOn = dispatch("start", "end", "cancel", "interrupt"); | ||
var emptyTween = []; | ||
@@ -42,3 +42,3 @@ | ||
var schedule = get(node, id); | ||
if (schedule.state > STARTING) throw new Error("too late; already started"); | ||
if (schedule.state > STARTED) throw new Error("too late; already running"); | ||
return schedule; | ||
@@ -86,3 +86,2 @@ } | ||
// Interrupt the active transition, if any. | ||
// Dispatch the interrupt event. | ||
if (o.state === RUNNING) { | ||
@@ -95,8 +94,7 @@ o.state = ENDED; | ||
// Cancel any pre-empted transitions. No interrupt event is dispatched | ||
// because the cancelled transitions never started. Note that this also | ||
// removes this transition from the pending list! | ||
// Cancel any pre-empted transitions. | ||
else if (+i < id) { | ||
o.state = ENDED; | ||
o.timer.stop(); | ||
o.on.call("cancel", node, node.__data__, o.index, o.group); | ||
delete schedules[i]; | ||
@@ -141,3 +139,3 @@ } | ||
while (++i < n) { | ||
tween[i].call(null, t); | ||
tween[i].call(node, t); | ||
} | ||
@@ -144,0 +142,0 @@ |
import {interpolateTransformCss as interpolateTransform} from "d3-interpolate"; | ||
import {style} from "d3-selection"; | ||
import {set} from "./schedule"; | ||
import {tweenValue} from "./tween"; | ||
import interpolate from "./interpolate"; | ||
function styleRemove(name, interpolate) { | ||
var value00, | ||
value10, | ||
function styleNull(name, interpolate) { | ||
var string00, | ||
string10, | ||
interpolate0; | ||
return function() { | ||
var value0 = style(this, name), | ||
value1 = (this.style.removeProperty(name), style(this, name)); | ||
return value0 === value1 ? null | ||
: value0 === value00 && value1 === value10 ? interpolate0 | ||
: interpolate0 = interpolate(value00 = value0, value10 = value1); | ||
var string0 = style(this, name), | ||
string1 = (this.style.removeProperty(name), style(this, name)); | ||
return string0 === string1 ? null | ||
: string0 === string00 && string1 === string10 ? interpolate0 | ||
: interpolate0 = interpolate(string00 = string0, string10 = string1); | ||
}; | ||
} | ||
function styleRemoveEnd(name) { | ||
function styleRemove(name) { | ||
return function() { | ||
@@ -26,9 +27,10 @@ this.style.removeProperty(name); | ||
function styleConstant(name, interpolate, value1) { | ||
var value00, | ||
var string00, | ||
string1 = value1 + "", | ||
interpolate0; | ||
return function() { | ||
var value0 = style(this, name); | ||
return value0 === value1 ? null | ||
: value0 === value00 ? interpolate0 | ||
: interpolate0 = interpolate(value00 = value0, value1); | ||
var string0 = style(this, name); | ||
return string0 === string1 ? null | ||
: string0 === string00 ? interpolate0 | ||
: interpolate0 = interpolate(string00 = string0, value1); | ||
}; | ||
@@ -38,23 +40,43 @@ } | ||
function styleFunction(name, interpolate, value) { | ||
var value00, | ||
value10, | ||
var string00, | ||
string10, | ||
interpolate0; | ||
return function() { | ||
var value0 = style(this, name), | ||
value1 = value(this); | ||
if (value1 == null) value1 = (this.style.removeProperty(name), style(this, name)); | ||
return value0 === value1 ? null | ||
: value0 === value00 && value1 === value10 ? interpolate0 | ||
: interpolate0 = interpolate(value00 = value0, value10 = value1); | ||
var string0 = style(this, name), | ||
value1 = value(this), | ||
string1 = value1 + ""; | ||
if (value1 == null) string1 = value1 = (this.style.removeProperty(name), style(this, name)); | ||
return string0 === string1 ? null | ||
: string0 === string00 && string1 === string10 ? interpolate0 | ||
: (string10 = string1, interpolate0 = interpolate(string00 = string0, value1)); | ||
}; | ||
} | ||
function styleMaybeRemove(id, name) { | ||
var on0, on1, listener0, key = "style." + name, event = "end." + key, remove; | ||
return function() { | ||
var schedule = set(this, id), | ||
on = schedule.on, | ||
listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined; | ||
// If this node shared a dispatch with the previous node, | ||
// just assign the updated shared dispatch and we’re done! | ||
// Otherwise, copy-on-write. | ||
if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener); | ||
schedule.on = on1; | ||
}; | ||
} | ||
export default function(name, value, priority) { | ||
var i = (name += "") === "transform" ? interpolateTransform : interpolate; | ||
return value == null ? this | ||
.styleTween(name, styleRemove(name, i)) | ||
.on("end.style." + name, styleRemoveEnd(name)) | ||
: this.styleTween(name, typeof value === "function" | ||
? styleFunction(name, i, tweenValue(this, "style." + name, value)) | ||
: styleConstant(name, i, value + ""), priority); | ||
.styleTween(name, styleNull(name, i)) | ||
.on("end.style." + name, styleRemove(name)) | ||
: typeof value === "function" ? this | ||
.styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value))) | ||
.each(styleMaybeRemove(this._id, name)) | ||
: this | ||
.styleTween(name, styleConstant(name, i, value), priority) | ||
.on("end.style." + name, null); | ||
} |
@@ -0,7 +1,13 @@ | ||
function styleInterpolate(name, i, priority) { | ||
return function(t) { | ||
this.style.setProperty(name, i(t), priority); | ||
}; | ||
} | ||
function styleTween(name, value, priority) { | ||
var t, i0; | ||
function tween() { | ||
var node = this, i = value.apply(node, arguments); | ||
return i && function(t) { | ||
node.style.setProperty(name, i(t), priority); | ||
}; | ||
var i = value.apply(this, arguments); | ||
if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority); | ||
return t; | ||
} | ||
@@ -8,0 +14,0 @@ tween._value = value; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149863
35
1592
431