如何在haskell中访问点格式图(Generalized)的节点边

时间:2016-08-08 14:20:47

标签: haskell graphviz dot digraphs

我想访问'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

1 个答案:

答案 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