diff --git a/N2G/plugins/diagrams/N2G_DrawIO.py b/N2G/plugins/diagrams/N2G_DrawIO.py index 8f9d655..cde430b 100644 --- a/N2G/plugins/diagrams/N2G_DrawIO.py +++ b/N2G/plugins/diagrams/N2G_DrawIO.py @@ -442,17 +442,20 @@ def dump_file(self, filename=None, folder="./Output/"): with open(os.path.join(folder, filename), "w") as outfile: outfile.write(self.dump_xml()) - def layout(self, algo="kk", **kwargs): + def layout(self, algo="kk", ig_kwargs=None, **kwargs): """ Method to calculate graph layout using Python - `igraph `_ + `igraph `_ library **Parameters** * ``algo`` (str) name of layout algorithm to use, default is 'kk'. Reference `Layout algorithms` table below for valid algo names + * ``ig_kwargs`` (dict) arguments to use to instantiate igraph's Graph instance + as per `documentation `_ * ``kwargs`` any additional kwargs to pass to igraph ``Graph.layout`` method + as per `documentation `_ **Layout algorithms** @@ -492,19 +495,18 @@ def layout(self, algo="kk", **kwargs): raise SystemExit( "Failed to import igraph, install - pip install python-igraph" ) + ig_kwargs = ig_kwargs or {} # iterate over diagrams and layout elements for diagram in self.drawing.findall("./diagram"): - igraph_graph = ig() + igraph_graph = ig(**ig_kwargs) self.go_to_diagram(diagram.attrib["name"]) # populate igraph with nodes and edges from object tags for item in self.current_root.iterfind("./object"): # add edges, item[0] refernece to object's mxCell child tag if item[0].get("source") and item[0].get("target"): - igraph_graph.add_vertex(name=item[0].get("source")) - igraph_graph.add_vertex(name=item[0].get("target")) - igraph_graph.add_edge( - source=item[0].get("source"), target=item[0].get("target") - ) + src = igraph_graph.add_vertex(name=item[0].get("source")) + tgt = igraph_graph.add_vertex(name=item[0].get("target")) + igraph_graph.add_edge(source=src, target=tgt) # add nodes else: igraph_graph.add_vertex(name=item.get("id")) diff --git a/tests/Output/should_be_test_xlsx_data_base.drawio b/tests/Output/should_be_test_xlsx_data_base.drawio index 0c1816e..7211e86 100644 --- a/tests/Output/should_be_test_xlsx_data_base.drawio +++ b/tests/Output/should_be_test_xlsx_data_base.drawio @@ -1,44 +1,44 @@ - + - + - - - + + + - - - + + + - - - + + + - - + + - - + + - - - + + + - - + + - - + + - - - + + + diff --git a/tests/Output/should_be_test_xlsx_data_tanslate_headers.drawio b/tests/Output/should_be_test_xlsx_data_tanslate_headers.drawio index 0c1816e..7211e86 100644 --- a/tests/Output/should_be_test_xlsx_data_tanslate_headers.drawio +++ b/tests/Output/should_be_test_xlsx_data_tanslate_headers.drawio @@ -1,44 +1,44 @@ - + - + - - - + + + - - - + + + - - - + + + - - + + - - + + - - - + + + - - + + - - + + - - - + + + diff --git a/tests/Output/should_be_test_xlsx_data_tanslate_headers_several_tabs.drawio b/tests/Output/should_be_test_xlsx_data_tanslate_headers_several_tabs.drawio index 24d0866..7a650df 100644 --- a/tests/Output/should_be_test_xlsx_data_tanslate_headers_several_tabs.drawio +++ b/tests/Output/should_be_test_xlsx_data_tanslate_headers_several_tabs.drawio @@ -1,72 +1,72 @@ - + - + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - - + + - - - + + + - - + + - - + + - - - + + + - - + + - - + + - - - + + + - - + + - - + + - - - + + +