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, 300, 100, strokeColor=Color(0, 0, 1, 1), strokeWidth=14.17323, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=None, strokeOpacity=None)) self.add( Line(50, 100, 300, 50, strokeColor=Color(0, 0, 1, 1), strokeWidth=14.17323, strokeLineCap=0, strokeLineJoin=0, strokeMiterLimit=0, strokeDashArray=[5, 10, 15], strokeOpacity=None))
def y_axis_tics(x_axis, y_axis, side): if side == "left": x1 = scale(x_axis["min"], x_axis) - 4 x2 = scale(x_axis["min"], x_axis) else: x1 = scale(x_axis["max"], x_axis) x2 = scale(x_axis["max"], x_axis) + 2 tics = [ Line(scale(x_axis["min"], x_axis), scale(y_axis["min"], y_axis), scale(x_axis["max"], x_axis), scale(y_axis["min"], y_axis), strokeWidth=0.5) ] for tic in y_axis["tics"]: tics.append( Line(x1, scale(tic, y_axis), x2, scale(tic, y_axis), strokeWidth=0.5)) return tics
def _draw_segment(self, cur_drawing): """Draw the current chromosome segment.""" # set the coordinates of the segment -- it'll take up the MIDDLE part # of the space we have. segment_y = self.end_y_position segment_width = (self.end_x_position - self.start_x_position) \ * self.chr_percent segment_height = self.start_y_position - self.end_y_position segment_x = self.start_x_position \ + 0.5 * (self.end_x_position - self.start_x_position - segment_width) # first draw the sides of the segment right_line = Line(segment_x, segment_y, segment_x, segment_y + segment_height) left_line = Line(segment_x + segment_width, segment_y, segment_x + segment_width, segment_y + segment_height) cur_drawing.add(right_line) cur_drawing.add(left_line) # now draw the box, if it is filled in if self.fill_color is not None: fill_rectangle = Rect(segment_x, segment_y, segment_width, segment_height) fill_rectangle.fillColor = self.fill_color fill_rectangle.strokeColor = None cur_drawing.add(fill_rectangle)
def nextPagesHeader(self, isSecondPage): if isSecondPage: psHeaderText = ParagraphStyle('Hed0', fontSize=16, alignment=TA_LEFT, borderWidth=3, textColor=self.colorOhkaGreen0) text = 'REPORTE DE SESIONES' paragraphReportHeader = Paragraph(text, psHeaderText) self.elements.append(paragraphReportHeader) spacer = Spacer(10, 10) self.elements.append(spacer) d = Drawing(500, 1) line = Line(-15, 0, 483, 0) line.strokeColor = self.colorOhkaGreenLineas line.strokeWidth = 2 d.add(line) self.elements.append(d) spacer = Spacer(10, 1) self.elements.append(spacer) d = Drawing(500, 1) line = Line(-15, 0, 483, 0) line.strokeColor = self.colorOhkaGreenLineas line.strokeWidth = 0.5 d.add(line) self.elements.append(d) spacer = Spacer(10, 22) self.elements.append(spacer)
def addCross(d, x, y, w=5, h=5, strokeColor='black', strokeWidth=0.5): w *= 0.5 h *= 0.5 d.add( Line(x - w, y, x + w, y, strokeWidth=0.5, strokeColor=colors.blue)) d.add( Line(x, y - h, x, y + h, strokeWidth=0.5, strokeColor=colors.blue))
def annotation(self,xScale,yScale): x = xScale(xv) y = yScale(yv) g = Group() xA = xScale.__self__ #the x axis g.add(Line(xA._x,y,xA._x+xA._length,y,strokeColor=strokeColor,strokeWidth=strokeWidth)) yA = yScale.__self__ #the y axis g.add(Line(x,yA._y,x,yA._y+yA._length,strokeColor=strokeColor,strokeWidth=strokeWidth)) return g
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 left_labels = _place_labels(left_labels, y_min, y_max, h) right_labels = _place_labels(right_labels, y_min, y_max, h) x1 = segment_x x2 = segment_x - label_sep for (y1, y2, color, name) in left_labels: cur_drawing.add( Line(x1, y1, x2, y2, strokeColor=color, strokeWidth=0.25)) label_string = String(x2, y2, name, textAnchor="end") label_string.fontName = 'Helvetica' label_string.fontSize = self.label_size if color_label: label_string.fillColor = color cur_drawing.add(label_string) x1 = segment_x + segment_width x2 = segment_x + segment_width + label_sep for (y1, y2, color, name) in right_labels: cur_drawing.add( Line(x1, y1, x2, y2, strokeColor=color, strokeWidth=0.25)) label_string = String(x2, y2, name) label_string.fontName = 'Helvetica' label_string.fontSize = self.label_size if color_label: label_string.fillColor = color cur_drawing.add(label_string)
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(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,225,70) v0.add(String(-10,-10,'Ying',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1)))
def makeBackground(self): if self.background is not None: BG = self.background if isinstance(BG,Group): g = BG for bg in g.contents: bg.x = self.x bg.y = self.y bg.width = self.width bg.height = self.height else: g = Group() if type(BG) not in (type(()),type([])): BG=(BG,) for bg in BG: bg.x = self.x bg.y = self.y bg.width = self.width bg.height = self.height g.add(bg) return g else: strokeColor,strokeWidth,fillColor=self.strokeColor, self.strokeWidth, self.fillColor if (strokeWidth and strokeColor) or fillColor: g = Group() _3d_dy = getattr(self,'_3d_dy',None) x = self.x y = self.y h = self.height w = self.width if _3d_dy is not None: _3d_dx = self._3d_dx if fillColor and not strokeColor: from reportlab.lib.colors import Blacker c = Blacker(fillColor, getattr(self,'_3d_blacken',0.7)) else: c = strokeColor if not strokeWidth: strokeWidth = 0.5 if fillColor or strokeColor or c: bg = Polygon([x,y,x,y+h,x+_3d_dx,y+h+_3d_dy,x+w+_3d_dx,y+h+_3d_dy,x+w+_3d_dx,y+_3d_dy,x+w,y], strokeColor=strokeColor or c or grey, strokeWidth=strokeWidth, fillColor=fillColor) g.add(bg) g.add(Line(x,y,x+_3d_dx,y+_3d_dy, strokeWidth=0.5, strokeColor=c)) g.add(Line(x+_3d_dx,y+_3d_dy, x+_3d_dx,y+h+_3d_dy,strokeWidth=0.5, strokeColor=c)) fc = Blacker(c, getattr(self,'_3d_blacken',0.8)) g.add(Polygon([x,y,x+_3d_dx,y+_3d_dy,x+w+_3d_dx,y+_3d_dy,x+w,y], strokeColor=strokeColor or c or grey, strokeWidth=strokeWidth, fillColor=fc)) bg = Line(x+_3d_dx,y+_3d_dy, x+w+_3d_dx,y+_3d_dy,strokeWidth=0.5, strokeColor=c) else: bg = None else: bg = Rect(x, y, w, h, strokeColor=strokeColor, strokeWidth=strokeWidth, fillColor=fillColor) if bg: g.add(bg) return g else: return None
def _Flag_Switzerland(self): s = _size g = Group() self._width = s g.add(Rect(0, 0, s, s, fillColor = colors.red, strokeColor = colors.black, strokeWidth=0)) g.add(Line((s/2), (s/5.5), (s/2), (s-(s/5.5)), fillColor = colors.mintcream, strokeColor = colors.mintcream, strokeWidth=(s/5))) g.add(Line((s/5.5), (s/2), (s-(s/5.5)), (s/2), fillColor = colors.mintcream, strokeColor = colors.mintcream, strokeWidth=s/5)) 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(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(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 hdimarrow_outside(dim, scale, x, y, strwid, boundsln_len): """Return a horizontal outer dimension arrow for a flat panel drawing. The return value is a Group. dim is the dimension measurement. scale is the scale of the drawing. x, y are the coordinates of the left end of the arrow. strwid is the stroke width of the lines. boundsln_len is the length of the dimension bounds lines. """ x2, y2 = x + dim * inch * scale, y result = Group( # Boundary lines Line(x, y - boundsln_len / 2, x, y + boundsln_len / 2, strokeWidth=strwid), Line(x2, y2 - boundsln_len / 2, x2, y2 + boundsln_len / 2, strokeWidth=strwid), # Left outside arrow Line(x - 11, y, x, y, strokeWidth=strwid), Line(x - 5.5, y + 2, x, y, strokeWidth=strwid), Line(x - 5.5, y - 2, x, y, strokeWidth=strwid), # Right outside arrow Line(x2, y2, x2 + 11, y2, strokeWidth=strwid), Line(x2, y2, x2 + 5.5, y2 + 2, strokeWidth=strwid), Line(x2, y2, x2 + 5.5, y2 - 2, strokeWidth=strwid)) return result
def makeSwatchSample(self, rowNo, x, y, width, height): baseStyle = self.strands styleIdx = rowNo % len(baseStyle) style = baseStyle[styleIdx] strokeColor = getattr(style, 'strokeColor', getattr(baseStyle,'strokeColor',None)) fillColor = getattr(style, 'fillColor', getattr(baseStyle,'fillColor',None)) strokeDashArray = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None)) strokeWidth = getattr(style, 'strokeWidth', getattr(baseStyle, 'strokeWidth',0)) symbol = getattr(style, 'symbol', getattr(baseStyle, 'symbol',None)) ym = y+height/2.0 if fillColor is None and strokeColor is not None and strokeWidth>0: bg = Line(x,ym,x+width,ym,strokeWidth=strokeWidth,strokeColor=strokeColor, strokeDashArray=strokeDashArray) elif fillColor is not None: bg = Rect(x,y,width,height,strokeWidth=strokeWidth,strokeColor=strokeColor, strokeDashArray=strokeDashArray,fillColor=fillColor) else: bg = None if symbol: symbol = uSymbol2Symbol(symbol,x+width/2.,ym,color) if bg: g = Group() g.add(bg) g.add(symbol) return g return symbol or bg
def _PDFElements(self, doc, content): time_now = time.strftime("%I:%M:%S:%p %m-%d-%Y", time.gmtime()) elements = [] content['report'].insert(0, ["kiloWatts/month", "Date"]) # table headers Hstyle = getSampleStyleSheet() Hstyle = Hstyle["BodyText"] Hstyle.alignment = TA_CENTER Hstyle.fontSize = 28 Hstyle.spaceBefore = 20 Hstyle.spaceAfter = 10 data = content['report'] I = Image('assets/images/ql-logo.jpg', 520, 475) I.drawHeight = 10 * cm I.drawWidth = 40 * cm H1 = Paragraph("Monthly Energy", Hstyle) H2 = Paragraph("Consumption Report", Hstyle) d = Drawing(800, 18) d.add(Line(0, 0, 570, 0)) s = getSampleStyleSheet() s = s["Normal"] s.alignment = TA_CENTER date = Paragraph(time_now, s) page = "GENERATED BY User at " + time_now x = 128 style = TableStyle([ ('ALIGN', (0, 0), (-1, -1), 'CENTER'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('TEXTCOLOR', (1, 1), (1, 1), colors.black), ('TEXTCOLOR', (0, 0), (0, 0), colors.blue), ('ALIGN', (0, -1), (0, -1), 'CENTER'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('TEXTCOLOR', (0, -1), (0, -1), colors.black), ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black), ('BOX', (0, 0), (-1, -1), 0.25, colors.black), ]) s.wordWrap = 'LTR' s.fontSize = 14 data2 = [[Paragraph(cell, s) for cell in row] for row in data] if len(data2) < 2: data2.insert(1, ['no data', 'no data']) t = Table(data2, (50 * cm, 50 * cm), [13 * cm] * len(data2), style=style, spaceBefore=50, spaceAfter=100) elements.append(I) elements.append(H1) elements.append(H2) elements.append(d) elements.append(date) elements.append(t) return elements
def makeSwatchSample(self,rowNo, x, y, width, height): baseStyle = self.lines styleIdx = rowNo % len(baseStyle) style = baseStyle[styleIdx] color = style.strokeColor yh2 = y+height/2. lineStyle = getattr(style,'lineStyle',None) if lineStyle=='bar': dash = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None)) strokeWidth= getattr(style, 'strokeWidth', getattr(style, 'strokeWidth',None)) L = Rect(x,y,width,height,strokeWidth=strokeWidth,strokeColor=color,strokeLineCap=0,strokeDashArray=dash,fillColor=getattr(style,'fillColor',color)) elif self.joinedLines or lineStyle=='joinedLine': dash = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None)) strokeWidth= getattr(style, 'strokeWidth', getattr(style, 'strokeWidth',None)) L = Line(x,yh2,x+width,yh2,strokeColor=color,strokeLineCap=0) if strokeWidth: L.strokeWidth = strokeWidth if dash: L.strokeDashArray = dash else: L = None if hasattr(style, 'symbol'): S = style.symbol elif hasattr(baseStyle, 'symbol'): S = baseStyle.symbol else: S = None if S: S = uSymbol2Symbol(S,x+width/2.,yh2,color) if S and L: g = Group() g.add(L) g.add(S) return g return S or L
def convertLine(self, node): getAttr = node.getAttribute x1, y1, x2, y2 = map(getAttr, ("x1", "y1", "x2", "y2")) x1, y1, x2, y2 = map(self.attrConverter.convertLength, (x1, y1, x2, y2)) shape = Line(x1, y1, x2, y2) return shape
def p_header(self, canvas, ldoc): """Set up the header for all portrait pages""" canvas.saveState() self.header_line.wrap(ldoc.width, ldoc.topMargin) self.header_line.drawOn(canvas, ldoc.leftMargin + 40, ldoc.height + ldoc.topMargin + 40) self.logo.drawHeight = 0.6 * cm self.logo.drawWidth = 1.9 * cm self.logo.drawOn(canvas, ldoc.leftMargin - 20, ldoc.height + ldoc.topMargin + 45) self.emblem1.drawHeight = 0.6 * cm self.emblem1.drawWidth = 0.6 * cm self.emblem1.drawOn(canvas, ldoc.width + 75, ldoc.height + ldoc.topMargin + 45) d = Drawing(ldoc.width, 1) d.add( Line(0, 0, ldoc.width + 40, 0, strokeWidth=0.1, strokeColor=ReportColors.get_my_blue())) d.drawOn(canvas, ldoc.leftMargin - 20, ldoc.height + ldoc.topMargin + 40) canvas.restoreState()
def create_horizontal_line(): """ Create horizontal line on the page """ d = Drawing(100, 1) d.add(Line(0, 0, 1000, 0)) return d
def __init__(self, width=400, height=200, *args, **kw): Drawing.__init__(self, width, height, *args, **kw) #for x1,y1, x2,y2 in diagonalLines(45, 5, [Polygon([5,5, 5,100, 99,105, 105,5])]): self._add(self,Line(x1,y1,x2,y2,strokeWidth=1,strokeColor=toColor('black')),name=None,validate=None,desc=None) self._add(self, Hatching(spacing=(30, 30, 30), angles=(45, 0, -45), xyLists=[5, 5, 5, 100, 99, 105, 105, 5], strokeWidth=0.1, strokeColor=toColor('red'), strokeDashArray=None), name='hatching', validate=None, desc=None) self.width = 110 self.height = 110 self._add(self, Line(0, 105, 110, 105, strokeWidth=0.5, strokeColor=toColor('blue')), name=None, validate=None, desc=None)
def __call__(self,legend, g, x, xt, y, width, lWidth): from reportlab.graphics.shapes import String, Line fontSize = self.fontSize fontName = self.fontName fillColor = self.fillColor strokeColor = self.strokeColor strokeWidth = self.strokeWidth ascent=getFont(fontName).face.ascent/1000. if ascent==0: ascent=0.718 # default (from helvetica) ascent *= fontSize leading = fontSize*1.2 yt = y+self.dy-ascent*1.3 if self.lText and fillColor: g.add(String(xt,yt,self.lText, fontName=fontName, fontSize=fontSize, fillColor=fillColor, textAnchor = "start")) if self.rText: g.add(String(xt+width,yt,self.rText, fontName=fontName, fontSize=fontSize, fillColor=fillColor, textAnchor = "end")) if strokeWidth and strokeColor: yL = y+self.dly-leading g.add(Line(x+self.dlx[0],yL,x+self.dlx[1]+lWidth,yL, strokeColor=strokeColor, strokeWidth=strokeWidth, strokeDashArray=self.strokeDashArray))
def get_key_symbol(x, y, element_type, color): return { "line": Line(x, y + 3, x + 10, y + 3, strokeColor=color, strokeWidth=3), "circle": Circle(x + 6, y + 3, 2, fillColor=color, strokeColor=color), "rect": Rect(x + 6, y, 4, 4, fillColor=color, strokeColor=color), }[element_type]
def right_axis_line(x_axis, y_axis): return [ Line(scale(x_axis["max"], x_axis), scale(y_axis["min"], y_axis), scale(x_axis["max"], x_axis), scale(y_axis["max"], y_axis), strokeWidth=0.5) ]
def vdimarrow_iso(dim, scale, x, y, strwid, boundsln_len): """Return a vertical dimension arrow for the isometric drawing. The isometric version of the dimension arrow has angled boundary lines and arrowheads. dim is the dimension measurement. scale is the scale of the drawing. x, y are the coordinates of the bottom end of the arrow. strwid is the stroke width of the lines. boundsln_len is the length of the dimension bounds lines. """ x2, y2 = x, y + dim * inch * scale off = math.sqrt((boundsln_len / 2)**2 / 2) result = Group( # Arrow Line(x, y, x2, y2, strokeWidth=strwid), # Bottom arrowhead Line(x, y, x - 1.25, y + 5.5 - 1.25, strokeWidth=strwid), Line(x, y, x + 1.25, y + 5.5 + 1.25, strokeWidth=strwid), # Top arrowhead Line(x2 - 1.25, y2 - 5.5 - 1.25, x2, y2, strokeWidth=strwid), Line(x2 + 1.25, y2 - 5.5 + 1.25, x2, y2, strokeWidth=strwid), # Boundary lines Line(x - off, y - off, x + off, y + off, strokeWidth=strwid), Line(x2 - off, y2 - off, x2 + off, y2 + off, strokeWidth=strwid)) return result
def vdimarrow(dim, scale, x, y, strwid, boundsln_len): """Return a vertical dimension arrow for a flat panel drawing. The return value is a Group. dim is the dimension measurement. scale is the scale of the drawing. x, y are the coordinates of the bottom end of the arrow. strwid is the stroke width of the lines. boundsln_len is the length of the dimension bounds lines. """ x2, y2 = x, y + dim * inch * scale result = Group( # Arrow Line(x, y, x2, y2, strokeWidth=strwid), # Bottom arrowhead Line(x, y, x - 2, y + 5.5, strokeWidth=strwid), Line(x, y, x + 2, y + 5.5, strokeWidth=strwid), # Top arrowhead Line(x2, y2, x2 - 2, y2 - 5.5, strokeWidth=strwid), Line(x2, y2, x2 + 2, y2 - 5.5, strokeWidth=strwid), # Boundary lines Line(x - boundsln_len / 2, y, x + boundsln_len / 2, y, strokeWidth=strwid), Line(x2 - boundsln_len / 2, y2, x2 + boundsln_len / 2, y2, strokeWidth=strwid)) return result
def x_axis_tics(x_axis, y_axis): tics = [ Line(scale(x_axis["min"], x_axis), scale(y_axis["min"], y_axis), scale(x_axis["min"], x_axis), scale(y_axis["max"], y_axis), strokeWidth=0.5) ] for tic in x_axis["tics"]: tics.append( Line(scale(tic, x_axis), scale(y_axis["min"], y_axis), scale(tic, x_axis), scale(y_axis["min"], y_axis) - 4, strokeWidth=0.5)) return tics
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,53.47222,50,13.88889,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,115.9722,300,13.88889,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,67.36111,100,13.88889,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,129.8611,250,13.88889,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,81.25,150,13.88889,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,143.75,200,13.88889,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,95.13889,200,13.88889,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,157.6389,150,13.88889,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 c_square(self, **kwargs): """return a drawing the a^2+b^2 part of the pythagorean""" show_grid = kwargs.get('show_grid', 0) count_squares = kwargs.get('count_squares', 0) drawing = Drawing(self.size, self.size) angle = math.atan(1. * self.a / self.b) * 180 / math.pi print("fotate:", angle) drawing.rotate(angle) c = math.pow(self.a * self.a + self.b * self.b, 0.5) print("c:", c) step = 1. * self.size / (self.a + self.b) if show_grid: i = 1 while i <= c: drawing.add( Line(0, i * step, self.size, i * step, strokeColor=self.grid_color)) drawing.add( Line(i * step, 0, i * step, self.size, strokeColor=self.grid_color)) i += 1 drawing.add( Rect(self.a, 0, c, c, fillColor=self.fill_color, strokeColor=self.stroke_color)) #drawing.rotate(-angle) drawing.add( Rect(0, 0, self.size, self.size, fillColor=self.fill_color, strokeColor=self.stroke_color)) 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(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(60,50,40,20.83333,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(270,50,40,125,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(110,50,40,41.66667,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(320,50,40,104.1667,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(160,50,40,62.5,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(370,50,40,83.33333,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(210,50,40,83.33333,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(420,50,40,62.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(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,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 _draw_segment(self, cur_drawing): """Draw a half circle representing the end of a linear chromosome. """ # set the coordinates of the segment -- it'll take up the left part # of the space we have. width = (self.end_x_position - self.start_x_position) \ * self.chr_percent height = self.start_y_position - self.end_y_position center_x = self.start_x_position + width / 2 if self._inverted: center_y = self.start_y_position start_angle = 180 end_angle = 360 else: center_y = self.end_y_position start_angle = 0 end_angle = 180 cap_wedge = Wedge(center_x, center_y, width / 2, start_angle, end_angle, height / 2) cap_wedge.fillColor = self.fill_color cur_drawing.add(cap_wedge) # draw a line to cover up the the bottom part of the wedge if self._inverted: cover_line = Line(self.start_x_position, self.start_y_position, self.start_x_position + width, self.start_y_position) else: cover_line = Line(self.start_x_position, self.end_y_position, self.start_x_position + width, self.end_y_position) if self.fill_color is not None: cover_color = self.fill_color else: cover_color = colors.white cover_line.strokeColor = cover_color cur_drawing.add(cover_line)
def __init__(self,width=400,height=200,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) smallFontSize = float(os.environ.get('smallFontSize','40')) self._add(self,String(65,10,'text0',fontSize=80,fontName='Helvetica',fillColor=toColor('blue'),strokeColor=toColor('red'),strokeWidth=1.5,textRenderMode=0),name='S0',validate=None,desc=None) self._add(self,String(405,20,'text1',fontSize=80,fontName='Helvetica',fillColor=toColor('blue'),strokeColor=toColor('red'),strokeWidth=1.5,textRenderMode=1, textAnchor='end'),name='S1',validate=None,desc=None) self._add(self,String(190,90,'text2',fontSize=80,fontName='Helvetica',fillColor=toColor('blue'),strokeColor=toColor('red'),strokeWidth=1.5,textRenderMode=2),name='S2',validate=None,desc=None) self._add(self,String(240,150,'text3',fontSize=smallFontSize,fontName='Helvetica',fillColor=toColor('green'),strokeColor=toColor('magenta'),strokeWidth=0.5,textRenderMode=2),name='S3',validate=None,desc=None) self._add(self,String(140,150,'text4',fontSize=smallFontSize,fontName='Helvetica',fillColor=toColor('green'),strokeColor=toColor('magenta'),strokeWidth=0.5,textRenderMode=1),name='S4',validate=None,desc=None) self._add(self,String(70,120,'text5',fontSize=smallFontSize,fontName='Helvetica',fillColor=toColor('green'),strokeColor=toColor('magenta'),strokeWidth=0.5,textRenderMode=0),name='S5',validate=None,desc=None) self._add(self,Line(40,40,70,70,strokeWidth=0.5,strokeColor=toColor('green')),name='L0',validate=None,desc=None) self._add(self,definePath([('moveTo',80,80),('lineTo',110,110),('lineTo',80,110),'closePath'],fillColor=None,strokeWidth=2,strokeColor=toColor('yellow')),name='P0',validate=None,desc=None)