Grid
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'
});
// Generate a random graph
ogma.generate.random({ nodes: 100, edges: 100 })
.then(function(graph) {
// Assign it to Ogma
ogma.setGraph(graph);
// Set a node size to order them by size.
ogma.getNodes().forEach(function(node) {
node.setAttributes({
radius: 2 + 10 * Math.random()
});
});
// Apply a grid layout to the graph
ogma.layouts.grid({
rows: 8,
columns: 8,
sortBy: 'radius', // or any node property,
}, {duration: 1500})
.then(function() {
ogma.view.locateGraph({
easing: 'linear',
duration: 300
});
});
});
</script>
</body>
</html>