Ejemplo n.º 1
0
 def test_paths(self):
     g = nx.Graph()
     g.add_edge(Node(0, 0), Node(1, 0))
     g.add_edge(Node(3, 0), Node(2, 0))
     g.add_edge(Node(2, 0), Node(1, 0))
     g.add_edge(Node(2, 0), Node(2, 2))
     g.add_edge(Node(3, 0), Node(3, 2))
     opengraph = OpenGraph(g)
     assert len(opengraph.paths()) == 2
Ejemplo n.º 2
0
 def test_min_max(self):
     graph = nx.Graph()
     graph.add_node(Node(0,-1))
     graph.add_node(Node(1,1))
     graph.add_node(Node(-2,4))
     graph.add_node(Node(3,-5))
     opengraph = OpenGraph(graph)
     assert opengraph.min() == (-2, -5)
     assert opengraph.max() == (3, 4)
Ejemplo n.º 3
0
    def test_draw_open_graph(self):
        self.__backend.set_canvas_size(80, 80)
        self.__backend.create_canvas()
        graph = nx.Graph()
        open_graph = OpenGraph(graph)

        self.__backend.push_surface()
        self.__backend.draw_open_graph(open_graph)
        self.__backend.export_to_file(
            TestUtils.OPEN_GRAPH_EMPTY_GENERATED_IMAGE)
        self.__backend.pop_surface()
        assert TestUtils.images_equal(
            TestUtils.OPEN_GRAPH_EMPTY_GENERATED_IMAGE,
            TestUtils.OPEN_GRAPH_EMPTY_EXPECTED_IMAGE)

        graph.add_edge(Node(10, 10), Node(20, 10))
        graph.add_edge(Node(20, 10), Node(20, 20))
        graph.add_edge(Node(20, 20), Node(10, 20))
        graph.add_edge(Node(10, 20), Node(10, 10))
        open_graph = OpenGraph(graph)
        self.__backend.push_surface()
        self.__backend.draw_open_graph(open_graph)
        self.__backend.export_to_file(
            TestUtils.OPEN_GRAPH_CLOSED_GENERATED_IMAGE)
        self.__backend.pop_surface()
        assert TestUtils.images_equal(
            TestUtils.OPEN_GRAPH_CLOSED_GENERATED_IMAGE,
            TestUtils.OPEN_GRAPH_CLOSED_EXPECTED_IMAGE)

        graph = nx.Graph()
        edge_list = [((10, 10), (40, 10)), ((40, 10), (60, 10)),
                     ((40, 10), (50, 40)), ((50, 40), (20, 30)),
                     ((50, 40), (50, 60))]
        for edge in edge_list:
            graph.add_edge(Node(*edge[0]), Node(*edge[1]))
        graph.add_edge(Node(50, 60, 'curve'), Node(20, 80, 'curve'))
        graph.add_edge(Node(20, 80, 'curve'), Node(40, 90, 'curve'))
        open_graph = OpenGraph(graph)

        self.__backend.push_surface()
        self.__backend.draw_open_graph(open_graph)
        self.__backend.export_to_file(TestUtils.OPEN_GRAPH_GENERATED_IMAGE)
        self.__backend.pop_surface()
        assert TestUtils.images_equal(TestUtils.OPEN_GRAPH_GENERATED_IMAGE,
                                      TestUtils.OPEN_GRAPH_EXPECTED_IMAGE)
Ejemplo n.º 4
0
 def test_run(self):
     parser = StyleParser()
     arrow_style = Style('_arrow_', 'fill', ['red'], 1)
     fill_style = Style('.*', 'fill', ['blue'], 0)
     line_style = Style('_line_', 'fill', ['green'], 2)
     frame_style = Style('.*', 'frame', [[0.1, 0.2, 0.3]], 0)
     custom_fill_style = Style('(abc)|(def)', 'fill', [[0.3, 0.2, 0.3]], 3)
     custom_line_style = Style('line', 'fill', [[0.4, 0.3, 0.3]], 3)
     custom_frame_style = Style('(abc)|(def)', 'frame', [[0.5, 0.2, 0.3]], 3)
     polygon1 = Polygon([Node(0, 0)])
     opengraph1 = OpenGraph()
     opengraph2 = OpenGraph()
     opengraph2.add_name('line')
     arrow = Arrow()
     background = Background()
     polygon2 = Polygon([Node(0, 0)])
     polygon2.add_name('abc')
     polygon3 = Polygon([Node(0, 0)])
     polygon3.add_name('def')
     
     objects = [arrow_style, fill_style, line_style, frame_style, custom_fill_style, custom_line_style, custom_frame_style, polygon1, polygon2, polygon3, opengraph1, opengraph2, arrow, background]
     parser.run([], objects)
     assert arrow.style().color() == arrow_style.color(), str(arrow.style().color()) + " != " + str(arrow_style.color())
     assert polygon1.style().color() == fill_style.color(), str(polygon1.style().color()) + " != " + str(fill_style.color())
     assert polygon1.frame().style().color() == frame_style.color()
     assert opengraph1.style().color() == line_style.color()
     assert opengraph2.style().color() == custom_line_style.color()
     assert polygon2.style().color() == custom_fill_style.color()
     assert polygon3.style().color() == custom_fill_style.color()
     assert polygon2.frame().style().color() == custom_frame_style.color()
     assert polygon3.frame().style().color() == custom_frame_style.color()
