Skip to content
  1. Examples

Add node

This example shows how to add a node to the graph using the addNode method.

ts
import Ogma from '@linkurious/ogma';

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

// Add multiple nodes
ogma
  .addNodes([
    { id: 'n1', attributes: { x: -40, y: 20, color: 'magenta' } },
    { id: 'n2', attributes: { x: 0, y: -30, color: 'orange' } },
    { id: 'n3', attributes: { x: 40, y: 20, color: 'orange' } }
  ])
  .then(() => ogma.view.locateGraph());

setTimeout(() => {
  ogma
    .addNode({
      id: 'n0',
      attributes: { x: 0, y: 0, color: 'green', radius: 20 }
    })
    .pulse({ width: 5, duration: 1000 });
}, 1000);
html
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />

    <link type="text/css" rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <div id="graph-container"></div>
    <script type="module" src="index.ts"></script>
  </body>
</html>
css
#graph-container {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  position: absolute;
  margin: 0;
  overflow: hidden;
}