Skip to content
  1. Examples

Random

This example shows how to generate a random graph using the random method.

ts
import Ogma from '@linkurious/ogma';

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

const graph = await ogma.generate.random({
  nodes: 100,
  edges: 100
});
await ogma.setGraph(graph);
document.getElementById('load')?.remove();
await 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>
    <span id="load">Loading...</span>
    <script src="index.ts"></script>
  </body>
</html>
css
#graph-container {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  position: absolute;
  margin: 0;
  overflow: hidden;
}
#load {
  position: absolute;
  top: 0;
  left: 0;
  padding: 5px;
  color: #fff;
  background: #141229;
  font-size: 12px;
  font-family: monospace;
}