dotgen 0.1 → 0.1.1
raw patch · 2 files changed
+20/−5 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Data.Dot: userNode :: NodeId -> [(String, String)] -> Dot ()
+ Data.Dot: userNodeId :: Int -> NodeId
- Data.Dot: showDot :: Dot () -> String
+ Data.Dot: showDot :: Dot a -> String
Files
- Data/Dot.hs +18/−4
- dotgen.cabal +2/−1
Data/Dot.hs view
@@ -17,6 +17,8 @@ -- * Nodes , node , NodeId -- abstract+ , userNodeId+ , userNode -- * Edges , edge , (.->.)@@ -32,10 +34,14 @@ data DotGraph = DotGraph [GraphElement] -newtype NodeId = NodeId String+data NodeId = NodeId String+ | UserNodeId Int instance Show NodeId where show (NodeId str) = str+ show (UserNodeId i) + | i < 0 = "u_" ++ show (negate i)+ | otherwise = "u" ++ show i data GraphElement = GraphAttribute String String | GraphNode NodeId [(String,String)]@@ -56,6 +62,15 @@ node attrs = Dot $ \ uq -> let nid = NodeId $ "n" ++ show uq in ( [ GraphNode nid attrs ],succ uq,nid) ++-- | 'userNodeId' allows a user to use their own (Int-based) node id's, without needing to remap them.+userNodeId :: Int -> NodeId+userNodeId i = UserNodeId i++-- | 'userNode' takes a NodeId, and adds some attributes to that node. +userNode :: NodeId -> [(String,String)] -> Dot ()+userNode nId attrs = Dot $ \ uq -> ( [GraphNode nId attrs ],uq,())+ -- | 'edge' generates an edge between two 'NodeId's, with attributes. edge :: NodeId -> NodeId -> [(String,String)] -> Dot () edge from to attrs = Dot (\ uq -> ( [ GraphEdge from to attrs ],uq,()))@@ -63,7 +78,6 @@ -- | '.->.' generates an edge between two 'NodeId's. (.->.) from to = edge from to [] - -- | 'scope' groups a subgraph together; in dot these are the subgraphs inside "{" and "}". scope :: Dot a -> Dot a scope (Dot fn) = Dot (\ uq -> case fn uq of@@ -94,9 +108,9 @@ attribute (name,val) = Dot (\ uq -> ( [ GraphAttribute name val ],uq,())) -- 'showDot' renders a dot graph as a 'String'.-showDot :: Dot () -> String+showDot :: Dot a -> String showDot (Dot dm) = case dm 0 of- (elems,_,()) -> "digraph G {\n" ++ unlines (map showGraphElement elems) ++ "\n}\n"+ (elems,_,_) -> "digraph G {\n" ++ unlines (map showGraphElement elems) ++ "\n}\n" showGraphElement (GraphAttribute name val) = showAttr (name,val) ++ ";" showGraphElement (GraphNode nid attrs) = show nid ++ showAttrs attrs ++ ";"
dotgen.cabal view
@@ -1,5 +1,5 @@ Name: dotgen-Version: 0.1+Version: 0.1.1 Synopsis: A simple interface for building .dot graph files. Description: This package provides a simple interface for building .dot graph files, for input into the dot and graphviz tools. @@ -17,4 +17,5 @@ -- Trivial (build) test framework --Executable: dotgen-test --hs-source-dirs: test, .+--ghc-options: -fhpc --Main-is: DotTest.hs