SVG viewBox reversing Y-coordinates
I'm using SVG to draw in a HTML page different shapes. These different shapes are retrieved from geometry objects of a spatial database in Microsoft Sql Server. The problem I'm facing is开发者_Python百科 that the system of coords (Svg and Microsoft Sql Server) is different. 0,0 begins in Svg on the top left corner, whereas in Microsoft Sql Server it starts at the bottom left corner. I need to reverse just the Y coords. I'm also using viewBox to display the data properly (for different transformations). Is there any way to solve my problem without touching the coords of the object and working just with the attributes of my viewbox? I create the objects dynamically and would prefer a "viewBox" solution.
Thanks in advance!
I don't think you can use viewBox. The SVG specifications say that if you want to define a new coordinate system then you have to use a transformation. What you want is to reflect everything about a horizontal line through the centre of the image. For that, wrap all your elements in a group like so:
<svg>
<g transform="matrix(1 0 0 -1 0 height)">
all the other elements...
</g>
</svg>
Where height
is the height of your SVG. One potential problem is that text will be rendered upside down.
Been facing a similar problem, which I have solved by applying CSS to the entire svg
element as follows:
<svg width="400" height="250" viewbox="0 0 400 250">
<style type="text/css">
svg {
transform: scaleY(-1);
}
</style>
</svg>
精彩评论