Skip to content

Commit d568610

Browse files
committed
fixup "opposite margin" piece of opts._maxWidth logic
1 parent df70ca4 commit d568610

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/components/legend/draw.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,15 @@ function computeLegendDimensions(gd, groups, traces) {
527527
var xanchor = getXanchor(opts);
528528
var isLeftOfPlotArea = opts.x < 0 || (opts.x === 0 && xanchor === 'right');
529529
var isRightOfPlotArea = opts.x > 1 || (opts.x === 1 && xanchor === 'left');
530+
var isBeyondPlotAreaX = isAbovePlotArea || isBelowPlotArea;
531+
var hw = fullLayout.width / 2;
530532

531533
// - if placed within x-margins, extend the width of the plot area
532-
// - else if below/above plot area, extend to opposite margin,
534+
// - else if below/above plot area and anchored in the margin, extend to opposite margin,
533535
// - otherwise give it the maximum potential margin-push value
534536
opts._maxWidth = opts.maxwidth || Math.max(
535-
isLeftOfPlotArea ? ((isAbovePlotArea || isBelowPlotArea) ? gs.l + gs.w : fullLayout.width / 2) :
536-
isRightOfPlotArea ? ((isAbovePlotArea || isBelowPlotArea) ? gs.r + gs.w : fullLayout.width / 2) :
537+
isLeftOfPlotArea ? ((isBeyondPlotAreaX && xanchor === 'left') ? gs.l + gs.w : hw) :
538+
isRightOfPlotArea ? ((isBeyondPlotAreaX && yanchor === 'right') ? gs.r + gs.w : hw) :
537539
gs.w,
538540
2 * textGap);
539541

Loading

0 commit comments

Comments
 (0)