code: function verticalAlignment(g, layering, conflicts, neighborFn) {
    var root = {},
      align = {},
      pos = {};
  
    // We cache the position here based on the layering because the graph and
    // layering may be out of sync. The layering matrix is manipulated to
    // generate different extreme alignments.
    _.forEach(layering, function(layer) {
      _.forEach(layer, function(v, order) {
        root[v] = v;
        align[v] = v;
        pos[v] = order;
      });
    });
  
    _.forEach(layering, function(layer) {
      var prevIdx = -1;
      _.forEach(layer, function(v) {
        var ws = neighborFn(v);
        if (ws.length) {
          ws = _.sortBy(ws, function(w) { return pos[w]; });
          var mp = (ws.length - 1) / 2;
          for (var i = Math.floor(mp), il = Math.ceil(mp); i <= il; ++i) {
            var w = ws[i];
            if (align[v] === v &&
                prevIdx < pos[w] &&
                !hasConflict(conflicts, v, w)) {
              align[w] = v;
              align[v] = root[v] = root[w];
              prevIdx = pos[w];
            }
          }
        }
      });
    });
  
    return { root: root, align: align };
  }
docs: /*
  Try to align nodes into vertical "blocks" where possible. This algorithm
  attempts to align a node with one of its median neighbors. If the edge
  connecting a neighbor is a type-1 conflict then we ignore that possibility.
  If a previous node has already formed a block with a node after the node
  we're trying to form a block with, we also ignore that possibility - our
  blocks would be split in that scenario.