8000 Multiple legend positioning and sizing fixes by etpinard · Pull Request #4160 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Multiple legend positioning and sizing fixes #4160

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 20 commits into from
Sep 23, 2019
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
drop expandHorizontalMargin logic
... which doesn't appear to do anything,
   and mv computeLegendDimension to separate step
  • Loading branch information
etpinard committed Aug 30, 2019
commit f12c62c27c65156d836cbdbadf28cb543974ca14
37 changes: 4 additions & 33 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,17 @@ module.exports = function draw(gd) {
.call(style, gd)
.each(function() { d3.select(this).call(setupTraceToggle, gd); });

Lib.syncOrAsync([Plots.previousPromises,
Lib.syncOrAsync([
Plots.previousPromises,
function() { return computeLegendDimensions(gd, groups, traces); },
function() { return expandMargin(gd); },
function() {
// Position and size the legend
var lxMin = 0;
var lxMax = fullLayout.width;
var lyMin = 0;
var lyMax = fullLayout.height;

computeLegendDimensions(gd, groups, traces);

if(opts._height > lyMax) {
// If the legend doesn't fit in the plot area,
// do not expand the vertical margins.
expandHorizontalMargin(gd);
} else {
expandMargin(gd);
}

// Scroll section must be executed after repositionLegend.
// It requires the legend width, height, x and y to position the scrollbox
// and these values are mutated in repositionLegend.
Expand Down Expand Up @@ -689,25 +682,3 @@ function expandMargin(gd) {
t: opts._height * (FROM_TL[yanchor])
});
}

function expandHorizontalMargin(gd) {
var fullLayout = gd._fullLayout;
var opts = fullLayout.legend;

var xanchor = 'left';
if(Lib.isRightAnchor(opts)) {
xanchor = 'right';
} else if(Lib.isCenterAnchor(opts)) {
xanchor = 'center';
}

// lastly check if the margin auto-expand has changed
Plots.autoMargin(gd, 'legend', {
x: opts.x,
y: 0.5,
l: opts._width * (FROM_TL[xanchor]),
r: opts._width * (FROM_BR[xanchor]),
b: 0,
t: 0
});
}
0