Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c5d238

Browse filesBrowse files
authored
Merge pull request plotly#2455 from plotly/legendonly-fix
fix plotly#2452 - removing and adding scatter(gl) as not the first module
2 parents 4997900 + 2c2b94a commit 3c5d238
Copy full SHA for 3c5d238

File tree

Expand file treeCollapse file tree

4 files changed

+63
-25
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+63
-25
lines changed

‎src/plots/cartesian/index.js

Copy file name to clipboardExpand all lines: src/plots/cartesian/index.js
+7-23Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -216,35 +216,19 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
216216
var oldModules = oldFullLayout._modules || [],
217217
newModules = newFullLayout._modules || [];
218218

219-
var hadScatter, hasScatter, hadGl, hasGl, i, oldPlots, ids, subplotInfo;
219+
var hadScatter, hasScatter, hadGl, hasGl, i, oldPlots, ids, subplotInfo, moduleName;
220220

221221

222222
for(i = 0; i < oldModules.length; i++) {
223-
if(oldModules[i].name === 'scatter') {
224-
hadScatter = true;
225-
}
226-
break;
227-
}
228-
229-
for(i = 0; i < newModules.length; i++) {
230-
if(newModules[i].name === 'scatter') {
231-
hasScatter = true;
232-
break;
233-
}
234-
}
235-
236-
for(i = 0; i < oldModules.length; i++) {
237-
if(oldModules[i].name === 'scattergl') {
238-
hadGl = true;
239-
}
240-
break;
223+
moduleName = oldModules[i].name;
224+
if(moduleName === 'scatter') hadScatter = true;
225+
else if(moduleName === 'scattergl') hadGl = true;
241226
}
242227

243228
for(i = 0; i < newModules.length; i++) {
244-
if(newModules[i].name === 'scattergl') {
245-
hasGl = true;
246-
break;
247-
}
229+
moduleName = newModules[i].name;
230+
if(moduleName === 'scatter') hasScatter = true;
231+
else if(moduleName === 'scattergl') hasGl = true;
248232
}
249233

250234
if(hadScatter && !hasScatter) {

‎src/traces/scattergl/index.js

Copy file name to clipboardExpand all lines: src/traces/scattergl/index.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,9 @@ function sceneUpdate(gd, subplot) {
610610
scene.selectBatch = null;
611611
scene.unselectBatch = null;
612612

613-
delete subplot._scene;
613+
// we can't just delete _scene, because `destroy` is called in the
614+
// middle of supplyDefaults, before relinkPrivateKeys which will put it back.
615+
subplot._scene = null;
614616
};
615617
}
616618

‎test/jasmine/tests/cartesian_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/cartesian_test.js
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,58 @@ describe('restyle', function() {
159159
.then(done);
160160

161161
});
162+
163+
it('can legend-hide the second and only scatter trace', function(done) {
164+
Plotly.plot(gd, [
165+
{y: [1, 2, 3], type: 'bar'},
166+
{y: [1, 2, 3], xaxis: 'x2', yaxis: 'y2', type: 'scatter'}
167+
], {
168+
xaxis: {domain: [0, 0.4]},
169+
xaxis2: {domain: [0.6, 1]},
170+
yaxis2: {anchor: 'x2'},
171+
width: 600,
172+
height: 400
173+
})
174+
.then(function() {
175+
expect(d3.select('.scatter').size()).toBe(1);
176+
return Plotly.restyle(gd, {visible: 'legendonly'}, 1);
177+
})
178+
.then(function() {
179+
expect(d3.select('.scatter').size()).toBe(0);
180+
return Plotly.restyle(gd, {visible: true}, 1);
181+
})
182+
.then(function() {
183+
expect(d3.select('.scatter').size()).toBe(1);
184+
})
185+
.catch(failTest)
186+
.then(done);
187+
});
188+
189+
it('@gl can legend-hide the second and only scattergl trace', function(done) {
190+
Plotly.plot(gd, [
191+
{y: [1, 2, 3], type: 'bar'},
192+
{y: [1, 2, 3], xaxis: 'x2', yaxis: 'y2', type: 'scattergl'}
193+
], {
194+
xaxis: {domain: [0, 0.4]},
195+
xaxis2: {domain: [0.6, 1]},
196+
yaxis2: {anchor: 'x2'},
197+
width: 600,
198+
height: 400
199+
})
200+
.then(function() {
201+
expect(!!gd._fullLayout._plots.x2y2._scene).toBe(true);
202+
return Plotly.restyle(gd, {visible: 'legendonly'}, 1);
203+
})
204+
.then(function() {
205+
expect(!!gd._fullLayout._plots.x2y2._scene).toBe(false);
206+
return Plotly.restyle(gd, {visible: true}, 1);
207+
})
208+
.then(function() {
209+
expect(!!gd._fullLayout._plots.x2y2._scene).toBe(true);
210+
})
211+
.catch(failTest)
212+
.then(done);
213+
});
162214
});
163215
});
164216

‎test/jasmine/tests/gl2d_plot_interact_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/gl2d_plot_interact_test.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('@gl Test removal of gl contexts', function() {
3939
expect(gd._fullLayout._plots.xy._scene).toBeDefined();
4040
Plots.cleanPlot([], {}, gd._fullData, gd._fullLayout);
4141

42-
expect(gd._fullLayout._plots.xy._scene).toBeUndefined();
42+
expect(!!gd._fullLayout._plots.xy._scene).toBe(false);
4343
})
4444
.then(done);
4545
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.