Skip to content

Commit ff311c5

Browse files
committed
fix #8117 - don't reuse stale zmin/zmax for autocontour when coloring is 'none'
With `contours.coloring: 'none'` the colorscale attributes are not coerced, so `zauto` is undefined on the full trace. After `Plotly.react`, `relinkPrivateKeys` + `Colorscale.crossTraceDefaults` put the previous `_zmin`/`_zmax` back onto `zmin`/`zmax`, and `setContours` used them because `trace.zauto` was falsy. Treat an undefined `zauto` as auto, as `Colorscale.calc` already does.
1 parent 1ef3c78 commit ff311c5

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎src/traces/contour/set_contours.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ module.exports = function setContours(trace, vals) {
1212
// these values here are meant to remain "per-trace" for now
1313
var zmin = trace.zmin;
1414
var zmax = trace.zmax;
15-
if(trace.zauto || zmin === undefined) {
15+
// `zauto` is only coerced when the trace has a colorscale (i.e. not for
16+
// `contours.coloring: 'none'`). Treat an undefined `zauto` as auto, like
17+
// Colorscale.calc does, so that we never reuse the zmin/zmax relinked
18+
// from a previous full trace after `Plotly.react` (see #8117).
19+
if(trace.zauto !== false || zmin === undefined) {
1620
zmin = Lib.aggNums(Math.min, null, vals);
1721
}
18-
if(trace.zauto || zmax === undefined) {
22+
if(trace.zauto !== false || zmax === undefined) {
1923
zmax = Lib.aggNums(Math.max, null, vals);
2024
}
2125

‎test/jasmine/tests/contour_test.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,35 @@ describe('contour plotting and editing', function() {
622622
.then(done, done.fail);
623623
});
624624

625+
it('should recompute autocontour levels from the new z on react when coloring is *none*', function(done) {
626+
// https://github.com/plotly/plotly.js/issues/8117
627+
// with contours.coloring 'none' the colorscale attributes are not coerced,
628+
// so setContours must not reuse the zmin/zmax relinked from the previous full trace
629+
function _trace(z) {
630+
return {type: 'contour', z: z, contours: {coloring: 'none'}};
631+
}
632+
633+
function _assertLevels(msg, start, end, size) {
634+
var contours = gd._fullData[0].contours;
635+
expect(contours.start).toBe(start, msg + ' start');
636+
expect(contours.end).toBe(end, msg + ' end');
637+
expect(contours.size).toBe(size, msg + ' size');
638+
expect(gd.querySelectorAll('.contourlevel path').length).toBeGreaterThan(0, msg + ' no contour lines drawn');
639+
}
640+
641+
Plotly.newPlot(gd, [_trace([[1, 2, 3], [4, 5, 6], [7, 8, 9]])])
642+
.then(function() {
643+
_assertLevels('initial', 2, 8, 1);
644+
645+
// new trace object and new z array, with a completely different range
646+
return Plotly.react(gd, [_trace([[4100, 4200, 4300], [4400, 4500, 4600], [4700, 4800, 4900]])]);
647+
})
648+
.then(function() {
649+
_assertLevels('after react', 4200, 4800, 100);
650+
})
651+
.then(done, done.fail);
652+
});
653+
625654
it('keeps the correct ordering after hide and show', function(done) {
626655
function getIndices() {
627656
var out = [];

0 commit comments

Comments
 (0)