Example #1
0
def visualize_trie( t ) :
    def walk( node, parent=None ) :
        if parent is None :
            parent = graph.newItem('root')
        for k, v in node[1].items() :
            n = graph.newItem(k)
            graph.newLink(parent, n)
            if v[1] :
                walk(v, n)
    graph = GvGen()
    walk(t.root)
    graph.dot()
    def generateGraphizGraph(self):
        """Return graphviz graph of this trie.
		
		@return: gvgen.GvGen object
		"""
        graph = GvGen()
        self.root.generateGraphizGraph(graph)
        return graph
Example #3
0
    def to_graph(self, filename='graph.jpg'):
        """ Generates a jpg-file displaying the instrument tree. """

        self.graph_filename = filename

        if self.graph_filename.endswith('.jpg'):
            dot_filename = self.graph_filename[:-4] + '.dot'
            jpg_filename = self.graph_filename
        else:
            dot_filename = self.graph_filename + '.dot'
            jpg_filename = self.graph_filename + '.jpg'

        graph = GvGen()
        graph.styleDefaultAppend("color", "red")
        graph.styleDefaultAppend("style", "filled")
        graph.styleDefaultAppend("fontcolor", "white")

        stack = []
        new_parents = []
        stack.append(self.instrument_tree)

        root = True
        while (len(stack) > 0):
            if root:
                sub_tree = stack.pop()
                node = graph.newItem(sub_tree["code"]["symbol"])
                root = False
            else:
                sub_tree = stack.pop()
                node = new_parents.pop()

            if len(sub_tree["children"]) > 0:
                for i, child in enumerate(sub_tree["children"]):

                    if child["code"]["name"] == "const":
                        const_value = round(float(child["code"]["value"]), 2)
                        child_node = graph.newItem(const_value)
                        graph.styleAppend("const", "shape", "rectangle")
                        graph.styleAppend("const", "color", "black")
                        graph.styleAppend("const", "style", "filled")
                        graph.styleApply("const", child_node)

                    else:
                        child_node = graph.newItem(child["code"]["symbol"])
                        stack.append(child)
                        new_parents.append(child_node)

                    curr_link = graph.newLink(node, child_node)

                    if sub_tree["code"]["type"] == "code":
                        graph.propertyAppend(
                            curr_link, "label",
                            sub_tree["code"]["params"][i]["name"])

        f = open(dot_filename, 'w')
        graph.dot(f)
        f.close()
        os.system('dot -Tjpg %(dot)s -o %(jpg)s' % {
            "dot": dot_filename,
            "jpg": jpg_filename
        })
Example #4
0
    def to_graph(self, filename='graph.jpg'):
        """ Generates a jpg-file displaying the instrument tree. """

        self.graph_filename = filename

        if self.graph_filename.endswith('.jpg'):
            dot_filename = self.graph_filename[:-4] + '.dot'
            jpg_filename = self.graph_filename
        else:
            dot_filename = self.graph_filename + '.dot'
            jpg_filename = self.graph_filename + '.jpg'

        graph = GvGen()
        graph.styleDefaultAppend("color", "red")
        graph.styleDefaultAppend("style", "filled")
        graph.styleDefaultAppend("fontcolor", "white")

        stack = []
        new_parents = []
        stack.append(self.instrument_tree)

        root = True
        while (len(stack) > 0):
            if root:
                sub_tree = stack.pop()
                node = graph.newItem(sub_tree["code"]["symbol"])
                root = False
            else:
                sub_tree = stack.pop()
                node = new_parents.pop()

            if len(sub_tree["children"]) > 0:
                for i, child in enumerate(sub_tree["children"]):

                    if child["code"]["name"] == "const":
                        const_value = round(float(child["code"]["value"]), 2)
                        child_node = graph.newItem(const_value)
                        graph.styleAppend("const", "shape", "rectangle")
                        graph.styleAppend("const", "color", "black")
                        graph.styleAppend("const", "style", "filled")
                        graph.styleApply("const", child_node)

                    else:
                        child_node = graph.newItem(child["code"]["symbol"])
                        stack.append(child)
                        new_parents.append(child_node)

                    curr_link = graph.newLink(node, child_node)

                    if sub_tree["code"]["type"] == "code":
                        graph.propertyAppend(
                            curr_link, "label",
                            sub_tree["code"]["params"][i]["name"])

        f = open(dot_filename, 'w')
        graph.dot(f)
        f.close()
        os.system('dot -Tjpg %(dot)s -o %(jpg)s' % {
            "dot": dot_filename, "jpg": jpg_filename})
Example #5
0
def visualize_tst( t, add_legend=False ) :
    def walk( n ) :
        node = graph.newItem(n.splitchar)
        if n.l :
            graph.styleApply("leftNode",graph.newLink(node,walk(n.l)))
        if n.m :
            graph.styleApply("middleNode", graph.newLink(node,walk(n.m)))
        if n.r :
            graph.styleApply("rightNode", graph.newLink(node,walk(n.r)))
        return node
    if add_legend :
        graph = GvGen('Ternary Search Tree')
    else :
        graph = GvGen()
    graph.styleAppend("leftNode", "color", "blue")
    graph.styleAppend("middleNode", "color", "green")
    graph.styleAppend("rightNode", "color", "red")
    if add_legend :
        graph.legendAppend("leftNode", "Left Node")
        graph.legendAppend("middleNode", "Middle Node")
        graph.legendAppend("rightNode", "Right Node")
    walk( t )
    graph.dot()