@@ -6,12 +6,13 @@ import {
6
6
ICategory ,
7
7
ICondition ,
8
8
IDirectedGraph ,
9
- Link ,
10
- Node ,
9
+ IPath ,
11
10
IProperty ,
12
11
ISetter ,
13
12
IStyle ,
14
- IXmlNode
13
+ IXmlNode ,
14
+ Link ,
15
+ Node
15
16
} from '@model' ;
16
17
17
18
export class DgmlParser {
@@ -47,6 +48,8 @@ export class DgmlParser {
47
48
directedGraph . properties = this . convertXmlToProperties ( xmlNode . children ) ;
48
49
} else if ( xmlNode . name !== undefined && xmlNode . name . toLowerCase ( ) === 'styles' ) {
49
50
directedGraph . styles = this . convertXmlToStyles ( xmlNode . children ) ;
51
+ } else if ( xmlNode . name !== undefined && xmlNode . name . toLowerCase ( ) === 'paths' ) {
52
+ directedGraph . paths = this . convertXmlToPaths ( xmlNode . children ) ;
50
53
}
51
54
} ) ;
52
55
this . addStylingToCategories ( directedGraph ) ;
@@ -99,6 +102,7 @@ export class DgmlParser {
99
102
newNode . style = this . getAttributeValue ( attributesCopy , 'style' ) ;
100
103
newNode . horizontalAlignment = this . getAttributeValue ( attributesCopy , 'horizontalalignment' ) ;
101
104
newNode . verticalAlignment = this . getAttributeValue ( attributesCopy , 'verticalalignment' ) ;
105
+ newNode . filePath = this . getAttributeValue ( attributesCopy , 'filepath' ) ;
102
106
const minWidth = this . getAttributeValue ( attributesCopy , 'minwidth' ) ;
103
107
newNode . minWidth = minWidth !== undefined ? + minWidth : undefined ;
104
108
const maxWidth = this . getAttributeValue ( attributesCopy , 'maxwidth' ) ;
@@ -116,10 +120,10 @@ export class DgmlParser {
116
120
newNode . boundsWidth = + bounds [ 2 ] ;
117
121
newNode . boundsHeight = + bounds [ 3 ] ;
118
122
}
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
+ const customProperties = Object . keys ( attributesCopy ) ;
124
+ if ( customProperties . length > 0 ) {
125
+ customProperties . forEach ( property => {
126
+ newNode . customProperties . push ( { id : property , value : attributesCopy [ property ] } ) ;
123
127
} ) ;
124
128
}
125
129
if ( nodes . filter ( n => n . id === newNode . id ) . length === 0 ) {
@@ -275,6 +279,23 @@ export class DgmlParser {
275
279
return styles ;
276
280
}
277
281
282
+ private convertXmlToPaths ( xmlNodes : IXmlNode [ ] ) : IPath [ ] {
283
+ const paths : IPath [ ] = [ ] ;
284
+ if ( xmlNodes . length > 0 ) {
285
+ xmlNodes . forEach ( xmlNode => {
286
+ if ( xmlNode . attributes !== undefined ) {
287
+ const attributesCopy : { [ key : string ] : string } = this . toLowercaseDictionary ( xmlNode . attributes ) ;
288
+ const newProperty = {
289
+ id : attributesCopy [ 'id' ] ,
290
+ value : attributesCopy [ 'value' ] ,
291
+ } as IPath ;
292
+ paths . push ( newProperty ) ;
293
+ }
294
+ } ) ;
295
+ }
296
+ return paths ;
297
+ }
298
+
278
299
private createCondition ( xmlNode : IXmlNode ) : ICondition | undefined {
279
300
let condition : ICondition | undefined = undefined ;
280
301
if ( xmlNode . children !== undefined ) {
@@ -409,15 +430,31 @@ export class DgmlParser {
409
430
}
410
431
411
432
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 ( ) ) ;
433
+ directedGraph . nodes . forEach ( node => {
434
+ if ( node . filePath !== undefined ) {
435
+ node . filePath = this . replacePaths ( node . filePath , directedGraph ) ;
436
+ }
437
+ if ( node . customProperties !== undefined && node . customProperties . length > 0 ) {
438
+ directedGraph . properties . forEach ( property => {
439
+ const existingPropertyIdx = node . customProperties . findIndex ( nodeProperty => nodeProperty . id . toLowerCase ( ) === property . id . toLowerCase ( ) ) ;
416
440
if ( existingPropertyIdx !== - 1 ) {
417
- Object . assign ( node . properties [ existingPropertyIdx ] , property ) ;
441
+ Object . assign ( node . customProperties [ existingPropertyIdx ] , property ) ;
442
+ if ( node . customProperties [ existingPropertyIdx ] . isReference ) {
443
+ node . customProperties [ existingPropertyIdx ] . value = this . replacePaths ( node . customProperties [ existingPropertyIdx ] . value , directedGraph ) ;
444
+ }
418
445
}
419
- }
420
- } ) ;
446
+ } ) ;
447
+ }
421
448
} ) ;
422
449
}
450
+
451
+ private replacePaths ( filePath : string | undefined , directedGraph : IDirectedGraph ) : string | undefined {
452
+ let fixedFilepath = filePath ;
453
+ if ( fixedFilepath !== undefined && directedGraph . paths !== undefined && directedGraph . paths . length > 0 ) {
454
+ directedGraph . paths . forEach ( path => {
455
+ fixedFilepath = fixedFilepath ?. replace ( `\$(${ path . id } )` , path . value ) ;
456
+ } ) ;
457
+ }
458
+ return fixedFilepath ;
459
+ }
423
460
}
0 commit comments