Socket
Socket
Sign inDemoInstall

vega-force

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vega-force - npm Package Compare versions

Comparing version 4.0.7 to 4.1.0

1287

build/vega-force.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-dataflow'), require('vega-util'), require('d3-force')) :
typeof define === 'function' && define.amd ? define(['exports', 'vega-dataflow', 'vega-util', 'd3-force'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.vega = global.vega || {}, global.vega.transforms = {}), global.vega, global.vega, global.d3));
}(this, (function (exports, vegaDataflow, vegaUtil, d3Force) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-dataflow'), require('vega-util')) :
typeof define === 'function' && define.amd ? define(['exports', 'vega-dataflow', 'vega-util'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.vega = global.vega || {}, global.vega.transforms = {}), global.vega, global.vega));
})(this, (function (exports, vegaDataflow, vegaUtil) { 'use strict';
function forceCenter (x, y) {
var nodes,
strength = 1;
if (x == null) x = 0;
if (y == null) y = 0;
function force() {
var i,
n = nodes.length,
node,
sx = 0,
sy = 0;
for (i = 0; i < n; ++i) {
node = nodes[i], sx += node.x, sy += node.y;
}
for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
node = nodes[i], node.x -= sx, node.y -= sy;
}
}
force.initialize = function (_) {
nodes = _;
};
force.x = function (_) {
return arguments.length ? (x = +_, force) : x;
};
force.y = function (_) {
return arguments.length ? (y = +_, force) : y;
};
force.strength = function (_) {
return arguments.length ? (strength = +_, force) : strength;
};
return force;
}
function tree_add (d) {
const x = +this._x.call(null, d),
y = +this._y.call(null, d);
return add(this.cover(x, y), x, y, d);
}
function add(tree, x, y, d) {
if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
var parent,
node = tree._root,
leaf = {
data: d
},
x0 = tree._x0,
y0 = tree._y0,
x1 = tree._x1,
y1 = tree._y1,
xm,
ym,
xp,
yp,
right,
bottom,
i,
j; // If the tree is empty, initialize the root as a leaf.
if (!node) return tree._root = leaf, tree; // Find the existing leaf for the new point, or add it.
while (node.length) {
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm;else x1 = xm;
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym;else y1 = ym;
if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
} // Is the new point is exactly coincident with the existing point?
xp = +tree._x.call(null, node.data);
yp = +tree._y.call(null, node.data);
if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree; // Otherwise, split the leaf node until the old and new point are separated.
do {
parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm;else x1 = xm;
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym;else y1 = ym;
} while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | xp >= xm));
return parent[j] = node, parent[i] = leaf, tree;
}
function addAll(data) {
var d,
i,
n = data.length,
x,
y,
xz = new Array(n),
yz = new Array(n),
x0 = Infinity,
y0 = Infinity,
x1 = -Infinity,
y1 = -Infinity; // Compute the points and their extent.
for (i = 0; i < n; ++i) {
if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
xz[i] = x;
yz[i] = y;
if (x < x0) x0 = x;
if (x > x1) x1 = x;
if (y < y0) y0 = y;
if (y > y1) y1 = y;
} // If there were no (valid) points, abort.
if (x0 > x1 || y0 > y1) return this; // Expand the tree to cover the new points.
this.cover(x0, y0).cover(x1, y1); // Add the new points.
for (i = 0; i < n; ++i) {
add(this, xz[i], yz[i], data[i]);
}
return this;
}
function tree_cover (x, y) {
if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
var x0 = this._x0,
y0 = this._y0,
x1 = this._x1,
y1 = this._y1; // If the quadtree has no extent, initialize them.
// Integer extent are necessary so that if we later double the extent,
// the existing quadrant boundaries don’t change due to floating point error!
if (isNaN(x0)) {
x1 = (x0 = Math.floor(x)) + 1;
y1 = (y0 = Math.floor(y)) + 1;
} // Otherwise, double repeatedly to cover.
else {
var z = x1 - x0 || 1,
node = this._root,
parent,
i;
while (x0 > x || x >= x1 || y0 > y || y >= y1) {
i = (y < y0) << 1 | x < x0;
parent = new Array(4), parent[i] = node, node = parent, z *= 2;
switch (i) {
case 0:
x1 = x0 + z, y1 = y0 + z;
break;
case 1:
x0 = x1 - z, y1 = y0 + z;
break;
case 2:
x1 = x0 + z, y0 = y1 - z;
break;
case 3:
x0 = x1 - z, y0 = y1 - z;
break;
}
}
if (this._root && this._root.length) this._root = node;
}
this._x0 = x0;
this._y0 = y0;
this._x1 = x1;
this._y1 = y1;
return this;
}
function tree_data () {
var data = [];
this.visit(function (node) {
if (!node.length) do data.push(node.data); while (node = node.next);
});
return data;
}
function tree_extent (_) {
return arguments.length ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1]) : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
}
function Quad (node, x0, y0, x1, y1) {
this.node = node;
this.x0 = x0;
this.y0 = y0;
this.x1 = x1;
this.y1 = y1;
}
function tree_find (x, y, radius) {
var data,
x0 = this._x0,
y0 = this._y0,
x1,
y1,
x2,
y2,
x3 = this._x1,
y3 = this._y1,
quads = [],
node = this._root,
q,
i;
if (node) quads.push(new Quad(node, x0, y0, x3, y3));
if (radius == null) radius = Infinity;else {
x0 = x - radius, y0 = y - radius;
x3 = x + radius, y3 = y + radius;
radius *= radius;
}
while (q = quads.pop()) {
// Stop searching if this quadrant can’t contain a closer node.
if (!(node = q.node) || (x1 = q.x0) > x3 || (y1 = q.y0) > y3 || (x2 = q.x1) < x0 || (y2 = q.y1) < y0) continue; // Bisect the current quadrant.
if (node.length) {
var xm = (x1 + x2) / 2,
ym = (y1 + y2) / 2;
quads.push(new Quad(node[3], xm, ym, x2, y2), new Quad(node[2], x1, ym, xm, y2), new Quad(node[1], xm, y1, x2, ym), new Quad(node[0], x1, y1, xm, ym)); // Visit the closest quadrant first.
if (i = (y >= ym) << 1 | x >= xm) {
q = quads[quads.length - 1];
quads[quads.length - 1] = quads[quads.length - 1 - i];
quads[quads.length - 1 - i] = q;
}
} // Visit this point. (Visiting coincident points isn’t necessary!)
else {
var dx = x - +this._x.call(null, node.data),
dy = y - +this._y.call(null, node.data),
d2 = dx * dx + dy * dy;
if (d2 < radius) {
var d = Math.sqrt(radius = d2);
x0 = x - d, y0 = y - d;
x3 = x + d, y3 = y + d;
data = node.data;
}
}
}
return data;
}
function tree_remove (d) {
if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
var parent,
node = this._root,
retainer,
previous,
next,
x0 = this._x0,
y0 = this._y0,
x1 = this._x1,
y1 = this._y1,
x,
y,
xm,
ym,
right,
bottom,
i,
j; // If the tree is empty, initialize the root as a leaf.
if (!node) return this; // Find the leaf node for the point.
// While descending, also retain the deepest parent with a non-removed sibling.
if (node.length) while (true) {
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm;else x1 = xm;
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym;else y1 = ym;
if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
if (!node.length) break;
if (parent[i + 1 & 3] || parent[i + 2 & 3] || parent[i + 3 & 3]) retainer = parent, j = i;
} // Find the point to remove.
while (node.data !== d) if (!(previous = node, node = node.next)) return this;
if (next = node.next) delete node.next; // If there are multiple coincident points, remove just the point.
if (previous) return next ? previous.next = next : delete previous.next, this; // If this is the root point, remove it.
if (!parent) return this._root = next, this; // Remove this leaf.
next ? parent[i] = next : delete parent[i]; // If the parent now contains exactly one leaf, collapse superfluous parents.
if ((node = parent[0] || parent[1] || parent[2] || parent[3]) && node === (parent[3] || parent[2] || parent[1] || parent[0]) && !node.length) {
if (retainer) retainer[j] = node;else this._root = node;
}
return this;
}
function removeAll(data) {
for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
return this;
}
function tree_root () {
return this._root;
}
function tree_size () {
var size = 0;
this.visit(function (node) {
if (!node.length) do ++size; while (node = node.next);
});
return size;
}
function tree_visit (callback) {
var quads = [],
q,
node = this._root,
child,
x0,
y0,
x1,
y1;
if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
while (q = quads.pop()) {
if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
var xm = (x0 + x1) / 2,
ym = (y0 + y1) / 2;
if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
}
}
return this;
}
function tree_visitAfter (callback) {
var quads = [],
next = [],
q;
if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
while (q = quads.pop()) {
var node = q.node;
if (node.length) {
var child,
x0 = q.x0,
y0 = q.y0,
x1 = q.x1,
y1 = q.y1,
xm = (x0 + x1) / 2,
ym = (y0 + y1) / 2;
if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
}
next.push(q);
}
while (q = next.pop()) {
callback(q.node, q.x0, q.y0, q.x1, q.y1);
}
return this;
}
function defaultX(d) {
return d[0];
}
function tree_x (_) {
return arguments.length ? (this._x = _, this) : this._x;
}
function defaultY(d) {
return d[1];
}
function tree_y (_) {
return arguments.length ? (this._y = _, this) : this._y;
}
function quadtree(nodes, x, y) {
var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
return nodes == null ? tree : tree.addAll(nodes);
}
function Quadtree(x, y, x0, y0, x1, y1) {
this._x = x;
this._y = y;
this._x0 = x0;
this._y0 = y0;
this._x1 = x1;
this._y1 = y1;
this._root = undefined;
}
function leaf_copy(leaf) {
var copy = {
data: leaf.data
},
next = copy;
while (leaf = leaf.next) next = next.next = {
data: leaf.data
};
return copy;
}
var treeProto = quadtree.prototype = Quadtree.prototype;
treeProto.copy = function () {
var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
node = this._root,
nodes,
child;
if (!node) return copy;
if (!node.length) return copy._root = leaf_copy(node), copy;
nodes = [{
source: node,
target: copy._root = new Array(4)
}];
while (node = nodes.pop()) {
for (var i = 0; i < 4; ++i) {
if (child = node.source[i]) {
if (child.length) nodes.push({
source: child,
target: node.target[i] = new Array(4)
});else node.target[i] = leaf_copy(child);
}
}
}
return copy;
};
treeProto.add = tree_add;
treeProto.addAll = addAll;
treeProto.cover = tree_cover;
treeProto.data = tree_data;
treeProto.extent = tree_extent;
treeProto.find = tree_find;
treeProto.remove = tree_remove;
treeProto.removeAll = removeAll;
treeProto.root = tree_root;
treeProto.size = tree_size;
treeProto.visit = tree_visit;
treeProto.visitAfter = tree_visitAfter;
treeProto.x = tree_x;
treeProto.y = tree_y;
function constant (x) {
return function () {
return x;
};
}
function jiggle (random) {
return (random() - 0.5) * 1e-6;
}
function x$1(d) {
return d.x + d.vx;
}
function y$1(d) {
return d.y + d.vy;
}
function forceCollide (radius) {
var nodes,
radii,
random,
strength = 1,
iterations = 1;
if (typeof radius !== "function") radius = constant(radius == null ? 1 : +radius);
function force() {
var i,
n = nodes.length,
tree,
node,
xi,
yi,
ri,
ri2;
for (var k = 0; k < iterations; ++k) {
tree = quadtree(nodes, x$1, y$1).visitAfter(prepare);
for (i = 0; i < n; ++i) {
node = nodes[i];
ri = radii[node.index], ri2 = ri * ri;
xi = node.x + node.vx;
yi = node.y + node.vy;
tree.visit(apply);
}
}
function apply(quad, x0, y0, x1, y1) {
var data = quad.data,
rj = quad.r,
r = ri + rj;
if (data) {
if (data.index > node.index) {
var x = xi - data.x - data.vx,
y = yi - data.y - data.vy,
l = x * x + y * y;
if (l < r * r) {
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
l = (r - (l = Math.sqrt(l))) / l * strength;
node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
node.vy += (y *= l) * r;
data.vx -= x * (r = 1 - r);
data.vy -= y * r;
}
}
return;
}
return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
}
}
function prepare(quad) {
if (quad.data) return quad.r = radii[quad.data.index];
for (var i = quad.r = 0; i < 4; ++i) {
if (quad[i] && quad[i].r > quad.r) {
quad.r = quad[i].r;
}
}
}
function initialize() {
if (!nodes) return;
var i,
n = nodes.length,
node;
radii = new Array(n);
for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
}
force.initialize = function (_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();
};
force.iterations = function (_) {
return arguments.length ? (iterations = +_, force) : iterations;
};
force.strength = function (_) {
return arguments.length ? (strength = +_, force) : strength;
};
force.radius = function (_) {
return arguments.length ? (radius = typeof _ === "function" ? _ : constant(+_), initialize(), force) : radius;
};
return force;
}
function index(d) {
return d.index;
}
function find(nodeById, nodeId) {
var node = nodeById.get(nodeId);
if (!node) throw new Error("node not found: " + nodeId);
return node;
}
function forceLink (links) {
var id = index,
strength = defaultStrength,
strengths,
distance = constant(30),
distances,
nodes,
count,
bias,
random,
iterations = 1;
if (links == null) links = [];
function defaultStrength(link) {
return 1 / Math.min(count[link.source.index], count[link.target.index]);
}
function force(alpha) {
for (var k = 0, n = links.length; k < iterations; ++k) {
for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
link = links[i], source = link.source, target = link.target;
x = target.x + target.vx - source.x - source.vx || jiggle(random);
y = target.y + target.vy - source.y - source.vy || jiggle(random);
l = Math.sqrt(x * x + y * y);
l = (l - distances[i]) / l * alpha * strengths[i];
x *= l, y *= l;
target.vx -= x * (b = bias[i]);
target.vy -= y * b;
source.vx += x * (b = 1 - b);
source.vy += y * b;
}
}
}
function initialize() {
if (!nodes) return;
var i,
n = nodes.length,
m = links.length,
nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
link;
for (i = 0, count = new Array(n); i < m; ++i) {
link = links[i], link.index = i;
if (typeof link.source !== "object") link.source = find(nodeById, link.source);
if (typeof link.target !== "object") link.target = find(nodeById, link.target);
count[link.source.index] = (count[link.source.index] || 0) + 1;
count[link.target.index] = (count[link.target.index] || 0) + 1;
}
for (i = 0, bias = new Array(m); i < m; ++i) {
link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
}
strengths = new Array(m), initializeStrength();
distances = new Array(m), initializeDistance();
}
function initializeStrength() {
if (!nodes) return;
for (var i = 0, n = links.length; i < n; ++i) {
strengths[i] = +strength(links[i], i, links);
}
}
function initializeDistance() {
if (!nodes) return;
for (var i = 0, n = links.length; i < n; ++i) {
distances[i] = +distance(links[i], i, links);
}
}
force.initialize = function (_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();
};
force.links = function (_) {
return arguments.length ? (links = _, initialize(), force) : links;
};
force.id = function (_) {
return arguments.length ? (id = _, force) : id;
};
force.iterations = function (_) {
return arguments.length ? (iterations = +_, force) : iterations;
};
force.strength = function (_) {
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initializeStrength(), force) : strength;
};
force.distance = function (_) {
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), initializeDistance(), force) : distance;
};
return force;
}
var noop = {
value: () => {}
};
function dispatch() {
for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
if (!(t = arguments[i] + "") || t in _ || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
_[t] = [];
}
return new Dispatch(_);
}
function Dispatch(_) {
this._ = _;
}
function parseTypenames(typenames, types) {
return typenames.trim().split(/^|\s+/).map(function (t) {
var name = "",
i = t.indexOf(".");
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
return {
type: t,
name: name
};
});
}
Dispatch.prototype = dispatch.prototype = {
constructor: Dispatch,
on: function (typename, callback) {
var _ = this._,
T = parseTypenames(typename + "", _),
t,
i = -1,
n = T.length; // If no callback was specified, return the callback of the given type and name.
if (arguments.length < 2) {
while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
return;
} // If a type was specified, set the callback for the given type and name.
// Otherwise, if a null callback was specified, remove callbacks of the given name.
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
while (++i < n) {
if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
}
return this;
},
copy: function () {
var copy = {},
_ = this._;
for (var t in _) copy[t] = _[t].slice();
return new Dispatch(copy);
},
call: function (type, that) {
if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
},
apply: function (type, that, args) {
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
}
};
function get(type, name) {
for (var i = 0, n = type.length, c; i < n; ++i) {
if ((c = type[i]).name === name) {
return c.value;
}
}
}
function set(type, name, callback) {
for (var i = 0, n = type.length; i < n; ++i) {
if (type[i].name === name) {
type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
break;
}
}
if (callback != null) type.push({
name: name,
value: callback
});
return type;
}
var frame = 0,
// is an animation frame pending?
timeout = 0,
// is a timeout pending?
interval = 0,
// are any timers active?
pokeDelay = 1000,
// how frequently we check for clock skew
taskHead,
taskTail,
clockLast = 0,
clockNow = 0,
clockSkew = 0,
clock = typeof performance === "object" && performance.now ? performance : Date,
setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function (f) {
setTimeout(f, 17);
};
function now() {
return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
}
function clearNow() {
clockNow = 0;
}
function Timer() {
this._call = this._time = this._next = null;
}
Timer.prototype = timer.prototype = {
constructor: Timer,
restart: function (callback, delay, time) {
if (typeof callback !== "function") throw new TypeError("callback is not a function");
time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
if (!this._next && taskTail !== this) {
if (taskTail) taskTail._next = this;else taskHead = this;
taskTail = this;
}
this._call = callback;
this._time = time;
sleep();
},
stop: function () {
if (this._call) {
this._call = null;
this._time = Infinity;
sleep();
}
}
};
function timer(callback, delay, time) {
var t = new Timer();
t.restart(callback, delay, time);
return t;
}
function timerFlush() {
now(); // Get the current time, if not already set.
++frame; // Pretend we’ve set an alarm, if we haven’t already.
var t = taskHead,
e;
while (t) {
if ((e = clockNow - t._time) >= 0) t._call.call(undefined, e);
t = t._next;
}
--frame;
}
function wake() {
clockNow = (clockLast = clock.now()) + clockSkew;
frame = timeout = 0;
try {
timerFlush();
} finally {
frame = 0;
nap();
clockNow = 0;
}
}
function poke() {
var now = clock.now(),
delay = now - clockLast;
if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
}
function nap() {
var t0,
t1 = taskHead,
t2,
time = Infinity;
while (t1) {
if (t1._call) {
if (time > t1._time) time = t1._time;
t0 = t1, t1 = t1._next;
} else {
t2 = t1._next, t1._next = null;
t1 = t0 ? t0._next = t2 : taskHead = t2;
}
}
taskTail = t0;
sleep(time);
}
function sleep(time) {
if (frame) return; // Soonest alarm already set, or will be.
if (timeout) timeout = clearTimeout(timeout);
var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
if (delay > 24) {
if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
if (interval) interval = clearInterval(interval);
} else {
if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
frame = 1, setFrame(wake);
}
}
// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
const a = 1664525;
const c = 1013904223;
const m = 4294967296; // 2^32
function lcg () {
let s = 1;
return () => (s = (a * s + c) % m) / m;
}
function x(d) {
return d.x;
}
function y(d) {
return d.y;
}
var initialRadius = 10,
initialAngle = Math.PI * (3 - Math.sqrt(5));
function forceSimulation (nodes) {
var simulation,
alpha = 1,
alphaMin = 0.001,
alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
alphaTarget = 0,
velocityDecay = 0.6,
forces = new Map(),
stepper = timer(step),
event = dispatch("tick", "end"),
random = lcg();
if (nodes == null) nodes = [];
function step() {
tick();
event.call("tick", simulation);
if (alpha < alphaMin) {
stepper.stop();
event.call("end", simulation);
}
}
function tick(iterations) {
var i,
n = nodes.length,
node;
if (iterations === undefined) iterations = 1;
for (var k = 0; k < iterations; ++k) {
alpha += (alphaTarget - alpha) * alphaDecay;
forces.forEach(function (force) {
force(alpha);
});
for (i = 0; i < n; ++i) {
node = nodes[i];
if (node.fx == null) node.x += node.vx *= velocityDecay;else node.x = node.fx, node.vx = 0;
if (node.fy == null) node.y += node.vy *= velocityDecay;else node.y = node.fy, node.vy = 0;
}
}
return simulation;
}
function initializeNodes() {
for (var i = 0, n = nodes.length, node; i < n; ++i) {
node = nodes[i], node.index = i;
if (node.fx != null) node.x = node.fx;
if (node.fy != null) node.y = node.fy;
if (isNaN(node.x) || isNaN(node.y)) {
var radius = initialRadius * Math.sqrt(0.5 + i),
angle = i * initialAngle;
node.x = radius * Math.cos(angle);
node.y = radius * Math.sin(angle);
}
if (isNaN(node.vx) || isNaN(node.vy)) {
node.vx = node.vy = 0;
}
}
}
function initializeForce(force) {
if (force.initialize) force.initialize(nodes, random);
return force;
}
initializeNodes();
return simulation = {
tick: tick,
restart: function () {
return stepper.restart(step), simulation;
},
stop: function () {
return stepper.stop(), simulation;
},
nodes: function (_) {
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
},
alpha: function (_) {
return arguments.length ? (alpha = +_, simulation) : alpha;
},
alphaMin: function (_) {
return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
},
alphaDecay: function (_) {
return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
},
alphaTarget: function (_) {
return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
},
velocityDecay: function (_) {
return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
},
randomSource: function (_) {
return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
},
force: function (name, _) {
return arguments.length > 1 ? (_ == null ? forces.delete(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
},
find: function (x, y, radius) {
var i = 0,
n = nodes.length,
dx,
dy,
d2,
node,
closest;
if (radius == null) radius = Infinity;else radius *= radius;
for (i = 0; i < n; ++i) {
node = nodes[i];
dx = x - node.x;
dy = y - node.y;
d2 = dx * dx + dy * dy;
if (d2 < radius) closest = node, radius = d2;
}
return closest;
},
on: function (name, _) {
return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
}
};
}
function forceManyBody () {
var nodes,
node,
random,
alpha,
strength = constant(-30),
strengths,
distanceMin2 = 1,
distanceMax2 = Infinity,
theta2 = 0.81;
function force(_) {
var i,
n = nodes.length,
tree = quadtree(nodes, x, y).visitAfter(accumulate);
for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
}
function initialize() {
if (!nodes) return;
var i,
n = nodes.length,
node;
strengths = new Array(n);
for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
}
function accumulate(quad) {
var strength = 0,
q,
c,
weight = 0,
x,
y,
i; // For internal nodes, accumulate forces from child quadrants.
if (quad.length) {
for (x = y = i = 0; i < 4; ++i) {
if ((q = quad[i]) && (c = Math.abs(q.value))) {
strength += q.value, weight += c, x += c * q.x, y += c * q.y;
}
}
quad.x = x / weight;
quad.y = y / weight;
} // For leaf nodes, accumulate forces from coincident quadrants.
else {
q = quad;
q.x = q.data.x;
q.y = q.data.y;
do strength += strengths[q.data.index]; while (q = q.next);
}
quad.value = strength;
}
function apply(quad, x1, _, x2) {
if (!quad.value) return true;
var x = quad.x - node.x,
y = quad.y - node.y,
w = x2 - x1,
l = x * x + y * y; // Apply the Barnes-Hut approximation if possible.
// Limit forces for very close nodes; randomize direction if coincident.
if (w * w / theta2 < l) {
if (l < distanceMax2) {
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
node.vx += x * quad.value * alpha / l;
node.vy += y * quad.value * alpha / l;
}
return true;
} // Otherwise, process points directly.
else if (quad.length || l >= distanceMax2) return; // Limit forces for very close nodes; randomize direction if coincident.
if (quad.data !== node || quad.next) {
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
}
do if (quad.data !== node) {
w = strengths[quad.data.index] * alpha / l;
node.vx += x * w;
node.vy += y * w;
} while (quad = quad.next);
}
force.initialize = function (_nodes, _random) {
nodes = _nodes;
random = _random;
initialize();
};
force.strength = function (_) {
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
};
force.distanceMin = function (_) {
return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
};
force.distanceMax = function (_) {
return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
};
force.theta = function (_) {
return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
};
return force;
}
function forceX (x) {
var strength = constant(0.1),
nodes,
strengths,
xz;
if (typeof x !== "function") x = constant(x == null ? 0 : +x);
function force(alpha) {
for (var i = 0, n = nodes.length, node; i < n; ++i) {
node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
}
}
function initialize() {
if (!nodes) return;
var i,
n = nodes.length;
strengths = new Array(n);
xz = new Array(n);
for (i = 0; i < n; ++i) {
strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
}
}
force.initialize = function (_) {
nodes = _;
initialize();
};
force.strength = function (_) {
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
};
force.x = function (_) {
return arguments.length ? (x = typeof _ === "function" ? _ : constant(+_), initialize(), force) : x;
};
return force;
}
function forceY (y) {
var strength = constant(0.1),
nodes,
strengths,
yz;
if (typeof y !== "function") y = constant(y == null ? 0 : +y);
function force(alpha) {
for (var i = 0, n = nodes.length, node; i < n; ++i) {
node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
}
}
function initialize() {
if (!nodes) return;
var i,
n = nodes.length;
strengths = new Array(n);
yz = new Array(n);
for (i = 0; i < n; ++i) {
strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
}
}
force.initialize = function (_) {
nodes = _;
initialize();
};
force.strength = function (_) {
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
};
force.y = function (_) {
return arguments.length ? (y = typeof _ === "function" ? _ : constant(+_), initialize(), force) : y;
};
return force;
}
const ForceMap = {
center: d3Force.forceCenter,
collide: d3Force.forceCollide,
nbody: d3Force.forceManyBody,
link: d3Force.forceLink,
x: d3Force.forceX,
y: d3Force.forceY
center: forceCenter,
collide: forceCollide,
nbody: forceManyBody,
link: forceLink,
x: forceX,
y: forceY
};

@@ -246,3 +1509,3 @@ const Forces = 'forces',

function simulation(nodes, _) {
const sim = d3Force.forceSimulation(nodes),
const sim = forceSimulation(nodes),
stop = sim.stop,

@@ -321,2 +1584,2 @@ restart = sim.restart;

})));
}));

2

build/vega-force.min.js

@@ -1,2 +0,2 @@

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);
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vega-dataflow"),require("vega-util")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-util"],n):n(((t="undefined"!=typeof globalThis?globalThis:t||self).vega=t.vega||{},t.vega.transforms={}),t.vega,t.vega)}(this,(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},d=t._x0,v=t._y0,x=t._x1,g=t._y1;if(!y)return t._root=p,t;for(;y.length;)if((l=n>=(o=(d+x)/2))?d=o:x=o,(s=e>=(a=(v+g)/2))?v=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=(d+x)/2))?d=o:x=o,(s=e>=(a=(v+g)/2))?v=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 d(t){return t.index}function v(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,d=[],v=this._root;for(v&&d.push(new i(v,h,c,y,p)),null==e?e=1/0:(h=t-e,c=n-e,y=t+e,p=n+e,e*=e);l=d.pop();)if(!(!(v=l.node)||(o=l.x0)>y||(a=l.y0)>p||(u=l.x1)<h||(f=l.y1)<c))if(v.length){var x=(o+u)/2,g=(a+f)/2;d.push(new i(v[3],x,g,u,f),new i(v[2],o,g,x,f),new i(v[1],x,a,u,g),new i(v[0],o,a,x,g)),(s=(n>=g)<<1|t>=x)&&(l=d[d.length-1],d[d.length-1]=d[d.length-1-s],d[d.length-1-s]=l)}else{var _=t-+this._x.call(null,v.data),m=n-+this._y.call(null,v.data),w=_*_+m*m;if(w<e){var b=Math.sqrt(e=w);h=t-b,c=n-b,y=t+b,p=n+b,r=v.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,d=this._y0,v=this._x1,x=this._y1;if(!y)return this;if(y.length)for(;;){if((l=o>=(u=(p+v)/2))?p=u:v=u,(s=a>=(f=(d+x)/2))?d=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 b(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]=b(r[e],t.name,n);else if(null==n)for(e in r)r[e]=b(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 N,M,k=0,A=0,q=0,E=0,T=0,z=0,D="object"==typeof performance&&performance.now?performance:Date,F="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function O(){return T||(F(P),T=D.now()+z)}function P(){T=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(){T=(E=D.now())+z,k=A=0;try{!function(){O(),++k;for(var t,n=N;n;)(t=T-n._time)>=0&&n._call.call(void 0,t),n=n._next;--k}()}finally{k=0,function(){var t,n,e=N,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:N=n);M=t,U(r)}(),T=0}}function R(){var t=D.now(),n=t-E;n>1e3&&(z-=n,E=t)}function U(t){k||(A&&(A=clearTimeout(A)),t-T>24?(t<1/0&&(A=setTimeout(S,t-D.now()-z)),q&&(q=clearInterval(q))):(q||(E=D.now(),q=setInterval(R,1e3)),k=1,F(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:N=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,d,v,x=n.length,g=0;g<o;++g)for(a=u(n,y,p).visitAfter(f),t=0;t<x;++t)l=n[t],d=e[l.index],v=d*d,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=d+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)/(v+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(d)}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 d(t,o,u,s){if(!t.value)return!0;var h=t.x-n.x,y=t.y-n.y,p=s-o,d=h*h+y*y;if(p*p/l<d)return d<f&&(0===h&&(d+=(h=c(e))*h),0===y&&(d+=(y=c(e))*y),d<a&&(d=Math.sqrt(a*d)),n.vx+=h*t.value*r/d,n.vy+=y*t.value*r/d),!0;if(!(t.length||d>=f)){(t.data!==n||t.next)&&(0===h&&(d+=(h=c(e))*h),0===y&&(d+=(y=c(e))*y),d<a&&(d=Math.sqrt(a*d)));do{t.data!==n&&(p=i[t.data.index]*r/d,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=d,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,d,v,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*=d=((d=Math.sqrt(y*y+p*p))-e[x])/d*r*n[x],p*=d,h.vx-=y*(v=o[x]),h.vy-=p*v,l.vx+=y*(v=1-v),l.vy+=p*v}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=v(h,f.source)),"object"!=typeof f.target&&(f.target=v(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)}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,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=vega-force.min.js.map
{
"name": "vega-force",
"version": "4.0.7",
"version": "4.1.0",
"description": "Force simulation transform for Vega dataflows.",

@@ -23,3 +23,3 @@ "keywords": [

"dependencies": {
"d3-force": "^2.1.1",
"d3-force": "^3.0.0",
"vega-dataflow": "^5.7.3",

@@ -31,3 +31,3 @@ "vega-util": "^1.15.2"

},
"gitHead": "4affcbedb9d14815dbb6d3b250ed231b54fc95c0"
"gitHead": "9a3faca4395cade9ecdfde90af98f1c53e9916b2"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc