-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
scrollable dropdown menus #1214
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
Changes from 12 commits
2ec79e7
5a4ecf3
66e503c
9a0aa64
8df8fd6
7057bc7
8d1f333
563009b
ef5210e
f17773f
9e3ac1b
13508da
8ab3ebe
4975401
3b17d1d
b155a8a
109f284
e7c3ae3
89c615d
a554ea6
79f1107
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ var svgTextUtils = require('../../lib/svg_text_utils'); | |
var anchorUtils = require('../legend/anchor_utils'); | ||
|
||
var constants = require('./constants'); | ||
var ScrollBox = require('./scrollbox'); | ||
|
||
module.exports = function draw(gd) { | ||
var fullLayout = gd._fullLayout, | ||
|
@@ -253,11 +254,19 @@ function drawButtons(gd, gHeader, gButton, menuOpts) { | |
|
||
exit.transition() | ||
.attr('opacity', '0') | ||
.remove(); | ||
.remove() | ||
.each('end', function() { | ||
// remove the scrollbox, if all the buttons have been removed | ||
if(gButton.selectAll('g.' + klass).size() === 0) { | ||
gButton.call(removeAllButtons); | ||
} | ||
}); | ||
} else { | ||
exit.remove(); | ||
} | ||
|
||
// if folding a dropdown menu, don't draw the buttons | ||
if(!buttons.size()) return; | ||
|
||
var x0 = 0; | ||
var y0 = 0; | ||
|
@@ -281,13 +290,23 @@ function drawButtons(gd, gHeader, gButton, menuOpts) { | |
} | ||
|
||
var posOpts = { | ||
x: x0 + menuOpts.pad.l, | ||
y: y0 + menuOpts.pad.t, | ||
x: menuOpts.lx + x0 + menuOpts.pad.l, | ||
y: menuOpts.ly + y0 + menuOpts.pad.t, | ||
yPad: constants.gapButton, | ||
xPad: constants.gapButton, | ||
index: 0, | ||
}; | ||
|
||
var fullLayout = gd._fullLayout, | ||
scrollBoxId = 'updatemenus' + fullLayout._uid + menuOpts._index, | ||
scrollBoxPosition = { | ||
l: menuOpts.lx + menuOpts.borderwidth + x0 + menuOpts.pad.l, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job taking into account |
||
t: menuOpts.ly + menuOpts.borderwidth + y0 + menuOpts.pad.t, | ||
w: Math.max(menuOpts.openWidth, menuOpts.headerWidth), | ||
h: menuOpts.openHeight | ||
}, | ||
scrollBox = new ScrollBox(gd, gButton, scrollBoxPosition, scrollBoxId); | ||
|
||
buttons.each(function(buttonOpts, buttonIndex) { | ||
var button = d3.select(this); | ||
|
||
|
@@ -296,6 +315,9 @@ function drawButtons(gd, gHeader, gButton, menuOpts) { | |
.call(setItemPosition, menuOpts, posOpts); | ||
|
||
button.on('click', function() { | ||
// skip `dragend` events | ||
if(d3.event.defaultPrevented) return; | ||
|
||
setActive(gd, menuOpts, buttonOpts, gHeader, gButton, buttonIndex); | ||
|
||
Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args); | ||
|
@@ -315,8 +337,32 @@ function drawButtons(gd, gHeader, gButton, menuOpts) { | |
|
||
buttons.call(styleButtons, menuOpts); | ||
|
||
// translate button group | ||
Lib.setTranslate(gButton, menuOpts.lx, menuOpts.ly); | ||
scrollBox.enable(); | ||
|
||
var active = menuOpts.active, | ||
i; | ||
if(isVertical) { | ||
if(scrollBox._vbar) { | ||
var translateY = 0; | ||
for(i = 0; i < active; i++) { | ||
translateY += menuOpts.heights[i] + constants.gapButton; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks off for var direction = 'up',
data = [],
layout = {
updatemenus: [{
y: 0,
direction: direction,
buttons: []
}]
};
for (var i = 0, n = 20; i < n; i++) {
data.push({
y: Array.apply(null, Array(10)).map(() => Math.random()),
line: {
shape: 'spline',
color: 'red'
},
visible: i === 0,
name: 'Data set ' + i,
});
var visible = Array.apply(null, Array(n)).map((_, j) => i === j);
layout.updatemenus[0].buttons.push({
method: 'restyle',
args: ['visible', visible],
label: 'Data set ' + i
});
}
Plotly.plot('graph', data, layout); gives (after clicking on the header) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! The position of the scrollbox is wrong! This happens in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one hasn't been addressed yet, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking great now! |
||
} | ||
translateY -= constants.gapButton; | ||
|
||
scrollBox.setTranslate(0, translateY); | ||
} | ||
} | ||
else { | ||
if(scrollBox._hbar) { | ||
var translateX = 0; | ||
for(i = 0; i < active; i++) { | ||
translateX += menuOpts.widths[i] + constants.gapButton; | ||
} | ||
translateX -= constants.gapButton; | ||
|
||
scrollBox.setTranslate(translateX, 0); | ||
} | ||
} | ||
} | ||
|
||
function setActive(gd, menuOpts, buttonOpts, gHeader, gButton, buttonIndex, isSilentUpdate) { | ||
|
@@ -565,6 +611,11 @@ function setItemPosition(item, menuOpts, posOpts, overrideOpts) { | |
|
||
function removeAllButtons(gButton) { | ||
gButton.selectAll('g.' + constants.dropdownButtonClassName).remove(); | ||
|
||
// remove scrollbox | ||
gButton.selectAll('rect.scrollbar-horizontal').remove(); | ||
gButton.selectAll('rect.scrollbar-vertical').remove(); | ||
gButton.call(Drawing.setClipUrl, null); | ||
} | ||
|
||
function clearPushMargins(gd) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the scrollbox disappear after the button exit transition is completed (you can chain
.delay(1000)
to the transition to make the problem easier to detect).I would prefer making the scrollbox disappear at the same time as the buttons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good now 👍