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