Skip to content

Commit 99f39f8

Browse files
committed
allow contour labels even without lines
1 parent 6299303 commit 99f39f8

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/traces/contour/plot.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,16 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
273273
lineContainer.enter().append('g')
274274
.classed('contourlines', true);
275275

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.
276284
var linegroup = lineContainer.selectAll('g.contourlevel')
277-
.data(contours.showlines === false ? [] : pathinfo);
285+
.data(showLines || showLabels ? pathinfo : []);
278286
linegroup.enter().append('g')
279287
.classed('contourlevel', true);
280288
linegroup.exit().remove();
@@ -303,11 +311,10 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
303311
.style('stroke-miterlimit', 1)
304312
.style('vector-effect', 'non-scaling-stroke');
305313

306-
var showLabels = contours.showlabels;
307-
var clipId = showLabels ? 'clipline' + cd0.trace.uid : null;
314+
var clipId = clipLinesForLabels ? 'clipline' + cd0.trace.uid : null;
308315

309316
var lineClip = defs.select('.clips').selectAll('#' + clipId)
310-
.data(showLabels ? [0] : []);
317+
.data(clipLinesForLabels ? [0] : []);
311318
lineClip.exit().remove();
312319

313320
lineClip.enter().append('clipPath')
@@ -440,11 +447,14 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
440447
.call(Drawing.font, contours.font.family, contours.font.size);
441448
});
442449

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+
}
446455
}
447456

457+
if(showLabels && !showLines) linegroup.remove();
448458
}
449459

450460
function straightClosedPath(pts) {

0 commit comments

Comments
 (0)