MCPcopy
hub / github.com/tdewolff/minify / forceLayout

Function forceLayout

_benchmarks/sample_echarts.js:56916–57064  ·  view source on GitHub ↗
(inNodes, inEdges, opts)

Source from the content-addressed store, hash-verified

56914 // }
56915
56916 function forceLayout(inNodes, inEdges, opts) {
56917 var nodes = inNodes;
56918 var edges = inEdges;
56919 var rect = opts.rect;
56920 var width = rect.width;
56921 var height = rect.height;
56922 var center = [rect.x + width / 2, rect.y + height / 2]; // let scale = opts.scale || 1;
56923
56924 var gravity = opts.gravity == null ? 0.1 : opts.gravity; // for (let i = 0; i < edges.length; i++) {
56925 // let e = edges[i];
56926 // let n1 = e.n1;
56927 // let n2 = e.n2;
56928 // n1.edges = n1.edges || [];
56929 // n2.edges = n2.edges || [];
56930 // n1.edges.push(e);
56931 // n2.edges.push(e);
56932 // }
56933 // Init position
56934
56935 for (var i = 0; i < nodes.length; i++) {
56936 var n = nodes[i];
56937
56938 if (!n.p) {
56939 n.p = create(width * (Math.random() - 0.5) + center[0], height * (Math.random() - 0.5) + center[1]);
56940 }
56941
56942 n.pp = clone$1(n.p);
56943 n.edges = null;
56944 } // Formula in 'Graph Drawing by Force-directed Placement'
56945 // let k = scale * Math.sqrt(width * height / nodes.length);
56946 // let k2 = k * k;
56947
56948
56949 var initialFriction = opts.friction == null ? 0.6 : opts.friction;
56950 var friction = initialFriction;
56951 var beforeStepCallback;
56952 var afterStepCallback;
56953 return {
56954 warmUp: function () {
56955 friction = initialFriction * 0.8;
56956 },
56957 setFixed: function (idx) {
56958 nodes[idx].fixed = true;
56959 },
56960 setUnfixed: function (idx) {
56961 nodes[idx].fixed = false;
56962 },
56963
56964 /**
56965 * Before step hook
56966 */
56967 beforeStep: function (cb) {
56968 beforeStepCallback = cb;
56969 },
56970
56971 /**
56972 * After step hook
56973 */

Callers 1

graphForceLayoutFunction · 0.85

Calls 9

subFunction · 0.85
lenFunction · 0.85
isNaNFunction · 0.85
createFunction · 0.70
clone$1Function · 0.70
normalizeFunction · 0.70
setFunction · 0.70
copyFunction · 0.70
cbFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…