code: function improveRankOrdering(g, fixed, movable) {
      var weights = rankWeights(g, fixed, movable);
  
      var result = [];
  
      var layer = movable.slice(0);
      
      // Move fixed nodes into the result array first
      for (var i = 0; i < layer.length; ++i) {
        var u = layer[i];
        if (weights[u] === -1) {
          result[i] = u;
          layer[i] = null;
        }
      }
  
      layer.sort(function(x, y) { return (x ? weights[x] : -1) - (y ? weights[y] : -1); });
  
      var nextIdx = 0;
      for (var i = 0; i < layer.length; ++i) {
        if (layer[i] !== null) {
          while (result[nextIdx] !== undefined) {
            ++nextIdx;
          }
          result[nextIdx] = layer[i];
        }
      }
  
      return result;
    }
docs: /*
  Given a fixed layer and a movable layer in a graph this function will
  attempt to find an improved ordering for the movable layer such that
  edge crossings may be reduced.
  
  This algorithm is based on the barycenter method.