0 | module Graphics.DOT.Utils.Filters
2 | import Graphics.DOT.AST
16 | dotidIsStyle : DOTID -> Bool
17 | dotidIsStyle (NameID "style") = True
18 | dotidIsStyle (StringID "\"style\"") = True
19 | dotidIsStyle _ = False
24 | dotidIsInvis : DOTID -> Bool
25 | dotidIsInvis (NameID "invis") = True
26 | dotidIsInvis (StringID "\"invis\"") = True
27 | dotidIsInvis _ = False
30 | assignIsInvis : Assign -> Bool
31 | assignIsInvis (MkAssign lhs rhs) = dotidIsStyle lhs && dotidIsInvis rhs
36 | removeInvisAssign : List Assign -> List Assign
37 | removeInvisAssign = filter (not . assignIsInvis)
41 | isInvisEdge : Stmt -> Bool
42 | isInvisEdge (EdgeStmt x rhs (assigns :: attrs)) =
43 | any assignIsInvis assigns || any (any assignIsInvis) attrs
44 | isInvisEdge _ = False
48 | removeInvisEdges : Graph -> Graph
49 | removeInvisEdges g@(MkGraph strict graphTy mID_ []) = g
50 | removeInvisEdges (MkGraph strict graphTy mID_ stmts) =
51 | MkGraph strict graphTy mID_ $
filter (not . isInvisEdge) stmts
60 | dotidIsCluster : DOTID -> Bool
61 | dotidIsCluster (StringID id_) = isPrefixOf "\"cluster" $
toLower id_
62 | dotidIsCluster (NameID name) = isPrefixOf "cluster" $
toLower name
63 | dotidIsCluster _ = False
68 | graphIsCluster : Graph -> Bool
69 | graphIsCluster (MkGraph strict SubgraphKW (Just graphID) stmtList) =
70 | dotidIsCluster graphID
71 | graphIsCluster _ = False
76 | subgraphIsCluster : Subgraph -> Bool
77 | subgraphIsCluster (MkSubgraph (Just (kw, (Just subgraphID))) stmtList) =
78 | dotidIsCluster subgraphID
79 | subgraphIsCluster _ = False
83 | edgeRHSHasCluster : EdgeRHS -> Bool
84 | edgeRHSHasCluster (MkEdgeRHS op (Right subgr)) = subgraphIsCluster subgr
85 | edgeRHSHasCluster _ = False
89 | stmtHasCluster : Stmt -> Bool
90 | stmtHasCluster (EdgeStmt (Right subgr) erhss _) =
91 | subgraphIsCluster subgr || any edgeRHSHasCluster erhss
92 | stmtHasCluster (EdgeStmt _ erhss _) = any edgeRHSHasCluster erhss
93 | stmtHasCluster (SubgraphStmt subgr) = subgraphIsCluster subgr
94 | stmtHasCluster _ = False
98 | removeClusters : Graph -> Graph
99 | removeClusters g@(MkGraph strict graphTy mID_ []) = g
100 | removeClusters (MkGraph strict graphTy mID_ stmts) =
101 | MkGraph strict graphTy mID_ $
filter (not . stmtHasCluster) stmts