iVis-at-Bilkent / cytoscape.js-expand-collapse

A Cytoscape.js extension to expand/collapse nodes for better management of complexity of compound graphs
MIT License
126 stars 37 forks source link

Example for a layout function #139

Closed Phpaulsen closed 2 years ago

Phpaulsen commented 2 years ago

Hi, I am currently working on a project that will use your extension. In your options it says: "layoutBy: null, // to rearrange after expand/collapse. It's just layout options or whole layout function. Choose your side!" and I don't really understand what is meant by "layout functions". I did not find any examples for layout functions in cytoscape which can be passed as an argument/parameter/option in other extensions. Have I misunderstood this point or can you give me a quick example of such a function? It would be really appreciated.

hasanbalci commented 2 years ago

Hi, you can give a layout function in the following way:

let layout = function(){
  cy.nodes().forEach(function(node){
    node.shift({x:50});
  });
}
let api = cy.expandCollapse({
  layoutBy: layout,
  fisheye: true,
  animate: true,
  ...
});

The example layout function shifts node positions 50 units each time. You can write another layout implementation for your own purpose.