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

Feature Request: option to handle when label cannot fit inside a bar #395

Open
getify opened this issue Sep 20, 2023 · 1 comment
Open

Comments

@getify
Copy link

getify commented Sep 20, 2023

I have a bar chart (horizontal in this case, but vertical would be the same thing) where I want the labels to sit right inside the end (right or top) of the bar.

So I use anchor: 'end' and then position: 'left' (or position: 'start'). For most bars, this works fine. But if a bar is rendering quite short, then the label looks ugly overlapping the axis, and possibly even being cut off. So in those cases, I want the label outside the bar, with anchor: 'end' and position: 'right' / position: 'end'.

I've tried defining align as a function, so I can programmatically give different values. The problem is, I can't really reliably "compute" whether the label could fit or not. The context object that's passed in gives me the plotted dataset value, but it doesn't really tell me the relative dimensions of the bar versus the label.

A solution that might work is to be able to pass an array of values, like position: [ 'left', 'right' ] or position: [ 'start', 'end' ], and the library tries to position with the first value, and if it doesn't fit, or overlaps, or whatever... then it tries the next value, and so on.

Even more simply, maybe n position: 'auto' could cycle from 'left' > 'center' > 'right' (or 'start' > 'center' > 'end'), trying each position until the label can fit?

@jcorevnue2022
Copy link

+1

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

No branches or pull requests

2 participants