Skip to content

Legend cannot be scrolled to the end if xref/yref is set to container #7072

Open
@attatrol

Description

@attatrol

If a legend is anchored to the container, the container sizes aren't taken into account when the legend sizes are computed.

In the example codepen legends aren't visible fully and it is not possible to scroll then to the end.

function computeLegendDimensions should take into account the container sizes for calculation of _maxHeight and _maxWidth

Activity

attatrol

attatrol commented on Aug 6, 2024

@attatrol
Author

My fix for _maxHeight calculation:

  // - if below/above plot area, give it the maximum potential margin-push value
  // - otherwise, extend the height of the plot area
  legendObj._maxHeight = Math.max(
    (isBelowPlotArea || isAbovePlotArea) ? fullLayout.height / 2 : gs.h,
    30
  );
  // _maxHeight is also limited by the container if it is anchored to it
  if (legendObj.yref === 'container' && legendObj._maxHeight > 30) {
    var yanchor = getYanchor(legendObj);
    var containerAllowedHeight;
    if (yanchor === 'top')
      containerAllowedHeight = legendObj.y * fullLayout.height;
    else if (yanchor === 'bottom')
      containerAllowedHeight = (1 - legendObj.y) * fullLayout.height;
    else // if (yanchor === 'middle')
      containerAllowedHeight = 2 * Math.min(1 - legendObj.y, legendObj.y) * fullLayout.height;
    legendObj._maxHeight = Math.min(containerAllowedHeight, legendObj._maxHeight);
  }
added
bugsomething broken
P2considered for next cycle
on Aug 7, 2024
linked a pull request that will close this issue on Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclebugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @gvwilson@attatrol

      Issue actions

        Legend cannot be scrolled to the end if `xref`/`yref` is set to `container` · Issue #7072 · plotly/plotly.js