| Maintainer | dennis@felsin9.de |
|---|---|
| Safe Haskell | Safe-Infered |
Graphics.XDot.Parser
Description
After an xdot file has been opened using GraphViz, its drawing operations can be parsed using this module.
xDotText <- L.readFile "example.xdot" let xDotGraph = parseDotGraph xDotText :: G.DotGraph String let operations = getOperations xDotGraph
xdot files can be created using the dot binary from the Graphviz package:
$ cat example.dot
digraph {
0 [label=""];
1 [label=":"];
0 -> 1 [label="[1..]"];
}
$ dot -Txdot example.dot > example.xdot
Or you can skip saving an xdot file and use a dot file directly:
$ dotText <- L.readFile "example.dot"
$ let dotGraph = parseDotGraph dotText :: G.DotGraph String
$ xDotText <- graphvizWithHandle Dot dotGraph XDot T.hGetContents
$ let xDotGraph = parseDotGraph $ B.fromChunks [xDotText] :: G.DotGraph String
$ getOperations xDotGraph
[ (Nothing,Color {rgba = (1.0,1.0,1.0,1.0), filled = False})
, (Nothing,Color {rgba = (1.0,1.0,1.0,1.0), filled = True})
, (Nothing,Polygon {points = [(0.0,-1.0),(0.0,130.0),(55.0,130.0),(55.0,-1.0)], filled = True})
, (Just "0",Color {rgba = (0.0,0.0,0.0,1.0), filled = False})
, (Just "0",Ellipse {xy = (27.0,112.0), w = 27.0, h = 18.0, filled = False})
, (Just "1",Color {rgba = (0.0,0.0,0.0,1.0), filled = False})
, (Just "1",Ellipse {xy = (27.0,19.0), w = 27.0, h = 19.0, filled = False})
, (Just "1",Font {size = 14.0, name = "Times-Roman"})
, (Just "1",Color {rgba = (0.0,0.0,0.0,1.0), filled = False})
, (Just "1",Text {baseline = (27.0,15.0), alignment = CenterAlign, width = 4.0, text = ":"})
, (Nothing,Color {rgba = (0.0,0.0,0.0,1.0), filled = False})
, (Nothing,BSpline {points = [(27.0,94.0),(27.0,81.0),(27.0,63.0),(27.0,48.0)], filled = False})
, (Nothing,Style {style = "solid"})
, (Nothing,Color {rgba = (0.0,0.0,0.0,1.0), filled = False})
, (Nothing,Color {rgba = (0.0,0.0,0.0,1.0), filled = True})
, (Nothing,Polygon {points = [(31.0,48.0),(27.0,38.0),(24.0,48.0)], filled = True})
, (Nothing,Font {size = 14.0, name = "Times-Roman"})
, (Nothing,Color {rgba = (0.0,0.0,0.0,1.0), filled = False})
, (Nothing,Text {baseline = (39.0,62.0), alignment = CenterAlign, width = 24.0, text = "[1..]"})
]
The following imports are needed for this:
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