Skip to content

Commit 40ee980

Browse files
committed
fix #4164 - add fallbacks to fullLayout._subplots[k] entries
... in modebar buttons handlers called on graphs with different subplot arrangement that may or may not be part of one's partial or custom bundle.
1 parent 9b5f089 commit 40ee980

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

Diff for: src/components/modebar/buttons.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ function handleCamera3d(gd, ev) {
343343
var button = ev.currentTarget;
344344
var attr = button.getAttribute('data-attr');
345345
var fullLayout = gd._fullLayout;
346-
var sceneIds = fullLayout._subplots.gl3d;
346+
var sceneIds = fullLayout._subplots.gl3d || [];
347347
var aobj = {};
348348

349349
for(var i = 0; i < sceneIds.length; i++) {
@@ -380,7 +380,7 @@ function getNextHover3d(gd, ev) {
380380
var button = ev.currentTarget;
381381
var val = button._previousVal;
382382
var fullLayout = gd._fullLayout;
383-
var sceneIds = fullLayout._subplots.gl3d;
383+
var sceneIds = fullLayout._subplots.gl3d || [];
384384

385385
var axes = ['xaxis', 'yaxis', 'zaxis'];
386386

@@ -618,7 +618,7 @@ modeBarButtons.resetViewMapbox = {
618618

619619
function resetView(gd, subplotType) {
620620
var fullLayout = gd._fullLayout;
621-
var subplotIds = fullLayout._subplots[subplotType];
621+
var subplotIds = fullLayout._subplots[subplotType] || [];
622622
var aObj = {};
623623

624624
for(var i = 0; i < subplotIds.length; i++) {

Diff for: test/jasmine/tests/modebar_test.js

+50
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,56 @@ describe('ModeBar', function() {
13421342
.then(done);
13431343
});
13441344
});
1345+
1346+
describe('button toggleHover', function() {
1347+
it('ternary case', function(done) {
1348+
var gd = createGraphDiv();
1349+
1350+
function _run(msg) {
1351+
expect(gd._fullLayout.hovermode).toBe('closest', msg + '| pre');
1352+
selectButton(gd._fullLayout._modeBar, 'toggleHover').click();
1353+
expect(gd._fullLayout.hovermode).toBe(false, msg + '| after first click');
1354+
selectButton(gd._fullLayout._modeBar, 'toggleHover').click();
1355+
expect(gd._fullLayout.hovermode).toBe('closest', msg + '| after 2nd click');
1356+
}
1357+
1358+
Plotly.plot(gd, [
1359+
{type: 'scatterternary', a: [1], b: [2], c: [3]}
1360+
])
1361+
.then(function() {
1362+
_run('base');
1363+
1364+
// mock for *cartesian* bundle
1365+
delete gd._fullLayout._subplots.gl3d;
1366+
1367+
_run('cartesian bundle');
1368+
})
1369+
.catch(failTest)
1370+
.then(done);
1371+
});
1372+
});
1373+
1374+
describe('button resetViews', function() {
1375+
it('ternary + geo case ', function(done) {
1376+
var gd = createGraphDiv();
1377+
1378+
Plotly.plot(gd, [
1379+
{type: 'scatterternary', a: [1], b: [2], c: [3]},
1380+
{type: 'scattergeo', lon: [10], lat: [20]}
1381+
])
1382+
.then(function() {
1383+
selectButton(gd._fullLayout._modeBar, 'resetViews').click();
1384+
1385+
// mock for custom geo + ternary bundle
1386+
delete gd._fullLayout._subplots.gl3d;
1387+
delete gd._fullLayout._subplots.mapbox;
1388+
1389+
selectButton(gd._fullLayout._modeBar, 'resetViews').click();
1390+
})
1391+
.catch(failTest)
1392+
.then(done);
1393+
});
1394+
});
13451395
});
13461396

13471397
describe('modebar styling', function() {

0 commit comments

Comments
 (0)