Skip to content

Commit 65ae9b2

Browse files
committed
visual and merger
1 parent aae5d77 commit 65ae9b2

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

cyaron/merger.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ def add_edge(self, u, v, **kwargs):
3131
self.graphs[ v[0] ].offset + v[1],
3232
weight=kwargs.get("weight", 1))
3333

34-
def result(self):
35-
return self.G
34+
def to_str(self, **kwargs):
35+
return self.G.to_str(**kwargs)
36+
37+
def __str__(self):
38+
return self.to_str()
3639

3740
@staticmethod
3841
def component(point_count, edge_count, **kwargs):
@@ -51,4 +54,4 @@ def component(point_count, edge_count, **kwargs):
5154
for i in xrange(real_count):
5255
graphs[i] = Graph.graph(point_count, edge_count, **kwargs)
5356
G = Merger(*graphs)
54-
return G.result()
57+
return G.G

cyaron/visual.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from .graph import *
2+
from .merger import Merger
23
import pygraphviz as pgv
34

4-
def visualize(graph, **kwargs):
5+
def visualize(graph, output_path="a.png"):
56
"""visualize(graph, **kwargs) -> None
6-
Graph graph -> the graph that will be visualized
7-
**kwargs(Keyword args):
8-
string outptu_file -> the path of the image
7+
Graph/Merger graph -> the graph/Merger that will be visualized
8+
string output_path-> the output path of the image
99
"""
10-
output_file = kwargs.get("output_file", "a.png")
10+
11+
if isinstance(graph, Merger): graph = Merger.G
1112
G = pgv.AGraph(directed=graph.directed)
1213

1314
G.add_nodes_from([i for i in xrange(1, len(graph.edges))])
@@ -20,6 +21,6 @@ def visualize(graph, **kwargs):
2021
G.edge_attr['arrowhead'] = 'open'
2122

2223
G.layout(prog='dot')
23-
G.draw(output_file)
24+
G.draw(output_path)
2425

2526

0 commit comments

Comments
 (0)