8000 feat: Allow configuration of horizontal legend max height by camdecoster · Pull Request #7359 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

feat: Allow configuration of horizontal legend max height #7359

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 12 commits into from
Mar 6, 2025
Prev Previous commit
Next Next commit
Switch to single attribute for controlling legend height
  • Loading branch information
camdecoster committed Feb 8, 2025
commit fb035f7420d0c4604f4ca867eae4fdb631286482
18 changes: 6 additions & 12 deletions src/components/legend/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,17 @@ module.exports = {
editType: 'legend',
description: 'Sets the color of the border enclosing the legend.'
},
hmaxheightratio: {
valType: 'number',
min: 2,
dflt: 2,
role: 'style',
editType: 'legend',
description: [
'Sets the max height ratio (layout / ratio) of the visible legend when horizontaly aligned.',
'Default value is 2; the legend will take up to 50% of the layout height before displaying a scrollbar',
].join(' ')
},
hmaxheight: {
valType: 'number',
min: 0,
dflt: 0.5,
role: 'style',
editType: 'legend',
description: 'Sets the max height (in px) of the horizontaly aligned legend.'
description: [
'If greater than one, it sets the max height (in px) of the horizontaly aligned legend.',
'Otherwise, it sets the max height ratio (layout * ratio) of the visible legend when horizontaly aligned.',
'Default value is 0.5; the legend will take up to 50% of the layout height before displaying a scrollbar'
].join(' ')
},
borderwidth: {
valType: 'number',
Expand Down
1 change: 0 additions & 1 deletion src/components/legend/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {

coerce('xanchor', defaultXAnchor);
coerce('yanchor', defaultYAnchor);
coerce('hmaxheightratio');
coerce('hmaxheight');
coerce('valign');
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
Expand Down
22 changes: 14 additions & 8 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,19 +769,25 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
var traceGroupGap = legendObj.tracegroupgap;
var legendGroupWidths = {};

// - if below/above plot area, give it the [user defined] maximum potential margin-push value
// - if below/above plot area, give it the user defined maximum potential margin-push value
// - otherwise, extend the height of the plot area
if (isBelowPlotArea || isAbovePlotArea) {
if (legendObj.hmaxheight !== undefined) {
legendObj._maxHeight = legendObj.hmaxheight;
} else {
legendObj._maxHeight = fullLayout.height / legendObj.hmaxheightratio;
}
}
else {
legendObj._maxHeight = legendObj.hmaxheight > 1
? legendObj.hmaxheight
: fullLayout.height * legendObj.hmaxheight;
} else {
legendObj._maxHeight = Math.max(gs.h, 30);
}

console.log({
isBelowPlotArea,
isAbovePlotArea,
hmaxheight: legendObj.hmaxheight,
fullLayout_height: fullLayout.height,
gs_h: gs.h,
legendObj_maxHeight: legendObj._maxHeight
})

var toggleRectWidth = 0;
legendObj._width = 0;
legendObj._height = 0;
Expand Down
0