From 83d688811f8aecc21bcbf917653512ab788c5b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 8 Sep 2016 16:44:11 -0400 Subject: [PATCH 1/3] clean up old scatter traces that were restyle to 'visible: false' - as of PR #802, scatter traces are no longer purged in the per-subplot cartesian plot step - to maintain consistency between transitions. - While the scatter plot module can remove individual 'visible: false' traces, when all scatter traces are restyled to 'visible: false' the scatter plot module is currently not called! --- src/plots/cartesian/index.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/plots/cartesian/index.js b/src/plots/cartesian/index.js index 156d89ca120..aaed864dc92 100644 --- a/src/plots/cartesian/index.js +++ b/src/plots/cartesian/index.js @@ -110,3 +110,39 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { } } }; + +exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) { + var oldModules = oldFullLayout._modules || [], + newModules = newFullLayout._modules || []; + + var hadScatter, hasScatter, i; + + for(i = 0; i < oldModules.length; i++) { + if(oldModules[i].name === 'scatter') { + hadScatter = true; + break; + } + } + + for(i = 0; i < newModules.length; i++) { + if(newModules[i].name === 'scatter') { + hasScatter = true; + break; + } + } + + if(hadScatter && !hasScatter) { + var oldPlots = oldFullLayout._plots, + ids = Object.keys(oldPlots || {}); + + for(i = 0; i < ids.length; i++) { + var subplotInfo = oldPlots[ids[i]]; + + if(subplotInfo.plot) { + subplotInfo.plot.select('g.scatterlayer') + .selectAll('g.trace') + .remove(); + } + } + } +}; From e8b7afaee6bf6796e48ebd32673369459cab4a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 8 Sep 2016 16:45:32 -0400 Subject: [PATCH 2/3] test: add case for scatter Plotly.restyle(gd, 'visible', false) --- test/jasmine/tests/cartesian_test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/jasmine/tests/cartesian_test.js b/test/jasmine/tests/cartesian_test.js index e43b9265aa6..597fe636922 100644 --- a/test/jasmine/tests/cartesian_test.js +++ b/test/jasmine/tests/cartesian_test.js @@ -105,6 +105,11 @@ describe('restyle', function() { // The second has been recreated so is different: expect(firstToNext).not.toBe(secondToNext); + + return Plotly.restyle(gd, 'visible', false); + }).then(function() { + expect(d3.selectAll('g.trace.scatter').size()).toEqual(0); + }).then(done); }); From e3ac9d743d920391648016990b6356c8646eb2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 8 Sep 2016 16:46:27 -0400 Subject: [PATCH 3/3] coerce 'name' in visible: false traces --- src/plots/plots.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index a38c9a13744..8162489ce73 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -707,6 +707,7 @@ plots.supplyTraceDefaults = function(traceIn, traceIndex, layout) { coerce('type'); coerce('uid'); + coerce('name', 'trace ' + traceIndex); // coerce subplot attributes of all registered subplot types var subplotTypes = Object.keys(subplotsRegistry); @@ -733,8 +734,6 @@ plots.supplyTraceDefaults = function(traceIn, traceIndex, layout) { if(_module) _module.supplyDefaults(traceIn, traceOut, defaultColor, layout); - coerce('name', 'trace ' + traceIndex); - if(!plots.traceIs(traceOut, 'noOpacity')) coerce('opacity'); coerceSubplotAttr('cartesian', 'xaxis');