Appearance
Width
This example shows how to use the edge width attribute to change the width of edges in a graph.
ts
import Ogma, { RawEdge, RawNode } from '@linkurious/ogma';
const ogma = new Ogma({
container: 'graph-container'
});
// Create a random graph.
const nodes: RawNode[] = [];
const edges: RawEdge[] = [];
const distance = 100;
ogma.styles.addRule({
nodeAttributes: {
color: '#1499ff'
}
});
for (let i = 0; i < 5; i++) {
nodes.push(
{ id: nodes.length.toString(), attributes: { x: distance * i, y: 0 } },
{
id: (nodes.length + 1).toString(),
attributes: { x: distance * i, y: distance }
}
);
edges.push({
source: nodes[nodes.length - 2].id!,
target: nodes[nodes.length - 1].id!,
attributes: { width: i + 1 }
});
}
await ogma.setGraph({ nodes, edges });
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>
<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;
}