on master help sign in
Add DirectedGraph to DOT module
commit5bc8028696ae8d5aa2c60db87aea3d00f9d7aebd authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSun 26 Dec 2010, 00:09 (16 years ago) parentec85de4
1 file changed+30
src/Hakyll/Core/DirectedGraph/Dot.hs+30
src/Hakyll/Core/DirectedGraph/Dot.hsnew file+30
@@ -0,0 +1,30 @@
1+-- | Dump a directed graph in dot format. Used for debugging purposes
2+--
3+module Hakyll.Core.DirectedGraph.Dot
4+ ( toDot
5+ , writeDot
6+ ) where
7+
8+import Hakyll.Core.DirectedGraph
9+import qualified Data.Set as S
10+
11+-- | Convert a directed graph into dot format for debugging purposes
12+--
13+toDot :: Ord a
14+ => (a -> String) -- ^ Convert nodes to dot names
15+ -> DirectedGraph a -- ^ Graph to dump
16+ -> String -- ^ Resulting string
17+toDot 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 ++ "\";"
25+
26+-- | Write out the @.dot@ file to a given file path. See 'toDot' for more
27+-- information.
28+--
29+writeDot :: Ord a => FilePath -> (a -> String) -> DirectedGraph a -> IO ()
30+writeDot path showTag = writeFile path . toDot showTag