graphite 0.9.1.0 → 0.9.2.0
raw patch · 2 files changed
+54/−21 lines, 2 filesdep +textPVP ok
version bump matches the API change (PVP)
Dependencies added: text
API changes (from Hackage documentation)
+ Data.Graph.Visualize: labeledEdges :: (Hashable v, Eq v, Show e) => UGraph v e -> [(v, v, String)]
+ Data.Graph.Visualize: labeledNodes :: (Graph g, Show v) => g v e -> [(v, String)]
+ Data.Graph.Visualize: plotDGraphEdgeLabeled :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> IO ThreadId
+ Data.Graph.Visualize: plotUGraphEdgeLabeled :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => UGraph v e -> IO ThreadId
Files
- graphite.cabal +2/−1
- src/Data/Graph/Visualize.hs +52/−20
graphite.cabal view
@@ -1,5 +1,5 @@ name: graphite-version: 0.9.1.0+version: 0.9.2.0 synopsis: Graphs and networks library description: Represent, analyze and visualize graphs homepage: https://github.com/alx741/graphite#readme@@ -32,6 +32,7 @@ , cassava , containers , deepseq+ , text , graphviz , hashable , process
src/Data/Graph/Visualize.hs view
@@ -1,16 +1,21 @@ module Data.Graph.Visualize ( plotUGraph , plotUGraphPng- , plotDGraph , plotDGraphPng+ , plotUGraphEdgeLabeled+ , plotDGraphEdgeLabeled++ , labeledNodes+ , labeledEdges ) where import Control.Concurrent -import Data.GraphViz-import Data.GraphViz.Attributes.Complete-import Data.Hashable+import Data.GraphViz+import Data.GraphViz.Attributes.Complete+import Data.Hashable+import qualified Data.Text.Lazy as TL import Data.Graph.DGraph import Data.Graph.Types@@ -20,27 +25,39 @@ plotUGraph :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => UGraph v e -> IO ThreadId-plotUGraph g = forkIO $ runGraphvizCanvas Sfdp (toUndirectedDot g) Xlib+plotUGraph g = forkIO $ runGraphvizCanvas Sfdp (toUndirectedDot False g) Xlib +-- | Same as 'plotUGraph' but render edge labels+plotUGraphEdgeLabeled :: (Hashable v, Ord v, PrintDot v, Show v, Show e)+ => UGraph v e+ -> IO ThreadId+plotUGraphEdgeLabeled g = forkIO $ runGraphvizCanvas Sfdp (toUndirectedDot True g) Xlib+ -- | Plot an undirected 'UGraph' to a PNG image file plotUGraphPng :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => UGraph v e -> FilePath -> IO FilePath-plotUGraphPng g = addExtension (runGraphvizCommand Sfdp $ toUndirectedDot g) Png+plotUGraphPng g = addExtension (runGraphvizCommand Sfdp $ toUndirectedDot False g) Png -- | Plot a directed 'DGraph' plotDGraph :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> IO ThreadId-plotDGraph g = forkIO $ runGraphvizCanvas Sfdp (toDirectedDot g) Xlib+plotDGraph g = forkIO $ runGraphvizCanvas Sfdp (toDirectedDot False g) Xlib +-- | Same as 'plotDGraph' but render edge labels+plotDGraphEdgeLabeled :: (Hashable v, Ord v, PrintDot v, Show v, Show e)+ => DGraph v e+ -> IO ThreadId+plotDGraphEdgeLabeled g = forkIO $ runGraphvizCanvas Sfdp (toDirectedDot True g) Xlib+ -- | Plot a directed 'DGraph' to a PNG image file plotDGraphPng :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> FilePath -> IO FilePath-plotDGraphPng g = addExtension (runGraphvizCommand Sfdp $ toDirectedDot g) Png+plotDGraphPng g = addExtension (runGraphvizCommand Sfdp $ toDirectedDot False g) Png labeledNodes :: (Graph g, Show v) => g v e -> [(v, String)] labeledNodes g = (\v -> (v, show v)) <$> vertices g@@ -52,17 +69,32 @@ labeledArcs g = (\(Arc v1 v2 attr) -> (v1, v2, show attr)) <$> arcs g toUndirectedDot :: (Hashable v, Ord v, Show v, Show e)- => UGraph v e+ => Bool -- ^ Label edges+ -> UGraph v e -> DotGraph v-toUndirectedDot g = graphElemsToDot params (labeledNodes g) (labeledEdges g)- where params = nonClusteredParams- { isDirected = False- , globalAttributes = [GraphAttrs [Overlap ScaleOverlaps]]- }+toUndirectedDot labelEdges g = graphElemsToDot params (labeledNodes g) (labeledEdges g)+ where params = sensibleDotParams False labelEdges -toDirectedDot :: (Hashable v, Ord v, Show v, Show e) => DGraph v e -> DotGraph v-toDirectedDot g = graphElemsToDot params (labeledNodes g) (labeledArcs g)- where params = nonClusteredParams- { isDirected = True- , globalAttributes = [GraphAttrs [Overlap ScaleOverlaps]]- }+toDirectedDot :: (Hashable v, Ord v, Show v, Show e)+ => Bool -- ^ Label edges+ -> DGraph v e+ -> DotGraph v+toDirectedDot labelEdges g = graphElemsToDot params (labeledNodes g) (labeledArcs g)+ where params = sensibleDotParams True labelEdges++sensibleDotParams+ :: Bool -- ^ Directed+ -> Bool -- ^ Label edges+ -> GraphvizParams t l String () l+sensibleDotParams directed edgeLabeled = nonClusteredParams+ { isDirected = directed+ , globalAttributes =+ [ GraphAttrs [Overlap ScaleOverlaps]+ , EdgeAttrs [FontColor (X11Color DarkGreen)]+ ]+ , fmtEdge = edgeFmt+ }+ where+ edgeFmt (_, _, l) = if edgeLabeled+ then [Label $ StrLabel $ TL.pack l]+ else []