From: stockiNail Date: Fri, 4 Nov 2022 15:17:49 +0000 (+0100) Subject: Enable colors plugin for pie charts (#10851) X-Git-Tag: v4.0.0-release~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b271b5098ae1c979a070e533f7812d1971e83eda;p=thirdparty%2FChart.js.git Enable colors plugin for pie charts (#10851) * Enable colors plugin for pie charts * fixes CC --- diff --git a/src/plugins/plugin.colors.ts b/src/plugins/plugin.colors.ts index 8d4766667..234171cd2 100644 --- a/src/plugins/plugin.colors.ts +++ b/src/plugins/plugin.colors.ts @@ -55,6 +55,15 @@ function createPolarAreaDatasetColorizer() { }; } +function getColorizer(type: string) { + if (type === 'doughnut' || type === 'pie') { + return createDoughnutDatasetColorizer(); + } else if (type === 'polarArea') { + return createPolarAreaDatasetColorizer(); + } + return createDefaultDatasetColorizer(); +} + function containsColorsDefinitions( descriptors: ColorsDescriptor[] | Record ) { @@ -91,16 +100,7 @@ export default { return; } - let colorizer: DatasetColorizer; - - if (type === 'doughnut') { - colorizer = createDoughnutDatasetColorizer(); - } else if (type === 'polarArea') { - colorizer = createPolarAreaDatasetColorizer(); - } else { - colorizer = createDefaultDatasetColorizer(); - } - + const colorizer: DatasetColorizer = getColorizer(type); datasets.forEach(colorizer); } }; diff --git a/test/fixtures/plugin.colors/pie.js b/test/fixtures/plugin.colors/pie.js new file mode 100644 index 000000000..ef58bc14d --- /dev/null +++ b/test/fixtures/plugin.colors/pie.js @@ -0,0 +1,23 @@ +module.exports = { + config: { + type: 'pie', + data: { + datasets: [ + { + data: [0, 2, 4, null, 6, 8] + }, + { + data: [5, 1, 6, 2, null, 9] + } + ] + }, + options: { + plugins: { + legend: false, + colors: { + enabled: true + } + } + } + } +}; diff --git a/test/fixtures/plugin.colors/pie.png b/test/fixtures/plugin.colors/pie.png new file mode 100644 index 000000000..c92b35b05 Binary files /dev/null and b/test/fixtures/plugin.colors/pie.png differ