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