Appearance
Power law
This example shows how to generate a graph from the Barabási–Albert (BA) model. It uses barbasiAlbert.
ts
import Ogma from '@linkurious/ogma';
const ogma = new Ogma({
container: 'graph-container'
});
// pastel dark blue color for nodes
ogma.styles.addNodeRule({
color: '#122140',
radius: 10
});
// Generate a Barabasi graph.
const graph = await ogma.generate.barabasiAlbert({
nodes: 100,
m0: 10,
m: 1
});
// Assign the graph to Ogma
await ogma.setGraph(graph);
// Apply a layout
await ogma.layouts.force({ locate: true, duration: 0 });
// Remove the 'Loading...' banner.
document.getElementById('load')?.remove();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 type="module" src="index.ts"></script>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
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;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19