Background color
We can change the background to a custom color at the initialisation of Ogma, or after with the setOptions method.
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',
options: {
backgroundColor: '#514F6A'
}
});
// Change the background after the initialization of Ogma.
ogma.setOptions({
backgroundColor: '#514F6A'
});
ogma.generate.random({ nodes: 10, edges: 20 }).then(function(g) {
ogma.setGraph(g);
ogma.view.locateGraph();
});
ogma.styles.addNodeRule({
color: 'white',
text: {
color: 'white',
content: function (n) {return 'Node ' + n.getId()}
}
});
ogma.styles.addEdgeRule({
color: null,
text: {
color: 'white',
content: function (e) {return 'Edge ' + e.getId()}
}
});
ogma.styles.setHoveredNodeAttributes({
text: {
backgroundColor: '#0A091D'
}
});
ogma.styles.setHoveredEdgeAttributes({
text: {
backgroundColor: '#0A091D'
}
});
</script>
</body>
</html>