def get_content(self, column_data, row_values, col_values): """return the content formated as defined in the constructor or in the column """ if self.value == None or self.value == False: return "" format = self.DEFAULT_FORMAT if self.format != None: format = self.format elif type(column_data) == DateColData and column_data.format != None: format = column_data.format value = super(DateCellData,self).get_content(column_data, row_values, col_values) if format != None: value = time.strftime(format, value) else: value = time.strftime(self.format, value) ps = ParagraphStyle('date_cell') ps.fontName = self.get_font(column_data) ps.fontSize = self.get_font_size(column_data) ps.alignment = self.get_align_code(column_data) res = Paragraph(c2c_helper.encode_entities(value), ps) return res
def _add_items(self): """ add labels and color to the table """ #X starting position X_pos = 0 if self.title != None: X_pos = 1 Y_pos = 0 cpt = 0 for i in self.items_order: #add the label txt = c2c_helper.encode_entities(self.items[i].label) ps = ParagraphStyle('color_legend') ps.alignment = TA_CENTER ps.fontName = self.DEFAULT_FONT ps.fontSize = self.DEFAULT_FONT_SIZE p = Paragraph(txt, ps) self.table[0][cpt+X_pos] = p #add the color self.styles.append(('BACKGROUND', (cpt+X_pos,0), (cpt+X_pos,0), self.items[i].color)) cpt+=1
def _build_table(self): """ return the list of list that represent the table structure """ line = [] if self.title != None: txt = c2c_helper.encode_entities(self.title) ps = ParagraphStyle('color_legend') ps.alignment = TA_CENTER ps.fontName = self.DEFAULT_FONT ps.fontSize = self.DEFAULT_FONT_SIZE p = Paragraph(txt, ps) line.append([p]) for i in self.items_order: line.append('') self.table.append(line) #global font for the whole graphic self.styles.append(('FONT', (0,0), (-1,-1),self.DEFAULT_FONT, self.DEFAULT_FONT_SIZE)) # main frame arround the whole table self.styles.append(('BOX', (0,0), (-1,-1), 1, "#000000")) #in cells, text start in the top left corner self.styles.append(('VALIGN', (0,0), (-1,-1), 'TOP')) if self.title != None: #background of the legend title self.styles.append(('BACKGROUND', (0,0), (0,0), "#cccccc"))
def _add_Y_items(self): """ add Y items labels to the chart (Text and styles). Add also light grid for their lines """ X_pos = 0 Y_pos = 3 #draw the items titles with the right indentation for i in self.data.items_order: item = self.data.items[i] ps = ParagraphStyle('indent') ps.fontName = self.DEFAULT_FONT ps.fontSize = self.DEFAULT_FONT_SIZE ps.leftIndent = item.indent * self.INDENT_SPACE p = Paragraph(self._encode_entities(item.label), ps) self.table[Y_pos + item.Y_pos][X_pos] = p #draw the inner grid for this lines start_X = X_pos end_X = -1 start_Y = Y_pos + item.Y_pos end_Y = Y_pos + item.Y_pos + item.line_number self.styles.append(('LINEABOVE', (start_X, end_Y), (end_X, end_Y), 0.2, "#bbbbbb")) self.styles.append(('LINEAFTER', (start_X, start_Y), (end_X, end_Y), 0.2, "#bbbbbb")) #line that separate the Y items and the datas self.styles.append(('LINEAFTER', (X_pos, Y_pos-2), (X_pos, -1), 1, colors.black))
def get_title(self): """return the title of the col""" ps = ParagraphStyle('header') ps.fontName = self.header_font ps.fontSize = self.header_font_size ps.alignment = self.get_align_code() return Paragraph(self._title, ps)
def get_content(self, column_data, row_values, col_values): """ return the content of the cell, formated as define in the constructor or in the column object """ res = self.get_raw_content(column_data, row_values, col_values) ps = ParagraphStyle('num_cell') ps.fontName = self.get_font(column_data) ps.fontSize = self.get_font_size(column_data) ps.alignment = self.get_align_code(column_data) res = Paragraph(res, ps) return res
def _add_secondary_scale(self): """ add the secondary scale to the table (text + styles) """ Y_pos = 1 X_pos = 1 #write the label ps = ParagraphStyle('secondary_scale_label') ps.alignment = TA_RIGHT ps.fontName = self.DEFAULT_FONT ps.fontSize = self.DEFAULT_FONT_SIZE title = Paragraph(self.data.scale.secondary_label, ps) self.table[Y_pos][0] = title ps = ParagraphStyle('secondary_scale') ps.alignment = TA_CENTER ps.fontName = self.DEFAULT_FONT ps.fontSize = self.DEFAULT_FONT_SIZE #the secondary scale is not define the same way as the primary scale. #it's defined by groups of same label. (start_pos, start_end, item) # see ScaleData._group_scale() for details for group in self.data.scale.secondary_scale_groups: pos_start, pos_end, item = group p = Paragraph(item, ps) #draw the label in the middle of the similar cells self.table[Y_pos][int((pos_start+pos_end)/2)+1] = p #draw light border arrounds items self.styles.append(('BOX', (pos_start+X_pos,Y_pos), (pos_end+X_pos,Y_pos), 0.2, "#bbbbbb"))
def get_content(self, column_data, row_values, col_values): """ return the content formated as defined in the constructor or in the column """ res = self.get_raw_content(column_data, row_values, col_values) if res == None or res == False or res == "": return "" res += " "+self.get_currency(column_data) ps = ParagraphStyle('money_cell') ps.fontName = self.get_font(column_data) ps.fontSize = self.get_font_size(column_data) ps.alignment = self.get_align_code(column_data) res = Paragraph(c2c_helper.encode_entities(res), ps) return res
def get_content(self, column_data, row_values, col_values): """ return the content formated as defined in the constructor or in the column """ res = self.get_raw_content(column_data, row_values, col_values) if res == None: return "" res += " "+self.get_currency(column_data) ps = ParagraphStyle('tot_money_cell') ps.fontName = self.get_font(column_data) ps.fontSize = self.get_font_size(column_data) #handle the alignment (if defined and different from the column alignement) ps.alignment = self.get_align_code(column_data) res = Paragraph(res, ps) return res
def _add_main_scale(self): """ add the main scale to the table (text + style) """ Y_pos = 2 X_pos = 1 #write the label ps = ParagraphStyle('scale_label') ps.alignment = TA_RIGHT ps.fontName = self.DEFAULT_FONT ps.fontSize = self.DEFAULT_FONT_SIZE title = Paragraph(self.data.scale.main_label, ps) self.table[Y_pos][0] = title ps = ParagraphStyle('scale') ps.alignment = TA_CENTER ps.fontName = self.DEFAULT_FONT ps.fontSize = self.DEFAULT_FONT_SIZE #reduce the size of the font for large scales if len(self.data.scale.scale_items) > 80: ps.fontSize = 6 #add labels for each scale item #also add weekend grayed column cpt = X_pos for item in self.data.scale.scale_items: p = Paragraph(item, ps) self.table[Y_pos][cpt] = p #handle weekemd if self.data.scale.weekend[cpt-X_pos]: #light grey columns self.styles.append(('BACKGROUND', (cpt,Y_pos), (cpt,-1), "#dddddd")) cpt+= 1 #light grid beetween self.styles.append(('INNERGRID', (X_pos,Y_pos), (-1,Y_pos), 0.2, "#bbbbbb")) #line that separate the dates and the datas self.styles.append(('LINEBELOW', (0, Y_pos), (-1,Y_pos), 1, colors.black))
def get_content(self, column_data, row_values, col_values): """ return the content formated as defined in the constructor or in the column object """ value = self.value if value == None or value == False: return "" #should we trunc the text if self.truncate_length != None: value = c2c_helper.ellipsis(value, self.truncate_length, ellipsis="[...]") ps = ParagraphStyle('standard_text') ps.fontName = self.get_font(column_data) ps.fontSize = self.get_font_size(column_data) ps.alignment = self.get_align_code(column_data) #should we indent the content if self.indent != None: ps.leftIndent = self.indent * 2 * mm elif type(column_data) == TextColData and column_data.indent != None: ps.leftIndent = column_data.indent * 2 * mm p = Paragraph(c2c_helper.encode_entities(value), ps) return p