xdot 0.2.2 → 0.2.3
raw patch · 5 files changed
+86/−16 lines, 5 filesdep ~cairodep ~graphvizdep ~gtk
Dependency ranges changed: cairo, graphviz, gtk, mtl, polyparse, text
Files
- Demo.hs +4/−2
- dot-examples/simple.dot +7/−0
- src/Graphics/XDot/Parser.hs +43/−1
- src/Graphics/XDot/Viewer.hs +20/−5
- xdot.cabal +12/−8
Demo.hs view
@@ -8,6 +8,7 @@ import Data.GraphViz import qualified Data.GraphViz.Types.Generalised as G+import qualified Data.GraphViz.Types.Graph as R import Data.GraphViz.Commands.IO import Graphics.XDot.Parser@@ -34,7 +35,8 @@ run :: String -> IO () run file = do dotText <- L.readFile file- let dg = parseDotGraph dotText :: G.DotGraph String+ -- If dg is a G.DotGraph it fails when there's a subgraph in it+ let dg = parseDotGraph dotText :: R.DotGraph String -- You can choose another graphviz command by changing Dot to Neato, TwoPi, Circo or Fdp xdg <- graphvizWithHandle Dot dg XDot hGetDot@@ -72,7 +74,7 @@ onDestroy window mainQuit mainGUI -click :: IORef State -> G.DotGraph String -> IO ()+click :: IORef State -> R.DotGraph String -> IO () click state _dg = do s <- readIORef state
+ dot-examples/simple.dot view
@@ -0,0 +1,7 @@+digraph graphname+{+ subgraph G0{+ a -> b -> c;+ b -> d;+ }+}
src/Graphics/XDot/Parser.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings, NamedFieldPuns #-} {- | Module : Graphics.XDot.Parser@@ -58,7 +58,9 @@ > import qualified Data.GraphViz.Types.Generalised as G -} module Graphics.XDot.Parser (+ --test, getOperations,+ getDimensions, getSize ) where@@ -80,6 +82,10 @@ import Graphics.XDot.Types hiding (w, h, filled, baseline, width, alignment, size, text, xy, name) +--import qualified Data.Text.Lazy.IO as L+--import Data.GraphViz.Commands.IO+--import Data.GraphViz (GraphvizCommand(Dot), GraphvizOutput(XDot), graphvizWithHandle)+ -- | Extract all operations of an xdot graph and connect them to the node they -- belong to, if any. getOperations :: G.DotGraph a -> [(Object a, Operation)]@@ -102,6 +108,42 @@ handleSecond (A.UnknownAttribute "_hldraw_" r) l = parse r ++ l handleSecond (A.UnknownAttribute "_tlldraw_" r) l = parse r ++ l handleSecond _ l = l++-- | Extract the dimensions of all nodes and edges in the graph.+getDimensions :: G.DotGraph a -> [(Object a, Rectangle)]+getDimensions (G.DotGraph _ _ _ graphStatements) = F.foldr handle [] graphStatements+ where handle (G.DN (DotNode ident attrs)) l = (Node ident, (x - w / 2, y - h / 2, w, h)) : l+ where (x,y) = foldr getPos (0,0) attrs+ w = 72 * foldr getWidth 0 attrs+ h = 72 * foldr getHeight 0 attrs++ handle (G.DE (DotEdge from to attrs)) l = zip (repeat (Edge from to)) (map (\(x,y) -> (x - w / 2, y - h / 2, w, h)) xys) ++ l+ where xys = foldr getEdgePos [] attrs+ w = 30+ h = 30+ handle _ l = l++ getEdgePos (A.Pos (A.SplinePos splines)) l = foldr getSplinePos [] splines ++ l+ getEdgePos _ l = l++ getSplinePos (A.Spline {A.splinePoints = ((A.Point xStart yStart _ _):_), A.endPoint = Just (A.Point xEnd yEnd _ _)}) l = (xStart, yStart) : (xEnd, yEnd) : l+ getSplinePos _ l = l++ getWidth (A.Width w) _ = w+ getWidth _ l = l++ getHeight (A.Height h) _ = h+ getHeight _ l = l++ getPos (A.Pos (A.PointPos (A.Point x y _ _))) _ = (x,y)+ getPos _ l = l++--test = do+-- dotText <- L.readFile "/tmp/foo.dot"+-- let dotGraph = parseDotGraph dotText :: G.DotGraph String+-- xDotGraph <- graphvizWithHandle Dot dotGraph XDot hGetDot :: IO (G.DotGraph String)+-- putStrLn $ show $ xDotGraph+-- putStrLn $ show $ getDimensions xDotGraph -- | Extract the dimensions of the graph when drawn. getSize :: G.DotGraph a -> Rectangle
src/Graphics/XDot/Viewer.hs view
@@ -99,14 +99,14 @@ None -> [] o -> [(o, (x - w, y + h, 2 * w, 2 * h))] -draw hover (mn, Polygon ((x,y):xys) filled) = do+draw hover (mn, Polygon a@((x,y):xys) filled) = do stylizedDraw filled hover mn $ do moveTo x y mapM_ (uncurry lineTo) xys closePath - let xs = x : map fst xys- let ys = y : map snd xys+ let xs = x : map fst a+ let ys = y : map snd a return $ case mn of None -> []@@ -114,12 +114,27 @@ draw _ (_, Polygon [] _) = return [] -draw _ (_, Polyline _) = return []+draw hover (mn, Polyline a@((x,y):xys)) = do+ stylizedDraw False hover mn $ do+ moveTo x y+ mapM_ (uncurry lineTo) xys -draw hover (mn, BSpline ((x,y):xys) filled) = do+ let xs = x : map fst a+ let ys = y : map snd a++ return $ case mn of+ None -> []+ o -> [(o, (minimum xs, maximum ys, maximum xs - minimum xs, maximum ys - minimum ys))]++draw _ (_, Polyline []) = return []++draw hover (mn, BSpline a@((x,y):xys) filled) = do stylizedDraw filled hover mn $ do moveTo x y drawBezier xys++ let xs = x : map fst a+ let ys = y : map snd a return $ case mn of None -> []
xdot.cabal view
@@ -1,5 +1,5 @@ name: xdot-version: 0.2.2+version: 0.2.3 license: BSD3 license-file: LICENSE category: Graphs, Graphics@@ -22,17 +22,21 @@ is now a seperate project, in case anyone else may have a use for it. -tested-with: GHC == 7.4.1, GHC == 7.4.2+tested-with: GHC == 7.4.1, GHC == 7.4.2, GHC == 7.6.1 Extra-source-files: Demo.hs, dot-examples/*.dot Library Exposed-modules: Graphics.XDot.Parser Graphics.XDot.Viewer Graphics.XDot.Types Default-Language: Haskell2010 Build-depends: base == 4.*,- mtl >= 2.0,- cairo,- gtk,- graphviz >= 2999.14.1.0,- text,- polyparse+ mtl >= 2.0 && < 2.2,+ cairo == 0.12.*,+ gtk == 0.12.*,+ graphviz == 2999.16.*,+ text == 0.11.*,+ polyparse == 1.8.* Hs-source-dirs: src/ Ghc-options: -Wall -fno-warn-unused-do-bind++source-repository head+ type: git+ location: git://r0q.ath.cx/xdot