Skip to content
  1. Examples

Stroke

This example shows how to use the innerStroke and outerStroke attributes to change the stroke of a node.

js
import Ogma from '@linkurious/ogma';

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

// Define the default stroke appearance
// innerStroke is the node border
ogma.styles.addNodeRule({
  innerStroke: {
    color: 'black',
    width: 2,
    minVisibleSize: 5
  }
});

// Define the stroke appearance on hover
ogma.styles.setHoveredNodeAttributes({
  outerStroke: {
    width: 10,
    color: 'red'
  }
});

// Define the stroke appearance on selection
ogma.styles.setSelectedNodeAttributes({
  innerStroke: {
    color: 'white'
  },
  outerStroke: {
    width: 7,
    color: 'red'
  }
});

// Generate a random graph and assign it to Ogma
ogma.generate
  .random({
    nodes: 10,
    edges: 5
  })
  .then(graph => {
    ogma.setGraph(graph);
    ogma.view.locateGraph();
  });
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 src="index.js"></script>
  </body>
</html>
css
#graph-container {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  position: absolute;
  margin: 0;
  overflow: hidden;
}