def _render(self): if self.background: self.fill_area(0, 0, self.width, self.height, self.background) default_font = pango.FontDescription(gtk.Style().font_desc.to_string()) default_font.set_size(self.fontsize * pango.SCALE) self.layout.set_font_description(default_font) #self.context.set_source_rgb(0,0,0) self.layout.set_markup(self.text) self.layout.set_width((self.width) * pango.SCALE) self.context.move_to(0,0) charting.set_color(self.context, charting.dark[8]) self.context.show_layout(self.layout)
def _render(self): import calendar if self.draw_mode != self.MODE_YEAR: return self.fill_area(0, 0, self.width, self.height, (0.975,0.975,0.975)) charting.set_color(self.context, (100,100,100)) self.set_value_range(x_min = 1, x_max = (self.end_date - self.start_date).days) month_label_fits = True for month in range(1, 13): self.layout.set_text(calendar.month_abbr[month]) label_w, label_h = self.layout.get_pixel_size() if label_w * 2 > self.x_factor * 30: month_label_fits = False break ticker_date = self.start_date year_pos = 0 for year in range(self.start_date.year, self.end_date.year + 1): #due to how things overlay, we are putting labels on backwards, so that they don't overlap self.context.set_line_width(1) for month in range(1, 13): for day in range(1, calendar.monthrange(year, month)[1] + 1): ticker_pos = year_pos + ticker_date.timetuple().tm_yday #if ticker_date.weekday() in [0, 6]: # self.fill_area(ticker_pos * self.x_factor + 1, 20, self.x_factor, self.height - 20, (240, 240, 240)) # self.context.stroke() if self.x_factor > 5: self.move_to(ticker_pos, self.height - 20) self.line_to(ticker_pos, self.height) self.layout.set_text(ticker_date.strftime("%d")) label_w, label_h = self.layout.get_pixel_size() if label_w < self.x_factor / 1.2: #if label fits self.context.move_to(self.get_pixel(ticker_pos) + 2, self.height - 20) self.context.show_layout(self.layout) self.context.stroke() #now facts facts_today = self.facts.get(ticker_date, []) if facts_today: total_length = dt.timedelta() for fact in facts_today: total_length += fact["delta"] total_length = total_length.seconds / 60 / 60.0 + total_length.days * 24 total_length = total_length / float(self.max_hours) * self.height - 16 self.fill_area(ticker_pos * self.x_factor, self.height - total_length, self.x_factor, total_length, (190,190,190)) ticker_date += dt.timedelta(1) if month_label_fits: #roll back a little month_pos = ticker_pos - calendar.monthrange(year, month)[1] + 1 self.move_to(month_pos, 0) #self.line_to(month_pos, 20) self.layout.set_text(dt.date(year, month, 1).strftime("%b")) self.move_to(month_pos, 0) self.context.show_layout(self.layout) self.layout.set_text("%d" % year) label_w, label_h = self.layout.get_pixel_size() self.move_to(year_pos + 2 / self.x_factor, month_label_fits * label_h * 1.2) self.context.show_layout(self.layout) self.context.stroke() year_pos = ticker_pos #save current state for next year