on 5dba607 help sign in
32 lines 1.1 kB history raw
1-- | Dump a directed graph in dot format. Used for debugging purposes
2--
3module Hakyll.Core.DirectedGraph.Dot
4 ( toDot
5 , writeDot
6 ) where
8import Hakyll.Core.DirectedGraph
9import qualified Data.Set as S
11-- | Convert a directed graph into dot format for debugging purposes
12--
13toDot :: Ord a
14 => (a -> String) -- ^ Convert nodes to dot names
15 -> DirectedGraph a -- ^ Graph to dump
16 -> String -- ^ Resulting string
17toDot showTag graph = unlines $ concat
18 [ return "digraph dependencies {"
19 , map showNode (S.toList $ nodes graph)
20 , concatMap showEdges (S.toList $ nodes graph)
21 , return "}"
22 ]
23 where
24 showNode node = " \"" ++ showTag node ++ "\";"
25 showEdges node = map (showEdge node) $ S.toList $ neighbours node graph
26 showEdge x y = " \"" ++ showTag x ++ "\" -> \"" ++ showTag y ++ "\";"
28-- | Write out the @.dot@ file to a given file path. See 'toDot' for more
29-- information.
30--
31writeDot :: Ord a => FilePath -> (a -> String) -> DirectedGraph a -> IO ()
32writeDot path showTag = writeFile path . toDot showTag