-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Incorrect context for plugin options when scriptable #8623
Comments
I think its the correct behavior, the option is not resolved in plugin context. Either way, it can't be fixed in current design, because its the plugin that sets the context when it accesses the options. |
I was thinking it's working as designed. |
In v2, you'd get the function in that case. Might be worth documenting. |
I fully agree! |
That's one of the reasons proxied options should not be exposed publicly. It magically (and wrongly) hides the context logic to the user who should actually expect the same result as v2. The datalabels options are guaranteed to receive a datalabels context and trying to access these options manually should force the consumer (here @stockiNail) to pass the correct context using |
@simonbrunel @kurkle FYI, I have found a workaround for my lib in order to the callback is not invoked if the context is not what I'm expecting, therefore I'm not in hurry to have this behavior fixed. My personal opinion, if I may. Maybe other Chart.js's wrapper libs (like mine) could face this issue, but I'm not sure. |
Sorry if I'm annoying you... I have recognized that if inside the callback you will refer the same property by display(context) {
const s = context.chart.options.plugins.datalabels.display;
return true;
} you get |
@stockiNail that is correct. You can also get similar error with longer chains of options, if you did for example: enabled(context, opts) {
return opts.display;
},
display(context, opts) {
return opts.enabled;
} You'd get |
I would not say it "worked", but you'd get no errors in that case. The |
@stockiNail Actually, that's a good point. Proxied options are indeed nice but plugins and integrations should be able to access unresolved (i.e. raw) options as passed by the user without implicit fallback. I'm not sure that's still possible? Maybe via |
@simonbrunel the chart.config.options is decorated on the scales part, to include all the relevant defaults. plugins key is also added, if missing. Ideally it would be the user provided, unchanged options. |
Agreed, ideally. But is |
@simonbrunel as far as I know |
|
Expected Behavior
It's a special case but could happen.
When you are accessing to a plugin (i.e. datalabels) option which has been defined as a callback, by
chart.options
, for instance clicking a button in the DOM, the expectation is that callback is invoked with the right context in order to have the correct value.Current Behavior
With above sample, the context passed to
display
callback when you click on the button is not the correct one.If the callback is implemented to access to context properties (in this case, being datalabels,
datasetIndex
ordataIndex
) the value are not there and then you will get an error.The context passed is the
chart
context.Here log click randomize (see codepen below).
Steps to Reproduce
https://codepen.io/stockinail/pen/XWXgrdO
See codepen sample log.
Environment
The text was updated successfully, but these errors were encountered: