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
Conversation
…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
❌ Author of the following commits did not sign a Contributor Agreement: Please, read and sign the above mentioned agreement if you want to contribute to this project |
Community pull request, @elastic/datavis please add the |
buildkite test this |
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); |
There was a problem hiding this comment.
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 PointShape
s? 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Closing for now as I don't see updates since January |
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
:xy
,:partition
):interactions
,:axis
)