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

Global defaults have no effect for doughnuts and pie charts. #10927

Closed
santam85 opened this issue Nov 30, 2022 · 14 comments
Closed

Global defaults have no effect for doughnuts and pie charts. #10927

santam85 opened this issue Nov 30, 2022 · 14 comments

Comments

@santam85
Copy link

Expected behavior

Doughnut and pie charts use global datasets defaults or arc elements defaults for backgroundColor.

Polar area charts scriptable property dataIndex seems dependent on the property type.

Current behavior

The global defaults have no effect. Scriptable options funcitons are not called.

Reproducible sample

https://codepen.io/leelenaleee/pen/WNyJXEe

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

Testing new Chart.js version for ng2-charts

chart.js version

v4.0.1

Browser name and version

No response

Link to your project

No response

@stockiNail
Copy link
Contributor

I think this is related to new color plugin of version 4, see https://www.chartjs.org/docs/latest/general/colors.html#per-dataset-color-settings.

I think it's a bug of the plugin, on the following code:

const {
type,
options: {elements},
data: {datasets}
} = chart.config as ChartConfiguration;

I see 2 things:

  1. the plugin is using chart.config but it doesn't seem to be a proxy therefore doesn't have the fallback to the defaults. It's (AFAIK) the user configuration, ignoring defaults both on controller and elements.
  2. type is not used anymore after PR Allow color plugin to work with custom dataset controllers #10904

@santam85
Copy link
Author

Nice find, thanks! Given the addition of this new plugin in v4, as a maintainer of the Angular wrapper, I wonder if I should remove the color generation feature and just delegate to the new plugin, any opinions from the Chart.js maintainers?

@dangreen
Copy link
Collaborator

@santam85 For tests you can disable this plugin by options.plugins.colors.enabled option.

@kurkle
Copy link
Member

kurkle commented Nov 30, 2022

I don't think the colors plugin can resort to fallback colors, because then there always is a color already.

The plugin can also be disabled globally:

Chart.defaults.plugins.colors.enabled = false;

@stockiNail
Copy link
Contributor

@kurkle exactly what I'm thinking. No options apart disable it, globally.

@santam85
Copy link
Author

Yes that's what I did. I can confirm that it fixes my issue, so for now I'll go ahead and disable the color plugin when generating colors myself.

@kurkle
Copy link
Member

kurkle commented Nov 30, 2022

Another option, for the colors plugin, could be to attach as a scriptable global default.
But it has performance impact: would always have scriptable options, so no option sharing between elements.

@stockiNail
Copy link
Contributor

@kurkle for my understanding, do you mean the plugin will set a scriptable option in the defaults? The plugin will just set the scriptable option and the logic is overthere, correct?

@stockiNail
Copy link
Contributor

Anyway, even if the color plugin is a feature and not a breaking change, I think something could be reported in the migration guide because this is a common use case which is broken. WDYT?

@santam85
Copy link
Author

Another option, for the colors plugin, could be to attach as a scriptable global default.
But it has performance impact: would always have scriptable options, so no option sharing between elements.

That's what I've gone for in the Angular wrapper lib

@dangreen
Copy link
Collaborator

I can make a fix for this case.

@dangreen
Copy link
Collaborator

dangreen commented Dec 9, 2022

It is impossible to detect whether the defaults changed or not on the plugin level. So I suggest accepting this as expected behavior and closing the issue.

I think something could be reported in the migration guide

It is a valid problem only for the UMD bundle, where all plugins are enabled by default. We have a notice about that in the docs:

https://www.chartjs.org/docs/latest/general/colors.html

If you are using the UMD version of Chart.js, this plugin will be enabled by default. You can disable it by setting the enabled option to false

@dangreen
Copy link
Collaborator

@santam85 @stockiNail @kurkle what do you think?

@stockiNail
Copy link
Contributor

@santam85 @stockiNail @kurkle what do you think?

Fine for me

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

No branches or pull requests

4 participants