Sha256: ed2c13aa199458549d1f5aa84cc1595aea8c1f2d6d5bbf6ca1faab17b3d0f999

Contents?: true

Size: 1.46 KB

Versions: 31

Compression:

Stored size: 1.46 KB

Contents

// Implements hierarchical edge bundling using Holten's algorithm. For each
// input link, a path is computed that travels through the tree, up the parent
// hierarchy to the least common ancestor, and then back down to the destination
// node. Each path is simply an array of nodes.
d3.layout.bundle = function() {
  return function(links) {
    var paths = [],
        i = -1,
        n = links.length;
    while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
    return paths;
  };
};

function d3_layout_bundlePath(link) {
  var start = link.source,
      end = link.target,
      lca = d3_layout_bundleLeastCommonAncestor(start, end),
      points = [start];
  while (start !== lca) {
    start = start.parent;
    points.push(start);
  }
  var k = points.length;
  while (end !== lca) {
    points.splice(k, 0, end);
    end = end.parent;
  }
  return points;
}

function d3_layout_bundleAncestors(node) {
  var ancestors = [],
      parent = node.parent;
  while (parent != null) {
    ancestors.push(node);
    node = parent;
    parent = parent.parent;
  }
  ancestors.push(node);
  return ancestors;
}

function d3_layout_bundleLeastCommonAncestor(a, b) {
  if (a === b) return a;
  var aNodes = d3_layout_bundleAncestors(a),
      bNodes = d3_layout_bundleAncestors(b),
      aNode = aNodes.pop(),
      bNode = bNodes.pop(),
      sharedNode = null;
  while (aNode === bNode) {
    sharedNode = aNode;
    aNode = aNodes.pop();
    bNode = bNodes.pop();
  }
  return sharedNode;
}

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
picky-statistics-4.5.0 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.4.2 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.4.1 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.4.0 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.3.2 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.3.1 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.3.0 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.2.4 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.2.3 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.2.2 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.2.1 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.2.0 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.1.0 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.0.9 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.0.8 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.0.7 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.0.6 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.0.5 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.0.4 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js
picky-statistics-4.0.3 lib/picky-statistics/application/javascripts/d3/src/layout/bundle.js