Skip to content

Instantly share code, notes, and snippets.

@DavidDurman
Created January 2, 2014 22:25
Show Gist options
  • Save DavidDurman/8228247 to your computer and use it in GitHub Desktop.
Save DavidDurman/8228247 to your computer and use it in GitHub Desktop.
function layout(graph) {
var graphJSON = { id: 'root', children: [], edges: [] };
_.each(graph.getElements(), function(el) {
graphJSON.children.push({
id: el.id,
width: el.get('size').width,
height: el.get('size').height
});
});
_.each(graph.getLinks(), function(link) {
graphJSON.edges.push({
id: link.id,
source: link.get('source').id,
target: link.get('target').id
});
});
var options = {
spacing: 100,
algorithm: 'de.cau.cs.kieler.klay.layered'
};
var xhr = $.ajax({
type : 'POST',
contentType : 'application/json',
url : 'http://layout.rtsys.informatik.uni-kiel.de:9444' + '/live',
data : {
graph : JSON.stringify(graphJSON),
config : JSON.stringify(options),
iFormat : 'org.json',
oFormat : 'org.json'
}
});
xhr.done(function(data) {
var graphJSON = JSON.parse(data);
_.each(graphJSON[0].children, function(child) {
graph.getCell(child.id).set('position', { x: child.x, y: child.y });
});
_.each(graphJSON[0].edges, function(edge) {
graph.getCell(edge.id).set('vertices', edge.bendPoints);
});
});
xhr.fail(function(xhr, err) {
console.log('Error', xhr.responseText);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment