import filter from "../lodash-es/filter.js";
import max from "../lodash-es/max.js";
import map from "../lodash-es/map.js";
import range from "../lodash-es/range.js";
import sortBy from "../lodash-es/sortBy.js";
import forEach from "../lodash-es/forEach.js";
import has from "../lodash-es/has.js";
function initOrder(g) {
  var visited = {};
  var simpleNodes = filter(g.nodes(), function(v) {
    return !g.children(v).length;
  });
  var maxRank = max(
    map(simpleNodes, function(v) {
      return g.node(v).rank;
    })
  );
  var layers = map(range(maxRank + 1), function() {
    return [];
  });
  function dfs(v) {
    if (has(visited, v)) return;
    visited[v] = true;
    var node = g.node(v);
    layers[node.rank].push(v);
    forEach(g.successors(v), dfs);
  }
  var orderedVs = sortBy(simpleNodes, function(v) {
    return g.node(v).rank;
  });
  forEach(orderedVs, dfs);
  return layers;
}
export {
  initOrder
};
//# sourceMappingURL=src-dagre-order-init-order.js.map
