2 # Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
4 # Jockey is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the
6 # Free Software Foundation; either version 2, or (at your option) any
9 # Jockey is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 def inch_to_point(inch):
22 def point_to_inch(pt):
23 return float(pt) / 72.0
25 def rotate(x, y, degree):
26 """Rotate a coordinate around point (0,0).
27 - x and y specify the coordinate.
28 - degree is a number from 0 to 360.
29 Returns a new coordinate.
31 radian = float(degree) * 2 * math.pi / 360.0
32 newx = math.cos(radian) * x - math.sin(radian) * y
33 newy = math.sin(radian) * x + math.cos(radian) * y
40 sys.stderr.write(str(s))
42 sys.stderr.write("\n")
48 sys.stderr.write(str(s))
49 sys.stderr.write("\n")
51 def get_sample_val(l, col):
56 def get_data_list(data, col):
57 # data = [ elem[col] for elem in data if elem[col] != None ]
60 val = get_sample_val(item, col)
65 def get_data_range(data, col):
66 data = get_data_list(data, col)
68 if type(item) not in (types.IntType, types.LongType, types.FloatType):
69 raise TypeError, "Non-number passed to data: %s" % (data)
70 return (min(data), max(data))
72 def round_down(val, bound):
73 return int(val/float(bound)) * bound
75 def round_up(val, bound):
76 return (int((val-1)/float(bound))+1) * bound
80 # Attribute type checking stuff
86 def union_dict(dict1, dict2):
91 def TextVAlignType(val):
92 if val in ('T', 'B', 'M', None):
94 return "Text vertical alignment must be one of T(op), B(ottom), or M(iddle).\n"
96 def TextAlignType(val):
97 if val in ('C', 'R', 'L', None):
99 return "Text horizontal alignment must be one of C(enter), R(ight), or L(eft)."
101 def apply_format(format, val, defaultidx):
104 elif type(format) == StringType:
105 return format % val[defaultidx]
107 return apply(format, val)
110 data_desc = "Specifies the data points. <<chart_data>>"
111 label_desc = "The label to be displayed in the legend. <<legend>>, <<font>>"
112 xcol_desc = """The column, within attribute "data", from which the X values of sample points are extracted. <<chart_data>>"""
113 ycol_desc = """The column, within attribute "data", from which the Y values of sample points are extracted. <<chart_data>>"""
114 tick_mark_desc = "Tick marks to be displayed at each sample point. <<tick_mark>>"
115 line_desc="The style of the line. "
117 def interval_desc(w):
118 return "When the value is a number, it specifies the interval at which %s are drawn. Otherwise, the value must be a function that takes no argument and returns the list of numbers. The return value specifies the X or Y points at which %s are drawn." % (w,w)
120 shadow_desc = """The value is either None or a tuple. When non-None,
121 a drop-shadow is drawn beneath the object. X-off, and y-off specifies the
122 offset of the shadow relative to the object, and fill specifies the
123 style of the shadow (@pxref{module-fill-style})."""
125 string_desc = """The appearance of the string produced here can be
126 controlled using escape sequences. <<font>>"""
131 class symbol_lookup_table:
132 def __init__(self, dict, objs):
134 for name, val in dict.items():
135 for obj in objs.list():
137 self.names[val] = name
139 def lookup(self, obj):
140 if self.names.has_key(obj):
141 return self.names[obj]