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

Allow color plugin to work with custom dataset controllers #10904

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/plugins/plugin.colors.ts
@@ -1,3 +1,4 @@
import {DoughnutController, PolarAreaController} from '../index.js';
import type {Chart, ChartConfiguration, ChartDataset} from '../types.js';

export interface ColorsPluginOptions {
Expand Down Expand Up @@ -49,17 +50,17 @@ function colorizePolarAreaDataset(dataset: ChartDataset, i: number) {
return i;
}

function getColorizer(chartType: string) {
function getColorizer(chart: Chart) {
let i = 0;

return (dataset: ChartDataset) => {
const type = dataset.type || chartType;
return (dataset: ChartDataset, datasetIndex: number) => {
const controller = chart.getDatasetMeta(datasetIndex).controller;

if (type === 'doughnut' || type === 'pie') {
if (controller instanceof DoughnutController) {
i = colorizeDoughnutDataset(dataset, i);
} else if (type === 'polarArea') {
} else if (controller instanceof PolarAreaController) {
i = colorizePolarAreaDataset(dataset, i);
} else if (type) {
} else if (controller) {
i = colorizeDefaultDataset(dataset, i);
}
};
Expand Down Expand Up @@ -101,7 +102,7 @@ export default {
return;
}

const colorizer = getColorizer(type);
const colorizer = getColorizer(chart);

datasets.forEach(colorizer);
}
Expand Down