894
894
self.value_label = self.context.text_extents(str(max(sum(serie) for serie in self.data)))[2 + self.main_dir]
896
896
self.value_label = self.context.text_extents(str(max(max(serie) for serie in self.data)))[2 + self.main_dir]
897
print self.context.text_extents(str(max(max(serie) for serie in self.data)))
898
897
if self.labels[self.main_dir]:
899
898
self.plot_dimensions[self.main_dir] = self.dimensions[self.main_dir] - 2*self.borders[self.main_dir] - self.value_label
927
925
self.render_values()
928
926
self.render_labels()
929
927
self.render_plot()
928
if self.series_labels:
931
931
def draw_3d_rectangle_front(self, x0, y0, x1, y1, shift):
932
932
self.context.rectangle(x0-shift, y0+shift, x1-x0, y1-y0)
977
977
self.render_horz_labels()
978
978
if self.labels[VERT]:
979
979
self.render_vert_labels()
981
def render_legend(self):
983
cr.set_font_size(self.font_size)
984
cr.set_line_width(self.line_width)
986
widest_word = max(self.series_labels, key = lambda item: self.context.text_extents(item)[2])
987
tallest_word = max(self.series_labels, key = lambda item: self.context.text_extents(item)[3])
988
max_width = self.context.text_extents(widest_word)[2]
989
max_height = self.context.text_extents(tallest_word)[3] * 1.1 + 5
991
color_box_height = max_height / 2
992
color_box_width = color_box_height * 2
995
bounding_box_width = max_width + color_box_width + 15
996
bounding_box_height = (len(self.series_labels)+0.5) * max_height
997
cr.set_source_rgba(1,1,1)
998
cr.rectangle(self.dimensions[HORZ] - self.border - bounding_box_width, self.border,
999
bounding_box_width, bounding_box_height)
1002
cr.set_source_rgba(*self.line_color)
1003
cr.set_line_width(self.line_width)
1004
cr.rectangle(self.dimensions[HORZ] - self.border - bounding_box_width, self.border,
1005
bounding_box_width, bounding_box_height)
1008
for idx,key in enumerate(self.series_labels):
1010
cr.set_source_rgba(*self.series_colors[idx])
1011
cr.rectangle(self.dimensions[HORZ] - self.border - max_width - color_box_width - 10,
1012
self.border + color_box_height + (idx*max_height) ,
1013
color_box_width, color_box_height)
1016
cr.set_source_rgba(0, 0, 0)
1017
cr.rectangle(self.dimensions[HORZ] - self.border - max_width - color_box_width - 10,
1018
self.border + color_box_height + (idx*max_height),
1019
color_box_width, color_box_height)
1023
cr.set_source_rgba(0, 0, 0)
1024
cr.move_to(self.dimensions[HORZ] - self.border - max_width - 5, self.border + ((idx+1)*max_height))
981
1028
class HorizontalBarPlot(BarPlot):
982
1029
def __init__(self,
1000
1048
BarPlot.__init__(self, surface, data, width, height, background, border,
1001
1049
display_values, grid, rounded_corners, stack, three_dimension,
1002
1050
x_labels, y_labels, x_bounds, y_bounds, series_colors, HORZ)
1051
self.series_labels = series_labels
1004
1053
def calc_vert_extents(self):
1005
1054
self.calc_extents(VERT)
1039
1088
self.context.set_source_rgba(0.8, 0.8, 0.8)
1040
1089
if self.labels[HORZ]:
1041
1090
self.context.set_font_size(self.font_size * 0.8)
1042
step = (self.dimensions[HORZ] - 2*self.borders[HORZ])/(len(self.labels[HORZ])-1)
1091
step = (self.dimensions[HORZ] - 2*self.borders[HORZ] - self.value_label)/(len(self.labels[HORZ])-1)
1043
1092
x = self.borders[HORZ]
1045
1094
for item in self.labels[HORZ]:
1167
1217
BarPlot.__init__(self, surface, data, width, height, background, border,
1168
1218
display_values, grid, rounded_corners, stack, three_dimension,
1169
1219
x_labels, y_labels, x_bounds, y_bounds, series_colors, VERT)
1220
self.series_labels = series_labels
1171
1222
def calc_vert_extents(self):
1172
1223
self.calc_extents(VERT)
1249
1300
def render_vert_labels(self):
1250
1301
self.context.set_source_rgba(*self.label_color)
1251
y = self.borders[VERT]
1252
step = (self.dimensions[VERT] - 2*self.borders[VERT])/(len(self.labels[VERT]) - 1)
1302
y = self.borders[VERT] + self.value_label
1303
step = (self.dimensions[VERT] - 2*self.borders[VERT] - self.value_label)/(len(self.labels[VERT]) - 1)
1253
1304
self.labels[VERT].reverse()
1254
1305
for item in self.labels[VERT]:
1255
1306
width, height = self.context.text_extents(item)[2:4]
1930
1982
CairoPlot.vertical_bar_plot ('bar2', data, 400, 300, border = 20, grid = True, rounded_corners = False)
1933
plot = VerticalBarPlot(name, data, width, height, background, border,
1985
plot = VerticalBarPlot(name, data, width, height, background, border, series_labels,
1934
1986
display_values, grid, rounded_corners, stack, three_dimension,
1935
1987
x_labels, y_labels, x_bounds, y_bounds, colors)
1981
2034
CairoPlot.bar_plot ('bar2', data, 400, 300, border = 20, grid = True, rounded_corners = False)
1984
plot = HorizontalBarPlot(name, data, width, height, background, border,
2037
plot = HorizontalBarPlot(name, data, width, height, background, border, series_labels,
1985
2038
display_values, grid, rounded_corners, stack, three_dimension,
1986
2039
x_labels, y_labels, x_bounds, y_bounds, colors)