on 9939708 help sign in
30 lines 987 B 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 , concatMap showNode (S.toList $ nodes graph)
20 , return "}"
21 ]
22 where
23 showNode node = map (showEdge node) $ S.toList $ neighbours node graph
24 showEdge x y = " \"" ++ showTag x ++ "\" -> \"" ++ showTag y ++ "\";"
26-- | Write out the @.dot@ file to a given file path. See 'toDot' for more
27-- information.
28--
29writeDot :: Ord a => FilePath -> (a -> String) -> DirectedGraph a -> IO ()
30writeDot path showTag = writeFile path . toDot showTag