-
I'm trying to do something simple. I want to generate a tidy tree plot in which the text of each node is a hyperlink. I've tried various approaches with no success. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You can use the href option: Plot.tree(flare, {
path: "name",
delimiter: ".",
href: ({name}) => `https://github.com/prefuse/Flare/blob/master/flare/src/${name.replaceAll(".", "/")}.as`,
target: "_blank"
}) (paste this into https://observablehq.com/@observablehq/plot-tree-tidy to test) |
Beta Was this translation helpful? Give feedback.
-
Thank you! I have succeeded in implementing this. A further question: Is it possible to embed JavaScript in the link? Rather than simply seeking to the href, I'd like to invoke React useNavigate. |
Beta Was this translation helpful? Give feedback.
-
Thank you again. Your proposal works well. Unfortunately, the javascript code cannot access methods within React's scope. I wanted to invoke React's useNavigate hook from the javascript and this was not possible. In the end, I solved it by adding an event listener to plot's text elements - within the SVG - that should implement hyperlinking. My code works, but it's somewhat fragile and would break if the structure of the SVG were to change. I'm new to Observable, so I have three questions: (1) should I be concerned about the fragility?, (2) is there an acknowledged way to bridge between DOM and React context?, and (3) is this the correct forum for such a discussion? I'm happy to share my code. |
Beta Was this translation helpful? Give feedback.
You can use the href option:
(paste this into https://observablehq.com/@observablehq/plot-tree-tidy to test)