Skip to content

Commit 23c1cf0

Browse files
committed
fix and 🔒 cmid/zmid edits
1 parent ba72887 commit 23c1cf0

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

src/components/colorscale/attributes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ module.exports = function colorScaleAttrs(context, opts) {
166166
valType: 'number',
167167
role: 'info',
168168
dflt: null,
169-
editType: editTypeOverride || 'plot',
170-
impliedEdits: minmaxImpliedEdits,
169+
editType: 'calc',
170+
impliedEdits: autoImpliedEdits,
171171
description: [
172172
'Sets the mid-point of the color domain by scaling ', minFull,
173173
' and/or ', maxFull, ' to be equidistant to this point.',

src/components/colorscale/defaults.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce,
3333
var minIn = containerIn[cLetter + 'min'];
3434
var maxIn = containerIn[cLetter + 'max'];
3535
var validMinMax = isNumeric(minIn) && isNumeric(maxIn) && (minIn < maxIn);
36-
coerce(prefix + cLetter + 'auto', !validMinMax);
37-
coerce(prefix + cLetter + 'min');
38-
coerce(prefix + cLetter + 'max');
39-
coerce(prefix + cLetter + 'mid');
36+
var auto = coerce(prefix + cLetter + 'auto', !validMinMax);
37+
38+
if(auto) {
39+
coerce(prefix + cLetter + 'mid');
40+
} else {
41+
coerce(prefix + cLetter + 'min');
42+
coerce(prefix + cLetter + 'max');
43+
}
4044

4145
// handles both the trace case (autocolorscale is false by default) and
4246
// the marker and marker.line case (autocolorscale is true by default)

test/jasmine/tests/plot_api_test.js

+71
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,77 @@ describe('Test plot api', function() {
11951195
.then(done);
11961196
});
11971197

1198+
it('turns on cauto when cmid is edited', function(done) {
1199+
function _assert(msg, exp) {
1200+
return function() {
1201+
var mk = gd._fullData[0].marker;
1202+
for(var k in exp) {
1203+
expect(mk[k]).toBe(exp[k], [msg, k].join(' - '));
1204+
}
1205+
};
1206+
}
1207+
1208+
function _restyle(arg) {
1209+
return function() { return Plotly.restyle(gd, arg); };
1210+
}
1211+
1212+
Plotly.plot(gd, [{
1213+
mode: 'markers',
1214+
y: [1, 2, 1],
1215+
marker: { color: [1, -1, 4] }
1216+
}])
1217+
.then(_assert('base', {
1218+
cauto: true,
1219+
cmid: undefined,
1220+
cmin: -1,
1221+
cmax: 4
1222+
}))
1223+
.then(_restyle({'marker.cmid': 0}))
1224+
.then(_assert('set cmid=0', {
1225+
cauto: true,
1226+
cmid: 0,
1227+
cmin: -4,
1228+
cmax: 4
1229+
}))
1230+
.then(_restyle({'marker.cmid': -2}))
1231+
.then(_assert('set cmid=-2', {
1232+
cauto: true,
1233+
cmid: -2,
1234+
cmin: -8,
1235+
cmax: 4
1236+
}))
1237+
.then(_restyle({'marker.cmid': 2}))
1238+
.then(_assert('set cmid=2', {
1239+
cauto: true,
1240+
cmid: 2,
1241+
cmin: -1,
1242+
cmax: 5
1243+
}))
1244+
.then(_restyle({'marker.cmin': 0}))
1245+
.then(_assert('set cmin=0', {
1246+
cauto: false,
1247+
cmid: undefined,
1248+
cmin: 0,
1249+
cmax: 5
1250+
}))
1251+
.then(_restyle({'marker.cmax': 10}))
1252+
.then(_assert('set cmin=0 + cmax=10', {
1253+
cauto: false,
1254+
cmid: undefined,
1255+
cmin: 0,
1256+
cmax: 10
1257+
}))
1258+
.then(_restyle({'marker.cauto': true, 'marker.cmid': null}))
1259+
.then(_assert('back to cauto=true', {
1260+
cauto: true,
1261+
cmid: undefined,
1262+
cmin: -1,
1263+
cmax: 4
1264+
}))
1265+
.catch(failTest)
1266+
.then(done);
1267+
});
1268+
11981269
it('turns off autobin when you edit bin specs', function(done) {
11991270
// test retained (modified) for backward compat with new autobin logic
12001271
var start0 = 0.2;

0 commit comments

Comments
 (0)