vega-dataflow
Advanced tools
Comparing version 4.0.4 to 4.1.0
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vega-util"),require("vega-loader")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-loader"],n):n(t.vega={},t.vega,t.vega)}(this,function(t,m,l){"use strict";function h(t){var r=t||m.identity,i=[],s={};return i.add=function(t){var n=r(t);return s[n]||(s[n]=1,i.push(t)),i},i.remove=function(t){var n,e=r(t);return s[e]&&(s[e]=0)<=(n=i.indexOf(t))&&i.splice(n,1),i},i}var e=Symbol("vega_id"),r=1;function _(t){return t[e]}function i(t,n){return t[e]=n,t}function y(t){var n=t===Object(t)?t:{data:t};return _(n)?n:i(n,r++)}function n(t,n){for(var e in t)n[e]=t[e];return n}function c(t){return t&&t.constructor===s}function s(){var c=[],f=[],d=[],p=[],v=[],g=!1;return{constructor:s,insert:function(t){for(var n=m.array(t),e=0,r=n.length;e<r;++e)c.push(n[e]);return this},remove:function(t){for(var n=m.isFunction(t)?p:f,e=m.array(t),r=0,i=e.length;r<i;++r)n.push(e[r]);return this},modify:function(t,n,e){var r={field:n,value:m.constant(e)};return m.isFunction(t)?(r.filter=t,v.push(r)):(r.tuple=t,d.push(r)),this},encode:function(t,n){return m.isFunction(t)?v.push({filter:t,field:n}):d.push({tuple:t,field:n}),this},reflow:function(){return g=!0,this},pulse:function(r,t){var n,e,i,s,u,o,a={},h={};for(n=0,e=t.length;n<e;++n)a[_(t[n])]=1;for(n=0,e=f.length;n<e;++n)a[_(u=f[n])]=-1;for(n=0,e=p.length;n<e;++n)s=p[n],t.forEach(function(t){s(t)&&(a[_(t)]=-1)});for(n=0,e=c.length;n<e;++n)o=_(u=c[n]),a[o]?a[o]=1:r.add.push(y(c[n]));for(n=0,e=t.length;n<e;++n)u=t[n],a[_(u)]<0&&r.rem.push(u);function l(t,n,e){e?t[n]=e(t):r.encode=n,g||(h[_(t)]=t)}for(n=0,e=d.length;n<e;++n)u=(i=d[n]).tuple,s=i.field,0<(o=a[_(u)])&&(l(u,s,i.value),r.modifies(s));for(n=0,e=v.length;n<e;++n)i=v[n],s=i.filter,t.forEach(function(t){s(t)&&0<a[_(t)]&&l(t,i.field,i.value)}),r.modifies(i.field);if(g)r.mod=f.length||p.length?t.filter(function(t){return 0<a[_(t)]}):t.slice();else for(o in h)r.mod.push(h[o]);return r}}}var u="_:mod:_";function f(){Object.defineProperty(this,u,{writable:!0,value:{}})}var o=f.prototype;o.set=function(t,n,e,r){var i=this[t],s=this[u];return null!=n&&0<=n?(i[n]!==e||r)&&(i[n]=e,s[n+":"+t]=-1,s[t]=-1):(i!==e||r)&&(this[t]=e,s[t]=m.isArray(e)?1+e.length:-1),this},o.modified=function(t,n){var e,r=this[u];if(!arguments.length){for(e in r)if(r[e])return!0;return!1}if(m.isArray(t)){for(e=0;e<t.length;++e)if(r[t[e]])return!0;return!1}return null!=n&&0<=n?n+1<r[t]||!!r[n+":"+t]:!!r[t]},o.clear=function(){return this[u]={},this};var a=0,d=new f;function p(t,n,e,r){this.id=++a,this.value=t,this.stamp=-1,this.rank=-1,this.qrank=-1,this.flags=0,n&&(this._update=n),e&&this.parameters(e,r)}var v=p.prototype;function g(e){return function(t){var n=this.flags;return 0===arguments.length?!!(n&e):(this.flags=t?n|e:n&~e,this)}}v.targets=function(){return this._targets||(this._targets=h(m.id))},v.set=function(t){return this.value!==t?(this.value=t,1):0},v.skip=g(1),v.modified=g(2),v.parameters=function(t,r){r=!1!==r;var n,e,i,s,u=this,o=u._argval=u._argval||new f,a=u._argops=u._argops||[],h=[];function l(t,n,e){e instanceof p?(e!==u&&(r&&e.targets().add(u),h.push(e)),a.push({op:e,name:t,index:n})):o.set(t,n,e)}for(n in t)if(e=t[n],"pulse"===n)m.array(e).forEach(function(t){t instanceof p?t!==u&&(t.targets().add(u),h.push(t)):m.error("Pulse parameters must be operator instances.")}),u.source=e;else if(m.isArray(e))for(o.set(n,-1,Array(i=e.length)),s=0;s<i;++s)l(n,s,e[s]);else l(n,-1,e);return this.marshall().clear(),h},v.marshall=function(t){var n,e,r,i,s,u=this._argval||d,o=this._argops;if(o&&(r=o.length))for(e=0;e<r;++e)s=(i=(n=o[e]).op).modified()&&i.stamp===t,u.set(n.name,n.index,i.value,s);return u},v.evaluate=function(t){if(this._update){var n=this.marshall(t.stamp),e=this._update(n,t);if(n.clear(),e!==this.value)this.value=e;else if(!this.modified())return t.StopPropagation}},v.run=function(t){return t.stamp<=this.stamp?t.StopPropagation:(this.skip()?(this.skip(!1),n=0):n=this.evaluate(t),this.stamp=t.stamp,this.pulse=n||t);var n};var k=0;function F(t,n,e){this.id=++k,this.value=null,e&&(this.receive=e),t&&(this._filter=t),n&&(this._apply=n)}function w(t,n,e){return new F(t,n,e)}var A=F.prototype;A._filter=m.truthy,A._apply=m.identity,A.targets=function(){return this._targets||(this._targets=h(m.id))},A.consume=function(t){return arguments.length?(this._consume=!!t,this):!!this._consume},A.receive=function(t){if(this._filter(t)){for(var n=this.value=this._apply(t),e=this._targets,r=e?e.length:0,i=0;i<r;++i)e[i].receive(n);this._consume&&(t.preventDefault(),t.stopPropagation())}},A.filter=function(t){var n=w(t);return this.targets().add(n),n},A.apply=function(t){var n=w(null,t);return this.targets().add(n),n},A.merge=function(){var t=w();this.targets().add(t);for(var n=0,e=arguments.length;n<e;++n)arguments[n].targets().add(t);return t},A.throttle=function(n){var e=-1;return this.filter(function(){var t=Date.now();return n<t-e?(e=t,1):0})},A.debounce=function(t){var e=w();return this.targets().add(w(null,null,m.debounce(t,function(t){var n=t.dataflow;e.receive(t),n&&n.run&&n.run()}))),e},A.between=function(t,n){var e=!1;return t.targets().add(w(null,null,function(){e=!0})),n.targets().add(w(null,null,function(){e=!1})),this.filter(function(){return e})};var D={skip:!0};function O(r,t,i,n,e,s){var u,o,a=m.extend({},s,D);m.isFunction(i)||(i=m.constant(i)),void 0===n?u=function(t){r.touch(i(t))}:m.isFunction(n)?(o=new p(null,n,e,!1),u=function(t){var n,e=i(t);o.evaluate(t),c(n=o.value)?r.pulse(e,n,s):r.update(e,n,a)}):u=function(t){r.update(i(t),n,a)},t.apply(u)}function P(t,n,r,e,i,s){var u,o;void 0===e?o=r:(u=m.isFunction(e)?e:m.constant(e),(o=new p(null,e=r?function(t,n){var e=u(t,n);return r.skip()||(r.skip(e!==this.value).value=e),e}:u,i,!1)).modified(s&&s.force),o.rank=0,r&&(o.skip(!0),o.value=r.value,o.targets().add(r))),n.targets().add(o)}var E={};function q(t,n,e){this.dataflow=t,this.stamp=null==n?-1:n,this.add=[],this.rem=[],this.mod=[],this.fields=null,this.encode=e||null}var b=q.prototype;function M(e,r){return e?function(t,n){return e(t,n)&&r(t,n)}:r}function S(t,n){var e=[];return m.visitArray(t,n,function(t){e.push(t)}),e}function L(t,n){var e={};return t.visit(n,function(t){e[_(t)]=1}),function(t){return e[_(t)]?null:t}}function R(t,n,e,r){var i,s,u,o,a,h=this,l=0;for(this.dataflow=t,this.stamp=n,this.fields=null,this.encode=r||null,u=0,o=(this.pulses=e).length;u<o;++u)if((i=e[u]).stamp===n){if(i.fields)for(a in s=h.fields||(h.fields={}),i.fields)s[a]=1;i.changed(h.ADD)&&(l|=h.ADD),i.changed(h.REM)&&(l|=h.REM),i.changed(h.MOD)&&(l|=h.MOD)}this.changes=l}b.StopPropagation=E,b.ADD=1,b.REM=2,b.MOD=4,b.ADD_REM=3,b.ADD_MOD=5,b.ALL=7,b.REFLOW=8,b.SOURCE=16,b.NO_SOURCE=32,b.NO_FIELDS=64,b.fork=function(t){return new q(this.dataflow).init(this,t)},b.clone=function(){var t=this.fork(7);return t.add=t.add.slice(),t.rem=t.rem.slice(),t.mod=t.mod.slice(),t.source&&(t.source=t.source.slice()),t.materialize(23)},b.addAll=function(){var t=this;return this.source&&this.source.length!==this.add.length&&((t=new q(this.dataflow).init(this)).add=t.source),t},b.init=function(t,n){var e=this;return e.stamp=t.stamp,e.encode=t.encode,!t.fields||64&n||(e.fields=t.fields),1&n?(e.addF=t.addF,e.add=t.add):(e.addF=null,e.add=[]),2&n?(e.remF=t.remF,e.rem=t.rem):(e.remF=null,e.rem=[]),4&n?(e.modF=t.modF,e.mod=t.mod):(e.modF=null,e.mod=[]),32&n?(e.srcF=null,e.source=null):(e.srcF=t.srcF,e.source=t.source),e},b.runAfter=function(t){this.dataflow.runAfter(t)},b.changed=function(t){var n=t||7;return 1&n&&this.add.length||2&n&&this.rem.length||4&n&&this.mod.length},b.reflow=function(t){if(t)return this.fork(7).reflow();var n=this.add.length,e=this.source&&this.source.length;return e&&e!==n&&(this.mod=this.source,n&&this.filter(4,L(this,1))),this},b.modifies=function(t){var n=m.array(t),e=this.fields||(this.fields={});return n.forEach(function(t){e[t]=!0}),this},b.modified=function(t){var n=this.fields;return!(!this.mod.length||!n)&&(arguments.length?m.isArray(t)?t.some(function(t){return n[t]}):n[t]:!!n)},b.filter=function(t,n){var e=this;return 1&t&&(e.addF=M(e.addF,n)),2&t&&(e.remF=M(e.remF,n)),4&t&&(e.modF=M(e.modF,n)),16&t&&(e.srcF=M(e.srcF,n)),e},b.materialize=function(t){var n=this;return 1&(t=t||7)&&n.addF&&(n.add=S(n.add,n.addF),n.addF=null),2&t&&n.remF&&(n.rem=S(n.rem,n.remF),n.remF=null),4&t&&n.modF&&(n.mod=S(n.mod,n.modF),n.modF=null),16&t&&n.srcF&&(n.source=n.source.filter(n.srcF),n.srcF=null),n},b.visit=function(t,n){var e,r,i=this,s=n;return 16&t?m.visitArray(i.source,i.srcF,s):(1&t&&m.visitArray(i.add,i.addF,s),2&t&&m.visitArray(i.rem,i.remF,s),4&t&&m.visitArray(i.mod,i.modF,s),8&t&&(e=i.source)&&((r=i.add.length+i.mod.length)===e.length||(r?m.visitArray(e,L(i,5),s):m.visitArray(e,i.srcF,s)))),i};var x=m.inherits(R,q);function T(n,t){try{t(n)}catch(t){n.error(t)}}x.fork=function(t){var n=new q(this.dataflow).init(this,t&this.NO_FIELDS);return void 0!==t&&(t&n.ADD&&this.visit(n.ADD,function(t){return n.add.push(t)}),t&n.REM&&this.visit(n.REM,function(t){return n.rem.push(t)}),t&n.MOD&&this.visit(n.MOD,function(t){return n.mod.push(t)})),n},x.changed=function(t){return this.changes&t},x.modified=function(t){var n=this.fields;return n&&this.changes&this.MOD?m.isArray(t)?t.some(function(t){return n[t]}):n[t]:0},x.filter=function(){m.error("MultiPulse does not support filtering.")},x.materialize=function(){m.error("MultiPulse does not support materialization.")};var z={skip:!(x.visit=function(t,n){var e=this.pulses,r=e.length,i=0;if(t&this.SOURCE)for(;i<r;++i)e[i].visit(t,n);else for(;i<r;++i)e[i].stamp===this.stamp&&e[i].visit(t,n);return this}),force:!1};function C(t){this.cmp=t,this.nodes=[]}var I=C.prototype;function U(t,n,e,r){var i,s,u;for(i=t[e];n<e&&r(i,s=t[u=e-1>>1])<0;)t[e]=s,e=u;return t[e]=i}function j(t,n,e){for(var r,i=n,s=t.length,u=t[n],o=2*n+1;o<s;)(r=o+1)<s&&0<=e(t[o],t[r])&&(o=r),t[n]=t[o],o=2*(n=o)+1;return t[n]=u,U(t,i,n,e)}function N(){this._log=m.logger(),this.logLevel(m.Error),this._clock=0,this._rank=0;try{this._loader=l.loader()}catch(t){}this._touched=h(m.id),this._pulses={},this._pulse=null,this._heap=new C(function(t,n){return t.qrank-n.qrank}),this._postrun=[]}I.size=function(){return this.nodes.length},I.clear=function(){return this.nodes=[],this},I.peek=function(){return this.nodes[0]},I.push=function(t){var n=this.nodes;return n.push(t),U(n,0,n.length-1,this.cmp)},I.pop=function(){var t,n=this.nodes,e=n.pop();return n.length?(t=n[0],n[0]=e,j(n,0,this.cmp)):t=e,t},I.replace=function(t){var n=this.nodes,e=n[0];return n[0]=t,j(n,0,this.cmp),e},I.pushpop=function(t){var n=this.nodes,e=n[0];return n.length&&this.cmp(e,t)<0&&(n[0]=t,t=e,j(n,0,this.cmp)),t};var G=N.prototype;function W(t){return function(){return this._log[t].apply(this,arguments)}}function B(t,n){p.call(this,t,null,n)}G.stamp=function(){return this._clock},G.loader=function(t){return arguments.length?(this._loader=t,this):this._loader},G.cleanThreshold=1e4,G.add=function(t,n,e,r){var i,s=1;return t instanceof p?i=t:t&&t.prototype instanceof p?i=new t:m.isFunction(t)?i=new p(null,t):(s=0,i=new p(t,n)),this.rank(i),s&&(r=e,e=n),e&&this.connect(i,i.parameters(e,r)),this.touch(i),i},G.connect=function(t,n){var e,r,i=t.rank;for(e=0,r=n.length;e<r;++e)if(i<n[e].rank)return void this.rerank(t)},G.rank=function(t){t.rank=++this._rank},G.rerank=function(t){for(var n,e,r,i=[t];i.length;)if(this.rank(n=i.pop()),e=n._targets)for(r=e.length;0<=--r;)i.push(n=e[r]),n===t&&m.error("Cycle detected in dataflow graph.")},G.pulse=function(t,n,e){this.touch(t,e||z);var r=new q(this,this._clock+(this._pulse?0:1)),i=t.pulse&&t.pulse.source||[];return r.target=t,this._pulses[t.id]=n.pulse(r,i),this},G.touch=function(t,n){var e=n||z;return this._pulse?this._enqueue(t):this._touched.add(t),e.skip&&t.skip(!0),this},G.update=function(t,n,e){var r=e||z;return(t.set(n)||r.force)&&this.touch(t,r),this},G.changeset=s,G.ingest=function(t,n,e){return this.pulse(t,this.changeset().insert(l.read(n,e)))},G.request=function(n,e,r){var i,s,u,t,o=this,a=0,h=o._pending||(i=o,(t=new Promise(function(t,n){s=function(){t(i)},u=n})).requests=0,t.done=function(){0==--t.requests&&i.runAfter(function(){i._pending=null;try{i.run(),i._pending?i._pending.then(s):s()}catch(t){u(t)}})},i._pending=t);return h.requests+=1,o.loader().load(e,{context:"dataflow"}).then(function(t){return l.read(t,r)},function(t){a=-1,o.error("Loading failed",e,t)}).catch(function(t){a=-2,o.error("Data ingestion failed",e,t)}).then(function(t){return o.pulse(n,o.changeset().remove(m.truthy).insert(t||[])),h.done(),a})},G.events=function(t,n,e,r){for(var i,s=this,u=w(e,r),o=function(t){t.dataflow=s;try{u.receive(t)}catch(t){s.error(t)}finally{s.run()}},a=0,h=(i="string"==typeof t&&"undefined"!=typeof document?document.querySelectorAll(t):m.array(t)).length;a<h;++a)i[a].addEventListener(n,o);return u},G.on=function(t,n,e,r,i){return(t instanceof p?P:O)(this,t,n,e,r,i),this},G.run=function(t){var n,e,r,i,s=this,u=0,o=s.logLevel();if(s._pending)return s.info("Awaiting requests, delaying dataflow run."),0;if(s._pulse)return s.error("Dataflow invoked recursively. Use the runAfter method to queue invocation."),0;if(!s._touched.length)return s.info("Dataflow invoked, but nothing to do."),0;s._pulse=new q(s,++s._clock,t),o>=m.Info&&(r=Date.now(),s.debug("-- START PROPAGATION ("+s._clock+") -----")),s._touched.forEach(function(t){s._enqueue(t,!0)}),s._touched=h(m.id);try{for(;0<s._heap.size();)(n=s._heap.pop()).rank===n.qrank?(e=n.run(s._getPulse(n,t)),o>=m.Debug&&s.debug(n.id,e===E?"STOP":e,n),e!==E&&(s._pulse=e,n._targets&&n._targets.forEach(function(t){s._enqueue(t)})),++u):s._enqueue(n,!0)}catch(t){i=t}if(s._pulses={},s._pulse=null,o>=m.Info&&(r=Date.now()-r,s.info("> Pulse "+s._clock+": "+u+" operators; "+r+"ms")),i&&(s._postrun=[],s.error(i)),s._onrun)try{s._onrun(s,u,i)}catch(t){s.error(t)}if(s._postrun.length){var a=s._postrun;s._postrun=[],a.sort(function(t,n){return n.priority-t.priority}).forEach(function(t){T(s,t.callback)})}return this},G.runAsync=function(){return this._pending||this.run()&&this._pending||Promise.resolve(this)},G.runAfter=function(t,n,e){this._pulse||n?this._postrun.push({priority:e||0,callback:t}):T(this,t)},G._enqueue=function(t,n){var e=!this._pulses[t.id];e&&(this._pulses[t.id]=this._pulse),(e||n)&&(t.qrank=t.rank,this._heap.push(t))},G._getPulse=function(t,n){var e,r=t.source,i=this._clock;return r&&m.isArray(r)?new R(this,i,e=r.map(function(t){return t.pulse}),n):(e=this._pulses[t.id],r&&((r=r.pulse)&&r!==E?r.stamp===i&&e.target!==t?e=r:e.source=r.source:e.source=[]),e)},G.error=W("error"),G.warn=W("warn"),G.info=W("info"),G.debug=W("debug"),G.logLevel=W("level");var H=m.inherits(B,p);H.run=function(t){return t.stamp<=this.stamp?t.StopPropagation:(this.skip()?this.skip(!1):n=this.evaluate(t),(n=n||t)!==t.StopPropagation&&(this.pulse=n),this.stamp=t.stamp,n);var n},H.evaluate=function(t){var n=this.marshall(t.stamp),e=this.transform(n,t);return n.clear(),e},H.transform=function(){};var J={};function K(t){return t=t&&t.toLowerCase(),J.hasOwnProperty(t)?J[t]:null}t.UniqueList=h,t.changeset=s,t.isChangeSet=c,t.Dataflow=N,t.EventStream=F,t.Parameters=f,t.Pulse=q,t.MultiPulse=R,t.Operator=p,t.Transform=B,t.derive=function(t){return n(t,y({}))},t.rederive=n,t.ingest=y,t.isTuple=function(t){return!(!t||!_(t))},t.replace=function(t,n){return i(n,_(t))},t.tupleid=_,t.definition=function(t){var n=K(t);return n&&n.Definition||null},t.transform=K,t.transforms=J,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vega-loader"),require("vega-util")):"function"==typeof define&&define.amd?define(["exports","vega-loader","vega-util"],n):n(t.vega={},t.vega,t.vega)}(this,function(t,h,m){"use strict";function l(t){var r=t||m.identity,i=[],s={};return i.add=function(t){var n=r(t);return s[n]||(s[n]=1,i.push(t)),i},i.remove=function(t){var n,e=r(t);return s[e]&&(s[e]=0)<=(n=i.indexOf(t))&&i.splice(n,1),i},i}var e=Symbol("vega_id"),r=1;function _(t){return t[e]}function i(t,n){return t[e]=n,t}function y(t){var n=t===Object(t)?t:{data:t};return _(n)?n:i(n,r++)}function n(t,n){for(var e in t)n[e]=t[e];return n}function c(t){return t&&t.constructor===s}function s(){var c=[],f=[],d=[],p=[],v=[],g=!1;return{constructor:s,insert:function(t){for(var n=m.array(t),e=0,r=n.length;e<r;++e)c.push(n[e]);return this},remove:function(t){for(var n=m.isFunction(t)?p:f,e=m.array(t),r=0,i=e.length;r<i;++r)n.push(e[r]);return this},modify:function(t,n,e){var r={field:n,value:m.constant(e)};return m.isFunction(t)?(r.filter=t,v.push(r)):(r.tuple=t,d.push(r)),this},encode:function(t,n){return m.isFunction(t)?v.push({filter:t,field:n}):d.push({tuple:t,field:n}),this},reflow:function(){return g=!0,this},pulse:function(r,t){var n,e,i,s,u,o,a={},l={};for(n=0,e=t.length;n<e;++n)a[_(t[n])]=1;for(n=0,e=f.length;n<e;++n)a[_(u=f[n])]=-1;for(n=0,e=p.length;n<e;++n)s=p[n],t.forEach(function(t){s(t)&&(a[_(t)]=-1)});for(n=0,e=c.length;n<e;++n)o=_(u=c[n]),a[o]?a[o]=1:r.add.push(y(c[n]));for(n=0,e=t.length;n<e;++n)u=t[n],a[_(u)]<0&&r.rem.push(u);function h(t,n,e){e?t[n]=e(t):r.encode=n,g||(l[_(t)]=t)}for(n=0,e=d.length;n<e;++n)u=(i=d[n]).tuple,s=i.field,0<(o=a[_(u)])&&(h(u,s,i.value),r.modifies(s));for(n=0,e=v.length;n<e;++n)i=v[n],s=i.filter,t.forEach(function(t){s(t)&&0<a[_(t)]&&h(t,i.field,i.value)}),r.modifies(i.field);if(g)r.mod=f.length||p.length?t.filter(function(t){return 0<a[_(t)]}):t.slice();else for(o in l)r.mod.push(l[o]);return r}}}var u="_:mod:_";function f(){Object.defineProperty(this,u,{writable:!0,value:{}})}var o=f.prototype;o.set=function(t,n,e,r){var i=this[t],s=this[u];return null!=n&&0<=n?(i[n]!==e||r)&&(i[n]=e,s[n+":"+t]=-1,s[t]=-1):(i!==e||r)&&(this[t]=e,s[t]=m.isArray(e)?1+e.length:-1),this},o.modified=function(t,n){var e,r=this[u];if(!arguments.length){for(e in r)if(r[e])return!0;return!1}if(m.isArray(t)){for(e=0;e<t.length;++e)if(r[t[e]])return!0;return!1}return null!=n&&0<=n?n+1<r[t]||!!r[n+":"+t]:!!r[t]},o.clear=function(){return this[u]={},this};var a=0,d=new f;function p(t,n,e,r){this.id=++a,this.value=t,this.stamp=-1,this.rank=-1,this.qrank=-1,this.flags=0,n&&(this._update=n),e&&this.parameters(e,r)}var v=p.prototype;function g(e){return function(t){var n=this.flags;return 0===arguments.length?!!(n&e):(this.flags=t?n|e:n&~e,this)}}v.targets=function(){return this._targets||(this._targets=l(m.id))},v.set=function(t){return this.value!==t?(this.value=t,1):0},v.skip=g(1),v.modified=g(2),v.parameters=function(t,r,n){r=!1!==r;var e,i,s,u,o=this,a=o._argval=o._argval||new f,l=o._argops=o._argops||[],h=[];function c(t,n,e){e instanceof p?(e!==o&&(r&&e.targets().add(o),h.push(e)),l.push({op:e,name:t,index:n})):a.set(t,n,e)}for(e in t)if(i=t[e],"pulse"===e)m.array(i).forEach(function(t){t instanceof p?t!==o&&(t.targets().add(o),h.push(t)):m.error("Pulse parameters must be operator instances.")}),o.source=i;else if(m.isArray(i))for(a.set(e,-1,Array(s=i.length)),u=0;u<s;++u)c(e,u,i[u]);else c(e,-1,i);return this.marshall().clear(),n&&(l.initonly=!0),h},v.marshall=function(t){var n,e,r,i,s,u=this._argval||d,o=this._argops;if(o){for(e=0,r=o.length;e<r;++e)s=(i=(n=o[e]).op).modified()&&i.stamp===t,u.set(n.name,n.index,i.value,s);if(o.initonly){for(e=0;e<r;++e)(n=o[e]).op.targets().remove(this);this._argops=null,this._update=null}}return u},v.evaluate=function(t){var n=this._update;if(n){var e=this.marshall(t.stamp),r=n.call(this,e,t);if(e.clear(),r!==this.value)this.value=r;else if(!this.modified())return t.StopPropagation}},v.run=function(t){return t.stamp<=this.stamp?t.StopPropagation:(this.skip()?(this.skip(!1),n=0):n=this.evaluate(t),this.stamp=t.stamp,this.pulse=n||t);var n};var k=0;function F(t,n,e){this.id=++k,this.value=null,e&&(this.receive=e),t&&(this._filter=t),n&&(this._apply=n)}function w(t,n,e){return new F(t,n,e)}var A=F.prototype;A._filter=m.truthy,A._apply=m.identity,A.targets=function(){return this._targets||(this._targets=l(m.id))},A.consume=function(t){return arguments.length?(this._consume=!!t,this):!!this._consume},A.receive=function(t){if(this._filter(t)){for(var n=this.value=this._apply(t),e=this._targets,r=e?e.length:0,i=0;i<r;++i)e[i].receive(n);this._consume&&(t.preventDefault(),t.stopPropagation())}},A.filter=function(t){var n=w(t);return this.targets().add(n),n},A.apply=function(t){var n=w(null,t);return this.targets().add(n),n},A.merge=function(){var t=w();this.targets().add(t);for(var n=0,e=arguments.length;n<e;++n)arguments[n].targets().add(t);return t},A.throttle=function(n){var e=-1;return this.filter(function(){var t=Date.now();return n<t-e?(e=t,1):0})},A.debounce=function(t){var e=w();return this.targets().add(w(null,null,m.debounce(t,function(t){var n=t.dataflow;e.receive(t),n&&n.run&&n.run()}))),e},A.between=function(t,n){var e=!1;return t.targets().add(w(null,null,function(){e=!0})),n.targets().add(w(null,null,function(){e=!1})),this.filter(function(){return e})};var D={skip:!0};function O(r,t,i,n,e,s){var u,o,a=m.extend({},s,D);m.isFunction(i)||(i=m.constant(i)),void 0===n?u=function(t){r.touch(i(t))}:m.isFunction(n)?(o=new p(null,n,e,!1),u=function(t){var n,e=i(t);o.evaluate(t),c(n=o.value)?r.pulse(e,n,s):r.update(e,n,a)}):u=function(t){r.update(i(t),n,a)},t.apply(u)}function P(t,n,r,e,i,s){var u,o;void 0===e?o=r:(u=m.isFunction(e)?e:m.constant(e),(o=new p(null,e=r?function(t,n){var e=u(t,n);return r.skip()||(r.skip(e!==this.value).value=e),e}:u,i,!1)).modified(s&&s.force),o.rank=0,r&&(o.skip(!0),o.value=r.value,o.targets().add(r))),n.targets().add(o)}var E={};function q(t,n,e){this.dataflow=t,this.stamp=null==n?-1:n,this.add=[],this.rem=[],this.mod=[],this.fields=null,this.encode=e||null}var b=q.prototype;function M(e,r){return e?function(t,n){return e(t,n)&&r(t,n)}:r}function S(t,n){var e=[];return m.visitArray(t,n,function(t){e.push(t)}),e}function L(t,n){var e={};return t.visit(n,function(t){e[_(t)]=1}),function(t){return e[_(t)]?null:t}}function R(t,n,e,r){var i,s,u,o,a,l=this,h=0;for(this.dataflow=t,this.stamp=n,this.fields=null,this.encode=r||null,u=0,o=(this.pulses=e).length;u<o;++u)if((i=e[u]).stamp===n){if(i.fields)for(a in s=l.fields||(l.fields={}),i.fields)s[a]=1;i.changed(l.ADD)&&(h|=l.ADD),i.changed(l.REM)&&(h|=l.REM),i.changed(l.MOD)&&(h|=l.MOD)}this.changes=h}b.StopPropagation=E,b.ADD=1,b.REM=2,b.MOD=4,b.ADD_REM=3,b.ADD_MOD=5,b.ALL=7,b.REFLOW=8,b.SOURCE=16,b.NO_SOURCE=32,b.NO_FIELDS=64,b.fork=function(t){return new q(this.dataflow).init(this,t)},b.clone=function(){var t=this.fork(7);return t.add=t.add.slice(),t.rem=t.rem.slice(),t.mod=t.mod.slice(),t.source&&(t.source=t.source.slice()),t.materialize(23)},b.addAll=function(){var t=this;return this.source&&this.source.length!==this.add.length&&((t=new q(this.dataflow).init(this)).add=t.source),t},b.init=function(t,n){var e=this;return e.stamp=t.stamp,e.encode=t.encode,!t.fields||64&n||(e.fields=t.fields),1&n?(e.addF=t.addF,e.add=t.add):(e.addF=null,e.add=[]),2&n?(e.remF=t.remF,e.rem=t.rem):(e.remF=null,e.rem=[]),4&n?(e.modF=t.modF,e.mod=t.mod):(e.modF=null,e.mod=[]),32&n?(e.srcF=null,e.source=null):(e.srcF=t.srcF,e.source=t.source),e},b.runAfter=function(t){this.dataflow.runAfter(t)},b.changed=function(t){var n=t||7;return 1&n&&this.add.length||2&n&&this.rem.length||4&n&&this.mod.length},b.reflow=function(t){if(t)return this.fork(7).reflow();var n=this.add.length,e=this.source&&this.source.length;return e&&e!==n&&(this.mod=this.source,n&&this.filter(4,L(this,1))),this},b.modifies=function(t){var n=m.array(t),e=this.fields||(this.fields={});return n.forEach(function(t){e[t]=!0}),this},b.modified=function(t){var n=this.fields;return!(!this.mod.length||!n)&&(arguments.length?m.isArray(t)?t.some(function(t){return n[t]}):n[t]:!!n)},b.filter=function(t,n){var e=this;return 1&t&&(e.addF=M(e.addF,n)),2&t&&(e.remF=M(e.remF,n)),4&t&&(e.modF=M(e.modF,n)),16&t&&(e.srcF=M(e.srcF,n)),e},b.materialize=function(t){var n=this;return 1&(t=t||7)&&n.addF&&(n.add=S(n.add,n.addF),n.addF=null),2&t&&n.remF&&(n.rem=S(n.rem,n.remF),n.remF=null),4&t&&n.modF&&(n.mod=S(n.mod,n.modF),n.modF=null),16&t&&n.srcF&&(n.source=n.source.filter(n.srcF),n.srcF=null),n},b.visit=function(t,n){var e,r,i=this,s=n;return 16&t?m.visitArray(i.source,i.srcF,s):(1&t&&m.visitArray(i.add,i.addF,s),2&t&&m.visitArray(i.rem,i.remF,s),4&t&&m.visitArray(i.mod,i.modF,s),8&t&&(e=i.source)&&((r=i.add.length+i.mod.length)===e.length||(r?m.visitArray(e,L(i,5),s):m.visitArray(e,i.srcF,s)))),i};var x=m.inherits(R,q);function T(n,t){try{t(n)}catch(t){n.error(t)}}x.fork=function(t){var n=new q(this.dataflow).init(this,t&this.NO_FIELDS);return void 0!==t&&(t&n.ADD&&this.visit(n.ADD,function(t){return n.add.push(t)}),t&n.REM&&this.visit(n.REM,function(t){return n.rem.push(t)}),t&n.MOD&&this.visit(n.MOD,function(t){return n.mod.push(t)})),n},x.changed=function(t){return this.changes&t},x.modified=function(t){var n=this.fields;return n&&this.changes&this.MOD?m.isArray(t)?t.some(function(t){return n[t]}):n[t]:0},x.filter=function(){m.error("MultiPulse does not support filtering.")},x.materialize=function(){m.error("MultiPulse does not support materialization.")};var z={skip:!(x.visit=function(t,n){var e=this.pulses,r=e.length,i=0;if(t&this.SOURCE)for(;i<r;++i)e[i].visit(t,n);else for(;i<r;++i)e[i].stamp===this.stamp&&e[i].visit(t,n);return this}),force:!1};function C(t){this.cmp=t,this.nodes=[]}var I=C.prototype;function U(t,n,e,r){var i,s,u;for(i=t[e];n<e&&r(i,s=t[u=e-1>>1])<0;)t[e]=s,e=u;return t[e]=i}function j(t,n,e){for(var r,i=n,s=t.length,u=t[n],o=2*n+1;o<s;)(r=o+1)<s&&0<=e(t[o],t[r])&&(o=r),t[n]=t[o],o=2*(n=o)+1;return t[n]=u,U(t,i,n,e)}function N(){this._log=m.logger(),this.logLevel(m.Error),this._clock=0,this._rank=0;try{this._loader=h.loader()}catch(t){}this._touched=l(m.id),this._pulses={},this._pulse=null,this._heap=new C(function(t,n){return t.qrank-n.qrank}),this._postrun=[]}I.size=function(){return this.nodes.length},I.clear=function(){return this.nodes=[],this},I.peek=function(){return this.nodes[0]},I.push=function(t){var n=this.nodes;return n.push(t),U(n,0,n.length-1,this.cmp)},I.pop=function(){var t,n=this.nodes,e=n.pop();return n.length?(t=n[0],n[0]=e,j(n,0,this.cmp)):t=e,t},I.replace=function(t){var n=this.nodes,e=n[0];return n[0]=t,j(n,0,this.cmp),e},I.pushpop=function(t){var n=this.nodes,e=n[0];return n.length&&this.cmp(e,t)<0&&(n[0]=t,t=e,j(n,0,this.cmp)),t};var G=N.prototype;function W(t){return function(){return this._log[t].apply(this,arguments)}}function B(t,n){p.call(this,t,null,n)}G.stamp=function(){return this._clock},G.loader=function(t){return arguments.length?(this._loader=t,this):this._loader},G.cleanThreshold=1e4,G.add=function(t,n,e,r){var i,s=1;return t instanceof p?i=t:t&&t.prototype instanceof p?i=new t:m.isFunction(t)?i=new p(null,t):(s=0,i=new p(t,n)),this.rank(i),s&&(r=e,e=n),e&&this.connect(i,i.parameters(e,r)),this.touch(i),i},G.connect=function(t,n){var e,r,i=t.rank;for(e=0,r=n.length;e<r;++e)if(i<n[e].rank)return void this.rerank(t)},G.rank=function(t){t.rank=++this._rank},G.rerank=function(t){for(var n,e,r,i=[t];i.length;)if(this.rank(n=i.pop()),e=n._targets)for(r=e.length;0<=--r;)i.push(n=e[r]),n===t&&m.error("Cycle detected in dataflow graph.")},G.pulse=function(t,n,e){this.touch(t,e||z);var r=new q(this,this._clock+(this._pulse?0:1)),i=t.pulse&&t.pulse.source||[];return r.target=t,this._pulses[t.id]=n.pulse(r,i),this},G.touch=function(t,n){var e=n||z;return this._pulse?this._enqueue(t):this._touched.add(t),e.skip&&t.skip(!0),this},G.update=function(t,n,e){var r=e||z;return(t.set(n)||r.force)&&this.touch(t,r),this},G.changeset=s,G.ingest=function(t,n,e){return this.pulse(t,this.changeset().insert(h.read(n,e)))},G.request=function(n,e,r){var i,s,u,t,o=this,a=0,l=o._pending||(i=o,(t=new Promise(function(t,n){s=function(){t(i)},u=n})).requests=0,t.done=function(){0==--t.requests&&i.runAfter(function(){i._pending=null;try{i.run(),i._pending?i._pending.then(s):s()}catch(t){u(t)}})},i._pending=t);return l.requests+=1,o.loader().load(e,{context:"dataflow"}).then(function(t){return h.read(t,r)},function(t){a=-1,o.error("Loading failed",e,t)}).catch(function(t){a=-2,o.error("Data ingestion failed",e,t)}).then(function(t){return o.pulse(n,o.changeset().remove(m.truthy).insert(t||[])),l.done(),a})},G.events=function(t,n,e,r){for(var i,s=this,u=w(e,r),o=function(t){t.dataflow=s;try{u.receive(t)}catch(t){s.error(t)}finally{s.run()}},a=0,l=(i="string"==typeof t&&"undefined"!=typeof document?document.querySelectorAll(t):m.array(t)).length;a<l;++a)i[a].addEventListener(n,o);return u},G.on=function(t,n,e,r,i){return(t instanceof p?P:O)(this,t,n,e,r,i),this},G.run=function(t){var n,e,r,i,s=this,u=0,o=s.logLevel();if(s._pending)return s.info("Awaiting requests, delaying dataflow run."),0;if(s._pulse)return s.error("Dataflow invoked recursively. Use the runAfter method to queue invocation."),0;if(!s._touched.length)return s.info("Dataflow invoked, but nothing to do."),0;s._pulse=new q(s,++s._clock,t),o>=m.Info&&(r=Date.now(),s.debug("-- START PROPAGATION ("+s._clock+") -----")),s._touched.forEach(function(t){s._enqueue(t,!0)}),s._touched=l(m.id);try{for(;0<s._heap.size();)(n=s._heap.pop()).rank===n.qrank?(e=n.run(s._getPulse(n,t)),o>=m.Debug&&s.debug(n.id,e===E?"STOP":e,n),e!==E&&(s._pulse=e,n._targets&&n._targets.forEach(function(t){s._enqueue(t)})),++u):s._enqueue(n,!0)}catch(t){i=t}if(s._pulses={},s._pulse=null,o>=m.Info&&(r=Date.now()-r,s.info("> Pulse "+s._clock+": "+u+" operators; "+r+"ms")),i&&(s._postrun=[],s.error(i)),s._onrun)try{s._onrun(s,u,i)}catch(t){s.error(t)}if(s._postrun.length){var a=s._postrun;s._postrun=[],a.sort(function(t,n){return n.priority-t.priority}).forEach(function(t){T(s,t.callback)})}return this},G.runAsync=function(){return this._pending||this.run()&&this._pending||Promise.resolve(this)},G.runAfter=function(t,n,e){this._pulse||n?this._postrun.push({priority:e||0,callback:t}):T(this,t)},G._enqueue=function(t,n){var e=!this._pulses[t.id];e&&(this._pulses[t.id]=this._pulse),(e||n)&&(t.qrank=t.rank,this._heap.push(t))},G._getPulse=function(t,n){var e,r=t.source,i=this._clock;return r&&m.isArray(r)?new R(this,i,e=r.map(function(t){return t.pulse}),n):(e=this._pulses[t.id],r&&((r=r.pulse)&&r!==E?r.stamp===i&&e.target!==t?e=r:e.source=r.source:e.source=[]),e)},G.error=W("error"),G.warn=W("warn"),G.info=W("info"),G.debug=W("debug"),G.logLevel=W("level");var H=m.inherits(B,p);H.run=function(t){return t.stamp<=this.stamp?t.StopPropagation:(this.skip()?this.skip(!1):n=this.evaluate(t),(n=n||t)!==t.StopPropagation&&(this.pulse=n),this.stamp=t.stamp,n);var n},H.evaluate=function(t){var n=this.marshall(t.stamp),e=this.transform(n,t);return n.clear(),e},H.transform=function(){};var J={};function K(t){return t=t&&t.toLowerCase(),J.hasOwnProperty(t)?J[t]:null}t.UniqueList=l,t.changeset=s,t.isChangeSet=c,t.Dataflow=N,t.EventStream=F,t.Parameters=f,t.Pulse=q,t.MultiPulse=R,t.Operator=p,t.Transform=B,t.derive=function(t){return n(t,y({}))},t.rederive=n,t.ingest=y,t.isTuple=function(t){return!(!t||!_(t))},t.replace=function(t,n){return i(n,_(t))},t.tupleid=_,t.definition=function(t){var n=K(t);return n&&n.Definition||null},t.transform=K,t.transforms=J,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "vega-dataflow", | ||
"version": "4.0.4", | ||
"version": "4.1.0", | ||
"description": "Reactive dataflow processing.", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"dependencies": { | ||
"vega-loader": "^3.0.1", | ||
"vega-loader": "^3.1.0", | ||
"vega-util": "^1.7.0" | ||
@@ -38,3 +38,3 @@ }, | ||
"eslint": "5", | ||
"rollup": "0.62.0", | ||
"rollup": "0.67.4", | ||
"tape": "4", | ||
@@ -41,0 +41,0 @@ "uglify-js": "3" |
@@ -109,5 +109,8 @@ import Parameters from './Parameters'; | ||
* any upstream operators included in the parameters. | ||
* @param {boolean} [initonly=false] - A flag indicating if this operator | ||
* should calculate an update only upon its initiatal evaluation, then | ||
* deregister dependencies and suppress all future update invocations. | ||
* @return {Operator[]} - An array of upstream dependencies. | ||
*/ | ||
prototype.parameters = function(params, react) { | ||
prototype.parameters = function(params, react, initonly) { | ||
react = react !== false; | ||
@@ -154,2 +157,4 @@ var self = this, | ||
this.marshall().clear(); // initialize values | ||
if (initonly) argops.initonly = true; | ||
return deps; | ||
@@ -167,4 +172,4 @@ }; | ||
if (argops && (n = argops.length)) { | ||
for (i=0; i<n; ++i) { | ||
if (argops) { | ||
for (i=0, n=argops.length; i<n; ++i) { | ||
item = argops[i]; | ||
@@ -175,2 +180,11 @@ op = item.op; | ||
} | ||
if (argops.initonly) { | ||
for (i=0; i<n; ++i) { | ||
item = argops[i]; | ||
item.op.targets().remove(this); | ||
} | ||
this._argops = null; | ||
this._update = null; | ||
} | ||
} | ||
@@ -192,5 +206,6 @@ return argval; | ||
prototype.evaluate = function(pulse) { | ||
if (this._update) { | ||
var update = this._update; | ||
if (update) { | ||
var params = this.marshall(pulse.stamp), | ||
v = this._update(params, pulse); | ||
v = update.call(this, params, pulse); | ||
@@ -197,0 +212,0 @@ params.clear(); |
@@ -10,3 +10,3 @@ import {isArray} from 'vega-util'; | ||
export default function Parameters() { | ||
Object.defineProperty(this, CACHE, {writable:true, value: {}}); | ||
Object.defineProperty(this, CACHE, {writable: true, value: {}}); | ||
} | ||
@@ -13,0 +13,0 @@ |
Sorry, the diff of this file is too big to display
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
148928
3714
Updatedvega-loader@^3.1.0