Skip to content

Commit

Permalink
Enable dashboard to update token nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverStolzBO committed Jun 10, 2024
1 parent da3eaf5 commit 28b81ef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/src/code_visualization/element_creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const loopTree = (
* @param fileString a JSON string containing the graph objects
* @returns an array containing all existing nodes and edges in the dotfile
*/
const parseElementsFromDotFileString = (
export const parseElementsFromDotFileString = (
fileString: any,
standaloneTesting = false
) => {
Expand Down
47 changes: 44 additions & 3 deletions client/src/code_visualization/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { setupCytoscapeInstance } from './setup_cytoscape';
import { setupEventHandlers } from './event_handler';
import { createGraph } from './graph_creation';
import { rotateNodes } from './context_menu';
import { parseElementsFromDotFileString } from './element_creation';

const cytoscapeDiv = document.getElementById('cy');
if (cytoscapeDiv) {
Expand All @@ -14,14 +15,14 @@ if (cytoscapeDiv) {

// create the graph
createGraph(cy, null);

// global function to enable the dashboard in the standalone browser version to access the cytoscape instance
(window as any).getCy = function () {
return cy;
};

// global function used to update the dashboard in the standalone browser version
(window as any).createCodeVisualization = async function (
parsedDotfile = null
) {
(window as any).createCodeVisualization = function (parsedDotfile = null) {
cy.elements().remove();
createGraph(cy, parsedDotfile);
const imgElement = document.getElementById('codeVisuImg');
Expand All @@ -30,4 +31,44 @@ if (cytoscapeDiv) {
rotateNodes(cy.nodes(), cy.nodes('.container'), false);
}
};

// global function for the dashboard in the standalone browser version to enable the comparison of two dotfiles
(window as any).getElementsFromDotfile = function (dotfile) {
return parseElementsFromDotFileString(dotfile);
};

(window as any).flipTokensForNodeIds = function (nodeIds) {
nodeIds.forEach((id) => {
const node = cy.getElementById(id);
const tokenNode = cy.getElementById(id + '_token');
if (tokenNode.length && tokenNode.inside()) {
// node had a token before, remove it
const newParentId = tokenNode.data('parent');
node.data('label', '');
node.move({ parent: newParentId });
node.classes(['single_node', 'upper_round_node']);
tokenNode.remove();
} else {
if (tokenNode.removed()) {
tokenNode.restore();
} else {
// create a new token node for the object
const newTokenNode = {
group: 'nodes',
classes: ['upper_round_node', 'token_label'],
data: {
id: id + '_token',
label: '',
tippyContent: node.label,
parent: node.parentId
}
};
cy.add(newTokenNode);
}
node.data('label', '•');
node.move({ parent: node.id + '_token' });
node.classes(['single_node', 'token_node']);
}
});
};
}

0 comments on commit 28b81ef

Please sign in to comment.