Skip to content
  1. Examples

Nodes ​

This example shows how to animate NodeAttributes. You could annimate any attribute in the same way. Here we animate the color and position of the nodes.

ts
import Ogma from '@linkurious/ogma';

const graph = {
  nodes: [
    { id: 0, attributes: { x: 0, y: 0, radius: 5, color: 'blue' } },
    { id: 1, attributes: { x: 200, y: 200, radius: 5, color: 'blue' } }
  ]
};

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

setTimeout(() => {
  ogma.getNodes().setAttributes(
    {
      x: 100,
      y: 100,
      color: 'red',
      radius: 40
    },
    2500
  );
}, 0);
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;
}