Skip to content

Commit 6fc4dd6

Browse files
committed
components / legend / add hmaxheightratio, hmaxheightratio attributes
- Replace hardcoded horizontal legend max height ratio of 2 with user options (default is still 2).
1 parent 4ac68aa commit 6fc4dd6

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/components/legend/attributes.js

+18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ module.exports = {
2929
editType: 'legend',
3030
description: 'Sets the color of the border enclosing the legend.'
3131
},
32+
hmaxheightratio: {
33+
valType: 'number',
34+
min: 2,
35+
dflt: 2,
36+
role: 'style',
37+
editType: 'legend',
38+
description: [
39+
'Sets the max height ratio (layout / ratio) of the visible legend when horizontaly aligned.',
40+
'Default value is 2; the legend will take up to 50% of the layout height before displaying a scrollbar',
41+
].join(' ')
42+
},
43+
hmaxheight: {
44+
valType: 'number',
45+
min: 0,
46+
role: 'style',
47+
editType: 'legend',
48+
description: 'Sets the max height (in px) of the horizontaly aligned legend.'
49+
},
3250
borderwidth: {
3351
valType: 'number',
3452
min: 0,

src/components/legend/defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
121121
coerce('xanchor');
122122
coerce('y', defaultY);
123123
coerce('yanchor', defaultYAnchor);
124+
coerce('hmaxheightratio');
125+
coerce('hmaxheight');
124126
coerce('valign');
125127
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
126128

src/components/legend/draw.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,18 @@ function computeLegendDimensions(gd, groups, traces, opts) {
602602
var isBelowPlotArea = opts.y < 0 || (opts.y === 0 && yanchor === 'top');
603603
var isAbovePlotArea = opts.y > 1 || (opts.y === 1 && yanchor === 'bottom');
604604

605-
// - if below/above plot area, give it the maximum potential margin-push value
605+
// - if below/above plot area, give it the [user defined] maximum potential margin-push value
606606
// - otherwise, extend the height of the plot area
607-
opts._maxHeight = Math.max(
608-
(isBelowPlotArea || isAbovePlotArea) ? fullLayout.height / 2 : gs.h,
609-
30
610-
);
607+
if (isBelowPlotArea || isAbovePlotArea) {
608+
if (opts.hmaxheight !== undefined) {
609+
opts._maxHeight = opts.hmaxheight;
610+
} else {
611+
opts._maxHeight = fullLayout.height / opts.hmaxheightratio;
612+
}
613+
}
614+
else {
615+
opts._maxHeight = Math.max(gs.h, 30);
616+
}
611617

612618
var toggleRectWidth = 0;
613619
opts._width = 0;

0 commit comments

Comments
 (0)