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

feat(Bar): Add option to chose label position #2585

Merged
merged 10 commits into from
Jul 2, 2024

Conversation

evasseure
Copy link
Contributor

@evasseure evasseure commented May 3, 2024

This adds two new props to the bar charts:

  • labelPosition: defaults to 'middle', and allows to chose at which end of the bar the label should appear (start, middle, end)
  • labelOffset: defaults to 0, and allows to chose the vertical or horizontal offset of the label. This depends on if the chart is horizontal or vertical.

➡️ DEMO

This is related to #2579.

Option Result
Vertical - "end" Screenshot 2024-05-03 at 15 38 15
Vertical - "start" Screenshot 2024-05-03 at 15 38 59
Horizontal - "end" Screenshot 2024-05-03 at 15 39 45
Horizontal - "start" Screenshot 2024-05-03 at 15 39 27
Vertical - Stacked - "start" Screenshot 2024-05-03 at 15 40 56
Vertical - "end" - no offset Screenshot 2024-05-03 at 15 46 02
Vertical - "end" - reverse Screenshot 2024-05-03 at 15 50 02

Copy link

vercel bot commented May 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nivo ❌ Failed (Inspect) Jul 1, 2024 2:42pm

@plouc
Copy link
Owner

plouc commented May 3, 2024

I noticed that for the reversed horizontal mode, end labels still have a start text anchor, I think it should be mirrored, as for the position, I was also wondering if the offset should be applied negatively as well in this mode.

@plouc
Copy link
Owner

plouc commented May 3, 2024

But I should have started with: great work! 😅 You added tests, updated the website, stories... 👍🏻

@plouc
Copy link
Owner

plouc commented May 3, 2024

Inverting the effect of the offset could also be done for the vertical reversed mode.

@plouc plouc added the 📊 bar @nivo/bar package label May 3, 2024
packages/bar/src/types.ts Outdated Show resolved Hide resolved
@evasseure
Copy link
Contributor Author

labels still have a start text anchor, I think it should be mirrored

Good idea, will update!

I was also wondering if the offset should be applied negatively as well in this mode.
...
Inverting the effect of the offset could also be done for the vertical reversed mode.

That's up to you, right now its consistent with the how the x and y axis work in svg and canvas, which could remove a bit of possible confusion, but we could also have the offset work relative to the base of the bar, if you think that's better.

@plouc
Copy link
Owner

plouc commented May 3, 2024

I was also wondering if the offset should be applied negatively as well in this mode.
...
Inverting the effect of the offset could also be done for the vertical reversed mode.

That's up to you, right now its consistent with the how the x and y axis work in svg and canvas, which could remove a bit of possible confusion, but we could also have the offset work relative to the base of the bar, if you think that's better.

I think it's best to mirror the offset as we're already mirroring the position.

@evasseure
Copy link
Contributor Author

evasseure commented May 7, 2024

I made it so the offset is based on the direction and start of the bar, so for a label positioned in the center, a negative offset will go towards the start of the bar, and a positive offset will go towards the end of the bar.
Is that what you had in mind?
@plouc

@evasseure
Copy link
Contributor Author

Hello @plouc! Did you have time to look at my changes?

@plouc
Copy link
Owner

plouc commented May 20, 2024

Hi @evasseure, I've been a bit busy, and it might be hard this week because of work, but I'll try to review asap.

@evasseure
Copy link
Contributor Author

Hello @plouc! Any chance you can have a look at the changes soon please? They are pretty light 🙂

@plouc
Copy link
Owner

plouc commented Jun 20, 2024

@evasseure, it looks good, I think we should adjust the labelPosition though.

There's another limitation, it's the fact that labels aren't in a separate layer, causing the labels to be under the bars in certain cases, I wouldn't be surprised if some users report this as an issue, but maybe that's ok.

@evasseure
Copy link
Contributor Author

I think we should adjust the labelPosition though.

My bad, forgot about this. Should be good now.

There's another limitation, it's the fact that labels aren't in a separate layer, causing the labels to be under the bars in certain cases, I wouldn't be surprised if some users report this as an issue, but maybe that's ok.

That's one of the issue with giving full control over the labelOffset. That's up to you 😕

@plouc
Copy link
Owner

plouc commented Jul 2, 2024

