Appearance
Remove node
This example shows how to remove a node from the graph using the removeNode method.
ts
import Ogma from '@linkurious/ogma';
const ogma = new Ogma({
container: 'graph-container'
});
ogma.generate
.grid({
rows: 3,
columns: 3
})
.then(graph => ogma.setGraph(graph))
.then(() => ogma.view.locateGraph())
.then(() => {
// Remove the node after 1s
setTimeout(() => {
ogma.removeNode(5);
// notice that the adjacent edges are also removed
}, 1000);
// Notice that removeNodes(array) is a faster operation
// to remove multiple nodes at once.
});
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;
}