I am creating bunch of different SVG files in Python using
svgwrite module. I need to present those pictures later on a website.
Since those pictures consists of different mathematical object I am working in whole plane, both with positive and negative numbers. That means that I need to shift all the objects so they will be visible and maintain the structure. Sometimes shifting those objects is not hard, but since I have to do it in almost all my work I am looking for something more general.
So I am looking for something that will shift all of the objects and maintain their structure, so that everything will be visible and the size of the picture would be minimal(meaning the width/height).
I search the official documentation but haven't been successful so far, maybe just blind.
Update To make it clearer I have added an example
import svgwrite im = svgwrite.drawing.Drawing() im.add(im.line( start = (-10,-10),\ end = (20,20),\ stroke= 'black')) im.saveas('example.svg')
Then, when I view
example.svg in e.g. Firefox there would be only part the "positive" part that is line from [0,0] to [20,20].
Or slightly different example:
import svgwrite im = svgwrite.drawing.Drawing() im.add(im.line( start = (10,10),\ end = (20,20),\ stroke= 'black')) im.saveas('example2.svg')
Now there is unnecessary gap between [0,0] and the line, which starts at [10,10].
So, to sum it up. Imagine bunch of SVG objects, they can be drawn anywhere. I want to find minimal x_min, y_min coordinates throughout all the objects and then:
- if the the coordinate x_min (resp. y_min) is negative, add |x_min| (resp. |y_min|) to all the x (resp. y) coordinates of all objects. Where |a| stands for absolute value of a
- if the the coordinate x_min (resp. y_min) is positive, substract x_min (resp. y_min) from all the x (resp. y) coordinates of all objects
After that the all the objects will be visible, and they will touch one or both axis at zero. As discussed below, same result might be achieved by shifting the origin (in corresponding way).
Note While I am at it, the similar problem comes with