diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index cfc7fbfaa51..cb79776c665 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -1624,6 +1624,11 @@ function _restyle(gd, aobj, _traces) { flags.docalc = true; } + // some attributes declare an 'editType' flaglist + if(valObject.editType === 'docalc') { + flags.docalc = true; + } + // all the other ones, just modify that one attribute param.set(newVal); } diff --git a/src/traces/contour/attributes.js b/src/traces/contour/attributes.js index 069a965af9c..042bc7355f8 100644 --- a/src/traces/contour/attributes.js +++ b/src/traces/contour/attributes.js @@ -128,7 +128,10 @@ module.exports = extendFlat({}, { }) } }, - colorscaleAttrs, - { autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) }, + colorscaleAttrs, { + autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}), + zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'docalc'}), + zmax: extendFlat({}, colorscaleAttrs.zmax, {editType: 'docalc'}) + }, { colorbar: colorbarAttrs } ); diff --git a/src/traces/histogram2dcontour/attributes.js b/src/traces/histogram2dcontour/attributes.js index 0a7ba7f36c5..b8164531ee0 100644 --- a/src/traces/histogram2dcontour/attributes.js +++ b/src/traces/histogram2dcontour/attributes.js @@ -35,6 +35,9 @@ module.exports = extendFlat({}, { contours: contourAttrs.contours, line: contourAttrs.line }, - colorscaleAttrs, + colorscaleAttrs, { + zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'docalc'}), + zmax: extendFlat({}, colorscaleAttrs.zmax, {editType: 'docalc'}) + }, { colorbar: colorbarAttrs } ); diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index eee008c4a4f..da617cbfdd1 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -363,6 +363,72 @@ describe('Test plot api', function() { expect(PlotlyInternal.plot.calls.count()).toEqual(2); }); + it('should clear calcdata when restyling \'zmin\' and \'zmax\' on contour traces', function() { + var contour = { + data: [{ + type: 'contour', + z: [[1, 2, 3], [1, 2, 1]] + }] + }; + + var histogram2dcontour = { + data: [{ + type: 'histogram2dcontour', + x: [1, 1, 2, 2, 2, 3], + y: [0, 0, 0, 0, 1, 3] + }] + }; + + var mocks = [contour, histogram2dcontour]; + + mocks.forEach(function(gd) { + mockDefaultsAndCalc(gd); + PlotlyInternal.plot.calls.reset(); + Plotly.restyle(gd, 'zmin', 0); + expect(gd.calcdata).toBeUndefined(); + expect(PlotlyInternal.plot).toHaveBeenCalled(); + + mockDefaultsAndCalc(gd); + PlotlyInternal.plot.calls.reset(); + Plotly.restyle(gd, 'zmax', 10); + expect(gd.calcdata).toBeUndefined(); + expect(PlotlyInternal.plot).toHaveBeenCalled(); + }); + }); + + it('should not clear calcdata when restyling \'zmin\' and \'zmax\' on heatmap traces', function() { + var heatmap = { + data: [{ + type: 'heatmap', + z: [[1, 2, 3], [1, 2, 1]] + }] + }; + + var histogram2d = { + data: [{ + type: 'histogram2d', + x: [1, 1, 2, 2, 2, 3], + y: [0, 0, 0, 0, 1, 3] + }] + }; + + var mocks = [heatmap, histogram2d]; + + mocks.forEach(function(gd) { + mockDefaultsAndCalc(gd); + PlotlyInternal.plot.calls.reset(); + Plotly.restyle(gd, 'zmin', 0); + expect(gd.calcdata).toBeDefined(); + expect(PlotlyInternal.plot).toHaveBeenCalled(); + + mockDefaultsAndCalc(gd); + PlotlyInternal.plot.calls.reset(); + Plotly.restyle(gd, 'zmax', 10); + expect(gd.calcdata).toBeDefined(); + expect(PlotlyInternal.plot).toHaveBeenCalled(); + }); + }); + it('ignores undefined values', function() { var gd = { data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}], diff --git a/test/jasmine/tests/plotschema_test.js b/test/jasmine/tests/plotschema_test.js index 91cecf03bcd..ccafd31b3bf 100644 --- a/test/jasmine/tests/plotschema_test.js +++ b/test/jasmine/tests/plotschema_test.js @@ -76,7 +76,7 @@ describe('plot schema', function() { var valObject = valObjects[attr.valType], opts = valObject.requiredOpts .concat(valObject.otherOpts) - .concat(['valType', 'description', 'role']); + .concat(['valType', 'description', 'role', 'editType']); Object.keys(attr).forEach(function(key) { expect(opts.indexOf(key) !== -1).toBe(true, key, attr);