Radius
Node size is controlled by the radius attribtue.
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'
});
// Specify a random size for each node.
ogma.styles.addNodeRule({
radius: function (n) { return 3 + (n.getId() % 10); }
});
// Generate a random graph.
ogma.generate.random({ nodes: 50, edges: 0 })
.then(function (graph) {
// Assign the graph to Ogma.
ogma.setGraph(graph);
ogma.view.locateGraph();
// Change the size of a single node and its color to purple.
ogma.getNode('0')
.setAttributes({ radius: 5, color: 'purple' });
// Change the size of two nodes and their color to orange.
ogma.getNodes(['1', '2'])
.setAttributes({ radius: 8, color: 'orange' });
});
</script>
</body>
</html>