summaryrefslogtreecommitdiff
path: root/src/GF/Visualization
diff options
context:
space:
mode:
authorbringert <bringert@cs.chalmers.se>2006-01-05 12:59:36 +0000
committerbringert <bringert@cs.chalmers.se>2006-01-05 12:59:36 +0000
commit5c0d9d52b3d502faf87377303bf06c6028e8612e (patch)
treec531abee2e52b5804bc1d706e1415b94e6331733 /src/GF/Visualization
parenta4ba93cc556dadc33ed95abd9baac0d29236bcfe (diff)
Print slf_graphviz with subgraphs.
Diffstat (limited to 'src/GF/Visualization')
-rw-r--r--src/GF/Visualization/Graphviz.hs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/GF/Visualization/Graphviz.hs b/src/GF/Visualization/Graphviz.hs
index d326d5364..b59e3ecd2 100644
--- a/src/GF/Visualization/Graphviz.hs
+++ b/src/GF/Visualization/Graphviz.hs
@@ -17,6 +17,8 @@ module GF.Visualization.Graphviz (
Node(..), Edge(..),
Attr,
addSubGraphs,
+ setName,
+ setAttr,
prGraphviz
) where
@@ -25,7 +27,14 @@ import Data.Char
import GF.Data.Utilities
-- | Graph type, graph ID, graph attirbutes, graph nodes, graph edges, subgraphs
-data Graph = Graph GraphType String [Attr] [Node] [Edge] [Graph]
+data Graph = Graph {
+ gType :: GraphType,
+ gId :: Maybe String,
+ gAttrs :: [Attr],
+ gNodes :: [Node],
+ gEdges :: [Edge],
+ gSubgraphs :: [Graph]
+ }
deriving (Show)
data GraphType = Directed | Undirected
@@ -44,7 +53,13 @@ type Attr = (String,String)
--
addSubGraphs :: [Graph] -> Graph -> Graph
-addSubGraphs nss (Graph t i at ns es ss) = Graph t i at ns es (nss++ss)
+addSubGraphs gs g = g { gSubgraphs = gs ++ gSubgraphs g }
+
+setName :: String -> Graph -> Graph
+setName n g = g { gId = Just n }
+
+setAttr :: String -> String -> Graph -> Graph
+setAttr n v g = g { gAttrs = tableSet n v (gAttrs g) }
--
-- * Pretty-printing
@@ -52,11 +67,11 @@ addSubGraphs nss (Graph t i at ns es ss) = Graph t i at ns es (nss++ss)
prGraphviz :: Graph -> String
prGraphviz g@(Graph t i _ _ _ _) =
- graphtype t ++ " " ++ esc i ++ " {\n" ++ prGraph g ++ "}\n"
+ graphtype t ++ " " ++ maybe "" esc i ++ " {\n" ++ prGraph g ++ "}\n"
prSubGraph :: Graph -> String
prSubGraph g@(Graph _ i _ _ _ _) =
- "subgraph" ++ " " ++ esc i ++ " {\n" ++ prGraph g ++ "}"
+ "subgraph" ++ " " ++ maybe "" esc i ++ " {\n" ++ prGraph g ++ "}"
prGraph :: Graph -> String
prGraph (Graph t id at ns es ss) =