def _do_draw(self, context, rect, mode, maximum_value, value_label_size, label_size): if maximum_value == 0: return exp = int(math.log10(maximum_value)) if exp: n = maximum_value / 10 ** exp else: n = maximum_value / 10 context.set_antialias(cairo.ANTIALIAS_NONE) set_context_line_style(context, self._line_style) labels = [] if mode == MODE_VERTICAL: delta = (rect.height - value_label_size - label_size) / n if self._show_values: max_label_size = 0 for i in range(0, int(n + 1)): y = rect.y + rect.height - i * delta - label_size value = maximum_value * float(i) / n value_label = label.Label((rect.x, y), str(value)) max_label_size = max(max_label_size, value_label.get_calculated_dimensions(context, rect)[0]) labels.append(value_label) max_label_size += 3 rect = gtk.gdk.Rectangle(int(rect.x + max_label_size), rect.y, int(rect.width - max_label_size), rect.height) for i in range(0, len(labels)): y = rect.y + rect.height - i * delta - label_size value_label = labels[i] value_label.set_position((rect.x - 3, y)) value_label.set_anchor(label.ANCHOR_RIGHT_CENTER) value_label.draw(context, rect) context.fill() elif mode == MODE_HORIZONTAL: delta = (rect.width - value_label_size - label_size) / n if self._show_values: max_label_size = 0 for i in range(0, int(n + 1)): x = rect.x + i * delta + label_size value = maximum_value * float(i) / n value_label = label.Label((x, rect.y + rect.height), str(value)) max_label_size = max(max_label_size, value_label.get_calculated_dimensions(context, rect)[1]) labels.append(value_label) max_label_size += 3 rect = gtk.gdk.Rectangle(rect.x, rect.y, rect.width, int(rect.height - max_label_size)) for i in range(0, len(labels)): x = rect.x + i * delta + label_size value_label = labels[i] value_label.set_position((x, rect.y + rect.height + 3)) value_label.set_anchor(label.ANCHOR_TOP_CENTER) value_label.draw(context, rect) context.fill() for i in range(0, int(n + 1)): x = rect.x + i * delta + label_size context.set_source_rgb(*color_gdk_to_cairo(self._color)) context.move_to(x, rect.y) context.rel_line_to(0, rect.height) context.stroke() rect = gtk.gdk.Rectangle(rect.x, rect.y + self._padding, rect.width, rect.height - 2 * self._padding) return rect
def __init__(self, name, title=""): ChartObject.__init__(self) #private properties: self._group_label_object = label.Label((0, 0), title) #gobject properties: self._bars = [] self._name = name self._title = title self._bar_padding = 2
def __init__(self, name, value, title=""): chart.Area.__init__(self, name, value, title) self._label_object = label.Label((0, 0), title) self._value_label_object = label.Label((0, 0), "") self._corner_radius = 0
def __init__(self, name, value, title=""): chart.Area.__init__(self, name, value, title) self._label_object = label.Label((0, 0), title)