@@ -65,12 +65,20 @@ function markerCircleStroke(color) {
6565
6666let nextMarkerId = 0 ;
6767
68- export function applyMarkers ( path , { markerStart, markerMid, markerEnd} ) {
69- if ( ! ( markerStart || markerMid || markerEnd ) ) return ;
68+ export function applyMarkers ( path , mark , { stroke : S } ) {
69+ return applyMarkersColor ( path , mark , S && ( i => S [ i ] ) ) ;
70+ }
71+
72+ export function applyGroupedMarkers ( path , mark , { stroke : S } ) {
73+ return applyMarkersColor ( path , mark , S && ( ( [ i ] ) => S [ i ] ) ) ;
74+ }
75+
76+ function applyMarkersColor ( path , { markerStart, markerMid, markerEnd, stroke} , strokeof = ( ) => stroke ) {
7077 const iriByMarkerColor = new Map ( ) ;
71- path . each ( function ( ) {
72- const color = this . getAttribute ( "stroke" ) ;
73- const applyMarker = ( name , marker ) => {
78+
79+ function applyMarker ( marker ) {
80+ return function ( i ) {
81+ const color = strokeof ( i ) ;
7482 let iriByColor = iriByMarkerColor . get ( marker ) ;
7583 if ( ! iriByColor ) iriByMarkerColor . set ( marker , iriByColor = new Map ( ) ) ;
7684 let iri = iriByColor . get ( color ) ;
@@ -80,10 +88,11 @@ export function applyMarkers(path, {markerStart, markerMid, markerEnd}) {
8088 node . setAttribute ( "id" , id ) ;
8189 iriByColor . set ( color , iri = `url(#${ id } )` ) ;
8290 }
83- this . setAttribute ( name , iri ) ;
91+ return iri ;
8492 } ;
85- if ( markerStart ) applyMarker ( "marker-start" , markerStart ) ;
86- if ( markerMid ) applyMarker ( "marker-mid" , markerMid ) ;
87- if ( markerEnd ) applyMarker ( "marker-end" , markerEnd ) ;
88- } ) ;
93+ }
94+
95+ if ( markerStart ) path . attr ( "marker-start" , applyMarker ( markerStart ) ) ;
96+ if ( markerMid ) path . attr ( "marker-mid" , applyMarker ( markerMid ) ) ;
97+ if ( markerEnd ) path . attr ( "marker-end" , applyMarker ( markerEnd ) ) ;
8998}
0 commit comments