1

similar to this prototype http://jsfiddle.net/g5f16erz/ I use Cytoscape.js to create an interactive directed acyclic graph using the dagre layout.

In particular the following code is used to collapse and expand nodes:

cy.nodes().on('click', function(e) {
if (this.hasClass('open')) {
  this.removeClass('open');
  this.successors().removeClass('open').addClass('hidden');
} else {
  var children = this.neighborhood('.hidden');
  this.removeClass("collapsed");
  children.removeClass("hidden");
  children.incomers(".hidden").removeClass("hidden");
  this.addClass('open');
}
});

Is there a way to recalculate the layout of the graph every time a node has been collapsed or expanded?

Thanks in advance

Andy
  • 9,483
  • 12
  • 38
  • 39

1 Answers1

0

You can run a layout whenever you want. You can also run layouts on a particular subset of elements: http://js.cytoscape.org/#eles.layout

In your case, I suppose you'd just run the layout at the end of your event callback.

maxkfranz
  • 11,896
  • 1
  • 27
  • 36