Skip to content

Commit 7931626

Browse files
committed
Adding label to links in generated dgml file. Fixed TsFilename path in generated dgml file.
1 parent 145cccd commit 7931626

File tree

3 files changed

+97
-91
lines changed

3 files changed

+97
-91
lines changed

src/commands/generateDependencyInjectionGraph.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,22 @@ export class GenerateDependencyInjectionGraph extends ShowHierarchyBase {
126126

127127
private addNamedEntityNodeAndEdges(namedEntityMap: Map<string, Component | NamedEntity>, noteType: NodeType, arrowType: ArrowType) {
128128
namedEntityMap.forEach(namedEntity => {
129-
let namedEntityFilename = namedEntity.filename.replace(this.workspaceDirectory, '.');
130-
namedEntityFilename = namedEntityFilename.split('\\').join('/');
131129
const entityPosition = this.graphState.nodePositions[namedEntity.name];
132-
this.appendNodes([new Node(namedEntity.name, this.getNodeLabel(namedEntity), namedEntityFilename, namedEntity.filename, false, noteType, entityPosition)]);
130+
this.appendNodes([new Node(namedEntity.name, this.getNodeLabel(namedEntity), this.fixTsFilename(namedEntity.filename), namedEntity.filename, false, noteType, entityPosition)]);
133131
namedEntity.dependencies.forEach(dependency => {
134132
const dependencyPosition = this.graphState.nodePositions[dependency.name];
135-
this.appendNodes([new Node(dependency.name, dependency.name, dependency.filename.replace(this.workspaceDirectory, ''), dependency.filename, false, NodeType.injectable, dependencyPosition)]);
133+
this.appendNodes([new Node(dependency.name, dependency.name, this.fixTsFilename(dependency.filename), dependency.filename, false, NodeType.injectable, dependencyPosition)]);
136134
this.appendEdges([new Edge((this.edges.length + 1).toString(), dependency.name, namedEntity.name, arrowType)]);
137135
});
138136
});
139137
}
140138

139+
private fixTsFilename(filename: string): string {
140+
let entityFilename = filename.replace(this.workspaceDirectory, '.');
141+
entityFilename = entityFilename.split('\\').join('/');
142+
return entityFilename;
143+
}
144+
141145
private generateJavascriptContent(nodesJson: string, edgesJson: string) {
142146
let template = fs.readFileSync(this.extensionContext?.asAbsolutePath(path.join('templates', this.templateJsFilename)), 'utf8');
143147
let jsContent = template.replace('const nodes = new vis.DataSet([]);', `var nodes = new vis.DataSet([${nodesJson}]);`);

src/dgmlManager.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class DgmlManager {
4848
}
4949
}
5050

51-
private addLinkNode(xmlDoc: Document, element: Element | null, source: string, target: string, categoryId: string) {
51+
private addLinkNode(xmlDoc: Document, element: Element | null, source: string, target: string, categoryId: string, label: string | undefined) {
5252
if (element !== null) {
5353
let nodeAlreadyAdded = false;
5454
if (element.childNodes.length > 0) {
@@ -68,6 +68,9 @@ export class DgmlManager {
6868
linkElement.setAttribute("Source", source);
6969
linkElement.setAttribute("Target", target);
7070
linkElement.setAttribute("Category", categoryId);
71+
if (label !== undefined) {
72+
linkElement.setAttribute("Label", label);
73+
}
7174
element.appendChild(linkElement);
7275
}
7376
}
@@ -84,7 +87,7 @@ export class DgmlManager {
8487
this.generateDirectedGraphNodesXml(xmlDoc, node, nodesElement);
8588
const categoryId = NodeType[node.nodeType];
8689
if (!(categoryId in categoryDictionary)) {
87-
categoryDictionary[categoryId] = new Category(categoryId, categoryId, node.getNodeTypeColor(node.nodeType), '', '');
90+
categoryDictionary[categoryId] = new Category(categoryId, node.getNodeTypeTitle(), node.getNodeTypeColor(node.nodeType), '', '');
8891
}
8992
if (!('File' in categoryDictionary)) {
9093
categoryDictionary['File'] = new Category('File', '', '', '', 'File');
@@ -142,7 +145,7 @@ export class DgmlManager {
142145

143146
private generateDirectedGraphLinksXml(xmlDoc: Document, edge: Edge, linksElement: Element | null) {
144147
const categoryId = ArrowType[edge.arrowType];
145-
this.addLinkNode(xmlDoc, linksElement, edge.source, edge.target, categoryId);
148+
this.addLinkNode(xmlDoc, linksElement, edge.source, edge.target, categoryId, edge.getEdgeTitle());
146149
}
147150

148151
private addCategoryRef(xmlDoc: Document, node: Element, categoryRef: string) {

src/model/Edge.ts

Lines changed: 83 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,93 @@ import { ArrowType } from "@model";
22
import { Config } from "@src";
33

44
export class Edge {
5-
private config: Config = new Config();
6-
constructor(id: string, source: string, target: string, arrowType: ArrowType = ArrowType.none) {
7-
this.id = id;
8-
this.source = source;
9-
this.target = target;
10-
this.arrowType = arrowType;
11-
}
12-
public id: string;
13-
public source: string;
14-
public target: string;
15-
public arrowType: ArrowType;
16-
public mutualEdgeCount: number = 1;
17-
public showPopupsOverNodesAndEdges: boolean = true;
18-
19-
public toJsonString(): string {
20-
let arrowColorAttr = `, color: "${this.getEdgeTypeColor(this.arrowType)}"`;
21-
const jsStringProperties: string[] = [
22-
`from: "${this.source}"`,
23-
`to: "${this.target}"`,
24-
`arrows: arrowAttr${arrowColorAttr}`
25-
];
26-
if (this.mutualEdgeCount > 1) {
27-
jsStringProperties.push(`smooth: {type: 'curvedCW', roundness: 0.2}`);
28-
} else {
29-
jsStringProperties.push(`smooth: false`);
30-
}
31-
if (this.showPopupsOverNodesAndEdges) {
32-
switch (this.arrowType) {
33-
case ArrowType.injectable:
34-
jsStringProperties.push(`title: "${this.source} injected into ${this.target}"`);
35-
break;
36-
case ArrowType.import:
37-
jsStringProperties.push(`title: "${this.target} imports ${this.source}"`);
38-
break;
39-
case ArrowType.export:
40-
jsStringProperties.push(`title: "${this.source} exports ${this.target}"`);
41-
break;
42-
case ArrowType.uses:
43-
jsStringProperties.push(`title: "${this.source} uses ${this.target}"`);
44-
break;
45-
case ArrowType.route:
46-
jsStringProperties.push(`title: "${this.source} routes to ${this.target}"`);
47-
break;
48-
default:
49-
break;
50-
}
5+
private config: Config = new Config();
6+
constructor(id: string, source: string, target: string, arrowType: ArrowType = ArrowType.none) {
7+
this.id = id;
8+
this.source = source;
9+
this.target = target;
10+
this.arrowType = arrowType;
5111
}
52-
return `{${jsStringProperties.join(', ')}}`;
53-
}
12+
public id: string;
13+
public source: string;
14+
public target: string;
15+
public arrowType: ArrowType;
16+
public mutualEdgeCount: number = 1;
17+
public showPopupsOverNodesAndEdges: boolean = true;
5418

55-
public toGraphViz(): string {
56-
const regex = /\W/g;
57-
const source = this.source.replace(regex, '_');
58-
const target = this.target.replace(regex, '_');
59-
const attributes: string[] = [];
60-
const color = this.getEdgeTypeColor(this.arrowType);
61-
if (color) {
62-
attributes.push(`color="${color}"`);
19+
public toJsonString(): string {
20+
let arrowColorAttr = `, color: "${this.getEdgeTypeColor(this.arrowType)}"`;
21+
const jsStringProperties: string[] = [
22+
`from: "${this.source}"`,
23+
`to: "${this.target}"`,
24+
`arrows: arrowAttr${arrowColorAttr}`
25+
];
26+
if (this.mutualEdgeCount > 1) {
27+
jsStringProperties.push(`smooth: {type: 'curvedCW', roundness: 0.2}`);
28+
} else {
29+
jsStringProperties.push(`smooth: false`);
30+
}
31+
if (this.showPopupsOverNodesAndEdges) {
32+
const title = this.getEdgeTitle();
33+
jsStringProperties.push(`title: "${title}"`);
34+
}
35+
return `{${jsStringProperties.join(', ')}}`;
6336
}
64-
let attributesStr: string = '';
65-
if (attributes.length > 0) {
66-
attributesStr = ` [${attributes.join(', ')}]`;
37+
38+
public toGraphViz(): string {
39+
const regex = /\W/g;
40+
const source = this.source.replace(regex, '_');
41+
const target = this.target.replace(regex, '_');
42+
const attributes: string[] = [];
43+
const color = this.getEdgeTypeColor(this.arrowType);
44+
if (color) {
45+
attributes.push(`color="${color}"`);
46+
}
47+
let attributesStr: string = '';
48+
if (attributes.length > 0) {
49+
attributesStr = ` [${attributes.join(', ')}]`;
50+
}
51+
return `${source} -> ${target}${attributesStr};`;
6752
}
68-
return `${source} -> ${target}${attributesStr};`;
69-
}
7053

71-
public getEdgeTypeColor(arrowType: ArrowType): string {
72-
let edgeTypeColor = '';
73-
switch (arrowType) {
74-
case ArrowType.import:
75-
edgeTypeColor = this.config.importEdgeColor;
76-
break;
77-
case ArrowType.export:
78-
edgeTypeColor = this.config.exportEdgeColor;
79-
break;
80-
case ArrowType.injectable:
81-
edgeTypeColor = this.config.injectableEdgeColor;
82-
break;
83-
case ArrowType.uses:
84-
edgeTypeColor = this.config.usesEdgeColor;
85-
break;
86-
case ArrowType.route:
87-
edgeTypeColor = this.config.routeEdgeColor;
88-
break;
89-
default:
90-
edgeTypeColor = '';
91-
break;
54+
public getEdgeTypeColor(arrowType: ArrowType): string {
55+
let edgeTypeColor = '';
56+
switch (arrowType) {
57+
case ArrowType.import:
58+
edgeTypeColor = this.config.importEdgeColor;
59+
break;
60+
case ArrowType.export:
61+
edgeTypeColor = this.config.exportEdgeColor;
62+
break;
63+
case ArrowType.injectable:
64+
edgeTypeColor = this.config.injectableEdgeColor;
65+
break;
66+
case ArrowType.uses:
67+
edgeTypeColor = this.config.usesEdgeColor;
68+
break;
69+
case ArrowType.route:
70+
edgeTypeColor = this.config.routeEdgeColor;
71+
break;
72+
default:
73+
edgeTypeColor = '';
74+
break;
75+
}
76+
return edgeTypeColor;
77+
}
78+
public getEdgeTitle() {
79+
switch (this.arrowType) {
80+
case ArrowType.import:
81+
return `${this.target} imports ${this.source}`;
82+
case ArrowType.export:
83+
return `${this.target} exports ${this.source}`;
84+
case ArrowType.injectable:
85+
return `${this.source} injected into ${this.target}`;
86+
case ArrowType.uses:
87+
return `${this.target} uses ${this.source}`;
88+
case ArrowType.route:
89+
return `${this.target} routes to ${this.source}`;
90+
default:
91+
return '';
92+
}
9293
}
93-
return edgeTypeColor;
94-
}
9594
}

0 commit comments

Comments
 (0)