如何在 haskell 中访问点格式图(通用)的节点边缘
How to access nodes edges of dot format graph (Generalised ) in haskell
我想访问 '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
这对我有用(大部分与您的代码相同,但有一些更改):
#!/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
我想访问 '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
这对我有用(大部分与您的代码相同,但有一些更改):
#!/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