-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_layouts.py
69 lines (53 loc) · 1.92 KB
/
test_layouts.py
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
65
66
67
68
69
from pathlib import Path
from ogdf_python import ogdf, cppinclude
def disown(obj):
obj.__python_owns__ = False
return obj
def call_layout(GA, L):
print("Calling", type(L).__name__)
L.call(GA)
out = Path(__file__).parent / ("%s.svg" % type(L).__name__)
print("Writing Drawing to", out)
ogdf.GraphIO.drawSVG(GA, str(out))
bb = GA.boundingBox()
size = "%s x %s" % (bb.width(), bb.height())
print("Drawing size:", size)
assert bb.width() > 100, size
assert bb.height() > 100, size
def test_layouts():
cppinclude("ogdf/basic/graph_generators/randomized.h")
cppinclude("ogdf/energybased/SpringEmbedderFRExact.h")
cppinclude("ogdf/energybased/FMMMLayout.h")
cppinclude("ogdf/layered/MedianHeuristic.h")
cppinclude("ogdf/layered/OptimalHierarchyLayout.h")
cppinclude("ogdf/layered/OptimalRanking.h")
cppinclude("ogdf/layered/SugiyamaLayout.h")
G = ogdf.Graph()
ogdf.setSeed(1)
ogdf.randomPlanarTriconnectedGraph(G, 20, 40)
GA = ogdf.GraphAttributes(G, ogdf.GraphAttributes.all)
for v in G.nodes:
GA.width[v] = GA.height[v] = 20
GA.label[v] = str(v.index())
SL = ogdf.SugiyamaLayout()
SL.setRanking(disown(ogdf.OptimalRanking()))
SL.setCrossMin(disown(ogdf.MedianHeuristic()))
ohl = disown(ogdf.OptimalHierarchyLayout())
ohl.layerDistance(30.0)
ohl.nodeDistance(40.0)
ohl.weightBalancing(0.8)
SL.setLayout(ohl)
call_layout(GA, SL)
GA.scale(0.01, False) # make old drawing too small for assertion
sefr = ogdf.SpringEmbedderFRExact()
sefr.idealEdgeLength(200.0)
call_layout(GA, sefr)
GA.scale(0.01, False)
fmmm = ogdf.FMMMLayout()
fmmm.useHighLevelOptions(True)
fmmm.unitEdgeLength(50.0)
fmmm.newInitialPlacement(True)
fmmm.qualityVersusSpeed(ogdf.FMMMOptions.QualityVsSpeed.GorgeousAndEfficient)
call_layout(GA, fmmm)
if __name__ == "__main__":
test_layouts()