MCPcopy Create free account
hub / github.com/microsoft/SandDance / cluster

Function cluster

docs/app/js/sanddance-app.js:137478–137501  ·  view source on GitHub ↗
(root)

Source from the content-addressed store, hash-verified

137476exports.default = function() {
137477 var separation = defaultSeparation, dx = 1, dy = 1, nodeSize = false;
137478 function cluster(root) {
137479 var previousNode, x = 0;
137480 // First walk, computing the initial x & y values.
137481 root.eachAfter(function(node) {
137482 var children = node.children;
137483 if (children) {
137484 node.x = meanX(children);
137485 node.y = maxY(children);
137486 } else {
137487 node.x = previousNode ? x += separation(node, previousNode) : 0;
137488 node.y = 0;
137489 previousNode = node;
137490 }
137491 });
137492 var left = leafLeft(root), right = leafRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;
137493 // Second walk, normalizing x & y to the desired size.
137494 return root.eachAfter(nodeSize ? function(node) {
137495 node.x = (node.x - root.x) * dx;
137496 node.y = (root.y - node.y) * dy;
137497 } : function(node) {
137498 node.x = (node.x - x0) / (x1 - x0) * dx;
137499 node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
137500 });
137501 }
137502 cluster.separation = function(x) {
137503 return arguments.length ? (separation = x, cluster) : separation;
137504 };

Callers

nothing calls this directly

Calls 4

meanXFunction · 0.70
maxYFunction · 0.70
leafLeftFunction · 0.70
leafRightFunction · 0.70

Tested by

no test coverage detected