All versions of this documentation

Small world

Generate a graph from the Erdős–Rényi (ER) model. It can be called with either (n,p) or (n,m) options. We apply a layout after the graph is generated.

Open in a new window.
          <!DOCTYPE html>
  <meta charset="utf-8">
  <script src="../build/ogma.min.js"></script>
    #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;
  <div id="graph-container"></div>
  <span id="load">Loading...</span>

'use strict';

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

  nodes : 100,
  p: 0.1
}).then(function(graph) {
  return ogma.setGraph(graph);
}).then(function() {
  // Apply a layout then adjust the view to show the whole graph and remove the 'Loading...' banner.
  return ogma.layouts.forceLink()
}).then(function() {
  return ogma.view.locateGraph({
    easing: 'linear',
    duration: 300
}).then(function() {
  // Remove the 'Loading...' banner.