Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expanding collapsed edges breaks existing edges #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sashokbg
Copy link

@sashokbg sashokbg commented Nov 8, 2021

This PR fixes issues described in #128 where expanding / collapsing edges can lead to an exception and a loss of edges between nodes.

Second issue was that collapsing / expanding nodes with collapsed edges would result into a bad "repair" of the original link's source and destination

@@ -606,9 +609,12 @@ return {
edge.data('originalEnds', originalEndsData);
}

Copy link
Author

@sashokbg sashokbg Nov 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this improves readability and inverses the condition

this.repairEdgesForNode(edge.source());
this.repairEdgesForNode(edge.target());
},
repairEdgesForNode: function(node) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a "repairEdge" function that repairs meta links for edges after they have been expanded

@@ -670,6 +684,10 @@ return {
*/
getCollapsedChildrenRecursively: function(node, collapsedChildren){
var children = node.data('collapsedChildren') || [];
for(let child of node.children()) {
collapsedChildren = this.getCollapsedChildrenRecursively(child, collapsedChildren);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collapsed children are also children who have collapsed children

@@ -783,7 +801,33 @@ return {
edge.trigger('expandcollapse.beforeexpandedge');
result.oldEdges = result.oldEdges.add(edge);
cy.remove(edge);
result.edges = cy.add(edges);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix:

  1. added try / catch to avoid breaking everything in case of an exception
  2. before adding the new edges (after expanding a collapsed edge) verify that their source/target are visible
  3. If source or target not visible treat the edge as a meta edge
  • save original ends
  • add meta edge class
  • instead of "move" just update source and data - move will fail since its source or target is missing
  1. After everything call "repairEdge" to properly re-link all meta edges

@Revadike
Copy link

Revadike commented Jul 9, 2022

Your PR does not seem to fix this issue, but the master banch on your fork does. What's up with that?

@Revadike
Copy link

Revadike commented Jul 9, 2022

Your fork was working perfectly, until I came across this issue when I try to collapse a compound node with a lot of nodes:

image

This node actually exists in the input data
I don't know why it throws this error
The original cytoscape.js-expand-collapse library does not have this issue
This is really frustrating!

@sashokbg
Copy link
Author

Hello, @Revadike it is because there are a couple of fixes and the repository maintainers do not wish to merge them. On my fork I have merged both to the master branch.

Regarding your other issue I can't tell where it may be coming from. You should create a minimal example that reproduces it.

P.S Yes it is frustrating when things do not work but please have in mind that this is a open source collaboration and everyone of us contributes in terms of their availability and motivation. Please try contributing as well ! :)

@Revadike
Copy link

Revadike commented Aug 28, 2022

I can't figure out what the issue is, but when I expand a node with collapsed edges (to other collapsed nodes), it gives this error:
image

Even though, the non-existent source (in this case scan-1110-12877) is stored in the appropriate collapsed edge originalEnds property.

If I leave all edges expanded and only use collapsing/expanding nodes, it works without issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants