# # Sam Hadow - Huffman-py # Copyright (C) 2023 # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import graphviz def generate_node(graph, node, father = None): if node.left and node.right: # not a leaf graph.node(str(node.identifier), label = str(node.occurrence) , style = "filled", fillcolor = "red", shape="circle") else: # a leaf graph.node(str(node.identifier), label = graphviz.escape(str(node.occurrence)+'\n'+str(node.char)), style = "filled", fillcolor = "green") # https://graphviz.readthedocs.io/en/stable/api.html#graphviz.escape if father != None: graph.edge(str(father), str(node.identifier), label=str(node.code)) if node.left: generate_node(graph, node.left, node.identifier) if node.right: generate_node(graph, node.right, node.identifier)