{-| Module : Data.Tree.LogTreeUtil Description : A package of utilities for working with 'LogTree' instances. Copyright : Copyright (c) 2014 David Banas; all rights reserved World wide. License : BSD3 Maintainer : capn.freako@gmail.com Stability : Development Portability : -} module Data.Tree.LogTreeUtil ( dotLogTree, getLevels, getFlatten, getEval ) where import Control.Monad.State.Lazy import Text.Printf (printf, PrintfArg) import Data.Tree import Data.List import Data.Tree.LogTree -- | Converts a GenericLogTree to a GraphViz dot diagram. dotLogTree :: (Show a, Eq a, Num a, LogTree t a) => Either String t -> (String, String) dotLogTree (Left msg) = (header ++ "\"node0\" [label = \"" ++ msg ++ "\"]\n" ++ "}\n", "") dotLogTree (Right tree) = (header ++ treeStr ++ "}\n", compNodeLegend) where (treeStr, compNodeTypes) = runState (dotLogTreeRecurse "0" (getCompNodes tree) tree twiddles) [] -- This is just a convenient way to get a list of correctly typed "1.0"s of the correct length: twiddles = concat $ getTwiddleStrs $ Node (Nothing, [], 0, DIT) $ subForest tree nodeLen = fromIntegral $ length $ last (levels tree) compNodeLegend = "digraph {\n" ++ "label = \"Computational Node Legend\" fontsize = \"24\"\n" ++ "\"node0L\"" ++ " [label = <