-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize.go
More file actions
64 lines (61 loc) · 1.92 KB
/
Copy pathnormalize.go
File metadata and controls
64 lines (61 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package dagro
func runNormalize(g *Graph) {
graphAttrs := asAttrs(g.Graph())
graphAttrs["dummyChains"] = []string{}
for _, e := range g.Edges() {
normalizeEdge(g, e)
}
}
func normalizeEdge(g *Graph, e Edge) {
v, w := e.V, e.W
vRank, wRank := num(asAttrs(g.Node(v)), "rank"), num(asAttrs(g.Node(w)), "rank")
edgeLabel := asAttrs(g.Edge(e))
labelRank := num(edgeLabel, "labelRank")
if wRank == vRank+1 {
return
}
g.RemoveEdge(e)
for i := 0; vRank+1 < wRank; i++ {
vRank++
edgeLabel["points"] = []Point{}
attrs := Attrs{
"width": float64(0), "height": float64(0),
"edgeLabel": edgeLabel, "edgeObj": e, "rank": vRank,
}
dummy := addDummyNode(g, "edge", attrs, "_d")
if vRank == labelRank {
attrs["width"], attrs["height"] = num(edgeLabel, "width"), num(edgeLabel, "height")
attrs["dummy"] = "edge-label"
attrs["labelpos"] = edgeLabel["labelpos"]
}
setEdgePreservingName(g, v, dummy, Attrs{"weight": num(edgeLabel, "weight")}, e)
if i == 0 {
chains := asAttrs(g.Graph())["dummyChains"].([]string)
asAttrs(g.Graph())["dummyChains"] = append(chains, dummy)
}
v = dummy
}
setEdgePreservingName(g, v, w, Attrs{"weight": num(edgeLabel, "weight")}, e)
}
func undoNormalize(g *Graph) {
chains, _ := asAttrs(g.Graph())["dummyChains"].([]string)
for _, start := range chains {
v := start
node := asAttrs(g.Node(v))
origLabel := node["edgeLabel"].(Attrs)
origEdge := node["edgeObj"].(Edge)
g.SetEdgeObject(origEdge, origLabel)
for stringValue(node, "dummy") != "" {
w := g.Successors(v)[0]
g.RemoveNode(v)
points, _ := origLabel["points"].([]Point)
origLabel["points"] = append(points, Point{X: num(node, "x"), Y: num(node, "y")})
if stringValue(node, "dummy") == "edge-label" {
origLabel["x"], origLabel["y"] = num(node, "x"), num(node, "y")
origLabel["width"], origLabel["height"] = num(node, "width"), num(node, "height")
}
v = w
node = asAttrs(g.Node(v))
}
}
}