archi-scripting-plugin icon indicating copy to clipboard operation
archi-scripting-plugin copied to clipboard

[feature request] Set viewBox Bounds during SVG export

Open davidsara opened this issue 3 years ago • 3 comments

Hi! Current API allows to export to SVG using $.model.renderViewToSVG(view, filePath, setViewBox)

Would it be possible to add viewBoxBounds optional parameter to enter min_x, min_y, width and height as seen in GUI?

image

For example:

var viewBoxBounds = {min_x: 0, min_y: 0, width: 1000, height: 495};
$.model.renderViewToSVG(view, "myView.svg", "true", viewBoxBounds);

Thanks, David

davidsara avatar Oct 27 '21 07:10 davidsara

I'll look at it. It requires a change to Archi itself as well as jArchi so would have to tie in with the next Archi release.

Phillipus avatar Oct 27 '21 07:10 Phillipus

Just FYI, for now I'm using this simple Python script to set minimum width of exported SVG files. Could be useful workaround.

from bs4 import BeautifulSoup
import os
import os.path


def setViewBox(fileName):
    with open(fileName, 'r') as f:
        data = f.read()

    svg_xml = BeautifulSoup(data, 'xml')
    svg = svg_xml.find('svg')
    viewBox = svg.get('viewBox')
    values = viewBox.split()
    if (int(values[2]) < 1200):
        svg['viewBox'] = values[0] + ' ' + values[1] + ' 1200 ' + values[3]
        with open(fileName, 'w') as f:
            f.write(str(svg_xml))


for dirpath, dirnames, filenames in os.walk("."):
    for filename in [f for f in filenames if f.endswith(".svg")]:
        setViewBox(os.path.join(dirpath, filename))

davidsara avatar Jan 05 '23 10:01 davidsara

This will be implemented as part of the new API with options. You'll be able to set an option like:

var options = {setViewBox: true, viewBoxBounds: "0 0 1000 495"};
$.model.renderViewToSVG(view, "pathTo/test.svg", options);

See https://github.com/archimatetool/archi-scripting-plugin/issues/130#issuecomment-2295300342

Phillipus avatar Aug 18 '24 17:08 Phillipus