cytoscape / cytoscape.js-dagre

The Dagre layout for DAGs and trees for Cytoscape.js
MIT License
246 stars 82 forks source link

Add onlyVisible option to ignore hidden elements #32

Closed physikerwelt closed 6 years ago

physikerwelt commented 6 years ago

In the default configuration even hidden nodes use space. This might result in an unintuitive layout. Space is reserved for those nodes, but no content is displayed.

According to http://js.cytoscape.org/#style/visibility elements with the property display:none do not use space and elements should not use space and not be connected.

However, the cytoscape API http://js.cytoscape.org/#ele.visible provides a 'hide' method that sets display to 'none' and a 'hidden' function that is just the oposit of the 'visible' function.

Thus a new option 'onlyVisible' was added that the user can define, if invisible elements should use space.

maxkfranz commented 6 years ago

If you don't want elements to be in a layout don't include those elements in the eles.layout() call.

physikerwelt commented 6 years ago

Thank you. For reference I had to replace

  cytoscape.use(dagre);
  cy.layout({
    name: 'dagre',
    fit:true
  }).run();

with

  cytoscape.use(dagre);
  cy.elements().filter(e => e.visible()).layout({
    name: 'dagre',
    fit:true
  }).run();