Code Monkey home page Code Monkey logo

graphviz2drawio's Introduction

graphviz2drawio

pypi Lint and Test codecov.io Code style: black Checked with pytype twitter

Convert graphviz (dot) files into draw.io (mxGraph) format.

Roadmap for 0.3 release (as of July 2, 2024)

  • Migrate from Travis to GHA for CI
  • Migrate from Make to GHA for release
  • Fix "cb" bug
  • Add support for clusters
  • Add support for edge labels
  • Upgrade to latest pygraphviz
  • Upgrade to latest svg.path
  • Reformat for most recent black style
  • Publish api docs to GH pages
  • Remove this section before release! (move to release notes)

Getting Started

Prerequisites

The graphviz library is required before installing this package.

macOS

Python 3 and graphviz can be installed with Homebrew:

brew update
brew install python3 graphviz
# In order to build pygraphviz:
export CFLAGS="-I$(brew --prefix graphviz)/include/"                                                   
export LDFLAGS="-L$(brew --prefix graphviz)/lib/"

Ubuntu / Debian

sudo apt install python3-pip graphviz graphviz-dev

CLI Installation

It is recommended to use pipx to install and run the CLI tool. If you wish to use the library, you can install with pip instead.

brew install pipx
pipx install -U graphviz2drawio

Usage

Run the conversion app on your graphviz file

graphviz2drawio example.dot

You can them import the output XML file into draw.io

Library Usage

from graphviz2drawio import graphviz2drawio

xml = graphviz2drawio.convert(graph_to_convert)
print(xml)

where graph_to_convert can be any of a file path, file handle, string of dot language, or PyGraphviz.AGraph object

Limitations

Please open an issue with your dot file to report crashes or incorrect conversions.

Built With

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Developing

git clone [email protected]:hbmartin/graphviz2drawio.git
cd graphviz2drawio
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Replace with the actual path to your dot files
python -m graphviz2drawio test/directed/hello.gv.txt

Roadmap to 0.4

  • Bezier curve support
  • Subgraph conversion #33
  • Invisible node handling for edges #67
  • Implementation for outstanding TODOs in code
  • Image / tooltip support #49
  • Text on edge alignment #59
  • Support for node with path shape #47

Roadmap to 1.0

  • Complete test suite for official graphviz examples
  • Migrate to uv/hatch for packaging and dep mgmt
  • Port layout/orientation
  • Fix text alignment inside of shape
  • Possible to screenshot test with maxGraph ?

License

GPLv3

graphviz2drawio's People

Contributors

altre avatar bollwyvl avatar bperel avatar deepsource-autofix[bot] avatar dependabot[bot] avatar haisland0909 avatar hbmartin avatar jcaplan avatar ralequi avatar raucha avatar samkhal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphviz2drawio's Issues

Fix edge layout

Edges / arrows are often layed out incorrectly, fix in 0.0.6

Crahses when open .dot file on Python 3.7

I try to open this file https://graphviz.gitlab.io/_pages/Gallery/directed/datastruct.gv.txt -> saved as test.dot using Python 3.7.1 on a Mac with MacOS 10.12.6

This is the error I get:

This is beta software, please report issues to:
https://github.com/hbmartin/graphviz2drawio/issues
Something went wrong, please report
Traceback (most recent call last):
File "/usr/local/bin/graphviz2drawio", line 10, in
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/graphviz2drawio/main.py", line 26, in main
output = convert(args.to_convert, args.program)
File "/usr/local/lib/python3.7/site-packages/graphviz2drawio/graphviz2drawio.py", line 27, in convert
[e.enrich_from_graph(graph_edges[e.gid]) for e in edges]
File "/usr/local/lib/python3.7/site-packages/graphviz2drawio/graphviz2drawio.py", line 27, in
[e.enrich_from_graph(graph_edges[e.gid]) for e in edges]
KeyError: 'node0:f0->node1:f0'
Sentry is attempting to send 2 pending error messages
Waiting up to 10 seconds
Press Ctrl-C to quit

Support for compound=true

