Skip to content

Commit

Permalink
Show warning when multiple datasets are used in Pie & Donut
Browse files Browse the repository at this point in the history
  • Loading branch information
theiliad committed May 3, 2019
1 parent 438907b commit 155436c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/core/src/pie-chart.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// D3 Imports
import { select, selectAll, mouse } from "d3-selection";
import { select } from "d3-selection";
import { scaleOrdinal } from "d3-scale";
import { pie, arc, Pie, Arc } from "d3-shape";
import { interpolate } from "d3-interpolate";
Expand Down Expand Up @@ -44,6 +44,10 @@ export class PieChart extends BaseChart {
// Cap number of slices at a specific number, and group the remaining items into the label "Other"
dataProcessor(dataObject: ChartData): PieData {
// TODO - Support multiple datasets
if (dataObject.datasets.length > 1) {
console.warn("Currently the Pie & Donut charts support a single dataset, you appear to have more than that. Will only use your first provided dataset.");
}

// Check for duplicate keys in the data
const duplicates = Tools.getDuplicateValues(dataObject.labels);
if (duplicates.length > 0) {
Expand Down Expand Up @@ -313,6 +317,7 @@ export class PieChart extends BaseChart {
const oldData = Tools.clone(this.displayData);
const activeLegendItems = this.getActiveLegendItems();

// TODO - Support multiple datasets
const newDisplayData = Object.assign({}, oldData);
newDisplayData.datasets[0].data = oldData.datasets[0].data.filter(dataPoint => activeLegendItems.indexOf(dataPoint.label) !== -1);

Expand Down

0 comments on commit 155436c

Please sign in to comment.