/
20110504b.py
52 lines (45 loc) · 1.47 KB
/
20110504b.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
"""Make a TikZ tree that shows harmonically extended valuations.
"""
from StringIO import StringIO
import Form
import FormOut
import tikz
import Newick
import TreeProjection
g_default_yaw = 0
g_default_pitch = 0.2
g_default_eigenvector_index = 2
g_default_tree = Newick.daylight_example_tree
def get_form():
"""
@return: the body of a form
"""
# define the tree string
tree = Newick.parse(g_default_tree, Newick.NewickTree)
formatted_tree_string = Newick.get_narrow_newick_string(tree, 60)
# get the form objects
form_objects = [
Form.MultiLine('tree', 'tree', formatted_tree_string),
Form.Integer('eigenvector_index',
'eigenvector index (1 is Fiedler)',
g_default_eigenvector_index, low=1),
Form.Float('yaw', 'yaw', g_default_yaw),
Form.Float('pitch', 'pitch', g_default_pitch),
Form.TikzFormat()]
return form_objects
def get_form_out():
return FormOut.Tikz()
def get_response_content(fs):
"""
@param fs: a FieldStorage object containing the cgi arguments
@return: the response
"""
tikz_body_lines = TreeProjection.get_tikz_lines(
fs.tree, fs.eigenvector_index, fs.yaw, fs.pitch)
tikz_body = '\n'.join(tikz_body_lines)
options = {
'x' : '1em',
'y' : '1em',
'inner sep': '0pt'}
tikzpicture = tikz.get_picture(tikz_body, **options)
return tikz.get_response(tikzpicture, fs.tikzformat)