Skip to content

fall back for contour labels when there's only one contour #2411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/traces/carpet/calc_gridlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/traces/contour/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 20 additions & 1 deletion test/jasmine/tests/contour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ describe('contour calc', function() {
});
});

describe('contour edits', function() {
describe('contour plotting and editing', function() {
var gd;

beforeEach(function() {
Expand Down Expand Up @@ -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);
});
});