Skip to content

feat: support function type for discrete legend maxRow / maxCol#4597

Open
g1f9 wants to merge 1 commit into
VisActor:developfrom
g1f9:feat/discrete-legend-maxrow-maxcol-function
Open

feat: support function type for discrete legend maxRow / maxCol#4597
g1f9 wants to merge 1 commit into
VisActor:developfrom
g1f9:feat/discrete-legend-maxrow-maxcol-function

Conversation

@g1f9

@g1f9 g1f9 commented Jun 19, 2026

Copy link
Copy Markdown

🔎 Background

The discrete legend's maxRow / maxCol currently only accept a fixed number, 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 / maxCol of the discrete legend now also accept a callback:

type DiscreteLegendArrangeCount =
  | number
  | ((ctx: { rect: ILayoutRect; orient?: IOrientType; id?: StringOrNumber }) => number);

The callback is evaluated inside getLegendAttributes during layout, against the legend's allocated rect, 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 / maxCol pass through unchanged.

🌈 Usage

legends: {
  type: 'discrete',
  orient: 'bottom',
  // allow as many rows as roughly fit 25% of the legend's available height
  maxRow: ({ rect }) => Math.max(1, Math.floor((rect.height * 0.25) / 26))
}

✅ Test

Added packages/vchart/__tests__/unit/component/legend/discrete-legend.test.ts:

  • function maxRow is evaluated against the layout rect;
  • function maxCol receives { rect, orient, id } in its context;
  • numeric maxRow / maxCol keep working unchanged.

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.
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.

1 participant