Appearance
Style
This example shows how to use the style attribute to change the style of the text on nodes and edges.
ts
import Ogma from '@linkurious/ogma';
const ogma = new Ogma({
container: 'graph-container'
});
ogma.styles.addNodeRule({
text: {
style: 'bold',
minVisibleSize: 5,
content: n => 'Node ' + n.getId()
}
});
ogma.styles.addEdgeRule({
text: {
// style: 'none', // not necessary here
minVisibleSize: 1,
style: 'italic',
content: e => 'Edge ' + e.getId()
}
});
ogma.styles.setHoveredEdgeAttributes({ text: { style: 'italic' } });
ogma.styles.setSelectedEdgeAttributes({ text: { style: 'bold' } });
const graph = await ogma.generate.grid({
columns: 2,
rows: 2
});
await ogma.setGraph(graph);
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;
}