Skip to content
Snippets Groups Projects
Commit e38d6fca authored by David Bühler's avatar David Bühler
Browse files

[ivette] Dive: prevents cytoscape to automatically select (and unselect) nodes.

parent ddac9da6
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,21 @@ function callstackToString(callstack: callstack): string { ...@@ -54,6 +54,21 @@ function callstackToString(callstack: callstack): string {
return callstack.map((cs) => `${cs.fun}:${cs.instr}`).join('/'); return callstack.map((cs) => `${cs.fun}:${cs.instr}`).join('/');
} }
/* The Dive class handles the selection of nodes according to user actions.
To prevent cytoscape to automatically select (and unselect) nodes wrongly,
we make some nodes unselectable. We then use the functions below to make
the nodes selectable before (un)selecting them. */
function select(node: Cytoscape.NodeSingular): void {
node.selectify();
node.select();
}
function unselect(node: Cytoscape.NodeSingular): void {
node.selectify();
node.unselect();
}
export type mode = 'explore' | 'overview'; export type mode = 'explore' | 'overview';
class Dive { class Dive {
...@@ -425,12 +440,15 @@ class Dive { ...@@ -425,12 +440,15 @@ class Dive {
const writes = node.data()?.writes; const writes = node.data()?.writes;
if (writes) if (writes)
this.onSelect?.(writes); this.onSelect?.(writes);
this.selectNode(node); this.selectNode(node);
/* Cytoscape automatically selects the node clicked, and unselects all other
nodes and edges. As we want some incoming edges to remain selected, we
make the node unselectable, preventing cytoscape to select it. */
node.unselectify();
} }
selectLocation(location: States.Location) { selectLocation(location: States.Location) {
const selectNode = this.cy.$(':selected'); const selectNode = this.cy.$('node:selected');
const writes = selectNode?.data()?.writes; const writes = selectNode?.data()?.writes;
if (location.marker && !_.some(writes, location)) { if (location.marker && !_.some(writes, location)) {
this.add(location.marker); this.add(location.marker);
...@@ -444,8 +462,8 @@ class Dive { ...@@ -444,8 +462,8 @@ class Dive {
const hasOrigin = (ele: Cytoscape.NodeSingular) => ( const hasOrigin = (ele: Cytoscape.NodeSingular) => (
_.some(ele.data().origins, this.selectedLocation) _.some(ele.data().origins, this.selectedLocation)
); );
this.cy.$(':selected').unselect(); this.cy.$(':selected').forEach(unselect);
node.select(); select(node);
const edges = node.incomers('edge'); const edges = node.incomers('edge');
edges.unselect(); edges.unselect();
edges.filter(hasOrigin).select(); edges.filter(hasOrigin).select();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment