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

Add getColor to props provided to custom layers #2651

Merged
merged 3 commits into from
Oct 24, 2024

Conversation

lemps
Copy link
Contributor

@lemps lemps commented Sep 24, 2024

I was creating a custom layer for my bar chart and didn't find a way to access the colours passed to the chart.

Figured that the most correct approach is to actually pass colors and colorBy props to the layer so I could use const getColor = useOrdinalColorScale(colors, colorBy) in my custom layer.

Copy link

vercel bot commented Sep 24, 2024

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

Name Status Preview Comments Updated (UTC)
nivo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 3, 2024 10:56am

@plouc
Copy link
Owner

plouc commented Sep 24, 2024

getColor is already returned by the useBar hook, so I'd suggest to pass this instead of recomputing the same color scale inside the custom layer.

@lemps
Copy link
Contributor Author

lemps commented Sep 24, 2024

Thanks for the feedback. Updated the PR to pass getColor along instead

@lemps lemps changed the title Add colors and colorBy to common props Add getColor to props provided to custom layers Sep 24, 2024
packages/bar/src/types.ts Outdated Show resolved Hide resolved
@tombennet
Copy link

@plouc This would be useful for us too - can we get this one merged? Thanks!

Copy link
Owner

@plouc plouc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@plouc plouc merged commit 7ed3ae0 into plouc:master Oct 24, 2024
4 of 5 checks passed
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

Successfully merging this pull request may close these issues.

3 participants