All versions of this documentation
X

Add edge

We add an edge to the graph after initializing Ogma. Notice that it is possible to add edges in batch.

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; }
  </style>
</head>
<body>
  <div id="graph-container"></div>

<script>
'use strict';

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

ogma.addNodes([
  {id: 'n0', attributes: {x: 0, y: 0, color: 'green'}},
  {id: 'n1', attributes: {x: 60, y: 20, color: 'magenta'}},
  {id: 'n2', attributes: {x: 30, y: -30, color: 'orange'}}
]);

ogma.addEdge({ id: 'e0', source: 'n0', target: 'n1' });

// Add multiple edges:
ogma.addEdges([
  { id: 'e1', source: 'n2', target: 'n2' },
  { id: 'e2', source: 'n1', target: 'n2' },
  { id: 'e3', source: 'n0', target: 'n1' }
]);

ogma.view.locateGraph();
</script>
</body>
</html>