Appearance
Radius
This example shows how to use the radius attribute to change the size of a node.
ts
import Ogma from '@linkurious/ogma';
const ogma = new Ogma({
container: 'graph-container'
});
// Specify a random size for each node.
ogma.styles.addNodeRule({
radius: n => 5 + (+n.getId() % 10)
});
// Generate a random graph.
ogma.generate
.random({ nodes: 20, edges: 0 })
// Assign the graph to Ogma.
.then(graph => ogma.setGraph(graph))
.then(() => ogma.layouts.force({ locate: true, duration: 0 }))
.then(() => {
// Change the size of a single node and its color to purple.
ogma.getNode('0')!.setAttributes({ radius: 5, color: 'purple' });
// Change the size of two nodes and their color to orange.
ogma.getNodes(['1', '2']).setAttributes({ radius: 8, color: 'orange' });
});
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;
}