Skip to content

Commit

Permalink
CELE-53 Fix neuron group not being removed from "visible" panel in 2D
Browse files Browse the repository at this point in the history
graph
  • Loading branch information
aranega committed Oct 11, 2024
1 parent f96340a commit eeff032
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const ContextMenu: React.FC<ContextMenuProps> = ({ open, onClose, position, setS
removeNodeFromGroup(cy, groupedNeuronId, true);
}
delete draft.neuronGroups[elementId]; // Delete the entire group
delete draft.visibilities[elementId];
if (openGroups.has(elementId)) {
groupsToRemoveFromOpen.add(elementId);
}
Expand Down
27 changes: 18 additions & 9 deletions applications/visualizer/frontend/src/helpers/twoD/groupHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import type { Core } from "cytoscape";
import type { NeuronGroup, Workspace } from "../../models";
import { SELECTED_CLASS } from "../../settings/twoDSettings.tsx";

const _incrementInt = () => {
let i = 0;
return () => {
i++;
return i;
};
};

const incrementInt = _incrementInt();

export const groupNeurons = (selectedNeurons: Set<string>, workspace: Workspace) => {
const newGroupId = `group_${Date.now()}`;
const newGroupId = `group_${incrementInt()}`;
const newGroupNeurons = new Set<string>();
const groupsToDelete = new Set<string>();
let originalGroupName = "";
Expand All @@ -16,24 +26,24 @@ export const groupNeurons = (selectedNeurons: Set<string>, workspace: Workspace)

// Check if the neuronId is a group itself or part of another group
if (group) {
group.neurons.forEach((groupedNeuronId) => {
for (const groupedNeuronId of group.neurons) {
newGroupNeurons.add(groupedNeuronId);
});
}
groupsToDelete.add(neuronId);
originalGroupName = group.name;
originalGroupColor = group.color;
} else {
Object.entries(workspace.neuronGroups).forEach(([groupId, existingGroup]) => {
for (const [groupId, existingGroup] of Object.entries(workspace.neuronGroups)) {
if (existingGroup.neurons.has(neuronId)) {
existingGroup.neurons.forEach((groupedNeuronId) => {
for (const groupedNeuronId of existingGroup.neurons) {
newGroupNeurons.add(groupedNeuronId);
});
}
groupsToDelete.add(groupId);
originalGroupName = existingGroup.name;
originalGroupColor = existingGroup.color;
isPartOfAnotherGroup = true;
}
});
}

// If neuronId is not part of any group, add it directly
if (!isPartOfAnotherGroup) {
Expand All @@ -48,15 +58,14 @@ export const groupNeurons = (selectedNeurons: Set<string>, workspace: Workspace)
name: originalGroupName || newGroupId,
color: originalGroupColor,
neurons: newGroupNeurons,
visible: true,
};

return { newGroupId, newGroup, groupsToDelete };
};

export function removeNodeFromGroup(cy: Core, nodeId: string, setSelected: boolean) {
const cyNode = cy.getElementById(nodeId);
if (cyNode && cyNode.isNode()) {
if (cyNode?.isNode()) {
cyNode.move({ parent: null });
if (setSelected) {
cyNode.addClass(SELECTED_CLASS);
Expand Down
1 change: 0 additions & 1 deletion applications/visualizer/frontend/src/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface NeuronGroup {
name: string;
color: string;
neurons: Set<string>;
visible: boolean;
}

export interface GraphViewerData {
Expand Down

0 comments on commit eeff032

Please sign in to comment.