/*
Constructs an adjacency graph using the nodes and edges specified through
config. For each node and edge we add a property `dagre` that contains an
object that will hold intermediate and final layout information. Some of
the contents include:

1) A generated ID that uniquely identifies the object.
2) Dimension information for nodes (copied from the source node).
3) Optional dimension information for edges.

After the adjacency graph is constructed the code no longer needs to use
the original nodes and edges passed in via config.
function initLayoutGraph(inputGraph) {
    var g = new CDigraph();

    inputGraph.eachNode(function(u, value) {
      if (value === undefined) value = {};
      g.addNode(u, {
        width: value.width,
        height: value.height
      });
      if (value.hasOwnProperty('rank')) {
        g.node(u).prefRank = value.rank;
      }
    });

    // Set up subgraphs
    if (inputGraph.parent) {
      inputGraph.nodes().forEach(function(u) {
        g.parent(u, inputGraph.parent(u));
      });
    }

    inputGraph.eachEdge(function(e, u, v, value) {
      if (value === undefined) value = {};
      var newValue = {
        e: e,
        minLen: value.minLen || 1,
        width: value.width || 0,
        height: value.height || 0,
        points: []
      };

      g.addEdge(null, u, v, newValue);
    });

    // Initial graph attributes
    var graphValue = inputGraph.graph() || {};
    g.graph({
      rankDir: graphValue.rankDir || config.rankDir
    });

    return g;
  }