From 492db5680f95034aed2d109a92bfcb1e18c78a7d Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Tue, 27 Feb 2018 13:19:48 -0500 Subject: [PATCH] fall back for contour labels when there's only one contour also break up Axes.calcTicks -> prepTicks only finishes setting up the axis object --- src/plots/cartesian/axes.js | 16 +++++++++++----- src/traces/carpet/calc_gridlines.js | 2 +- src/traces/contour/plot.js | 12 ++++++------ test/jasmine/tests/contour_test.js | 21 ++++++++++++++++++++- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 01f892f748f..972d90e9e12 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -742,11 +742,8 @@ function autoShiftMonthBins(binStart, data, dtick, dataMin, calendar) { // Ticks and grids // ---------------------------------------------------- -// calculate the ticks: text, values, positioning -// if ticks are set to automatic, determine the right values (tick0,dtick) -// in any case, set tickround to # of digits to round tick labels to, -// or codes to this effect for log and date scales -axes.calcTicks = function calcTicks(ax) { +// ensure we have tick0, dtick, and tick rounding calculated +axes.prepTicks = function(ax) { var rng = Lib.simpleMap(ax.range, ax.r2l); // calculate max number of (auto) ticks to display based on plot size @@ -787,6 +784,15 @@ axes.calcTicks = function calcTicks(ax) { // now figure out rounding of tick values autoTickRound(ax); +}; + +// calculate the ticks: text, values, positioning +// if ticks are set to automatic, determine the right values (tick0,dtick) +// in any case, set tickround to # of digits to round tick labels to, +// or codes to this effect for log and date scales +axes.calcTicks = function calcTicks(ax) { + axes.prepTicks(ax); + var rng = Lib.simpleMap(ax.range, ax.r2l); // now that we've figured out the auto values for formatting // in case we're missing some ticktext, we can break out for array ticks diff --git a/src/traces/carpet/calc_gridlines.js b/src/traces/carpet/calc_gridlines.js index 93c6021e81b..64006e071ab 100644 --- a/src/traces/carpet/calc_gridlines.js +++ b/src/traces/carpet/calc_gridlines.js @@ -37,7 +37,7 @@ module.exports = function calcGridlines(trace, cd, axisLetter, crossAxisLetter) var na = trace.a.length; var nb = trace.b.length; - Axes.calcTicks(axis); + Axes.prepTicks(axis); // don't leave tickvals in axis looking like an attribute if(axis.tickmode === 'array') delete axis.tickvals; diff --git a/src/traces/contour/plot.js b/src/traces/contour/plot.js index b116a276712..be126d43e59 100644 --- a/src/traces/contour/plot.js +++ b/src/traces/contour/plot.js @@ -428,19 +428,19 @@ exports.labelFormatter = function(contours, colorbar, fullLayout) { formatAxis.range = [value[0], value[value.length - 1]]; } else formatAxis.range = [value, value]; - - if(formatAxis.range[0] === formatAxis.range[1]) { - formatAxis.range[1] += formatAxis.range[0] || 1; - } - formatAxis.nticks = 1000; } else { formatAxis.range = [contours.start, contours.end]; formatAxis.nticks = (contours.end - contours.start) / contours.size; } + if(formatAxis.range[0] === formatAxis.range[1]) { + formatAxis.range[1] += formatAxis.range[0] || 1; + } + if(!formatAxis.nticks) formatAxis.nticks = 1000; + setConvert(formatAxis, fullLayout); - Axes.calcTicks(formatAxis); + Axes.prepTicks(formatAxis); formatAxis._tmin = null; formatAxis._tmax = null; } diff --git a/test/jasmine/tests/contour_test.js b/test/jasmine/tests/contour_test.js index 279b451bf46..dea87bd6869 100644 --- a/test/jasmine/tests/contour_test.js +++ b/test/jasmine/tests/contour_test.js @@ -347,7 +347,7 @@ describe('contour calc', function() { }); }); -describe('contour edits', function() { +describe('contour plotting and editing', function() { var gd; beforeEach(function() { @@ -388,4 +388,23 @@ describe('contour edits', function() { .catch(fail) .then(done); }); + + it('works and draws labels when explicitly specifying ncontours=1', function(done) { + Plotly.newPlot(gd, [{ + z: [[0.20, 0.57], [0.3, 0.4]], + type: 'contour', + zmin: 0.4, + zmax: 0.41, + ncontours: 1, + showscale: false, + contours: {showlabels: true} + }], { + width: 500, height: 500 + }) + .then(function() { + expect(gd.querySelector('.contourlabels text').textContent).toBe('0.41'); + }) + .catch(fail) + .then(done); + }); });