Skip to content

Commit

Permalink
Factored out scaling at a point.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Crosswhite authored and gcross committed Oct 10, 2015
1 parent 273e38b commit 0b3a90f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Slick/SVG.hs
Expand Up @@ -90,6 +90,14 @@ document_root = lens getter setter
root_element_attributes = document_root . element_attributes

transformScale scale = pack $ "scale(" ++ show scale ++ ")"

transformScaleAt x y scale =
transformTranslate (-x*scale) (-y*scale)
<>
transformScale scale
<>
transformTranslate x y

transformTranslate dx dy = pack $ "translate(" ++ show dx ++ " " ++ show dy ++ ")"

groupTransform :: Text [Element] Element
Expand All @@ -112,7 +120,7 @@ svg header scale elements =
,("width",pack . show $ width)
,("height",pack . show $ height)
,("viewBox",pack $ "0 0 " ++ show width ++ " " ++ show height)
,("transform",transform)
,("transform",transformScaleAt fixed_x fixed_y scale)
]
)
(map NodeElement elements)
Expand All @@ -123,12 +131,6 @@ svg header scale elements =
height = header ^. header_height * scale
fixed_x = header ^. header_width / 2
fixed_y = header ^. header_height / 2
transform =
transformTranslate (-width/2) (-height/2)
<>
transformScale scale
<>
transformTranslate fixed_x fixed_y

mkName :: Text Name
mkName name = Name name Nothing Nothing
Expand Down

0 comments on commit 0b3a90f

Please sign in to comment.