Hierarchical
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.generate.balancedTree({
children : 2,
height: 5
}).then(function(graph) {
ogma.setGraph(graph);
// Wire some nodes to create a DAG
ogma.addEdge({ id: 999, source: 0, target: 11 });
ogma.addEdge({ id: 998, source: 2, target: 18 });
// Run layout
ogma.layouts.hierarchical({
direction: 'TB', // Direction of the layout. Can be TB, BT, LR, or RL,
// where T = top, B = bottom, L = left, and R = right.
duration: 300, // Duration of the animation
nodeDistance: 60, // Number of pixels that separate nodes horizontally in the layout.
levelDistance: 50 // Number of pixels between each layer in the layout.
})
.then(function() {
console.log('done');
ogma.view.locateGraph({
easing: 'linear',
duration: 300
});
});
});
</script>
</body>
</html>