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(); + } + } + } +}; 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'); 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); });