summaryrefslogtreecommitdiff
path: root/src/Codec/Pesto/Dot.lhs
blob: 89439e0ae44d1705641be975ad980d6974dc0081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Presentation
------------

.. class:: nodoc

> module Codec.Pesto.Dot (toDot) where
> import Codec.Pesto.Serialize (serialize)

Since each recipe is just a directed graph (digraph), we can use the dot
language to represent it as well. This in turnXXX can be transformed into an
image, for example.

> toDot nodes edges = unlines $ ["digraph a {\nnode [fontname=\"Roboto Semi-Light\"];"] ++ n ++ e ++ ["}"]
> 	where
>		f (a, b) = show a ++ " -> " ++ show b ++ ";"
> 		e = map f edges
> 		n = map (\(a, b) -> show a ++ " [label=\"" ++ dotEncodeString (serialize b) ++ "\"];") nodes

> dotEncodeString = concatMap dotEncodeChar
> dotEncodeChar '\n' = "\\n"
> dotEncodeChar '"' = "\\\""
> dotEncodeChar x = [x]