feat(legend): add "list" layout for horizontal legends#2784
Open
maryam-saeidi wants to merge 52 commits intoelastic:mainfrom
Open
feat(legend): add "list" layout for horizontal legends#2784maryam-saeidi wants to merge 52 commits intoelastic:mainfrom
maryam-saeidi wants to merge 52 commits intoelastic:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new "list" layout option for chart legends to improve space efficiency and usability when displaying many data series. The list layout is now the default for legends positioned at the top or bottom, while maintaining backward compatibility through an optional legendLayout prop that allows users to switch between list and table views.
Changes:
- Added new
LegendLayoutenum withListandTableoptions as a public API - Implemented list-based legend rendering with horizontal wrapping for top/bottom positions
- Enhanced label truncation to support both line-based and pixel-based width limits
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/charts/src/utils/common.tsx | Defines new LegendLayout enum and Layout type |
| packages/charts/src/specs/settings.tsx | Adds legendLayout prop to LegendSpec interface |
| packages/charts/src/utils/themes/theme.ts | Extends LegendLabelOptions with widthLimit property and makes maxLines optional |
| packages/charts/src/components/legend/legend.tsx | Updates rendering logic to conditionally render grid list or list layout |
| packages/charts/src/components/legend/legend_item_list.tsx | New component implementing horizontal list layout for legends |
| packages/charts/src/components/legend/label.tsx | Enhances label truncation with pixel-based width limiting |
| packages/charts/src/common/legend.ts | Adds logic to determine when to display table vs grid list vs list layouts |
| packages/charts/src/state/selectors/get_legend_size.ts | Improves legend height calculation for multi-row list layouts |
| storybook/stories/legend/2_legend_layout.story.tsx | New story demonstrating the legend layout feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
buildkite update vrt |
maryam-saeidi
commented
Feb 9, 2026
Member
Author
|
buildkite update vrt |
Member
Author
|
buildkite update vrt |
Member
Author
|
buildkite update vrt |
Member
Author
|
buildkite update vrt |
maryam-saeidi
commented
Feb 17, 2026
Collaborator
|
buildkite build this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A new List legend layout is now available for horizontal legends (top/bottom), offering a more space-efficient alternative to the existing GridList/Table layout. In the list layout each legend item flows inline — label, color marker, and values are arranged in a compact row that wraps naturally, making it easier to scan many series without excessive scrolling.
The list layout supports all standard legend features: series highlighting, filtering via actions,
CurrentAndLastValuedisplay with stable column widths, and label truncation.Example usage
Demo
Screen.Recording.2026-02-17.at.10.40.26.mov
Details
Layout & rendering
legendLayout: 'list'option to theSettingsspec, enabling the list layout for horizontal legendsLegendListcomponent (legend_list.tsx) that renders legend items as inline<li>elements with label, color, values, and optional action grouped togetherCurrentAndLastValueshows a—placeholder when no value is available (e.g. on hover)theme.legend.labelOptions.widthLimit)Stable column widths
getLegendMaxFormattedValueto theChartSelectorsinterface, allowing each chart type to provide the longest formatted Y domain valuewithTextMeasure) and used asminWidthonCurrentAndLastValuecells, preventing layout shift on hoverLegend sizing
computeHorizontalLegendRowCountutility that measures items and lays them out greedily row-by-row to determine if the legend fits in 1, 2, or 3+ rows — short-circuiting as soon as a third row is reachedshouldDisplayGridListandshouldDisplayTablehelpers to select the correct layout mode based on legend values, position, and layout configOther
_legend.scss→_legend_grid_list.scssfor clarity2_legend_layout.story.tsx)computeHorizontalLegendRowCountand theshouldDisplay*helpersIssues
Related to elastic/kibana#238777
Checklist
:interactions,:axis)closes #123,fixes #123)packages/charts/src/index.tslightanddarkthemes🤖 This pull request was assisted by Cursor