From 3507538bbd1f29b01699366df180e9493d743184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 8 May 2017 12:54:23 -0400 Subject: [PATCH 1/5] make restyle aware of 'recalc' flag in attributes --- src/plot_api/plot_api.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index cfc7fbfaa51..777fca8f72b 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 a 'recalc' flag + if(valObject.recalc) { + flags.docalc = true; + } + // all the other ones, just modify that one attribute param.set(newVal); } From 52d3724f34ca97dce1f038dcce2709ba4cb40d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 8 May 2017 12:55:07 -0400 Subject: [PATCH 2/5] add `recalc: true` to contour and histogram2dcontour attributes --- src/traces/contour/attributes.js | 7 +++++-- src/traces/histogram2dcontour/attributes.js | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/traces/contour/attributes.js b/src/traces/contour/attributes.js index 069a965af9c..9b9f5649a85 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, {recalc: true}), + zmax: extendFlat({}, colorscaleAttrs.zmax, {recalc: true}) + }, { colorbar: colorbarAttrs } ); diff --git a/src/traces/histogram2dcontour/attributes.js b/src/traces/histogram2dcontour/attributes.js index 0a7ba7f36c5..93b82f302d4 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, {recalc: true}), + zmax: extendFlat({}, colorscaleAttrs.zmax, {recalc: true}) + }, { colorbar: colorbarAttrs } ); From 6400baaa6b00e1dd7c6ffcf4d6b8446762a4dea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 8 May 2017 12:55:58 -0400 Subject: [PATCH 3/5] add tests for recalc restyle switch for zmin / zmax - note the different behavior between heatmap-like and contour-like traces. --- test/jasmine/tests/plot_api_test.js | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) 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'}], From 8ac49aec0a5e6939af0b31ca7e7ea47d677847f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 8 May 2017 13:04:59 -0400 Subject: [PATCH 4/5] add 'recalc' to list of compatible attribute keys --- test/jasmine/tests/plotschema_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jasmine/tests/plotschema_test.js b/test/jasmine/tests/plotschema_test.js index 91cecf03bcd..c09e3fe6e3e 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', 'recalc']); Object.keys(attr).forEach(function(key) { expect(opts.indexOf(key) !== -1).toBe(true, key, attr); From 413e5459960c4b4c2c4c6212919e3a5c3183f981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 8 May 2017 14:38:17 -0400 Subject: [PATCH 5/5] replace 'recalc' flag with 'editType' flaglist --- src/plot_api/plot_api.js | 4 ++-- src/traces/contour/attributes.js | 4 ++-- src/traces/histogram2dcontour/attributes.js | 4 ++-- test/jasmine/tests/plotschema_test.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 777fca8f72b..cb79776c665 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -1624,8 +1624,8 @@ function _restyle(gd, aobj, _traces) { flags.docalc = true; } - // some attributes declare a 'recalc' flag - if(valObject.recalc) { + // some attributes declare an 'editType' flaglist + if(valObject.editType === 'docalc') { flags.docalc = true; } diff --git a/src/traces/contour/attributes.js b/src/traces/contour/attributes.js index 9b9f5649a85..042bc7355f8 100644 --- a/src/traces/contour/attributes.js +++ b/src/traces/contour/attributes.js @@ -130,8 +130,8 @@ module.exports = extendFlat({}, { }, colorscaleAttrs, { autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}), - zmin: extendFlat({}, colorscaleAttrs.zmin, {recalc: true}), - zmax: extendFlat({}, colorscaleAttrs.zmax, {recalc: true}) + 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 93b82f302d4..b8164531ee0 100644 --- a/src/traces/histogram2dcontour/attributes.js +++ b/src/traces/histogram2dcontour/attributes.js @@ -36,8 +36,8 @@ module.exports = extendFlat({}, { line: contourAttrs.line }, colorscaleAttrs, { - zmin: extendFlat({}, colorscaleAttrs.zmin, {recalc: true}), - zmax: extendFlat({}, colorscaleAttrs.zmax, {recalc: true}) + zmin: extendFlat({}, colorscaleAttrs.zmin, {editType: 'docalc'}), + zmax: extendFlat({}, colorscaleAttrs.zmax, {editType: 'docalc'}) }, { colorbar: colorbarAttrs } ); diff --git a/test/jasmine/tests/plotschema_test.js b/test/jasmine/tests/plotschema_test.js index c09e3fe6e3e..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', 'recalc']); + .concat(['valType', 'description', 'role', 'editType']); Object.keys(attr).forEach(function(key) { expect(opts.indexOf(key) !== -1).toBe(true, key, attr);