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: Custom point renderer #2245

Closed
wants to merge 4 commits into from
Closed

Conversation

qbob1
Copy link

@qbob1 qbob1 commented Nov 15, 2023

Summary

This pr allows the user to specify a custom point renderer for line charts. Use cases include custom shapes displayed in line charts.

Details

This is done by exposing the canvas context during the point rendering. Specifically, by extending the point geometry style type to include a custom rendering function.

Checklist

  • [] The proper chart type label has been added (e.g. :xy, :partition)
  • [] The proper feature labels have been added (e.g. :interactions, :axis)
  • The proper documentation and/or storybook story has been added or updated

…endering

This commit aims to allow users to specify a custom point rendering function while iterating a line.
An example use case is adding the value label to the point in a custom manner
Copy link

❌ Author of the following commits did not sign a Contributor Agreement:
023dda1, 8bac653, 752cc28, 92a1daa

Please, read and sign the above mentioned agreement if you want to contribute to this project

@elastic-datavis
Copy link
Contributor

Community pull request, @elastic/datavis please add the ci:approved ✅ label to allow this and future builds.

@qbob1 qbob1 changed the title :xy :line :point Custom point renderer feat: Custom point renderer Nov 15, 2023
@nickofthyme
Copy link
Collaborator

buildkite test this

@nickofthyme
Copy link
Collaborator

Hey @qbob1 Thanks for these changes, I'll take a look at them soon.

@@ -33,6 +33,9 @@ export function renderPoints(ctx: CanvasRenderingContext2D, points: PointGeometr
...style.stroke,
color: overrideOpacity(style.stroke.color, (fillOpacity) => fillOpacity * opacity),
};
if (typeof style.shape === 'function') {
return style.shape(ctx, coordinates);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey @qbob1 thanks again for contributing to elastic charts!

Looking over these changes I wonder what is the primary goal or feature that you are looking for from these changes?

Are you looking for a way to define unique shape for the points aside from the limited PointShapes? In that case we could add an option to provide a Path2D, to support any abstract path/symbol.

Or are you looking for support of value labels on line/area charts (i.e. #797)?

The reason I ask is because we are not big fans of exposing the ctx directly to the user to do with as they please. With that said I'm happy to hear your thoughts and get the changes you are looking for added to the library.

Copy link
Author

Choose a reason for hiding this comment

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

Totally understandable!
Fortunately, I was able to find a work around for #797 and posted a comment to help anyone else that may need to display the labels.
I'd say a Path2D would be excellent and a much cleaner solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding that comment to #797.

Perfect, if you'd like to refactor this PR or create a fresh PR to add the option to assign a Path2D to PointStyle.shape I'll take another look. Otherwise it'll probably be a few weeks before we get around to adding it ourselves.

Copy link
Author

Choose a reason for hiding this comment

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

I wouldn't mind taking a crack at it. Any preference on implementation?

@markov00
Copy link
Member

Closing for now as I don't see updates since January

@markov00 markov00 closed this May 13, 2024
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.

None yet

3 participants