Skip to content

Commit e0817df

Browse files
committed
When edges have the same source and target the edges no longer overlap.
1 parent fe3104d commit e0817df

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/commands/showHierarchyBase.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ShowHierarchyBase extends CommandBase {
2525
protected showHierarchyCssFilename: string = 'showHierarchy.css';
2626
protected fontAwesomeCssFilename: string = 'all.min.css';
2727
protected fontAwesomeFontFilename: string = '../webfonts/fa-';
28-
28+
2929
protected workspaceDirectory = this.fsUtils.getWorkspaceFolder();
3030

3131
constructor(context: vscode.ExtensionContext, graphState: GraphState, setNewState: (newGraphState: GraphState) => any) {
@@ -49,6 +49,11 @@ export class ShowHierarchyBase extends CommandBase {
4949
};
5050
protected appendEdges = (edgeList: Edge[]) => {
5151
edgeList.forEach(newEdge => {
52+
const mutualEdges = this.edges.filter(edge => edge.target === newEdge.source && edge. source=== newEdge.target);
53+
if (mutualEdges.length > 0) {
54+
newEdge.mutualEdgeCount += 1;
55+
mutualEdges.forEach(e => e.mutualEdgeCount += 1 );
56+
}
5257
if (!this.edges.some(edge => edge.source === newEdge.source && edge.target === newEdge.target)) {
5358
this.edges.push(newEdge);
5459
}
@@ -171,7 +176,7 @@ export class ShowHierarchyBase extends CommandBase {
171176
var regex = new RegExp(this.fontAwesomeFontFilename, "g");
172177
cssFileContent = cssFileContent.replace(regex, fontPathUri.toString());
173178
const newCssFilename = 'all.vscode.min.css';
174-
this.fsUtils.writeFile(this.extensionContext?.asAbsolutePath(path.join('stylesheet', newCssFilename)), cssFileContent, () => {});
179+
this.fsUtils.writeFile(this.extensionContext?.asAbsolutePath(path.join('stylesheet', newCssFilename)), cssFileContent, () => { });
175180
return newCssFilename;
176181
}
177182

src/model/Edge.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@ export class Edge {
1313
public source: string;
1414
public target: string;
1515
public arrowType: ArrowType;
16+
public mutualEdgeCount: number = 1;
1617

1718
public toJsonString(): string {
1819
let arrowColorAttr = `, color: "${this.getEdgeTypeColor(this.arrowType)}"`;
19-
return `{from: "${this.source}", to: "${this.target}", arrows: arrowAttr${arrowColorAttr} }`;
20+
const jsStringProperties: string[] = [
21+
`from: "${this.source}"`,
22+
`to: "${this.target}"`,
23+
`arrows: arrowAttr${arrowColorAttr}`
24+
];
25+
if (this.mutualEdgeCount > 1) {
26+
jsStringProperties.push(`smooth: {type: 'curvedCW', roundness: 0.2}`);
27+
} else {
28+
jsStringProperties.push(`smooth: false`);
29+
}
30+
return `{${jsStringProperties.join(', ')}}`;
2031
}
2132

2233
public toGraphViz(): string {

templates/showHierarchy_Template.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
edges: edges
2222
};
2323
let options = {
24-
edges: {
25-
smooth: false // Make edges straight lines.
26-
},
2724
nodes: {
2825
font: { multi: 'html' },
2926
shape: 'box' // The shape of the nodes.

0 commit comments

Comments
 (0)