Skip to content

Commit bda830b

Browse files
committed
Fix contour colorscale domain :
- Force include zmin/zmax only if explicitly set - Allows to set zmin/zmax range narrower than contours start/end
1 parent fa5c3e3 commit bda830b

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/traces/contour/make_color_map.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,28 @@ module.exports = function makeColorMap(trace) {
6666
range[i] = si[1];
6767
}
6868

69-
// Ensure zmin and zmax are included in the colorscale
70-
71-
if(domain[0] > zmin0) {
72-
domain.unshift(zmin0);
73-
range.unshift(range[0]);
74-
}
75-
76-
if(domain[domain.length - 1] < zmax0) {
77-
domain.push(zmax0);
78-
range.push(range[range.length - 1]);
69+
// If zmin/zmax are explicitly set
70+
if(typeof trace._input.zmin === 'number' && typeof trace._input.zmax === 'number') {
71+
// Consider case where user specifies a narrower z range than that
72+
// of the contours start/end.
73+
if(start <= zmin0) {
74+
domain = domain.filter(function(z) { return z >= zmin0; });
75+
range.splice(0, range.length - domain.length);
76+
}
77+
if(end >= zmax0) {
78+
domain = domain.filter(function(z) { return z <= zmax0; });
79+
range.splice(domain.length, range.length - domain.length);
80+
}
81+
82+
// Make the colorscale fit the z range
83+
if(domain[0] > zmin0) {
84+
domain.unshift(zmin0);
85+
range.unshift(range[0]);
86+
}
87+
if(domain[domain.length - 1] < zmax0) {
88+
domain.push(zmax0);
89+
range.push(range[range.length - 1]);
90+
}
7991
}
8092
}
8193

0 commit comments

Comments
 (0)