Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix toggleHover and resetViews modebar buttons for some partial bundle + graph setups #4184

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
etpinard committed Sep 10, 2019
commit 40ee980cfaa543877bb295ab99acd621531c2482
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