DSD-DBS / py-capellambse

A Python 3 headless implementation of the Capella modeling tool.
https://dsd-dbs.github.io/py-capellambse/
Apache License 2.0
53 stars 11 forks source link

Minimize SVG viewboxes when creating diagram cache #410

Closed jamilraichouni closed 7 months ago

jamilraichouni commented 7 months ago

This PR proposes a post-processing step in the diagram cache which gets the x_min, x_max, y_min, y_max limits for the bounding box of found content. It will then adjust the viewBox, canvas size and white background rectangle (another custom post-process step) so that the found content appears to be moved to the top left corner of the canvas whereby the canvas is cropped to surround the content with a 10 px margin.

Considered are the following shape kinds/ XML tags for now:

circle, ellipse, image, line, polygon, polyline, rect, and text.

Since this approach covers basic scenarios and is not considering all possible / specified (XML spec) kinds of shapes and/ or imaginable transformations (translate, rotate, scale), nested coordinate systems etc., the post-process step will be applied when an env var "CAPELLAMBSE_EXPERIMENTAL_CROP_SVG_DIAGRAM_CACHE_VIEWPORT" is set to "1". SVG elements with a transform attribute are ignored.