Add DirectedGraph to DOT module
This commit is contained in:
parent
ec85de418b
commit
5bc8028696
1 changed files with 30 additions and 0 deletions
30
src/Hakyll/Core/DirectedGraph/Dot.hs
Normal file
30
src/Hakyll/Core/DirectedGraph/Dot.hs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
-- | Dump a directed graph in dot format. Used for debugging purposes
|
||||||
|
--
|
||||||
|
module Hakyll.Core.DirectedGraph.Dot
|
||||||
|
( toDot
|
||||||
|
, writeDot
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Hakyll.Core.DirectedGraph
|
||||||
|
import qualified Data.Set as S
|
||||||
|
|
||||||
|
-- | Convert a directed graph into dot format for debugging purposes
|
||||||
|
--
|
||||||
|
toDot :: Ord a
|
||||||
|
=> (a -> String) -- ^ Convert nodes to dot names
|
||||||
|
-> DirectedGraph a -- ^ Graph to dump
|
||||||
|
-> String -- ^ Resulting string
|
||||||
|
toDot showTag graph = unlines $ concat
|
||||||
|
[ return "digraph dependencies {"
|
||||||
|
, concatMap showNode (S.toList $ nodes graph)
|
||||||
|
, return "}"
|
||||||
|
]
|
||||||
|
where
|
||||||
|
showNode node = map (showEdge node) $ S.toList $ neighbours node graph
|
||||||
|
showEdge x y = " \"" ++ showTag x ++ "\" -> \"" ++ showTag y ++ "\";"
|
||||||
|
|
||||||
|
-- | Write out the @.dot@ file to a given file path. See 'toDot' for more
|
||||||
|
-- information.
|
||||||
|
--
|
||||||
|
writeDot :: Ord a => FilePath -> (a -> String) -> DirectedGraph a -> IO ()
|
||||||
|
writeDot path showTag = writeFile path . toDot showTag
|
Loading…
Reference in a new issue