bundle()

in src/models/GraphBundler.js [21:58]


  bundle() {
    const heap = new Heap((a, b) => a.data.id - b.data.id);

    // Add candidate parents to heap
    this.nodes
      .filter(n => this.hasPotential(n))
      .forEach(n => { heap.push(n); });

    while (heap.size() > 0) {
      const parent = heap.pop();
      if (parent.merged) {
        continue;
      }

      let groups = [];
      if (parent.leftLinks.length > 1) {
        const lNodes = parent.leftLinks.map(l => l.source);
        groups = groups.concat(this.groupMergeableNodes(lNodes));
      }

      if (parent.rightLinks.length > 1) {
        const rNodes = parent.rightLinks.map(l => l.target);
        groups = groups.concat(this.groupMergeableNodes(rNodes));
      }

      if (groups.length > 0) {
        const newNodes = groups.map(group => this.mergeNodes(group));
        newNodes.filter(n => this.hasPotential(n))
          .forEach(n => { heap.push(n); });
      }
    }

    return {
      nodes: this.nodes.filter(n => !n.merged),
      links: this.links.filter(l =>
        !l.source.merged && !l.target.merged),
    };
  }