예제 #1
0
 def test_node_records(self):
     graph = Graph()
     (graph.add_node_record('struct1', '<f0> left|<f1> middle|<f2> right').
      add_node_record('struct2', '<f0> one|<f1> two').add_node_record(
          'struct3',
          'hello&#92;nworld |{ b |{c|<here> d|e}| f}| g | h').add_edge(
              'struct1:f1', 'struct2:f0').add_edge('struct1:f2',
                                                   'struct3:here'))
     graph_dot = Graph_Dot(graph)
     (graph_dot.set_layout_engine_dot().render_svg_to_file(self.svg_file))
     graph_dot.print_dot_code()
예제 #2
0
 def test_extra_dot_code(self):
     extra_dot = """
                     node [shape=record];
                     struct1 [label="<f0> left|<f1> middle|<f2> right"];
                     struct2 [label="<f0> one|<f1> two"];
                     struct3 [label="hello&#92;nworld |{ b |{c|<here> d|e}| f}| g | h"];
                     struct1:f1 -> struct2:f0;
                     struct1:f2 -> struct3:here;                                                
                 """
     (Graph_Dot().set_layout_engine_dot().set_extra_dot_code(
         extra_dot).render_svg_to_file(self.svg_file))
예제 #3
0
    def test_graph__set_rank__set_label__set_node_params(self):
        #graph_dot = Lambda_Graph().get_graph_dot('graph_SCE')
        graph_dot = Graph_Dot()
        graph_dot.graph.add_node('extra node',data={'shape': 'rectangle', 'color': 'black', 'fontcolor': 'white', 'fontsize': 10, 'width':2}) \
                       .add_edge('extra node', 'GUILD-4', {'label': 'an label', 'color': 'red', 'fontsize': 10 ,'dir': 'both'})      \
                       .add_edge_with_label('extra node', 'an-label-2', 'GUILD-4', { 'color': 'red', 'fontsize': 10, 'dir': 'back'})

        graph_dot.graph.add_edge_in_direction('aaa', 'both', 'both')
        graph_dot.graph.add_edge__back('aaa', 'back')
        graph_dot.graph.add_edge__both('aaa', 'both')
        graph_dot.graph.add_edge__forward('aaa', 'forward')
        graph_dot.graph.add_edge__none('aaa', 'none', {'label': 'edge label'})

        (graph_dot.set_layout_engine_dot().set_rank_dir('LR').set_label(
            'Controlling direction of edges\n\n').set_node_params({
                'shape':
                'box',
                'color':
                'deepskyblue',
                'style':
                'filled'
            }).set_concentrate().render_svg_to_file(self.svg_file))
        graph_dot.print_dot_code()
예제 #4
0
 def get_graph_dot(self, graph_name):
     return Graph_Dot(self.get_graph(graph_name))
예제 #5
0
    def test_sub_graphs(self):
        # dot_code = """subgraph cluster_0 {
        #                 style=filled;
        #                 color=lightgrey;
        #                 node [style=filled,color=white];
        #                 a0 -> a1 -> a2 -> a3;
        #                 label = "process #1";
        #                }
        #
        #                subgraph cluster_1 {
        #                 node [style=filled];
        #                 b0 -> b1 -> b2 -> b3;
        #                 label = "process #2";
        #                 color=blue
        #               }
        #
        #               start -> a0;
        #               start -> b0;
        #               a1 -> b3;
        #               b2 -> a3;
        #               a3 -> a0;
        #               a3 -> end;
        #               b3 -> end;
        #
        #               start [shape=Mdiamond];
        #               end [shape=Msquare];
        #               """

        subgraph_1 = Graph_Dot(graph_name='cluster_F1', graph_type='subgraph')

        (subgraph_1.add_edges([
            ('a0', 'a1'), ('a1', 'a2'), ('a2', 'a3')
        ]).set_node_params({
            'style': 'filled',
            'color': 'white'
        }).set_extra_dot_code("""style=filled; color=lightgrey;""").set_label(
            'process #1'))

        subgraph_2 = Graph_Dot(graph_name='cluster_G1', graph_type='subgraph')
        (subgraph_2.add_edges([
            ('b0', 'b1'), ('b1', 'b2'), ('b2', 'b3')
        ]).set_node_params({
            'style': 'filled'
        }).set_extra_dot_code("""color=blue;""").set_label('process #2'))

        graph_dot = Graph_Dot().add_sub_graph(subgraph_1).add_sub_graph(
            subgraph_2)

        (graph_dot.add_edge('start', 'a0').add_edge('start', 'b0').add_edge(
            'a1', 'b3').add_edge('b2', 'a3').add_edge('a3', 'a0').add_edge(
                'a3', 'end').add_edge('b3',
                                      'end').add_node('start', {
                                          'shape': 'Mdiamond'
                                      }).add_node('end', {'shape': 'Msquare'}))

        #graph_dot.set_extra_dot_code(dot_code).set_layout_engine_dot()
        graph_dot.set_layout_engine_dot()
        graph_dot.render_svg_to_file(self.svg_file)
        graph_dot.print_dot_code()
