Skip to content

Commit

Permalink
support event dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
penqe committed Apr 4, 2024
1 parent 2ea4fec commit db2df78
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions stanzas/barchart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export default class Barchart extends MetaStanza {
}
if (this.params["event-outgoing_change_selected_nodes"]) {
barGroup.on("click", (_, d) =>
emitSelectedEvent.apply(this, [d[1][0]["__togostanza_id__"]])
emitSelectedEventByBarChart.apply(this, [d[1][0]["__togostanza_id__"]])
);
}

Expand Down Expand Up @@ -459,10 +459,8 @@ export default class Barchart extends MetaStanza {

if (this.params["event-outgoing_change_selected_nodes"]) {
bar.on("click", (_, d) => {
d["__values__"].forEach((value) => {
console.log(value["__togostanza_id__"])
emitSelectedEvent.apply(this, [value["__togostanza_id__"]])
})
const ids = d["__values__"].map(value => value["__togostanza_id__"]);
emitSelectedEventByHistogram.apply(this, [ids]);
});
}
}
Expand Down Expand Up @@ -605,7 +603,7 @@ function addErrorBars(
}

// emit selected event
function emitSelectedEvent(this: Barchart, id: any) {
function emitSelectedEventByBarChart(this: Barchart, id: any) {
// collect selected bars
const barGroups = this._graphArea.selectAll("g.bar-group");
const filteredBars = barGroups.filter(".-selected");
Expand All @@ -626,6 +624,14 @@ function emitSelectedEvent(this: Barchart, id: any) {
);
changeSelectedStyle.apply(this, [ids]);
}
function emitSelectedEventByHistogram(this: Barchart, ids: any[]) {
// dispatch event
this.element.dispatchEvent(
new CustomEvent("changeSelectedNodes", {
detail: ids,
})
);
}

function changeSelectedStyle(this: Barchart, ids: string[]) {
console.log(ids);
Expand Down

0 comments on commit db2df78

Please sign in to comment.