Skip to content

Commit 203c7e6

Browse files
committed
fix(core): legend updates in pie & donut should respect legend filters
1 parent 39c0367 commit 203c7e6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Diff for: packages/core/src/base-chart.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ export class BaseChart {
473473
if (this.getLegendType() === Configuration.legend.basedOn.LABELS && d.value === Configuration.legend.items.status.ACTIVE) {
474474
return this.colorScale[this.displayData.datasets[0].label](d.key);
475475
} else if (d.value === Configuration.legend.items.status.ACTIVE) {
476-
return this.colorScale[d.key]();
476+
return this.colorScale[d.key]();
477477
}
478478

479479
return "white";
@@ -520,6 +520,7 @@ export class BaseChart {
520520

521521
addOrUpdateLegend() {
522522
this.addLegend();
523+
523524
if (this.options.legendClickable) {
524525
this.setClickableLegend();
525526
}

Diff for: packages/core/src/pie-chart.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,30 @@ export class PieChart extends BaseChart {
342342
this.container.select(".legend")
343343
.selectAll("*").remove();
344344

345+
const legendItems = this.getLegendItems();
345346
const legend = this.container.select(".legend")
346347
.attr("font-size", Configuration.legend.fontSize)
347348
.selectAll("div")
348-
.data(this.getLegendItemKeys())
349+
.data(Object.keys(legendItems))
349350
.enter().append("li")
350351
.attr("class", "legend-btn active");
351352

352353
legend.append("div")
353354
.attr("class", "legend-circle")
354-
.style("background-color", (d, i) => this.colorScale(d));
355+
.style("background-color", (d, i) => {
356+
if (legendItems[d] === Configuration.legend.items.status.ACTIVE) {
357+
return this.colorScale(d);
358+
}
359+
360+
return "white";
361+
})
362+
.style("border", (d, i) => {
363+
if (legendItems[d] === Configuration.legend.items.status.ACTIVE) {
364+
return "none";
365+
}
366+
367+
return `2px solid ${this.colorScale(d)}`;
368+
});
355369

356370
legend.append("text")
357371
.text(d => d);

0 commit comments

Comments
 (0)