I have defined a data structure using pygraph. I can display that data easily as PNG
using graphviz
.
I would like to display the data graphically, but making each node in the graph clickable. Each node must be linked to a different web page. How would I approach this?
What I would like is:
href
for each nodehover
event: whenever the cursor is positioned on top of an edge / node, a tooltip should be displayedI believe graphviz can already output an image as a map for use in html.
Check this doc or this one for how to tell graphviz to output a coordinate map to use. It will even append the url you specify, and there even is a version that only uses rectangles for mapping links
Edit:
You can also check this document by LanyeThomas which outlines the basic steps:
Create a GraphViz dot file with the required linking information, maybe with a script.
Run GraphViz once to generate an image of the graph.
Run GraphViz again to generate an html image-map of the graph.
Create an index.html (or wiki page) with an IMG tag of the graph, followed by the image-map's html.
Direct the image-map urls to a Wiki page with each node's name - generate the Wiki pages automatically if needed.
Optionally, link directly to the class hierarchy image generated by DoxyGen. Have the Wiki page link to any additional documentation, including DoxyGen docs, images, etc.
You can use pygraphviz and cmapx
import pygraphviz
my_graph = pygraphviz.AGraph(id="my_graph", name="my_graph")
my_graph.add_node("node",
label="my_node",
tooltip="tooltip text \r next line", # use \r for new line
URL="http://ya.ru/",
target="_blank")
my_graph.layout(prog='dot')
my_graph.draw(path="my_graph.map", format="cmapx")
my_graph.draw(path="my_graph.svg", format="svg")
then use content of my_graph.map in html
<IMG SRC="my_graph.svg" USEMAP="#my_graph" />
... [content of my_graph.map] ...
You could use click maps:
<img src="graph.png" width="400" height="300" usemap="#mygraphmap">
<map name="mygraphmap">
<area shape="circle" coords="100,100,30" href="f8a08.htm">
<area shape="circle" coords="200,100,30" href="1d0f.htm">
</map>
You'd obviously have to find out the coordinates somehow.
edit: You can also use rect or polygon for the shape attribute. I think you can also add a mouseover or title attribute to the area elements.
more edit: Or you could make graphviz output svg which can be integrated in the html5 DOM. I mean that you might be able to handle the elements inside a graph as a DOM-object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With