-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.py
31 lines (24 loc) · 1.31 KB
/
render.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
import defaults
def render(graph):
assert "node" in graph and "edges" in graph
node = graph["node"]
_, h = node.get_size()
canvas_height = h+ defaults.BOX_PADDING*2
xml = "<?xml version=\"1.0\" standalone=\"no\"?>\n"+ \
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" + \
"<svg height=\"%d\" width=\"%d\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n" % (800, defaults.CANVAS_WIDTH)+ \
" <g style=\"fill-opacity:1.0; stroke:black;\n"+\
" stroke-width:1;\">\n"
xml += node.draw()
for edge in graph["edges"]:
xml += edge.draw()
xml += " </g>\n</svg>\n"
return xml
def render_box(x, y, w, h):
return """<rect x="%d" y="%d" height="%d" width="%d" fill="none" stroke="black" stroke-width="2" rx="4" ry="4" />""" % (x, y, h, w)
def render_box_dashed(x, y, w, h):
return """<rect x="%d" y="%d" height="%d" width="%d" fill="none" stroke="navy" stroke-width="2" rx="2" ry="2" stroke-dasharray="2,2" />""" % (x, y, h, w)
def render_text(x, y, text):
return """<text x="%d" y="%d" font-family="Verdana" font-size="12" fill="blue">%s</text>""" % (x, y, text)
def render_line(x1, y1, x2, y2):
return """<line x1="%d" y1="%d" x2="%d" y2="%d" stroke-width="2"/>""" % (x1, y1, x2, y2)