Background
Open in a new window.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../build/ogma.min.js"></script>
<style>
#graph-container { top: 0; bottom: 0; left: 0; right: 0; position: absolute; margin: 0; overflow: hidden; }
</style>
</head>
<body>
<div id="graph-container"></div>
<script>
'use strict';
var ogma = new Ogma({
container: 'graph-container'
});
ogma.styles.addNodeRule({
radius: 3,
text: {
content: function (n) { return 'Node ' + n.getId(); },
color: '#000',
backgroundColor: 'inherit', // values: named, hex, rgb, rgba, 'inherit' (will inherit node color)
padding: 3,
minVisibleSize: 5,
margin: 20
}
});
ogma.styles.setHoveredNodeAttributes({
text: {
color: '#fff',
backgroundColor: '#000'
}
});
ogma.styles.setSelectedNodeAttributes({
text: {
color: '#fff',
backgroundColor: '#000'
}
});
ogma.styles.addEdgeRule({
color: '#ccc',
text: {
content: function (e) { return 'Edge ' + e.getId(); },
color: '#fff',
backgroundColor: 'inherit', // values: named, hex, rgb, rgba, 'inherit' (will inherit node color)
minVisibleSize: 3,
padding: 2
}
});
ogma.styles.setHoveredEdgeAttributes({
text: {
color: '#fff',
backgroundColor: '#000'
}
});
ogma.styles.setSelectedEdgeAttributes({
text: {
color: '#fff',
backgroundColor: '#000'
}
});
ogma.generate.random({ nodes: 6, edges: 6 }).then(function(g) {
ogma.setGraph(g);
ogma.view.locateGraph();
});
</script>
</body>
</html>