All versions of this documentation

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

'use strict';

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

  {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:
  { id: 'e1', source: 'n2', target: 'n2' },
  { id: 'e2', source: 'n1', target: 'n2' },
  { id: 'e3', source: 'n0', target: 'n1' }