Skip to content

Commit 4e2a866

Browse files
authored
Merge pull request #1653 from plotly/contour-restyle-zmin-zmax
Contour restyle zmin zmax
2 parents 87de776 + 413e545 commit 4e2a866

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

src/plot_api/plot_api.js

+5
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,11 @@ function _restyle(gd, aobj, _traces) {
16241624
flags.docalc = true;
16251625
}
16261626

1627+
// some attributes declare an 'editType' flaglist
1628+
if(valObject.editType === 'docalc') {
1629+
flags.docalc = true;
1630+
}
1631+
16271632
// all the other ones, just modify that one attribute
16281633
param.set(newVal);
16291634
}

src/traces/contour/attributes.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ module.exports = extendFlat({}, {
128128
})
129129
}
130130
},
131-
colorscaleAttrs,
132-
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
131+
colorscaleAttrs, {
132+
autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}),
133+
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'docalc'}),
134+
zmax: extendFlat({}, colorscaleAttrs.zmax, {editType: 'docalc'})
135+
},
133136
{ colorbar: colorbarAttrs }
134137
);

src/traces/histogram2dcontour/attributes.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ module.exports = extendFlat({}, {
3535
contours: contourAttrs.contours,
3636
line: contourAttrs.line
3737
},
38-
colorscaleAttrs,
38+
colorscaleAttrs, {
39+
zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'docalc'}),
40+
zmax: extendFlat({}, colorscaleAttrs.zmax, {editType: 'docalc'})
41+
},
3942
{ colorbar: colorbarAttrs }
4043
);

test/jasmine/tests/plot_api_test.js

+66
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,72 @@ describe('Test plot api', function() {
363363
expect(PlotlyInternal.plot.calls.count()).toEqual(2);
364364
});
365365

366+
it('should clear calcdata when restyling \'zmin\' and \'zmax\' on contour traces', function() {
367+
var contour = {
368+
data: [{
369+
type: 'contour',
370+
z: [[1, 2, 3], [1, 2, 1]]
371+
}]
372+
};
373+
374+
var histogram2dcontour = {
375+
data: [{
376+
type: 'histogram2dcontour',
377+
x: [1, 1, 2, 2, 2, 3],
378+
y: [0, 0, 0, 0, 1, 3]
379+
}]
380+
};
381+
382+
var mocks = [contour, histogram2dcontour];
383+
384+
mocks.forEach(function(gd) {
385+
mockDefaultsAndCalc(gd);
386+
PlotlyInternal.plot.calls.reset();
387+
Plotly.restyle(gd, 'zmin', 0);
388+
expect(gd.calcdata).toBeUndefined();
389+
expect(PlotlyInternal.plot).toHaveBeenCalled();
390+
391+
mockDefaultsAndCalc(gd);
392+
PlotlyInternal.plot.calls.reset();
393+
Plotly.restyle(gd, 'zmax', 10);
394+
expect(gd.calcdata).toBeUndefined();
395+
expect(PlotlyInternal.plot).toHaveBeenCalled();
396+
});
397+
});
398+
399+
it('should not clear calcdata when restyling \'zmin\' and \'zmax\' on heatmap traces', function() {
400+
var heatmap = {
401+
data: [{
402+
type: 'heatmap',
403+
z: [[1, 2, 3], [1, 2, 1]]
404+
}]
405+
};
406+
407+
var histogram2d = {
408+
data: [{
409+
type: 'histogram2d',
410+
x: [1, 1, 2, 2, 2, 3],
411+
y: [0, 0, 0, 0, 1, 3]
412+
}]
413+
};
414+
415+
var mocks = [heatmap, histogram2d];
416+
417+
mocks.forEach(function(gd) {
418+
mockDefaultsAndCalc(gd);
419+
PlotlyInternal.plot.calls.reset();
420+
Plotly.restyle(gd, 'zmin', 0);
421+
expect(gd.calcdata).toBeDefined();
422+
expect(PlotlyInternal.plot).toHaveBeenCalled();
423+
424+
mockDefaultsAndCalc(gd);
425+
PlotlyInternal.plot.calls.reset();
426+
Plotly.restyle(gd, 'zmax', 10);
427+
expect(gd.calcdata).toBeDefined();
428+
expect(PlotlyInternal.plot).toHaveBeenCalled();
429+
});
430+
});
431+
366432
it('ignores undefined values', function() {
367433
var gd = {
368434
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],

test/jasmine/tests/plotschema_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('plot schema', function() {
7676
var valObject = valObjects[attr.valType],
7777
opts = valObject.requiredOpts
7878
.concat(valObject.otherOpts)
79-
.concat(['valType', 'description', 'role']);
79+
.concat(['valType', 'description', 'role', 'editType']);
8080

8181
Object.keys(attr).forEach(function(key) {
8282
expect(opts.indexOf(key) !== -1).toBe(true, key, attr);

0 commit comments

Comments
 (0)