Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistencies when saving to a stretched image? #431

Open
etiennedeg opened this issue Jan 7, 2022 · 2 comments
Open

Inconsistencies when saving to a stretched image? #431

etiennedeg opened this issue Jan 7, 2022 · 2 comments

Comments

@etiennedeg
Copy link
Contributor

Hi, when the output image in SVG format is shaped to a stretched rectangle, there are inconsistencies in the way forms are reshaped.
In the following example, the circle is still a circle, but the rectangle and the lines are stretched.

using Compose
using Colors
center = (0, 0)
p1 = (1, 0)
p2 = (0, 1)
p3 = (-1, 0)
p4 = (0, -1)
lines2 = [[center, p1], [center, p2], [center, p3],[center, p4]]
c = compose(
        context(units=UnitBox(-2., -2., 4., 4.)),
        compose(context(), line(lines2), stroke(colorant"white")),
        compose(context(), rectangle(-1, -1, 2, 2), fill(colorant"red")),
        compose(context(), circle(0, 0, 1.5), fill(colorant"blue"))
)
draw(SVG("myplot.svg", 10cm, 10cm), c)
draw(SVG("myplot_reshaped.svg", 10cm, 5cm), c)

"myplot.svg"
myplot
"myplot_reshaped.svg"
myplot_reshaped

@Mattriks Mattriks changed the title Inconsistensies when saving to a stretched SVG. Inconsistencies when saving to a stretched image? Jan 7, 2022
@Mattriks
Copy link
Member

Mattriks commented Jan 8, 2022

I can't tell whether you think the circle or rectangle (or both) are "inconsistent".
In Compose.jl, circles are always circles (this behaviour is useful for plotting e.g. in Gadfly.jl you can change the size of image to fit your publication, and still get point circles). The radius defaults to cx units, but you can change to cy as shown below (or other units). Other forms should behave as you expect: e.g. in both your images the rectangle is drawn relative to the UnitBox coordinates. So both the rectangles and circles are correct as designed.
Two notes:

gridf(xs, ys, args...) = (context(),
 line([[(x, 0h), (x, 1h)] for x in xs]), line([[(0w, y), (1w, y)] for y in ys]), args..., linewidth(0.1mm))

c3 = compose(context(units=UnitBox(-2., -2., 4., 4.)),
    gridf(-2:2, -2:2, stroke("gray")),
#    (context(), rectangle(-1, -1, 2, 2), fill("red")),
    circle([0], [0], [1.5cx, 1.5cy]), fill(["deepskyblue","coral"])
)
draw(PNG("Comp431.png", 10cm, 5cm), c3)

Comp431

@etiennedeg
Copy link
Contributor Author

Indeed, my circles are clipped in svg, this is due to conversion to png.
Ok, I didn't see that there were absolute and relative coordinates, I should have read the documentation more carefully.
I understand the rationale, but it still feels weird that the circle favors the x coordinate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants