Skip to content

fix: Update legend maxheight calculation logic #7483

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions src/components/legend/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ module.exports = {
min: 0,
editType: 'legend',
description: [
'Sets the max height (in px) of the legend, or max height ratio (reference height * ratio) if less than one.',
'Sets the max height (in px) of the legend, or max height ratio (reference height * ratio) if less than or equal to 1.',
'Default value is: 0.5 for horizontal legends; 1 for vertical legends. The minimum allowed height is 30px.',
'For a ratio of 0.5, the legend will take up to 50% of the reference height before displaying a scrollbar.',
'The reference height is the full layout height except for vertically oriented legends with',
'a `yref` of `"paper"`, where the reference height is the plot height.'
'The reference height is the full layout height with the following exception: vertically oriented legends with',
'a `yref` of `"paper" located to the side of the plot. In this case, the reference height',
'is the plot height.'
].join(' ')
},
borderwidth: {
Expand Down Expand Up @@ -243,7 +244,7 @@ module.exports = {
values: ['auto', 'top', 'middle', 'bottom'],
editType: 'legend',
description: [
'Sets the legend\'s vertical position anchor',
'Sets the legend\'s vertical position anchor.',
'This anchor binds the `y` position to the *top*, *middle*',
'or *bottom* of the legend.',
'Value *auto* anchors legends at their bottom for `y` values less than or equal to 1/3,',
Expand Down
2 changes: 1 addition & 1 deletion src/components/legend/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {

coerce('xanchor', defaultXAnchor);
coerce('yanchor', defaultYAnchor);
coerce('maxheight', isHorizontal ? 0.5 : 1);
coerce('maxheight');
coerce('valign');
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);

Expand Down
8 changes: 6 additions & 2 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,12 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
var traceGroupGap = legendObj.tracegroupgap;
var legendGroupWidths = {};

var { maxheight, orientation, yref } = legendObj;
var heightToBeScaled = orientation === "v" && yref === "paper" ? gs.h : fullLayout.height;
const { orientation, yref } = legendObj;
let { maxheight } = legendObj;
const useFullLayoutHeight = (isBelowPlotArea || isAbovePlotArea) && !(orientation === "v" && yref === "paper")
// Set default maxheight here since it depends on values passed in by user
maxheight ||= useFullLayoutHeight ? 0.5 : 1;
const heightToBeScaled = useFullLayoutHeight ? fullLayout.height : gs.h;
legendObj._maxHeight = Math.max(maxheight > 1 ? maxheight : maxheight * heightToBeScaled, 30);

var toggleRectWidth = 0;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading