Skip to content

Commit 1f55078

Browse files
committed
Make maxheight apply to horizontal and vertical legends
1 parent b61970f commit 1f55078

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/components/legend/attributes.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ module.exports = {
3333
editType: 'legend',
3434
description: 'Sets the color of the border enclosing the legend.'
3535
},
36-
hmaxheight: {
36+
maxheight: {
3737
valType: 'number',
3838
min: 0,
39-
dflt: 0.5,
4039
editType: 'legend',
4140
description: [
42-
'If greater than one, it sets the max height (in px) of the horizontaly aligned legend.',
43-
'Otherwise, it sets the max height ratio (layout * ratio) of the visible legend when horizontaly aligned.',
44-
'Default value is 0.5; the legend will take up to 50% of the layout height before displaying a scrollbar.'
41+
'Sets the max height (in px) of the legend, or max height ratio (reference height * ratio) if less than one.',
42+
'Default value is: 0.5 for horizontal legends; 1 for vertical legends. The minimum allowed height is 30px.',
43+
'For a ratio of 0.5, the legend will take up to 50% of the reference height before displaying a scrollbar.',
44+
'The reference height is the full layout height except for vertically oriented legends with',
45+
'a `yref` of `"paper"`, where the reference height is the plot height.'
4546
].join(' ')
4647
},
4748
borderwidth: {

src/components/legend/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
188188

189189
coerce('xanchor', defaultXAnchor);
190190
coerce('yanchor', defaultYAnchor);
191-
coerce('hmaxheight');
191+
coerce('maxheight', isHorizontal ? 0.5 : 1);
192192
coerce('valign');
193193
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
194194

src/components/legend/draw.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,9 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
769769
var traceGroupGap = legendObj.tracegroupgap;
770770
var legendGroupWidths = {};
771771

772-
// - if below/above plot area, give it the user defined maximum potential margin-push value
773-
// - otherwise, extend the height of the plot area
774-
if (isBelowPlotArea || isAbovePlotArea) {
775-
legendObj._maxHeight = legendObj.hmaxheight > 1
776-
? legendObj.hmaxheight
777-
: fullLayout.height * legendObj.hmaxheight;
778-
} else {
779-
legendObj._maxHeight = Math.max(gs.h, 30);
780-
}
772+
var { maxheight, orientation, yref } = legendObj;
773+
var heightToBeScaled = orientation === "v" && yref === "paper" ? gs.h : fullLayout.height;
774+
legendObj._maxHeight = Math.max(maxheight > 1 ? maxheight : maxheight * heightToBeScaled, 30);
781775

782776
var toggleRectWidth = 0;
783777
legendObj._width = 0;

0 commit comments

Comments
 (0)