All versions of this documentation
X

Shape

Node shape is controlled by the `shape` attribute.

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 SHAPES = ['circle', 'square', 'cross', 'diamond', 'star', 'equilateral'];

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

// Define the style of nodes. Use a deterministic function to randomly assign a shape to each node.
ogma.styles.addNodeRule({
    shape: function (n) { return SHAPES[n.getId() % SHAPES.length]; }
});

// Generate a random graph
ogma.generate.random({ nodes: 20, edges: 0 })
  // Assign this graph to Ogma.
  .then( function (graph) {
      ogma.setGraph(graph);
      ogma.view.locateGraph();

      // Change the shape and color of a specific node
      ogma.getNode('0').setAttributes({color:'orange', shape:'circle'})
  });

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