All versions of this documentation
X

SVG


Open in a new window.
          <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <script src="../build/ogma.min.js"></script>
  <style>
    #graph-container { height: 300px; }
  </style>
</head>
<body>
  <div id="graph-container"></div>
  <hr>
  SVG preview:
  <br>

<script>
'use strict';

function randomGraph(N, E) {
  var g = {nodes:[], edges:[]};

  for (var i = 0; i < N; i++) {
    g.nodes.push({
      id: 'n' + i,
      attributes: {
        x: Math.random() * 100,
        y: Math.random() * 100
      }
    });
  }

  for (var i = 0; i < E; i++) {
    g.edges.push({
      id: 'e' + i,
      source: 'n' + (Math.random() * N | 0),
      target: 'n' + (Math.random() * N | 0)
    });
  }

  return g;
}

var g = randomGraph(50, 50);

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

ogma.export.svg({
  download: false
}).then(function(svg) {
  var div = document.createElement('div');
  div.innerHTML = svg;
  document.body.appendChild(div);
});
</script>
</body>
</html>