Created
January 27, 2015 18:14
-
-
Save erantapaa/dae5edc14e8be734f7fd to your computer and use it in GitHub Desktop.
embed svg diagram in html using blaze
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Text.Blaze.Svg11 ((!), mkPath, rotate, l, m) | |
import qualified Text.Blaze.Svg11 as S | |
import qualified Text.Blaze.Svg11.Attributes as A | |
import Text.Blaze.Svg.Renderer.String (renderSvg) | |
import qualified Text.Blaze.Html5 as H | |
import Text.Blaze.Html.Renderer.Text | |
import qualified Data.Text.Lazy.IO as TL | |
main :: IO () | |
main = do | |
let a = renderHtml try1 -- renderSvg svgDoc | |
TL.putStrLn a | |
try1 :: H.Html | |
try1 = H.html $ | |
H.body $ do | |
H.h1 "My first diagram" | |
svgDoc | |
-- svgDoc :: S.Svg | |
svgDoc = S.svg ! A.version "1.1" ! A.width "150" ! A.height "100" ! A.viewbox "0 0 3 2" $ do | |
S.g ! A.transform makeTransform $ do | |
S.rect ! A.width "1" ! A.height "2" ! A.fill "#008d46" | |
S.rect ! A.width "1" ! A.height "2" ! A.fill "#ffffff" | |
S.rect ! A.width "1" ! A.height "2" ! A.fill "#d2232c" | |
S.path ! A.d makePath | |
makePath :: S.AttributeValue | |
makePath = mkPath $ do | |
l 2 3 | |
m 4 5 | |
makeTransform :: S.AttributeValue | |
makeTransform = rotate 50 | |
e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment