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
24 from pychart_types import *
32 "data" : (AnyType, None, pychart_util.data_desc),
33 "label": (StringType, "???", pychart_util.label_desc),
34 "data_label_offset": (CoordType, (0, 5),
35 """The location of data labels relative to the sample point. Meaningful only when data_label_format != None."""),
36 "data_label_format": (FormatType, None,
37 """The format string for the label printed
38 beside a sample point.
39 It can be a `printf' style format string, or
40 a two-parameter function that takes the (x, y)
41 values and returns a string. """
42 + pychart_util.string_desc),
43 "xcol" : (IntType, 0, pychart_util.xcol_desc),
44 "ycol": (IntType, 1, pychart_util.ycol_desc),
45 "y_error_minus_col": (IntType, 2,
46 """The column (within "data") from which the depth of the errorbar is extracted. Meaningful only when error_bar != None. <<error_bar>>"""),
47 "y_error_plus_col": (IntType, -1,
48 """The column (within "data") from which the height of the errorbar is extracted. Meaningful only when error_bar != None. <<error_bar>>"""),
49 "y_qerror_minus_col": (IntType, -1, "<<error_bar>>"),
50 "y_qerror_plus_col": (IntType, -1, "<<error_bar>>"),
52 "line_style": (line_style.T, lambda: line_style_itr.next(), pychart_util.line_desc,
53 "By default, a style is picked from standard styles round-robin. <<line_style>>"),
55 "tick_mark": (tick_mark.T, None, pychart_util.tick_mark_desc),
56 "error_bar": (error_bar.T, None,
57 "The style of the error bar. <<error_bar>>"),
60 class T(chart_object.T):
61 __doc__ = line_plot_doc.doc
63 def check_integrity(self):
66 ##AUTOMATICALLY GENERATED
68 ##END AUTOMATICALLY GENERATED
69 def get_data_range(self, which):
71 return pychart_util.get_data_range(self.data, self.xcol)
73 return pychart_util.get_data_range(self.data, self.ycol)
74 def get_legend_entry(self):
76 return legend.Entry(line_style=self.line_style,
77 tick_mark=self.tick_mark,
82 def draw(self, ar, can):
86 clipbox = theme.adjust_bounding_box([ar.loc[0], ar.loc[1],
87 ar.loc[0] + ar.size[0],
88 ar.loc[1] + ar.size[1]]);
90 can.clip(clipbox[0],clipbox[1],clipbox[2],clipbox[3])
93 for pair in self.data:
94 yval = pychart_util.get_sample_val(pair, self.ycol)
95 xval = pair[self.xcol]
96 if None not in (xval, yval):
97 points.append((ar.x_pos(xval), ar.y_pos(yval)))
98 can.lines(self.line_style, points)
101 # Draw tick marks and error bars
102 can.clip(ar.loc[0] - 10, ar.loc[1] - 10,
103 ar.loc[0] + ar.size[0] + 10,
104 ar.loc[1] + ar.size[1] + 10)
105 for pair in self.data:
107 y = pychart_util.get_sample_val(pair, self.ycol)
108 if None in (x, y): continue
114 plus = pair[self.y_error_plus_col or self.y_error_minus_col]
115 minus = pair[self.y_error_minus_col or self.y_error_plus_col]
116 if self.y_qerror_minus_col or self.y_qerror_plus_col:
117 q_plus = pair[self.y_qerror_plus_col or self.y_qerror_minus_col]
118 q_minus = pair[self.y_qerror_minus_col or self.y_qerror_plus_col]
119 if None not in (minus,plus,q_minus,q_plus):
120 self.error_bar.draw(can, (x_pos, y_pos),
123 ar.y_pos(y - q_minus),
124 ar.y_pos(y + q_plus))
126 if None not in (minus,plus): #PDS
127 self.error_bar.draw(can, (x_pos, y_pos),
132 self.tick_mark.draw(can, x_pos, y_pos)
133 if self.data_label_format:
134 can.show(x_pos + self.data_label_offset[0],
135 y_pos + self.data_label_offset[1],
136 "/hC" + pychart_util.apply_format(self.data_label_format, (x, y), 1))
141 global line_style_itr
142 line_styles = object_set.T()
143 for org_style in line_style.standards.list():
144 style = line_style.T(width = default_width, color = org_style.color,
145 dash = org_style.dash)
146 line_styles.add(style)
148 line_style_itr = line_styles.iterate()
150 theme.add_reinitialization_hook(init)