Appearance
Color
This example shows how to use the color attribute on texts.
ts
import Ogma from '@linkurious/ogma';
const ogma = new Ogma({
container: 'graph-container'
});
ogma.styles.addNodeRule({
text: {
color: 'blue',
minVisibleSize: 5,
content: n => 'Node ' + n.getId()
}
});
ogma.styles.addEdgeRule({
text: {
color: 'grey',
minVisibleSize: 3,
content: e => 'Edge ' + e.getId()
}
});
ogma.styles.setHoveredNodeAttributes({ text: { color: 'red' } });
ogma.styles.setSelectedNodeAttributes({ text: { color: 'red' } });
ogma.styles.setHoveredEdgeAttributes({ text: { color: 'red' } });
ogma.styles.setSelectedEdgeAttributes({ text: { color: 'red' } });
const graph = await ogma.generate.random({ nodes: 15, edges: 15 });
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;
}