packages feed

diagrams-graphviz 1.3.0.1 → 1.3.1

raw patch · 3 files changed

+54/−15 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Diagrams.TwoD.GraphViz: simpleGraphDiagram :: (Ord v, Renderable (Path V2 Double) b) => GraphvizCommand -> Gr v e -> IO (QDiagram b V2 Double Any)

Files

CHANGES.markdown view
@@ -1,3 +1,8 @@+1.3.1 (13 July 2016)+--------------------++- add `simpleGraphDiagram` function+ 1.3.0.1 (6 June 2016) --------------------- 
diagrams-graphviz.cabal view
@@ -1,5 +1,5 @@ name:                diagrams-graphviz-version:             1.3.0.1+version:             1.3.1 synopsis:            Graph layout and drawing with GrahpViz and diagrams description:         Use GraphViz and diagrams together, with each doing what                      it does best: GraphViz for laying out graphs, and diagrams
src/Diagrams/TwoD/GraphViz.hs view
@@ -17,24 +17,40 @@ -- not let GraphViz do what it is good at, and use a dedicated drawing -- library for the actual drawing? ----- Here is some example code to lay out and draw a simple directed--- graph hierarchically:+-- In all the following examples we will make use of this example graph: --+-- > hex = mkGraph [0..19]+-- >         (   [ (v, (v+1)`mod`6, ()) | v <- [0..5] ]+-- >          ++ [ (v, v+k, ()) | v <- [0..5], k <- [6,12] ]+-- >          ++ [ (2,18,()), (2,19,()), (15,18,()), (15,19,()), (18,3,()), (19,3,()) ]+-- >         )+--+-- The easiest thing to do is to just use the provided+-- 'simpleGraphDiagram' function to create a default diagram quickly:+-- -- > {-# LANGUAGE NoMonomorphismRestriction #-} -- > -- > import           Diagrams.Backend.Rasterific.CmdLine -- > import           Diagrams.Prelude -- > import           Diagrams.TwoD.GraphViz -- >+-- > main = theGraph >>= defaultMain+-- >   where+-- >     theGraph :: IO (Diagram B)+-- >     theGraph = simpleGraphDiagram Dot hex+--+-- Here is how we would produce a similar image, but with more control+-- over the specific ways that things are drawn:+--+-- > {-# LANGUAGE NoMonomorphismRestriction #-}+-- >+-- > import           Diagrams.Backend.Rasterific.CmdLine+-- > import           Diagrams.Prelude+-- > import           Diagrams.TwoD.GraphViz+-- > -- > import           Data.GraphViz -- > import           Data.GraphViz.Commands -- >--- > hex = mkGraph [0..19]--- >         (   [ (v, (v+1)`mod`6, ()) | v <- [0..5] ]--- >          ++ [ (v, v+k, ()) | v <- [0..5], k <- [6,12] ]--- >          ++ [ (2,18,()), (2,19,()), (15,18,()), (15,19,()), (18,3,()), (19,3,()) ]--- >         )--- > -- > graphvizExample1 = do -- >   hex' <- layoutGraph Dot hex -- >   let hexDrawing :: Diagram B@@ -66,12 +82,6 @@ -- > import           Data.GraphViz.Attributes.Complete -- > import           Data.GraphViz.Commands -- >--- > hex = mkGraph [0..19]--- >         (   [ (v, (v+1)`mod`6, ()) | v <- [0..5] ]--- >          ++ [ (v, v+k, ()) | v <- [0..5], k <- [6,12] ]--- >          ++ [ (2,18,()), (2,19,()), (15,18,()), (15,19,()), (18,3,()), (19,3,()) ]--- >         )--- > -- > main = do -- >   let params :: GraphvizParams Int v e () v -- >       params = defaultDiaParams@@ -99,6 +109,7 @@    , drawGraph   , getGraph+  , simpleGraphDiagram   ) where  import           Diagrams.Prelude@@ -239,3 +250,26 @@   = augmentGraph gr . parseDG <$> graphvizWithHandle command asDot DotOutput hGetDot   where     parseDG = (`asTypeOf` asDot) . fromGeneralised+++-- | Just draw the nodes of the graph as circles and the edges as+--   arrows between them.+simpleGraphDiagram :: (Ord v, Renderable (Path V2 Double) b)+     => GraphvizCommand -> Gr v e -> IO (QDiagram b V2 Double Any)+simpleGraphDiagram layoutCmd gr = do+  gr' <- layoutGraph layoutCmd gr+  let nodes = G.labNodes gr'+      vmap = M.fromList [ (i, pointToP2 pt)+                        | (i,(attrs,_)) <- nodes, Pos (PointPos pt) <- attrs ]+      edgeLengths = [ (fromJust $ M.lookup i vmap) `distance` (fromJust $ M.lookup j vmap)+                    | (i, j, _) <- G.labEdges gr'+                    ]+      nodeRadius = minimum edgeLengths / 4+      drawing = drawGraph+                     (const $ place (circle nodeRadius))+                     (\_ p₁ _ p₂ _ p -> arrowBetween' (opts p) p₁ p₂)+                     gr'+      opts p = with & gaps .~ local nodeRadius+                    & arrowShaft .~ (unLoc . head $ pathTrails p)+                    & headLength .~ local nodeRadius+  return drawing