Code Monkey home page Code Monkey logo

graphviz2drawio's Introduction

graphviz2drawio

pypi Build Status codecov.io

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

Getting Started

Prerequisites

graphviz2drawio requires Python 3 and Graphviz

  • On Mac OS these can be installed with Homebrew:
brew update; brew install python3 graphviz
pip3 install pygraphviz --install-option="--include-path=/usr/local/include/graphviz" --install-option="--library-path=/usr/local/lib/graphviz/"
  • On Ubuntu / Debian based Linux, install graphviz using:
sudo apt install python3-pip graphviz graphviz-dev

If you encounter installation errors you may need to manually install pygraphviz with links to the graphviz libraries

Installation / Upgrade

pip3 install graphviz2drawio --upgrade

Usage

Run the conversion app on your graphviz file

graphviz2drawio example.dot

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

Python 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 incorrectect conversions.

Built With

Contributing

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

Code Formatting

This project is linted with pyflakes and makes strict use of Black for code formatting.

Authors

License

GPLv3

graphviz2drawio's People

Contributors

bperel avatar dependabot[bot] avatar hbmartin avatar jcaplan avatar ralequi 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  avatar

graphviz2drawio's Issues

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

Convert error

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

Fix edge layout

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

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

deterministic output

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

Conversion fails in SVG.py

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

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.

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

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>

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!

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.

Error in conversion to drawio - KeyError

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

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

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

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

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

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.

Shapes are still not working

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

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

raven

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

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.