vega-force
Advanced tools
Comparing version 4.0.6 to 4.0.7
@@ -15,11 +15,6 @@ (function (global, factory) { | ||
}; | ||
const Forces = 'forces', | ||
ForceParams = [ | ||
'alpha', 'alphaMin', 'alphaTarget', | ||
'velocityDecay', 'forces' | ||
], | ||
ForceParams = ['alpha', 'alphaMin', 'alphaTarget', 'velocityDecay', 'forces'], | ||
ForceConfig = ['static', 'iterations'], | ||
ForceOutput = ['x', 'y', 'vx', 'vy']; | ||
/** | ||
@@ -31,75 +26,150 @@ * Force simulation layout. | ||
*/ | ||
function Force(params) { | ||
vegaDataflow.Transform.call(this, null, params); | ||
} | ||
Force.Definition = { | ||
'type': 'Force', | ||
'metadata': {'modifies': true}, | ||
'params': [ | ||
{ 'name': 'static', 'type': 'boolean', 'default': false }, | ||
{ 'name': 'restart', 'type': 'boolean', 'default': false }, | ||
{ 'name': 'iterations', 'type': 'number', 'default': 300 }, | ||
{ 'name': 'alpha', 'type': 'number', 'default': 1 }, | ||
{ 'name': 'alphaMin', 'type': 'number', 'default': 0.001 }, | ||
{ 'name': 'alphaTarget', 'type': 'number', 'default': 0 }, | ||
{ 'name': 'velocityDecay', 'type': 'number', 'default': 0.4 }, | ||
{ 'name': 'forces', 'type': 'param', 'array': true, | ||
'params': [ | ||
{ | ||
'key': {'force': 'center'}, | ||
'params': [ | ||
{ 'name': 'x', 'type': 'number', 'default': 0 }, | ||
{ 'name': 'y', 'type': 'number', 'default': 0 } | ||
] | ||
}, | ||
{ | ||
'key': {'force': 'collide'}, | ||
'params': [ | ||
{ 'name': 'radius', 'type': 'number', 'expr': true }, | ||
{ 'name': 'strength', 'type': 'number', 'default': 0.7 }, | ||
{ 'name': 'iterations', 'type': 'number', 'default': 1 } | ||
] | ||
}, | ||
{ | ||
'key': {'force': 'nbody'}, | ||
'params': [ | ||
{ 'name': 'strength', 'type': 'number', 'default': -30 }, | ||
{ 'name': 'theta', 'type': 'number', 'default': 0.9 }, | ||
{ 'name': 'distanceMin', 'type': 'number', 'default': 1 }, | ||
{ 'name': 'distanceMax', 'type': 'number' } | ||
] | ||
}, | ||
{ | ||
'key': {'force': 'link'}, | ||
'params': [ | ||
{ 'name': 'links', 'type': 'data' }, | ||
{ 'name': 'id', 'type': 'field' }, | ||
{ 'name': 'distance', 'type': 'number', 'default': 30, 'expr': true }, | ||
{ 'name': 'strength', 'type': 'number', 'expr': true }, | ||
{ 'name': 'iterations', 'type': 'number', 'default': 1 } | ||
] | ||
}, | ||
{ | ||
'key': {'force': 'x'}, | ||
'params': [ | ||
{ 'name': 'strength', 'type': 'number', 'default': 0.1 }, | ||
{ 'name': 'x', 'type': 'field' } | ||
] | ||
}, | ||
{ | ||
'key': {'force': 'y'}, | ||
'params': [ | ||
{ 'name': 'strength', 'type': 'number', 'default': 0.1 }, | ||
{ 'name': 'y', 'type': 'field' } | ||
] | ||
} | ||
] }, | ||
{ | ||
'name': 'as', 'type': 'string', 'array': true, 'modify': false, | ||
'default': ForceOutput | ||
} | ||
] | ||
'metadata': { | ||
'modifies': true | ||
}, | ||
'params': [{ | ||
'name': 'static', | ||
'type': 'boolean', | ||
'default': false | ||
}, { | ||
'name': 'restart', | ||
'type': 'boolean', | ||
'default': false | ||
}, { | ||
'name': 'iterations', | ||
'type': 'number', | ||
'default': 300 | ||
}, { | ||
'name': 'alpha', | ||
'type': 'number', | ||
'default': 1 | ||
}, { | ||
'name': 'alphaMin', | ||
'type': 'number', | ||
'default': 0.001 | ||
}, { | ||
'name': 'alphaTarget', | ||
'type': 'number', | ||
'default': 0 | ||
}, { | ||
'name': 'velocityDecay', | ||
'type': 'number', | ||
'default': 0.4 | ||
}, { | ||
'name': 'forces', | ||
'type': 'param', | ||
'array': true, | ||
'params': [{ | ||
'key': { | ||
'force': 'center' | ||
}, | ||
'params': [{ | ||
'name': 'x', | ||
'type': 'number', | ||
'default': 0 | ||
}, { | ||
'name': 'y', | ||
'type': 'number', | ||
'default': 0 | ||
}] | ||
}, { | ||
'key': { | ||
'force': 'collide' | ||
}, | ||
'params': [{ | ||
'name': 'radius', | ||
'type': 'number', | ||
'expr': true | ||
}, { | ||
'name': 'strength', | ||
'type': 'number', | ||
'default': 0.7 | ||
}, { | ||
'name': 'iterations', | ||
'type': 'number', | ||
'default': 1 | ||
}] | ||
}, { | ||
'key': { | ||
'force': 'nbody' | ||
}, | ||
'params': [{ | ||
'name': 'strength', | ||
'type': 'number', | ||
'default': -30 | ||
}, { | ||
'name': 'theta', | ||
'type': 'number', | ||
'default': 0.9 | ||
}, { | ||
'name': 'distanceMin', | ||
'type': 'number', | ||
'default': 1 | ||
}, { | ||
'name': 'distanceMax', | ||
'type': 'number' | ||
}] | ||
}, { | ||
'key': { | ||
'force': 'link' | ||
}, | ||
'params': [{ | ||
'name': 'links', | ||
'type': 'data' | ||
}, { | ||
'name': 'id', | ||
'type': 'field' | ||
}, { | ||
'name': 'distance', | ||
'type': 'number', | ||
'default': 30, | ||
'expr': true | ||
}, { | ||
'name': 'strength', | ||
'type': 'number', | ||
'expr': true | ||
}, { | ||
'name': 'iterations', | ||
'type': 'number', | ||
'default': 1 | ||
}] | ||
}, { | ||
'key': { | ||
'force': 'x' | ||
}, | ||
'params': [{ | ||
'name': 'strength', | ||
'type': 'number', | ||
'default': 0.1 | ||
}, { | ||
'name': 'x', | ||
'type': 'field' | ||
}] | ||
}, { | ||
'key': { | ||
'force': 'y' | ||
}, | ||
'params': [{ | ||
'name': 'strength', | ||
'type': 'number', | ||
'default': 0.1 | ||
}, { | ||
'name': 'y', | ||
'type': 'field' | ||
}] | ||
}] | ||
}, { | ||
'name': 'as', | ||
'type': 'string', | ||
'array': true, | ||
'modify': false, | ||
'default': ForceOutput | ||
}] | ||
}; | ||
vegaUtil.inherits(Force, vegaDataflow.Transform, { | ||
@@ -110,8 +180,9 @@ transform(_, pulse) { | ||
params = _.modified(ForceParams), | ||
iters = _.iterations || 300; | ||
iters = _.iterations || 300; // configure simulation | ||
// configure simulation | ||
if (!sim) { | ||
this.value = sim = simulation(pulse.source, _); | ||
sim.on('tick', rerun(pulse.dataflow, this)); | ||
if (!_.static) { | ||
@@ -121,2 +192,3 @@ change = true; | ||
} | ||
pulse.modifies('index'); | ||
@@ -128,14 +200,12 @@ } else { | ||
} | ||
if (params || pulse.changed(pulse.MOD)) { | ||
setup(sim, _, 0, pulse); | ||
} | ||
} | ||
} // run simulation | ||
// run simulation | ||
if (params || change || _.modified(ForceConfig) | ||
|| (pulse.changed() && _.restart)) | ||
{ | ||
sim.alpha(Math.max(sim.alpha(), _.alpha || 1)) | ||
.alphaDecay(1 - Math.pow(sim.alphaMin(), 1 / iters)); | ||
if (params || change || _.modified(ForceConfig) || pulse.changed() && _.restart) { | ||
sim.alpha(Math.max(sim.alpha(), _.alpha || 1)).alphaDecay(1 - Math.pow(sim.alphaMin(), 1 / iters)); | ||
if (_.static) { | ||
@@ -153,11 +223,12 @@ for (sim.stop(); --iters >= 0;) sim.tick(); | ||
finish(_, pulse) { | ||
const dataflow = pulse.dataflow; | ||
const dataflow = pulse.dataflow; // inspect dependencies, touch link source data | ||
// inspect dependencies, touch link source data | ||
for (let args=this._argops, j=0, m=args.length, arg; j<m; ++j) { | ||
for (let args = this._argops, j = 0, m = args.length, arg; j < m; ++j) { | ||
arg = args[j]; | ||
if (arg.name !== Forces || arg.op._argval.force !== 'link') { | ||
continue; | ||
} | ||
for (var ops=arg.op._argops, i=0, n=ops.length, op; i<n; ++i) { | ||
for (var ops = arg.op._argops, i = 0, n = ops.length, op; i < n; ++i) { | ||
if (ops[i].name === 'links' && (op = ops[i].op.source)) { | ||
@@ -168,7 +239,8 @@ dataflow.pulse(op, dataflow.changeset().reflow()); | ||
} | ||
} | ||
} // reflow all nodes | ||
// reflow all nodes | ||
return pulse.reflow(_.modified()).modifies(ForceOutput); | ||
} | ||
}); | ||
@@ -187,3 +259,5 @@ | ||
sim.stopped = () => stopped; | ||
sim.restart = () => (stopped = false, restart()); | ||
sim.stop = () => (stopped = true, stop()); | ||
@@ -195,5 +269,9 @@ | ||
function setup(sim, _, init, pulse) { | ||
var f = vegaUtil.array(_.forces), i, n, p, name; | ||
var f = vegaUtil.array(_.forces), | ||
i, | ||
n, | ||
p, | ||
name; | ||
for (i=0, n=ForceParams.length; i<n; ++i) { | ||
for (i = 0, n = ForceParams.length; i < n; ++i) { | ||
p = ForceParams[i]; | ||
@@ -203,11 +281,9 @@ if (p !== Forces && _.modified(p)) sim[p](_[p]); | ||
for (i=0, n=f.length; i<n; ++i) { | ||
for (i = 0, n = f.length; i < n; ++i) { | ||
name = Forces + i; | ||
p = init || _.modified(Forces, i) ? getForce(f[i]) | ||
: pulse && modified(f[i], pulse) ? sim.force(name) | ||
: null; | ||
p = init || _.modified(Forces, i) ? getForce(f[i]) : pulse && modified(f[i], pulse) ? sim.force(name) : null; | ||
if (p) sim.force(name, p); | ||
} | ||
for (n=(sim.numForces || 0); i<n; ++i) { | ||
for (n = sim.numForces || 0; i < n; ++i) { | ||
sim.force(Forces + i, null); // remove | ||
@@ -222,6 +298,7 @@ } | ||
var k, v; | ||
for (k in f) { | ||
if (vegaUtil.isFunction(v = f[k]) && pulse.modified(vegaUtil.accessorFields(v))) | ||
return 1; | ||
if (vegaUtil.isFunction(v = f[k]) && pulse.modified(vegaUtil.accessorFields(v))) return 1; | ||
} | ||
return 0; | ||
@@ -236,2 +313,3 @@ } | ||
} | ||
f = ForceMap[_.force](); | ||
@@ -238,0 +316,0 @@ |
@@ -1,1 +0,2 @@ | ||
!function(e,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports,require("vega-dataflow"),require("vega-util"),require("d3-force")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-util","d3-force"],a):a(((e="undefined"!=typeof globalThis?globalThis:e||self).vega=e.vega||{},e.vega.transforms={}),e.vega,e.vega,e.d3)}(this,(function(e,a,t,r){"use strict";const n={center:r.forceCenter,collide:r.forceCollide,nbody:r.forceManyBody,link:r.forceLink,x:r.forceX,y:r.forceY},o="forces",i=["alpha","alphaMin","alphaTarget","velocityDecay","forces"],f=["static","iterations"],s=["x","y","vx","vy"];function l(e){a.Transform.call(this,null,e)}function u(e,a,r,n){var f,s,l,u,m=t.array(a.forces);for(f=0,s=i.length;f<s;++f)(l=i[f])!==o&&a.modified(l)&&e[l](a[l]);for(f=0,s=m.length;f<s;++f)u=o+f,(l=r||a.modified(o,f)?c(m[f]):n&&d(m[f],n)?e.force(u):null)&&e.force(u,l);for(s=e.numForces||0;f<s;++f)e.force(o+f,null);return e.numForces=m.length,e}function d(e,a){var r,n;for(r in e)if(t.isFunction(n=e[r])&&a.modified(t.accessorFields(n)))return 1;return 0}function c(e){var a,r;for(r in t.hasOwnProperty(n,e.force)||t.error("Unrecognized force: "+e.force),a=n[e.force](),e)t.isFunction(a[r])&&m(a[r],e[r],e);return a}function m(e,a,r){e(t.isFunction(a)?e=>a(e,r):a)}l.Definition={type:"Force",metadata:{modifies:!0},params:[{name:"static",type:"boolean",default:!1},{name:"restart",type:"boolean",default:!1},{name:"iterations",type:"number",default:300},{name:"alpha",type:"number",default:1},{name:"alphaMin",type:"number",default:.001},{name:"alphaTarget",type:"number",default:0},{name:"velocityDecay",type:"number",default:.4},{name:"forces",type:"param",array:!0,params:[{key:{force:"center"},params:[{name:"x",type:"number",default:0},{name:"y",type:"number",default:0}]},{key:{force:"collide"},params:[{name:"radius",type:"number",expr:!0},{name:"strength",type:"number",default:.7},{name:"iterations",type:"number",default:1}]},{key:{force:"nbody"},params:[{name:"strength",type:"number",default:-30},{name:"theta",type:"number",default:.9},{name:"distanceMin",type:"number",default:1},{name:"distanceMax",type:"number"}]},{key:{force:"link"},params:[{name:"links",type:"data"},{name:"id",type:"field"},{name:"distance",type:"number",default:30,expr:!0},{name:"strength",type:"number",expr:!0},{name:"iterations",type:"number",default:1}]},{key:{force:"x"},params:[{name:"strength",type:"number",default:.1},{name:"x",type:"field"}]},{key:{force:"y"},params:[{name:"strength",type:"number",default:.1},{name:"y",type:"field"}]}]},{name:"as",type:"string",array:!0,modify:!1,default:s}]},t.inherits(l,a.Transform,{transform(e,a){var t,n,o=this.value,s=a.changed(a.ADD_REM),l=e.modified(i),d=e.iterations||300;if(o?(s&&(a.modifies("index"),o.nodes(a.source)),(l||a.changed(a.MOD))&&u(o,e,0,a)):(this.value=o=function(e,a){const t=r.forceSimulation(e),n=t.stop,o=t.restart;let i=!1;return t.stopped=()=>i,t.restart=()=>(i=!1,o()),t.stop=()=>(i=!0,n()),u(t,a,!0).on("end",()=>i=!0)}(a.source,e),o.on("tick",(t=a.dataflow,n=this,()=>t.touch(n).run())),e.static||(s=!0,o.tick()),a.modifies("index")),l||s||e.modified(f)||a.changed()&&e.restart)if(o.alpha(Math.max(o.alpha(),e.alpha||1)).alphaDecay(1-Math.pow(o.alphaMin(),1/d)),e.static)for(o.stop();--d>=0;)o.tick();else if(o.stopped()&&o.restart(),!s)return a.StopPropagation;return this.finish(e,a)},finish(e,a){const t=a.dataflow;for(let e,a=this._argops,s=0,l=a.length;s<l;++s)if(e=a[s],e.name===o&&"link"===e.op._argval.force)for(var r,n=e.op._argops,i=0,f=n.length;i<f;++i)if("links"===n[i].name&&(r=n[i].op.source)){t.pulse(r,t.changeset().reflow());break}return a.reflow(e.modified()).modifies(s)}}),e.force=l,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
this.vega=this.vega||{},this.vega.transforms=function(t,n,e){"use strict";function r(t,n,e,r){if(isNaN(n)||isNaN(e))return t;var i,o,a,u,f,l,s,h,c,y=t._root,p={data:r},v=t._x0,d=t._y0,x=t._x1,g=t._y1;if(!y)return t._root=p,t;for(;y.length;)if((l=n>=(o=(v+x)/2))?v=o:x=o,(s=e>=(a=(d+g)/2))?d=a:g=a,i=y,!(y=y[h=s<<1|l]))return i[h]=p,t;if(u=+t._x.call(null,y.data),f=+t._y.call(null,y.data),n===u&&e===f)return p.next=y,i?i[h]=p:t._root=p,t;do{i=i?i[h]=new Array(4):t._root=new Array(4),(l=n>=(o=(v+x)/2))?v=o:x=o,(s=e>=(a=(d+g)/2))?d=a:g=a}while((h=s<<1|l)==(c=(f>=a)<<1|u>=o));return i[c]=y,i[h]=p,t}function i(t,n,e,r,i){this.node=t,this.x0=n,this.y0=e,this.x1=r,this.y1=i}function o(t){return t[0]}function a(t){return t[1]}function u(t,n,e){var r=new f(null==n?o:n,null==e?a:e,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function f(t,n,e,r,i,o){this._x=t,this._y=n,this._x0=e,this._y0=r,this._x1=i,this._y1=o,this._root=void 0}function l(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}var s=u.prototype=f.prototype;function h(t){return function(){return t}}function c(t){return 1e-6*(t()-.5)}function y(t){return t.x+t.vx}function p(t){return t.y+t.vy}function v(t){return t.index}function d(t,n){var e=t.get(n);if(!e)throw new Error("node not found: "+n);return e}s.copy=function(){var t,n,e=new f(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return e;if(!r.length)return e._root=l(r),e;for(t=[{source:r,target:e._root=new Array(4)}];r=t.pop();)for(var i=0;i<4;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(4)}):r.target[i]=l(n));return e},s.add=function(t){const n=+this._x.call(null,t),e=+this._y.call(null,t);return r(this.cover(n,e),n,e,t)},s.addAll=function(t){var n,e,i,o,a=t.length,u=new Array(a),f=new Array(a),l=1/0,s=1/0,h=-1/0,c=-1/0;for(e=0;e<a;++e)isNaN(i=+this._x.call(null,n=t[e]))||isNaN(o=+this._y.call(null,n))||(u[e]=i,f[e]=o,i<l&&(l=i),i>h&&(h=i),o<s&&(s=o),o>c&&(c=o));if(l>h||s>c)return this;for(this.cover(l,s).cover(h,c),e=0;e<a;++e)r(this,u[e],f[e],t[e]);return this},s.cover=function(t,n){if(isNaN(t=+t)||isNaN(n=+n))return this;var e=this._x0,r=this._y0,i=this._x1,o=this._y1;if(isNaN(e))i=(e=Math.floor(t))+1,o=(r=Math.floor(n))+1;else{for(var a,u,f=i-e||1,l=this._root;e>t||t>=i||r>n||n>=o;)switch(u=(n<r)<<1|t<e,(a=new Array(4))[u]=l,l=a,f*=2,u){case 0:i=e+f,o=r+f;break;case 1:e=i-f,o=r+f;break;case 2:i=e+f,r=o-f;break;case 3:e=i-f,r=o-f}this._root&&this._root.length&&(this._root=l)}return this._x0=e,this._y0=r,this._x1=i,this._y1=o,this},s.data=function(){var t=[];return this.visit((function(n){if(!n.length)do{t.push(n.data)}while(n=n.next)})),t},s.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},s.find=function(t,n,e){var r,o,a,u,f,l,s,h=this._x0,c=this._y0,y=this._x1,p=this._y1,v=[],d=this._root;for(d&&v.push(new i(d,h,c,y,p)),null==e?e=1/0:(h=t-e,c=n-e,y=t+e,p=n+e,e*=e);l=v.pop();)if(!(!(d=l.node)||(o=l.x0)>y||(a=l.y0)>p||(u=l.x1)<h||(f=l.y1)<c))if(d.length){var x=(o+u)/2,g=(a+f)/2;v.push(new i(d[3],x,g,u,f),new i(d[2],o,g,x,f),new i(d[1],x,a,u,g),new i(d[0],o,a,x,g)),(s=(n>=g)<<1|t>=x)&&(l=v[v.length-1],v[v.length-1]=v[v.length-1-s],v[v.length-1-s]=l)}else{var _=t-+this._x.call(null,d.data),m=n-+this._y.call(null,d.data),w=_*_+m*m;if(w<e){var N=Math.sqrt(e=w);h=t-N,c=n-N,y=t+N,p=n+N,r=d.data}}return r},s.remove=function(t){if(isNaN(o=+this._x.call(null,t))||isNaN(a=+this._y.call(null,t)))return this;var n,e,r,i,o,a,u,f,l,s,h,c,y=this._root,p=this._x0,v=this._y0,d=this._x1,x=this._y1;if(!y)return this;if(y.length)for(;;){if((l=o>=(u=(p+d)/2))?p=u:d=u,(s=a>=(f=(v+x)/2))?v=f:x=f,n=y,!(y=y[h=s<<1|l]))return this;if(!y.length)break;(n[h+1&3]||n[h+2&3]||n[h+3&3])&&(e=n,c=h)}for(;y.data!==t;)if(r=y,!(y=y.next))return this;return(i=y.next)&&delete y.next,r?(i?r.next=i:delete r.next,this):n?(i?n[h]=i:delete n[h],(y=n[0]||n[1]||n[2]||n[3])&&y===(n[3]||n[2]||n[1]||n[0])&&!y.length&&(e?e[c]=y:this._root=y),this):(this._root=i,this)},s.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},s.root=function(){return this._root},s.size=function(){var t=0;return this.visit((function(n){if(!n.length)do{++t}while(n=n.next)})),t},s.visit=function(t){var n,e,r,o,a,u,f=[],l=this._root;for(l&&f.push(new i(l,this._x0,this._y0,this._x1,this._y1));n=f.pop();)if(!t(l=n.node,r=n.x0,o=n.y0,a=n.x1,u=n.y1)&&l.length){var s=(r+a)/2,h=(o+u)/2;(e=l[3])&&f.push(new i(e,s,h,a,u)),(e=l[2])&&f.push(new i(e,r,h,s,u)),(e=l[1])&&f.push(new i(e,s,o,a,h)),(e=l[0])&&f.push(new i(e,r,o,s,h))}return this},s.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new i(this._root,this._x0,this._y0,this._x1,this._y1));n=e.pop();){var o=n.node;if(o.length){var a,u=n.x0,f=n.y0,l=n.x1,s=n.y1,h=(u+l)/2,c=(f+s)/2;(a=o[0])&&e.push(new i(a,u,f,h,c)),(a=o[1])&&e.push(new i(a,h,f,l,c)),(a=o[2])&&e.push(new i(a,u,c,h,s)),(a=o[3])&&e.push(new i(a,h,c,l,s))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.x1,n.y1);return this},s.x=function(t){return arguments.length?(this._x=t,this):this._x},s.y=function(t){return arguments.length?(this._y=t,this):this._y};var x={value:()=>{}};function g(){for(var t,n=0,e=arguments.length,r={};n<e;++n){if(!(t=arguments[n]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new _(r)}function _(t){this._=t}function m(t,n){return t.trim().split(/^|\s+/).map((function(t){var e="",r=t.indexOf(".");if(r>=0&&(e=t.slice(r+1),t=t.slice(0,r)),t&&!n.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}}))}function w(t,n){for(var e,r=0,i=t.length;r<i;++r)if((e=t[r]).name===n)return e.value}function N(t,n,e){for(var r=0,i=t.length;r<i;++r)if(t[r].name===n){t[r]=x,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=e&&t.push({name:n,value:e}),t}_.prototype=g.prototype={constructor:_,on:function(t,n){var e,r=this._,i=m(t+"",r),o=-1,a=i.length;if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++o<a;)if(e=(t=i[o]).type)r[e]=N(r[e],t.name,n);else if(null==n)for(e in r)r[e]=N(r[e],t.name,null);return this}for(;++o<a;)if((e=(t=i[o]).type)&&(e=w(r[e],t.name)))return e},copy:function(){var t={},n=this._;for(var e in n)t[e]=n[e].slice();return new _(t)},call:function(t,n){if((e=arguments.length-2)>0)for(var e,r,i=new Array(e),o=0;o<e;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=0,e=(r=this._[t]).length;o<e;++o)r[o].value.apply(n,i)},apply:function(t,n,e){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],i=0,o=r.length;i<o;++i)r[i].value.apply(n,e)}};var b,M,k=0,A=0,q=0,E=0,z=0,D=0,F="object"==typeof performance&&performance.now?performance:Date,T="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function O(){return z||(T(P),z=F.now()+D)}function P(){z=0}function j(){this._call=this._time=this._next=null}function I(t,n,e){var r=new j;return r.restart(t,n,e),r}function S(){z=(E=F.now())+D,k=A=0;try{!function(){O(),++k;for(var t,n=b;n;)(t=z-n._time)>=0&&n._call.call(null,t),n=n._next;--k}()}finally{k=0,function(){var t,n,e=b,r=1/0;for(;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:b=n);M=t,U(r)}(),z=0}}function R(){var t=F.now(),n=t-E;n>1e3&&(D-=n,E=t)}function U(t){k||(A&&(A=clearTimeout(A)),t-z>24?(t<1/0&&(A=setTimeout(S,t-F.now()-D)),q&&(q=clearInterval(q))):(q||(E=F.now(),q=setInterval(R,1e3)),k=1,T(S)))}j.prototype=I.prototype={constructor:j,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?O():+e)+(null==n?0:+n),this._next||M===this||(M?M._next=this:b=this,M=this),this._call=t,this._time=e,U()},stop:function(){this._call&&(this._call=null,this._time=1/0,U())}};const B=4294967296;function C(t){return t.x}function G(t){return t.y}var H=Math.PI*(3-Math.sqrt(5));function J(t){var n,e=1,r=.001,i=1-Math.pow(r,1/300),o=0,a=.6,u=new Map,f=I(h),l=g("tick","end"),s=function(){let t=1;return()=>(t=(1664525*t+1013904223)%B)/B}();function h(){c(),l.call("tick",n),e<r&&(f.stop(),l.call("end",n))}function c(r){var f,l,s=t.length;void 0===r&&(r=1);for(var h=0;h<r;++h)for(e+=(o-e)*i,u.forEach((function(t){t(e)})),f=0;f<s;++f)null==(l=t[f]).fx?l.x+=l.vx*=a:(l.x=l.fx,l.vx=0),null==l.fy?l.y+=l.vy*=a:(l.y=l.fy,l.vy=0);return n}function y(){for(var n,e=0,r=t.length;e<r;++e){if((n=t[e]).index=e,null!=n.fx&&(n.x=n.fx),null!=n.fy&&(n.y=n.fy),isNaN(n.x)||isNaN(n.y)){var i=10*Math.sqrt(.5+e),o=e*H;n.x=i*Math.cos(o),n.y=i*Math.sin(o)}(isNaN(n.vx)||isNaN(n.vy))&&(n.vx=n.vy=0)}}function p(n){return n.initialize&&n.initialize(t,s),n}return null==t&&(t=[]),y(),n={tick:c,restart:function(){return f.restart(h),n},stop:function(){return f.stop(),n},nodes:function(e){return arguments.length?(t=e,y(),u.forEach(p),n):t},alpha:function(t){return arguments.length?(e=+t,n):e},alphaMin:function(t){return arguments.length?(r=+t,n):r},alphaDecay:function(t){return arguments.length?(i=+t,n):+i},alphaTarget:function(t){return arguments.length?(o=+t,n):o},velocityDecay:function(t){return arguments.length?(a=1-t,n):1-a},randomSource:function(t){return arguments.length?(s=t,u.forEach(p),n):s},force:function(t,e){return arguments.length>1?(null==e?u.delete(t):u.set(t,p(e)),n):u.get(t)},find:function(n,e,r){var i,o,a,u,f,l=0,s=t.length;for(null==r?r=1/0:r*=r,l=0;l<s;++l)(a=(i=n-(u=t[l]).x)*i+(o=e-u.y)*o)<r&&(f=u,r=a);return f},on:function(t,e){return arguments.length>1?(l.on(t,e),n):l.on(t)}}}const K={center:function(t,n){var e,r=1;function i(){var i,o,a=e.length,u=0,f=0;for(i=0;i<a;++i)u+=(o=e[i]).x,f+=o.y;for(u=(u/a-t)*r,f=(f/a-n)*r,i=0;i<a;++i)(o=e[i]).x-=u,o.y-=f}return null==t&&(t=0),null==n&&(n=0),i.initialize=function(t){e=t},i.x=function(n){return arguments.length?(t=+n,i):t},i.y=function(t){return arguments.length?(n=+t,i):n},i.strength=function(t){return arguments.length?(r=+t,i):r},i},collide:function(t){var n,e,r,i=1,o=1;function a(){for(var t,a,l,s,h,v,d,x=n.length,g=0;g<o;++g)for(a=u(n,y,p).visitAfter(f),t=0;t<x;++t)l=n[t],v=e[l.index],d=v*v,s=l.x+l.vx,h=l.y+l.vy,a.visit(_);function _(t,n,e,o,a){var u=t.data,f=t.r,y=v+f;if(!u)return n>s+y||o<s-y||e>h+y||a<h-y;if(u.index>l.index){var p=s-u.x-u.vx,x=h-u.y-u.vy,g=p*p+x*x;g<y*y&&(0===p&&(g+=(p=c(r))*p),0===x&&(g+=(x=c(r))*x),g=(y-(g=Math.sqrt(g)))/g*i,l.vx+=(p*=g)*(y=(f*=f)/(d+f)),l.vy+=(x*=g)*y,u.vx-=p*(y=1-y),u.vy-=x*y)}}}function f(t){if(t.data)return t.r=e[t.data.index];for(var n=t.r=0;n<4;++n)t[n]&&t[n].r>t.r&&(t.r=t[n].r)}function l(){if(n){var r,i,o=n.length;for(e=new Array(o),r=0;r<o;++r)i=n[r],e[i.index]=+t(i,r,n)}}return"function"!=typeof t&&(t=h(null==t?1:+t)),a.initialize=function(t,e){n=t,r=e,l()},a.iterations=function(t){return arguments.length?(o=+t,a):o},a.strength=function(t){return arguments.length?(i=+t,a):i},a.radius=function(n){return arguments.length?(t="function"==typeof n?n:h(+n),l(),a):t},a},nbody:function(){var t,n,e,r,i,o=h(-30),a=1,f=1/0,l=.81;function s(e){var i,o=t.length,a=u(t,C,G).visitAfter(p);for(r=e,i=0;i<o;++i)n=t[i],a.visit(v)}function y(){if(t){var n,e,r=t.length;for(i=new Array(r),n=0;n<r;++n)e=t[n],i[e.index]=+o(e,n,t)}}function p(t){var n,e,r,o,a,u=0,f=0;if(t.length){for(r=o=a=0;a<4;++a)(n=t[a])&&(e=Math.abs(n.value))&&(u+=n.value,f+=e,r+=e*n.x,o+=e*n.y);t.x=r/f,t.y=o/f}else{(n=t).x=n.data.x,n.y=n.data.y;do{u+=i[n.data.index]}while(n=n.next)}t.value=u}function v(t,o,u,s){if(!t.value)return!0;var h=t.x-n.x,y=t.y-n.y,p=s-o,v=h*h+y*y;if(p*p/l<v)return v<f&&(0===h&&(v+=(h=c(e))*h),0===y&&(v+=(y=c(e))*y),v<a&&(v=Math.sqrt(a*v)),n.vx+=h*t.value*r/v,n.vy+=y*t.value*r/v),!0;if(!(t.length||v>=f)){(t.data!==n||t.next)&&(0===h&&(v+=(h=c(e))*h),0===y&&(v+=(y=c(e))*y),v<a&&(v=Math.sqrt(a*v)));do{t.data!==n&&(p=i[t.data.index]*r/v,n.vx+=h*p,n.vy+=y*p)}while(t=t.next)}}return s.initialize=function(n,r){t=n,e=r,y()},s.strength=function(t){return arguments.length?(o="function"==typeof t?t:h(+t),y(),s):o},s.distanceMin=function(t){return arguments.length?(a=t*t,s):Math.sqrt(a)},s.distanceMax=function(t){return arguments.length?(f=t*t,s):Math.sqrt(f)},s.theta=function(t){return arguments.length?(l=t*t,s):Math.sqrt(l)},s},link:function(t){var n,e,r,i,o,a,u=v,f=function(t){return 1/Math.min(i[t.source.index],i[t.target.index])},l=h(30),s=1;function y(r){for(var i=0,u=t.length;i<s;++i)for(var f,l,h,y,p,v,d,x=0;x<u;++x)l=(f=t[x]).source,y=(h=f.target).x+h.vx-l.x-l.vx||c(a),p=h.y+h.vy-l.y-l.vy||c(a),y*=v=((v=Math.sqrt(y*y+p*p))-e[x])/v*r*n[x],p*=v,h.vx-=y*(d=o[x]),h.vy-=p*d,l.vx+=y*(d=1-d),l.vy+=p*d}function p(){if(r){var a,f,l=r.length,s=t.length,h=new Map(r.map((t,n)=>[u(t,n,r),t]));for(a=0,i=new Array(l);a<s;++a)(f=t[a]).index=a,"object"!=typeof f.source&&(f.source=d(h,f.source)),"object"!=typeof f.target&&(f.target=d(h,f.target)),i[f.source.index]=(i[f.source.index]||0)+1,i[f.target.index]=(i[f.target.index]||0)+1;for(a=0,o=new Array(s);a<s;++a)f=t[a],o[a]=i[f.source.index]/(i[f.source.index]+i[f.target.index]);n=new Array(s),x(),e=new Array(s),g()}}function x(){if(r)for(var e=0,i=t.length;e<i;++e)n[e]=+f(t[e],e,t)}function g(){if(r)for(var n=0,i=t.length;n<i;++n)e[n]=+l(t[n],n,t)}return null==t&&(t=[]),y.initialize=function(t,n){r=t,a=n,p()},y.links=function(n){return arguments.length?(t=n,p(),y):t},y.id=function(t){return arguments.length?(u=t,y):u},y.iterations=function(t){return arguments.length?(s=+t,y):s},y.strength=function(t){return arguments.length?(f="function"==typeof t?t:h(+t),x(),y):f},y.distance=function(t){return arguments.length?(l="function"==typeof t?t:h(+t),g(),y):l},y},x:function(t){var n,e,r,i=h(.1);function o(t){for(var i,o=0,a=n.length;o<a;++o)(i=n[o]).vx+=(r[o]-i.x)*e[o]*t}function a(){if(n){var o,a=n.length;for(e=new Array(a),r=new Array(a),o=0;o<a;++o)e[o]=isNaN(r[o]=+t(n[o],o,n))?0:+i(n[o],o,n)}}return"function"!=typeof t&&(t=h(null==t?0:+t)),o.initialize=function(t){n=t,a()},o.strength=function(t){return arguments.length?(i="function"==typeof t?t:h(+t),a(),o):i},o.x=function(n){return arguments.length?(t="function"==typeof n?n:h(+n),a(),o):t},o},y:function(t){var n,e,r,i=h(.1);function o(t){for(var i,o=0,a=n.length;o<a;++o)(i=n[o]).vy+=(r[o]-i.y)*e[o]*t}function a(){if(n){var o,a=n.length;for(e=new Array(a),r=new Array(a),o=0;o<a;++o)e[o]=isNaN(r[o]=+t(n[o],o,n))?0:+i(n[o],o,n)}}return"function"!=typeof t&&(t=h(null==t?0:+t)),o.initialize=function(t){n=t,a()},o.strength=function(t){return arguments.length?(i="function"==typeof t?t:h(+t),a(),o):i},o.y=function(n){return arguments.length?(t="function"==typeof n?n:h(+n),a(),o):t},o}},L="forces",Q=["alpha","alphaMin","alphaTarget","velocityDecay","forces"],V=["static","iterations"],W=["x","y","vx","vy"];function X(t){n.Transform.call(this,null,t)}function Y(t,n,r,i){var o,a,u,f,l=e.array(n.forces);for(o=0,a=Q.length;o<a;++o)(u=Q[o])!==L&&n.modified(u)&&t[u](n[u]);for(o=0,a=l.length;o<a;++o)f=L+o,(u=r||n.modified(L,o)?$(l[o]):i&&Z(l[o],i)?t.force(f):null)&&t.force(f,u);for(a=t.numForces||0;o<a;++o)t.force(L+o,null);return t.numForces=l.length,t}function Z(t,n){var r,i;for(r in t)if(e.isFunction(i=t[r])&&n.modified(e.accessorFields(i)))return 1;return 0}function $(t){var n,r;for(r in e.hasOwnProperty(K,t.force)||e.error("Unrecognized force: "+t.force),n=K[t.force](),t)e.isFunction(n[r])&&tt(n[r],t[r],t);return n}function tt(t,n,r){t(e.isFunction(n)?t=>n(t,r):n)}return X.Definition={type:"Force",metadata:{modifies:!0},params:[{name:"static",type:"boolean",default:!1},{name:"restart",type:"boolean",default:!1},{name:"iterations",type:"number",default:300},{name:"alpha",type:"number",default:1},{name:"alphaMin",type:"number",default:.001},{name:"alphaTarget",type:"number",default:0},{name:"velocityDecay",type:"number",default:.4},{name:"forces",type:"param",array:!0,params:[{key:{force:"center"},params:[{name:"x",type:"number",default:0},{name:"y",type:"number",default:0}]},{key:{force:"collide"},params:[{name:"radius",type:"number",expr:!0},{name:"strength",type:"number",default:.7},{name:"iterations",type:"number",default:1}]},{key:{force:"nbody"},params:[{name:"strength",type:"number",default:-30},{name:"theta",type:"number",default:.9},{name:"distanceMin",type:"number",default:1},{name:"distanceMax",type:"number"}]},{key:{force:"link"},params:[{name:"links",type:"data"},{name:"id",type:"field"},{name:"distance",type:"number",default:30,expr:!0},{name:"strength",type:"number",expr:!0},{name:"iterations",type:"number",default:1}]},{key:{force:"x"},params:[{name:"strength",type:"number",default:.1},{name:"x",type:"field"}]},{key:{force:"y"},params:[{name:"strength",type:"number",default:.1},{name:"y",type:"field"}]}]},{name:"as",type:"string",array:!0,modify:!1,default:W}]},e.inherits(X,n.Transform,{transform(t,n){var e,r,i=this.value,o=n.changed(n.ADD_REM),a=t.modified(Q),u=t.iterations||300;if(i?(o&&(n.modifies("index"),i.nodes(n.source)),(a||n.changed(n.MOD))&&Y(i,t,0,n)):(this.value=i=function(t,n){const e=J(t),r=e.stop,i=e.restart;let o=!1;return e.stopped=()=>o,e.restart=()=>(o=!1,i()),e.stop=()=>(o=!0,r()),Y(e,n,!0).on("end",()=>o=!0)}(n.source,t),i.on("tick",(e=n.dataflow,r=this,()=>e.touch(r).run())),t.static||(o=!0,i.tick()),n.modifies("index")),a||o||t.modified(V)||n.changed()&&t.restart)if(i.alpha(Math.max(i.alpha(),t.alpha||1)).alphaDecay(1-Math.pow(i.alphaMin(),1/u)),t.static)for(i.stop();--u>=0;)i.tick();else if(i.stopped()&&i.restart(),!o)return n.StopPropagation;return this.finish(t,n)},finish(t,n){const e=n.dataflow;for(let t,n=this._argops,u=0,f=n.length;u<f;++u)if(t=n[u],t.name===L&&"link"===t.op._argval.force)for(var r,i=t.op._argops,o=0,a=i.length;o<a;++o)if("links"===i[o].name&&(r=i[o].op.source)){e.pulse(r,e.changeset().reflow());break}return n.reflow(t.modified()).modifies(W)}}),t.force=X,t}({},vega,vega); | ||
//# sourceMappingURL=vega-force.min.js.map |
{ | ||
"name": "vega-force", | ||
"version": "4.0.6", | ||
"version": "4.0.7", | ||
"description": "Force simulation transform for Vega dataflows.", | ||
@@ -12,18 +12,16 @@ "keywords": [ | ||
"main": "build/vega-force.js", | ||
"module": "index", | ||
"module": "build/vega-force.module.js", | ||
"unpkg": "build/vega-force.min.js", | ||
"repository": "vega/vega", | ||
"scripts": { | ||
"rollup": "rollup -g d3-force:d3,vega-dataflow:vega,vega-util:vega -f umd -n vega.transforms -o build/vega-force.js -- index.js", | ||
"prebuild": "rimraf build && mkdir build", | ||
"build": "yarn rollup", | ||
"postbuild": "terser build/vega-force.js -c -m -o build/vega-force.min.js", | ||
"pretest": "yarn prebuild && yarn rollup", | ||
"prebuild": "rimraf build", | ||
"build": "rollup -c --config-transform", | ||
"pretest": "yarn build --config-test", | ||
"test": "tape 'test/**/*-test.js'", | ||
"prepublishOnly": "yarn test && yarn build", | ||
"postpublish": "git push && git push --tags" | ||
"prepublishOnly": "yarn test && yarn build" | ||
}, | ||
"dependencies": { | ||
"d3-force": "^2.1.1", | ||
"vega-dataflow": "^5.7.2", | ||
"vega-util": "^1.15.1" | ||
"vega-dataflow": "^5.7.3", | ||
"vega-util": "^1.15.2" | ||
}, | ||
@@ -33,3 +31,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "8d6793f4ca7eaaf2d22186764e9ce2dae687cf52" | ||
"gitHead": "4affcbedb9d14815dbb6d3b250ed231b54fc95c0" | ||
} |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
114539
10
838
1
Updatedvega-dataflow@^5.7.3
Updatedvega-util@^1.15.2