feat: support function type for discrete legend maxRow / maxCol#4597
Open
g1f9 wants to merge 1 commit into
Open
feat: support function type for discrete legend maxRow / maxCol#4597g1f9 wants to merge 1 commit into
g1f9 wants to merge 1 commit into
Conversation
Allow a discrete legend's `maxRow` / `maxCol` to be a callback
`(ctx: { rect, orient, id }) => number`, evaluated during layout in
`getLegendAttributes` against the legend's allocated rect, so the row /
column count can adapt to the available space instead of a layout-blind
static number. Numeric values keep working unchanged.
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.
🔎 Background
The discrete legend's
maxRow/maxColcurrently only accept a fixednumber, decided before layout. There is no way to let the row / column count depend on the space actually allocated to the legend at layout time (e.g. "allow more rows when the legend area is tall and narrow"). A static, layout-blind number means the legend can paginate and hide items even when the available space could fit them — and it can't adapt on resize.✨ What's changed
maxRow/maxColof the discrete legend now also accept a callback:The callback is evaluated inside
getLegendAttributesduring layout, against the legend's allocatedrect, so the row / column count can adapt to the available space. Since it runs on every layout pass, it also re-evaluates on resize automatically.Fully backward compatible — numeric
maxRow/maxColpass through unchanged.🌈 Usage
✅ Test
Added
packages/vchart/__tests__/unit/component/legend/discrete-legend.test.ts:maxRowis evaluated against the layoutrect;maxColreceives{ rect, orient, id }in its context;maxRow/maxColkeep working unchanged.