1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-18 20:59:39 +02:00
Maybe/vendor/javascript/d3-transition.js
Josh Pigford 868d4ede6e
Sankey Diagram (#2269)
* Enhance cash flow dashboard with new cash flow period handling and improved Sankey diagram rendering. Update D3 and related dependencies for better performance and features.

* Fix Rubocop offenses

* Refactor Sankey chart controller to use Number.parseFloat for value formatting and improve code readability by restructuring conditional logic for node shapes.
2025-05-20 13:31:05 -05:00

4 lines
13 KiB
JavaScript

// d3-transition@3.0.1 downloaded from https://ga.jspm.io/npm:d3-transition@3.0.1/src/index.js
import{namespace as t,matcher as n,selector as e,selectorAll as r,selection as i,style as o}from"d3-selection";import{dispatch as a}from"d3-dispatch";import{timer as s,timeout as u,now as l}from"d3-timer";import{interpolateNumber as c,interpolateRgb as f,interpolateString as h,interpolateTransformSvg as _,interpolateTransformCss as v}from"d3-interpolate";import{color as d}from"d3-color";import{easeCubicInOut as p}from"d3-ease";var y=a("start","end","cancel","interrupt");var w=[];var m=0;var g=1;var T=2;var x=3;var C=4;var A=5;var N=6;function schedule(t,n,e,r,i,o){var a=t.__transition;if(a){if(e in a)return}else t.__transition={};create(t,e,{name:n,index:r,group:i,on:y,tween:w,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:m})}function init(t,n){var e=get(t,n);if(e.state>m)throw new Error("too late; already scheduled");return e}function set(t,n){var e=get(t,n);if(e.state>x)throw new Error("too late; already running");return e}function get(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function create(t,n,e){var r,i=t.__transition;i[n]=e;e.timer=s(schedule,0,e.time);function schedule(t){e.state=g;e.timer.restart(start,e.delay,e.time);e.delay<=t&&start(t-e.delay)}function start(o){var a,s,l,c;if(e.state!==g)return stop();for(a in i){c=i[a];if(c.name===e.name){if(c.state===x)return u(start);if(c.state===C){c.state=N;c.timer.stop();c.on.call("interrupt",t,t.__data__,c.index,c.group);delete i[a]}else if(+a<n){c.state=N;c.timer.stop();c.on.call("cancel",t,t.__data__,c.index,c.group);delete i[a]}}}u((function(){if(e.state===x){e.state=C;e.timer.restart(tick,e.delay,e.time);tick(o)}}));e.state=T;e.on.call("start",t,t.__data__,e.index,e.group);if(e.state===T){e.state=x;r=new Array(l=e.tween.length);for(a=0,s=-1;a<l;++a)(c=e.tween[a].value.call(t,t.__data__,e.index,e.group))&&(r[++s]=c);r.length=s+1}}function tick(n){var i=n<e.duration?e.ease.call(null,n/e.duration):(e.timer.restart(stop),e.state=A,1),o=-1,a=r.length;while(++o<a)r[o].call(t,i);if(e.state===A){e.on.call("end",t,t.__data__,e.index,e.group);stop()}}function stop(){e.state=N;e.timer.stop();delete i[n];for(var r in i)return;delete t.__transition}}function interrupt(t,n){var e,r,i,o=t.__transition,a=true;if(o){n=null==n?null:n+"";for(i in o)if((e=o[i]).name===n){r=e.state>T&&e.state<A;e.state=N;e.timer.stop();e.on.call(r?"interrupt":"cancel",t,t.__data__,e.index,e.group);delete o[i]}else a=false;a&&delete t.__transition}}function selection_interrupt(t){return this.each((function(){interrupt(this,t)}))}function tweenRemove(t,n){var e,r;return function(){var i=set(this,t),o=i.tween;if(o!==e){r=e=o;for(var a=0,s=r.length;a<s;++a)if(r[a].name===n){r=r.slice();r.splice(a,1);break}}i.tween=r}}function tweenFunction(t,n,e){var r,i;if("function"!==typeof e)throw new Error;return function(){var o=set(this,t),a=o.tween;if(a!==r){i=(r=a).slice();for(var s={name:n,value:e},u=0,l=i.length;u<l;++u)if(i[u].name===n){i[u]=s;break}u===l&&i.push(s)}o.tween=i}}function transition_tween(t,n){var e=this._id;t+="";if(arguments.length<2){var r=get(this.node(),e).tween;for(var i,o=0,a=r.length;o<a;++o)if((i=r[o]).name===t)return i.value;return null}return this.each((null==n?tweenRemove:tweenFunction)(e,t,n))}function tweenValue(t,n,e){var r=t._id;t.each((function(){var t=set(this,r);(t.value||(t.value={}))[n]=e.apply(this,arguments)}));return function(t){return get(t,r).value[n]}}function interpolate(t,n){var e;return("number"===typeof n?c:n instanceof d?f:(e=d(n))?(n=e,f):h)(t,n)}function attrRemove(t){return function(){this.removeAttribute(t)}}function attrRemoveNS(t){return function(){this.removeAttributeNS(t.space,t.local)}}function attrConstant(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)}}function attrConstantNS(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 attrFunction(t,n,e){var r,i,o;return function(){var a,s,u=e(this);if(null!=u){a=this.getAttribute(t);s=u+"";return a===s?null:a===r&&s===i?o:(i=s,o=n(r=a,u))}this.removeAttribute(t)}}function attrFunctionNS(t,n,e){var r,i,o;return function(){var a,s,u=e(this);if(null!=u){a=this.getAttributeNS(t.space,t.local);s=u+"";return a===s?null:a===r&&s===i?o:(i=s,o=n(r=a,u))}this.removeAttributeNS(t.space,t.local)}}function transition_attr(n,e){var r=t(n),i="transform"===r?_:interpolate;return this.attrTween(n,"function"===typeof e?(r.local?attrFunctionNS:attrFunction)(r,i,tweenValue(this,"attr."+n,e)):null==e?(r.local?attrRemoveNS:attrRemove)(r):(r.local?attrConstantNS:attrConstant)(r,i,e))}function attrInterpolate(t,n){return function(e){this.setAttribute(t,n.call(this,e))}}function attrInterpolateNS(t,n){return function(e){this.setAttributeNS(t.space,t.local,n.call(this,e))}}function attrTweenNS(t,n){var e,r;function tween(){var i=n.apply(this,arguments);i!==r&&(e=(r=i)&&attrInterpolateNS(t,i));return e}tween._value=n;return tween}function attrTween(t,n){var e,r;function tween(){var i=n.apply(this,arguments);i!==r&&(e=(r=i)&&attrInterpolate(t,i));return e}tween._value=n;return tween}function transition_attrTween(n,e){var r="attr."+n;if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==e)return this.tween(r,null);if("function"!==typeof e)throw new Error;var i=t(n);return this.tween(r,(i.local?attrTweenNS:attrTween)(i,e))}function delayFunction(t,n){return function(){init(this,t).delay=+n.apply(this,arguments)}}function delayConstant(t,n){return n=+n,function(){init(this,t).delay=n}}function transition_delay(t){var n=this._id;return arguments.length?this.each(("function"===typeof t?delayFunction:delayConstant)(n,t)):get(this.node(),n).delay}function durationFunction(t,n){return function(){set(this,t).duration=+n.apply(this,arguments)}}function durationConstant(t,n){return n=+n,function(){set(this,t).duration=n}}function transition_duration(t){var n=this._id;return arguments.length?this.each(("function"===typeof t?durationFunction:durationConstant)(n,t)):get(this.node(),n).duration}function easeConstant(t,n){if("function"!==typeof n)throw new Error;return function(){set(this,t).ease=n}}function transition_ease(t){var n=this._id;return arguments.length?this.each(easeConstant(n,t)):get(this.node(),n).ease}function easeVarying(t,n){return function(){var e=n.apply(this,arguments);if("function"!==typeof e)throw new Error;set(this,t).ease=e}}function transition_easeVarying(t){if("function"!==typeof t)throw new Error;return this.each(easeVarying(this._id,t))}function transition_filter(t){"function"!==typeof t&&(t=n(t));for(var e=this._groups,r=e.length,i=new Array(r),o=0;o<r;++o)for(var a,s=e[o],u=s.length,l=i[o]=[],c=0;c<u;++c)(a=s[c])&&t.call(a,a.__data__,c,s)&&l.push(a);return new Transition(i,this._parents,this._name,this._id)}function transition_merge(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),s=0;s<o;++s)for(var u,l=n[s],c=e[s],f=l.length,h=a[s]=new Array(f),_=0;_<f;++_)(u=l[_]||c[_])&&(h[_]=u);for(;s<r;++s)a[s]=n[s];return new Transition(a,this._parents,this._name,this._id)}function start(t){return(t+"").trim().split(/^|\s+/).every((function(t){var n=t.indexOf(".");n>=0&&(t=t.slice(0,n));return!t||"start"===t}))}function onFunction(t,n,e){var r,i,o=start(n)?init:set;return function(){var a=o(this,t),s=a.on;s!==r&&(i=(r=s).copy()).on(n,e);a.on=i}}function transition_on(t,n){var e=this._id;return arguments.length<2?get(this.node(),e).on.on(t):this.each(onFunction(e,t,n))}function removeFunction(t){return function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}}function transition_remove(){return this.on("end.remove",removeFunction(this._id))}function transition_select(t){var n=this._name,r=this._id;"function"!==typeof t&&(t=e(t));for(var i=this._groups,o=i.length,a=new Array(o),s=0;s<o;++s)for(var u,l,c=i[s],f=c.length,h=a[s]=new Array(f),_=0;_<f;++_)if((u=c[_])&&(l=t.call(u,u.__data__,_,c))){"__data__"in u&&(l.__data__=u.__data__);h[_]=l;schedule(h[_],n,r,_,h,get(u,r))}return new Transition(a,this._parents,n,r)}function transition_selectAll(t){var n=this._name,e=this._id;"function"!==typeof t&&(t=r(t));for(var i=this._groups,o=i.length,a=[],s=[],u=0;u<o;++u)for(var l,c=i[u],f=c.length,h=0;h<f;++h)if(l=c[h]){for(var _,v=t.call(l,l.__data__,h,c),d=get(l,e),p=0,y=v.length;p<y;++p)(_=v[p])&&schedule(_,n,e,p,v,d);a.push(v);s.push(l)}return new Transition(a,s,n,e)}var F=i.prototype.constructor;function transition_selection(){return new F(this._groups,this._parents)}function styleNull(t,n){var e,r,i;return function(){var a=o(this,t),s=(this.style.removeProperty(t),o(this,t));return a===s?null:a===e&&s===r?i:i=n(e=a,r=s)}}function styleRemove(t){return function(){this.style.removeProperty(t)}}function styleConstant(t,n,e){var r,i,a=e+"";return function(){var s=o(this,t);return s===a?null:s===r?i:i=n(r=s,e)}}function styleFunction(t,n,e){var r,i,a;return function(){var s=o(this,t),u=e(this),l=u+"";null==u&&(l=u=(this.style.removeProperty(t),o(this,t)));return s===l?null:s===r&&l===i?a:(i=l,a=n(r=s,u))}}function styleMaybeRemove(t,n){var e,r,i,o,a="style."+n,s="end."+a;return function(){var u=set(this,t),l=u.on,c=null==u.value[a]?o||(o=styleRemove(n)):void 0;l===e&&i===c||(r=(e=l).copy()).on(s,i=c);u.on=r}}function transition_style(t,n,e){var r="transform"===(t+="")?v:interpolate;return null==n?this.styleTween(t,styleNull(t,r)).on("end.style."+t,styleRemove(t)):"function"===typeof n?this.styleTween(t,styleFunction(t,r,tweenValue(this,"style."+t,n))).each(styleMaybeRemove(this._id,t)):this.styleTween(t,styleConstant(t,r,n),e).on("end.style."+t,null)}function styleInterpolate(t,n,e){return function(r){this.style.setProperty(t,n.call(this,r),e)}}function styleTween(t,n,e){var r,i;function tween(){var o=n.apply(this,arguments);o!==i&&(r=(i=o)&&styleInterpolate(t,o,e));return r}tween._value=n;return tween}function transition_styleTween(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,styleTween(t,n,null==e?"":e))}function textConstant(t){return function(){this.textContent=t}}function textFunction(t){return function(){var n=t(this);this.textContent=null==n?"":n}}function transition_text(t){return this.tween("text","function"===typeof t?textFunction(tweenValue(this,"text",t)):textConstant(null==t?"":t+""))}function textInterpolate(t){return function(n){this.textContent=t.call(this,n)}}function textTween(t){var n,e;function tween(){var r=t.apply(this,arguments);r!==e&&(n=(e=r)&&textInterpolate(r));return n}tween._value=t;return tween}function transition_textTween(t){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(null==t)return this.tween(n,null);if("function"!==typeof t)throw new Error;return this.tween(n,textTween(t))}function transition_transition(){var t=this._name,n=this._id,e=newId();for(var r=this._groups,i=r.length,o=0;o<i;++o)for(var a,s=r[o],u=s.length,l=0;l<u;++l)if(a=s[l]){var c=get(a,n);schedule(a,t,e,l,s,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new Transition(r,this._parents,t,e)}function transition_end(){var t,n,e=this,r=e._id,i=e.size();return new Promise((function(o,a){var s={value:a},u={value:function(){0===--i&&o()}};e.each((function(){var e=set(this,r),i=e.on;if(i!==t){n=(t=i).copy();n._.cancel.push(s);n._.interrupt.push(s);n._.end.push(u)}e.on=n}));0===i&&o()}))}var b=0;function Transition(t,n,e,r){this._groups=t;this._parents=n;this._name=e;this._id=r}function transition(t){return i().transition(t)}function newId(){return++b}var S=i.prototype;Transition.prototype=transition.prototype={constructor:Transition,select:transition_select,selectAll:transition_selectAll,selectChild:S.selectChild,selectChildren:S.selectChildren,filter:transition_filter,merge:transition_merge,selection:transition_selection,transition:transition_transition,call:S.call,nodes:S.nodes,node:S.node,size:S.size,empty:S.empty,each:S.each,on:transition_on,attr:transition_attr,attrTween:transition_attrTween,style:transition_style,styleTween:transition_styleTween,text:transition_text,textTween:transition_textTween,remove:transition_remove,tween:transition_tween,delay:transition_delay,duration:transition_duration,ease:transition_ease,easeVarying:transition_easeVarying,end:transition_end,[Symbol.iterator]:S[Symbol.iterator]};var E={time:null,delay:0,duration:250,ease:p};function inherit(t,n){var e;while(!(e=t.__transition)||!(e=e[n]))if(!(t=t.parentNode))throw new Error(`transition ${n} not found`);return e}function selection_transition(t){var n,e;t instanceof Transition?(n=t._id,t=t._name):(n=newId(),(e=E).time=l(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,o=0;o<i;++o)for(var a,s=r[o],u=s.length,c=0;c<u;++c)(a=s[c])&&schedule(a,t,n,c,s,e||inherit(a,n));return new Transition(r,this._parents,t,n)}i.prototype.interrupt=selection_interrupt;i.prototype.transition=selection_transition;var I=[null];function active(t,n){var e,r,i=t.__transition;if(i){n=null==n?null:n+"";for(r in i)if((e=i[r]).state>g&&e.name===n)return new Transition([[t]],I,n,+r)}return null}export{active,interrupt,transition};