File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 22
22
from .utils import *
23
23
from .matrix import *
24
24
from .io import *
25
+ from .gviz import *
25
26
26
27
# Setup global module state
27
28
init_wrapper ()
Original file line number Diff line number Diff line change
1
+ def matrix_data_to_gviz (shape , rows , cols , ** kwargs ):
2
+ if len (rows ) != len (cols ):
3
+ raise Exception ("Rows and cols arrays must have equal size" )
4
+ result = "digraph {\n "
5
+ graph_name = kwargs .get ("graph_name" )
6
+ vertex_color = kwargs .get ("vertex_color" )
7
+ edge_color = kwargs .get ("edge_color" )
8
+ _base_vertex = kwargs .get ("base_vertex" )
9
+ _label = kwargs .get ("label" )
10
+ label = "" if _label is None else _label
11
+ base_vertex = 0 if _base_vertex is None else _base_vertex
12
+
13
+ n = shape [0 ]
14
+ m = shape [1 ]
15
+
16
+ if not (graph_name is None ):
17
+ result += f'graph [label={ graph_name } ];\n '
18
+ if not (vertex_color is None ):
19
+ result += f'node [color={ vertex_color } ];\n '
20
+ if not (vertex_color is None ):
21
+ result += f'edge [color={ edge_color } ];\n '
22
+
23
+ used_vertex = [False ] * n
24
+ for i in range (len (rows )):
25
+ result += f"{ rows [i ] + base_vertex } -> { cols [i ] + base_vertex } [label={ label } ];\n "
26
+ used_vertex [rows [i ]] = True
27
+ used_vertex [cols [i ]] = True
28
+ for i in range (n ):
29
+ if not used_vertex [i ]:
30
+ result += f"{ i + base_vertex } ;\n "
31
+ result += "}\n "
32
+ return result
You can’t perform that action at this time.
0 commit comments