Skip to content

Commit 9e5fb5c

Browse files
committed
First attempt at saving the node positions to the dot file.
1 parent 9e72714 commit 9e5fb5c

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/commands/showHierarchyBase.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ export class ShowHierarchyBase extends CommandBase {
112112
}
113113

114114
protected saveAsGraphViz(graphVizFilename: string, messageText: string, graphType: string, popMessageText: string) {
115+
const message = JSON.parse(messageText);
115116
const graphVizManager = new GraphVizManager();
116-
const fileContent = graphVizManager.createGraphVizDiagram(graphType, this.nodes, this.edges);
117+
const fileContent = graphVizManager.createGraphVizDiagram(graphType, this.nodes, message.nodes, this.edges);
117118

118119
// Write the prettified xml string to the ReadMe-ProjectStructure.dgml file.
119120
var directoryPath: string = this.fsUtils.getWorkspaceFolder();

src/graphvizManager.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
import { Edge, Node } from "@model";
1+
import { Edge, NetworkNode, Node, Position } from "@model";
22

33
export class GraphVizManager {
44

5-
public createGraphVizDiagram(graphType: string, nodes: Node[], edges: Edge[]): string {
5+
public createGraphVizDiagram(graphType: string, nodes: Node[], nodeInfoDictionary: { [id: string]: NetworkNode }, edges: Edge[]): string {
6+
const maxX = Math.max(...Object.keys(nodeInfoDictionary).map(id => nodeInfoDictionary[id].position.x));
7+
const minX = Math.min(...Object.keys(nodeInfoDictionary).map(id => nodeInfoDictionary[id].position.x));
8+
const diffX = Math.max(...[Math.abs(maxX),Math.abs(minX)]);
9+
const maxY = Math.max(...Object.keys(nodeInfoDictionary).map(id => nodeInfoDictionary[id].position.y));
10+
const minY = Math.min(...Object.keys(nodeInfoDictionary).map(id => nodeInfoDictionary[id].position.y));
11+
const diffY = Math.max(...[Math.abs(maxY),Math.abs(minY)]);
12+
13+
nodes.forEach(node => {
14+
if(node.id in nodeInfoDictionary){
15+
const networkNode = nodeInfoDictionary[node.id];
16+
if (networkNode.label) {
17+
node.name = networkNode.label;
18+
}
19+
if (node.id in nodeInfoDictionary) {
20+
node.position = {x: Math.round(((networkNode.position.x + diffX) / maxX) * nodes.length), y: Math.round(((networkNode.position.y + diffY) / maxY) * nodes.length)};
21+
}
22+
}
23+
});
624
const digraphNodes = this.generateDigraphNodes(nodes);
725
const digraphEdges = this.generateDigraphEdges(edges);
826
const graphVizDigraph = this.addRootNode(graphType, digraphNodes, digraphEdges);

src/model/Node.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ export class Node {
5656
const regex = /\W/g;
5757
const id = this.id.replace(regex, '_');
5858
const attributes: string[] = [];
59-
attributes.push(`label="${this.name}"`);
59+
const label = this.config.maximumNodeLabelLength !== -1 && this.name.length > this.config.maximumNodeLabelLength ? this.name.substr(0, this.config.maximumNodeLabelLength) + '...' : this.name;
60+
attributes.push(`label="${label}"`);
6061
const color = this.getNodeTypeColor(this.nodeType);
6162
if (color) {
6263
attributes.push(`color="${color}"`);
6364
attributes.push(`style="filled"`);
6465
}
66+
if (this.position !== undefined) {
67+
const x = this.position.x;
68+
const y = this.position.y;
69+
attributes.push(`pos="${x},${y}!"`);
70+
}
6571
let attributesStr: string = '';
6672
if (attributes.length > 0) {
6773
attributesStr = ` [${attributes.join(', ')}]`;

0 commit comments

Comments
 (0)