Skip to content

Commit

Permalink
fix check for onClick handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Nov 1, 2023
1 parent 1ba3963 commit b8577aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ridges.js",
"version": "0.0.5",
"version": "0.0.6",
"description": "Create and visualize ridge plots",
"repository": "https://github.com/jkanche/ridges.js",
"homepage": "https://github.com/jkanche/ridges.js#readme",
Expand Down
16 changes: 15 additions & 1 deletion src/HorizontalRidgePlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class HorizontalRidgePlot extends RidgePlot {
.on("click", function (e, d) {
const idx = self._dkeys.indexOf(d);
const mets = self._dentries[idx];
if (mets === null && "onClick" in self.state) {
if (mets !== null && mets !== undefined && "onClick" in self.state) {
self.state.onClick(mets);
}
});
Expand Down Expand Up @@ -284,6 +284,13 @@ export class HorizontalRidgePlot extends RidgePlot {
.on("mouseout", function (event, d) {
self._hoverKey = null;
tip.style("opacity", 0);
})
.on("click", function (e, d) {
const idx = self._dkeys.indexOf(d.key);
const mets = self._dentries[idx][1];
if (mets !== null && mets !== undefined && "onClick" in self.state) {
self.state.onClick(mets);
}
});

let bars = svg.selectAll("bars").data(this._dentries);
Expand Down Expand Up @@ -355,6 +362,13 @@ export class HorizontalRidgePlot extends RidgePlot {
.on("mouseout", function (event, d) {
self._hoverKey = null;
tip.style("opacity", 0);
})
.on("click", function (e, d) {
const idx = self._dkeys.indexOf(d[0]);
const mets = self._dentries[idx][1];
if (mets !== null && mets !== undefined && "onClick" in self.state) {
self.state.onClick(mets);
}
});

// min
Expand Down
16 changes: 15 additions & 1 deletion src/VerticalRidgePlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class VerticalRidgePlot extends RidgePlot {
.on("click", function (e, d) {
const idx = self._dkeys.indexOf(d);
const mets = self._dentries[idx];
if (mets === null && "onClick" in self.state) {
if (mets !== null && mets !== undefined && "onClick" in self.state) {
self.state.onClick(mets);
}
});
Expand Down Expand Up @@ -269,6 +269,13 @@ export class VerticalRidgePlot extends RidgePlot {
.on("mouseout", function (event, d) {
self._hoverKey = null;
tip.style("opacity", 0);
})
.on("click", function (e, d) {
const idx = self._dkeys.indexOf(d.key);
const mets = self._dentries[idx][1];
if (mets !== null && mets !== undefined && "onClick" in self.state) {
self.state.onClick(mets);
}
});

let bars = svg.selectAll("bars").data(this._dentries);
Expand Down Expand Up @@ -340,6 +347,13 @@ export class VerticalRidgePlot extends RidgePlot {
.on("mouseout", function (event, d) {
self._hoverKey = null;
tip.style("opacity", 0);
})
.on("click", function (e, d) {
const idx = self._dkeys.indexOf(d[0]);
const mets = self._dentries[idx][1];
if (mets !== null && mets !== undefined && "onClick" in self.state) {
self.state.onClick(mets);
}
});

// min
Expand Down

0 comments on commit b8577aa

Please sign in to comment.