Search code examples
javascriptpythongraphvizpygraphviz

Display node information(other custom information) when i hover/click over a node in Graphviz in python


I am coding in python by importing graphviz, i have a set of nodes but i want to display further info once i hover/click on the node. I tried googling but looks like their site http://www.graphviz.org/ is down. Can someone help me out on this.

 import graphviz as gv
 g1.attr('node',shape="box")
 g1.attr('node',fontname="Lucida Sans   Unicode",style="filled",fillcolor="mediumslateblue",label="hostinfo")
 g1.attr('node',URL="http://google.com")
 g1.node(dest)

Solution

  • 1- after importing the library you should create a graph:

        g1 = gv.Graph()
    

    2- then you can add a node into your graph:

        g1.node("MyNode")
    

    3- then you can add any more styling to your node using the same name you assigned to the node:

        g1.node("MyNode", shape="box", fontname="Lucida Sans   Unicode",style="filled",fillcolor="mediumslateblue",label="hostinfo", URL="http://google.com" )
    

    4- After that you have to render the graph:

        g1.render()
    

    The output image will be saved in your current directory and it will look like this when I hove over the node, and it's a clickable node:

    enter image description here

    Note: you can skip step2 if you are doing step3