ihaskell-graphviz: use SVG and enable by default in IHaskell

This commit is contained in:
Vaibhav Sagar 2018-12-31 14:24:56 -05:00
parent 198a54485d
commit e8934f5d61
2 changed files with 11 additions and 15 deletions

View File

@ -14,7 +14,7 @@
-- @ dot "digraph { l -> o; o -> v; v -> e; h -> a ; a -> s; s -> k ; k -> e ; e -> l ; l -> l}" @
module IHaskell.Display.Graphviz (
dot
, Graphviz
, Graphviz(..)
) where
import qualified Data.ByteString.Char8 as Char
@ -37,23 +37,19 @@ dot = Dot
instance IHaskellDisplay Graphviz where
display fig = do
pngDisp <- graphDataPNG fig
return $ Display [pngDisp]
svgDisp <- graphDataSVG fig
return $ Display [svgDisp]
name = "ihaskell-graphviz."
-- Width and height
w = 300
h = 300
graphDataPNG :: Graphviz -> IO DisplayData
graphDataPNG (Dot dotBody) = do
graphDataSVG :: Graphviz -> IO DisplayData
graphDataSVG (Dot dotBody) = do
switchToTmpDir
let fname = name ++ "png"
let fname = name ++ "svg"
-- Write the image.
ret <- readProcess "dot" ["-Tpng", "-o", fname] dotBody
ret <- readProcess "dot" ["-Tsvg", "-o", fname] dotBody
-- Force strictness on readProcess, read file, and convert to base64.
imgData <- seq (length ret) $ Char.readFile fname
return $ png w h $ base64 imgData
-- Force strictness on readProcess, read file, and output as SVG
imgData <- seq (length ret) $ readFile fname
return $ svg imgData

View File

@ -171,7 +171,7 @@ defaultKernelState :: KernelState
defaultKernelState = KernelState
{ getExecutionCounter = 1
, getLintStatus = LintOn
, useSvg = False
, useSvg = True
, useShowErrors = False
, useShowTypes = False
, usePager = True