]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graphviz/scl/Visualization/GGraph.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graphviz / scl / Visualization / GGraph.scl
1 import "Visualization/Graphviz"\r
2 import "MMap" as MMap\r
3 include "Visualization/Graphviz/Property"\r
4 \r
5 data GGraph a e = GGraph Graph (MMap.T a Node) (a -> <e> [Property])\r
6 \r
7 newGGraph :: [Property] -> (a -> <e> [Property]) -> <Proc> GGraph a e\r
8 newGGraph properties f = GGraph (newGraph properties) (MMap.create ()) f \r
9 \r
10 @private\r
11 toNode :: GGraph a e -> a -> <e,Proc> Node\r
12 toNode (GGraph graph nodeMap f) r =\r
13     match MMap.get nodeMap r with\r
14         Just n -> n\r
15         Nothing -> do\r
16             n = newNode graph (f r)\r
17             MMap.put nodeMap r n\r
18             n\r
19 \r
20 newGEdge :: GGraph a e -> a -> a -> [Property] -> <e,Proc> Edge\r
21 newGEdge graph r1 r2 properties = edge\r
22   where\r
23     edge = newEdge (toNode graph r1) (toNode graph r2) properties\r
24 \r
25 newGNode :: GGraph a e -> a -> <e,Proc> Node\r
26 newGNode = toNode\r
27 \r
28 showGGraph :: GGraph a e -> <Proc> ()\r
29 showGGraph (GGraph graph _ _) = showGraph graph\r
30 \r
31 showGGraphWithAlgorithm :: String -> GGraph a e -> <Proc> ()\r
32 showGGraphWithAlgorithm algorithm (GGraph graph _ _) = showGraphWithAlgorithm graph algorithm\r