jakezatecky/d3-funnel

Question about the Click Event

Closed this issue · 3 comments

I'm trying to link each section of the funnel to a unique URL using the click event but I can't seem to get it working correctly as it's only going to the first URL. Below is the fiddle showing what I am trying to accomplish.
https://jsfiddle.net/uk4yf1wn/216/

Your onClick function merely checks the contents of your initial data array by index. Those checks always return a member of that array, which are always objects. if (someValidObject) will always be coerced into true, which is why only the first link is opening. You can use the index key of the parameter supplied to the onClick function to determine which node was clicked.

I updated your Fiddle below:

https://jsfiddle.net/9dkLt4wc/1/

It might be cleaner to add a url key to your data array so that instead of having a bunch of if statement you can just use window.open(data[d.index], '_blank');.

Thank you for the quick response. This was very helpful answer and I'll take your advice and add the url to the data array.

Closing the issue. Please let me know if you have any more problems.