Skip to content

Commit

Permalink
mx: NodeFactory: support creating blank rect from image
Browse files Browse the repository at this point in the history
Image nodes are nice to have in some schematics.
Because of the representation in mxGraph, it would be a pain to create them in the xml.

Instead, this follows the least-effort methodology and replace the image by an equally sized rectangle.

In drawio GUI, the image can then be switched back in place of the rectangle.

As a reference on the mxImageShape if someone wants to dive deeper:
https://jgraph.github.io/mxgraph/java/docs/com/mxgraph/shape/mxImageShape.html
  • Loading branch information
laurierloi committed Sep 14, 2022
1 parent f384e3a commit d3c5a89
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions graphviz2drawio/mx/NodeFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def rect_from_svg_points(self, svg):
height = test_height
return Rect(x=min_x, y=min_y, width=width, height=height)

@staticmethod
def rect_from_image(attrib):
filtered = dict()
for k, v in attrib.items():
if k in ['x', 'y', 'width', 'height']
filtered = { k: float(v.strip('px')) }
return Rect(**filtered)

def rect_from_ellipse_svg(self, attrib):
cx = float(attrib["cx"])
cy = float(attrib["cy"])
Expand Down Expand Up @@ -56,6 +64,8 @@ def from_svg(self, g):
rect = self.rect_from_svg_points(
SVG.get_first(g, "polygon").attrib["points"]
)
elif SVG.has(g, "image"):
rect = self.rect_from_image(SVG.get_first(g, "image").attrib)
else:
rect = self.rect_from_ellipse_svg(SVG.get_first(g, "ellipse").attrib)

Expand Down

0 comments on commit d3c5a89

Please sign in to comment.