cytoscape.js-expand-collapse
cytoscape.js-expand-collapse copied to clipboard
Exception - Expanding Collapsed Edges of a Collapsed Child
Hello, I have stumbled upon two bugs (possible more) when I try to expand edges that are pointing to a child of a collapsed node:
I have created a small demo file to reproduce the issue - you can check out at https://github.com/sashokbg/cytoscape.js-expand-collapse.git branch bug/child_collapse_edges file: demo/demo-bug.html
Bug 1 Disappearing edges - Steps to reproduce:
-
Starting graph
-
Click on "collapse edges" button
-
Close node 1
-
Close node a
-
Click on expand all edges <-- exception
-
Edges disappear
Stack:
Uncaught Error: Can not create edge `e1` with nonexistant source `1`
Ee cytoscape.min.js:23
restore cytoscape.min.js:29
add cytoscape.min.js:29
expandEdge expandCollapseUtilities.js:786
expandEdges index.js:272
forEach cytoscape.min.js:29
expandEdges index.js:271
expandAllEdges index.js:360
<anonymous> demo-bug.html:151
EventListener.handleEvent* demo-bug.html:150
EventListener.handleEvent* demo-bug.html:16
Bug 2 - Expanded edges change source / destination
-
Starting graph
-
Click on "collapse all"
-
Click on "collapse edges"
-
Click on "expand all" <-- bug Edges are not having as a source the parent node "a" instead of "1"
-
Click on "expand edges" <-- bug Bug persist after expanding edges, now original links are wrongly having node "a" as a source
Observations
If we first collapse all nodes and then we expand them it seems that the exception issue is gone. I have however still managed to reproduce the second bug in some scenarios when manually expanding and collapsing the child nodes and edges.
Any help or ideas are greatly appreciated ! Have a nice day! Alex
I have debugged for a while and it seems both problems are coming from manipulating collapsed edges.
First issue The function barrowEdgesOfcollapsedChildren.
In the case of the first bug, it turns out when collapsing a node, and it has edges that have already been collapsed, we are not properly creating the _cy-expand-collapse-collapsed-edge_s.
A quick fix for this issue is to just expand collapsed edges when collapsing a node. This way the meta edges are properly calculated.
Second issue Same solution can be applied in the repairEdges function:
node.connectedEdges('.cy-expand-collapse-collapsed-edge').forEach((edge) => this.expandEdge(edge));
A better fix is available at #131
Can anyone of the maintainers please take a look ? @metincansiper @hasanbalci
Anyone ?
I came here to report this exact issue. Can we get any insight from the maintainers to respond or accept #131? Or alternatively explain why they cannot/will not use this fix?
I came here to report this exact issue. Can we get any insight from the maintainers to respond or accept #131? Or alternatively explain why they cannot/will not use this fix?
+1
The first bug doesn't seem like a bug to me. It is a misuse of the API. You should not let the user expand a cy-expand-collapse-meta-edge
It is a meta edge created after you collapsed a compound node. First, the compound should be expanded since the source/target doesn't exist.
For the second, I can also say this is not a bug if you first expand the collapsed edge. But this time, expanding all the collapsed edges connected to the compounds before it is going to be expanded might be a good use case.
"Collapse/expand edges" feature was added later. It seems that its interaction with the "collapse/expand nodes" feature wasn't considered comprehensively during addition of this new feature. Therefore, these side-effects/bugs are possible. However, expand-collapse is a rather complex extension and solving such bugs requires a detailed analysis and effort. We don't want to add bug-specific patches since they may cause other unexpected issues.
Unfortunately, we currently don't have enough sources to solve this issue. My suggestion for you to avoid these cases is either to use @sashokbg's branch that possibly has a fix (I didn't try it) or to find some workarounds while presenting these features to your users.
The first bug doesn't seem like a bug to me. It is a misuse of the API. You should not let the user expand a
cy-expand-collapse-meta-edge
It is a meta edge created after you collapsed a compound node. First, the compound should be expanded since the source/target doesn't exist.For the second, I can also say this is not a bug if you first expand the collapsed edge. But this time, expanding all the collapsed edges connected to the compounds before it is going to be expanded might be a good use case.
I am sorry to disagree but those are obviously bugs. Calling an API function that completely breaks the library, or wrongly reconstructs your edges afterwards is a definition of a bug. Either the API should not allow such scenarios or if does they should not break anything.