@@ -273,8 +273,16 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
273
273
lineContainer . enter ( ) . append ( 'g' )
274
274
. classed ( 'contourlines' , true ) ;
275
275
276
+ var showLines = contours . showlines !== false ;
277
+ var showLabels = contours . showlabels ;
278
+ var clipLinesForLabels = showLines && showLabels ;
279
+
280
+ // Even if we're not going to show lines, we need to create them
281
+ // if we're showing labels, because the fill paths include the perimeter
282
+ // so can't be used to position the labels correctly.
283
+ // In this case we'll remove the lines after making the labels.
276
284
var linegroup = lineContainer . selectAll ( 'g.contourlevel' )
277
- . data ( contours . showlines === false ? [ ] : pathinfo ) ;
285
+ . data ( showLines || showLabels ? pathinfo : [ ] ) ;
278
286
linegroup . enter ( ) . append ( 'g' )
279
287
. classed ( 'contourlevel' , true ) ;
280
288
linegroup . exit ( ) . remove ( ) ;
@@ -303,11 +311,10 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
303
311
. style ( 'stroke-miterlimit' , 1 )
304
312
. style ( 'vector-effect' , 'non-scaling-stroke' ) ;
305
313
306
- var showLabels = contours . showlabels ;
307
- var clipId = showLabels ? 'clipline' + cd0 . trace . uid : null ;
314
+ var clipId = clipLinesForLabels ? 'clipline' + cd0 . trace . uid : null ;
308
315
309
316
var lineClip = defs . select ( '.clips' ) . selectAll ( '#' + clipId )
310
- . data ( showLabels ? [ 0 ] : [ ] ) ;
317
+ . data ( clipLinesForLabels ? [ 0 ] : [ ] ) ;
311
318
lineClip . exit ( ) . remove ( ) ;
312
319
313
320
lineClip . enter ( ) . append ( 'clipPath' )
@@ -440,11 +447,14 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
440
447
. call ( Drawing . font , contours . font . family , contours . font . size ) ;
441
448
} ) ;
442
449
443
- var lineClipPath = lineClip . selectAll ( 'path' ) . data ( [ 0 ] ) ;
444
- lineClipPath . enter ( ) . append ( 'path' ) ;
445
- lineClipPath . attr ( 'd' , labelClipPathData ) ;
450
+ if ( clipLinesForLabels ) {
451
+ var lineClipPath = lineClip . selectAll ( 'path' ) . data ( [ 0 ] ) ;
452
+ lineClipPath . enter ( ) . append ( 'path' ) ;
453
+ lineClipPath . attr ( 'd' , labelClipPathData ) ;
454
+ }
446
455
}
447
456
457
+ if ( showLabels && ! showLines ) linegroup . remove ( ) ;
448
458
}
449
459
450
460
function straightClosedPath ( pts ) {
0 commit comments