Adds type property to label context - #229
stockiNail wants to merge 5 commits into
Conversation
|
I don't think this But even if it was using the proxy logic, I don't fully get the benefit of this |
|
First of all, as I wrote in the chartjs/Chart.js#8623 issue in CHART.JS, this is a special case.
As I described in the issue, above mentioned, accessing to As @kurkle replied, this is the behavior of
In my opinion, I think it's helpful to have a property which describes the type of context (forgive me, I don't see any confusion but that could be my fault). The other way is to check if the context contains all needed properties (not undefined) and in many cases you should perform more than 1
Last but not least, the CHART.JS context contains the |
As you said, it's a special case. The plugin options are intended to be consumed by the plugin itself. If you want to resolve these options outside of the plugin, it's your responsibility to provide a context compatible with the datalabels one or to provide a way to check the context for this special case.
Each option level must be guaranteed to receive a certain context shape:
You can't ask to check
I don't think it's a good approach to handle different contexts. You should never have to check
Don't make a root option aware of plugins, scales, etc.
I'm probably missing some use cases that would make this |
|
@simonbrunel think about: Chart.defaults.color = (ctx) => {...}edit, or: new Chart('id', {
type: 'line',
data: {
labels: ['a', 'b', 'c'],
datasets: [{
label: 'test',
data: [1, 2, 3],
backgroundColor(ctx) => ctx.type ==='dataset' ? 'red' : 'blue' // latter is for points (etc, because not tested)
}]
}
} |
|
@kurkle I'm not sure I get your point, why would you ever need to write: Chart.defaults.color = (ctx) => {
return ctx.type === 'datalabels' ? 'red' : 'blue';
}Instead of: Chart.defaults.set({
color: 'blue',
plugins: {
datalabels: {
color: 'red';
}
}
}About your second example, it could be: backgroundColor: (ctx) => ctx.dataIndex === undefined ? 'red' : 'blue' The difference with scales, ticks and plugins is that there is no option level for |
|
@stockiNail Thank you for your contribution, I really appreciate your effort in helping for the upcoming Chart.js v3 release. I explained my concerns more in details in chartjs/Chart.js#8642 so it doesn't get lost. I'm closing this PR because I don't adhere to the use of |
|
@simonbrunel ur welcome! nop for this PR. I don't want to push too much on this topic, being a special case. |
As reported in CHART.JS issue chartjs/Chart.js#8623 and the related PR chartjs/Chart.js#8626, there is the following new guideline about context:
This PR is adding
typeproperty to label context.