8000 Introducing layout update menus (aka dropdowns) by etpinard · Pull Request #770 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Introducing layout update menus (aka dropdowns) #770

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 17 commits into from
Aug 3, 2016
Merged
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
Prev Previous commit
Next Next commit
DRY up button remove routine
  • Loading branch information
etpinard committed Aug 1, 2016
commit ca26892e61c92d6b825048c8177b5bfec05dfa22
26 changes: 16 additions & 10 deletions src/components/updatemenus/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ module.exports = function draw(gd) {
.classed(constants.buttonGroupClassName, true)
.style('pointer-events', 'all');

// whenever we add new menu,
// whenever we add new menu, attach 'state' variable to node
// to keep track of the active menu ('-1' means no menu is active)
// and remove all dropped buttons (if any)
if(headerGroups.enter().size()) {

// attach 'state' variable to node to keep track of the active menu
// '-1' means no menu is active
gButton.attr(constants.menuIndexAttrName, '-1');

// remove all dropped buttons (if any)
gButton.selectAll('g.' + constants.buttonClassName).remove();
gButton
.call(removeAllButtons)
.attr(constants.menuIndexAttrName, '-1');
}

// remove exiting header, remove dropped buttons and reset margins
headerGroups.exit().each(function(menuOpts) {
d3.select(this).remove();
gButton.selectAll('g.' + constants.buttonClassName).remove();

gButton
.call(removeAllButtons)
.attr(constants.menuIndexAttrName, '-1');

Plots.autoMargin(gd, constants.autoMarginIdRoot + menuOpts._index);
});

Expand Down Expand Up @@ -177,7 +179,7 @@ function drawHeader(gd, gHeader, gButton, menuOpts) {
});

header.on('click', function() {
gButton.selectAll('g.' + constants.buttonClassName).remove();
gButton.call(removeAllButtons);

// if clicked index is same as dropped index => fold
// otherwise => drop buttons associated with header
Expand Down Expand Up @@ -429,3 +431,7 @@ function setItemPosition(item, menuOpts, posOpts) {

posOpts.y += menuOpts.height1 + posOpts.yPad;
}

function removeAllButtons(gButton) {
gButton.selectAll('g.' + constants.buttonClassName).remove();
}
0