1
- import { BoundingBox , Category , Edge , NetworkNode , Node , Position } from "@model" ;
1
+ import { BoundingBox , Category , Edge , NetworkNode , Node , NodeType , Position } from "@model" ;
2
2
3
3
export class DgmlManager {
4
4
@@ -74,15 +74,22 @@ export class DgmlManager {
74
74
const nodeInfoDictionary = Object . assign ( { } , ...nodeInfos . map ( ( nodeInfo ) => ( { [ nodeInfo . id ] : nodeInfo } ) ) ) ;
75
75
const nodesElement = this . addNodeToRoot ( xmlDoc , "Nodes" ) ;
76
76
const linksElement = this . addNodeToRoot ( xmlDoc , "Links" ) ;
77
+ const categoryDictionary : { [ nodeType : string ] : Category } = { } ;
77
78
nodes . forEach ( node => {
78
79
if ( node . id in nodeInfoDictionary ) {
79
80
this . enrichNode ( node , nodeInfoDictionary [ node . id ] ) ;
80
81
}
81
82
this . generateDirectedGraphNodesXml ( xmlDoc , node , nodesElement ) ;
83
+ const categoryId = NodeType [ node . nodeType ] ;
84
+ if ( ! ( categoryId in categoryDictionary ) ) {
85
+ categoryDictionary [ categoryId ] = new Category ( categoryId , categoryId , node . getNodeTypeColor ( node . nodeType ) ) ;
86
+ }
82
87
} ) ;
83
88
edges . forEach ( edge => {
84
89
this . generateDirectedGraphLinksXml ( xmlDoc , edge , linksElement ) ;
85
90
} ) ;
91
+ this . addCategoriesAndStyles ( xmlDoc , categoryDictionary ) ;
92
+ this . addProperties ( xmlDoc ) ;
86
93
}
87
94
88
95
private enrichNode ( node : Node , networkNode : NetworkNode ) {
@@ -105,6 +112,7 @@ export class DgmlManager {
105
112
nodeElement . setAttribute ( "Bounds" , this . calculateBounds ( node . position , node . boundingBox ) ) ;
106
113
nodeElement . setAttribute ( "UseManualLocation" , "True" ) ;
107
114
}
115
+ nodeElement . setAttribute ( "Category" , NodeType [ node . nodeType ] ) ;
108
116
if ( node . attributes && node . attributes . length > 0 ) {
109
117
node . attributes . forEach ( attribute => {
110
118
nodeElement . setAttribute ( attribute . name , attribute . value ) ;
@@ -134,20 +142,14 @@ export class DgmlManager {
134
142
}
135
143
}
136
144
137
- public addCategories ( xmlDoc : Document , categories : Category [ ] ) {
145
+ private addCategoriesAndStyles ( xmlDoc : Document , categories : { [ nodeType : string ] : Category } ) {
138
146
const categoriesElement = this . addNodeToRoot ( xmlDoc , "Categories" ) ;
139
- // const categoryElement = xmlDoc.createElement("Category");
140
- // categoryElement.setAttribute("Id", "RootComponent");
141
- // categoryElement.setAttribute("Label", "Root component");
142
- // // categoryElement.setAttribute("Background", this.config.rootNodeBackgroundColor);
143
- // categoryElement.setAttribute("IsTag", "True");
144
- // this.addNode(categoriesElement, categoryElement);
145
- categories . forEach ( category => {
146
- this . addCategory ( xmlDoc , categoriesElement , category ) ;
147
+ Object . keys ( categories ) . forEach ( nodeType => {
148
+ this . addCategory ( xmlDoc , categoriesElement , categories [ nodeType ] ) ;
147
149
} ) ;
148
150
}
149
151
150
- public addProperties ( xmlDoc : Document ) {
152
+ private addProperties ( xmlDoc : Document ) {
151
153
const propertiesElement = this . addNodeToRoot ( xmlDoc , "Properties" ) ;
152
154
this . addProperty ( xmlDoc , propertiesElement , "ComponentFilename" , "System.String" ) ;
153
155
this . addProperty ( xmlDoc , propertiesElement , "Background" , "System.Windows.Media.Brush" ) ;
@@ -169,7 +171,7 @@ export class DgmlManager {
169
171
this . addNode ( propertiesElement , propertyElement ) ;
170
172
}
171
173
172
- public addStyles ( xmlDoc : Document ) {
174
+ private addStyles ( xmlDoc : Document ) {
173
175
const stylesElement = this . addNodeToRoot ( xmlDoc , "Styles" ) ;
174
176
const styleElement = xmlDoc . createElement ( "Style" ) ;
175
177
styleElement . setAttribute ( "TargetType" , "Node" ) ;
0 commit comments