Skip to content

Commit

Permalink
fix #4164 - add fallbacks to fullLayout._subplots[k] entries
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
etpinard committed Sep 10, 2019
1 parent 9b5f089 commit 40ee980
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ function handleCamera3d(gd, ev) {
var button = ev.currentTarget;
var attr = button.getAttribute('data-attr');
var fullLayout = gd._fullLayout;
var sceneIds = fullLayout._subplots.gl3d;
var sceneIds = fullLayout._subplots.gl3d || [];
var aobj = {};

for(var i = 0; i < sceneIds.length; i++) {
Expand Down Expand Up @@ -380,7 +380,7 @@ function getNextHover3d(gd, ev) {
var button = ev.currentTarget;
var val = button._previousVal;
var fullLayout = gd._fullLayout;
var sceneIds = fullLayout._subplots.gl3d;
var sceneIds = fullLayout._subplots.gl3d || [];

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

Expand Down Expand Up @@ -618,7 +618,7 @@ modeBarButtons.resetViewMapbox = {

function resetView(gd, subplotType) {
var fullLayout = gd._fullLayout;
var subplotIds = fullLayout._subplots[subplotType];
var subplotIds = fullLayout._subplots[subplotType] || [];
var aObj = {};

for(var i = 0; i < subplotIds.length; i++) {
Expand Down
50 changes: 50 additions & 0 deletions test/jasmine/tests/modebar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,56 @@ describe('ModeBar', function() {
.then(done);
});
});

describe('button toggleHover', function() {
it('ternary case', function(done) {
var gd = createGraphDiv();

function _run(msg) {
expect(gd._fullLayout.hovermode).toBe('closest', msg + '| pre');
selectButton(gd._fullLayout._modeBar, 'toggleHover').click();
expect(gd._fullLayout.hovermode).toBe(false, msg + '| after first click');
selectButton(gd._fullLayout._modeBar, 'toggleHover').click();
expect(gd._fullLayout.hovermode).toBe('closest', msg + '| after 2nd click');
}

Plotly.plot(gd, [
{type: 'scatterternary', a: [1], b: [2], c: [3]}
])
.then(function() {
_run('base');

// mock for *cartesian* bundle
delete gd._fullLayout._subplots.gl3d;

_run('cartesian bundle');
})
.catch(failTest)
.then(done);
});
});

describe('button resetViews', function() {
it('ternary + geo case ', function(done) {
var gd = createGraphDiv();

Plotly.plot(gd, [
{type: 'scatterternary', a: [1], b: [2], c: [3]},
{type: 'scattergeo', lon: [10], lat: [20]}
])
.then(function() {
selectButton(gd._fullLayout._modeBar, 'resetViews').click();

// mock for custom geo + ternary bundle
delete gd._fullLayout._subplots.gl3d;
delete gd._fullLayout._subplots.mapbox;

selectButton(gd._fullLayout._modeBar, 'resetViews').click();
})
.catch(failTest)
.then(done);
});
});
});

describe('modebar styling', function() {
Expand Down

0 comments on commit 40ee980

Please sign in to comment.