Skip to content

Commit

Permalink
Allow color plugin to work with custom dataset controllers (#10904)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeLenaleee committed Nov 25, 2022
1 parent 5fdc0f7 commit 8239567
Showing 1 changed file with 8 additions and 7 deletions.
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

0 comments on commit 8239567

Please sign in to comment.