Compose.jl icon indicating copy to clipboard operation
Compose.jl copied to clipboard

Inconsistencies when saving to a stretched image?

Open etiennedeg opened this issue 2 years ago • 2 comments

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

etiennedeg avatar Jan 07 '22 14:01 etiennedeg

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:

  • The circle didn't get clipped in your second image: did you convert the svg to png in another program?
  • Compose also has a fourth type of unit (sx,sy) (#409). Unfortunately the docs have not been deploying correctly (#410), but the info can be found in the doc md files.
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

Mattriks avatar Jan 08 '22 00:01 Mattriks

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.

etiennedeg avatar Jan 10 '22 15:01 etiennedeg