Skip to content

Commit bb7311c

Browse files
committed
Merge branch 'master' into simplifying-font-attribute-docs
2 parents 7640e3e + bd35269 commit bb7311c

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

draftlogs/7359_add.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Allow configuration of horizontal legend max height [[#7359](https://github.com/plotly/plotly.js/pull/7359)]

src/components/legend/attributes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ module.exports = {
3333
editType: 'legend',
3434
description: 'Sets the color of the border enclosing the legend.'
3535
},
36+
maxheight: {
37+
valType: 'number',
38+
min: 0,
39+
editType: 'legend',
40+
description: [
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.'
46+
].join(' ')
47+
},
3648
borderwidth: {
3749
valType: 'number',
3850
min: 0,

src/components/legend/defaults.js

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

189189
coerce('xanchor', defaultXAnchor);
190190
coerce('yanchor', defaultYAnchor);
191+
coerce('maxheight', isHorizontal ? 0.5 : 1);
191192
coerce('valign');
192193
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
193194

src/components/legend/draw.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,12 +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 maximum potential margin-push value
773-
// - otherwise, extend the height of the plot area
774-
legendObj._maxHeight = Math.max(
775-
(isBelowPlotArea || isAbovePlotArea) ? fullLayout.height / 2 : gs.h,
776-
30
777-
);
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);
778775

779776
var toggleRectWidth = 0;
780777
legendObj._width = 0;

test/plot-schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,12 @@
34423442
"min": 30,
34433443
"valType": "number"
34443444
},
3445+
"maxheight": {
3446+
"description": "Sets the max height (in px) of the legend, or max height ratio (reference height * ratio) if less than one. Default value is: 0.5 for horizontal legends; 1 for vertical legends. The minimum allowed height is 30px. For a ratio of 0.5, the legend will take up to 50% of the reference height before displaying a scrollbar. The reference height is the full layout height except for vertically oriented legends with a `yref` of `\"paper\"`, where the reference height is the plot height.",
3447+
"editType": "legend",
3448+
"min": 0,
3449+
"valType": "number"
3450+
},
34453451
"orientation": {
34463452
"description": "Sets the orientation of the legend.",
34473453
"dflt": "v",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy