0

I have one question: I know how to output svg file with a help of ghc --make Strukturine.hs command in Terminal. As I understood it uses import Diagrams.Backend.SVG.CmdLine . Is it possible somehow load Strukturine.hs file with the help of :load Strukturine.hs in terminal and then just put the name of function for example: strukturine. That function should output a scheme/picture (to svg file).

The beginning of Strukturine.hs file looks like this

{-# LANGUAGE NoMonomorphismRestriction #-}

module Strukturine where

import Diagrams.Prelude

import Diagrams.Backend.SVG.CmdLine

import Data.Maybe (fromMaybe)

import Data.Char

import Input

import qualified Input(getNumber) --other module

main = mainWith(strukturine :: Diagram B R2)
duplode
  • 33,731
  • 7
  • 79
  • 150
Darius
  • 71
  • 2

1 Answers1

1

You can use the function renderSVG from Diagrams.Backend.SVG.

renderSVG :: FilePath -> SizeSpec2D -> Diagram SVG R2 -> IO ()

For example to render a 400x400 svg:

import Diagrams.Backend.SVG (renderSVG)

outputFile :: FilePath
outputFile = "strukturine.svg"

dimensions :: SizeSpec2D
dimensions = mkSizeSpec (Just 400) (Just 400)

strukturineDiagram :: Diagram SVG R2

strukturine = do renderSVG outputFile dimensions strukturineDiagram

See http://projects.haskell.org/diagrams/haddock/Diagrams-Backend-SVG.html#v:renderSVG

And for more specific rendering, see: http://projects.haskell.org/diagrams/doc/cmdline.html

grwp
  • 97
  • 7