Appearance
Color pie
This example shows how to use the color attribute to display a pie-chart on a node.
js
import Ogma from '@linkurious/ogma';
const COLORS = [
'#161344',
'#3f1c4c',
'#632654',
'#86315b',
'#a93c63',
'#cd476a',
'#f35371'
];
const ogma = new Ogma({
container: 'graph-container'
});
// Create a rule that assigns an array of colors to each node.
ogma.styles.addRule({
nodeAttributes: {
color: node => {
// in this case ids are numeric, so let's use it to decide how many slices to show
const i = +node.getId();
return COLORS.slice(0, 1 + (i % COLORS.length));
},
radius: 10
}
});
// Create a random graph
ogma.generate
.random({ nodes: 12, edges: 0 })
.then(graph => ogma.setGraph(graph))
.then(() => ogma.layouts.grid({ locate: true }));
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 src="index.js"></script>
</body>
</html>
css
#graph-container {
top: 0;
bottom: 0;
left: 0;
right: 0;
position: absolute;
margin: 0;
overflow: hidden;
}