diff --git a/package.json b/package.json index 2148cde..6976e47 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/HorizontalRidgePlot.js b/src/HorizontalRidgePlot.js index 23e480b..e5b94dc 100644 --- a/src/HorizontalRidgePlot.js +++ b/src/HorizontalRidgePlot.js @@ -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); } }); @@ -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); @@ -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 diff --git a/src/VerticalRidgePlot.js b/src/VerticalRidgePlot.js index 5b51159..b7f089c 100644 --- a/src/VerticalRidgePlot.js +++ b/src/VerticalRidgePlot.js @@ -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); } }); @@ -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); @@ -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