[Haskell-cafe] Re: ANN: diagrams 0.2

John MacFarlane jgm at berkeley.edu
Sun Feb 1 01:37:06 EST 2009


+++ Braden Shepherdson [Jan 31 09 18:23 ]:
> Brent Yorgey wrote:
>> I am very pleased to announce the 0.2 release of the diagrams package,
>> an embedded domain-specific language for creating simple graphics in a
>> compositional style.  This release includes a number of significant
>> new features, including:
>>
>>   * support for arbitrary straight and curved paths
>>   * more shape primitives, including polygons and rounded rectangles
>>   * support for rendering text
>>   * PNG, PDF, PS, and SVG output
>>   * built-in color support replaced with external dependence     on the 
>> feature-rich colour library
>>
>> and many more!  More information, examples, and installation
>> instructions can be found at http://code.haskell.org/diagrams.  More
>> features are planned for future releases, so contributions and
>> suggestions are welcome.
>>
>> (Please note: since diagrams depends on the Cairo library, which has
>> unfortunately not been Cabalized, you cannot install the diagrams
>> library with cabal-install, unless you already have the cairo package
>> installed. See the above website for instructions.)
>>
>> A special thanks to Dougal Stanton for his contributions to the
>> library and help in preparing this release.
>>
>> -Brent
>
> Would this make a handy plugin for gitit? I'm currently putting diagrams  
> together in xfig and saving them to my gitit tree while taking notes in  
> gitit, but being able to write diagrams code into gitit would be great.
>
> How easy or hard would this be to accomplish?

Not too hard, I think.  Here's code for something similar (for graphviz
diagrams), derived from plugins/DotPlugin.hs in SVN pandoc.

    transform :: Block -> IO Block
    transform (CodeBlock (id, classes, namevals) contents) | "dot" `elem` classes = do
      let (name, outfile) =  case lookup "name" namevals of
                                    Just fn   -> ([Str fn], fn ++ ".png")
                                    Nothing   -> ([], uniqueName contents ++ ".png")
      result <- readProcess "dot" ["-Tpng"] contents
      writeFile outfile result
      return $ Para [Image name (outfile, "")]
    transform x = return x
    
    -- | Generate a unique filename given the file's contents.
    uniqueName :: String -> String
    uniqueName = showDigest . sha1 . fromString

The 'transform' function will transform delimited code blocks such
as

    ~~~ {.dot name="diagram1"}
    digraph G {Hello->World}
    ~~~

into images generated by running the contents through graphviz's dot. To
lift this into a transformation of Pandoc documents, you can use syb:

    convertGraphviz :: Pandoc -> IO Pandoc
    convertGraphviz = everywhereM (mkM transform)

With minimal modifications, the same technique should work for
diagrams...

Best,
John



More information about the Haskell-Cafe mailing list