MCPcopy Create free account
hub / github.com/breck7/scroll / tree_remove

Function tree_remove

external/.d3.js:8662–8718  ·  view source on GitHub ↗
(d)

Source from the content-addressed store, hash-verified

8660}
8661
8662function tree_remove(d) {
8663 if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
8664
8665 var parent,
8666 node = this._root,
8667 retainer,
8668 previous,
8669 next,
8670 x0 = this._x0,
8671 y0 = this._y0,
8672 x1 = this._x1,
8673 y1 = this._y1,
8674 x,
8675 y,
8676 xm,
8677 ym,
8678 right,
8679 bottom,
8680 i,
8681 j;
8682
8683 // If the tree is empty, initialize the root as a leaf.
8684 if (!node) return this;
8685
8686 // Find the leaf node for the point.
8687 // While descending, also retain the deepest parent with a non-removed sibling.
8688 if (node.length) while (true) {
8689 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
8690 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
8691 if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
8692 if (!node.length) break;
8693 if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
8694 }
8695
8696 // Find the point to remove.
8697 while (node.data !== d) if (!(previous = node, node = node.next)) return this;
8698 if (next = node.next) delete node.next;
8699
8700 // If there are multiple coincident points, remove just the point.
8701 if (previous) return (next ? previous.next = next : delete previous.next), this;
8702
8703 // If this is the root point, remove it.
8704 if (!parent) return this._root = next, this;
8705
8706 // Remove this leaf.
8707 next ? parent[i] = next : delete parent[i];
8708
8709 // If the parent now contains exactly one leaf, collapse superfluous parents.
8710 if ((node = parent[0] || parent[1] || parent[2] || parent[3])
8711 && node === (parent[3] || parent[2] || parent[1] || parent[0])
8712 && !node.length) {
8713 if (retainer) retainer[j] = node;
8714 else this._root = node;
8715 }
8716
8717 return this;
8718}
8719

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected