def _draw_labels(self, cur_drawing, left_labels, right_labels): """Layout and draw sub-feature labels for the chromosome. Tries to place each label at the same vertical position as the feature it applies to, but will adjust the positions to avoid or at least reduce label overlap. Draws the label text and a coloured line linking it to the location (i.e. feature) it applies to. """ if not self._sub_components: return color_label = self._color_labels segment_width = (self.end_x_position - self.start_x_position) \ * self.chr_percent label_sep = (self.end_x_position - self.start_x_position) \ * self.label_sep_percent segment_x = self.start_x_position \ + 0.5 * (self.end_x_position - self.start_x_position - segment_width) y_limits = [] for sub_component in self._sub_components: y_limits.extend((sub_component.start_y_position, sub_component.end_y_position)) y_min = min(y_limits) y_max = max(y_limits) del y_limits # Now do some label placement magic... # from reportlab.pdfbase import pdfmetrics # font = pdfmetrics.getFont('Helvetica') # h = (font.face.ascent + font.face.descent) * 0.90 h = self.label_size for x1, x2, labels, anchor in [ (segment_x, segment_x - label_sep, _place_labels(left_labels, y_min, y_max, h), "end"), (segment_x + segment_width, segment_x + segment_width + label_sep, _place_labels(right_labels, y_min, y_max, h), "start"), ]: for (y1, y2, color, back_color, name) in labels: cur_drawing.add(Line(x1, y1, x2, y2, strokeColor=color, strokeWidth=0.25)) label_string = String(x2, y2, name, textAnchor=anchor) label_string.fontName = 'Helvetica' label_string.fontSize = h if color_label: label_string.fillColor = color if back_color: w = stringWidth(name, label_string.fontName, label_string.fontSize) if x1 > x2: w = w * -1.0 cur_drawing.add(Rect(x2, y2 - 0.1 * h, w, h, strokeColor=back_color, fillColor=back_color)) cur_drawing.add(label_string)
def _draw_title(self, cur_drawing, title, width, height): """Add a title to the page we are outputting (PRIVATE).""" title_string = String(width / 2, height - inch, title) title_string.fontName = 'Helvetica-Bold' title_string.fontSize = self.title_size title_string.textAnchor = "middle" cur_drawing.add(title_string)
def _draw_title(self, cur_drawing, title, width, height): """Write out the title of the organism figure.""" title_string = String(width / 2, height - inch, title) title_string.fontName = 'Helvetica-Bold' title_string.fontSize = self.title_size title_string.textAnchor = "middle" cur_drawing.add(title_string)
def _draw_title(self, cur_drawing, title, width, height): """Add the title of the figure to the drawing (PRIVATE).""" title_string = String(width / 2, height - inch, title) title_string.fontName = "Helvetica-Bold" title_string.fontSize = self.title_size title_string.textAnchor = "middle" cur_drawing.add(title_string)
def _draw_title(self, cur_drawing, title, start_x, start_y, end_x, end_y): """Add the title of the figure to the drawing (PRIVATE).""" x_center = start_x + (end_x - start_x) / 2 y_pos = end_y + (self.padding_percent * (start_y - end_y)) / 2 title_string = String(x_center, y_pos, title) title_string.fontName = "Helvetica-Bold" title_string.fontSize = self.chart_title_size title_string.textAnchor = "middle" cur_drawing.add(title_string)
def _rawDraw(self): _text = self._text self._text = _text or "" self.computeSize() self._text = _text g = Group() g.translate(self.x + self.dx, self.y + self.dy) g.rotate(self.angle) y = self._top - self._leading * self._baselineRatio textAnchor = self._getTextAnchor() if textAnchor == "start": x = self._left elif textAnchor == "middle": x = self._left + self._ewidth * 0.5 else: x = self._right # paint box behind text just in case they # fill it if self.boxFillColor or (self.boxStrokeColor and self.boxStrokeWidth): g.add( Rect( self._left - self.leftPadding, self._bottom - self.bottomPadding, self._width, self._height, strokeColor=self.boxStrokeColor, strokeWidth=self.boxStrokeWidth, fillColor=self.boxFillColor, ) ) fillColor, fontName, fontSize = self.fillColor, self.fontName, self.fontSize strokeColor, strokeWidth, leading = self.strokeColor, self.strokeWidth, self._leading svgAttrs = getattr(self, "_svgAttrs", {}) if strokeColor: for line in self._lines: s = _text2Path(line, x, y, fontName, fontSize, textAnchor) s.fillColor = fillColor s.strokeColor = strokeColor s.strokeWidth = strokeWidth g.add(s) y -= leading else: for line in self._lines: s = String(x, y, line, _svgAttrs=svgAttrs) s.textAnchor = textAnchor s.fontName = fontName s.fontSize = fontSize s.fillColor = fillColor g.add(s) y -= leading return g
def _draw_label(self, cur_drawing, label_name): """Draw a label for the chromosome.""" x_position = 0.5 * (self.start_x_position + self.end_x_position) y_position = self.end_y_position label_string = String(x_position, y_position, label_name) label_string.fontName = 'Times-BoldItalic' label_string.fontSize = self.title_size label_string.textAnchor = 'middle' cur_drawing.add(label_string)
def _draw_label(self, cur_drawing, label_name): """Draw a label for the chromosome. """ x_position = self.start_x_position y_position = self.end_y_position label_string = String(x_position, y_position, label_name) label_string.fontName = "Times-BoldItalic" label_string.fontSize = self.title_size label_string.textAnchor = "start" cur_drawing.add(label_string)
def draw(self): _text = self._text self._text = _text or '' self.computeSize() self._text = _text g = Group() g.translate(self.x + self.dx, self.y + self.dy) g.rotate(self.angle) y = self._top - self.fontSize textAnchor = self._getTextAnchor() if textAnchor == 'start': x = self._left elif textAnchor == 'middle': x = self._left + self._ewidth * 0.5 else: x = self._right # paint box behind text just in case they # fill it if self.boxFillColor or (self.boxStrokeColor and self.boxStrokeWidth): g.add( Rect( self._left - self.leftPadding, self._bottom - self.bottomPadding, self._width, self._height, strokeColor=self.boxStrokeColor, strokeWidth=self.boxStrokeWidth, fillColor=self.boxFillColor)) fillColor, fontName, fontSize = self.fillColor, self.fontName, self.fontSize strokeColor, strokeWidth, leading = self.strokeColor, self.strokeWidth, ( self.leading or 1.2 * fontSize) if strokeColor: for line in self._lines: s = _text2Path(line, x, y, fontName, fontSize, textAnchor) s.fillColor = fillColor s.strokeColor = strokeColor s.strokeWidth = strokeWidth g.add(s) y = y - leading else: for line in self._lines: s = String(x, y, line) s.textAnchor = textAnchor s.fontName = fontName s.fontSize = fontSize s.fillColor = fillColor g.add(s) y = y - leading return g
def _draw_label(self, cur_drawing): """Add a label to the chromosome segment. """ # the label will be applied to the right of the segment if self.label is not None: label_x = self.start_x_position + (self.chr_percent + 0.05) * (self.end_x_position - self.start_x_position) label_y = (self.start_y_position - self.end_y_position) / 2 + self.end_y_position label_string = String(label_x, label_y, self.label) label_string.fontName = "Helvetica" label_string.fontSize = self.label_size cur_drawing.add(label_string)
def _draw_label(self, cur_drawing): """Add a label to the chromosome segment. The label will be applied to the right of the segment. This may be overlapped by any sub-feature labels on other segments! """ if self.label is not None: label_x = 0.5 * (self.start_x_position + self.end_x_position) + \ (self.chr_percent + 0.05) * (self.end_x_position - self.start_x_position) label_y = ((self.start_y_position - self.end_y_position) / 2 + self.end_y_position) label_string = String(label_x, label_y, self.label) label_string.fontName = 'Helvetica' label_string.fontSize = self.label_size cur_drawing.add(label_string)
def makeSectors(self): # normalize slice data if type(self.data) in (ListType, TupleType) and type(self.data[0]) in (ListType, TupleType): # it's a nested list, more than one sequence normData = [] n = [] for l in self.data: t = self.normalizeData(l) normData.append(t) n.append(len(t)) else: normData = self.normalizeData(self.data) n = len(normData) # labels if self.labels is None: labels = [] if type(n) not in (ListType, TupleType): labels = [""] * n else: for m in n: labels = list(labels) + [""] * m else: labels = self.labels # there's no point in raising errors for less than enough errors if # we silently create all for the extreme case of no labels. if type(n) not in (ListType, TupleType): i = n - len(labels) if i > 0: labels = list(labels) + [""] * i else: tlab = 0 for m in n: tlab = tlab + m i = tlab - len(labels) if i > 0: labels = list(labels) + [""] * i xradius = self.width / 2.0 yradius = self.height / 2.0 centerx = self.x + xradius centery = self.y + yradius if self.direction == "anticlockwise": whichWay = 1 else: whichWay = -1 g = Group() i = 0 sn = 0 startAngle = self.startAngle #% 360 if type(self.data[0]) in (ListType, TupleType): # multi-series doughnut styleCount = len(self.slices) iradius = (self.height / 5.0) / len(self.data) for series in normData: for angle in series: endAngle = startAngle + (angle * whichWay) #% 360 if abs(startAngle - endAngle) >= 1e-5: if startAngle < endAngle: a1 = startAngle a2 = endAngle else: a1 = endAngle a2 = startAngle # if we didn't use %stylecount here we'd end up with the later sectors # all having the default style sectorStyle = self.slices[i % styleCount] # is it a popout? cx, cy = centerx, centery if sectorStyle.popout != 0: # pop out the sector averageAngle = (a1 + a2) / 2.0 aveAngleRadians = averageAngle * pi / 180.0 popdistance = sectorStyle.popout cx = centerx + popdistance * cos(aveAngleRadians) cy = centery + popdistance * sin(aveAngleRadians) if type(n) in (ListType, TupleType): theSector = Wedge( cx, cy, xradius + (sn * iradius) - iradius, a1, a2, yradius=yradius + (sn * iradius) - iradius, radius1=yradius + (sn * iradius) - (2 * iradius), ) else: theSector = Wedge(cx, cy, xradius, a1, a2, yradius=yradius, radius1=iradius) theSector.fillColor = sectorStyle.fillColor theSector.strokeColor = sectorStyle.strokeColor theSector.strokeWidth = sectorStyle.strokeWidth theSector.strokeDashArray = sectorStyle.strokeDashArray g.add(theSector) startAngle = endAngle if labels[i] != "": averageAngle = (a1 + a2) / 2.0 aveAngleRadians = averageAngle * pi / 180.0 labelRadius = sectorStyle.labelRadius labelX = centerx + (0.5 * self.width * cos(aveAngleRadians) * labelRadius) labelY = centery + (0.5 * self.height * sin(aveAngleRadians) * labelRadius) theLabel = String(labelX, labelY, labels[i]) theLabel.textAnchor = "middle" theLabel.fontSize = sectorStyle.fontSize theLabel.fontName = sectorStyle.fontName theLabel.fillColor = sectorStyle.fontColor g.add(theLabel) i = i + 1 sn = sn + 1 else: # single series doughnut styleCount = len(self.slices) iradius = self.height / 5.0 for angle in normData: endAngle = startAngle + (angle * whichWay) #% 360 if abs(startAngle - endAngle) >= 1e-5: if startAngle < endAngle: a1 = startAngle a2 = endAngle else: a1 = endAngle a2 = startAngle # if we didn't use %stylecount here we'd end up with the later sectors # all having the default style sectorStyle = self.slices[i % styleCount] # is it a popout? cx, cy = centerx, centery if sectorStyle.popout != 0: # pop out the sector averageAngle = (a1 + a2) / 2.0 aveAngleRadians = averageAngle * pi / 180.0 popdistance = sectorStyle.popout cx = centerx + popdistance * cos(aveAngleRadians) cy = centery + popdistance * sin(aveAngleRadians) if n > 1: theSector = Wedge(cx, cy, xradius, a1, a2, yradius=yradius, radius1=iradius) elif n == 1: theSector = Wedge(cx, cy, xradius, a1, a2, yradius=yradius, iradius=iradius) theSector.fillColor = sectorStyle.fillColor theSector.strokeColor = sectorStyle.strokeColor theSector.strokeWidth = sectorStyle.strokeWidth theSector.strokeDashArray = sectorStyle.strokeDashArray g.add(theSector) # now draw a label if labels[i] != "": averageAngle = (a1 + a2) / 2.0 aveAngleRadians = averageAngle * pi / 180.0 labelRadius = sectorStyle.labelRadius labelX = centerx + (0.5 * self.width * cos(aveAngleRadians) * labelRadius) labelY = centery + (0.5 * self.height * sin(aveAngleRadians) * labelRadius) theLabel = String(labelX, labelY, labels[i]) theLabel.textAnchor = "middle" theLabel.fontSize = sectorStyle.fontSize theLabel.fontName = sectorStyle.fontName theLabel.fillColor = sectorStyle.fontColor g.add(theLabel) startAngle = endAngle i = i + 1 return g
# -*- coding: UTF-8 -*- __author__ = 'mcxiaoke' from reportlab.graphics.shapes import Drawing, String from reportlab.graphics import renderPDF d = Drawing(200, 200) s = String(100, 100, 'Hello, World!', textAnchor='middle') d.add(s) renderPDF.drawToFile(d, 'hello.pdf', 'A Simple PDF file')
def __init__(self, barcode_value, width=200, height=320, fontSize=30): barcode = BarcodeGen(barcode_value) barcode.translate((width-barcode.width)/2, 0) Drawing.__init__(self, width, height) self.add(barcode, name='barcode') box = Box.objects.get(barcode=barcode_value) box_category = String(10, 275, box.box_category.letter) box_category.fontSize = 55 box_id = String(10, 230, box.box_id) box_id.fontSize = 55 expiration = String(12, 195, "Exp: " + box.get_printable_expiration()) expiration.fontSize = 30 category = String(12, 165, box.box_category.name) category.fontSize = 15 weight = String(12, 150, "Weight: " + "%.1f" % box.weight + ' lbs.') weight.fontSize = 15 contents = String(12, 135, "Contents:") contents.fontSize = 15 count = 120 for content in box.contents_set.all(): item = String(17, count, content.item.name) item.fontSize = 15 self.add(item, "item") count = count - 15 self.add(box_category, "box_category") self.add(box_id, "boxId") self.add(category, "category") self.add(expiration, "expiration") self.add(weight, "weight") self.add(contents, name="contents_of_box")
def draw(self): g = Group() #box g.add(Rect(self.x,self.y,len(self.xlabels)*self.gridDivWidth,len(self.ylabels)*self.gridDivWidth, strokeColor=self.gridColor, strokeWidth=self.strokeWidth, fillColor=None)) #internal gridding for f in range (1,len(self.ylabels)): #horizontal g.add(Line(strokeColor=self.gridColor, strokeWidth=self.strokeWidth, x1 = self.x, y1 = self.y+f*self.gridDivWidth, x2 = self.x+len(self.xlabels)*self.gridDivWidth, y2 = self.y+f*self.gridDivWidth)) for f in range (1,len(self.xlabels)): #vertical g.add(Line(strokeColor=self.gridColor, strokeWidth=self.strokeWidth, x1 = self.x+f*self.gridDivWidth, y1 = self.y, x2 = self.x+f*self.gridDivWidth, y2 = self.y+len(self.ylabels)*self.gridDivWidth)) # draw the 'dot' g.add(Circle(strokeColor=self.gridColor, strokeWidth=self.strokeWidth, fillColor=self.dotColor, cx = self.x+(self.dotXPosition*self.gridDivWidth), cy = self.y+(self.dotYPosition*self.gridDivWidth), r = self.dotDiameter/2.0)) #used for centering y-labels (below) ascent=getFont(self.labelFontName).face.ascent if ascent==0: ascent=0.718 # default (from helvetica) ascent=ascent*self.labelFontSize # normalize #do y-labels if self.ylabels != None: for f in range (len(self.ylabels)-1,-1,-1): if self.ylabels[f]!= None: g.add(String(strokeColor=self.gridColor, text = self.ylabels[f], fontName = self.labelFontName, fontSize = self.labelFontSize, fillColor=_PCMYK_black, x = self.x-self.labelOffset, y = self.y+(f*self.gridDivWidth+(self.gridDivWidth-ascent)/2.0), textAnchor = 'end')) #do x-labels if self.xlabels != None: for f in range (0,len(self.xlabels)): if self.xlabels[f]!= None: l=Label() l.x=self.x+(f*self.gridDivWidth)+(self.gridDivWidth+ascent)/2.0 l.y=self.y+(len(self.ylabels)*self.gridDivWidth)+self.labelOffset l.angle=90 l.textAnchor='start' l.fontName = self.labelFontName l.fontSize = self.labelFontSize l.fillColor = _PCMYK_black l.setText(self.xlabels[f]) l.boxAnchor = 'sw' l.draw() g.add(l) return g
# coding=utf-8 from reportlab.graphics.shapes import Drawing, String from reportlab.graphics import renderPDF d = Drawing(100, 100) # 创建一个自动尺寸的Drawing对象 s = String(x=50, y=50, text='Hello, world!', textAnchor='middle') # 创建指定属性的图形元素 d.add(s) # 添加图形元素到Drawing对象 renderPDF.drawToFile(d, 'hello.pdf', 'A simple PDF file') # 以PDF格式渲染Drawing对象,并将结果保存到文件 # ### ReportLab # HomePage: https://www.reportlab.com/ # Documentation: https://www.reportlab.com/documentation/ # 可以创建多种格式的图表文档,功能强大易于使用;
def getTempPlot(): drawing = Drawing(400, 200) temps = [getTemps()] bc = LinePlot() bc.x = 50 bc.y = 50 bc.height = 125 bc.width = 300 bc.data = temps bc.lines[0].symbol = makeMarker('Circle') #labels yilabel = Label() yilabel.setText("Temperatura (°C)") yilabel.angle = 90 yilabel.setOrigin(20, 120) xlabel = Label() xlabel.setText("Días") xlabel.setOrigin(200, 20) #labelT = Label() #labelT.setText("Temperatura") #labelT.setOrigin(210,185) #labelH = Label() #labelH.setText("Humedad") #labelH.setOrigin(285,185) label55 = Label() label55.setText("55°") label55.setOrigin(325, 185) bc.xValueAxis.valueMin = 0 bc.xValueAxis.valueMax = 30 bc.xValueAxis.valueSteps = [x for x in range(0, bc.xValueAxis.valueMax, 5)] #bc.xValueAxis.labelTextFormat = '%2.1f' bc.yValueAxis.valueMin = 0 bc.yValueAxis.valueMax = 80 bc.yValueAxis.valueSteps = [0, 10, 20, 30, 40, 50, 60, 70, 80] drawing.add(bc) drawing.add(yilabel) drawing.add(xlabel) #drawing.add(Line(170,185,185,185, strokeColor=colors.red)) #drawing.add(Line(250,185,265,185, strokeColor=colors.blue)) drawing.add( Line(300, 185, 315, 185, strokeColor=colors.black, strokeDashArray=[2, 2])) drawing.add( Line(50, 135, 350, 135, strokeColor=colors.black, strokeDashArray=[2, 2])) #drawing.add(labelT) #drawing.add(labelH) drawing.add(label55) #drawing.add(Grid()) drawing.add(String(130, 200, "Gráfico de temperaturas", fontSize=16)) return drawing
def __init__(self, width=400, height=200, *args, **kw): Drawing.__init__(self, width, height, *args, **kw) self.transform = (1, 0, 0, 1, 0, 0) self.add( Wedge(175, 100, 50, -127.3684, -95, yradius=50, annular=False, fillColor=Color(.27451, .509804, .705882, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -143.1579, -127.3684, yradius=50, annular=False, fillColor=Color(.847059, .74902, .847059, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -174.7368, -143.1579, yradius=50, annular=False, fillColor=Color(.392157, .584314, .929412, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -186.5789, -174.7368, yradius=50, annular=False, fillColor=Color(.690196, .768627, .870588, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -202.3684, -186.5789, yradius=50, annular=False, fillColor=Color(.498039, 1, .831373, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -226.0526, -202.3684, yradius=50, annular=False, fillColor=Color(.372549, .619608, .627451, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -265.5263, -226.0526, yradius=50, annular=False, fillColor=Color(1, 1, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -277.3684, -265.5263, yradius=50, annular=False, fillColor=Color(.27451, .509804, .705882, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -297.1053, -277.3684, yradius=50, annular=False, fillColor=Color(.847059, .74902, .847059, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -324.7368, -297.1053, yradius=50, annular=False, fillColor=Color(.392157, .584314, .929412, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -344.4737, -324.7368, yradius=50, annular=False, fillColor=Color(.690196, .768627, .870588, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -360.2632, -344.4737, yradius=50, annular=False, fillColor=Color(.498039, 1, .831373, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -383.9474, -360.2632, yradius=50, annular=False, fillColor=Color(.372549, .619608, .627451, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -415.5263, -383.9474, yradius=50, annular=False, fillColor=Color(1, 1, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -431.3158, -415.5263, yradius=50, annular=False, fillColor=Color(.27451, .509804, .705882, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Wedge(175, 100, 50, -455, -431.3158, yradius=50, annular=False, fillColor=Color(.847059, .74902, .847059, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=1, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( String(115, 44.05459, 'example1', textAnchor='end', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(115, 57.7689, 'example2', textAnchor='end', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(115, 78.44648, 'example3', textAnchor='end', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(115, 100.6889, 'example4', textAnchor='end', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(115, 114.9961, 'example5', textAnchor='end', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(115, 133.7341, 'example6', textAnchor='end', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(115, 154.7227, 'example7', textAnchor='end', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 165.9809, 'example8', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 157.3053, 'example9', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 145.3368, 'example10', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 125.7311, 'example11', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 107.9682, 'example12', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 87.4175, 'example13', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 61.64425, 'example14', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 52.34088, 'example15', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( String(235, 40.42731, 'example16', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( Line(156.9316, 53.37883, 135.9658, 47.05459, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(135.9658, 47.05459, 115, 47.05459, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(139.4826, 64.80742, 127.2413, 60.7689, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(127.2413, 60.7689, 115, 60.7689, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(128.3375, 82.03873, 121.6687, 81.44648, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(121.6687, 81.44648, 115, 81.44648, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(125.0033, 100.5741, 120.0016, 103.6889, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(120.0016, 103.6889, 115, 103.6889, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(126.5869, 112.4968, 120.7934, 117.9961, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(120.7934, 117.9961, 115, 117.9961, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(133.6511, 128.1118, 124.3256, 136.7341, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(124.3256, 136.7341, 115, 136.7341, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(154.4955, 145.6022, 134.7477, 157.7227, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(134.7477, 157.7227, 115, 157.7227, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(176.2629, 149.984, 205.6315, 168.9809, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(205.6315, 168.9809, 235, 168.9809, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(189.8161, 147.7544, 212.4081, 160.3053, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(212.4081, 160.3053, 235, 160.3053, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(207.7509, 137.7806, 221.3755, 148.3368, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(221.3755, 148.3368, 235, 148.3368, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(220.1687, 121.4426, 227.5844, 128.7311, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(227.5844, 128.7311, 235, 128.7311, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(224.5571, 106.6401, 229.7786, 110.9682, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(229.7786, 110.9682, 235, 110.9682, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(223.8882, 89.51458, 229.4441, 90.4175, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(229.4441, 90.4175, 235, 90.4175, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(213.4494, 68.03688, 224.2247, 64.64425, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(224.2247, 64.64425, 235, 64.64425, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(197.3715, 55.28406, 216.1858, 55.34088, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(216.1858, 55.34088, 235, 55.34088, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(180.9567, 50.35609, 207.9783, 43.42731, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(207.9783, 43.42731, 235, 43.42731, strokeColor=Color(0, 0, 0, 1), strokeWidth=.5, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None))
def __init__(self, width=400, height=200, *args, **kw): Drawing.__init__(self, width, height, *args, **kw) self.transform = (1, 0, 0, 1, 0, 0) self.add( Rect(50, 50, 300, 125, rx=0, ry=0, fillColor=None, fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(75, 50, 100, 7.5, rx=0, ry=0, fillColor=Color(1, 0, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(225, 50, 100, 25, rx=0, ry=0, fillColor=Color(1, 0, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 49, 350, 49, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 49, 50, 44, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(200, 49, 200, 44, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(350, 49, 350, 44, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 125, 44) v0.add( String(-10, -10, 'Ying', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 275, 44) v0.add( String(-10.83, -10, 'Yang', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( Line(50, 50, 50, 175, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 62.5, 45, 62.5, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 100, 45, 100, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 137.5, 45, 137.5, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 175, 45, 175, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 62.5) v0.add( String(-10, -4, '15', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 100) v0.add( String(-10, -4, '30', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 137.5) v0.add( String(-10, -4, '45', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 175) v0.add( String(-10, -4, '60', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1)))
# data = [ # # 其他数据 # (2016, 3, 30.9, 31.9, 29.9) # (2016, 4, 30.5, 32.5, 28.5) # # ] from reportlab.graphics.shapes import Drawing, String from reportlab.graphics import renderPDF d = Drawing(100, 100) s = String(50, 50, 'hello, world', textAnchor='middle') d.add(s) renderPDF.drawToFile(d, 'hello.pdf', 'A simple PDF file')
from reportlab.graphics.shapes import Drawing, String from reportlab.graphics import renderPDF d = Drawing(200, 200) s = String(100, 100, 'Hello, world', textAnchor='middle') d.add(s) renderPDF.drawToFile(d, 'hello.pdf', 'A simple PDF file')
def __init__(self, width=400, height=200, *args, **kw): Drawing.__init__(self, width, height, *args, **kw) self.transform = (1, 0, 0, 1, 0, 0) self.add( Line(50, 50, 350, 50, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 50, 50, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(143.75, 50, 143.75, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(237.5, 50, 237.5, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(331.25, 50, 331.25, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 50, 45) v0.add( String(-5, -10, '10', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 143.75, 45) v0.add( String(-5, -10, '20', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 237.5, 45) v0.add( String(-5, -10, '30', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 331.25, 45) v0.add( String(-5, -10, '40', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( Line(50, 50, 50, 175, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 50, 45, 50, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 81.25, 45, 81.25, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 112.5, 45, 112.5, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 143.75, 45, 143.75, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 175, 45, 175, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 65.625) v0.add( String(-18.88, -4, 'Beer', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 96.875) v0.add( String(-21.66, -4, 'Wine', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 128.125) v0.add( String(-20.55, -4, 'Meat', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 159.375) v0.add( String(-43.89, -4, 'Cannelloni', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1)))
def line_chart(doc, months, portfolioDate, monthlyInv, monthlyVal, Valuation, Investment): drawing = Drawing(doc.width / 2, doc.height / 2 - 80) data = [monthlyInv, monthlyVal] my_title = String(doc.width / 2 - 90, doc.height / 2, 'Performance Chart', fontSize=20) lc = HorizontalLineChart() lc.x = doc.leftMargin + 35 lc.y = doc.bottomMargin lc.height = doc.height / 2 - 60 lc.width = doc.width - 100 lc.data = data lc.joinedLines = 1 catNames = months[portfolioDate.month:] if portfolioDate.month > 1: catNames += months[:portfolioDate.month] lc.categoryAxis.categoryNames = catNames #lc.categoryAxis.labels.boxAnchor = 'autox' lc.valueAxis.valueMin = 0 roundedVal = Valuation if Valuation % 10 == 0 else Valuation + Valuation % 10 lc.valueAxis.valueMax = roundedVal lc.valueAxis.valueStep = int((roundedVal / 10) / 10) * 10 lc.lines[0].strokeWidth = 2 lc.lines[1].strokeWidth = 1.5 lc.lines[0].strokeColor = colors.blue lc.lines[ 1].strokeColor = colors.green if Valuation > Investment else colors.red lc.valueAxis.visibleGrid = 1 lc.valueAxis.gridStrokeColor = colors.lightgrey lc.lines[0].name = 'Investment Value' lc.lines[1].name = 'Closing Valuation' #lc.lineLabelFormat = '%2.0f' labels = ['Investment Value', 'Closing Valuation'] lc._seriesCount = len(labels) drawing.add(my_title) drawing.add(lc) add_legend1(drawing, lc, labels, doc) return drawing ################### Old Function Call Segment####################### # FI=[4531082, 4892169, 206462, 4.56, 45.94] # Equity=[5218922,5362021.34,-62131.35,-1.19,50.36] # Investment=225323 # Valuation=865489 # monthlyInv=[23564,5782,84,79765,3243,65799,43344,5668,43,78900,3456,7543] # monthlyVal=[85265,578954,8656,87533,29754,264256,23244,23435,243234,5767,576854,574321] # equityTrades=[ # ['UBS BANK USA \n DEPOSIT ACCOUNT','IN8543975','Corporate','654','764.7','7643','764.97','245.65','9877','86','','','85.32%','1.69%'] # ] # bondTrades=[ # ['UBS BANK USA \n DEPOSIT ACCOUNT','IN8543975','Corporate','654','764.7','7643','764.97','245.65','9877','86','78','1/12/2021','85.32%','1.69%'] # ,['UBS BANK USA \n DEPOSIT ACCOUNT','IN8543975','Corporate','654','764.7','7643','764.97','245.65','9877','86','78','1/12/2021','85.32%','1.69%'] # ,['UBS BANK USA \n DEPOSIT ACCOUNT','IN8543975','Corporate','654','764.7','7643','764.97','245.65','9877','86','78','1/12/2021','85.32%','1.69%'] # ] # #Page 5 data # net_position=[ # ['Total Portfolio','','','','','','$9,967,814.44','$10,648,193.73','$145,102.43','1.46%','100%','100%'] # ] # generatePDF(FI,Equity,Investment,Valuation,monthlyInv,monthlyVal,equityTrades,bondTrades,net_position) ################### New Function Call Segment####################### # from helper_pdfgen import helperPdfgen , historyHelper , invAndVal # resp = helperPdfgen() # histdata = historyHelper() # FI= resp['FI'] # Equity= resp['Equity'] # iv = invAndVal() # Investment = iv['Investment'] # Valuation = iv['Valuation'] # monthlyInv = histdata['monthlyInv'] # monthlyVal = histdata['monthlyVal'] # labels = histdata['labels'] # equityTrades = resp['equityTrades'] # bondTrades= resp['bondTrades'] # URPL = Valuation - Investment # perURPL = URPL*100 / ( Valuation ) # #Page 5 data # net_position=[ # ['Total Portfolio','','','','','', Investment , Valuation , URPL , perURPL ,'100%','100%'] # ] # generatePDF(FI,Equity,Investment,Valuation,monthlyInv,monthlyVal,equityTrades,bondTrades,net_position,labels)
def generatePDF(FI, Equity, Investment, Valuation, monthlyInv, monthlyVal, equityTrades, bondTrades, net_position, mlabels): logo = 'AIM_logo.jpg' portfolioDate = date.today() months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] portfolioHoldings = [[ '', 'Cost basis($)', 'Value on\n' + str(date.today()), 'Unrealized\ngain/loss($)', 'Unrealized\ngain/loss(%)', '% of\nPortfolio' ], ['Bond'] + FI, ['Equity'] + Equity, ['Total Portfolio'] + [round(a + b, 2) for (a, b) in zip(FI, Equity)]] #Page 4 data equity_data = [[ 'Equity', 'Sector', 'Qty', 'Buy \nAverage($)', 'Previous \nClosing Price($)', 'Holdings buy\nvalue($)', 'Current\n Value($)', 'Unrealized\n gain/loss ($)', 'Unrealized \ngain/loss(%)', '', '', '% of portfolio' ]] + equityTrades bond_data = [[ 'Bond', 'Sector', 'Qty', 'Buy \nAverage($)', 'Previous\nClosing Price($)', 'Holdings buy\nvalue($)', 'Current\nValue($)', 'Unrealized\n gain/loss ($)', 'Unrealized \ngain/loss(%)', 'Accrued\nInterest (%)', 'Maturity\n Date', '% of portfolio' ]] + bondTrades portfolioDetails = equity_data + [[''] * 14] + bond_data netPosition = [[ 'Net Position', '', '', '', '', '', 'Holdings buy\nvalue($)', 'Current\n Value($)', 'Unrealized\n gain/loss ($)', 'Unrealized \ngain/loss(%)', '% of Asset Class', '% of portfolio' ]] + net_position styles = getSampleStyleSheet() styleN = styles['Normal'] styleContent = ParagraphStyle(name='content', parent=styles['Normal'], fontSize=18, leading=35) styleH = styles['Heading1'] style_right = ParagraphStyle(name='right', parent=styles['Heading1'], alignment=TA_RIGHT, fontSize=24) style_center = ParagraphStyle(name='center', parent=styles['Normal'], alignment=TA_CENTER, fontSize=16, leading=35) story = [] doc = SimpleDocTemplate('uploads/portfolio.pdf', pagesize=landscape(A4), rightMargin=30, leftMargin=30, topMargin=30, bottomMargin=30) myFrame = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='myFrame') frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width / 2 - 6, doc.height, id='col1') frame2 = Frame(doc.leftMargin + doc.width / 2 + 6, doc.bottomMargin, doc.width / 2 - 6, doc.height, id='col2') frame3 = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height / 2, id='col3') coverPage = PageTemplate(id='Cover', frames=[myFrame]) threeTemplate = PageTemplate(id='ThreeSec', frames=[frame1, frame2, frame3]) columnTemplate = PageTemplate(id='TwoCol', frames=[frame1, frame2]) #Page 1 story.append(Image(logo, 2 * inch, 2 * inch, hAlign='RIGHT')) story.append(Spacer(0, 10)) story.append(Paragraph("CLIENT PORTFOLIO", style_right)) story.append(HRFlowable(width='100%', thickness=5, color=colors.navy)) story.append(Spacer(0, 15)) story.append( Paragraph( "TABLE OF CONTENTS", ParagraphStyle(name='content', parent=styles['Normal'], fontSize=18, leading=35))) story.append(Paragraph("Investment Value" + "." * 104 + "1", styleN)) story.append(Spacer(0, 15)) story.append(Paragraph("Portfolio Holdings" + "." * 103 + "2", styleN)) story.append(Spacer(0, 15)) story.append(Paragraph("Net Position" + "." * 112 + "3", styleN)) story.append(Spacer(0, 15)) story.append(NextPageTemplate('ThreeSec')) story.append(PageBreak()) #Page 2 story.append(Paragraph("Investment Value", styleH)) story.append(Paragraph("As of " + str(portfolioDate), styleContent)) #Frame1 draw = Drawing(200, 150) rect = Rect(doc.width / 4, 100, 120, 50) rect.fillColor = colors.lightcoral draw.add(rect) my_title = String(doc.width / 4 + 6, 135, 'Total Investment', fontSize=16) my_title.fillColor = colors.white draw.add(my_title) my_title = String(doc.width / 4 + 15, 110, '$' + str(Investment), fontSize=20) my_title.fillColor = colors.white draw.add(my_title) story.append(draw) story.append(FrameBreak()) #Frame 2 story.append(Spacer(0, 75)) draw = Drawing(200, 150) rect = Rect(40, 112, 120, 50) rect.fillColor = colors.orange draw.add(rect) my_title = String(41, 145, 'Current Valuation', fontSize=16) my_title.fillColor = colors.white draw.add(my_title) my_title = String(55, 122, '$' + str(Valuation), fontSize=20) my_title.fillColor = colors.white draw.add(my_title) story.append(draw) story.append(FrameBreak()) #Frame 3 lineChart = line_chart(doc, months, portfolioDate, monthlyInv, monthlyVal, Valuation, Investment) story.append(lineChart) story.append(NextPageTemplate('TwoCol')) story.append(PageBreak()) # Page 3 story.append(Paragraph("Portfolio Holdings", styleH)) story.append(Paragraph("As of " + str(portfolioDate), styleContent)) story.append(Spacer(0, 100)) story.append(Paragraph("Summary of Portfolio Holdings", style_center)) style = TableStyle([('BACKGROUND', (0, -1), (-1, -1), colors.whitesmoke), ('ALIGN', (1, 0), (-1, -1), 'CENTER'), ('FONTSIZE', (0, 0), (-1, -1), 8), ('BODYTEXT', (0, 0), (-1, -1), 'TEXTWRAP'), ('LINEABOVE', (0, 0), (-1, 1), 1, colors.black)]) table1 = Table(portfolioHoldings) table1.setStyle(style) story.append(table1) story.append(FrameBreak()) #Frame2 chart = pie_chart_with_legend(doc, FI, Equity) story.append(chart) #Page 4 story.append(PageBreak()) story.append(Paragraph("Details of portfolio holdings", styleH)) story.append(Paragraph("As of " + str(portfolioDate), styleContent)) story.append(Spacer(0, 5)) #style=[('BACKGROUND', (0,1), (-1,1), colors.whitesmoke),('ALIGN',(1,0),(-1,-1),'CENTER'),('FONTSIZE',(0,0),(-1,-1),8),('BODYTEXT',(0,0),(-1,-1),'TEXTWRAP'),('FONTNAME', (0,2), (-1,2), 'Helvetica-Bold')] style2 = [('ALIGN', (1, 0), (-1, -1), 'CENTER'), ('FONTSIZE', (0, 0), (-1, -1), 8), ('BODYTEXT', (0, 0), (-1, -1), 'TEXTWRAP'), ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'), ('LINEABOVE', (0, 0), (-1, 1), 1, colors.black)] style = [('ALIGN', (1, 0), (-1, -1), 'CENTER'), ('FONTSIZE', (0, 0), (-1, -1), 8), ('BODYTEXT', (0, 0), (-1, -1), 'TEXTWRAP'), ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'), ('LINEABOVE', (0, 0), (-1, 1), 1, colors.black), ('BOX', (0, 0), (-1, -1), 0.25, colors.black)] data_len = len(equity_data) for each in range(3, data_len): bg_color = colors.white if each % 2 == 0: bg_color = colors.whitesmoke #style.append(('BACKGROUND', (0,each), (-1,each), bg_color)) style2.append( ('FONTNAME', (0, data_len + 1), (-1, data_len + 1), 'Helvetica-Bold')) style2.append( ('LINEABOVE', (0, data_len + 1), (-1, data_len + 2), 1, colors.black)) table = Table(portfolioDetails) table.setStyle(TableStyle(style2)) story.append(table) story.append(Spacer(0, 5)) #table=Table(bond_data) #table.setStyle(TableStyle(style2)) #story.append(table) #page 5 #story.append(PageBreak()) story.append(Paragraph("Net Position", styleH)) story.append(Paragraph("As of " + str(portfolioDate), styleContent)) story.append(Spacer(0, 20)) story.append(HRFlowable(width='100%', thickness=1, color=colors.black)) story.append(Spacer(0, 20)) table1 = Table(netPosition) table1.setStyle(style) story.append(table1) doc.addPageTemplates([ coverPage, threeTemplate, columnTemplate, ]) doc.build(story)
def __init__(self,width=400,height=200,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self.transform = (1,0,0,1,0,0) self.add(Rect(50,50,300,125,rx=0,ry=0,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[68.75,77.08333,106.25,60.41667,143.75,91.66667,181.25,95.83333,218.75,127.0833,256.25,143.75,293.75,89.58333,331.25,58.33333],strokeColor=Color(1,0,0,1),strokeWidth=2,strokeLineCap=0,strokeLineJoin=1,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[68.75,60.41667,106.25,91.66667,143.75,145.8333,181.25,129.1667,218.75,97.91667,256.25,93.75,293.75,62.5,331.25,79.16667],strokeColor=Color(0,.501961,0,1),strokeWidth=4,strokeLineCap=0,strokeLineJoin=1,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) v0=self._nn(Group()) v0.transform = (1,0,0,1,68.75,87.08333) v0.add(String(-5,-4,'13',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,106.25,70.41667) v0.add(String(-3.75,-4,' 5',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,143.75,101.6667) v0.add(String(-5,-4,'20',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,181.25,105.8333) v0.add(String(-5,-4,'22',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,218.75,137.0833) v0.add(String(-5,-4,'37',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,256.25,153.75) v0.add(String(-5,-4,'45',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,293.75,99.58333) v0.add(String(-5,-4,'19',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,331.25,68.33333) v0.add(String(-3.75,-4,' 4',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(Circle(68.75,60.41667,5,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(68.75,60.41667,4.8,fillColor=Color(1,.270588,0,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(64.75,59.41667,8,2,rx=0,ry=0,fillColor=Color(.972549,.972549,1,1),fillOpacity=None,strokeColor=Color(.972549,.972549,1,1),strokeWidth=0,strokeLineCap=1,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(106.25,91.66667,5,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(106.25,91.66667,4.8,fillColor=Color(1,.270588,0,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(102.25,90.66667,8,2,rx=0,ry=0,fillColor=Color(.972549,.972549,1,1),fillOpacity=None,strokeColor=Color(.972549,.972549,1,1),strokeWidth=0,strokeLineCap=1,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(143.75,145.8333,5,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(143.75,145.8333,4.8,fillColor=Color(1,.270588,0,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(139.75,144.8333,8,2,rx=0,ry=0,fillColor=Color(.972549,.972549,1,1),fillOpacity=None,strokeColor=Color(.972549,.972549,1,1),strokeWidth=0,strokeLineCap=1,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(181.25,129.1667,5,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(181.25,129.1667,4.8,fillColor=Color(1,.270588,0,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(177.25,128.1667,8,2,rx=0,ry=0,fillColor=Color(.972549,.972549,1,1),fillOpacity=None,strokeColor=Color(.972549,.972549,1,1),strokeWidth=0,strokeLineCap=1,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(218.75,97.91667,5,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(218.75,97.91667,4.8,fillColor=Color(1,.270588,0,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(214.75,96.91667,8,2,rx=0,ry=0,fillColor=Color(.972549,.972549,1,1),fillOpacity=None,strokeColor=Color(.972549,.972549,1,1),strokeWidth=0,strokeLineCap=1,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(256.25,93.75,5,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(256.25,93.75,4.8,fillColor=Color(1,.270588,0,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(252.25,92.75,8,2,rx=0,ry=0,fillColor=Color(.972549,.972549,1,1),fillOpacity=None,strokeColor=Color(.972549,.972549,1,1),strokeWidth=0,strokeLineCap=1,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(293.75,62.5,5,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(293.75,62.5,4.8,fillColor=Color(1,.270588,0,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(289.75,61.5,8,2,rx=0,ry=0,fillColor=Color(.972549,.972549,1,1),fillOpacity=None,strokeColor=Color(.972549,.972549,1,1),strokeWidth=0,strokeLineCap=1,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(331.25,79.16667,5,fillColor=None,fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Circle(331.25,79.16667,4.8,fillColor=Color(1,.270588,0,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(327.25,78.16667,8,2,rx=0,ry=0,fillColor=Color(.972549,.972549,1,1),fillOpacity=None,strokeColor=Color(.972549,.972549,1,1),strokeWidth=0,strokeLineCap=1,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) v0=self._nn(Group()) v0.transform = (1,0,0,1,68.75,70.41667) v0.add(String(-3.75,-4,' 5',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,106.25,101.6667) v0.add(String(-5,-4,'20',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,143.75,155.8333) v0.add(String(-5,-4,'46',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,181.25,139.1667) v0.add(String(-5,-4,'38',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,218.75,107.9167) v0.add(String(-5,-4,'23',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,256.25,103.75) v0.add(String(-5,-4,'21',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,293.75,72.5) v0.add(String(-3.75,-4,' 6',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,331.25,89.16667) v0.add(String(-5,-4,'14',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(Circle(68.75,77.08333,2.5,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(67.91667,77.91667,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(69.58333,77.91667,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[67.18385,76.5133,67.19403,76.48605,67.20469,76.45899,67.21583,76.43211,67.22742,76.40544,67.23949,76.37897,67.25201,76.35271,67.26499,76.32668,67.27842,76.30088,67.2923,76.27532,67.30662,76.25,67.32139,76.22494,67.33659,76.20013,67.35222,76.1756,67.36827,76.15135,67.38475,76.12737,67.40164,76.10369,67.41894,76.08031,67.43665,76.05723,67.45476,76.03447,67.47326,76.01202,67.49215,75.9899,67.51143,75.96812,67.53108,75.94667,67.5511,75.92557,67.57149,75.90482,67.59224,75.88443,67.61334,75.86441,67.63478,75.84476,67.65657,75.82548,67.67869,75.80659,67.70113,75.78809,67.7239,75.76998,67.74697,75.75227,67.77036,75.73497,67.79404,75.71808,67.81801,75.7016,67.84227,75.68555,67.8668,75.66992,67.8916,75.65472,67.91667,75.63996,67.94198,75.62563,67.96755,75.61175,67.99335,75.59832,68.01938,75.58534,68.04564,75.57282,68.07211,75.56076,68.09878,75.54916,68.12566,75.53803,68.15272,75.52737,68.17997,75.51718,68.20739,75.50747,68.23497,75.49824,68.26271,75.48949,68.2906,75.48123,68.31863,75.47346,68.3468,75.46617,68.37508,75.45938,68.40348,75.45309,68.43199,75.44729,68.46059,75.44199,68.48928,75.43719,68.51804,75.43289,68.54688,75.42909,68.57579,75.4258,68.60474,75.42301,68.63374,75.42073,68.66277,75.41895,68.69183,75.41768,68.72091,75.41692,68.75,75.41667,68.77909,75.41692,68.80817,75.41768,68.83723,75.41895,68.86626,75.42073,68.89526,75.42301,68.92421,75.4258,68.95312,75.42909,68.98196,75.43289,69.01072,75.43719,69.03941,75.44199,69.06801,75.44729,69.09652,75.45309,69.12492,75.45938,69.1532,75.46617,69.18137,75.47346,69.2094,75.48123,69.23729,75.48949,69.26503,75.49824,69.29261,75.50747,69.32003,75.51718,69.34728,75.52737,69.37434,75.53803,69.40122,75.54916,69.42789,75.56076,69.45436,75.57282,69.48062,75.58534,69.50665,75.59832,69.53245,75.61175,69.55802,75.62563,69.58333,75.63996,69.6084,75.65472,69.6332,75.66992,69.65773,75.68555,69.68199,75.7016,69.70596,75.71808,69.72964,75.73497,69.75303,75.75227,69.7761,75.76998,69.79887,75.78809,69.82131,75.80659,69.84343,75.82548,69.86522,75.84476,69.88666,75.86441,69.90776,75.88443,69.92851,75.90482,69.9489,75.92557,69.96892,75.94667,69.98857,75.96812,70.00785,75.9899,70.02674,76.01202,70.04524,76.03447,70.06335,76.05723,70.08106,76.08031,70.09836,76.10369,70.11525,76.12737,70.13173,76.15135,70.14778,76.1756,70.16341,76.20013,70.17861,76.22494,70.19338,76.25,70.2077,76.27532,70.22158,76.30088,70.23501,76.32668,70.24799,76.35271,70.26051,76.37897,70.27258,76.40544,70.28417,76.43211,70.29531,76.45899,70.30597,76.48605,70.31615,76.5133],strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None,fillColor=Color(0,0,0,1))) self.add(Circle(106.25,60.41667,2.5,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(105.4167,61.25,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(107.0833,61.25,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[104.6838,59.84663,104.694,59.81939,104.7047,59.79232,104.7158,59.76545,104.7274,59.73877,104.7395,59.7123,104.752,59.68605,104.765,59.66002,104.7784,59.63421,104.7923,59.60865,104.8066,59.58333,104.8214,59.55827,104.8366,59.53347,104.8522,59.50893,104.8683,59.48468,104.8847,59.46071,104.9016,59.43702,104.9189,59.41364,104.9366,59.39056,104.9548,59.3678,104.9733,59.34535,104.9922,59.32323,105.0114,59.30145,105.0311,59.28,105.0511,59.2589,105.0715,59.23816,105.0922,59.21777,105.1133,59.19774,105.1348,59.17809,105.1566,59.15882,105.1787,59.13993,105.2011,59.12142,105.2239,59.10332,105.247,59.08561,105.2704,59.06831,105.294,59.05141,105.318,59.03494,105.3423,59.01888,105.3668,59.00325,105.3916,58.98805,105.4167,58.97329,105.442,58.95897,105.4675,58.94509,105.4933,58.93166,105.5194,58.91868,105.5456,58.90615,105.5721,58.89409,105.5988,58.88249,105.6257,58.87136,105.6527,58.8607,105.68,58.85051,105.7074,58.8408,105.735,58.83157,105.7627,58.82283,105.7906,58.81456,105.8186,58.80679,105.8468,58.79951,105.8751,58.79272,105.9035,58.78642,105.932,58.78062,105.9606,58.77532,105.9893,58.77052,106.018,58.76622,106.0469,58.76242,106.0758,58.75913,106.1047,58.75634,106.1337,58.75406,106.1628,58.75228,106.1918,58.75102,106.2209,58.75025,106.25,58.75,106.2791,58.75025,106.3082,58.75102,106.3372,58.75228,106.3663,58.75406,106.3953,58.75634,106.4242,58.75913,106.4531,58.76242,106.482,58.76622,106.5107,58.77052,106.5394,58.77532,106.568,58.78062,106.5965,58.78642,106.6249,58.79272,106.6532,58.79951,106.6814,58.80679,106.7094,58.81456,106.7373,58.82283,106.765,58.83157,106.7926,58.8408,106.82,58.85051,106.8473,58.8607,106.8743,58.87136,106.9012,58.88249,106.9279,58.89409,106.9544,58.90615,106.9806,58.91868,107.0067,58.93166,107.0325,58.94509,107.058,58.95897,107.0833,58.97329,107.1084,58.98805,107.1332,59.00325,107.1577,59.01888,107.182,59.03494,107.206,59.05141,107.2296,59.06831,107.253,59.08561,107.2761,59.10332,107.2989,59.12142,107.3213,59.13993,107.3434,59.15882,107.3652,59.17809,107.3867,59.19774,107.4078,59.21777,107.4285,59.23816,107.4489,59.2589,107.4689,59.28,107.4886,59.30145,107.5078,59.32323,107.5267,59.34535,107.5452,59.3678,107.5634,59.39056,107.5811,59.41364,107.5984,59.43702,107.6153,59.46071,107.6317,59.48468,107.6478,59.50893,107.6634,59.53347,107.6786,59.55827,107.6934,59.58333,107.7077,59.60865,107.7216,59.63421,107.735,59.66002,107.748,59.68605,107.7605,59.7123,107.7726,59.73877,107.7842,59.76545,107.7953,59.79232,107.806,59.81939,107.8162,59.84663],strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None,fillColor=Color(0,0,0,1))) self.add(Circle(143.75,91.66667,2.5,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(142.9167,92.5,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(144.5833,92.5,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[142.1838,91.09663,142.194,91.06939,142.2047,91.04232,142.2158,91.01545,142.2274,90.98877,142.2395,90.9623,142.252,90.93605,142.265,90.91002,142.2784,90.88421,142.2923,90.85865,142.3066,90.83333,142.3214,90.80827,142.3366,90.78347,142.3522,90.75893,142.3683,90.73468,142.3847,90.71071,142.4016,90.68702,142.4189,90.66364,142.4366,90.64056,142.4548,90.6178,142.4733,90.59535,142.4922,90.57323,142.5114,90.55145,142.5311,90.53,142.5511,90.5089,142.5715,90.48816,142.5922,90.46777,142.6133,90.44774,142.6348,90.42809,142.6566,90.40882,142.6787,90.38993,142.7011,90.37142,142.7239,90.35332,142.747,90.33561,142.7704,90.31831,142.794,90.30141,142.818,90.28494,142.8423,90.26888,142.8668,90.25325,142.8916,90.23805,142.9167,90.22329,142.942,90.20897,142.9675,90.19509,142.9933,90.18166,143.0194,90.16868,143.0456,90.15615,143.0721,90.14409,143.0988,90.13249,143.1257,90.12136,143.1527,90.1107,143.18,90.10051,143.2074,90.0908,143.235,90.08157,143.2627,90.07283,143.2906,90.06456,143.3186,90.05679,143.3468,90.04951,143.3751,90.04272,143.4035,90.03642,143.432,90.03062,143.4606,90.02532,143.4893,90.02052,143.518,90.01622,143.5469,90.01242,143.5758,90.00913,143.6047,90.00634,143.6337,90.00406,143.6628,90.00228,143.6918,90.00102,143.7209,90.00025,143.75,90,143.7791,90.00025,143.8082,90.00102,143.8372,90.00228,143.8663,90.00406,143.8953,90.00634,143.9242,90.00913,143.9531,90.01242,143.982,90.01622,144.0107,90.02052,144.0394,90.02532,144.068,90.03062,144.0965,90.03642,144.1249,90.04272,144.1532,90.04951,144.1814,90.05679,144.2094,90.06456,144.2373,90.07283,144.265,90.08157,144.2926,90.0908,144.32,90.10051,144.3473,90.1107,144.3743,90.12136,144.4012,90.13249,144.4279,90.14409,144.4544,90.15615,144.4806,90.16868,144.5067,90.18166,144.5325,90.19509,144.558,90.20897,144.5833,90.22329,144.6084,90.23805,144.6332,90.25325,144.6577,90.26888,144.682,90.28494,144.706,90.30141,144.7296,90.31831,144.753,90.33561,144.7761,90.35332,144.7989,90.37142,144.8213,90.38993,144.8434,90.40882,144.8652,90.42809,144.8867,90.44774,144.9078,90.46777,144.9285,90.48816,144.9489,90.5089,144.9689,90.53,144.9886,90.55145,145.0078,90.57323,145.0267,90.59535,145.0452,90.6178,145.0634,90.64056,145.0811,90.66364,145.0984,90.68702,145.1153,90.71071,145.1317,90.73468,145.1478,90.75893,145.1634,90.78347,145.1786,90.80827,145.1934,90.83333,145.2077,90.85865,145.2216,90.88421,145.235,90.91002,145.248,90.93605,145.2605,90.9623,145.2726,90.98877,145.2842,91.01545,145.2953,91.04232,145.306,91.06939,145.3162,91.09663],strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None,fillColor=Color(0,0,0,1))) self.add(Circle(181.25,95.83333,2.5,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(180.4167,96.66667,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(182.0833,96.66667,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[179.6838,95.2633,179.694,95.23605,179.7047,95.20899,179.7158,95.18211,179.7274,95.15544,179.7395,95.12897,179.752,95.10271,179.765,95.07668,179.7784,95.05088,179.7923,95.02532,179.8066,95,179.8214,94.97494,179.8366,94.95013,179.8522,94.9256,179.8683,94.90135,179.8847,94.87737,179.9016,94.85369,179.9189,94.83031,179.9366,94.80723,179.9548,94.78447,179.9733,94.76202,179.9922,94.7399,180.0114,94.71812,180.0311,94.69667,180.0511,94.67557,180.0715,94.65482,180.0922,94.63443,180.1133,94.61441,180.1348,94.59476,180.1566,94.57548,180.1787,94.55659,180.2011,94.53809,180.2239,94.51998,180.247,94.50227,180.2704,94.48497,180.294,94.46808,180.318,94.4516,180.3423,94.43555,180.3668,94.41992,180.3916,94.40472,180.4167,94.38996,180.442,94.37563,180.4675,94.36175,180.4933,94.34832,180.5194,94.33534,180.5456,94.32282,180.5721,94.31076,180.5988,94.29916,180.6257,94.28803,180.6527,94.27737,180.68,94.26718,180.7074,94.25747,180.735,94.24824,180.7627,94.23949,180.7906,94.23123,180.8186,94.22346,180.8468,94.21617,180.8751,94.20938,180.9035,94.20309,180.932,94.19729,180.9606,94.19199,180.9893,94.18719,181.018,94.18289,181.0469,94.17909,181.0758,94.1758,181.1047,94.17301,181.1337,94.17073,181.1628,94.16895,181.1918,94.16768,181.2209,94.16692,181.25,94.16667,181.2791,94.16692,181.3082,94.16768,181.3372,94.16895,181.3663,94.17073,181.3953,94.17301,181.4242,94.1758,181.4531,94.17909,181.482,94.18289,181.5107,94.18719,181.5394,94.19199,181.568,94.19729,181.5965,94.20309,181.6249,94.20938,181.6532,94.21617,181.6814,94.22346,181.7094,94.23123,181.7373,94.23949,181.765,94.24824,181.7926,94.25747,181.82,94.26718,181.8473,94.27737,181.8743,94.28803,181.9012,94.29916,181.9279,94.31076,181.9544,94.32282,181.9806,94.33534,182.0067,94.34832,182.0325,94.36175,182.058,94.37563,182.0833,94.38996,182.1084,94.40472,182.1332,94.41992,182.1577,94.43555,182.182,94.4516,182.206,94.46808,182.2296,94.48497,182.253,94.50227,182.2761,94.51998,182.2989,94.53809,182.3213,94.55659,182.3434,94.57548,182.3652,94.59476,182.3867,94.61441,182.4078,94.63443,182.4285,94.65482,182.4489,94.67557,182.4689,94.69667,182.4886,94.71812,182.5078,94.7399,182.5267,94.76202,182.5452,94.78447,182.5634,94.80723,182.5811,94.83031,182.5984,94.85369,182.6153,94.87737,182.6317,94.90135,182.6478,94.9256,182.6634,94.95013,182.6786,94.97494,182.6934,95,182.7077,95.02532,182.7216,95.05088,182.735,95.07668,182.748,95.10271,182.7605,95.12897,182.7726,95.15544,182.7842,95.18211,182.7953,95.20899,182.806,95.23605,182.8162,95.2633],strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None,fillColor=Color(0,0,0,1))) self.add(Circle(218.75,127.0833,2.5,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(217.9167,127.9167,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(219.5833,127.9167,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[217.1838,126.5133,217.194,126.4861,217.2047,126.459,217.2158,126.4321,217.2274,126.4054,217.2395,126.379,217.252,126.3527,217.265,126.3267,217.2784,126.3009,217.2923,126.2753,217.3066,126.25,217.3214,126.2249,217.3366,126.2001,217.3522,126.1756,217.3683,126.1513,217.3847,126.1274,217.4016,126.1037,217.4189,126.0803,217.4366,126.0572,217.4548,126.0345,217.4733,126.012,217.4922,125.9899,217.5114,125.9681,217.5311,125.9467,217.5511,125.9256,217.5715,125.9048,217.5922,125.8844,217.6133,125.8644,217.6348,125.8448,217.6566,125.8255,217.6787,125.8066,217.7011,125.7881,217.7239,125.77,217.747,125.7523,217.7704,125.735,217.794,125.7181,217.818,125.7016,217.8423,125.6855,217.8668,125.6699,217.8916,125.6547,217.9167,125.64,217.942,125.6256,217.9675,125.6118,217.9933,125.5983,218.0194,125.5853,218.0456,125.5728,218.0721,125.5608,218.0988,125.5492,218.1257,125.538,218.1527,125.5274,218.18,125.5172,218.2074,125.5075,218.235,125.4982,218.2627,125.4895,218.2906,125.4812,218.3186,125.4735,218.3468,125.4662,218.3751,125.4594,218.4035,125.4531,218.432,125.4473,218.4606,125.442,218.4893,125.4372,218.518,125.4329,218.5469,125.4291,218.5758,125.4258,218.6047,125.423,218.6337,125.4207,218.6628,125.419,218.6918,125.4177,218.7209,125.4169,218.75,125.4167,218.7791,125.4169,218.8082,125.4177,218.8372,125.419,218.8663,125.4207,218.8953,125.423,218.9242,125.4258,218.9531,125.4291,218.982,125.4329,219.0107,125.4372,219.0394,125.442,219.068,125.4473,219.0965,125.4531,219.1249,125.4594,219.1532,125.4662,219.1814,125.4735,219.2094,125.4812,219.2373,125.4895,219.265,125.4982,219.2926,125.5075,219.32,125.5172,219.3473,125.5274,219.3743,125.538,219.4012,125.5492,219.4279,125.5608,219.4544,125.5728,219.4806,125.5853,219.5067,125.5983,219.5325,125.6118,219.558,125.6256,219.5833,125.64,219.6084,125.6547,219.6332,125.6699,219.6577,125.6855,219.682,125.7016,219.706,125.7181,219.7296,125.735,219.753,125.7523,219.7761,125.77,219.7989,125.7881,219.8213,125.8066,219.8434,125.8255,219.8652,125.8448,219.8867,125.8644,219.9078,125.8844,219.9285,125.9048,219.9489,125.9256,219.9689,125.9467,219.9886,125.9681,220.0078,125.9899,220.0267,126.012,220.0452,126.0345,220.0634,126.0572,220.0811,126.0803,220.0984,126.1037,220.1153,126.1274,220.1317,126.1513,220.1478,126.1756,220.1634,126.2001,220.1786,126.2249,220.1934,126.25,220.2077,126.2753,220.2216,126.3009,220.235,126.3267,220.248,126.3527,220.2605,126.379,220.2726,126.4054,220.2842,126.4321,220.2953,126.459,220.306,126.4861,220.3162,126.5133],strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None,fillColor=Color(0,0,0,1))) self.add(Circle(256.25,143.75,2.5,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(255.4167,144.5833,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(257.0833,144.5833,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[254.6838,143.18,254.694,143.1527,254.7047,143.1257,254.7158,143.0988,254.7274,143.0721,254.7395,143.0456,254.752,143.0194,254.765,142.9933,254.7784,142.9675,254.7923,142.942,254.8066,142.9167,254.8214,142.8916,254.8366,142.8668,254.8522,142.8423,254.8683,142.818,254.8847,142.794,254.9016,142.7704,254.9189,142.747,254.9366,142.7239,254.9548,142.7011,254.9733,142.6787,254.9922,142.6566,255.0114,142.6348,255.0311,142.6133,255.0511,142.5922,255.0715,142.5715,255.0922,142.5511,255.1133,142.5311,255.1348,142.5114,255.1566,142.4922,255.1787,142.4733,255.2011,142.4548,255.2239,142.4366,255.247,142.4189,255.2704,142.4016,255.294,142.3847,255.318,142.3683,255.3423,142.3522,255.3668,142.3366,255.3916,142.3214,255.4167,142.3066,255.442,142.2923,255.4675,142.2784,255.4933,142.265,255.5194,142.252,255.5456,142.2395,255.5721,142.2274,255.5988,142.2158,255.6257,142.2047,255.6527,142.194,255.68,142.1838,255.7074,142.1741,255.735,142.1649,255.7627,142.1562,255.7906,142.1479,255.8186,142.1401,255.8468,142.1328,255.8751,142.126,255.9035,142.1198,255.932,142.114,255.9606,142.1087,255.9893,142.1039,256.018,142.0996,256.0469,142.0958,256.0758,142.0925,256.1047,142.0897,256.1337,142.0874,256.1628,142.0856,256.1918,142.0843,256.2209,142.0836,256.25,142.0833,256.2791,142.0836,256.3082,142.0843,256.3372,142.0856,256.3663,142.0874,256.3953,142.0897,256.4242,142.0925,256.4531,142.0958,256.482,142.0996,256.5107,142.1039,256.5394,142.1087,256.568,142.114,256.5965,142.1198,256.6249,142.126,256.6532,142.1328,256.6814,142.1401,256.7094,142.1479,256.7373,142.1562,256.765,142.1649,256.7926,142.1741,256.82,142.1838,256.8473,142.194,256.8743,142.2047,256.9012,142.2158,256.9279,142.2274,256.9544,142.2395,256.9806,142.252,257.0067,142.265,257.0325,142.2784,257.058,142.2923,257.0833,142.3066,257.1084,142.3214,257.1332,142.3366,257.1577,142.3522,257.182,142.3683,257.206,142.3847,257.2296,142.4016,257.253,142.4189,257.2761,142.4366,257.2989,142.4548,257.3213,142.4733,257.3434,142.4922,257.3652,142.5114,257.3867,142.5311,257.4078,142.5511,257.4285,142.5715,257.4489,142.5922,257.4689,142.6133,257.4886,142.6348,257.5078,142.6566,257.5267,142.6787,257.5452,142.7011,257.5634,142.7239,257.5811,142.747,257.5984,142.7704,257.6153,142.794,257.6317,142.818,257.6478,142.8423,257.6634,142.8668,257.6786,142.8916,257.6934,142.9167,257.7077,142.942,257.7216,142.9675,257.735,142.9933,257.748,143.0194,257.7605,143.0456,257.7726,143.0721,257.7842,143.0988,257.7953,143.1257,257.806,143.1527,257.8162,143.18],strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None,fillColor=Color(0,0,0,1))) self.add(Circle(293.75,89.58333,2.5,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(292.9167,90.41667,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(294.5833,90.41667,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[292.1838,89.0133,292.194,88.98605,292.2047,88.95899,292.2158,88.93211,292.2274,88.90544,292.2395,88.87897,292.252,88.85271,292.265,88.82668,292.2784,88.80088,292.2923,88.77532,292.3066,88.75,292.3214,88.72494,292.3366,88.70013,292.3522,88.6756,292.3683,88.65135,292.3847,88.62737,292.4016,88.60369,292.4189,88.58031,292.4366,88.55723,292.4548,88.53447,292.4733,88.51202,292.4922,88.4899,292.5114,88.46812,292.5311,88.44667,292.5511,88.42557,292.5715,88.40482,292.5922,88.38443,292.6133,88.36441,292.6348,88.34476,292.6566,88.32548,292.6787,88.30659,292.7011,88.28809,292.7239,88.26998,292.747,88.25227,292.7704,88.23497,292.794,88.21808,292.818,88.2016,292.8423,88.18555,292.8668,88.16992,292.8916,88.15472,292.9167,88.13996,292.942,88.12563,292.9675,88.11175,292.9933,88.09832,293.0194,88.08534,293.0456,88.07282,293.0721,88.06076,293.0988,88.04916,293.1257,88.03803,293.1527,88.02737,293.18,88.01718,293.2074,88.00747,293.235,87.99824,293.2627,87.98949,293.2906,87.98123,293.3186,87.97346,293.3468,87.96617,293.3751,87.95938,293.4035,87.95309,293.432,87.94729,293.4606,87.94199,293.4893,87.93719,293.518,87.93289,293.5469,87.92909,293.5758,87.9258,293.6047,87.92301,293.6337,87.92073,293.6628,87.91895,293.6918,87.91768,293.7209,87.91692,293.75,87.91667,293.7791,87.91692,293.8082,87.91768,293.8372,87.91895,293.8663,87.92073,293.8953,87.92301,293.9242,87.9258,293.9531,87.92909,293.982,87.93289,294.0107,87.93719,294.0394,87.94199,294.068,87.94729,294.0965,87.95309,294.1249,87.95938,294.1532,87.96617,294.1814,87.97346,294.2094,87.98123,294.2373,87.98949,294.265,87.99824,294.2926,88.00747,294.32,88.01718,294.3473,88.02737,294.3743,88.03803,294.4012,88.04916,294.4279,88.06076,294.4544,88.07282,294.4806,88.08534,294.5067,88.09832,294.5325,88.11175,294.558,88.12563,294.5833,88.13996,294.6084,88.15472,294.6332,88.16992,294.6577,88.18555,294.682,88.2016,294.706,88.21808,294.7296,88.23497,294.753,88.25227,294.7761,88.26998,294.7989,88.28809,294.8213,88.30659,294.8434,88.32548,294.8652,88.34476,294.8867,88.36441,294.9078,88.38443,294.9285,88.40482,294.9489,88.42557,294.9689,88.44667,294.9886,88.46812,295.0078,88.4899,295.0267,88.51202,295.0452,88.53447,295.0634,88.55723,295.0811,88.58031,295.0984,88.60369,295.1153,88.62737,295.1317,88.65135,295.1478,88.6756,295.1634,88.70013,295.1786,88.72494,295.1934,88.75,295.2077,88.77532,295.2216,88.80088,295.235,88.82668,295.248,88.85271,295.2605,88.87897,295.2726,88.90544,295.2842,88.93211,295.2953,88.95899,295.306,88.98605,295.3162,89.0133],strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None,fillColor=Color(0,0,0,1))) self.add(Circle(331.25,58.33333,2.5,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(330.4167,59.16667,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Ellipse(332.0833,59.16667,.166667,.5,fillColor=Color(0,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[329.6838,57.7633,329.694,57.73605,329.7047,57.70899,329.7158,57.68211,329.7274,57.65544,329.7395,57.62897,329.752,57.60271,329.765,57.57668,329.7784,57.55088,329.7923,57.52532,329.8066,57.5,329.8214,57.47494,329.8366,57.45013,329.8522,57.4256,329.8683,57.40135,329.8847,57.37737,329.9016,57.35369,329.9189,57.33031,329.9366,57.30723,329.9548,57.28447,329.9733,57.26202,329.9922,57.2399,330.0114,57.21812,330.0311,57.19667,330.0511,57.17557,330.0715,57.15482,330.0922,57.13443,330.1133,57.11441,330.1348,57.09476,330.1566,57.07548,330.1787,57.05659,330.2011,57.03809,330.2239,57.01998,330.247,57.00227,330.2704,56.98497,330.294,56.96808,330.318,56.9516,330.3423,56.93555,330.3668,56.91992,330.3916,56.90472,330.4167,56.88996,330.442,56.87563,330.4675,56.86175,330.4933,56.84832,330.5194,56.83534,330.5456,56.82282,330.5721,56.81076,330.5988,56.79916,330.6257,56.78803,330.6527,56.77737,330.68,56.76718,330.7074,56.75747,330.735,56.74824,330.7627,56.73949,330.7906,56.73123,330.8186,56.72346,330.8468,56.71617,330.8751,56.70938,330.9035,56.70309,330.932,56.69729,330.9606,56.69199,330.9893,56.68719,331.018,56.68289,331.0469,56.67909,331.0758,56.6758,331.1047,56.67301,331.1337,56.67073,331.1628,56.66895,331.1918,56.66768,331.2209,56.66692,331.25,56.66667,331.2791,56.66692,331.3082,56.66768,331.3372,56.66895,331.3663,56.67073,331.3953,56.67301,331.4242,56.6758,331.4531,56.67909,331.482,56.68289,331.5107,56.68719,331.5394,56.69199,331.568,56.69729,331.5965,56.70309,331.6249,56.70938,331.6532,56.71617,331.6814,56.72346,331.7094,56.73123,331.7373,56.73949,331.765,56.74824,331.7926,56.75747,331.82,56.76718,331.8473,56.77737,331.8743,56.78803,331.9012,56.79916,331.9279,56.81076,331.9544,56.82282,331.9806,56.83534,332.0067,56.84832,332.0325,56.86175,332.058,56.87563,332.0833,56.88996,332.1084,56.90472,332.1332,56.91992,332.1577,56.93555,332.182,56.9516,332.206,56.96808,332.2296,56.98497,332.253,57.00227,332.2761,57.01998,332.2989,57.03809,332.3213,57.05659,332.3434,57.07548,332.3652,57.09476,332.3867,57.11441,332.4078,57.13443,332.4285,57.15482,332.4489,57.17557,332.4689,57.19667,332.4886,57.21812,332.5078,57.2399,332.5267,57.26202,332.5452,57.28447,332.5634,57.30723,332.5811,57.33031,332.5984,57.35369,332.6153,57.37737,332.6317,57.40135,332.6478,57.4256,332.6634,57.45013,332.6786,57.47494,332.6934,57.5,332.7077,57.52532,332.7216,57.55088,332.735,57.57668,332.748,57.60271,332.7605,57.62897,332.7726,57.65544,332.7842,57.68211,332.7953,57.70899,332.806,57.73605,332.8162,57.7633],strokeColor=Color(0,0,0,1),strokeWidth=.131579,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None,fillColor=Color(0,0,0,1))) self.add(Line(50,50,350,50,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(50,50,50,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(87.5,50,87.5,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(125,50,125,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(162.5,50,162.5,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(200,50,200,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(237.5,50,237.5,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(275,50,275,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(312.5,50,312.5,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(350,50,350,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) v0=self._nn(Group()) v0.transform = (1,0,0,1,68.75,45) v0.add(String(-6.665,-10,'Jan',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,106.25,45) v0.add(String(-7.5,-10,'Feb',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,143.75,45) v0.add(String(-8.33,-10,'Mar',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,181.25,45) v0.add(String(-7.775,-10,'Apr',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,218.75,45) v0.add(String(-9.165,-10,'May',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,256.25,45) v0.add(String(-6.945,-10,'Jun',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,293.75,45) v0.add(String(-5.835,-10,'Jul',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,331.25,45) v0.add(String(-8.61,-10,'Aug',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(Line(50,50,50,175,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(50,50,45,50,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(50,81.25,45,81.25,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(50,112.5,45,112.5,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(50,143.75,45,143.75,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(50,175,45,175,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) v0=self._nn(Group()) v0.transform = (1,0,0,1,45,50) v0.add(String(-5,-4,'0',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,45,81.25) v0.add(String(-10,-4,'15',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,45,112.5) v0.add(String(-10,-4,'30',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,45,143.75) v0.add(String(-10,-4,'45',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,45,175) v0.add(String(-10,-4,'60',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1)))
def _addWedgeLabel(self,text,add,angle,labelX,labelY,wedgeStyle,labelClass=WedgeLabel): # now draw a label if self.simpleLabels: theLabel = String(labelX, labelY, text) theLabel.textAnchor = "middle" theLabel._pmv = angle else: theLabel = labelClass() theLabel._pmv = angle theLabel.x = labelX theLabel.y = labelY theLabel.dx = wedgeStyle.label_dx theLabel.dy = wedgeStyle.label_dy theLabel.angle = wedgeStyle.label_angle theLabel.boxAnchor = wedgeStyle.label_boxAnchor theLabel.boxStrokeColor = wedgeStyle.label_boxStrokeColor theLabel.boxStrokeWidth = wedgeStyle.label_boxStrokeWidth theLabel.boxFillColor = wedgeStyle.label_boxFillColor theLabel.strokeColor = wedgeStyle.label_strokeColor theLabel.strokeWidth = wedgeStyle.label_strokeWidth _text = wedgeStyle.label_text if _text is None: _text = text theLabel._text = _text theLabel.leading = wedgeStyle.label_leading theLabel.width = wedgeStyle.label_width theLabel.maxWidth = wedgeStyle.label_maxWidth theLabel.height = wedgeStyle.label_height theLabel.textAnchor = wedgeStyle.label_textAnchor theLabel.visible = wedgeStyle.label_visible theLabel.topPadding = wedgeStyle.label_topPadding theLabel.leftPadding = wedgeStyle.label_leftPadding theLabel.rightPadding = wedgeStyle.label_rightPadding theLabel.bottomPadding = wedgeStyle.label_bottomPadding theLabel.fontSize = wedgeStyle.fontSize theLabel.fontName = wedgeStyle.fontName theLabel.fillColor = wedgeStyle.fontColor add(theLabel)
def _getText(self, x=0, y=0, color=None): return String(x,y, self._text, fontName=self._fontName, fontSize=self._fontSize, fillColor=color)
from reportlab.graphics.shapes import Drawing, String from reportlab.graphics import renderPDF s = String(50, 50, 'Hello World', textAnchor='middle') d = Drawing(100, 100) d.add(s) renderPDF.drawToFile(d, 'hello.pdf', 'a simple pdf file')
def draw(self): colorNamePairs = self.colorNamePairs autoCP = isAuto(colorNamePairs) if autoCP: chart = getattr(colorNamePairs,'chart',getattr(colorNamePairs,'obj',None)) swatchMarker = None autoCP = Auto(obj=chart) n = chart._seriesCount chartTexts = self._getTexts(colorNamePairs) else: swatchMarker = getattr(self,'swatchMarker',None) if isAuto(swatchMarker): chart = getattr(swatchMarker,'chart',getattr(swatchMarker,'obj',None)) swatchMarker = Auto(obj=chart) n = len(colorNamePairs) dx = self.dx dy = self.dy alignment = self.alignment columnMaximum = self.columnMaximum deltax = self.deltax deltay = self.deltay dxTextSpace = self.dxTextSpace fontName = self.fontName fontSize = self.fontSize fillColor = self.fillColor strokeWidth = self.strokeWidth strokeColor = self.strokeColor subCols = self.subCols leading = fontSize*1.2 yGap = self.yGap if not deltay: deltay = max(dy,leading)+self.autoYPadding ba = self.boxAnchor maxWidth = self._calculateMaxBoundaries(colorNamePairs) nCols = int((n+columnMaximum-1)/(columnMaximum*1.0)) xW = dx+dxTextSpace+self.autoXPadding variColumn = self.variColumn if variColumn: width = sum([m[-1] for m in maxWidth])+xW*nCols else: deltax = max(maxWidth[-1]+xW,deltax) width = nCols*deltax maxWidth = nCols*[maxWidth] thisx = self.x thisy = self.y - self.dy if ba not in ('ne','n','nw','autoy'): height = self._calcHeight() if ba in ('e','c','w'): thisy += height/2. else: thisy += height if ba not in ('nw','w','sw','autox'): if ba in ('n','c','s'): thisx -= width/2 else: thisx -= width upperlefty = thisy g = Group() ascent=getFont(fontName).face.ascent/1000. if ascent==0: ascent=0.718 # default (from helvetica) ascent *= fontSize # normalize lim = columnMaximum - 1 callout = getattr(self,'callout',None) scallout = getattr(self,'swatchCallout',None) dividerLines = self.dividerLines if dividerLines: dividerWidth = self.dividerWidth dividerColor = self.dividerColor dividerDashArray = self.dividerDashArray dividerOffsX = self.dividerOffsX dividerOffsY = self.dividerOffsY for i in xrange(n): if autoCP: col = autoCP col.index = i name = chartTexts[i] else: col, name = colorNamePairs[i] if isAuto(swatchMarker): col = swatchMarker col.index = i if isAuto(name): name = getattr(swatchMarker,'chart',getattr(swatchMarker,'obj',None)).getSeriesName(i,'series %d' % i) T = _getLines(name) S = [] aS = S.append j = int(i/(columnMaximum*1.0)) jOffs = maxWidth[j] # thisy+dy/2 = y+leading/2 y = y0 = thisy+(dy-ascent)*0.5 if callout: callout(self,g,thisx,y,(col,name)) if alignment == "left": x = thisx xn = thisx+jOffs[-1]+dxTextSpace elif alignment == "right": x = thisx+dx+dxTextSpace xn = thisx else: raise ValueError("bad alignment") if not isSeq(name): T = [T] yd = y for k,lines in enumerate(T): y = y0 kk = k*2 x1 = x+jOffs[kk] x2 = x+jOffs[kk+1] sc = subCols[k,i] anchor = sc.align scdx = sc.dx scdy = sc.dy fN = getattr(sc,'fontName',fontName) fS = getattr(sc,'fontSize',fontSize) fC = getattr(sc,'fillColor',fillColor) fL = getattr(sc,'leading',1.2*fontSize) if fN==fontName: fA = (ascent*fS)/fontSize else: fA = getFont(fontName).face.ascent/1000. if fA==0: fA=0.718 fA *= fS if anchor=='left': anchor = 'start' xoffs = x1 elif anchor=='right': anchor = 'end' xoffs = x2 elif anchor=='numeric': xoffs = x2 else: anchor = 'middle' xoffs = 0.5*(x1+x2) for t in lines: aS(String(xoffs+scdx,y+scdy,t,fontName=fN,fontSize=fS,fillColor=fC, textAnchor = anchor)) y -= fL yd = min(yd,y) y += fL for iy, a in ((y-max(fL-fA,0),'underlines'),(y+fA,'overlines')): il = getattr(sc,a,None) if il: if not isinstance(il,(tuple,list)): il = (il,) for l in il: l = copy.copy(l) l.y1 += iy l.y2 += iy l.x1 += x1 l.x2 += x2 aS(l) x = xn y = yd leadingMove = 2*y0-y-thisy if dividerLines: xd = thisx+dx+dxTextSpace+jOffs[-1]+dividerOffsX[1] yd = thisy+dy*0.5+dividerOffsY if ((dividerLines&1) and i%columnMaximum) or ((dividerLines&2) and not i%columnMaximum): g.add(Line(thisx+dividerOffsX[0],yd,xd,yd, strokeColor=dividerColor, strokeWidth=dividerWidth, strokeDashArray=dividerDashArray)) if (dividerLines&4) and (i%columnMaximum==lim or i==(n-1)): yd -= max(deltay,leadingMove)+yGap g.add(Line(thisx+dividerOffsX[0],yd,xd,yd, strokeColor=dividerColor, strokeWidth=dividerWidth, strokeDashArray=dividerDashArray)) # Make a 'normal' color swatch... swatchX = x + getattr(self,'swdx',0) swatchY = thisy + getattr(self,'swdy',0) if isAuto(col): chart = getattr(col,'chart',getattr(col,'obj',None)) c = chart.makeSwatchSample(getattr(col,'index',i),swatchX,swatchY,dx,dy) elif isinstance(col, colors.Color): if isSymbol(swatchMarker): c = uSymbol2Symbol(swatchMarker,swatchX+dx/2.,swatchY+dy/2.,col) else: c = self._defaultSwatch(swatchX,swatchY,dx,dy,fillColor=col,strokeWidth=strokeWidth,strokeColor=strokeColor) elif col is not None: try: c = copy.deepcopy(col) c.x = swatchX c.y = swatchY c.width = dx c.height = dy except: c = None else: c = None if c: g.add(c) if scallout: scallout(self,g,thisx,y0,i,(col,name),c) for s in S: g.add(s) if self.colEndCallout and (i%columnMaximum==lim or i==(n-1)): if alignment == "left": xt = thisx else: xt = thisx+dx+dxTextSpace yd = thisy+dy*0.5+dividerOffsY - (max(deltay,leadingMove)+yGap) self.colEndCallout(self, g, thisx, xt, yd, jOffs[-1], jOffs[-1]+dx+dxTextSpace) if i%columnMaximum==lim: if variColumn: thisx += jOffs[-1]+xW else: thisx = thisx+deltax thisy = upperlefty else: thisy = thisy-max(deltay,leadingMove)-yGap return g
def __init__(self, width=400, height=200, *args, **kw): Drawing.__init__(self, width, height, *args, **kw) self.transform = (1, 0, 0, 1, 0, 0) self.add( Line(75, 75, 375, 75, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(75, 75, 75, 70, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(150, 75, 150, 70, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(225, 75, 225, 70, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(300, 75, 300, 70, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(375, 75, 375, 70, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 112.5, 70) v0.add( String(-9.44, -10, 'Beer', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 187.5, 70) v0.add( String(-10.83, -10, 'Wine', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 262.5, 70) v0.add( String(-10.275, -10, 'Meat', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (.866025, .5, -0.5, .866025, 337.5, 60) v0.add( String(-23.34, -10, 'Cannelloni', textAnchor='start', fontName='Times-Bold', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( Line(50, 50, 50, 175, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 50, 45, 50, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 89.0625, 45, 89.0625, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 128.125, 45, 128.125, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 167.1875, 45, 167.1875, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 50) v0.add( String(-10, -4, '10', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 89.0625) v0.add( String(-10, -4, '20', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 128.125) v0.add( String(-10, -4, '30', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 167.1875) v0.add( String(-10, -4, '40', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1)))
def _Flag_Brazil(self): s = _size # abbreviate as we will use this a lot g = Group() m = s/14.0 self._width = w = (m * 20) def addStar(x,y,size, g=g, w=w, s=s, m=m): st = Star() st.fillColor=colors.mintcream st.size = size*m st.x = (w/2.0) + (x * (0.35 * m)) st.y = (s/2.0) + (y * (0.35 * m)) g.add(st) g.add(Rect(0, 0, w, s, fillColor = colors.green, strokeColor = None, strokeWidth=0)) g.add(Polygon(points = [ 1.7*m, (s/2.0), (w/2.0), s-(1.7*m), w-(1.7*m),(s/2.0),(w/2.0), 1.7*m], fillColor = colors.yellow, strokeColor = None, strokeWidth=0)) g.add(Circle(cx=w/2.0, cy=s/2.0, r=3.5*m, fillColor=colors.blue,strokeColor=None, strokeWidth=0)) g.add(Wedge((w/2.0)-(2*m), 0, 8.5*m, 50, 98.1, 8.5*m, fillColor=colors.mintcream,strokeColor=None, strokeWidth=0)) g.add(Wedge((w/2.0), (s/2.0), 3.501*m, 156, 352, 3.501*m, fillColor=colors.mintcream,strokeColor=None, strokeWidth=0)) g.add(Wedge((w/2.0)-(2*m), 0, 8*m, 48.1, 100, 8*m, fillColor=colors.blue,strokeColor=None, strokeWidth=0)) g.add(Rect(0, 0, w, (s/4.0) + 1.7*m, fillColor = colors.green, strokeColor = None, strokeWidth=0)) g.add(Polygon(points = [ 1.7*m,(s/2.0), (w/2.0),s/2.0 - 2*m, w-(1.7*m),(s/2.0) , (w/2.0),1.7*m], fillColor = colors.yellow, strokeColor = None, strokeWidth=0)) g.add(Wedge(w/2.0, s/2.0, 3.502*m, 166, 342.1, 3.502*m, fillColor=colors.blue,strokeColor=None, strokeWidth=0)) addStar(3.2,3.5,0.3) addStar(-8.5,1.5,0.3) addStar(-7.5,-3,0.3) addStar(-4,-5.5,0.3) addStar(0,-4.5,0.3) addStar(7,-3.5,0.3) addStar(-3.5,-0.5,0.25) addStar(0,-1.5,0.25) addStar(1,-2.5,0.25) addStar(3,-7,0.25) addStar(5,-6.5,0.25) addStar(6.5,-5,0.25) addStar(7,-4.5,0.25) addStar(-5.5,-3.2,0.25) addStar(-6,-4.2,0.25) addStar(-1,-2.75,0.2) addStar(2,-5.5,0.2) addStar(4,-5.5,0.2) addStar(5,-7.5,0.2) addStar(5,-5.5,0.2) addStar(6,-5.5,0.2) addStar(-8.8,-3.2,0.2) addStar(2.5,0.5,0.2) addStar(-0.2,-3.2,0.14) addStar(-7.2,-2,0.14) addStar(0,-8,0.1) sTmp = "ORDEM E PROGRESSO" nTmp = len(sTmp) delta = 0.850848010347/nTmp radius = 7.9 *m centerx = (w/2.0)-(2*m) centery = 0 for i in range(nTmp): rad = 2*pi - i*delta -4.60766922527 x=cos(rad)*radius+centerx y=sin(rad)*radius+centery if i == 6: z = 0.35*m else: z= 0.45*m g2 = Group(String(x, y, sTmp[i], fontName='Helvetica-Bold', fontSize = z,strokeColor=None,fillColor=colors.green)) g2.rotate(rad) g.add(g2) return g
def draw(self): fillColor = self.fillColor strokeColor = self.strokeColor g = Group() g.add( Rect(x=0, y=0, fillColor=self.fillColor, strokeColor=self.fillColor, width=self.borderWidth, height=self.height)) g.add( Rect(x=0, y=self.height - self.borderWidth, fillColor=self.fillColor, strokeColor=self.fillColor, width=self.width, height=self.borderWidth)) g2 = Group() rl = RL_CorpLogo() rl.height = 1.25 * cm rl.width = 1.9 * cm rl.draw() g2.add(rl) g.add(g2) g2.shift(x=(self.width - (rl.width + (self.width / 42))), y=(self.height - (rl.height + (self.height / 42)))) g.add( String(x=self.borderWidth / 5.0, y=((self.height - (rl.height + (self.height / 42))) + ((38 / 90.5) * rl.height)), fontSize=6, fillColor=self.altStrokeColor, fontName="Helvetica-BoldOblique", textAnchor='start', text=self._strapline)) leftText = ["Tel:", "Mobile:", "Fax:", "Email:", "Web:"] leftDetails = [ self.telephone, self.mobile, self.fax, self.email, self.web ] leftText.reverse() leftDetails.reverse() for f in range(len(leftText), 0, -1): g.add( String(x=self.borderWidth + (self.borderWidth / 5.0), y=(self.borderWidth / 5.0) + ((f - 1) * (5 * 1.2)), fontSize=5, fillColor=self.strokeColor, fontName="Helvetica", textAnchor='start', text=leftText[f - 1])) g.add( String(x=self.borderWidth + (self.borderWidth / 5.0) + self.borderWidth, y=(self.borderWidth / 5.0) + ((f - 1) * (5 * 1.2)), fontSize=5, fillColor=self.strokeColor, fontName="Helvetica", textAnchor='start', text=leftDetails[f - 1])) ty = (self.height - self.borderWidth - (self.borderWidth / 5.0) + 2) # g.add(Line(self.borderWidth, ty, self.borderWidth+(self.borderWidth/5.0), ty)) # g.add(Line(self.borderWidth+(self.borderWidth/5.0), ty, self.borderWidth+(self.borderWidth/5.0), # ty+(self.borderWidth/5.0))) # g.add(Line(self.borderWidth, ty-10, # self.borderWidth+(self.borderWidth/5.0), ty-10)) rightText = self.rh_blurb_top for f in range(1, (len(rightText) + 1)): g.add( String(x=self.width - (self.borderWidth / 5.0), y=ty - ((f) * (5 * 1.2)), fontSize=5, fillColor=self.strokeColor, fontName="Helvetica", textAnchor='end', text=rightText[f - 1])) g.add( String(x=self.borderWidth + (self.borderWidth / 5.0), y=ty - 10, fontSize=10, fillColor=self.strokeColor, fontName="Helvetica", textAnchor='start', text=self.name)) ty1 = ty - 10 * 1.2 g.add( String(x=self.borderWidth + (self.borderWidth / 5.0), y=ty1 - 8, fontSize=8, fillColor=self.strokeColor, fontName="Helvetica", textAnchor='start', text=self.position)) if self.border: g.add( Rect(x=0, y=0, fillColor=None, strokeColor=black, width=self.width, height=self.height)) g.shift(self.x, self.y) return g
def __init__(self, width=400, height=200, *args, **kw): Drawing.__init__(self, width, height, *args, **kw) self.transform = (1, 0, 0, 1, 0, 0) self.add( Rect(50, 50, 300, 125, rx=0, ry=0, fillColor=None, fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(50, 50, 50, 10, rx=0, ry=0, fillColor=Color(1, 0, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(50, 90, 300, 10, rx=0, ry=0, fillColor=Color(1, 0, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(50, 60, 100, 10, rx=0, ry=0, fillColor=Color(0, .501961, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(50, 100, 250, 10, rx=0, ry=0, fillColor=Color(0, .501961, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(50, 70, 150, 10, rx=0, ry=0, fillColor=Color(0, 0, 1, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(50, 110, 200, 10, rx=0, ry=0, fillColor=Color(0, 0, 1, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(50, 80, 200, 10, rx=0, ry=0, fillColor=Color(1, 0, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Rect(50, 120, 150, 10, rx=0, ry=0, fillColor=Color(1, 0, 0, 1), fillOpacity=None, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(49, 50, 49, 175, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(49, 50, 44, 50, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(49, 112.5, 44, 112.5, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(49, 175, 44, 175, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 44, 81.25) v0.add( String(-20, -4, 'Ying', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 44, 143.75) v0.add( String(-21.66, -4, 'Yang', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( Line(50, 50, 350, 50, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 50, 50, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(125, 50, 125, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(200, 50, 200, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(275, 50, 275, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(350, 50, 350, 45, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 50, 45) v0.add( String(-2.5, -10, '0', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 125, 45) v0.add( String(-5, -10, '15', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 200, 45) v0.add( String(-5, -10, '30', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 275, 45) v0.add( String(-5, -10, '45', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 350, 45) v0.add( String(-5, -10, '60', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1)))
def annotate(self,x,y,text,fontName,fontSize,anchor='middle'): self._Gadd(String(self.x+x,self.y+y,text,fontName=fontName,fontSize=fontSize, textAnchor=anchor,fillColor=self.textColor))
def make_graphs(self,canvas=None,left_margin=None):#text=None): from reportlab.graphics import renderPDF from reportlab.lib.pagesizes import letter from reportlab.graphics.shapes import Drawing,String from reportlab.graphics.charts.legends import Legend from reportlab.graphics.charts.lineplots import LinePlot from reportlab.graphics.widgets.markers import makeMarker from reportlab.lib import colors from reportlab.lib.units import inch #help(colors) self.framework = {4:dict(status=SpotClass.SPINDLE,color=colors.black), 5:dict(status=SpotClass.OVERLAP,color=colors.limegreen), 6:dict(status=SpotClass.OUTLIER,color=colors.greenyellow), 7:dict(status=SpotClass.ICE,color=colors.skyblue), } # set size and position width,height = letter #letter_landscape = (width,height) plot_dim = 3.0*inch # construct scatter plot plot_dxdy_pos = (left_margin*inch,height - plot_dim - 0.5*inch) plot_dxdy = LinePlot() plot_dxdy.data = self.plot_dxdy_data std_colors = {0:colors.darkred, 1:colors.red, 2:colors.salmon} for key in std_colors.keys(): plot_dxdy.lines[key].strokeColor = None plot_dxdy.lines[key].symbol = makeMarker('Circle') plot_dxdy.lines[key].symbol.strokeColor = None plot_dxdy.lines[key].symbol.fillColor = std_colors[key] plot_dxdy.lines[key].symbol.size = 1.2 for key in self.framework.keys(): plot_dxdy.lines[key].strokeColor = None plot_dxdy.lines[key].symbol = makeMarker('Circle') plot_dxdy.lines[key].symbol.strokeColor = None plot_dxdy.lines[key].symbol.fillColor = self.framework[key]["color"] plot_dxdy.lines[key].symbol.size = 1.2 plot_dxdy.lines[3].strokeColor = None plot_dxdy.lines[3].symbol = makeMarker('Circle') plot_dxdy.lines[3].symbol.strokeColor = colors.blue plot_dxdy.lines[3].symbol.fillColor = None plot_dxdy.lines[3].symbol.strokeWidth = 0.6 plot_dxdy.lines[3].symbol.size = plot_dim*(self.sqrtr2) #print plot_dxdy.lines[3].symbol.getProperties() plot_dxdy.width = plot_dim plot_dxdy.height = plot_dim plot_dxdy.xValueAxis.valueMax = 1.0 plot_dxdy.xValueAxis.valueMin = -1.0 plot_dxdy.xValueAxis.joinAxis = plot_dxdy.yValueAxis plot_dxdy.xValueAxis.joinAxisMode = 'value' plot_dxdy.xValueAxis.joinAxisPos = -1.0 plot_dxdy.yValueAxis.valueMax = 1.0 plot_dxdy.yValueAxis.valueMin = -1.0 d_dxdy = Drawing(plot_dim,plot_dim) d_dxdy.add(plot_dxdy) # construct cdf plot plot_cdf_pos = (left_margin*inch, height - 2.0*(plot_dim + 0.5*inch)) plot_cdf = LinePlot() plot_cdf.data = self.plot_cdf_data plot_cdf.lines[0].strokeColor = colors.blue for key in std_colors.keys(): plot_cdf.lines[key+1].strokeColor = None plot_cdf.lines[key+1].symbol = makeMarker('Circle') plot_cdf.lines[key+1].symbol.strokeColor = None plot_cdf.lines[key+1].symbol.fillColor = std_colors[key] plot_cdf.lines[key+1].symbol.size = 1.2 if (len(self.plot_cdf_data) == 5): plot_cdf.lines[4].strokeColor = colors.green plot_cdf.width = plot_dim plot_cdf.height = plot_dim plot_cdf.xValueAxis.valueMax = 1.0 plot_cdf.xValueAxis.valueMin = 0.0 plot_cdf.yValueAxis.valueMax = 1.0 plot_cdf.yValueAxis.valueMin = 0.0 d_cdf = Drawing(plot_dim,plot_dim) d_cdf.add(plot_cdf) # construct pdf plot plot_pdf_pos = (left_margin*inch, height - 3.0*(plot_dim + 0.5*inch)) plot_pdf = LinePlot() plot_pdf.data = self.plot_pdf_data plot_pdf.lines[1].strokeColor = colors.blue plot_pdf.lines[0].strokeColor = None plot_pdf.lines[0].symbol = makeMarker('Circle') plot_pdf.lines[0].symbol.strokeColor = colors.red plot_pdf.lines[0].symbol.size = 1 plot_pdf.width = plot_dim plot_pdf.height = plot_dim plot_pdf.xValueAxis.valueMax = 1.0 plot_pdf.xValueAxis.valueMin = 0.0 d_pdf = Drawing(2*plot_dim,plot_dim) d_pdf.add(plot_pdf) # add legend legend = Legend() legend.alignment = 'right' legend.colorNamePairs = [(std_colors[0],'Inliers (%d'%int(self.fraction*100.0) + '% used for fit)'), (std_colors[1],'Other inliers'), (std_colors[2],'Outliers, reject next round'),] for key in self.framework.keys(): legend.colorNamePairs.append( (self.framework[key]["color"], "%s"%self.framework[key]["status"] ) ) legend.x = plot_dim - 1.0*inch legend.y = plot_dim legend.columnMaximum = 8 d_pdf.add(legend) # add titles title_pos = (plot_dim/2.0,plot_dim + 0.25*inch) title_dxdy = String(title_pos[0],title_pos[1],'dx vs. dy (all)') title_dxdy.fontSize = 15 title_dxdy.textAnchor = 'middle' d_dxdy.add(title_dxdy) title_cdf = String(title_pos[0],title_pos[1],'cdf (good)') title_cdf.fontSize = 15 title_cdf.textAnchor = 'middle' d_cdf.add(title_cdf) title_pdf = String(title_pos[0],title_pos[1],'pdf (good)') title_pdf.fontSize = 15 title_pdf.textAnchor = 'middle' d_pdf.add(title_pdf) # draw everything renderPDF.draw(d_dxdy,canvas,plot_dxdy_pos[0],plot_dxdy_pos[1]) renderPDF.draw(d_cdf,canvas,plot_cdf_pos[0],plot_cdf_pos[1]) renderPDF.draw(d_pdf,canvas,plot_pdf_pos[0],plot_pdf_pos[1])
def testUtf8Canvas(self): """Verify canvas declared as utf8 autoconverts. This assumes utf8 input. It converts to the encoding of the underlying font, so both text lines APPEAR the same.""" c = Canvas(outputfile('test_pdfbase_encodings_utf8.pdf')) c.drawString(100,700, testUTF8) # Set a font with UTF8 encoding c.setFont('Vera', 12) # This should pass the UTF8 through unchanged c.drawString(100,600, testUTF8) # and this should convert from Unicode to UTF8 c.drawString(100,500, testUni) # now add a paragraph in Latin-1 in the latin-1 style p = Paragraph(testUTF8, style=self.styNormal, encoding="utf-8") w, h = p.wrap(150, 100) p.drawOn(c, 100, 400) #3 c.rect(100,300,w,h) # now add a paragraph in UTF-8 in the UTF-8 style p2 = Paragraph(testUTF8, style=self.styTrueType, encoding="utf-8") w, h = p2.wrap(150, 100) p2.drawOn(c, 300, 400) #4 c.rect(100,300,w,h) # now add a paragraph in Unicode in the latin-1 style p3 = Paragraph(testUni, style=self.styNormal) w, h = p3.wrap(150, 100) p3.drawOn(c, 100, 300) c.rect(100,300,w,h) # now add a paragraph in Unicode in the UTF-8 style p4 = Paragraph(testUni, style=self.styTrueType) p4.wrap(150, 100) p4.drawOn(c, 300, 300) c.rect(300,300,w,h) # now a graphic d1 = Drawing(400,50) d1.add(Ellipse(200,25,200,12.5, fillColor=None)) d1.add(String(200,25,testUTF8, textAnchor='middle', encoding='utf-8')) d1.drawOn(c, 100, 150) # now a graphic in utf8 d2 = Drawing(400,50) d2.add(Ellipse(200,25,200,12.5, fillColor=None)) d2.add(String(200,25,testUTF8, fontName='Vera', textAnchor='middle', encoding='utf-8')) d2.drawOn(c, 100, 100) # now a graphic in Unicode with T1 font d3 = Drawing(400,50) d3.add(Ellipse(200,25,200,12.5, fillColor=None)) d3.add(String(200,25,testUni, textAnchor='middle')) d3.drawOn(c, 100, 50) # now a graphic in Unicode with TT font d4 = Drawing(400,50) d4.add(Ellipse(200,25,200,12.5, fillColor=None)) d4.add(String(200,25,testUni, fontName='Vera', textAnchor='middle')) d4.drawOn(c, 100, 0) extracted = extractText(c.getCurrentPageContent()) self.assertEquals(extracted[0], expectedCp1252) self.assertEquals(extracted[1], extracted[2]) #self.assertEquals(subsetToUnicode(self.vera, extracted[1]), testUni) c.save()
def draw(self): g = Group() colorNamePairs = self.colorNamePairs thisx = upperleftx = self.x thisy = upperlefty = self.y - self.dy dx, dy, alignment, columnMaximum = self.dx, self.dy, self.alignment, self.columnMaximum deltax, deltay, dxTextSpace = self.deltax, self.deltay, self.dxTextSpace fontName, fontSize, fillColor = self.fontName, self.fontSize, self.fillColor strokeWidth, strokeColor = self.strokeWidth, self.strokeColor leading = fontSize*1.2 if not deltay: deltay = max(dy,leading)+self.autoYPadding if not deltax: maxWidth = self._calculateMaxWidth(colorNamePairs) deltax = maxWidth+dx+dxTextSpace+self.autoXPadding else: if alignment=='left': maxWidth = self._calculateMaxWidth(colorNamePairs) def gAdd(t,g=g,fontName=fontName,fontSize=fontSize,fillColor=fillColor): t.fontName = fontName t.fontSize = fontSize t.fillColor = fillColor return g.add(t) ascent=getFont(fontName).face.ascent/1000. if ascent==0: ascent=0.718 # default (from helvetica) ascent=ascent*fontSize # normalize columnCount = 0 count = 0 callout = getattr(self,'callout',None) for col, name in colorNamePairs: T = string.split(name and str(name) or '','\n') S = [] # thisy+dy/2 = y+leading/2 y = thisy+(dy-ascent)*0.5 if callout: callout(self,g,thisx,y,colorNamePairs[count]) if alignment == "left": for t in T: # align text to left s = String(thisx+maxWidth,y,t) s.textAnchor = "end" S.append(s) y = y-leading x = thisx+maxWidth+dxTextSpace elif alignment == "right": for t in T: # align text to right s = String(thisx+dx+dxTextSpace, y, t) s.textAnchor = "start" S.append(s) y = y-leading x = thisx else: raise ValueError, "bad alignment" # Make a 'normal' color line-swatch... if isinstance(col, colors.Color): l = LineSwatch() l.x = x l.y = thisy l.width = dx l.height = dy l.strokeColor = col g.add(l) else: #try and see if we should do better. try: c = copy.deepcopy(col) c.x = x c.y = thisy c.width = dx c.height = dy g.add(c) except: pass map(gAdd,S) if count%columnMaximum == columnMaximum-1: thisx = thisx+deltax thisy = upperlefty columnCount = columnCount + 1 else: thisy = thisy-max(deltay,len(S)*leading) count = count+1 return g
from reportlab.graphics.shapes import Drawing, String, colors from reportlab.graphics import renderPDF from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont '''--- 添加中文支持 ---''' # pdfmetrics.registerFont(TTFont('msyh', 'msyh.ttf')) # 注册要使用的字体 # pdfmetrics.registerFont(TTFont('g', 'futurama.ttf')) pdfmetrics.registerFont(TTFont('song', 'SimSun.ttf')) #注册字体 STHeiti Medium.ttc '''--- 创建画布 ---''' d = Drawing(300, 200) # 创建画布并设置画布尺寸 '''--- 创建文本内容并设置样式与位置 ---''' s1 = String(150, 100, '这是中文文字测试') # 创建字符串并设置坐标、内容 s1.fontName = 'song' # 设置字体 s1.fontSize = 14 # 设置字号 s1.fillColor = colors.red # 设置字体颜色 s1.textAnchor = 'middle' # 设置锚点为中心(即位置坐标为文本中心点坐标) s2 = String(150, 120, '汉子!', fontName='song', fontSize=16, fillColor=colors.red, textAnchor='middle') # 另一种设置方式 '''--- 添加内容到画布并生成PDF文件 ---''' d.add(s1) # 将字符串添加到画布 d.add(s2) renderPDF.drawToFile(d, 'myPDF.pdf', '231231') # 生成PDF文件并设置文件名称与文档描述
def _addWedgeLabel(self,text,add,angle,labelX,labelY,wedgeStyle,labelClass=WedgeLabel): # now draw a label if self.simpleLabels: theLabel = String(labelX, labelY, text) theLabel.textAnchor = "middle" else: theLabel = labelClass() theLabel._pmv = angle theLabel.x = labelX theLabel.y = labelY theLabel.dx = wedgeStyle.label_dx theLabel.dy = wedgeStyle.label_dy theLabel.angle = wedgeStyle.label_angle theLabel.boxAnchor = wedgeStyle.label_boxAnchor theLabel.boxStrokeColor = wedgeStyle.label_boxStrokeColor theLabel.boxStrokeWidth = wedgeStyle.label_boxStrokeWidth theLabel.boxFillColor = wedgeStyle.label_boxFillColor theLabel.strokeColor = wedgeStyle.label_strokeColor theLabel.strokeWidth = wedgeStyle.label_strokeWidth _text = wedgeStyle.label_text if _text is None: _text = text theLabel._text = _text theLabel.leading = wedgeStyle.label_leading theLabel.width = wedgeStyle.label_width theLabel.maxWidth = wedgeStyle.label_maxWidth theLabel.height = wedgeStyle.label_height theLabel.textAnchor = wedgeStyle.label_textAnchor theLabel.visible = wedgeStyle.label_visible theLabel.topPadding = wedgeStyle.label_topPadding theLabel.leftPadding = wedgeStyle.label_leftPadding theLabel.rightPadding = wedgeStyle.label_rightPadding theLabel.bottomPadding = wedgeStyle.label_bottomPadding theLabel.fontSize = wedgeStyle.fontSize theLabel.fontName = wedgeStyle.fontName theLabel.fillColor = wedgeStyle.fontColor add(theLabel)
def convert_text(self, node): """ Converts a <text> element """ x, y = self._length_attrs(node, 'x', 'y') preserve_space = utils.node_preserve_space(node, self.preserve_space) gr = Group() frag_lengths = [] dx0, dy0 = 0, 0 x1, y1 = 0, 0 ff = attributes.convert_font_family( attributes.find( node, "font-family")) # default is set inside convert_... fs = attributes.convert_length( attributes.find(node, "font-size") or "12") convert_len = partial(attributes.convert_length, em_base=fs) for c in itertools.chain([node], node.getchildren()): has_x, has_y = False, False dx, dy = 0, 0 baseline_shift = 0 if node_name(c) == 'text': text = self.clean_text(c.text, preserve_space) if not text: continue elif node_name(c) == 'tspan': text = self.clean_text(c.text, preserve_space) if not text: continue x1, y1, dx, dy = [ c.attrib.get(name, '') for name in ("x", "y", "dx", "dy") ] has_x, has_y = (x1 != '', y1 != '') x1, y1, dx, dy = map(convert_len, (x1, y1, dx, dy)) dx0 = dx0 + dx dy0 = dy0 + dy baseline_shift = c.attrib.get("baseline-shift", '0') if baseline_shift in ("sub", "super", "baseline"): baseline_shift = { "sub": -fs / 2, "super": fs / 2, "baseline": 0 }[baseline_shift] else: baseline_shift = convert_len(baseline_shift, fs) else: continue frag_lengths.append(stringWidth(text, ff, fs)) new_x = (x1 + dx) if has_x else (x + dx0 + sum(frag_lengths[:-1])) new_y = (y1 + dy) if has_y else (y + dy0) shape = String(new_x, -(new_y - baseline_shift), text) self.apply_style(to_shape=shape, from_node=node) if node_name(c) == 'tspan': self.apply_style(to_shape=shape, from_node=c) gr.add(shape) gr.scale(1, -1) return gr
def __init__(self,width=400,height=200,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self.transform = (1,0,0,1,0,0) self.add(Rect(225,22.5,-93.75,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,37.5,18.75,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,52.5,31.25,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,67.5,62.5,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,82.5,50,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,97.5,43.75,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,112.5,25,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,127.5,6.25,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,142.5,62.5,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Rect(225,157.5,18.75,10,rx=0,ry=0,fillColor=Color(1,0,0,1),fillOpacity=None,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) v0=self._nn(Group()) v0.transform = (1,0,0,1,121.25,27.5) v0.add(String(-6.837,-2.4,'-1.50',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,253.75,42.5) v0.add(String(5.838,-2.4,'0.30',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,266.25,57.5) v0.add(String(5.838,-2.4,'0.50',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,297.5,72.5) v0.add(String(5.838,-2.4,'1.00',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,285,87.5) v0.add(String(5.838,-2.4,'0.80',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,278.75,102.5) v0.add(String(5.838,-2.4,'0.70',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,260,117.5) v0.add(String(5.838,-2.4,'0.40',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,241.25,132.5) v0.add(String(5.838,-2.4,'0.10',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,297.5,147.5) v0.add(String(5.838,-2.4,'1.00',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,253.75,162.5) v0.add(String(5.838,-2.4,'0.30',textAnchor='middle',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) self.add(Line(99,20,99,170,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,27.5) v0.add(String(0,-2.4,'UK Equities',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,42.5) v0.add(String(0,-2.4,'US Equities',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,57.5) v0.add(String(0,-2.4,'European Equities',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,72.5) v0.add(String(0,-2.4,'Japanese Equities',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,87.5) v0.add(String(0,-2.4,'Pacific (ex Japan) Equities',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,102.5) v0.add(String(0,-2.4,'Emerging Markets Equities',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,117.5) v0.add(String(0,-2.4,'UK Bonds',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,132.5) v0.add(String(0,-2.4,'Overseas Bonds',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,147.5) v0.add(String(0,-2.4,'UK Index-Linked',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,-71,162.5) v0.add(String(0,-2.4,'Cash',textAnchor='start',fontName='Helvetica',fontSize=6,fillColor=Color(0,0,0,1)))
def __init__(self, width=400, height=200, *args, **kw): Drawing.__init__(self, width, height, *args, **kw) self.transform = (1, 0, 0, 1, 0, 0) self.add( Line(50, 147.6562, 350, 147.6562, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 147.6562, 50, 142.6562, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(143.75, 147.6562, 143.75, 142.6562, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(237.5, 147.6562, 237.5, 142.6562, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(331.25, 147.6562, 331.25, 142.6562, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 50, 142.6562) v0.add( String(-5, -10, '10', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 143.75, 142.6562) v0.add( String(-5, -10, '20', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 237.5, 142.6562) v0.add( String(-5, -10, '30', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 331.25, 142.6562) v0.add( String(-5, -10, '40', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) self.add( Line(50, 50, 50, 175, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 50, 45, 50, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 89.0625, 45, 89.0625, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 128.125, 45, 128.125, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 167.1875, 45, 167.1875, strokeColor=Color(0, 0, 0, 1), strokeWidth=1, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=10, strokeDashArray=None, strokeOpacity=None)) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 50) v0.add( String(-10, -4, '10', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 89.0625) v0.add( String(-10, -4, '20', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 128.125) v0.add( String(-10, -4, '30', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1))) v0 = self._nn(Group()) v0.transform = (1, 0, 0, 1, 45, 167.1875) v0.add( String(-10, -4, '40', textAnchor='start', fontName='Times-Roman', fontSize=10, fillColor=Color(0, 0, 0, 1)))
from reportlab.graphics.shapes import Drawing, String from reportlab.graphics import renderPDF ''' run python + filename ''' d = Drawing(100, 100) s = String(50, 50, 'Hello, world!', textAnchor='middle') d.add(s) renderPDF.drawToFile(d, 'hello.pdf', 'A simple PDF file')
def makeSectors(self): # normalize slice data if type(self.data) in (ListType, TupleType) and type(self.data[0]) in (ListType, TupleType): #it's a nested list, more than one sequence normData = [] n = [] for l in self.data: t = self.normalizeData(l) normData.append(t) n.append(len(t)) self._seriesCount = max(n) else: normData = self.normalizeData(self.data) n = len(normData) self._seriesCount = n #labels if self.labels is None: labels = [] if type(n) not in (ListType,TupleType): labels = [''] * n else: for m in n: labels = list(labels) + [''] * m else: labels = self.labels #there's no point in raising errors for less than enough labels if #we silently create all for the extreme case of no labels. if type(n) not in (ListType,TupleType): i = n-len(labels) if i>0: labels = list(labels) + [''] * i else: tlab = 0 for m in n: tlab += m i = tlab-len(labels) if i>0: labels = list(labels) + [''] * i xradius = self.width/2.0 yradius = self.height/2.0 centerx = self.x + xradius centery = self.y + yradius if self.direction == "anticlockwise": whichWay = 1 else: whichWay = -1 g = Group() sn = 0 startAngle = self.startAngle #% 360 styleCount = len(self.slices) if type(self.data[0]) in (ListType, TupleType): #multi-series doughnut iradius = (self.height/5.0)/len(self.data) for series in normData: i = 0 for angle in series: endAngle = (startAngle + (angle * whichWay)) #% 360 if abs(startAngle-endAngle)>=1e-5: if startAngle < endAngle: a1 = startAngle a2 = endAngle else: a1 = endAngle a2 = startAngle #if we didn't use %stylecount here we'd end up with the later sectors #all having the default style sectorStyle = self.slices[i%styleCount] # is it a popout? cx, cy = centerx, centery if sectorStyle.popout != 0: # pop out the sector averageAngle = (a1+a2)/2.0 aveAngleRadians = averageAngle * pi/180.0 popdistance = sectorStyle.popout cx = centerx + popdistance * cos(aveAngleRadians) cy = centery + popdistance * sin(aveAngleRadians) if type(n) in (ListType,TupleType): theSector = Wedge(cx, cy, xradius+(sn*iradius)-iradius, a1, a2, yradius=yradius+(sn*iradius)-iradius, radius1=yradius+(sn*iradius)-(2*iradius)) else: theSector = Wedge(cx, cy, xradius, a1, a2, yradius=yradius, radius1=iradius) theSector.fillColor = sectorStyle.fillColor theSector.strokeColor = sectorStyle.strokeColor theSector.strokeWidth = sectorStyle.strokeWidth theSector.strokeDashArray = sectorStyle.strokeDashArray g.add(theSector) startAngle = endAngle text = self.getSeriesName(i,'') if text: averageAngle = (a1+a2)/2.0 aveAngleRadians = averageAngle*pi/180.0 labelRadius = sectorStyle.labelRadius labelX = centerx + (0.5 * self.width * cos(aveAngleRadians) * labelRadius) labelY = centery + (0.5 * self.height * sin(aveAngleRadians) * labelRadius) g.add(_addWedgeLabel(self,text,averageAngle,labelX,labelY,sectorStyle)) i += 1 sn += 1 else: i = 0 #single series doughnut iradius = self.height/5.0 for angle in normData: endAngle = (startAngle + (angle * whichWay)) #% 360 if abs(startAngle-endAngle)>=1e-5: if startAngle < endAngle: a1 = startAngle a2 = endAngle else: a1 = endAngle a2 = startAngle #if we didn't use %stylecount here we'd end up with the later sectors #all having the default style sectorStyle = self.slices[i%styleCount] # is it a popout? cx, cy = centerx, centery if sectorStyle.popout != 0: # pop out the sector averageAngle = (a1+a2)/2.0 aveAngleRadians = averageAngle * pi/180.0 popdistance = sectorStyle.popout cx = centerx + popdistance * cos(aveAngleRadians) cy = centery + popdistance * sin(aveAngleRadians) if n > 1: theSector = Wedge(cx, cy, xradius, a1, a2, yradius=yradius, radius1=iradius) elif n==1: theSector = Wedge(cx, cy, xradius, a1, a2, yradius=yradius, iradius=iradius) theSector.fillColor = sectorStyle.fillColor theSector.strokeColor = sectorStyle.strokeColor theSector.strokeWidth = sectorStyle.strokeWidth theSector.strokeDashArray = sectorStyle.strokeDashArray g.add(theSector) # now draw a label if labels[i] != "": averageAngle = (a1+a2)/2.0 aveAngleRadians = averageAngle*pi/180.0 labelRadius = sectorStyle.labelRadius labelX = centerx + (0.5 * self.width * cos(aveAngleRadians) * labelRadius) labelY = centery + (0.5 * self.height * sin(aveAngleRadians) * labelRadius) theLabel = String(labelX, labelY, labels[i]) theLabel.textAnchor = "middle" theLabel.fontSize = sectorStyle.fontSize theLabel.fontName = sectorStyle.fontName theLabel.fillColor = sectorStyle.fontColor g.add(theLabel) startAngle = endAngle i += 1 return g
from reportlab.graphics.shapes import Drawing, String from reportlab.graphics import renderPDF d = Drawing(100, 100) s = String(50, 50, "Hello, World!", textAnchor="middle") d.add(s) renderPDF.drawToFile(d, "hello.pdf", "A simple PDF file")
def convertText(self, node): attrConv = self.attrConverter xml_space = node.getAttribute("{%s}space" % XML_NS) if xml_space: preserve_space = xml_space == 'preserve' else: preserve_space = self.preserve_space gr = Group() frag_lengths = [] dx0, dy0 = 0, 0 x1, y1 = 0, 0 ff = attrConv.findAttr(node, "font-family") or DEFAULT_FONT_NAME ff = attrConv.convertFontFamily(ff) fs = attrConv.findAttr(node, "font-size") or "12" fs = attrConv.convertLength(fs) convertLength = partial(attrConv.convertLength, em_base=fs) x, y = map(node.getAttribute, ('x', 'y')) x, y = map(convertLength, (x, y)) for c in itertools.chain([node], node.getchildren()): has_x, has_y = False, False dx, dy = 0, 0 baseLineShift = 0 if node_name(c) == 'text': text = self.clean_text(c.text, preserve_space) if not text: continue elif node_name(c) == 'tspan': text = self.clean_text(c.text, preserve_space) if not text: continue x1, y1, dx, dy = [ c.attrib.get(name, '') for name in ("x", "y", "dx", "dy") ] has_x, has_y = (x1 != '', y1 != '') x1, y1, dx, dy = map(convertLength, (x1, y1, dx, dy)) dx0 = dx0 + dx dy0 = dy0 + dy baseLineShift = c.attrib.get("baseline-shift", '0') if baseLineShift in ("sub", "super", "baseline"): baseLineShift = { "sub": -fs / 2, "super": fs / 2, "baseline": 0 }[baseLineShift] else: baseLineShift = convertLength(baseLineShift, fs) else: continue frag_lengths.append(stringWidth(text, ff, fs)) new_x = (x1 + dx) if has_x else (x + dx0 + sum(frag_lengths[:-1])) new_y = (y1 + dy) if has_y else (y + dy0) shape = String(new_x, -(new_y - baseLineShift), text) self.applyStyleOnShape(shape, node) if node_name(c) == 'tspan': self.applyStyleOnShape(shape, c) gr.add(shape) gr.scale(1, -1) return gr