Ejemplo n.º 5
0
    def test_draw_open_graph_shadow(self):
        self.__backend.set_canvas_size(50, 150)
        self.__backend.create_canvas()
        graph = nx.Graph()
        open_graph = OpenGraph(graph)

        self.__backend.push_surface()
        self.__backend.draw_open_graph_shadow(open_graph)
        self.__backend.export_to_file(
            TestUtils.OPEN_GRAPH_SHADOW_EMPTY_GENERATED_IMAGE)
        self.__backend.pop_surface()
        assert TestUtils.images_equal(
            TestUtils.OPEN_GRAPH_SHADOW_EMPTY_GENERATED_IMAGE,
            TestUtils.OPEN_GRAPH_SHADOW_EMPTY_EXPECTED_IMAGE)

        edge_list = [((10, 10), (40, 10)), ((40, 10), (60, 10)),
                     ((40, 10), (50, 40)), ((50, 40), (20, 30)),
                     ((50, 40), (50, 60))]
        edge_list2 = [((10, 10), (40, 10)), ((40, 10), (50, 40)),
                      ((50, 40), (20, 30)), ((20, 30), (10, 10))]
        for edge in edge_list:
            graph.add_edge(Node(*edge[0]), Node(*edge[1]))
        graph2 = nx.Graph()
        for edge in edge_list2:
            graph2.add_edge(Node(*edge[0], style='curve'),
                            Node(*edge[1], style='curve'))
        open_graph = OpenGraph(graph)
        open_graph2 = OpenGraph(graph2)

        self.__backend.push_surface()
        self.__backend.draw_open_graph_shadow(open_graph)
        self.__backend.translate(0, 60)
        self.__backend.draw_open_graph_shadow(open_graph2)
        self.__backend.export_to_file(
            TestUtils.OPEN_GRAPH_SHADOW_GENERATED_IMAGE)
        self.__backend.pop_surface()
        assert TestUtils.images_equal(
            TestUtils.OPEN_GRAPH_SHADOW_GENERATED_IMAGE,
            TestUtils.OPEN_GRAPH_SHADOW_EXPECTED_IMAGE)
Ejemplo n.º 6
0
 def generate_test_opengraph(seed=0, points=12, radius_range=(10, 50)):
     random.seed(seed)
     point_list = []
     graph = nx.Graph()
     for i in range(0, points / 2):
         angle1 = math.radians(i * 360 / points - 180)
         angle2 = math.radians(-1 * (i * 360 / points - 180))
         radius = random.randint(*radius_range)
         point1 = (math.sin(angle1) * radius, math.cos(angle1) * radius)
         point2 = (math.sin(angle2) * radius, math.cos(angle2) * radius)
         graph.add_edge(Node(*point1), Node(0, 0))
         graph.add_edge(Node(*point2), Node(0, 0))
     opengraph = OpenGraph(graph)
     return opengraph
Ejemplo n.º 7
0
    def test_run(self):
        parser = StyleParser()
        arrow_style = Style('_arrow_', 'fill', ['red'], 1)
        fill_style = Style('.*', 'fill', ['blue'], 0)
        line_style = Style('_line_', 'fill', ['green'], 2)
        frame_style = Style('.*', 'frame', [[0.1, 0.2, 0.3]], 0)
        custom_fill_style = Style('(abc)|(def)', 'fill', [[0.3, 0.2, 0.3]], 3)
        custom_line_style = Style('line', 'fill', [[0.4, 0.3, 0.3]], 3)
        custom_frame_style = Style('(abc)|(def)', 'frame', [[0.5, 0.2, 0.3]],
                                   3)
        polygon1 = Polygon([Node(0, 0)])
        opengraph1 = OpenGraph()
        opengraph2 = OpenGraph()
        opengraph2.add_name('line')
        arrow = Arrow()
        background = Background()
        polygon2 = Polygon([Node(0, 0)])
        polygon2.add_name('abc')
        polygon3 = Polygon([Node(0, 0)])
        polygon3.add_name('def')

        objects = [
            arrow_style, fill_style, line_style, frame_style,
            custom_fill_style, custom_line_style, custom_frame_style, polygon1,
            polygon2, polygon3, opengraph1, opengraph2, arrow, background
        ]
        parser.run([], objects)
        assert arrow.style().color() == arrow_style.color(), str(
            arrow.style().color()) + " != " + str(arrow_style.color())
        assert polygon1.style().color() == fill_style.color(), str(
            polygon1.style().color()) + " != " + str(fill_style.color())
        assert polygon1.frame().style().color() == frame_style.color()
        assert opengraph1.style().color() == line_style.color()
        assert opengraph2.style().color() == custom_line_style.color()
        assert polygon2.style().color() == custom_fill_style.color()
        assert polygon3.style().color() == custom_fill_style.color()
        assert polygon2.frame().style().color() == custom_frame_style.color()
        assert polygon3.frame().style().color() == custom_frame_style.color()
Ejemplo n.º 8
0
 def test_graph(self):
     opengraph = OpenGraph()
     assert opengraph.graph().nodes() == []
Ejemplo n.º 9
0
 def test_init(self):
     opengraph = OpenGraph()
     assert opengraph != None
     assert opengraph.style().target_type() == 'fill'
     assert opengraph.paths() == []