Skip to content

Commit 60fbfe1

Browse files
Nementoncamdecoster
authored andcommitted
components / legend / add hmaxheightratio, hmaxheight attributes
- Replace hardcoded horizontal legend max height ratio of 2 with user options (default is still 2).
1 parent 046d0ec commit 60fbfe1

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/components/legend/attributes.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ 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+
},
47+
hmaxheight: {
48+
valType: 'number',
49+
min: 0,
50+
role: 'style',
51+
editType: 'legend',
52+
description: 'Sets the max height (in px) of the horizontaly aligned legend.'
53+
},
3654
borderwidth: {
3755
valType: 'number',
3856
min: 0,

src/components/legend/defaults.js

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

189189
coerce('xanchor', defaultXAnchor);
190190
coerce('yanchor', defaultYAnchor);
191+
coerce('hmaxheightratio');
192+
coerce('hmaxheight');
191193
coerce('valign');
192194
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
193195

src/components/legend/draw.js

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

772-
// - if below/above plot area, give it the 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
774-
legendObj._maxHeight = Math.max(
775-
(isBelowPlotArea || isAbovePlotArea) ? fullLayout.height / 2 : gs.h,
776-
30
777-
);
774+
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 {
782+
legendObj._maxHeight = Math.max(gs.h, 30);
783+
}
778784

779785
var toggleRectWidth = 0;
780786
legendObj._width = 0;

0 commit comments

Comments
 (0)