Skip to content

[WIP] scrollable dropdown menus #8

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 15, 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
23 changes: 19 additions & 4 deletions src/components/updatemenus/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -281,13 +282,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,
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);

Expand All @@ -296,10 +307,15 @@ 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);

scrollBox.disable();

gd.emit('plotly_buttonclicked', {menu: menuOpts, button: buttonOpts, active: menuOpts.active});
});

Expand All @@ -315,8 +331,7 @@ function drawButtons(gd, gHeader, gButton, menuOpts) {

buttons.call(styleButtons, menuOpts);

// translate button group
Lib.setTranslate(gButton, menuOpts.lx, menuOpts.ly);
scrollBox.enable();
}

function setActive(gd, menuOpts, buttonOpts, gHeader, gButton, buttonIndex, isSilentUpdate) {
Expand Down
Loading