1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
5 # Jockey is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any
10 # Jockey is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 def inch_to_point(inch):
23 def point_to_inch(pt):
24 return float(pt) / 72.0
26 def rotate(x, y, degree):
27 """Rotate a coordinate around point (0,0).
28 - x and y specify the coordinate.
29 - degree is a number from 0 to 360.
30 Returns a new coordinate.
32 radian = float(degree) * 2 * math.pi / 360.0
33 newx = math.cos(radian) * x - math.sin(radian) * y
34 newy = math.sin(radian) * x + math.cos(radian) * y
41 sys.stderr.write(str(s))
43 sys.stderr.write("\n")
49 sys.stderr.write(str(s))
50 sys.stderr.write("\n")
52 def get_sample_val(l, col):
57 def get_data_list(data, col):
58 # data = [ elem[col] for elem in data if elem[col] != None ]
61 val = get_sample_val(item, col)
66 def get_data_range(data, col):
67 data = get_data_list(data, col)
69 if type(item) not in (types.IntType, types.LongType, types.FloatType):
70 raise TypeError, "Non-number passed to data: %s" % (data)
71 return (min(data), max(data))
73 def round_down(val, bound):
74 return int(val/float(bound)) * bound
76 def round_up(val, bound):
77 return (int((val-1)/float(bound))+1) * bound
81 # Attribute type checking stuff
87 def union_dict(dict1, dict2):
92 def TextVAlignType(val):
93 if val in ('T', 'B', 'M', None):
95 return "Text vertical alignment must be one of T(op), B(ottom), or M(iddle).\n"
97 def TextAlignType(val):
98 if val in ('C', 'R', 'L', None):
100 return "Text horizontal alignment must be one of C(enter), R(ight), or L(eft)."
102 def apply_format(format, val, defaultidx):
105 elif type(format) == StringType:
106 return format % val[defaultidx]
108 return apply(format, val)
111 data_desc = "Specifies the data points. <<chart_data>>"
112 label_desc = "The label to be displayed in the legend. <<legend>>, <<font>>"
113 xcol_desc = """The column, within attribute "data", from which the X values of sample points are extracted. <<chart_data>>"""
114 ycol_desc = """The column, within attribute "data", from which the Y values of sample points are extracted. <<chart_data>>"""
115 tick_mark_desc = "Tick marks to be displayed at each sample point. <<tick_mark>>"
116 line_desc="The style of the line. "
118 def interval_desc(w):
119 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)
121 shadow_desc = """The value is either None or a tuple. When non-None,
122 a drop-shadow is drawn beneath the object. X-off, and y-off specifies the
123 offset of the shadow relative to the object, and fill specifies the
124 style of the shadow (@pxref{module-fill-style})."""
126 string_desc = """The appearance of the string produced here can be
127 controlled using escape sequences. <<font>>"""
132 class symbol_lookup_table:
133 def __init__(self, dict, objs):
135 for name, val in dict.items():
136 for obj in objs.list():
138 self.names[val] = name
140 def lookup(self, obj):
141 if self.names.has_key(obj):
142 return self.names[obj]