The DOT guide (https://www.graphviz.org/pdf/dotguide.pdf) gives an example of a "compound" digraph, which renders with edges between two clusters and edges between nodes and clusters:

digraph G {
  compound=true;
  subgraph cluster0 {
    a -> b;
    a -> c;
    b -> d;
    c -> d;
  }
  subgraph cluster1 {
    e -> g;
    e -> f;
  }
  b -> f [lhead=cluster1];
  d -> e;
  c -> g [ltail=cluster0,lhead=cluster1];
  c -> e [ltail=cluster0];
  d -> h;
}

The DOT Guide rendering

When I convert this with graphviz2drawio, all the cluster information seems to get lost, and all the internal nodes are just connected together. Is there a way to get the conversion to keep the compound subgraph information? Or are you possibly planning on adding support for that?

The graphviz2drawio conversion:

Screen Shot 2020-03-12 at 9 05 48 PM

multiple calls to convert fail

simple test:

from graphviz2drawio import graphviz2drawio as gv
for i in range(2):
    gv.convert("./test/directed/hello.gv.txt")

results in failure:

Error: syntax error in line 1 near '"'
Traceback (most recent call last):
  File "/home/jonah/.local/lib/python3.6/site-packages/pygraphviz/agraph.py", line 1201, in read
    self.handle = gv.agread(fh, None)
ValueError: agread: bad input data

Not sure why this causes a segfault in pytest but it looks like pygraphviz is not closing and reopening the file or otherwise properly resetting the read offset somewhere under the hood.

no fill in text attributes

This is alpha software, please report issues to:
https://github.com/hbmartin/graphviz2drawio/issues
Something went wrong, please report
Traceback (most recent call last):
  File "/home/jcaplan/.local/bin/graphviz2drawio", line 11, in <module>
    sys.exit(main())
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/__main__.py", line 23, in main
    output = convert(args.to_convert, args.program)
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/graphviz2drawio.py", line 26, in convert
    nodes, edges = SVG.parse(svg_graph)
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/models/SVG.py", line 20, in parse
    nodes[title] = node_factory.from_svg(g)
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/mx/NodeFactory.py", line 47, in from_svg
    current_text = Text.from_svg(t)
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/mx/Text.py", line 35, in from_svg
    color=t.attrib["fill"],
KeyError: 'fill'
Sentry is attempting to send 2 pending error messages
Waiting up to 10 seconds
Press Ctrl-C to quit

Shapes are still not working

The test/directed/hello.gv.txt test is correctly failing as rectangles are being generated instead of ellipses.

deterministic output

Given an input, the output should be the same every time. This improves testability. Currently at least node orders are variable.

Convetration error

This is beta software, please report issues to:
https://github.com/hbmartin/graphviz2drawio/issues

Something went wrong, please report
Traceback (most recent call last):
  File "/usr/bin/graphviz2drawio", line 10, in <module>
    sys.exit(main())
  File "/usr/lib/python3.7/site-packages/graphviz2drawio/__main__.py", line 26, in main
    output = convert(args.to_convert, args.program)
  File "/usr/lib/python3.7/site-packages/graphviz2drawio/graphviz2drawio.py", line 27, in convert
    [e.enrich_from_graph(graph_edges[e.gid]) for e in edges]
  File "/usr/lib/python3.7/site-packages/graphviz2drawio/graphviz2drawio.py", line 27, in <listcomp>
    [e.enrich_from_graph(graph_edges[e.gid]) for e in edges]
KeyError: 'node0:f0->node1:f0'
Sentry is attempting to send 2 pending error messages
Waiting up to 10 seconds
Press Ctrl-C to quit

when tried to convert that: https://graphviz.gitlab.io/_pages/Gallery/directed/datastruct.html

Reorganize packages

Goal: make it easier for new contributors to understand the architecture.

Things are somewhat messy now and the current 2 package structure is making less sense. Let's plan something better.

Error in parsing the graph for xml conversion with `fdp`

Hi Everyone,
I made the graph with pydot library using "fdp" layout parameter and also giving position for each nodes for the graph. While converting the graph to xml, it is giving error as :

Traceback (most recent call last):

  File ~\AppData\Local\anaconda\Lib\site-packages\IPython\core\interactiveshell.py:3505 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  Cell In[160], line 3
    xml = graphviz2drawio.convert(gdt)

  File ~\AppData\Local\anaconda\Lib\site-packages\graphviz2drawio\graphviz2drawio.py:26 in convert
    nodes, edges = SvgParser(svg_graph).get_nodes_and_edges()

  File ~\AppData\Local\anaconda\Lib\site-packages\graphviz2drawio\models\SvgParser.py:14 in get_nodes_and_edges
    root = ElementTree.fromstring(self.svg_data)[0]

  File ~\AppData\Local\anaconda\Lib\xml\etree\ElementTree.py:1338 in XML
    parser.feed(text)

  File <string>
ParseError: not well-formed (invalid token): line 64, column 109

Some relevant code info is as follows which I find was different than usual standard code:

# Create an empty PyDot graph
G_pydot = pydot.Dot(graph_type='digraph',layout="fdp")

pydot_node = pydot.Node(str(node), label=item['text'],shape=get_shape(item['shape_type']),slane=key,pos=f"{X},{Y}!") 

# Add the PyDot node to the PyDot graph
G_pydot.add_node(pydot_node)`

gdt=G_pydot.to_string()
xml = graphviz2drawio.convert(gdt)

Support invisible nodes

Hi, I'm getting KeyError on both invisible nodes in my graph. Seems that graphviz doesn't create those nodes when converting to SVG.

Here's the dot source and I'm adding the generated SVG by hand as an attachment as well. (dot -Gsplines=none anon.dot | neato -n -Gsplines=ortho -Tsvg -oanon.svg)

digraph G {
    graph [rankdir = LR, splines=ortho];

    node[shape=record];

    emmc [label="eMMC" color="blue"]
    boot_host [label="" style=invis width=0 height=2]
    spinor [label="SPI NOR" color="green"]
    soc [label="SoC" height=4]
    nand [label="Raw NAND" color="yellow"]
    dev_eth [label="" style=invis width=0 height=2]
    eeprom [label="I2C EEPROM" color="red"]

    emmc -> soc [arrowhead=none]
    boot_host -> soc [xlabel="Boot Source"]
    boot_host -> soc [xlabel="USB" dir=both]
    spinor -> soc [arrowhead=none]
    soc -> nand [arrowhead=none]
    soc -> dev_eth [xlabel="USB-OTG" dir=both]
    soc -> dev_eth [xlabel="Ethernet" dir=both]
    soc -> eeprom [arrowhead=none]
}

anon

Python 3.4 circular imports

For whatever reason Python 3.4 can't handle the circular import SVG->NodeFactory->SVG

  File "/home/travis/virtualenv/python3.4.6/lib/python3.4/site-packages/graphviz2drawio/__main__.py", line 2, in <module>
    from .graphviz2drawio import convert
  File "/home/travis/virtualenv/python3.4.6/lib/python3.4/site-packages/graphviz2drawio/graphviz2drawio.py", line 4, in <module>
    from .models import SVG
  File "/home/travis/virtualenv/python3.4.6/lib/python3.4/site-packages/graphviz2drawio/models/SVG.py", line 3, in <module>
    from graphviz2drawio.mx.NodeFactory import NodeFactory
  File "/home/travis/virtualenv/python3.4.6/lib/python3.4/site-packages/graphviz2drawio/mx/NodeFactory.py", line 1, in <module>
    from graphviz2drawio.models import SVG
ImportError: cannot import name 'SVG'

Probably fixable by moving SVG.parse somewhere else and remove the imports of NodeFactory and Edge from SVG module.

Edge labeling

Is there a possibility to convert edge labels?

graphviz:
graph

draw.io:
Untitled Diagram

dot:

digraph {
	"$$x_t$$" [color="#187DF9" fill="#187DF9" fillcolor="#187DF9" fontcolor=white shape=box style=filled]
	Conv2d [color=plum fill=plum fillcolor=plum fontcolor=white shape=ellipse style=filled]
	"$$x_t$$" -> Conv2d [label="$$x_t$$" value=x_t]
	Conv2d2 [color=orange fill=orange fillcolor=orange fontcolor=white shape=ellipse style=filled]
	"$$x_t$$" -> Conv2d2 [label="$$x_t$$" value=x_t]
	"|" [color=black fill=black fillcolor=black fontcolor=black shape=point style=filled]
	"$$x_t$$" -> "|" [label="$$x_t$$" value=x_t]
	Conv2d [color=thistle fill=thistle fillcolor=thistle fontcolor=white shape=box style=filled]
	MaxPooling [color=steelblue1 fill=steelblue1 fillcolor=steelblue1 fontcolor=white shape=ellipse style=filled]
	Conv2d -> MaxPooling [label="$$g_t$$" value=g_t]
	Conv2d2 [color=steelblue1 fill=steelblue1 fillcolor=steelblue1 fontcolor=white shape=box style=filled]
	"|" [color=black fill=black fillcolor=black fontcolor=black shape=point style=filled]
	Conv2d2 -> "|" [label="$$c_t$$" value=c_t]
	MaxPooling [color=steelblue1 fill=steelblue1 fillcolor=steelblue1 fontcolor=white shape=box style=filled]
	Dropout [color=plum fill=plum fillcolor=plum fontcolor=white shape=ellipse style=filled]
	MaxPooling -> Dropout [label="$$s_t$$" value=s_t]
	Dropout [color=plum fill=plum fillcolor=plum fontcolor=white shape=box style=filled]
	"." [color=skyblue fill=skyblue fillcolor=skyblue fontcolor=skyblue height=0.01 shape=doublecircle style=filled width=0.01]
	Dropout -> "." [label="$$s_{t+1}$$" value="s_{t+1}"]
	"|" [color=black fill=black fillcolor=black fontcolor=black shape=point style=filled]
	"$$W_x$$" [color=plum fill=plum fillcolor=plum fontcolor=white shape=ellipse style=filled]
	"|" -> "$$W_x$$" [label="$$[x_t, c_t]$$" value="[x_t, c_t]"]
	"$$W_x$$" [color=plum fill=plum fillcolor=plum fontcolor=white shape=box style=filled]
	"." [color=skyblue fill=skyblue fillcolor=skyblue fontcolor=skyblue height=0.01 shape=doublecircle style=filled width=0.01]
	"$$W_x$$" -> "." [label="$$x_{t-1}$$" value="x_{t-1}"]
	"." [color=skyblue fill=skyblue fillcolor=skyblue fontcolor=skyblue height=0.01 shape=doublecircle style=filled width=0.01]
	"$$W_q$$" [color=powderblue fill=powderblue fillcolor=powderblue fontcolor=white shape=ellipse style=filled]
	"." -> "$$W_q$$" [label="$$q_t$$" value=q_t]
	"$$W_q$$" [color=powderblue fill=powderblue fillcolor=powderblue fontcolor=white shape=box style=filled]
	"$$l_t$$" [color=thistle fill=thistle fillcolor=thistle fontcolor=white shape=ellipse style=filled]
	"$$W_q$$" -> "$$l_t$$" [label="$$l_t$$" value=l_t]
	"$$x_t$$" [color=thistle fill=thistle fillcolor=thistle fontcolor=white shape=ellipse style=filled]
}

mxGraph

<?xml version="1.0"?><mxGraphModel><root><mxCell id="0" /><mxCell id="1" parent="0" /><mxCell edge="1" id="edge1" parent="1" source="node1" style="rounded=1;html=1;exitX=0.181;exitY=0.889;entryX=0.951;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node2"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge2" parent="1" source="node1" style="rounded=1;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node3"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge3" parent="1" source="node1" style="rounded=1;html=1;exitX=0.867;exitY=0.846;entryX=1;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node4"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge4" parent="1" source="node2" style="rounded=1;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node5"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge5" parent="1" source="node3" style="edgeStyle=orthogonalEdgeStyle;curved=1;rounded=1;html=1;exitX=0.5;exitY=1;entryX=0;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node4"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge6" parent="1" source="node4" style="rounded=1;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node6"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge7" parent="1" source="node5" style="rounded=1;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node7"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge10" parent="1" source="node6" style="rounded=1;html=1;exitX=0.5;exitY=1;entryX=1;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node8"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge8" parent="1" source="node7" style="edgeStyle=orthogonalEdgeStyle;curved=1;rounded=1;html=1;exitX=0.5;exitY=1;entryX=0;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node8"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge9" parent="1" source="node8" style="rounded=1;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node9"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell edge="1" id="edge11" parent="1" source="node9" style="rounded=1;html=1;exitX=0.5;exitY=1;entryX=0.5;entryY=0;jettySize=auto;orthogonalLoop=1;endArrow=block;dashed=0;endFill=1;" target="node10"><mxGeometry as="geometry" relative="1" /></mxCell><mxCell id="node1" parent="1" style="ellipse;verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#000000;strokeWidth=1;fillColor=thistle;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#ffffff;'&gt;$$x_t$$&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="36.0" width="96.3834" x="100.3083" y="4.0" /></mxCell><mxCell id="node2" parent="1" style="verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#d8bfd8;strokeWidth=1;fillColor=thistle;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#ffffff;'&gt;Conv2d&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="36.0" width="71.0" x="19.0" y="90.99999999999994" /></mxCell><mxCell id="node3" parent="1" style="verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#63b8ff;strokeWidth=1;fillColor=steelblue1;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#ffffff;'&gt;Conv2d2&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="36.0" width="80.0" x="108.5" y="90.99999999999994" /></mxCell><mxCell id="node4" parent="1" style="verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#000000;strokeWidth=1;fillColor=black;" value="" vertex="1"><mxGeometry as="geometry" height="3.6" width="3.6" x="172.7" y="194.19999999999993" /></mxCell><mxCell id="node5" parent="1" style="verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#63b8ff;strokeWidth=1;fillColor=steelblue1;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#ffffff;'&gt;MaxPooling&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="36.0" width="101.0" x="4.0" y="177.99999999999994" /></mxCell><mxCell id="node6" parent="1" style="verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#dda0dd;strokeWidth=1;fillColor=plum;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#ffffff;'&gt;$$W_x$$&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="36.0" width="83.0" x="133.0" y="264.99999999999994" /></mxCell><mxCell id="node7" parent="1" style="verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#dda0dd;strokeWidth=1;fillColor=plum;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#ffffff;'&gt;Dropout&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="36.0" width="75.0" x="17.0" y="264.99999999999994" /></mxCell><mxCell id="node8" parent="1" style="ellipse;shape=doubleEllipse;aspect=fixed;verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#000000;strokeWidth=1;fillColor=skyblue;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#87ceeb;'&gt;.&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="32.1516" width="32.1516" x="98.4242" y="356.1875999999999" /></mxCell><mxCell id="node9" parent="1" style="verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#b0e0e6;strokeWidth=1;fillColor=powderblue;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#ffffff;'&gt;$$W_q$$&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="36.0" width="84.0" x="72.5" y="443.52689999999996" /></mxCell><mxCell id="node10" parent="1" style="ellipse;verticalAlign=top;align=left;overflow=fill;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeColor=#000000;strokeWidth=1;fillColor=thistle;" value="&lt;p style='margin:0px;text-align:center;margin-top:4px;;font-size:10.0px;font-family:Times,serif;color:#ffffff;'&gt;$$l_t$$&lt;/p&gt;" vertex="1"><mxGeometry as="geometry" height="36.0" width="92.5846" x="68.2077" y="530.5269" /></mxCell></root></mxGraphModel>

TypeError if charset is in handle of dot file

Error appears If charset is in dot file.
C-function agget (from line176 from agraph.py) returns bytes, but it must be string.
And C-func agattrdefval (from line 1833) returns bytes too.
And I think the same returning is of C-func agattrdefval from line 1741.
Снимок экрана от 2019-08-23 22-29-29

no support for octagons

octagons fail assertion at NodeFactory.py:14

This is alpha software, please report issues to:
https://github.com/hbmartin/graphviz2drawio/issues
Something went wrong, please report
Traceback (most recent call last):
  File "/home/jcaplan/.local/bin/graphviz2drawio", line 11, in <module>
    sys.exit(main())
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/__main__.py", line 23, in main
    output = convert(args.to_convert, args.program)
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/graphviz2drawio.py", line 26, in convert
    nodes, edges = SVG.parse(svg_graph)
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/models/SVG.py", line 20, in parse
    nodes[title] = node_factory.from_svg(g)
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/mx/NodeFactory.py", line 47, in from_svg
    current_text = Text.from_svg(t)
  File "/home/jcaplan/.local/lib/python3.5/site-packages/graphviz2drawio/mx/Text.py", line 35, in from_svg
    color=t.attrib["fill"],
KeyError: 'fill'
Sentry is attempting to send 2 pending error messages
Waiting up to 10 seconds
Press Ctrl-C to quit

Simple example fails with `IndexError`

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!

Subgraph conversion

hi, error when try convert

digraph Layer1 {
	graph [fontcolor="#2D3436" fontname="Sans-Serif" fontsize=15 label=Layer1 nodesep=0.60 pad=2.0 rankdir=LR ranksep=0.75 splines=ortho]
	node [fixedsize=true fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13 height=1.4 imagescale=true labelloc=b shape=box style=rounded width=1.4]
	edge [color="#7B8894"]
	c1f7153c9e32421d836368051a837462 [label=dns height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/network/route-53.png" shape=none]
	"4adc5fcb62f74cfc91e0361a9d9df8e2" [label=lb height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/network/elastic-load-balancing.png" shape=none]
	a275ead10c404ea899628a2b9e96718d [label=memcached height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/database/elasticache.png" shape=none]
	"4298ae03bc26401ca91f226395f3c0ca" [label=userdb height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/database/rds.png" shape=none]
	subgraph cluster_Services {
		graph [bgcolor="#E5F5FD" fontname="Sans-Serif" fontsize=12 label=Services labeljust=l pencolor="#AEB6BE" rankdir=LR shape=box style=rounded]
		f54e1bfa37524a19b5a15a2af2423647 [label=web1 height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/compute/elastic-container-service.png" shape=none]
		"82b031cab3a2430a99d322923fd72bb1" [label=web2 height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/compute/elastic-container-service.png" shape=none]
		"5fe8e3fd159b4072b59496ead0c7dc39" [label=web3 height=1.9 image="/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/resources/aws/compute/elastic-container-service.png" shape=none]
	}
	c1f7153c9e32421d836368051a837462 -> "4adc5fcb62f74cfc91e0361a9d9df8e2" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	"4adc5fcb62f74cfc91e0361a9d9df8e2" -> f54e1bfa37524a19b5a15a2af2423647 [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	"4adc5fcb62f74cfc91e0361a9d9df8e2" -> "82b031cab3a2430a99d322923fd72bb1" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	"4adc5fcb62f74cfc91e0361a9d9df8e2" -> "5fe8e3fd159b4072b59496ead0c7dc39" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	f54e1bfa37524a19b5a15a2af2423647 -> "4298ae03bc26401ca91f226395f3c0ca" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	"82b031cab3a2430a99d322923fd72bb1" -> "4298ae03bc26401ca91f226395f3c0ca" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	"5fe8e3fd159b4072b59496ead0c7dc39" -> "4298ae03bc26401ca91f226395f3c0ca" [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	f54e1bfa37524a19b5a15a2af2423647 -> a275ead10c404ea899628a2b9e96718d [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	"82b031cab3a2430a99d322923fd72bb1" -> a275ead10c404ea899628a2b9e96718d [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
	"5fe8e3fd159b4072b59496ead0c7dc39" -> a275ead10c404ea899628a2b9e96718d [dir=forward fontcolor="#2D3436" fontname="Sans-Serif" fontsize=13]
}
Traceback (most recent call last):
  File "/home/anna/PycharmProjects/diagram/dg.py", line 36, in <module>
    cluster.get_diagram()
  File "/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/diagrams/__init__.py", line 141, in __exit__
    self.render()
  File "/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/diagrams/__init__.py", line 178, in render
    xml = graphviz2drawio.convert('/home/anna/PycharmProjects/diagram/' + self.filename)
  File "/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/graphviz2drawio/graphviz2drawio.py", line 26, in convert
    nodes, edges = SvgParser(svg_graph).get_nodes_and_edges()
  File "/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/graphviz2drawio/models/SvgParser.py", line 27, in get_nodes_and_edges
    nodes[title] = node_factory.from_svg(g)
  File "/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/graphviz2drawio/mx/NodeFactory.py", line 60, in from_svg
    rect = self.rect_from_ellipse_svg(SVG.get_first(g, "ellipse").attrib)
  File "/home/anna/PycharmProjects/diagram/venv/lib/python3.7/site-packages/graphviz2drawio/models/SVG.py", line 3, in get_first
    return g.findall("./{http://www.w3.org/2000/svg}" + tag)[0]
IndexError: list index out of range

raven

what is raven? Are you collecting data from me? Did I consent to that?

Conversion fails in SVG.py due to <image>

Traceback (most recent call last):
  File "/usr/local/homebrew/bin/graphviz2drawio", line 8, in <module>
    sys.exit(main())
  File "/usr/local/homebrew/lib/python3.9/site-packages/graphviz2drawio/__main__.py", line 16, in main
    output = convert(args.to_convert, args.program)
  File "/usr/local/homebrew/lib/python3.9/site-packages/graphviz2drawio/graphviz2drawio.py", line 26, in convert
    nodes, edges = SvgParser(svg_graph).get_nodes_and_edges()
  File "/usr/local/homebrew/lib/python3.9/site-packages/graphviz2drawio/models/SvgParser.py", line 27, in get_nodes_and_edges
    nodes[title] = node_factory.from_svg(g)
  File "/usr/local/homebrew/lib/python3.9/site-packages/graphviz2drawio/mx/NodeFactory.py", line 60, in from_svg
    rect = self.rect_from_ellipse_svg(SVG.get_first(g, "ellipse").attrib)
  File "/usr/local/homebrew/lib/python3.9/site-packages/graphviz2drawio/models/SVG.py", line 2, in get_first
    return g.findall("./{http://www.w3.org/2000/svg}" + tag)[0]
IndexError: list index out of range

Pip install pygraphviz fails on mac M1

The PIP command for installing pygraphviz on a macbook with the Arm M1 processor fails.

This command does work:

python3 -m pip  install  --global-option=build_ext \
  --global-option="-I/opt/homebrew/include"\
  --global-option="-L/opt/homebrew/lib"  pygraphviz 

I can create PR for README if you like

Error in convertion - from dot to drawio

I have a dot file that I want to converto to drawio.

The dot file is Ok

But the conversion failed

(base) cloud-di@vm096:/app/g-viewer$ graphviz2drawio H4-K3-A.dot
This is beta software, please report issues to:
https://github.com/hbmartin/graphviz2drawio/issues
Something went wrong, please report
An automatic crash report can be sent to the developer (no personal or graph information)
Type 'no' to cancel report, press enter to send:
Traceback (most recent call last):
File "/home/cloud-di/.local/bin/graphviz2drawio", line 8, in
sys.exit(main())
File "/home/cloud-di/.local/lib/python3.9/site-packages/graphviz2drawio/main.py", line 16, in main
output = convert(args.to_convert, args.program)
File "/home/cloud-di/.local/lib/python3.9/site-packages/graphviz2drawio/graphviz2drawio.py", line 30, in convert
mx_graph = MxGraph(nodes, edges)
File "/home/cloud-di/.local/lib/python3.9/site-packages/graphviz2drawio/mx/MxGraph.py", line 18, in init
self.add_edge(edge)
File "/home/cloud-di/.local/lib/python3.9/site-packages/graphviz2drawio/mx/MxGraph.py", line 38, in add_edge
self.add_mx_geo_with_points(edge_element, edge.curve)
File "/home/cloud-di/.local/lib/python3.9/site-packages/graphviz2drawio/mx/MxGraph.py", line 117, in add_mx_geo_with_points
if cb:
UnboundLocalError: local variable 'cb' referenced before assignment
Sentry is attempting to send 2 pending error messages
Waiting up to 10 seconds
Press Ctrl-C to quit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.