@@ -106,7 +106,8 @@ import {
106106 LEGEND_LIVE ,
107107 LEGEND_INLINE ,
108108 LEGEND_SERIES ,
109- LEGEND_MARKER ,
109+ LEGEND_MARKERR ,
110+ LEGEND_MARKERL ,
110111 LEGEND_LABEL ,
111112 LEGEND_VALUE ,
112113} from './domClasses' ;
@@ -614,6 +615,32 @@ export default function uPlot(opts, data, then) {
614615 const son = { show : true } ;
615616 const soff = { show : false } ;
616617
618+ function placeMarker ( seriesIndex , label , before ) {
619+ const svgProp = series [ seriesIndex ] . points . form . svg ;
620+
621+ const svgURI = 'http://www.w3.org/2000/svg' ;
622+ const svg = document . createElementNS ( svgURI , 'svg' ) ;
623+ svg . classList . add ( before ? LEGEND_MARKERL : LEGEND_MARKERR ) ;
624+ const path = document . createElementNS ( svgURI , 'path' ) ;
625+ label . appendChild ( svg ) ;
626+ svg . appendChild ( path ) ;
627+ path . setAttribute ( 'd' , svgProp . path ) ;
628+
629+ const width = markers . width ( self , seriesIndex ) ;
630+ const dw = ceil ( width / 2 ) ;
631+ const vb = svgProp . viewBox ;
632+ // Adapting the viewBox to the stroke's width
633+ svg . setAttribute ( 'viewBox' , ( vb . minX - dw ) + ' ' + ( vb . minY - dw ) + ' ' + ( vb . width + 2 * dw ) + ' ' + ( vb . height + 2 * dw ) ) ;
634+ if ( width ) {
635+ path . setAttribute ( 'stroke-width' , width ) ;
636+ path . setAttribute ( 'stroke' , markers . stroke ( self , seriesIndex ) ) ;
637+ const dash = markers . dash ( self , seriesIndex ) ;
638+ if ( dash != 'solid' ) path . setAttribute ( 'stroke-dasharray' , Array . isArray ( dash ) ? dash . join ( ' ' ) : '35 15' ) ;
639+ }
640+ const fill = markers . fill ( self , seriesIndex ) ;
641+ path . setAttribute ( 'fill' , fill == null ? transparent : fill ) ;
642+ }
643+
617644 function initLegendRow ( s , i ) {
618645 if ( i == 0 && ( multiValLegend || ! legend . live || mode == 2 ) )
619646 return nullNullTuple ;
@@ -629,20 +656,9 @@ export default function uPlot(opts, data, then) {
629656
630657 let label = placeTag ( "th" , null , row ) ;
631658
632- if ( markers . show ) {
633- let indic = placeDiv ( LEGEND_MARKER , label ) ;
634-
635- if ( i > 0 ) {
636- let width = markers . width ( self , i ) ;
637-
638- if ( width )
639- indic . style . border = width + "px " + markers . dash ( self , i ) + " " + markers . stroke ( self , i ) ;
640-
641- indic . style . background = markers . fill ( self , i ) ;
642- }
643- }
644-
659+ if ( markers . show && markers . before && i > 0 ) placeMarker ( i , label , true ) ;
645660 let text = placeDiv ( LEGEND_LABEL , label ) ;
661+ if ( markers . show && ! markers . before && i > 0 ) placeMarker ( i , label , false ) ;
646662
647663 if ( s . label instanceof HTMLElement )
648664 text . appendChild ( s . label ) ;
0 commit comments