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 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
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.select('.modebar-container').remove();

fullLayout._paper = fullLayout._paperdiv.insert('svg', ':first-child')
.classed('main-svg', true);
Expand Down
30 changes: 30 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3221,6 +3221,36 @@ describe('hovermode defaults to', function() {
});
});

describe('hover labels z-position', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);
var mock = require('@mocks/14.json');

it('is above the modebar', function(done) {
Plotly.plot(gd, mock).then(function() {
var infolayer = document.getElementsByClassName('infolayer');
var modebar = document.getElementsByClassName('modebar-container');
var hoverlayer = document.getElementsByClassName('hoverlayer');

expect(infolayer.length).toBe(1);
expect(modebar.length).toBe(1);
expect(hoverlayer.length).toBe(1);

var compareMask = infolayer[0].compareDocumentPosition(modebar[0]);
expect(compareMask).toBe(Node.DOCUMENT_POSITION_FOLLOWING, '.modebar-container appears after the .infolayer');
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow. I didn't know that thing existed. NICE!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Me neither! Just found out about them today: https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition 😄


compareMask = modebar[0].compareDocumentPosition(hoverlayer[0]);
expect(compareMask).toBe(Node.DOCUMENT_POSITION_FOLLOWING, '.hoverlayer appears after the .modebar');
})
.catch(failTest)
.then(done);
});
});

describe('touch devices', function() {
afterEach(destroyGraphDiv);
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