Skip to content

Commit

Permalink
rewrite code for new params
Browse files Browse the repository at this point in the history
  • Loading branch information
maruk0chan committed Jan 30, 2024
1 parent 14ea285 commit 1555810
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions stanzas/piechart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@ export default class Piechart extends MetaStanza {

const chart = chartG.selectAll("path").data(dataReady);

chart
const pieGroups = chart
.enter()
.append("path")
.classed("pie-slice", true)
.attr("d", <any>arcGenerator)
.attr("fill", (d) => d.data[colorSym])
.on("click", (_, d) =>
.attr("fill", (d) => d.data[colorSym]);

if (this.params["event-outgo_change_selected_nodes"]) {
pieGroups.on("click", (_, d) =>
emitSelectedEvent.apply(this, [d.data["__togostanza_id_dummy__"]])
);
}

if (showLegend) {
if (!this.legend) {
Expand Down Expand Up @@ -130,11 +133,9 @@ export default class Piechart extends MetaStanza {
}

handleEvent(event) {
const selectedNodes = event.detail;
const pieGroups = this._chartArea.selectAll(".pie-slice");
pieGroups.classed("-selected", (d: Datum) => {
return selectedNodes.indexOf(d.data.__togostanza_id_dummy__) !== -1;
});
if (this.params["event-income_change_selected_nodes"]) {
changeSelectedStyle.apply(this, [event.detail]);
}
}
}

Expand All @@ -159,3 +160,10 @@ function emitSelectedEvent(this: Piechart, id: string | number) {
})
);
}

function changeSelectedStyle(this: Piechart, ids: Array<string | number>) {
const pieGroups = this._chartArea.selectAll(".pie-slice");
pieGroups.classed("-selected", (d: Datum) => {
return ids.indexOf(d.data.__togostanza_id_dummy__) !== -1;
});
}

0 comments on commit 1555810

Please sign in to comment.