Skip to content

Draw updatemenus over sliders #1302

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
Jan 16, 2017
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
4 changes: 2 additions & 2 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ Plotly.plot = function(gd, data, layout, config) {

Registry.getComponentMethod('legend', 'draw')(gd);
Registry.getComponentMethod('rangeselector', 'draw')(gd);
Registry.getComponentMethod('updatemenus', 'draw')(gd);
Registry.getComponentMethod('sliders', 'draw')(gd);
Registry.getComponentMethod('updatemenus', 'draw')(gd);
Copy link
Contributor

@rreusser rreusser Jan 16, 2017

Choose a reason for hiding this comment

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

Real simple. The fact that it's quite this simple is a little concerning though.

I guess that means it works. For some reason I thought the dropdown was drawn on a separate layer (should it be?). (Edit: Ohhhh, it's a separate layer for all updatemenus but still within the updatemenus container.) The only corner case I can think of:

  1. Draw plot with updatemenus and no sliders
  2. Add slider
  3. Somehow the slider is appended after the updatemenu and ends up on top of it

But I guess that's what containerClass is for. So perhaps this is adequate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore this. Seems all good. Had to mentally work through the hierarchy once more, but yeah, this seems good. I'll only add a small note about long-term robustness of relying upon component ordering. I can imagine needing _upperinfolayer or something to which expanded components are added. Not necessary now but might be a better solution if more cases arise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessary now but might be a better solution if more cases arise.

Yeah. Maybe the best solution would have the dropdown buttons in a separate layer above <g class="infolayer">.

My solution aims to fix the 99% cases for users ASAP.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup. That fix is nicely future-aware, but unless I'm wrong there's not actually any difference in the present.


for(i = 0; i < calcdata.length; i++) {
cd = calcdata[i];
Expand Down Expand Up @@ -333,8 +333,8 @@ Plotly.plot = function(gd, data, layout, config) {
Registry.getComponentMethod('legend', 'draw')(gd);
Registry.getComponentMethod('rangeslider', 'draw')(gd);
Registry.getComponentMethod('rangeselector', 'draw')(gd);
Registry.getComponentMethod('updatemenus', 'draw')(gd);
Registry.getComponentMethod('sliders', 'draw')(gd);
Registry.getComponentMethod('updatemenus', 'draw')(gd);
}

function cleanUp() {
Expand Down
68 changes: 67 additions & 1 deletion test/jasmine/tests/updatemenus_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ describe('update menus interactions', function() {
}).catch(fail).then(done);
});

it('appliesy padding on relayout', function(done) {
it('applies y padding on relayout', function(done) {
var x1, x2;
var firstMenu = d3.select('.' + constants.headerGroupClassName);
var padShift = 40;
Expand Down Expand Up @@ -734,3 +734,69 @@ describe('update menus interactions', function() {
return button;
}
});


describe('update menus interaction with other components:', function() {
'use strict';

afterEach(destroyGraphDiv);

it('buttons show be drawn above sliders', function(done) {

Plotly.plot(createGraphDiv(), [{
x: [1, 2, 3],
y: [1, 2, 1]
}], {
sliders: [{
xanchor: 'right',
x: -0.05,
y: 0.9,
len: 0.3,
steps: [{
label: 'red',
method: 'restyle',
args: [{'line.color': 'red'}]
}, {
label: 'orange',
method: 'restyle',
args: [{'line.color': 'orange'}]
}, {
label: 'yellow',
method: 'restyle',
args: [{'line.color': 'yellow'}]
}]
}],
updatemenus: [{
buttons: [{
label: 'markers and lines',
method: 'restyle',
args: [{ 'mode': 'markers+lines' }]
}, {
label: 'markers',
method: 'restyle',
args: [{ 'mode': 'markers' }]
}, {
label: 'lines',
method: 'restyle',
args: [{ 'mode': 'lines' }]
}]
}]
})
.then(function() {
var infoLayer = d3.select('g.infolayer');
var containerClassNames = ['slider-container', 'updatemenu-container'];
var list = [];

infoLayer.selectAll('*').each(function() {
var className = d3.select(this).attr('class');

if(containerClassNames.indexOf(className) !== -1) {
list.push(className);
}
});

expect(list).toEqual(containerClassNames);
})
.then(done);
});
});