@@ -2,94 +2,93 @@ import { ArrowType } from "@model";
22import { Config } from "@src" ;
33
44export class Edge {
5- private config : Config = new Config ( ) ;
6- constructor ( id : string , source : string , target : string , arrowType : ArrowType = ArrowType . none ) {
7- this . id = id ;
8- this . source = source ;
9- this . target = target ;
10- this . arrowType = arrowType ;
11- }
12- public id : string ;
13- public source : string ;
14- public target : string ;
15- public arrowType : ArrowType ;
16- public mutualEdgeCount : number = 1 ;
17- public showPopupsOverNodesAndEdges : boolean = true ;
18-
19- public toJsonString ( ) : string {
20- let arrowColorAttr = `, color: "${ this . getEdgeTypeColor ( this . arrowType ) } "` ;
21- const jsStringProperties : string [ ] = [
22- `from: "${ this . source } "` ,
23- `to: "${ this . target } "` ,
24- `arrows: arrowAttr${ arrowColorAttr } `
25- ] ;
26- if ( this . mutualEdgeCount > 1 ) {
27- jsStringProperties . push ( `smooth: {type: 'curvedCW', roundness: 0.2}` ) ;
28- } else {
29- jsStringProperties . push ( `smooth: false` ) ;
30- }
31- if ( this . showPopupsOverNodesAndEdges ) {
32- switch ( this . arrowType ) {
33- case ArrowType . injectable :
34- jsStringProperties . push ( `title: "${ this . source } injected into ${ this . target } "` ) ;
35- break ;
36- case ArrowType . import :
37- jsStringProperties . push ( `title: "${ this . target } imports ${ this . source } "` ) ;
38- break ;
39- case ArrowType . export :
40- jsStringProperties . push ( `title: "${ this . source } exports ${ this . target } "` ) ;
41- break ;
42- case ArrowType . uses :
43- jsStringProperties . push ( `title: "${ this . source } uses ${ this . target } "` ) ;
44- break ;
45- case ArrowType . route :
46- jsStringProperties . push ( `title: "${ this . source } routes to ${ this . target } "` ) ;
47- break ;
48- default :
49- break ;
50- }
5+ private config : Config = new Config ( ) ;
6+ constructor ( id : string , source : string , target : string , arrowType : ArrowType = ArrowType . none ) {
7+ this . id = id ;
8+ this . source = source ;
9+ this . target = target ;
10+ this . arrowType = arrowType ;
5111 }
52- return `{${ jsStringProperties . join ( ', ' ) } }` ;
53- }
12+ public id : string ;
13+ public source : string ;
14+ public target : string ;
15+ public arrowType : ArrowType ;
16+ public mutualEdgeCount : number = 1 ;
17+ public showPopupsOverNodesAndEdges : boolean = true ;
5418
55- public toGraphViz ( ) : string {
56- const regex = / \W / g;
57- const source = this . source . replace ( regex , '_' ) ;
58- const target = this . target . replace ( regex , '_' ) ;
59- const attributes : string [ ] = [ ] ;
60- const color = this . getEdgeTypeColor ( this . arrowType ) ;
61- if ( color ) {
62- attributes . push ( `color="${ color } "` ) ;
19+ public toJsonString ( ) : string {
20+ let arrowColorAttr = `, color: "${ this . getEdgeTypeColor ( this . arrowType ) } "` ;
21+ const jsStringProperties : string [ ] = [
22+ `from: "${ this . source } "` ,
23+ `to: "${ this . target } "` ,
24+ `arrows: arrowAttr${ arrowColorAttr } `
25+ ] ;
26+ if ( this . mutualEdgeCount > 1 ) {
27+ jsStringProperties . push ( `smooth: {type: 'curvedCW', roundness: 0.2}` ) ;
28+ } else {
29+ jsStringProperties . push ( `smooth: false` ) ;
30+ }
31+ if ( this . showPopupsOverNodesAndEdges ) {
32+ const title = this . getEdgeTitle ( ) ;
33+ jsStringProperties . push ( `title: "${ title } "` ) ;
34+ }
35+ return `{${ jsStringProperties . join ( ', ' ) } }` ;
6336 }
64- let attributesStr : string = '' ;
65- if ( attributes . length > 0 ) {
66- attributesStr = ` [${ attributes . join ( ', ' ) } ]` ;
37+
38+ public toGraphViz ( ) : string {
39+ const regex = / \W / g;
40+ const source = this . source . replace ( regex , '_' ) ;
41+ const target = this . target . replace ( regex , '_' ) ;
42+ const attributes : string [ ] = [ ] ;
43+ const color = this . getEdgeTypeColor ( this . arrowType ) ;
44+ if ( color ) {
45+ attributes . push ( `color="${ color } "` ) ;
46+ }
47+ let attributesStr : string = '' ;
48+ if ( attributes . length > 0 ) {
49+ attributesStr = ` [${ attributes . join ( ', ' ) } ]` ;
50+ }
51+ return `${ source } -> ${ target } ${ attributesStr } ;` ;
6752 }
68- return `${ source } -> ${ target } ${ attributesStr } ;` ;
69- }
7053
71- public getEdgeTypeColor ( arrowType : ArrowType ) : string {
72- let edgeTypeColor = '' ;
73- switch ( arrowType ) {
74- case ArrowType . import :
75- edgeTypeColor = this . config . importEdgeColor ;
76- break ;
77- case ArrowType . export :
78- edgeTypeColor = this . config . exportEdgeColor ;
79- break ;
80- case ArrowType . injectable :
81- edgeTypeColor = this . config . injectableEdgeColor ;
82- break ;
83- case ArrowType . uses :
84- edgeTypeColor = this . config . usesEdgeColor ;
85- break ;
86- case ArrowType . route :
87- edgeTypeColor = this . config . routeEdgeColor ;
88- break ;
89- default :
90- edgeTypeColor = '' ;
91- break ;
54+ public getEdgeTypeColor ( arrowType : ArrowType ) : string {
55+ let edgeTypeColor = '' ;
56+ switch ( arrowType ) {
57+ case ArrowType . import :
58+ edgeTypeColor = this . config . importEdgeColor ;
59+ break ;
60+ case ArrowType . export :
61+ edgeTypeColor = this . config . exportEdgeColor ;
62+ break ;
63+ case ArrowType . injectable :
64+ edgeTypeColor = this . config . injectableEdgeColor ;
65+ break ;
66+ case ArrowType . uses :
67+ edgeTypeColor = this . config . usesEdgeColor ;
68+ break ;
69+ case ArrowType . route :
70+ edgeTypeColor = this . config . routeEdgeColor ;
71+ break ;
72+ default :
73+ edgeTypeColor = '' ;
74+ break ;
75+ }
76+ return edgeTypeColor ;
77+ }
78+ public getEdgeTitle ( ) {
79+ switch ( this . arrowType ) {
80+ case ArrowType . import :
81+ return `${ this . target } imports ${ this . source } ` ;
82+ case ArrowType . export :
83+ return `${ this . target } exports ${ this . source } ` ;
84+ case ArrowType . injectable :
85+ return `${ this . source } injected into ${ this . target } ` ;
86+ case ArrowType . uses :
87+ return `${ this . target } uses ${ this . source } ` ;
88+ case ArrowType . route :
89+ return `${ this . target } routes to ${ this . source } ` ;
90+ default :
91+ return '' ;
92+ }
9293 }
93- return edgeTypeColor ;
94- }
9594}
0 commit comments