@@ -38,7 +38,7 @@ export class DgmlParser {
38
38
const children : IXmlNode [ ] = obj . root . children as IXmlNode [ ] ;
39
39
children . forEach ( xmlNode => {
40
40
if ( xmlNode . name !== undefined && xmlNode . name . toLowerCase ( ) === 'nodes' ) {
41
- directedGraph . nodes = this . convertXmlToNodes ( xmlNode . children ) ;
41
+ directedGraph . nodes = this . convertXmlToNodes ( xmlNode . children , filename ) ;
42
42
} else if ( xmlNode . name !== undefined && xmlNode . name . toLowerCase ( ) === 'links' ) {
43
43
directedGraph . links = this . convertXmlToLinks ( xmlNode . children ) ;
44
44
} else if ( xmlNode . name !== undefined && xmlNode . name . toLowerCase ( ) === 'categories' ) {
@@ -52,6 +52,7 @@ export class DgmlParser {
52
52
this . addStylingToCategories ( directedGraph ) ;
53
53
this . addCategoryStylingToNodes ( directedGraph ) ;
54
54
this . addCategoryStylingToLinks ( directedGraph ) ;
55
+ this . enrichNodes ( directedGraph ) ;
55
56
}
56
57
return directedGraph ;
57
58
}
@@ -68,47 +69,59 @@ export class DgmlParser {
68
69
return dictKeysCopy ;
69
70
}
70
71
71
- private convertXmlToNodes ( xmlNodes : IXmlNode [ ] ) : Node [ ] {
72
+ private convertXmlToNodes ( xmlNodes : IXmlNode [ ] , filename : string ) : Node [ ] {
72
73
const nodes : Node [ ] = [ ] ;
73
74
if ( xmlNodes . length > 0 ) {
74
75
xmlNodes . forEach ( xmlNode => {
75
76
if ( xmlNode . attributes !== undefined ) {
77
+ const newNode = new Node ( filename ) ;
76
78
const attributesCopy : { [ key : string ] : string } = this . toLowercaseDictionary ( xmlNode . attributes ) ;
77
- const newNode = new Node ( ) ;
78
- newNode . id = attributesCopy [ 'id' ] ;
79
- newNode . category = attributesCopy [ 'category' ] ;
80
- newNode . description = attributesCopy [ 'description' ] ;
81
- newNode . reference = attributesCopy [ 'reference' ] ;
82
- newNode . isVertical = attributesCopy [ 'isvertical' ] !== undefined ? attributesCopy [ 'isvertical' ] === 'true' : undefined ;
83
- newNode . group = attributesCopy [ 'group' ] ;
84
- newNode . label = attributesCopy [ 'label' ] ;
85
- newNode . visibility = attributesCopy [ 'visibility' ] ;
86
- newNode . background = attributesCopy [ 'background' ] ;
87
- newNode . fontSize = attributesCopy [ 'fontsize' ] !== undefined ? + attributesCopy [ 'fontsize' ] : undefined ;
88
- newNode . fontFamily = attributesCopy [ 'fontfamily' ] ;
89
- newNode . fontStyle = attributesCopy [ 'fontstyle' ] ;
90
- newNode . fontWeight = attributesCopy [ 'fontweight' ] ;
91
- newNode . stroke = attributesCopy [ 'stroke' ] ;
92
- newNode . strokeThickness = attributesCopy [ 'strokethickness' ] ;
93
- newNode . strokeDashArray = attributesCopy [ 'strokedasharray' ] ;
94
- newNode . icon = attributesCopy [ 'icon' ] ;
95
- newNode . shape = attributesCopy [ 'shape' ] ;
96
- newNode . style = attributesCopy [ 'style' ] ;
97
- newNode . horizontalAlignment = attributesCopy [ 'horizontalalignment' ] ;
98
- newNode . verticalAlignment = attributesCopy [ 'verticalalignment' ] ;
99
- newNode . minWidth = attributesCopy [ 'minwidth' ] !== undefined ? + attributesCopy [ 'minwidth' ] : undefined ;
100
- newNode . maxWidth = attributesCopy [ 'maxwidth' ] !== undefined ? + attributesCopy [ 'maxwidth' ] : undefined ;
101
- newNode . nodeRadius = attributesCopy [ 'noderadius' ] !== undefined ? + attributesCopy [ 'noderadius' ] : undefined ;
79
+ newNode . id = this . getAttributeValue ( attributesCopy , 'id' ) ;
80
+ newNode . category = this . getAttributeValue ( attributesCopy , 'category' ) ;
81
+ newNode . description = this . getAttributeValue ( attributesCopy , 'description' ) ;
82
+ newNode . reference = this . getAttributeValue ( attributesCopy , 'reference' ) ;
83
+ const isVertical = this . getAttributeValue ( attributesCopy , 'isvertical' ) ;
84
+ newNode . isVertical = isVertical !== undefined ? isVertical === 'true' : undefined ;
85
+ newNode . group = this . getAttributeValue ( attributesCopy , 'group' ) ;
86
+ newNode . label = this . getAttributeValue ( attributesCopy , 'label' ) ;
87
+ newNode . visibility = this . getAttributeValue ( attributesCopy , 'visibility' ) ;
88
+ newNode . background = this . getAttributeValue ( attributesCopy , 'background' ) ;
89
+ const fontsize = this . getAttributeValue ( attributesCopy , 'fontsize' ) ;
90
+ newNode . fontSize = fontsize !== undefined ? + fontsize : undefined ;
91
+ newNode . fontFamily = this . getAttributeValue ( attributesCopy , 'fontfamily' ) ;
92
+ newNode . fontStyle = this . getAttributeValue ( attributesCopy , 'fontstyle' ) ;
93
+ newNode . fontWeight = this . getAttributeValue ( attributesCopy , 'fontweight' ) ;
94
+ newNode . stroke = this . getAttributeValue ( attributesCopy , 'stroke' ) ;
95
+ newNode . strokeThickness = this . getAttributeValue ( attributesCopy , 'strokethickness' ) ;
96
+ newNode . strokeDashArray = this . getAttributeValue ( attributesCopy , 'strokedasharray' ) ;
97
+ newNode . icon = this . getAttributeValue ( attributesCopy , 'icon' ) ;
98
+ newNode . shape = this . getAttributeValue ( attributesCopy , 'shape' ) ;
99
+ newNode . style = this . getAttributeValue ( attributesCopy , 'style' ) ;
100
+ newNode . horizontalAlignment = this . getAttributeValue ( attributesCopy , 'horizontalalignment' ) ;
101
+ newNode . verticalAlignment = this . getAttributeValue ( attributesCopy , 'verticalalignment' ) ;
102
+ const minWidth = this . getAttributeValue ( attributesCopy , 'minwidth' ) ;
103
+ newNode . minWidth = minWidth !== undefined ? + minWidth : undefined ;
104
+ const maxWidth = this . getAttributeValue ( attributesCopy , 'maxwidth' ) ;
105
+ newNode . maxWidth = maxWidth !== undefined ? + maxWidth : undefined ;
106
+ const nodeRadius = this . getAttributeValue ( attributesCopy , 'noderadius' ) ;
107
+ newNode . nodeRadius = nodeRadius !== undefined ? + nodeRadius : undefined ;
102
108
if ( newNode . category === undefined ) {
103
109
newNode . category = this . createCategoryRef ( xmlNode ) ;
104
110
}
105
- if ( attributesCopy [ 'bounds' ] !== undefined && attributesCopy [ 'bounds' ] . indexOf ( ',' ) !== - 1 ) {
106
- const bounds = attributesCopy [ 'bounds' ] . split ( ',' ) ;
111
+ const boundsValue = this . getAttributeValue ( attributesCopy , 'bounds' ) ;
112
+ if ( boundsValue !== undefined && boundsValue . indexOf ( ',' ) !== - 1 ) {
113
+ const bounds = boundsValue . split ( ',' ) ;
107
114
newNode . boundsX = + bounds [ 0 ] ;
108
115
newNode . boundsY = + bounds [ 1 ] ;
109
116
newNode . boundsWidth = + bounds [ 2 ] ;
110
117
newNode . boundsHeight = + bounds [ 3 ] ;
111
118
}
119
+ const additionalProperties = Object . keys ( attributesCopy ) ;
120
+ if ( additionalProperties . length > 0 ) {
121
+ additionalProperties . forEach ( property => {
122
+ newNode . properties . push ( { id : property , value : attributesCopy [ property ] } ) ;
123
+ } ) ;
124
+ }
112
125
if ( nodes . filter ( n => n . id === newNode . id ) . length === 0 ) {
113
126
nodes . push ( newNode ) ;
114
127
}
@@ -118,6 +131,12 @@ export class DgmlParser {
118
131
return nodes ;
119
132
}
120
133
134
+ private getAttributeValue ( attributes : { [ key : string ] : string } , attributeName : string ) : string {
135
+ const value = attributes [ attributeName ] ;
136
+ delete attributes [ attributeName ] ;
137
+ return value ;
138
+ }
139
+
121
140
private convertXmlToLinks ( xmlNodes : IXmlNode [ ] ) : Link [ ] {
122
141
const links : Link [ ] = [ ] ;
123
142
if ( xmlNodes . length > 0 ) {
@@ -129,7 +148,7 @@ export class DgmlParser {
129
148
newLink . target = attributesCopy [ 'target' ] ;
130
149
newLink . label = attributesCopy [ 'label' ] ;
131
150
newLink . category = attributesCopy [ 'category' ] ;
132
- newLink . visibility = attributesCopy [ 'visibility' ] !== undefined ? attributesCopy [ 'visibility' ] === 'hidden' : false ;
151
+ newLink . visibility = attributesCopy [ 'visibility' ] !== undefined ? attributesCopy [ 'visibility' ] . toLowerCase ( ) === 'hidden' : false ;
133
152
newLink . background = attributesCopy [ 'background' ] ;
134
153
newLink . fontSize = attributesCopy [ 'fontsize' ] !== undefined ? + attributesCopy [ 'fontsize' ] : undefined ;
135
154
newLink . fontFamily = attributesCopy [ 'fontfamily' ] ;
@@ -139,7 +158,7 @@ export class DgmlParser {
139
158
newLink . strokeThickness = attributesCopy [ 'strokethickness' ] ;
140
159
newLink . strokeDashArray = attributesCopy [ 'strokedasharray' ] ;
141
160
newLink . seeder = attributesCopy [ 'seeder' ] !== undefined ? attributesCopy [ 'seeder' ] === 'true' : undefined ;
142
- newLink . attractConsumers = attributesCopy [ 'attractconsumers' ] !== undefined ? attributesCopy [ 'attractconsumers' ] === 'true' : undefined ;
161
+ newLink . attractConsumers = attributesCopy [ 'attractconsumers' ] !== undefined ? attributesCopy [ 'attractconsumers' ] . toLowerCase ( ) === 'true' : undefined ;
143
162
if ( newLink . category === undefined ) {
144
163
newLink . category = this . createCategoryRef ( xmlNode ) ;
145
164
}
@@ -176,8 +195,8 @@ export class DgmlParser {
176
195
canBeDataDriven : attributesCopy [ 'canbedatadriven' ] ,
177
196
defaultAction : attributesCopy [ 'defaultaction' ] ,
178
197
incomingActionLabel : attributesCopy [ 'incomingactionlabel' ] ,
179
- isProviderRoot : attributesCopy [ 'isproviderroot' ] !== undefined ? attributesCopy [ 'isproviderroot' ] === 'true' : undefined ,
180
- isContainment : attributesCopy [ 'iscontainment' ] !== undefined ? attributesCopy [ 'iscontainment' ] === 'true' : undefined ,
198
+ isProviderRoot : attributesCopy [ 'isproviderroot' ] !== undefined ? attributesCopy [ 'isproviderroot' ] . toLowerCase ( ) === 'true' : undefined ,
199
+ isContainment : attributesCopy [ 'iscontainment' ] !== undefined ? attributesCopy [ 'iscontainment' ] . toLowerCase ( ) === 'true' : undefined ,
181
200
isTag : attributesCopy [ 'istag' ] !== undefined ? attributesCopy [ 'istag' ] === 'true' : undefined ,
182
201
navigationActionLabel : attributesCopy [ 'navigationactionlabel' ] ,
183
202
outgoingActionLabel : attributesCopy [ 'outgoingactionlabel' ] ,
@@ -220,7 +239,7 @@ export class DgmlParser {
220
239
const attributesCopy : { [ key : string ] : string } = this . toLowercaseDictionary ( xmlNode . attributes ) ;
221
240
const newProperty = {
222
241
id : attributesCopy [ 'id' ] ,
223
- isReference : attributesCopy [ 'isreference' ] !== undefined ? attributesCopy [ 'isreference' ] === 'true' : undefined ,
242
+ isReference : attributesCopy [ 'isreference' ] !== undefined ? attributesCopy [ 'isreference' ] . toLowerCase ( ) === 'true' : undefined ,
224
243
label : attributesCopy [ 'label' ] ,
225
244
dataType : attributesCopy [ 'datatype' ] ,
226
245
description : attributesCopy [ 'description' ] ,
@@ -242,7 +261,7 @@ export class DgmlParser {
242
261
const attributesCopy : { [ key : string ] : string } = this . toLowercaseDictionary ( xmlNode . attributes ) ;
243
262
const newProperty = {
244
263
targetType : attributesCopy [ 'targettype' ] ,
245
- isEnabled : attributesCopy [ 'isenabled' ] !== undefined ? attributesCopy [ 'isenabled' ] === 'true' : undefined ,
264
+ isEnabled : attributesCopy [ 'isenabled' ] !== undefined ? attributesCopy [ 'isenabled' ] . toLowerCase ( ) === 'true' : undefined ,
246
265
groupLabel : attributesCopy [ 'grouplabel' ] ,
247
266
valueLabel : attributesCopy [ 'valuelabel' ] ,
248
267
toolTip : attributesCopy [ 'tooltip' ] ,
@@ -388,4 +407,17 @@ export class DgmlParser {
388
407
} ) ;
389
408
}
390
409
}
410
+
411
+ private enrichNodes ( directedGraph : IDirectedGraph ) : void {
412
+ directedGraph . properties . forEach ( property => {
413
+ directedGraph . nodes . forEach ( node => {
414
+ if ( node . properties . length > 0 ) {
415
+ const existingPropertyIdx = node . properties . findIndex ( nodeProperty => nodeProperty . id . toLowerCase ( ) === property . id . toLowerCase ( ) ) ;
416
+ if ( existingPropertyIdx !== - 1 ) {
417
+ Object . assign ( node . properties [ existingPropertyIdx ] , property ) ;
418
+ }
419
+ }
420
+ } ) ;
421
+ } ) ;
422
+ }
391
423
}
0 commit comments