From f98d1063bc8e93b05c403f57548f9e719a548ed0 Mon Sep 17 00:00:00 2001 From: Nementon Date: Fri, 28 Aug 2020 17:59:12 +0200 Subject: [PATCH] components / legend / add `hmaxheightratio`, `hmaxheight` attributes - Replace hardcoded horizontal legend max height ratio of 2 with user options (default is still 2). --- src/components/legend/attributes.js | 18 ++++++++++++++++++ src/components/legend/defaults.js | 2 ++ src/components/legend/draw.js | 16 +++++++++++----- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/components/legend/attributes.js b/src/components/legend/attributes.js index 8e2456ef157..6ca46e24425 100644 --- a/src/components/legend/attributes.js +++ b/src/components/legend/attributes.js @@ -29,6 +29,24 @@ module.exports = { editType: 'legend', description: 'Sets the color of the border enclosing the legend.' }, + hmaxheightratio: { + valType: 'number', + min: 2, + dflt: 2, + role: 'style', + editType: 'legend', + description: [ + 'Sets the max height ratio (layout / ratio) of the visible legend when horizontaly aligned.', + 'Default value is 2; the legend will take up to 50% of the layout height before displaying a scrollbar', + ].join(' ') + }, + hmaxheight: { + valType: 'number', + min: 0, + role: 'style', + editType: 'legend', + description: 'Sets the max height (in px) of the horizontaly aligned legend.' + }, borderwidth: { valType: 'number', min: 0, diff --git a/src/components/legend/defaults.js b/src/components/legend/defaults.js index 9077a1e7890..d12db824781 100644 --- a/src/components/legend/defaults.js +++ b/src/components/legend/defaults.js @@ -121,6 +121,8 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) { coerce('xanchor'); coerce('y', defaultY); coerce('yanchor', defaultYAnchor); + coerce('hmaxheightratio'); + coerce('hmaxheight'); coerce('valign'); Lib.noneOrAll(containerIn, containerOut, ['x', 'y']); diff --git a/src/components/legend/draw.js b/src/components/legend/draw.js index 940c6a9c721..880ded228e9 100644 --- a/src/components/legend/draw.js +++ b/src/components/legend/draw.js @@ -602,12 +602,18 @@ function computeLegendDimensions(gd, groups, traces, opts) { var isBelowPlotArea = opts.y < 0 || (opts.y === 0 && yanchor === 'top'); var isAbovePlotArea = opts.y > 1 || (opts.y === 1 && yanchor === 'bottom'); - // - if below/above plot area, give it the maximum potential margin-push value + // - if below/above plot area, give it the [user defined] maximum potential margin-push value // - otherwise, extend the height of the plot area - opts._maxHeight = Math.max( - (isBelowPlotArea || isAbovePlotArea) ? fullLayout.height / 2 : gs.h, - 30 - ); + if (isBelowPlotArea || isAbovePlotArea) { + if (opts.hmaxheight !== undefined) { + opts._maxHeight = opts.hmaxheight; + } else { + opts._maxHeight = fullLayout.height / opts.hmaxheightratio; + } + } + else { + opts._maxHeight = Math.max(gs.h, 30); + } var toggleRectWidth = 0; opts._width = 0;