Package: treevizer
TreevizerVisualize node data structures usingGraphviz.How it worksTreevizer iterates over your datastructure to generate a DOT file and runs Graphviz turn it into an image. The datastructure needs to be built using Nodes.It also support recursive functions.ExamplesLinked listBalanced binary treeTrieRecursive FibonacciPrerequisitesYou need to installGraphvizand make sure it is in $PATH.CygwinGraphviz and Pillow need special installation on Cygwin.GraphvizDon't install Graphviz in Cygwin, do a windows installation. Otherwise there will be a problem with paths.PillowPillow is optional, it is only used to create GIFs. If you don't want to create GIFs you don't need to install it.Don't install Pillow with pip, instead do it with a Cygwin package. Install the Cygwin packagepython3X-imaging, replaceXwith your Python version.Installingpip install treevizerUsageThe following structures are supported:Linked list (ll)Structure type is called "ll". The config key is called "LinkedList".Require a Node class with the attributes that fulfill the following class diagram.Balanced binary tree (bbt)Structure type is called "bbt". The config key is called "BalancedBinaryTree".Require a Node class with the attributes that fulfill the following class diagram.Trie (trie)Structure type is called "trie". The config key is called "Trie".Require a Node class with the attributes that fulfill the following class diagram.Thestopattribute marks if node marks a word (True) or not (False).RecursionDecorate your recursive function withrecursion_viz. It is possible to decorate multiple functions. Each function is identified by the name of your function when creating the PNG or GIF.Exampleimporttreevizer@treevizer.recursion_vizdefa_rec_func():a_rec_func()@treevizer.recursion_vizdefanother_rec_func():another_rec_func()a_rec_func()another_rec_func()treevizer.recursion_to_png("a_rec_func",dot_path="recursion.dot",png_path="recursion.png")treevizer.recursion_to_png("another_rec_func",dot_path="rec2.dot",png_path="rec2.png")To configure the dot language, use "Recursion" as key in the json.FunctionsStructure to DOT fileimporttreevizertreevizer.to_dot(root,structure_type="bbt",dot_path="tree.dot")"""Generate DOT file from node structure.Parameters----------root : NodeRoot node for datastructurestructure_type : strName of the type of datastructure (default is "bbt")dot_path : strPath to generated DOT file (default is tree.dot)"""Structure to PNGThis also creates a DOT file.importtreevizertreevizer.to_png(root,structure_type="bbt",dot_path="tree.dot",png_path="tree.png")"""Generate DOT file from node structure and use Graphviz to create image.Parameters----------root : NodeRoot node for datastructurestructure_type : strName of the type of datastructure (default is "bbt")dot_path : strPath to generated DOT file (default is tree.dot)png_path : strPath to generated png file (default is tree.png)"""Recursion to PNGThis also creates a DOT file.importtreevizer@treevizer.recursion_vizdefa_recusive_function():a_recusive_function()treevizer.recursion_to_png(function_name,dot_path="recursion.dot",png_path="recursion.png")"""Generate DOT file of recursive function calls and use Graphviz to create image.Parameters----------function_name : strName of your decorated function.dot_path : strPath to generated DOT file (default is recursion.dot)png_path : strPath to generated png file (default is recursion.png)"""Recursion to GIFimporttreevizer@treevizer.recursion_vizdefa_recusive_function():a_recusive_function()treevizer.recursion_to_gif(function_name,gif_path="recursion.dot",duration=800,loop=0)"""Generate PNG files of recursive function calls and use Pillow to create GIF.Parameters----------function_name : strName of your decorated function.gif_path : strPath to generated GIF file (default is recursion.gif)duration : intduration, in miliseconds, of how long each image will be displayed in the GIF (default is 800)loop : inthow many times the GIF should loop after initial loop. 0 to loop infinitely (default is 0)"""DOT file to PNGimporttreevizertreevizer.dot_to_png(dot_path="tree.dot",png_path="tree.png")"""Use Graphviz to create image from a DOT file.Parameters----------dot_path : strPath to your DOT file (default is tree.dot)png_path : strPath to generated png file (default is tree.png)"""ConfigureCreate.dot.jsonin root folder to change DOT configuration.  Available options can be found inGraphviz documentation.For example to change color of Nodes in image for balanced binary tree use the following.# .dot.json
{
    "BalancedBinaryTree": {
        "node": {
            "fillcolor": "green"
        }
    }
}To change size and shape of nodes and color of edges in Linked list use the following.# .dot.json
{
    "LinkedList": {
        "node": {
            "shape": "square",
            "width": 1.5
        },
        "edge": {
            "color": "red"
        }
    }
}To change color of the font on edge labels for recursion.{
    "Recursion": {
        "edge": {
            "fontcolor": "black"
        }
    }
}Known Errors/WarningsKnown Errors and WarningsLinksPypiSource codeLicenseThis project is licensed under the MIT License - see theLICENSE.mdfile for details