-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Automargin fixes #2681
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
Automargin fixes #2681
Changes from 3 commits
970db80
26278de
6dd68bd
fa86147
95f9b33
8f3da82
f9fbbc6
222f396
bd07df7
84a5695
3deab4c
bb6c720
d02c76b
5d31324
16ea22a
24aeb7c
230a782
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 |
---|---|---|
|
@@ -54,6 +54,10 @@ module.exports = function draw(gd) { | |
* ... | ||
*/ | ||
|
||
function clearAutoMargin(menuOpts) { | ||
Plots.autoMargin(gd, autoMarginId(menuOpts)); | ||
} | ||
|
||
// draw update menu container | ||
var menus = fullLayout._menulayer | ||
.selectAll('g.' + constants.containerClassName) | ||
|
@@ -63,10 +67,15 @@ module.exports = function draw(gd) { | |
.classed(constants.containerClassName, true) | ||
.style('cursor', 'pointer'); | ||
|
||
menus.exit().remove(); | ||
|
||
// remove push margin object(s) | ||
if(menus.exit().size()) clearPushMargins(gd); | ||
menus.exit().each(function() { | ||
// Most components don't need to explicitly remove autoMargin, because | ||
// marginPushers does this - but updatemenu updates don't go through | ||
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. Why is this the case? Is it because updatemenus attributes are under 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. Oh man, I missed sliders in this PR but sure enough, they still have the older pattern - thanks, I'll take a look at those. 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. Updated sliders in 3deab4c |
||
// a full replot so we need to explicitly remove it. | ||
// This is for removing *all* updatemenus, removing individuals is | ||
// handled below, in hederGroups.exit | ||
d3.select(this).selectAll('g.' + constants.headerGroupClassName) | ||
.each(clearAutoMargin); | ||
}).remove(); | ||
|
||
// return early if no update menus are visible | ||
if(menuData.length === 0) return; | ||
|
@@ -97,21 +106,13 @@ module.exports = function draw(gd) { | |
if(headerGroups.enter().size()) { | ||
// make sure gButton is on top of all headers | ||
gButton.node().parentNode.appendChild(gButton.node()); | ||
|
||
gButton | ||
.call(removeAllButtons) | ||
.attr(constants.menuIndexAttrName, '-1'); | ||
gButton.call(removeAllButtons); | ||
} | ||
|
||
headerGroups.exit().each(function(menuOpts) { | ||
d3.select(this).remove(); | ||
|
||
gButton | ||
.call(removeAllButtons) | ||
.attr(constants.menuIndexAttrName, '-1'); | ||
|
||
Plots.autoMargin(gd, constants.autoMarginIdRoot + menuOpts._index); | ||
}); | ||
gButton.call(removeAllButtons); | ||
clearAutoMargin(menuOpts); | ||
}).remove(); | ||
|
||
// draw headers! | ||
headerGroups.each(function(menuOpts) { | ||
|
@@ -219,16 +220,8 @@ function drawHeader(gd, gHeader, gButton, scrollBox, menuOpts) { | |
}); | ||
|
||
header.on('click', function() { | ||
gButton.call(removeAllButtons); | ||
|
||
|
||
// if this menu is active, fold the dropdown container | ||
// otherwise, make this menu active | ||
gButton.attr( | ||
constants.menuIndexAttrName, | ||
isActive(gButton, menuOpts) ? | ||
-1 : | ||
String(menuOpts._index) | ||
gButton.call(removeAllButtons, | ||
String(isActive(gButton, menuOpts) ? -1 : menuOpts._index) | ||
); | ||
|
||
drawButtons(gd, gHeader, gButton, scrollBox, menuOpts); | ||
|
@@ -608,7 +601,7 @@ function findDimensions(gd, menuOpts) { | |
dims.lx = Math.round(dims.lx); | ||
dims.ly = Math.round(dims.ly); | ||
|
||
Plots.autoMargin(gd, constants.autoMarginIdRoot + menuOpts._index, { | ||
Plots.autoMargin(gd, autoMarginId(menuOpts), { | ||
x: menuOpts.x, | ||
y: menuOpts.y, | ||
l: paddedWidth * ({right: 1, center: 0.5}[xanchor] || 0), | ||
|
@@ -618,6 +611,10 @@ function findDimensions(gd, menuOpts) { | |
}); | ||
} | ||
|
||
function autoMarginId(menuOpts) { | ||
return constants.autoMarginIdRoot + menuOpts._index; | ||
} | ||
|
||
// set item positions (mutates posOpts) | ||
function setItemPosition(item, menuOpts, posOpts, overrideOpts) { | ||
overrideOpts = overrideOpts || {}; | ||
|
@@ -655,19 +652,8 @@ function setItemPosition(item, menuOpts, posOpts, overrideOpts) { | |
posOpts.index++; | ||
} | ||
|
||
function removeAllButtons(gButton) { | ||
gButton.selectAll('g.' + constants.dropdownButtonClassName).remove(); | ||
} | ||
|
||
function clearPushMargins(gd) { | ||
var pushMargins = gd._fullLayout._pushmargin || {}; | ||
var keys = Object.keys(pushMargins); | ||
|
||
for(var i = 0; i < keys.length; i++) { | ||
var k = keys[i]; | ||
|
||
if(k.indexOf(constants.autoMarginIdRoot) !== -1) { | ||
Plots.autoMargin(gd, k); | ||
} | ||
} | ||
function removeAllButtons(gButton, newMenuIndexAttr) { | ||
gButton | ||
.attr(constants.menuIndexAttrName, newMenuIndexAttr || '-1') | ||
.selectAll('g.' + constants.dropdownButtonClassName).remove(); | ||
} |
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.
Ha
exit().each()
returns the exit selection, good to know.