Skip to content

Commit c917381

Browse files
committed
Fix a couple updatemenus anchor cases
1 parent 97e05c6 commit c917381

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

src/components/updatemenus/draw.js

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ function drawButtons(gd, gHeader, gButton, menuOpts) {
266266

267267
if(menuOpts.type === 'dropdown' && menuOpts.openreverse) {
268268
if(menuOpts.orientation === 'v') {
269-
y0 = -2 * constants.gapButtonHeader - constants.gapButton - menuOpts.totalHeight;
269+
y0 = -2 * constants.gapButtonHeader - constants.gapButton - menuOpts.openHeight;
270270
} else {
271-
x0 = -2 * constants.gapButtonHeader - constants.gapButton - menuOpts.totalWidth;
271+
x0 = -2 * constants.gapButtonHeader - constants.gapButton - menuOpts.openWidth;
272272
}
273273
}
274274

@@ -384,14 +384,14 @@ function styleOnMouseOut(item, menuOpts) {
384384
function findDimenstions(gd, menuOpts) {
385385
var i;
386386

387-
menuOpts.width = 0;
388387
menuOpts.width1 = 0;
389-
menuOpts.height = 0;
390388
menuOpts.height1 = 0;
391389
menuOpts.heights = [];
392390
menuOpts.widths = [];
393391
menuOpts.totalWidth = 0;
394392
menuOpts.totalHeight = 0;
393+
menuOpts.openWidth = 0;
394+
menuOpts.openHeight = 0;
395395
menuOpts.lx = 0;
396396
menuOpts.ly = 0;
397397

@@ -424,41 +424,32 @@ function findDimenstions(gd, menuOpts) {
424424
menuOpts.widths[i] = wEff;
425425
menuOpts.heights[i] = hEff;
426426

427-
if(menuOpts.orientation === 'v' | menuOpts.type === 'dropdown') {
428-
menuOpts.width = Math.max(menuOpts.width, wEff);
429-
} else {
430-
menuOpts.width += wEff;
431-
}
432427
// Height and width of individual element:
433428
menuOpts.height1 = Math.max(menuOpts.height1, hEff);
434429
menuOpts.width1 = Math.max(menuOpts.width1, wEff);
435430

436431
if(menuOpts.orientation === 'v') {
437432
menuOpts.totalWidth = Math.max(menuOpts.totalWidth, wEff);
433+
menuOpts.openWidth = menuOpts.totalWidth;
438434
menuOpts.totalHeight += hEff;
435+
menuOpts.openHeight += hEff;
439436
} else {
440437
menuOpts.totalWidth += wEff;
441-
menuOpts.totalHeight += Math.max(menuOpts.totalWidth, hEff);
438+
menuOpts.openWidth += wEff;
439+
menuOpts.totalHeight = Math.max(menuOpts.totalHeight, hEff);
440+
menuOpts.openHeight = menuOpts.totalHeight;
442441
}
443442
});
444443

445444
menuOpts.headerWidth = menuOpts.width1 + constants.arrowPadX;
446445
menuOpts.headerHeight = menuOpts.height1;
447446

448-
if(menuOpts.orientation === 'v') {
449-
menuOpts.width = menuOpts.width1;
450-
451-
if(menuOpts.type === 'dropdown') {
447+
if(menuOpts.type === 'dropdown') {
448+
if(menuOpts.orientation === 'v') {
452449
menuOpts.width1 += constants.arrowPadX;
453-
}
454-
455-
for(i = 0; i < menuOpts.heights; i++) {
456-
menuOpts.height += menuOpts.heights[i];
457-
}
458-
} else {
459-
menuOpts.height = menuOpts.height1;
460-
for(i = 0; i < menuOpts.heights; i++) {
461-
menuOpts.width += menuOpts.width[i];
450+
menuOpts.totalHeight = menuOpts.height1;
451+
} else {
452+
menuOpts.totalWidth = menuOpts.width1;
462453
}
463454
}
464455

@@ -470,37 +461,39 @@ function findDimenstions(gd, menuOpts) {
470461

471462
var xanchor = 'left';
472463
if(anchorUtils.isRightAnchor(menuOpts)) {
473-
menuOpts.lx -= menuOpts.width;
464+
menuOpts.lx -= menuOpts.totalWidth;
474465
xanchor = 'right';
475466
}
476467
if(anchorUtils.isCenterAnchor(menuOpts)) {
477-
menuOpts.lx -= menuOpts.width / 2;
468+
menuOpts.lx -= menuOpts.totalWidth / 2;
478469
xanchor = 'center';
479470
}
480471

481472
var yanchor = 'top';
482473
if(anchorUtils.isBottomAnchor(menuOpts)) {
483-
menuOpts.ly -= menuOpts.height;
474+
menuOpts.ly -= menuOpts.totalHeight;
484475
yanchor = 'bottom';
485476
}
486477
if(anchorUtils.isMiddleAnchor(menuOpts)) {
487-
menuOpts.ly -= menuOpts.height / 2;
478+
menuOpts.ly -= menuOpts.totalHeight / 2;
488479
yanchor = 'middle';
489480
}
490481

491-
menuOpts.width = Math.ceil(menuOpts.width);
492-
menuOpts.height = Math.ceil(menuOpts.height);
482+
menuOpts.totalWidth = Math.ceil(menuOpts.totalWidth);
483+
menuOpts.totalHeight = Math.ceil(menuOpts.totalHeight);
493484
menuOpts.lx = Math.round(menuOpts.lx);
494485
menuOpts.ly = Math.round(menuOpts.ly);
495486

496487
Plots.autoMargin(gd, constants.autoMarginIdRoot + menuOpts._index, {
497488
x: menuOpts.x,
498489
y: menuOpts.y,
499-
l: menuOpts.width * ({right: 1, center: 0.5}[xanchor] || 0),
500-
r: menuOpts.width * ({left: 1, center: 0.5}[xanchor] || 0),
501-
b: menuOpts.height * ({top: 1, middle: 0.5}[yanchor] || 0),
502-
t: menuOpts.height * ({bottom: 1, middle: 0.5}[yanchor] || 0)
490+
l: menuOpts.totalWidth * ({right: 1, center: 0.5}[xanchor] || 0),
491+
r: menuOpts.totalWidth * ({left: 1, center: 0.5}[xanchor] || 0),
492+
b: menuOpts.totalHeight * ({top: 1, middle: 0.5}[yanchor] || 0),
493+
t: menuOpts.totalHeight * ({bottom: 1, middle: 0.5}[yanchor] || 0)
503494
});
495+
496+
console.log('menuOpts:', menuOpts);
504497
}
505498

506499
// set item positions (mutates posOpts)

0 commit comments

Comments
 (0)