Skip to content

ensure we create only one modebar-container #3678

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

Merged
merged 2 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3802,6 +3802,7 @@ function makePlotFramework(gd) {
.classed('gl-container', true);

fullLayout._paperdiv.selectAll('.main-svg').remove();
fullLayout._paperdiv.selectAll('.modebar-container').remove();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We remove the existing modebar because:

// Make the graph containers
// start fresh each time we get here, so we know the order comes out
// right, rather than enter/exit which can muck up the order
// TODO: sort out all the ordering so we don't have to
// explicitly delete anything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.select should suffice here, as there's only one <div.modebar-container> per graph.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 567edde


fullLayout._paper = fullLayout._paperdiv.insert('svg', ':first-child')
.classed('main-svg', true);
Expand Down
17 changes: 17 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,23 @@ describe('Test plot api', function() {
.catch(failTest)
.then(done);
});

it('should only have one modebar-container', function(done) {
var data = [{y: [1, 2]}];

Plotly.plot(gd, data).then(function() {
var modebars = document.getElementsByClassName('modebar-container');
expect(modebars.length).toBe(1);

return Plotly.newPlot(gd, data);
})
.then(function() {
var modebars = document.getElementsByClassName('modebar-container');
expect(modebars.length).toBe(1);
})
.catch(failTest)
.then(done);
});
});

describe('Plotly.update should', function() {
Expand Down