MCPcopy Create free account
hub / github.com/idank/explainshell / d3_layout_packSiblings

Function d3_layout_packSiblings

explainshell/web/static/js/d3.v3.js:6008–6071  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

6006 return dr * dr - dx * dx - dy * dy > .001;
6007 }
6008 function d3_layout_packSiblings(node) {
6009 if (!(nodes = node.children) || !(n = nodes.length)) return;
6010 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
6011 function bound(node) {
6012 xMin = Math.min(node.x - node.r, xMin);
6013 xMax = Math.max(node.x + node.r, xMax);
6014 yMin = Math.min(node.y - node.r, yMin);
6015 yMax = Math.max(node.y + node.r, yMax);
6016 }
6017 nodes.forEach(d3_layout_packLink);
6018 a = nodes[0];
6019 a.x = -a.r;
6020 a.y = 0;
6021 bound(a);
6022 if (n > 1) {
6023 b = nodes[1];
6024 b.x = b.r;
6025 b.y = 0;
6026 bound(b);
6027 if (n > 2) {
6028 c = nodes[2];
6029 d3_layout_packPlace(a, b, c);
6030 bound(c);
6031 d3_layout_packInsert(a, c);
6032 a._pack_prev = c;
6033 d3_layout_packInsert(c, b);
6034 b = a._pack_next;
6035 for (i = 3; i < n; i++) {
6036 d3_layout_packPlace(a, b, c = nodes[i]);
6037 var isect = 0, s1 = 1, s2 = 1;
6038 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
6039 if (d3_layout_packIntersects(j, c)) {
6040 isect = 1;
6041 break;
6042 }
6043 }
6044 if (isect == 1) {
6045 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
6046 if (d3_layout_packIntersects(k, c)) {
6047 break;
6048 }
6049 }
6050 }
6051 if (isect) {
6052 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
6053 i--;
6054 } else {
6055 d3_layout_packInsert(a, c);
6056 b = c;
6057 bound(c);
6058 }
6059 }
6060 }
6061 }
6062 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
6063 for (i = 0; i < n; i++) {
6064 c = nodes[i];
6065 c.x -= cx;

Callers

nothing calls this directly

Calls 5

boundFunction · 0.85
d3_layout_packPlaceFunction · 0.85
d3_layout_packInsertFunction · 0.85
d3_layout_packIntersectsFunction · 0.85
d3_layout_packSpliceFunction · 0.85

Tested by

no test coverage detected