That's one of the issue with giving full control over the labelOffset. That's up to you 😕

I think it's fine for now, labels should eventually be on their own layer, I don't remember exactly why I merged them with the bars, maybe for performance.

@plouc plouc linked an issue Jul 2, 2024 that may be closed by this pull request
@plouc plouc merged commit f2e440e into plouc:master Jul 2, 2024
4 of 5 checks passed
@bradlocking
Copy link

@plouc Thanks for merging this feature. Am I right in presuming that the docs have been updated with the labelPosition functionality, but the feature is yet to be released to npm?

@plouc
Copy link
Owner

plouc commented Jul 9, 2024

@bradlocking, yes, you're right, the workflow is not ideal as the website is updated automatically, but releases aren't automatically published. I'll try to release this week if I can find some time.

@bradlocking
Copy link

@bradlocking, yes, you're right, the workflow is not ideal as the website is updated automatically, but releases aren't automatically published. I'll try to release this week if I can find some time.

Cheers! No probs it was a nice coincidence that the function I needed was in the pipeline anwyay

@MonkeyDo
Copy link

MonkeyDo commented Jul 12, 2024

@bradlocking, yes, you're right, the workflow is not ideal as the website is updated automatically, but releases aren't automatically published. I'll try to release this week if I can find some time.

Cheers! No probs it was a nice coincidence that the function I needed was in the pipeline anwyay

Same here, except it was only this week I ran into the need for this new option. The timing is impeccable.

@plouc Thank you so much for your time and energy!
Could I potentially help in setting up automated package deployments with Github?
I have been working on a deployment workflow for an open source project I maintain, I'd be happy to help.

@bradlocking
Copy link

@plouc Shameless bump - is there anything I can do to help get this feature live?

@joesaunderson
Copy link

@plouc sorry to bump the above, I have just encountered the same issue as above, the docs mis-matching the code i have.

@plouc
Copy link
Owner

plouc commented Jul 18, 2024

Sorry for that, I'm quite busy with work atm, will do my best to release as soon as I can.

@nickfarm27
Copy link

nickfarm27 commented Sep 5, 2024

Hey @plouc, bumping the above once again. I'm looking to make use of this feature but it seems like a release still hasn't been made. Is it possible to make a release asap?

@bradlocking
Copy link

Second the above. It's been over 2 months since my initial comment, and even longer that it's been live as an option in your docs but not deployed functionality.

@Anubiso
Copy link

Anubiso commented Sep 26, 2024

Also going to +1 this. Decided for this library for my use-case because i could configure it as the case needed it on the docs-website. When then trying to implement this in the project failed because the docs show features which are not supported yet in a usable release.

@ssindher11
Copy link

Hey @plouc, any updates on releasing this feature?

@joesaunderson
Copy link

+1 on the above.

I know this is not a paid service, but for transparency is it worth marking this repo as abandoned and letting someone else take a fork?

The PR (and the docs) were updated 5 months ago. So we are 5 months of the docs being different to what's actually possible in the real life repo.

@bradlocking
Copy link

@plouc We are actively using your library as part of an enterprise application. Could you give us an update as to whether you're going to struggle to maintain the software moving forward so that we can start planning potential replacements?

@tarjep
Copy link

tarjep commented Nov 6, 2024

+1
Does anyone know about a workaround for this?

@MonkeyDo
Copy link

MonkeyDo commented Nov 6, 2024

+1 Does anyone know about a workaround for this?

Hello, here is my workaround: use the barComponent property to create a custom bar component in order to render bar and labels.
In my case, using the SVG version of the component, I opted for an svg foreignObject which allowed me to put an HTML div inside the SVG and style that accordingly with CSS.

The code in question: https://github.com/metabrainz/listenbrainz-server/blob/2dd924590d45f1a63d0d9ea3ecf2c01e9815e3fb/frontend/js/src/user/charts/UserEntityChart.tsx#L57-L77
And used like this: https://github.com/metabrainz/listenbrainz-server/blob/2dd924590d45f1a63d0d9ea3ecf2c01e9815e3fb/frontend/js/src/user/charts/UserEntityChart.tsx#L333

The result:
image

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

Successfully merging this pull request may close these issues.

[Bar] Option to decide label position
9 participants