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

Implement label events (enter, leave and click) #40

Merged
merged 1 commit into from
Mar 21, 2018

Conversation

simonbrunel
Copy link
Member

@simonbrunel simonbrunel commented Mar 11, 2018

Add a new listeners option (object), where the property is the type of the event to listen and the value a callback with a unique context argument containing the same information as for scriptable options. If a callback explicitly returns true, the label is updated with the modified context and the chart re-rendered. This allows to implement visual interactions with labels such as highlight, selection, etc.

Note that there should be no performance penalty for configuration that don't use events since if there is no listener registered, we immediately ignore the incoming event and avoid useless extra computation.

Documentation & samples: listeners, highlight, selection

Fixes #17

Add a new `listeners` option (object), where the property is the type of the event to listen and the value a callback with a unique `context` argument containing the same information as for scriptable options. If a callback explicitly returns `true`, the label is updated with the modified context and the chart re-rendered. This allows to implement visual interactions with labels such as highlight, selection, etc.

Note that there should be no performance penalty for configuration that don't use events since if there is no listener registered, we immediately ignore the incoming event and avoid useless extra computation.
@simonbrunel
Copy link
Member Author

@pingcheng @haimich will you guys be able to verify that PR? I would like to release 0.3.0 very soon and it would be great to have these changes tested before. You can grab built files directly from netlify (chartjs-plugin-datalabels.js and chartjs-plugin-datalabels.min.js)

@simonbrunel simonbrunel merged commit ecede9f into chartjs:master Mar 21, 2018
@simonbrunel simonbrunel deleted the feat/events branch March 21, 2018 16:20
@juanpprieto
Copy link

juanpprieto commented Mar 22, 2018

Hey @simonbrunel. Thanks for this! Do you happen to have a JSFiddle example with 0.3.0?

UPDATE:
Sorry I was being lazy :)
Here's one I made for the basic event handler example.
https://jsfiddle.net/jpprietobaez/7ggttc3w/

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

Successfully merging this pull request may close these issues.

2 participants