Skip to content

feat(legend): support pager.hugContent to hug and center paged legend content#2097

Merged
skie1997 merged 1 commit into
VisActor:developfrom
g1f9:feat/legend-pager-hug-content
Jul 14, 2026
Merged

feat(legend): support pager.hugContent to hug and center paged legend content#2097
skie1997 merged 1 commit into
VisActor:developfrom
g1f9:feat/legend-pager-hug-content

Conversation

@g1f9

@g1f9 g1f9 commented Jul 14, 2026

Copy link
Copy Markdown

🤔 This is a ...

  • New feature

🔗 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 - pagerWidth for 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 (clipGroup in _renderPager) is created with the fixed size contentWidth = maxWidth - pagerWidth - pagerSpace and clip: 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 since boundsWidth always equals the full available width.

Solution. 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; when the content fills the available space it falls back to the original edge-pinned position (Math.min clamp);
  2. the paging clip viewport shrinks to the actual content extent (Math.min(contentWidth, itemsContainer.AABBBounds.width()), and the height counterpart for vertical layouts). Items wrap before contentWidth, 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:

const legend = new DiscreteLegend({
  layout: 'horizontal',
  maxWidth: 400,
  maxRow: 1,
  items,
  pager: { hugContent: true }
});

Before (default, unchanged): [item1 item2 < 1/3 >]
After (hugContent: true), with an outer centering layout: [ item1 item2 < 1/3 > ]

📝 Changelog

Language Changelog
🇺🇸 English feat(legend): add pager.hugContent for 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 to false (no behavior change).
🇨🇳 Chinese feat(legend): 离散图例新增 pager.hugContent 配置——翻页器紧跟最后一个图例项排布,同时分页视口收缩到实际内容尺寸,使「图例项 + 翻页器」的包围盒随内容自适应,便于外部布局整块居中。默认 false,不改变现有行为。

☑️ Self-Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

🚀 Summary

copilot:summary

🔍 Walkthrough

copilot:walkthrough

… 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.
@skie1997
skie1997 merged commit 2acfee2 into VisActor:develop Jul 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants