All versions of this documentation
X

Hierarchical


Open in a new window.
          <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <script src="../build/ogma.min.js"></script>
  <script src="//unpkg.com/dagre@0.7.4/dist/dagre.min.js"></script>
  <style>
    #graph-container { top: 0; bottom: 0; left: 0; right: 0; position: absolute; margin: 0; overflow: hidden; }
  </style>
</head>
<body>
  <div id="graph-container"></div>

<script>
'use strict';

var ogma = new Ogma({
  container: 'graph-container',
  plugins: ['dagre']
});

ogma.generate.balancedTree({
  children : 2,
  height: 5
}).then(function(graph) {

  ogma.setGraph(graph);

  // Wire some nodes to create a DAG
  ogma.addEdge({ id: 999, source: 0, target: 11 });
  ogma.addEdge({ id: 998, source: 2, target: 18 });

  // Run layout
  ogma.layouts.hierarchical({
    directed: true,     // Take edge direction into account
    rankdir: 'TB',      // Direction for rank nodes. Can be TB, BT, LR, or RL,
                        // where T = top, B = bottom, L = left, and R = right.
    duration: 300,      // Duration of the animation
    nodeDistance:  15,  // Number of pixels that separate nodes horizontally in the layout.
    levelDistance: 30   // Number of pixels between each rank in the layout.
  })
  .then(function() {
    console.log('done');
    ogma.view.locateGraph({
      easing: 'linear',
      duration: 300
    });
  });
});

</script>
</body>
</html>