Skip to content

Commit 252f3e0

Browse files
committed
Adding a File icon to nodes in the generated dgml file.
1 parent e44b622 commit 252f3e0

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/dgmlManager.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class DgmlManager {
7373
}
7474
}
7575

76-
public addNodesAndLinks(xmlDoc: Document, nodes: Node[], nodeInfoDictionary: { [id: string]: NetworkNode}, edges: Edge[]) {
76+
public addNodesAndLinks(xmlDoc: Document, nodes: Node[], nodeInfoDictionary: { [id: string]: NetworkNode }, edges: Edge[]) {
7777
const nodesElement = this.addNodeToRoot(xmlDoc, "Nodes");
7878
const linksElement = this.addNodeToRoot(xmlDoc, "Links");
7979
const categoryDictionary: { [nodeType: string]: Category } = {};
@@ -84,13 +84,16 @@ export class DgmlManager {
8484
this.generateDirectedGraphNodesXml(xmlDoc, node, nodesElement);
8585
const categoryId = NodeType[node.nodeType];
8686
if (!(categoryId in categoryDictionary)) {
87-
categoryDictionary[categoryId] = new Category(categoryId, categoryId, node.getNodeTypeColor(node.nodeType), '');
87+
categoryDictionary[categoryId] = new Category(categoryId, categoryId, node.getNodeTypeColor(node.nodeType), '', '');
88+
}
89+
if (!('File' in categoryDictionary)) {
90+
categoryDictionary['File'] = new Category('File', '', '', '', 'File');
8891
}
8992
});
9093
edges.forEach(edge => {
9194
const categoryId = ArrowType[edge.arrowType];
9295
if (!(categoryId in categoryDictionary)) {
93-
categoryDictionary[categoryId] = new Category(categoryId, categoryId, '', edge.getEdgeTypeColor(edge.arrowType));
96+
categoryDictionary[categoryId] = new Category(categoryId, categoryId, '', edge.getEdgeTypeColor(edge.arrowType), '');
9497
}
9598
this.generateDirectedGraphLinksXml(xmlDoc, edge, linksElement);
9699
});
@@ -127,9 +130,10 @@ export class DgmlManager {
127130
if (node.tsFilename) {
128131
nodeElement.setAttribute("TypescriptFilepath", node.tsFilename);
129132
}
133+
this.addCategoryRef(xmlDoc, nodeElement, 'File');
130134
this.addNode(nodesElement, nodeElement);
131135
}
132-
136+
133137
private calculateBounds(position: Position, boundingBox: BoundingBox): string {
134138
const width = boundingBox.right - boundingBox.left;
135139
const height = boundingBox.bottom - boundingBox.top;
@@ -141,17 +145,28 @@ export class DgmlManager {
141145
this.addLinkNode(xmlDoc, linksElement, edge.source, edge.target, categoryId);
142146
}
143147

148+
private addCategoryRef(xmlDoc: Document, node: Element, categoryRef: string) {
149+
const categoryElement = xmlDoc.createElement("Category");
150+
categoryElement.setAttribute("Ref", categoryRef);
151+
node.appendChild(categoryElement);
152+
}
153+
144154
private addCategory(xmlDoc: Document, categoriesElement: Element | null, category: Category) {
145-
if (categoriesElement !== null && ( category.backgroundColor || category.stroke )) {
155+
if (categoriesElement !== null && (category.backgroundColor || category.stroke || category.icon)) {
146156
const categoryElement = xmlDoc.createElement("Category");
147157
categoryElement.setAttribute("Id", category.id);
148-
categoryElement.setAttribute("Label", category.label);
158+
if (category.label) {
159+
categoryElement.setAttribute("Label", category.label);
160+
}
149161
if (category.backgroundColor) {
150162
categoryElement.setAttribute("Background", category.backgroundColor);
151163
}
152164
if (category.stroke) {
153165
categoryElement.setAttribute("Stroke", category.stroke);
154166
}
167+
if (category.icon) {
168+
categoryElement.setAttribute("Icon", category.icon);
169+
}
155170
categoryElement.setAttribute("IsTag", "True");
156171
this.addNode(categoriesElement, categoryElement);
157172
}
@@ -180,7 +195,7 @@ export class DgmlManager {
180195
const propertyElement = xmlDoc.createElement("Property");
181196
propertyElement.setAttribute("Id", idValue);
182197
propertyElement.setAttribute("DataType", datatypeValue);
183-
if ( label !== undefined && label.length > 0) {
198+
if (label !== undefined && label.length > 0) {
184199
propertyElement.setAttribute("Label", label);
185200
}
186201
if (isReference !== undefined && isReference) {

src/model/Category.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11

22
export class Category {
33

4-
constructor(id: string, label: string, backGroundColor: string, stroke: string) {
4+
constructor(id: string, label: string, backGroundColor: string, stroke: string, icon: string) {
55
this.id = id;
66
this.label = label;
77
this.backgroundColor = backGroundColor;
88
this.stroke = stroke;
9+
this.icon = icon;
910
}
1011

1112
public id: string;
1213
public label: string;
1314
public backgroundColor: string;
1415
public stroke: string;
16+
public icon: string;
1517
}

0 commit comments

Comments
 (0)