Skip to content

Commit

Permalink
Fix closeInfoContainer logic when collapsing disease
Browse files Browse the repository at this point in the history
  • Loading branch information
tnaccarato committed Aug 11, 2024
1 parent 88d6c08 commit e319a6a
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions vis_phewas/static/mainapp/js/GraphHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class GraphHelper {
removeChildrenNodes(node);
/// Set expanded to false
nodeData.expanded = false;
// Close the info container with diseases
closeInfoContainer(
adjustSigmaContainerHeight,
graph,
this.sigmaInstance,
)();
}

// If the node is not expanded
Expand Down Expand Up @@ -286,44 +292,48 @@ class GraphHelper {
}

// Method for hovering off a node
hoverOffNode(node, graph, activeSelection=null) {
if (!this.sigmaInstance || typeof this.sigmaInstance.refresh !== "function") {
console.error("Sigma instance or refresh method not available in hoverOffNode");
return;
}
hoverOffNode(node, graph, activeSelection = null) {
if (
!this.sigmaInstance ||
typeof this.sigmaInstance.refresh !== "function"
) {
console.error(
"Sigma instance or refresh method not available in hoverOffNode",
);
return;
}

console.log(activeSelection)
// Get the selected nodes
const selectedDiseaseNode = activeSelection.disease;
const selectedAlleleNode = activeSelection.allele;

// Get the edges of the node
const nodeId = node;
const edges = graph.edges().filter((edge) => {
return graph.source(edge) === nodeId || graph.target(edge) === nodeId;
});

// Reset the color of the edges, but not for the selected edge
edges.forEach((edge) => {
const source = graph.source(edge);
const target = graph.target(edge);
const isSelectedEdge =
(source === selectedDiseaseNode && target === selectedAlleleNode) ||
(source === selectedAlleleNode && target === selectedDiseaseNode);
// Get the edges of the node
const nodeId = node;
const edges = graph.edges().filter((edge) => {
return graph.source(edge) === nodeId || graph.target(edge) === nodeId;
});

if (!isSelectedEdge) {
graph.setEdgeAttribute(edge, "color", "darkgrey");
}
});
// Reset the color of the edges, but not for the selected edge
edges.forEach((edge) => {
const source = graph.source(edge);
const target = graph.target(edge);
const isSelectedEdge =
(source === selectedDiseaseNode && target === selectedAlleleNode) ||
(source === selectedAlleleNode && target === selectedDiseaseNode);

if (!isSelectedEdge) {
graph.setEdgeAttribute(edge, "color", "darkgrey");
}
});

// Hide the edge source on hover
edges.forEach((edge) => {
this.hoverOffEdge(edge, this.graphManager.graph);
});
// Hide the edge source on hover
edges.forEach((edge) => {
this.hoverOffEdge(edge, this.graphManager.graph);
});

// Refresh the sigma instance
this.sigmaInstance.refresh();
}
// Refresh the sigma instance
this.sigmaInstance.refresh();
}

// Method for updating the graph with layout
applyLayout(graph) {
Expand Down Expand Up @@ -486,8 +496,6 @@ hoverOffNode(node, graph, activeSelection=null) {
// Get the source of the edge and the label of the source
const source = graph.source(edge);
const sourceLabel = graph.getNodeAttribute(source, "label");
console.log(source)
console.log(graph.getNodeAttribute(source, "node_type"))
if (graph.getNodeAttribute(source, "node_type") === "disease") {
const edgeLabel = `${sourceLabel}`;
graph.setEdgeAttribute(edge, "label", edgeLabel);
Expand Down

0 comments on commit e319a6a

Please sign in to comment.