hbmartin / graphviz2drawio

Convert graphviz (dot) files to draw.io / lucid (mxGraph) format. Beautiful and editable graphs in your favorite editor.
https://pypi.org/project/graphviz2drawio/
GNU General Public License v3.0
186 stars 32 forks source link

Simple example fails with `IndexError` #1

Closed zdk123 closed 6 years ago

zdk123 commented 6 years ago

Thanks for this tool... and very timely for me.

Your SmileyFace example is working fine, but simple graphs seem to fail. For example, the PyGraphics quick example:

import pygraphviz as pgv
G = pgv.AGraph()
G.add_node('a')
G.add_edge('b','c')
from graphviz2drawio import graphviz2drawio
graphviz2drawio.convert(G)

gives:

    nodes, edges = SVG.parse(svg_graph)
  File "/Users/zachary/miniconda3/envs/py36/lib/python3.6/site-packages/graphviz2drawio/models/SVG.py", line 20, in parse
    nodes[title] = node_factory.from_svg(g)
  File "/Users/zachary/miniconda3/envs/py36/lib/python3.6/site-packages/graphviz2drawio/models/NodeFactory.py", line 46, in from_svg
    rect = self.rect_from_svg_points(SVG.get_first(g, "polygon").attrib["points"])
  File "/Users/zachary/miniconda3/envs/py36/lib/python3.6/site-packages/graphviz2drawio/models/SVG.py", line 28, in get_first
    return g.findall("./{http://www.w3.org/2000/svg}" + tag)[0]
IndexError: list index out of range

thanks!

tinder-haroldmartin commented 6 years ago

@zdk123 will be fixed in the next release in a couple of days, thanks for the report

zdk123 commented 6 years ago

Poked around a bit more and of course the error is actually related to not having any node attributes.

The following construction seems to work:

G = pgv.AGraph({'a':'', 'b':'c', 'c':''}, directed=True)
for n in ['a','b','c']:
   G.get_node(n).attr['shape']='record'
hbmartin commented 6 years ago

@zdk123 please try the 0.0.3 release and let me know how that looks. The next release will address the odd edge shape.

hbmartin commented 6 years ago

Fixes complete in 0.0.4