예제 #6
0
 def setUp(self):
     super().setUp()
     self.svg_file = '/tmp/dot_image.svg'
     self.test_graph = Sample_Graphs.simple_dot_file()
     self.graph_dot = Graph_Dot(self.test_graph)
예제 #7
0
class test_Graph_Dot(Test_Helper):
    def setUp(self):
        super().setUp()
        self.svg_file = '/tmp/dot_image.svg'
        self.test_graph = Sample_Graphs.simple_dot_file()
        self.graph_dot = Graph_Dot(self.test_graph)

    def test_render(self):
        print()
        print(self.graph_dot.render())

    def test_render_svg(self):
        result = self.graph_dot.render_svg()
        svg = result.get('svg')
        if svg:
            file_create(self.svg_file, svg)
        else:
            self.result = result

    def test_sample_dot_graph(self):
        #self.test_graph.add_node('aaa', data={'shape':'box', 'color':'red'})
        #self.graph_dot.set_label('aaaa').set_node_param('shape','box')
        self.result = self.graph_dot.render_svg_to_file(self.svg_file)
        #self.graph_dot.print_dot_code()

    def test_extra_dot_code(self):
        extra_dot = """
                        node [shape=record];
                        struct1 [label="<f0> left|<f1> middle|<f2> right"];
                        struct2 [label="<f0> one|<f1> two"];
                        struct3 [label="hello&#92;nworld |{ b |{c|<here> d|e}| f}| g | h"];
                        struct1:f1 -> struct2:f0;
                        struct1:f2 -> struct3:here;                                                
                    """
        (Graph_Dot().set_layout_engine_dot().set_extra_dot_code(
            extra_dot).render_svg_to_file(self.svg_file))

    def test_node_records(self):
        graph = Graph()
        (graph.add_node_record('struct1', '<f0> left|<f1> middle|<f2> right').
         add_node_record('struct2', '<f0> one|<f1> two').add_node_record(
             'struct3',
             'hello&#92;nworld |{ b |{c|<here> d|e}| f}| g | h').add_edge(
                 'struct1:f1', 'struct2:f0').add_edge('struct1:f2',
                                                      'struct3:here'))
        graph_dot = Graph_Dot(graph)
        (graph_dot.set_layout_engine_dot().render_svg_to_file(self.svg_file))
        graph_dot.print_dot_code()

    def test_from_gs_graph(self):
        graph = Graph()
        #graph_name = 'graph_QIN'  # (SOW-18 128 nodes)
        #graph_name = 'graph_YXT' # person-42 (manages, 43 nodes)
        #graph_name = 'graph_CXJ'   # Playbook-2 (103 nodes)
        graph_name = 'graph_SCE'  # PERSON-4 (8 nodes)

        graph_dot = Lambda_Graph().get_graph_dot(graph_name)

        (graph_dot.set_layout_engine_dot().render_svg_to_file(self.svg_file))

    def test_from_records(self):
        graph_dot = Graph_Dot()
        graph_dot.graph.add_node('aaaa')
        graph_dot.set_layout_engine_dot()
        graph_dot.render_svg_to_file(self.svg_file)

    def test_graph__set_rank__set_label__set_node_params(self):
        #graph_dot = Lambda_Graph().get_graph_dot('graph_SCE')
        graph_dot = Graph_Dot()
        graph_dot.graph.add_node('extra node',data={'shape': 'rectangle', 'color': 'black', 'fontcolor': 'white', 'fontsize': 10, 'width':2}) \
                       .add_edge('extra node', 'GUILD-4', {'label': 'an label', 'color': 'red', 'fontsize': 10 ,'dir': 'both'})      \
                       .add_edge_with_label('extra node', 'an-label-2', 'GUILD-4', { 'color': 'red', 'fontsize': 10, 'dir': 'back'})

        graph_dot.graph.add_edge_in_direction('aaa', 'both', 'both')
        graph_dot.graph.add_edge__back('aaa', 'back')
        graph_dot.graph.add_edge__both('aaa', 'both')
        graph_dot.graph.add_edge__forward('aaa', 'forward')
        graph_dot.graph.add_edge__none('aaa', 'none', {'label': 'edge label'})

        (graph_dot.set_layout_engine_dot().set_rank_dir('LR').set_label(
            'Controlling direction of edges\n\n').set_node_params({
                'shape':
                'box',
                'color':
                'deepskyblue',
                'style':
                'filled'
            }).set_concentrate().render_svg_to_file(self.svg_file))
        graph_dot.print_dot_code()

    def test_sub_graphs(self):
        # dot_code = """subgraph cluster_0 {
        #                 style=filled;
        #                 color=lightgrey;
        #                 node [style=filled,color=white];
        #                 a0 -> a1 -> a2 -> a3;
        #                 label = "process #1";
        #                }
        #
        #                subgraph cluster_1 {
        #                 node [style=filled];
        #                 b0 -> b1 -> b2 -> b3;
        #                 label = "process #2";
        #                 color=blue
        #               }
        #
        #               start -> a0;
        #               start -> b0;
        #               a1 -> b3;
        #               b2 -> a3;
        #               a3 -> a0;
        #               a3 -> end;
        #               b3 -> end;
        #
        #               start [shape=Mdiamond];
        #               end [shape=Msquare];
        #               """

        subgraph_1 = Graph_Dot(graph_name='cluster_F1', graph_type='subgraph')

        (subgraph_1.add_edges([
            ('a0', 'a1'), ('a1', 'a2'), ('a2', 'a3')
        ]).set_node_params({
            'style': 'filled',
            'color': 'white'
        }).set_extra_dot_code("""style=filled; color=lightgrey;""").set_label(
            'process #1'))

        subgraph_2 = Graph_Dot(graph_name='cluster_G1', graph_type='subgraph')
        (subgraph_2.add_edges([
            ('b0', 'b1'), ('b1', 'b2'), ('b2', 'b3')
        ]).set_node_params({
            'style': 'filled'
        }).set_extra_dot_code("""color=blue;""").set_label('process #2'))

        graph_dot = Graph_Dot().add_sub_graph(subgraph_1).add_sub_graph(
            subgraph_2)

        (graph_dot.add_edge('start', 'a0').add_edge('start', 'b0').add_edge(
            'a1', 'b3').add_edge('b2', 'a3').add_edge('a3', 'a0').add_edge(
                'a3', 'end').add_edge('b3',
                                      'end').add_node('start', {
                                          'shape': 'Mdiamond'
                                      }).add_node('end', {'shape': 'Msquare'}))

        #graph_dot.set_extra_dot_code(dot_code).set_layout_engine_dot()
        graph_dot.set_layout_engine_dot()
        graph_dot.render_svg_to_file(self.svg_file)
        graph_dot.print_dot_code()
예제 #8
0
 def test_from_records(self):
     graph_dot = Graph_Dot()
     graph_dot.graph.add_node('aaaa')
     graph_dot.set_layout_engine_dot()
     graph_dot.render_svg_to_file(self.svg_file)