Skip to content

Commit fb035f7

Browse files
committed
Switch to single attribute for controlling legend height
1 parent 60fbfe1 commit fb035f7

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/components/legend/attributes.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,17 @@ module.exports = {
3333
editType: 'legend',
3434
description: 'Sets the color of the border enclosing the legend.'
3535
},
36-
hmaxheightratio: {
37-
valType: 'number',
38-
min: 2,
39-
dflt: 2,
40-
role: 'style',
41-
editType: 'legend',
42-
description: [
43-
'Sets the max height ratio (layout / ratio) of the visible legend when horizontaly aligned.',
44-
'Default value is 2; the legend will take up to 50% of the layout height before displaying a scrollbar',
45-
].join(' ')
46-
},
4736
hmaxheight: {
4837
valType: 'number',
4938
min: 0,
39+
dflt: 0.5,
5040
role: 'style',
5141
editType: 'legend',
52-
description: 'Sets the max height (in px) of the horizontaly aligned legend.'
42+
description: [
43+
'If greater than one, it sets the max height (in px) of the horizontaly aligned legend.',
44+
'Otherwise, it sets the max height ratio (layout * ratio) of the visible legend when horizontaly aligned.',
45+
'Default value is 0.5; the legend will take up to 50% of the layout height before displaying a scrollbar'
46+
].join(' ')
5347
},
5448
borderwidth: {
5549
valType: 'number',

src/components/legend/defaults.js

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

189189
coerce('xanchor', defaultXAnchor);
190190
coerce('yanchor', defaultYAnchor);
191-
coerce('hmaxheightratio');
192191
coerce('hmaxheight');
193192
coerce('valign');
194193
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);

src/components/legend/draw.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,19 +769,25 @@ 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
772+
// - if below/above plot area, give it the user defined maximum potential margin-push value
773773
// - otherwise, extend the height of the plot area
774774
if (isBelowPlotArea || isAbovePlotArea) {
775-
if (legendObj.hmaxheight !== undefined) {
776-
legendObj._maxHeight = legendObj.hmaxheight;
777-
} else {
778-
legendObj._maxHeight = fullLayout.height / legendObj.hmaxheightratio;
779-
}
780-
}
781-
else {
775+
legendObj._maxHeight = legendObj.hmaxheight > 1
776+
? legendObj.hmaxheight
777+
: fullLayout.height * legendObj.hmaxheight;
778+
} else {
782779
legendObj._maxHeight = Math.max(gs.h, 30);
783780
}
784781

782+
console.log({
783+
isBelowPlotArea,
784+
isAbovePlotArea,
785+
hmaxheight: legendObj.hmaxheight,
786+
fullLayout_height: fullLayout.height,
787+
gs_h: gs.h,
788+
legendObj_maxHeight: legendObj._maxHeight
789+
})
790+
785791
var toggleRectWidth = 0;
786792
legendObj._width = 0;
787793
legendObj._height = 0;

0 commit comments

Comments
 (0)