Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend sizing fails on long legend labels #2196

Open
nickofthyme opened this issue Oct 12, 2023 · 0 comments
Open

Legend sizing fails on long legend labels #2196

nickofthyme opened this issue Oct 12, 2023 · 0 comments
Assignees
Labels
bug Something isn't working kibana cross issue Has a Kibana issue counterpart :legend Legend related issue :Lens Kibana Lens related issue

Comments

@nickofthyme
Copy link
Collaborator

Describe the issue

Creating a chart with a legend that contains one or more labels that are very long, the Settings.legendSize prop is not handled as expected. The size is limited by 30% of the max label width.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/long-legend-sizing-xq2sky?file=/src/App.tsx
  2. Change the Settings.legendSize prop and notice with the very long label the size is ignored.

Expected behaviour
Legend size is limited to the provided size

Screenshots

Screen.Recording.2023-10-12.at.11.39.46.AM.mp4

Additional Context

if (legendPosition.direction === LayoutDirection.Vertical) {
const legendItemHeight = bbox.height + VERTICAL_PADDING * 2;
const legendHeight = legendItemHeight * labels.length + TOP_MARGIN;
const scrollBarDimension = legendHeight > parentDimensions.height ? SCROLL_BAR_WIDTH : 0;
const staticWidth = spacingBuffer + actionDimension + scrollBarDimension;
const width = Number.isFinite(legendConfig.legendSize)
? Math.min(Math.max(legendConfig.legendSize, legendItemWidth * 0.3 + staticWidth), parentDimensions.width * 0.7)
: Math.floor(Math.min(legendItemWidth + staticWidth, verticalWidth));
return {
width,
height: legendHeight,
margin,
position: legendPosition,
};
}

The main issue of the logic is at line 76 in which we clamp the width based on size of the labels. I think we are missing a check on when to use the constraints as an upper or lower bound, need to dig a little deeper.

@nickofthyme nickofthyme added bug Something isn't working kibana cross issue Has a Kibana issue counterpart :legend Legend related issue :Lens Kibana Lens related issue labels Oct 12, 2023
@nickofthyme nickofthyme self-assigned this Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kibana cross issue Has a Kibana issue counterpart :legend Legend related issue :Lens Kibana Lens related issue
Projects
None yet
Development

No branches or pull requests

1 participant