g-battaglia / kerykeion

Data driven Astrology 💫
Kerykeion is a python library for astrology. It can generate SVG charts and extract all data about a birthchart, a synastry chart and a transit chart.
https://kerykeion.net
GNU Affero General Public License v3.0
297 stars 103 forks source link

Scaling and Resizing SVG to Fit 16:9 #92

Open Vacant0mens opened 11 months ago

Vacant0mens commented 11 months ago

I can't seem to find a way to scale the resulting svg file so that it could fit into a 16:9 ratio (for many monitors, full screen)

I was able to scale up the image by reassigning the zoom property of the KerykeionChartSVG class after it's initialized, like this:

my_svg = KerykeionChartSVG(first_obj=me, chart_type=chart_type, new_settings_file=my_settings_file)
my_svg.zoom = (window_width - 100) / my_svg.natal_width
my_svg.makeSVG()

And that scales up the image, but it starts losing the edges outside of the window/screen if the aspect ratio doesn't match.

I've also tried changing the basic_chart_viewBox and wide_chart_viewBox settings in my json settings file, but that just resizes the box that the svg is placed into, and makes the main chart into an oval rather than keeping it a circle.

I've used cairosvg's svg2svg function, but that doesn't seem to change anything. Even svg2png results in the same size image, or at least an image with the same aspect ratio.

I noticed that in the template, the value for svg/g/g/g/rect.height is hard coded to 546.0, but the width is part of the template transforms.

I thought one of the main advantages of SVG's was that you can scale it or resize it any direction without losing any of the graphics but having a hard-coded value for height seems to be the core of this issue.

Is there a way to tell the KerykeionChartSCG class to resize the SVG so that it fits an aspect ratio besides 4:3?