我想访问'xDotGraph'(G.DotGraph)的节点,边和属性并再次设置它们。这是使用graphviz打印点格式图的Haskell代码:
$ cat example.dot
digraph {
a [type1="", type2=""];
b [type1="", type2=""];
a -> b [label=""];
}
import Data.GraphViz
import Data.Text.IO as T
import qualified Data.Text.Lazy as B
import qualified Data.Text.Lazy.IO as L
import qualified Data.GraphViz.Types.Generalised as G
import Data.GraphViz.Printing
xDotText <- L.readFile "example.xdot"
let xDotGraph = parseDotGraph xDotText :: G.DotGraph String
T.putStrLn $ renderDot $ toDot xDotGraph
答案 0 :(得分:1)
这适用于我(大多数与您的代码相同,但有一些更改):
#!/usr/bin/env stack
{- stack runghc --resolver lts-6.0 --package graphviz
-}
import Data.GraphViz
import Data.Text.IO as T
import qualified Data.Text.Lazy as B
import qualified Data.Text.Lazy.IO as L
import qualified Data.GraphViz.Types.Generalised as G
import Data.GraphViz.Printing
import Data.GraphViz.Types
main = do
xDotText <- L.readFile "example.dot"
let xDotGraph = parseDotGraph xDotText :: G.DotGraph String
L.putStrLn $ renderDot $ toDot xDotGraph
print $ graphNodes xDotGraph
print $ graphEdges xDotGraph