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

Option to Display number of collapsed nodes on collapsed groups #120

Closed Alexithemia closed 3 years ago

Alexithemia commented 3 years ago

Would you be able to implement an option for the collapsed groups to display how many nodes are collapsed within it?

Or do you know of an easy way to achieve this? I am already using the label normally.

image

ugurdogrusoz commented 3 years ago

@canbax The users should be able to access number of such nodes, right?

canbax commented 3 years ago

When the nodes are collapsed, the information about the collapsed children is stored inside their data with a property named collapsedChildren (includes both edges and nodes). So the API users can get this info easily.

Below is a sample code that prints console the number of collapsed children when a collapsed node is tapped.

cy.on('tap', 'node.cy-expand-collapse-collapsed-node', function (evt) {
  let node = evt.target;
  console.log('collapsed children count: ' + node.data('collapsedChildren').length);
});

Here node.data('collapsedChildren') is a cytoscape.js collection.

In the canvas, this information can be shown in at least 2 different ways.

Both can be implemented inside the API or an API user can also do these without changing the API.

Alexithemia commented 3 years ago

I did see how I would get the number from the collapsed node, and I will need to filter out only the nodes as edges are also in the collapsed children collection, adding it to the label would be easy but the badge look is what we want.

How would we go about showing that as a badge like the cue image?

ugurdogrusoz commented 3 years ago

That's a Cytoscape.js core issue not related to this extension. You could use background images for instance.