Skip to content

Commit 36b8483

Browse files
authored
Merge pull request #2411 from plotly/one-contour-label-fix
fall back for contour labels when there's only one contour
2 parents efa1275 + 492db56 commit 36b8483

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

src/plots/cartesian/axes.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,8 @@ function autoShiftMonthBins(binStart, data, dtick, dataMin, calendar) {
742742
// Ticks and grids
743743
// ----------------------------------------------------
744744

745-
// calculate the ticks: text, values, positioning
746-
// if ticks are set to automatic, determine the right values (tick0,dtick)
747-
// in any case, set tickround to # of digits to round tick labels to,
748-
// or codes to this effect for log and date scales
749-
axes.calcTicks = function calcTicks(ax) {
745+
// ensure we have tick0, dtick, and tick rounding calculated
746+
axes.prepTicks = function(ax) {
750747
var rng = Lib.simpleMap(ax.range, ax.r2l);
751748

752749
// calculate max number of (auto) ticks to display based on plot size
@@ -787,6 +784,15 @@ axes.calcTicks = function calcTicks(ax) {
787784

788785
// now figure out rounding of tick values
789786
autoTickRound(ax);
787+
};
788+
789+
// calculate the ticks: text, values, positioning
790+
// if ticks are set to automatic, determine the right values (tick0,dtick)
791+
// in any case, set tickround to # of digits to round tick labels to,
792+
// or codes to this effect for log and date scales
793+
axes.calcTicks = function calcTicks(ax) {
794+
axes.prepTicks(ax);
795+
var rng = Lib.simpleMap(ax.range, ax.r2l);
790796

791797
// now that we've figured out the auto values for formatting
792798
// in case we're missing some ticktext, we can break out for array ticks

src/traces/carpet/calc_gridlines.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function calcGridlines(trace, cd, axisLetter, crossAxisLetter)
3737
var na = trace.a.length;
3838
var nb = trace.b.length;
3939

40-
Axes.calcTicks(axis);
40+
Axes.prepTicks(axis);
4141

4242
// don't leave tickvals in axis looking like an attribute
4343
if(axis.tickmode === 'array') delete axis.tickvals;

src/traces/contour/plot.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -428,19 +428,19 @@ exports.labelFormatter = function(contours, colorbar, fullLayout) {
428428
formatAxis.range = [value[0], value[value.length - 1]];
429429
}
430430
else formatAxis.range = [value, value];
431-
432-
if(formatAxis.range[0] === formatAxis.range[1]) {
433-
formatAxis.range[1] += formatAxis.range[0] || 1;
434-
}
435-
formatAxis.nticks = 1000;
436431
}
437432
else {
438433
formatAxis.range = [contours.start, contours.end];
439434
formatAxis.nticks = (contours.end - contours.start) / contours.size;
440435
}
441436

437+
if(formatAxis.range[0] === formatAxis.range[1]) {
438+
formatAxis.range[1] += formatAxis.range[0] || 1;
439+
}
440+
if(!formatAxis.nticks) formatAxis.nticks = 1000;
441+
442442
setConvert(formatAxis, fullLayout);
443-
Axes.calcTicks(formatAxis);
443+
Axes.prepTicks(formatAxis);
444444
formatAxis._tmin = null;
445445
formatAxis._tmax = null;
446446
}

test/jasmine/tests/contour_test.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ describe('contour calc', function() {
347347
});
348348
});
349349

350-
describe('contour edits', function() {
350+
describe('contour plotting and editing', function() {
351351
var gd;
352352

353353
beforeEach(function() {
@@ -388,4 +388,23 @@ describe('contour edits', function() {
388388
.catch(fail)
389389
.then(done);
390390
});
391+
392+
it('works and draws labels when explicitly specifying ncontours=1', function(done) {
393+
Plotly.newPlot(gd, [{
394+
z: [[0.20, 0.57], [0.3, 0.4]],
395+
type: 'contour',
396+
zmin: 0.4,
397+
zmax: 0.41,
398+
ncontours: 1,
399+
showscale: false,
400+
contours: {showlabels: true}
401+
}], {
402+
width: 500, height: 500
403+
})
404+
.then(function() {
405+
expect(gd.querySelector('.contourlabels text').textContent).toBe('0.41');
406+
})
407+
.catch(fail)
408+
.then(done);
409+
});
391410
});

0 commit comments

Comments
 (0)