All versions of this documentation
X

Add node

We add a node to the graph after initializing Ogma. Notice that it is preferable to add nodes in batch using the addNodes function.

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.addNode({id: 'n0', attributes: {x: 0, y: 0, color: 'green'}});

// Add multiple nodes
ogma.addNodes([
  {id: 'n1', attributes: {x: 60, y: 20, color: 'magenta'}},
  {id: 'n2', attributes: {x: 30, y: -30, color: 'orange'}}
]);

ogma.view.locateGraph();

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