@@ -15,28 +15,29 @@ export const addEdgeMarkers = (
15
15
edge : Pick < EdgeData , 'arrowTypeStart' | 'arrowTypeEnd' > ,
16
16
url : string ,
17
17
id : string ,
18
- diagramType : string
18
+ diagramType : string ,
19
+ strokeColor ?: string
19
20
) => {
20
21
if ( edge . arrowTypeStart ) {
21
- addEdgeMarker ( svgPath , 'start' , edge . arrowTypeStart , url , id , diagramType ) ;
22
+ addEdgeMarker ( svgPath , 'start' , edge . arrowTypeStart , url , id , diagramType , strokeColor ) ;
22
23
}
23
24
if ( edge . arrowTypeEnd ) {
24
- addEdgeMarker ( svgPath , 'end' , edge . arrowTypeEnd , url , id , diagramType ) ;
25
+ addEdgeMarker ( svgPath , 'end' , edge . arrowTypeEnd , url , id , diagramType , strokeColor ) ;
25
26
}
26
27
} ;
27
28
28
29
const arrowTypesMap = {
29
- arrow_cross : 'cross' ,
30
- arrow_point : 'point' ,
31
- arrow_barb : 'barb' ,
32
- arrow_circle : 'circle' ,
33
- aggregation : 'aggregation' ,
34
- extension : 'extension' ,
35
- composition : 'composition' ,
36
- dependency : 'dependency' ,
37
- lollipop : 'lollipop' ,
38
- requirement_arrow : 'requirement_arrow' ,
39
- requirement_contains : 'requirement_contains' ,
30
+ arrow_cross : { type : 'cross' , fill : false } ,
31
+ arrow_point : { type : 'point' , fill : true } ,
32
+ arrow_barb : { type : 'barb' , fill : true } ,
33
+ arrow_circle : { type : 'circle' , fill : false } ,
34
+ aggregation : { type : 'aggregation' , fill : false } ,
35
+ extension : { type : 'extension' , fill : false } ,
36
+ composition : { type : 'composition' , fill : true } ,
37
+ dependency : { type : 'dependency' , fill : true } ,
38
+ lollipop : { type : 'lollipop' , fill : false } ,
39
+ requirement_arrow : { type : 'requirement_arrow' , fill : false } ,
40
+ requirement_contains : { type : 'requirement_contains' , fill : false } ,
40
41
} as const ;
41
42
42
43
const addEdgeMarker = (
@@ -45,15 +46,55 @@ const addEdgeMarker = (
45
46
arrowType : string ,
46
47
url : string ,
47
48
id : string ,
48
- diagramType : string
49
+ diagramType : string ,
50
+ strokeColor ?: string
49
51
) => {
50
- const endMarkerType = arrowTypesMap [ arrowType as keyof typeof arrowTypesMap ] ;
52
+ const arrowTypeInfo = arrowTypesMap [ arrowType as keyof typeof arrowTypesMap ] ;
51
53
52
- if ( ! endMarkerType ) {
54
+ if ( ! arrowTypeInfo ) {
53
55
log . warn ( `Unknown arrow type: ${ arrowType } ` ) ;
54
56
return ; // unknown arrow type, ignore
55
57
}
56
58
59
+ const endMarkerType = arrowTypeInfo . type ;
57
60
const suffix = position === 'start' ? 'Start' : 'End' ;
58
- svgPath . attr ( `marker-${ position } ` , `url(${ url } #${ id } _${ diagramType } -${ endMarkerType } ${ suffix } )` ) ;
61
+ const originalMarkerId = `${ id } _${ diagramType } -${ endMarkerType } ${ suffix } ` ;
62
+
63
+ // If stroke color is specified and non-empty, create or use a colored variant of the marker
64
+ if ( strokeColor && strokeColor . trim ( ) !== '' ) {
65
+ // Create a sanitized color value for use in IDs
66
+ const colorId = strokeColor . replace ( / [ ^ \d A - Z a - z ] / g, '_' ) ;
67
+ const coloredMarkerId = `${ originalMarkerId } _${ colorId } ` ;
68
+
69
+ // Check if the colored marker already exists
70
+ if ( ! document . getElementById ( coloredMarkerId ) ) {
71
+ // Get the original marker
72
+ const originalMarker = document . getElementById ( originalMarkerId ) ;
73
+ if ( originalMarker ) {
74
+ // Clone the marker and create colored version
75
+ const coloredMarker = originalMarker . cloneNode ( true ) as Element ;
76
+ coloredMarker . id = coloredMarkerId ;
77
+
78
+ // Apply colors to the paths inside the marker
79
+ const paths = coloredMarker . querySelectorAll ( 'path, circle, line' ) ;
80
+ paths . forEach ( ( path ) => {
81
+ path . setAttribute ( 'stroke' , strokeColor ) ;
82
+
83
+ // Apply fill only to markers that should be filled
84
+ if ( arrowTypeInfo . fill ) {
85
+ path . setAttribute ( 'fill' , strokeColor ) ;
86
+ }
87
+ } ) ;
88
+
89
+ // Add the new colored marker to the defs section
90
+ originalMarker . parentNode ?. appendChild ( coloredMarker ) ;
91
+ }
92
+ }
93
+
94
+ // Use the colored marker
95
+ svgPath . attr ( `marker-${ position } ` , `url(${ url } #${ coloredMarkerId } )` ) ;
96
+ } else {
97
+ // Always use the original marker for unstyled edges
98
+ svgPath . attr ( `marker-${ position } ` , `url(${ url } #${ originalMarkerId } )` ) ;
99
+ }
59
100
} ;
0 commit comments