Skip to content

Commit 923797a

Browse files
authored
Merge pull request #920 from plotly/hotfix-visible-false-scatter
Hotfix: clean up visible false scatter trace
2 parents ab51c36 + e3ac9d7 commit 923797a

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/plots/cartesian/index.js

+36
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,39 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
110110
}
111111
}
112112
};
113+
114+
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
115+
var oldModules = oldFullLayout._modules || [],
116+
newModules = newFullLayout._modules || [];
117+
118+
var hadScatter, hasScatter, i;
119+
120+
for(i = 0; i < oldModules.length; i++) {
121+
if(oldModules[i].name === 'scatter') {
122+
hadScatter = true;
123+
break;
124+
}
125+
}
126+
127+
for(i = 0; i < newModules.length; i++) {
128+
if(newModules[i].name === 'scatter') {
129+
hasScatter = true;
130+
break;
131+
}
132+
}
133+
134+
if(hadScatter && !hasScatter) {
135+
var oldPlots = oldFullLayout._plots,
136+
ids = Object.keys(oldPlots || {});
137+
138+
for(i = 0; i < ids.length; i++) {
139+
var subplotInfo = oldPlots[ids[i]];
140+
141+
if(subplotInfo.plot) {
142+
subplotInfo.plot.select('g.scatterlayer')
143+
.selectAll('g.trace')
144+
.remove();
145+
}
146+
}
147+
}
148+
};

src/plots/plots.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ plots.supplyTraceDefaults = function(traceIn, traceIndex, layout) {
707707

708708
coerce('type');
709709
coerce('uid');
710+
coerce('name', 'trace ' + traceIndex);
710711

711712
// coerce subplot attributes of all registered subplot types
712713
var subplotTypes = Object.keys(subplotsRegistry);
@@ -733,8 +734,6 @@ plots.supplyTraceDefaults = function(traceIn, traceIndex, layout) {
733734

734735
if(_module) _module.supplyDefaults(traceIn, traceOut, defaultColor, layout);
735736

736-
coerce('name', 'trace ' + traceIndex);
737-
738737
if(!plots.traceIs(traceOut, 'noOpacity')) coerce('opacity');
739738

740739
coerceSubplotAttr('cartesian', 'xaxis');

test/jasmine/tests/cartesian_test.js

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ describe('restyle', function() {
105105

106106
// The second has been recreated so is different:
107107
expect(firstToNext).not.toBe(secondToNext);
108+
109+
return Plotly.restyle(gd, 'visible', false);
110+
}).then(function() {
111+
expect(d3.selectAll('g.trace.scatter').size()).toEqual(0);
112+
108113
}).then(done);
109114
});
110115

0 commit comments

Comments
 (0)