@@ -63,8 +63,8 @@ exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) {
6363
6464 var fillPathinfo = pathinfo ;
6565 if ( contours . type === 'constraint' ) {
66+ // N.B. this also mutates pathinfo
6667 fillPathinfo = convertToConstraints ( pathinfo , contours . _operation ) ;
67- closeBoundaries ( fillPathinfo , contours . _operation , perimeter , trace ) ;
6868 }
6969
7070 // draw everything
@@ -88,10 +88,17 @@ function makeBackground(plotgroup, perimeter, contours) {
8888}
8989
9090function makeFills ( plotgroup , pathinfo , perimeter , contours ) {
91+ var hasFills = contours . coloring === 'fill' || ( contours . type === 'constraint' && contours . _operation !== '=' ) ;
92+ var boundaryPath = 'M' + perimeter . join ( 'L' ) + 'Z' ;
93+
94+ // fills prefixBoundary in pathinfo items
95+ if ( hasFills ) {
96+ closeBoundaries ( pathinfo , contours ) ;
97+ }
98+
9199 var fillgroup = Lib . ensureSingle ( plotgroup , 'g' , 'contourfill' ) ;
92100
93- var fillitems = fillgroup . selectAll ( 'path' )
94- . data ( contours . coloring === 'fill' || ( contours . type === 'constraint' && contours . _operation !== '=' ) ? pathinfo : [ ] ) ;
101+ var fillitems = fillgroup . selectAll ( 'path' ) . data ( hasFills ? pathinfo : [ ] ) ;
95102 fillitems . enter ( ) . append ( 'path' ) ;
96103 fillitems . exit ( ) . remove ( ) ;
97104 fillitems . each ( function ( pi ) {
@@ -100,30 +107,21 @@ function makeFills(plotgroup, pathinfo, perimeter, contours) {
100107 // if the whole perimeter is above this level, start with a path
101108 // enclosing the whole thing. With all that, the parity should mean
102109 // that we always fill everything above the contour, nothing below
103- var fullpath = joinAllPaths ( pi , perimeter ) ;
110+ var fullpath = ( pi . prefixBoundary ? boundaryPath : '' ) +
111+ joinAllPaths ( pi , perimeter ) ;
104112
105- if ( ! fullpath ) d3 . select ( this ) . remove ( ) ;
106- else d3 . select ( this ) . attr ( 'd' , fullpath ) . style ( 'stroke' , 'none' ) ;
113+ if ( ! fullpath ) {
114+ d3 . select ( this ) . remove ( ) ;
115+ } else {
116+ d3 . select ( this )
117+ . attr ( 'd' , fullpath )
118+ . style ( 'stroke' , 'none' ) ;
119+ }
107120 } ) ;
108121}
109122
110- function initFullPath ( pi , perimeter ) {
111- var prefixBoundary = pi . prefixBoundary ;
112- if ( prefixBoundary === undefined ) {
113- var edgeVal2 = Math . min ( pi . z [ 0 ] [ 0 ] , pi . z [ 0 ] [ 1 ] ) ;
114- prefixBoundary = ( ! pi . edgepaths . length && edgeVal2 > pi . level ) ;
115- }
116-
117- if ( prefixBoundary ) {
118- // TODO: why does ^^ not work for constraints?
119- // pi.prefixBoundary gets set by closeBoundaries
120- return 'M' + perimeter . join ( 'L' ) + 'Z' ;
121- }
122- return '' ;
123- }
124-
125123function joinAllPaths ( pi , perimeter ) {
126- var fullpath = initFullPath ( pi , perimeter ) ;
124+ var fullpath = '' ;
127125 var i = 0 ;
128126 var startsleft = pi . edgepaths . map ( function ( v , i ) { return i ; } ) ;
129127 var newloop = true ;
@@ -612,17 +610,18 @@ exports.drawLabels = function(labelGroup, labelData, gd, lineClip, labelClipPath
612610} ;
613611
614612function clipGaps ( plotGroup , plotinfo , gd , cd0 , perimeter ) {
613+ var trace = cd0 . trace ;
615614 var clips = gd . _fullLayout . _clips ;
616- var clipId = 'clip' + cd0 . trace . uid ;
615+ var clipId = 'clip' + trace . uid ;
617616
618617 var clipPath = clips . selectAll ( '#' + clipId )
619- . data ( cd0 . trace . connectgaps ? [ ] : [ 0 ] ) ;
618+ . data ( trace . connectgaps ? [ ] : [ 0 ] ) ;
620619 clipPath . enter ( ) . append ( 'clipPath' )
621620 . classed ( 'contourclip' , true )
622621 . attr ( 'id' , clipId ) ;
623622 clipPath . exit ( ) . remove ( ) ;
624623
625- if ( cd0 . trace . connectgaps === false ) {
624+ if ( trace . connectgaps === false ) {
626625 var clipPathInfo = {
627626 // fraction of the way from missing to present point
628627 // to draw the boundary.
@@ -644,10 +643,13 @@ function clipGaps(plotGroup, plotinfo, gd, cd0, perimeter) {
644643
645644 makeCrossings ( [ clipPathInfo ] ) ;
646645 findAllPaths ( [ clipPathInfo ] ) ;
647- var fullpath = joinAllPaths ( clipPathInfo , perimeter ) ;
646+ closeBoundaries ( [ clipPathInfo ] , { type : 'levels' } ) ;
648647
649648 var path = Lib . ensureSingle ( clipPath , 'path' , '' ) ;
650- path . attr ( 'd' , fullpath ) ;
649+ path . attr ( 'd' ,
650+ ( clipPathInfo . prefixBoundary ? 'M' + perimeter . join ( 'L' ) + 'Z' : '' ) +
651+ joinAllPaths ( clipPathInfo , perimeter )
652+ ) ;
651653 } else clipId = null ;
652654
653655 Drawing . setClipUrl ( plotGroup , clipId , gd ) ;
0 commit comments