Skip to content

Commit

Permalink
bug(common): include derived types in dependency graph (#90)
Browse files Browse the repository at this point in the history
* bug(common): include derived types in dependency graph

Signed-off-by: Sanket Shevkar <[email protected]>

* bug(common): include derived types in dependency graph

Signed-off-by: Sanket Shevkar <[email protected]>

---------

Signed-off-by: Sanket Shevkar <[email protected]>
Co-authored-by: Sanket Shevkar <[email protected]>
  • Loading branch information
sanketshevkar and Sanket Shevkar authored Feb 1, 2024
1 parent 14aeb8b commit 16d9d5a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 16 deletions.
20 changes: 17 additions & 3 deletions lib/common/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,22 @@ class DirectedGraph {
*/
print(writer) {
writer.writeLine(0, 'flowchart LR');
const diagramNodeSet = new Set();
Object.entries(this.adjacencyMap).forEach(([source, edges]) =>{
writer.writeLine(1, `\`${source}\``);
diagramNodeSet.add( `\`${source}\``);
(edges || []).forEach(target => {
writer.writeLine(1, `\`${source}\` --> \`${target}\``);
const setEntry = `\`${source}\` --> \`${target}\``;
if(diagramNodeSet.has(`\`${target}\` --> \`${source}\``)) {
diagramNodeSet.delete(`\`${target}\` --> \`${source}\``);
diagramNodeSet.add(`\`${source}\` <--> \`${target}\``);
} else {
diagramNodeSet.add(setEntry);
}
});
});
diagramNodeSet.forEach((diagramNode) => {
writer.writeLine(1, diagramNode);
});
}
}

Expand All @@ -174,8 +184,12 @@ class ConcertoGraphVisitor extends DiagramVisitor {

if (classDeclaration.getSuperType()){
parameters.graph.addEdge(classDeclaration.getFullyQualifiedName(), classDeclaration.getSuperType());
// this "if" block adds the types that extend the Super type
if(classDeclaration.getSuperType() !== '[email protected]') {
parameters.graph.addVertex(classDeclaration.getSuperType());
parameters.graph.addEdge(classDeclaration.getSuperType(), classDeclaration.getFullyQualifiedName());
}
}

super.visitClassDeclaration(classDeclaration, parameters);
parameters.stack.pop();
}
Expand Down
77 changes: 64 additions & 13 deletions test/common/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,39 +95,42 @@ describe('graph', function () {
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\`
\`[email protected]\`
`);
Expand All @@ -149,30 +152,78 @@ describe('graph', function () {
.filter(declaration => connectedGraph.hasVertex(declaration.getFullyQualifiedName()));

expect(filteredModelManager.getModelFiles()).toHaveLength(2);
expect(filteredModelManager.getModelFiles()[0].getAllDeclarations()).toHaveLength(3);
expect(filteredModelManager.getModelFiles()[0].getAllDeclarations()).toHaveLength(5);

writer.openFile('graph.mmd');
connectedGraph.print(writer);
writer.closeFile();
expect(writer.data.get('graph.mmd')).toEqual(`flowchart LR
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`String\`
\`[email protected]\`
\`[email protected]\` --> \`String\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`String\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\` --> \`[email protected]\`
\`[email protected]\`
\`[email protected]\` <--> \`[email protected]\`
\`[email protected]\`
\`[email protected]\`
`);
Expand Down

0 comments on commit 16d9d5a

Please sign in to comment.