Skip to content

Instantly share code, notes, and snippets.

@abailly
Created January 30, 2013 21:28
Show Gist options
  • Save abailly/4677191 to your computer and use it in GitHub Desktop.
Save abailly/4677191 to your computer and use it in GitHub Desktop.
File failing to compile with package conflicts
module YakGraph(listOfClusterNames, listOfNodesPerCluster, countOfNodesPerCluster) where
import Data.GraphViz.Types
import Data.GraphViz.Types.Graph
import Data.GraphViz.Commands.IO
import qualified Data.Map as M
import Data.List(groupBy)
import Data.Maybe
import Data.Text.Lazy(unpack)
import Data.Sequence(Seq)
import Data.Foldable(toList)
import Control.Arrow
fromGraphId (Str s) = unpack s
listOfClusterNames :: DotGraph String -> [String]
listOfClusterNames = map (fromGraphId.fromJust) . M.keys . snd . graphStructureInformation
keyByCluster ((n,(p,_)):ns) = (p,n) : keyByCluster ns
keyByCluster [] = []
extractClusterName :: Seq (Maybe GraphID) -> String
extractClusterName seq = case toList seq of
[] -> "inbox"
(Just (Str name)):_ -> unpack name
listOfPairsToMapOfKeysWithListOfValues :: [(Seq(Maybe GraphID),String)] -> M.Map String [String]
listOfPairsToMapOfKeysWithListOfValues pairs = groupStuff pairs M.empty
where
groupStuff [] m = m
groupStuff ((c,n):rest) m = M.alter (addToList n) (extractClusterName c) (groupStuff rest m)
addToList n Nothing = Just [n]
addToList n (Just ns) = Just $ n:ns
countOfNodesPerCluster :: DotGraph String -> [(String, Int)]
countOfNodesPerCluster = map (id *** length) . M.toList . listOfNodesPerCluster
listOfNodesPerCluster :: DotGraph String -> M.Map String [String]
listOfNodesPerCluster =
listOfPairsToMapOfKeysWithListOfValues . concatMap keyByCluster . groupBy sameCluster . M.toAscList . nodeInformation False
where
sameCluster (n,(p,_)) (n',(p',_)) = p == p'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment