All versions of this documentation
X

Power law

Generate a graph from the Barabási–Albert (BA) model. We apply a layout after the graph is generated.

Open in a new window.
          <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <script src="../build/ogma.min.js"></script>
  <style>
    #graph-container { top: 0; bottom: 0; left: 0; right: 0; position: absolute; margin: 0; overflow: hidden; }
    #load {
      position: absolute;
      top: 0;
      left: 0;
      padding: 5px;
      color: #fff;
      background: #141229;
      font-size: 12px;
      font-family: monospace;
    }
  </style>
</head>
<body>
  <div id="graph-container"></div>
  <span id="load">Loading...</span>

<script>
'use strict';

var ogma = new Ogma({
  container: 'graph-container'
});

// Generate a Barabasi graph.
ogma.generate.barabasiAlbert({
  nodes : 100,
  m0: 10,
  m: 1
}).then(function(graph) {
  // Assign the graph to Ogma
  return ogma.setGraph(graph);
}).then(function () {
  // Apply a layout
  return ogma.layouts.forceLink()
}).then(function() {
  // Center the view
  return ogma.view.locateGraph({
    easing: 'linear',
    duration: 300
  });
}).then(function() {
  // Remove the 'Loading...' banner.
  document.getElementById('load').parentElement.removeChild(document.getElementById('load'));
});

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