feat(legend): support pager.hugContent to hug and center paged legend content#2097
Merged
Merged
Conversation
… content By default the discrete legend pins its pager to the far end of the available legend space while items stay at the start, so a paged legend always renders justified (items left, pager right) and its bounds always occupy the full available width/height. Add an opt-in pager.hugContent option (default false, fully backward compatible). When enabled: 1. the pager is placed right after the last legend item (with pager.space as the gap), falling back to the original edge-pinned position when the content fills the available space; 2. the paging clip viewport shrinks to the actual content extent, so the legend bounds hug "items + pager" instead of being pinned at the full available size by the fixed-size clip group. With the bounds hugging the content, outer layouts (e.g. VChart legend position 'middle') can center the whole block, matching the common "content + pager centered together" legend layout.
5 tasks
skie1997
approved these changes
Jul 14, 2026
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.
🤔 This is a ...
🔗 Related issue link
N/A
🐞 Bugserver case id
N/A
💡 Background and solution
Problem. When a discrete legend paginates, the pager is pinned to the far end of the available legend space (
_updatePositionOfPager:x = compWidth - pagerWidthfor horizontal layouts), while the items stay at the start. The paged legend therefore always renders justified — items on the left, pager on the right — and its AABB always occupies the full available width, because the paging clip viewport (clipGroupin_renderPager) is created with the fixed sizecontentWidth = maxWidth - pagerWidth - pagerSpaceandclip: true, which pins the component bounds regardless of the actual content extent.This makes it impossible for outer layouts to center "items + pager" as one block — a very common legend design (the whole paged legend centered under the chart). For example, VChart's legend
position: 'middle'centering (offsetX = (rectWidth - boundsWidth) / 2) becomes a no-op for paged legends sinceboundsWidthalways equals the full available width.Solution. Add an opt-in
pager.hugContentoption (defaultfalse, fully backward compatible). When enabled:pager.spaceas the gap; when the content fills the available space it falls back to the original edge-pinned position (Math.minclamp);Math.min(contentWidth, itemsContainer.AABBBounds.width()), and the height counterpart for vertical layouts). Items wrap beforecontentWidth, so shrinking the viewport never clips content.With both applied, the legend bounds hug "items + pager", and outer layouts can center the whole block.
Usage:
Before (default, unchanged):
[item1 item2 < 1/3 >]After (
hugContent: true), with an outer centering layout:[ item1 item2 < 1/3 > ]📝 Changelog
pager.hugContentfor discrete legend — place the pager right after the last item and shrink the paging viewport to the content extent, so the paged legend bounds hug "items + pager" and outer layouts can center the whole block. Defaults tofalse(no behavior change).pager.hugContent配置——翻页器紧跟最后一个图例项排布,同时分页视口收缩到实际内容尺寸,使「图例项 + 翻页器」的包围盒随内容自适应,便于外部布局整块居中。默认false,不改变现有行为。☑️ Self-Check before Merge
🚀 Summary
copilot:summary
🔍 Walkthrough
copilot:walkthrough