Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y-labels cropped way too early for vertically stacked axes #11746

Open
jkmnt opened this issue Apr 18, 2024 · 0 comments
Open

Y-labels cropped way too early for vertically stacked axes #11746

jkmnt opened this issue Apr 18, 2024 · 0 comments

Comments

@jkmnt
Copy link

jkmnt commented Apr 18, 2024

Expected behavior

The max allowed width for y-labels show be about 50% of chart width.
It works this way for side-by-side axes.

Current behavior

2

If y-axes are stacked, this is not holds.

Reproducible sample

https://codepen.io/jkmnt/pen/mdgzXVv

Optional extra steps/info to reproduce

Resize the browser window to see the effect.

Possible solution

It appears the chart.js always calculates the max allowed axis width as chart width / 2 / number of axes regardless of stacking enabled.

vBoxMaxWidth: availableWidth / 2 / visibleVerticalBoxCount,

This picture confirms the suspision. Same chart as above, but without stacking.

2

The workaround I use now is the afterFit callback on every axis patching it width:

   afterFit: (axis) => {
      const widest = (axis as any)._labelSizes?.widest?.width;
      if (widest && axis.width < widest + 8) {
        axis.width = widest + 8;
      }
    },

Context

No response

chart.js version

v4.4.2

Browser name and version

No response

Link to your project

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant