Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion fails in SVG.py due to <image> #45

Closed
markthompson94 opened this issue Apr 26, 2022 · 12 comments
Closed

Conversion fails in SVG.py due to <image> #45

markthompson94 opened this issue Apr 26, 2022 · 12 comments
Milestone

Comments

@markthompson94
Copy link

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
@markthompson94
Copy link
Author

markthompson94 commented Apr 26, 2022

digraph_example.docx

Example .dot text included to assist troubleshooting

This .dot file was generated using the Python Diagrams module, using the following Python code;


from diagrams import Diagram
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB

with Diagram("Grouped Workers", show=True, outformat="dot", direction="TB"):
    ELB("lb") >> [EC2("worker1"),
                  EC2("worker2"),
                  EC2("worker3"),
                  EC2("worker4"),
                  EC2("worker5")] >> RDS("events")

@squio
Copy link

squio commented May 10, 2022

Ouch, got the same here; reduced testcase causes the same crash:

strict digraph CDD {
  splines="true"
  labelloc="t"
  label="CDD"
  // sep=.5
  Hello [label="/aa/bb\nHello"]
  World [shape=box, color=blue, fontcolor=blue, tooltip=aaaa]


  Hello -> { World }
}

Removing the tooltip attribute makes the conversion work

@markthompson94
Copy link
Author

@hbmartin could you possibly take a look into this for us? Much love and thanks!!

@ams1
Copy link

ams1 commented May 19, 2022

just came across this really interesting repo -> @hbmartin THANK YOU for sharing!

@markthompson94 : i'll probably try to fix this over the weekend if it's still not working and get back to you.

@ams1
Copy link

ams1 commented May 20, 2022

@markthompson94

The SVG file produced by graphviz via the Diagram lib (using the python code you provided) looks something like:

...

<!-- 1st g tag -->
<g id="edge3" class="edge">
  <title>94a1a24258c54e028e3b9cb0054dadc9&#45;&gt;739289249c574bffb2ed3d49b021b1da</title>
  <path fill="none" stroke="#7b8894" d="M338.5,-406.81C338.5,-406.81 338.5,-363.22 338.5,-363.22"/>

  <!-- this has a polygon tag -->
  <polygon fill="#7b8894" stroke="#7b8894" points="342,-363.22 338.5,-353.22 335,-363.22 342,-363.22"/>
</g>

...

<!-- 2nd g tag -->
<g id="node5" class="node">
  <title>2c1229f79a9141eea4b8ef297492ec26</title>
  <image xlink:href="does-not-matter/.local/lib/python3.8/site-packages/resources/aws/compute/ec2.png" width="101px" height="101px" preserveAspectRatio="xMinYMin meet" x="432" y="-335"/>
  <text text-anchor="middle" x="482.5" y="-219.6" font-family="Sans-Serif" font-size="13.00" fill="#2d3436">worker4</text>
  <!-- this does NOT hava a polygon tag -->
</g>

...

As we can see above, the 1st <g ...> tag HAS a <polygon .../> tag, while the 2nd g tag DOES NOT have a <polygon .../> tag, instead it has an <image ... /> tag.

Conclusion (might be wrong, I had just a quick look):

The problem is that this lib needs to have EITHER a <polygon .../> OR an <ellipse.../> in every <g ...> tag (see corresp. code below) and the python Diagrams returns an <image ...> tag instead, which is not supported.

@hbmartin Could you please just confirm -> yes/no? 😄

if SVG.has(g, "polygon"):
rect = self.rect_from_svg_points(
SVG.get_first(g, "polygon").attrib["points"]
)
else:
rect = self.rect_from_ellipse_svg(SVG.get_first(g, "ellipse").attrib)

@markthompson94
Copy link
Author

@hbmartin would you possibly be able to take a look at this? It'd be fantastic to have the ability to integrate Custom nodes from Python Diagrams in the graphviz2drawio module

@fabiomurillo
Copy link

Was anyone able to workaround this issue?

@markthompson94
Copy link
Author

Think we need @hbmartin to help us out there 🤞

@markthompson94
Copy link
Author

Hi @hbmartin, when you have any time would you be able to look into this at all?

thanks so much!!

laurierloi added a commit to laurierloi/graphviz2drawio that referenced this issue Sep 13, 2022
Instead of looking only at direct childs of a node,
search the complete tree starting at the node.

This is particularly useful when we add fancy attributes,
since they tend to add encompassing groups to the graph.

It is pretty easy to test for the bug and how it can be reproduced.
It's tracked in: hbmartin#45

I re-created a minimal fail case from
hbmartin#45 (comment)

```
digraph {
    Pitas
    Pizza [ tooltip=Delicious ]
    Pitas -> Pizza
}
```

Previous HEAD failed to parse this.
laurierloi added a commit to laurierloi/graphviz2drawio that referenced this issue Sep 14, 2022
Instead of looking only at direct childs of a node,
search the complete tree starting at the node.

This is particularly useful when we add fancy attributes,
since they tend to add encompassing groups to the graph.

It is pretty easy to test for the bug and how it can be reproduced.
It's tracked in: hbmartin#45

I re-created a minimal fail case from
hbmartin#45 (comment)

```
digraph {
    Pitas
    Pizza [ tooltip=Delicious ]
    Pitas -> Pizza
}
```

Previous HEAD failed to parse this.
laurierloi added a commit to laurierloi/graphviz2drawio that referenced this issue Sep 14, 2022
Instead of looking only at direct childs of a node,
search the complete tree starting at the node.

This is particularly useful when we add fancy attributes,
since they tend to add encompassing groups to the graph.

It is pretty easy to test for the bug and how it can be reproduced.
It's tracked in: hbmartin#45

I re-created a minimal fail case from
hbmartin#45 (comment)

```
digraph {
    Pitas
    Pizza [ tooltip=Delicious ]
    Pitas -> Pizza
}
```

Previous HEAD failed to parse this.
@karth123
Copy link

karth123 commented Jun 8, 2024

@markthompson94 @fabiomurillo @ams1 I came across the repo for the same reason as you guys, wanted to render my diagrams file into drawio. I did resolve the svg issue after hacking around the library files a bit. (The solution is too long to share here). But even if you solve the svg render issue the edge placement is very poor and the actual XML generated is not satisfactory by any means.

I have created a script which does a better conversion into drawio SOLELY for diagrams library code. I know its 2 years too late but im putting it out there for anyone who had this issue like me.

https://github.com/karth123/diagrams-to-drawio

@hbmartin hbmartin modified the milestones: 0.3, 0.4 Jul 2, 2024
@hbmartin hbmartin changed the title Conversion fails in SVG.py Conversion fails in SVG.py due to <image> Jul 3, 2024
@hbmartin
Copy link
Owner

hbmartin commented Jul 3, 2024

Work has started on this in #49 and is slated for 0.4 release!

@hbmartin
Copy link
Owner

hbmartin commented Jul 7, 2024

The fix for this will ship in 0.4 tomorrow, please reopen this issue if it doesn't meet your needs.

Screenshot 2024-07-06 at 5 56 56 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants