def makeSwatchSample(self,rowNo, x, y, width, height): styleCount = len(self.lines) styleIdx = rowNo % styleCount rowColor = self.lines[styleIdx].strokeColor if self.joinedLines: dash = getattr(self.lines[styleIdx], 'strokeDashArray', getattr(self.lines,'strokeDashArray',None)) strokeWidth= getattr(self.lines[styleIdx], 'strokeWidth', getattr(self.lines[styleIdx], 'strokeWidth',None)) L = Line(x,y,x+width,y+height,strokeColor=rowColor,strokeLineCap=0) if strokeWidth: L.strokeWidth = strokeWidth if dash: L.strokeDashArray = dash else: L = None if hasattr(self.lines[styleIdx], 'symbol'): S = self.lines[styleIdx].symbol elif hasattr(self.lines, 'symbol'): S = self.lines.symbol else: S = None if S: S = uSymbol2Symbol(S,x+width/2.,y+height/2.,rowColor) if S and L: g = Group() g.add(S) g.add(L) return g return S or L
def makeSwatchSample(self,rowNo, x, y, width, height): baseStyle = self.lines styleIdx = rowNo % len(baseStyle) style = baseStyle[styleIdx] color = style.strokeColor y = y+height/2. if self.joinedLines: dash = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None)) strokeWidth= getattr(style, 'strokeWidth', getattr(style, 'strokeWidth',None)) L = Line(x,y,x+width,y,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.,y,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 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 hdimarrow(dim, scale, x, y, strwid, boundsln_len): """Return a horizontal 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), # Arrow shaft Line(x, y, x2, y2, strokeWidth=strwid), # Left arrowhead Line(x, y, x + 5.5, y + 2, strokeWidth=strwid), Line(x, y, x + 5.5, y - 2, strokeWidth=strwid), # Right arrowhead Line(x2 - 5.5, y2 + 2, x2, y2, strokeWidth=strwid), Line(x2 - 5.5, y2 - 2, x2, 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(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 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(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 _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)
def ab_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) apb = self.a + self.b step = 1. * self.size / apb if show_grid: for i in range(1, apb): 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)) drawing.add( Line(0, self.b * step, self.size, self.b * step, strokeColor=self.stroke_color)) drawing.add( Line(self.a * step, 0, self.a * step, self.size, strokeColor=self.stroke_color)) drawing.add( Rect(0, 0, self.size, self.size, fillColor=self.fill_color, strokeColor=self.stroke_color)) return drawing
def annotation(self, xScale, yScale): x = xScale(xv) y = yScale(yv) g = Group() xA = xScale.im_self #the x axis g.add( Line(xA._x, y, xA._x + xA._length, y, strokeColor=strokeColor, strokeWidth=strokeWidth)) yA = yScale.im_self #the y axis g.add( Line(x, yA._y, x, yA._y + yA._length, strokeColor=strokeColor, strokeWidth=strokeWidth)) return g
def __init__(self,width=400,height=400,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self.transform = (1,0,0,1,0,0) self.add(Polygon(points=[108.3032,252.9412,200,288.2353,291.6968,252.9412,306.9796,138.2353,200,58.82353,93.02039,138.2353,108.3032,252.9412],fillColor=Color(1,.972549,.862745,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Polygon(points=[85.37899,266.1765,200,252.9412,261.1312,235.2941,276.414,155.8824,200,94.11765,131.2274,160.2941,85.37899,266.1765],fillColor=Color(0,1,1,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Polygon(points=[138.8688,235.2941,200,261.7647,261.1312,235.2941,329.9038,125,200,164.7059,108.3032,147.0588,138.8688,235.2941],fillColor=Color(.596078,.984314,.596078,1),fillOpacity=None,strokeColor=None,strokeWidth=0,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[108.3032,252.9412,200,288.2353,291.6968,252.9412,306.9796,138.2353,200,58.82353,93.02039,138.2353,108.3032,252.9412],strokeColor=Color(1,.972549,.862745,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[85.37899,266.1765,200,252.9412,261.1312,235.2941,276.414,155.8824,200,94.11765,131.2274,160.2941,85.37899,266.1765],strokeColor=Color(0,1,1,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(PolyLine(points=[138.8688,235.2941,200,261.7647,261.1312,235.2941,329.9038,125,200,164.7059,108.3032,147.0588,138.8688,235.2941],strokeColor=Color(.596078,.984314,.596078,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(200,200,200,350,strokeColor=Color(0,0,0,1),strokeWidth=.5,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=(2,2),strokeOpacity=None)) self.add(Line(200,200,329.9038,275,strokeColor=Color(0,0,0,1),strokeWidth=.5,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=(2,2),strokeOpacity=None)) self.add(Line(200,200,329.9038,125,strokeColor=Color(0,0,0,1),strokeWidth=.5,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=(2,2),strokeOpacity=None)) self.add(Line(200,200,200,50,strokeColor=Color(0,0,0,1),strokeWidth=.5,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=(2,2),strokeOpacity=None)) self.add(Line(200,200,70.09619,125,strokeColor=Color(0,0,0,1),strokeWidth=.5,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=(2,2),strokeOpacity=None)) self.add(Line(200,200,70.09619,275,strokeColor=Color(0,0,0,1),strokeWidth=.5,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=(2,2),strokeOpacity=None)) v0=self._nn(Group()) v0.transform = (1,0,0,1,200,357.5) v0.add(String(-2.22,-4,'a',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,336.399,278.75) v0.add(String(-2.5,-4,'b',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,336.399,121.25) v0.add(String(-2.22,-4,'c',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,200,42.5) v0.add(String(-2.5,-4,'d',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,63.601,121.25) v0.add(String(-2.22,-4,'e',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) v0=self._nn(Group()) v0.transform = (1,0,0,1,63.601,278.75) v0.add(String(-1.665,-4,'f',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1)))
def conv_plot(conv_data, conv_maxs): data = [] colors = [] widths = [] names = [] for k, u in sorted(conv_data.items(), key=lambda x: int(x[0])): data.append([(float(d[0]), float(d[1][0])) for d in u]) data.append([(float(d[0]), float(d[1][1])) for d in u]) colors += [HexColor(multi_color(int(k)))] * 2 widths += [2.0, 0.2] names += [[multi_name(int(k)), HexColor(multi_color(int(k)))]] lpt, _, _ = PGPlot.line_plot(data, colors, widths, conv_maxs[0], conv_maxs[1]) drw = Drawing(width=500, height=220) lpt.x, lpt.y = 100, 15 lpt.width, lpt.height = 300, 180 drw.add(lpt) sh = drw.height - 35 dsh = 10 sx = [10, 30] for na, cl in names: drw.add( Line(lpt.x + sx[0], sh, lpt.x + sx[1], sh, strokeColor=cl, strokeWidth=2.0)) drw.add( String(lpt.x + sx[1] + 3, sh - 3, na, fontName="Arial", fontSize=10, fillColor=cl)) sh -= dsh drw.add( String(410, 2, "Total # of Config.", fontName="Arial", fontSize=12, fillColor=HexColor("#151515"))) drw.add( String(82, drw.height - 13, "# of Converged Config.", fontName="Arial", fontSize=12, fillColor=HexColor("#151515"))) return drw
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 sample_lines(sample_data, x_axis, y_axis): lines = [] samples = iter(sample_data) for idx, key in enumerate(samples): x = scale(sample_data[key], x_axis) lines.append( Line(x, scale(0, y_axis), x, scale(y_axis["max"], y_axis), strokeColor=color_arr[idx % len(color_arr)], strokeOpacity=1.0)) return lines
def histogram_lines(pop_data, x_axis, y_axis): histo_lines = [] for cn in pop_data: y = scale(pop_data[cn], y_axis) x = scale(cn, x_axis) histo_lines.append( Line(x, y, x, scale(0, y_axis), strokeColor=colors["grey"], strokeOpacity=0.3, strokeWidth=0.5)) return histo_lines
def makeBackground(self): g = Group() g.add(HorizontalLineChart.makeBackground(self)) valAxis = self.valueAxis valTickPositions = valAxis._tickValues for y in valTickPositions: y = valAxis.scale(y) g.add(Line(self.x, y, self.x+self.width, y, strokeColor = self.strokeColor)) return g
def y_axis_lines(x_axis, y_axis): lines = [] for tic in y_axis["tics"]: y = scale(tic, y_axis) lines.append( Line(scale(x_axis["min"], x_axis), y, scale(x_axis["max"], x_axis), y, strokeOpacity=0.4, strokeDashArray=[2, 2], strokeWidth=0.5)) return lines
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(284.375,50,284.375,175,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(284.375,50,279.375,50,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(284.375,89.0625,279.375,89.0625,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(284.375,128.125,279.375,128.125,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(284.375,167.1875,279.375,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,279.375,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,279.375,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,279.375,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,279.375,167.1875) v0.add(String(-10,-4,'40',textAnchor='start',fontName='Times-Roman',fontSize=10,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(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(92.85714,60.41667,55.71429,41.66667,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(92.85714,122.9167,85.71429,41.66667,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(92.85714,50,92.85714,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(157.1429,50,157.1429,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(221.4286,50,221.4286,45,strokeColor=Color(0,0,0,1),strokeWidth=1,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=10,strokeDashArray=None,strokeOpacity=None)) self.add(Line(285.7143,50,285.7143,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,92.85714,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,157.1429,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,221.4286,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,285.7143,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 _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 line_demo(): drawing = Drawing(width=400, height=200) line = Line(25, 25, 150, 150) line.strokeColor = colors.red line.strokeWidth = 5 strokeLineJoin = 2 strokeMiterLimit = 10 drawing.add(line) line = Line(125, 75, 150, 150) line.strokeWidth = 5 line.strokeLineJoin = 2 line.strokeMiterLimit = 10 drawing.add(line) points = [25,50, 35,100, 100,50, 150,150] poly = PolyLine(points=points, strokeWidth=3, strokeColor=colors.blue) drawing.add(poly) drawing.save(formats=['pdf'], outDir='.', fnRoot='line_demo')
def encabezado(self): """ agrega el encabezado al reporte :return: None """ logo = settings.MEDIA_ROOT+"logo2.png" im = Image(logo, inch, inch) im.hAlign = 'LEFT' p = Paragraph("<i>Software Gestor de Proyectos<br/>Asunción-Paraguay<br/>Contacto: 0981-222333</i>", self.estiloPR()) data_tabla = [[im, p]] tabla = Table(data_tabla) self.story.append(tabla) d = Drawing(480, 3) d.add(Line(0, 0, 480, 0)) self.story.append(d) self.story.append(Spacer(1, 0.3 * inch))
def __init__(self,width=200,height=100,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self.transform = (1,0,0,1,0,0) self.add(String(40,85.585,'red',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(String(40,65.585,'green',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(String(40,45.585,'blue',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(String(40,25.585,'yellow',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(String(100,85.585,'pink',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(String(100,65.585,'black',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(String(100,45.585,'white',textAnchor='start',fontName='Times-Roman',fontSize=10,fillColor=Color(0,0,0,1))) self.add(Line(20,88,30,88,strokeColor=Color(1,0,0,1),strokeWidth=2,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(20,68,30,68,strokeColor=Color(0,.501961,0,1),strokeWidth=2,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(20,48,30,48,strokeColor=Color(0,0,1,1),strokeWidth=2,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(20,28,30,28,strokeColor=Color(1,1,0,1),strokeWidth=2,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(80,88,90,88,strokeColor=Color(1,.752941,.796078,1),strokeWidth=2,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(80,68,90,68,strokeColor=Color(0,0,0,1),strokeWidth=2,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None)) self.add(Line(80,48,90,48,strokeColor=Color(1,1,1,1),strokeWidth=2,strokeLineCap=0,strokeLineJoin=0,strokeMiterLimit=0,strokeDashArray=None,strokeOpacity=None))
def ddimarrow_iso(dim, scale, x, y, strwid, boundsln_len): """Return a depth 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 lower left end of the arrow. strwid is the stroke width of the lines. boundsln_len is the length of the dimension bounds lines. """ dim_scaled = dim * inch * scale # `iso45' is divided by 2 below because that is how it's calculated # in the isometric_view, above. iso45 = math.sin(math.radians(45)) * dim_scaled / 2 x2, y2 = x + iso45, y + iso45 result = Group( # Arrow Line(x, y, x2, y2, strokeWidth=strwid), # Lower left arrowhead Line(x, y, x + (5.5 - 1.25) - 2.5, y + 5.5 - 1.25, strokeWidth=strwid), Line(x, y, x + (5.5 - 1.25) + 3, y + 5.5 - 1.25, strokeWidth=strwid), # Upper right arrowhead Line(x2 - (5.5 - 1.25) - 2.5, y2 - 5.5 + 1.25, x2, y2, strokeWidth=strwid), Line(x2 - (5.5 - 1.25) + 2.75, y2 - 5.5 + 1.25, x2, y2, 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 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 __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 makeInnerLines(self): # inner grid lines group = Group() w, h = self.width, self.height if self.useLines == 1: if self.orientation == 'vertical': r = self.makeLinePosList(self.x, isX=1) for x in r: line = Line(x, self.y, x, self.y + h) line.strokeColor = self.strokeColor line.strokeWidth = self.strokeWidth group.add(line) elif self.orientation == 'horizontal': r = self.makeLinePosList(self.y, isX=0) for y in r: line = Line(self.x, y, self.x + w, y) line.strokeColor = self.strokeColor line.strokeWidth = self.strokeWidth group.add(line) return group
def add_vert_line(self, x, y, color, label): i = self.x_to_i(x) j = self.y_to_j(y) self.flowable.add( Line( i, self.j_plot_offset, i, j, strokeColor=color, strokeWidth=0.75)) if not label: return group = Group( String( 0, 0, label, fontSize=self.font_size, fontName='Helvetica', textAnchor='start', fillColor=color)) group.translate(i + 1, j + 2) group.rotate(90) self.flowable.add(group)
def draw(self): l = Line(self.x,self.y,self.x+self.width,self.y) l.strokeColor = self.strokeColor l.strokeDashArray = self.strokeDashArray l.strokeWidth = self.height return l
def render(self, node, parent=None): if parent is None: parent = self.mainGroup # ignore if display = none display = node.get('display') if display == "none": return if node.tag == self.SVG_ROOT: self.level += 1 if not self.drawing is None: raise SVGError('drawing already created!') self.root = node # default styles style = { 'color':'none', 'fill':'none', 'stroke':'none', 'font-family':'Helvetica', 'font-size':'12' } self.styles[self.level] = style # iterate children for child in node: self.render(child, self.mainGroup) # create drawing width = node.get('width', '100%') height = node.get('height', '100%') if node.get("viewBox"): try: minx, miny, width, height = node.get("viewBox").split() except ValueError: raise SVGError("viewBox values not valid") if width.endswith('%') and height.endswith('%'): # handle relative size wscale = parseLength(width) / 100. hscale = parseLength(height) / 100. xL,yL,xH,yH = self.mainGroup.getBounds() self.drawing = Drawing(xH*wscale + xL, yH*hscale + yL) else: self.drawing = Drawing(parseLength(width), parseLength(height)) height = self.drawing.height self.mainGroup.scale(1, -1) self.mainGroup.translate(0, -height) self.drawing.add(self.mainGroup) self.level -= 1 return self.drawing elif node.tag in (self.SVG_G, self.SVG_A): self.level += 1 # set this levels style style = self.styles[self.level - 1].copy() style = self.nodeStyle(node, style) self.styles[self.level] = style group = Group() # iterate children for child in node: self.render(child, group) parent.add(group) transforms = node.get('transform') if transforms: for op in parseTransform.iterparse(transforms): self.applyTransformOnGroup(group, op) self.level -= 1 elif node.tag == self.SVG_USE: self.level += 1 # set this levels style style = self.styles[self.level - 1].copy() style = self.nodeStyle(node, style) self.styles[self.level] = style group = Group() # link id link_id = node.get(self.LINK).lstrip('#') # find linked node in defs or symbol section target = None for defs in self.root.getiterator(self.SVG_DEFS): for element in defs: if element.get('id') == link_id: target = element break if target is None: for defs in self.root.getiterator(self.SVG_SYMBOL): for element in defs: if element.get('id') == link_id: target = element break if target is None: msg = "Could not find use node '%s'" % link_id raise SVGError(msg) self.render(target, group) parent.add(group) # apply transform transforms = node.get('transform') if transforms: for op in parseTransform.iterparse(transforms): self.applyTransformOnGroup(group, op) # apply 'x' and 'y' attribute as translation of defs object if node.get('x') or node.get('y'): dx = parseLength(node.get('x','0')) dy = parseLength(node.get('y','0')) self.applyTransformOnGroup(group, ('translate', (dx,dy))) self.level -= 1 elif node.tag == self.SVG_LINE: # get coordinates x1 = parseLength(node.get('x1', '0')) y1 = parseLength(node.get('y1', '0')) x2 = parseLength(node.get('x2', '0')) y2 = parseLength(node.get('y2', '0')) shape = Line(x1, y1, x2, y2) self.addShape(parent, node, shape) elif node.tag == self.SVG_RECT: # get coordinates x = parseLength(node.get('x', '0')) y = parseLength(node.get('y', '0')) width = parseLength(node.get('width')) height = parseLength(node.get('height')) rx = parseLength(node.get('rx', '0')) ry = parseLength(node.get('ry', '0')) shape = Rect(x, y, width, height, rx=rx, ry=ry) self.addShape(parent, node, shape) elif node.tag == self.SVG_CIRCLE: cx = parseLength(node.get('cx', '0')) cy = parseLength(node.get('cy', '0')) r = parseLength(node.get('r')) if r > 0.: shape = Circle(cx, cy, r) self.addShape(parent, node, shape) elif node.tag == self.SVG_ELLIPSE: cx = parseLength(node.get('cx', '0')) cy = parseLength(node.get('cy', '0')) rx = parseLength(node.get('rx')) ry = parseLength(node.get('ry')) if rx > 0. and ry > 0.: shape = Ellipse(cx, cy, rx, ry) self.addShape(parent, node, shape) elif node.tag == self.SVG_POLYLINE: # convert points points = node.get('points').strip() if len(points) == 0: return points = list(map(parseLength, re.split('[ ,]+', points))) # Need to use two shapes, because standard RLG polylines # do not support filling... group = Group() shape = Polygon(points) self.applyStyleToShape(shape, node) shape.strokeColor = None group.add(shape) shape = PolyLine(points) self.applyStyleToShape(shape, node) group.add(shape) self.addShape(parent, node, group) elif node.tag == self.SVG_POLYGON: # convert points points = node.get('points').strip() if len(points) == 0: return points = list(map(parseLength, re.split('[ ,]+', points))) shape = Polygon(points) self.addShape(parent, node, shape) elif node.tag == self.SVG_IMAGE: x = parseLength(node.get('x', '0')) y = parseLength(node.get('y', '0')) width = parseLength(node.get('width', '0')) height = parseLength(node.get('height', '0')) # link id link_id = node.get(self.LINK) filename = os.path.join(os.path.dirname(self.filename), link_id) shape = Image(x, y, width, height, filename) self.addShape(parent, node, shape) elif node.tag == self.SVG_TEXT: # Todo: # - rotation not handled # - baseshift not handled # - embedded span node not handled # def parsePos(node, subnode, name, default='0'): values = subnode.get(name) if values is None: if node is not None: values = node.get(name, default) else: values = default return list(map(parseLength, values.split())) def getPos(values, i, default=None): if i >= len(values): if default is None: return values[-1] else: return default else: return values[i] def handleText(node, subnode, text): # get position variables xs = parsePos(node, subnode, 'x') dxs = parsePos(node, subnode, 'dx') ys = parsePos(node, subnode,'y') dys = parsePos(node, subnode,'dy') if sum(map(len, (xs,ys,dxs,dys))) == 4: # single value shape = String(xs[0] + dxs[0], -ys[0] - dys[0], text) self.applyStyleToShape(shape, subnode) group.add(shape) else: # multiple values for i, c in enumerate(text): x = getPos(xs, i) dx = getPos(dxs, i, 0) y = getPos(ys, i) dy = getPos(dys, i, 0) shape = String(x + dx, -y -dy, c) self.applyStyleToShape(shape, subnode) group.add(shape) if node.text and node.text.strip(): group = Group() handleText(None, node, node.text.strip()) group.scale(1, -1) self.addShape(parent, node, group) if len(node) > 0: group = Group() self.level += 1 # set this levels style style = self.styles[self.level - 1].copy() nodestylestyle = self.nodeStyle(node, style) self.styles[self.level] = nodestylestyle for subnode in node: if subnode.tag == self.SVG_TSPAN: handleText(node, subnode, subnode.text.strip()) self.level -= 1 group.scale(1, -1) self.addShape(parent, node, group) elif node.tag == self.SVG_PATH: def convertQuadratic(Q0, Q1, Q2): C1 = (Q0[0] + 2./3*(Q1[0] - Q0[0]), Q0[1] + 2./3*(Q1[1] - Q0[1])) C2 = (C1[0] + 1./3*(Q2[0] - Q0[0]), C1[1] + 1./3*(Q2[1] - Q0[1])) C3 = Q2 return C1[0], C1[1], C2[0], C2[1], C3[0], C3[1] def prevCtrl(lastOp, lastArgs, currentX, currentY): # fetch last controll point if lastOp in 'CScsQqTt': x, y = lastArgs[-2] # mirror about current point return currentX + (currentX-x), currentY + (currentY-y) else: # defaults to current point return currentX, currentY # store sub paths in 'paths' list shape = Path() # keep track of current point and path start point startX, startY = 0., 0. currentX, currentY = 0., 0. # keep track of last operation lastOp = None lastArgs = None # avoid empty path data data = node.get('d') if data is None or len(data) == 0: return for op, args in parsePath.iterparse(data): if op == 'z' or op == 'Z': # close path or subpath shape.closePath() # next sub path starts at begining of current path currentX, currentY = startX, startY elif op == 'M': # moveto absolute if lastOp is not None and lastOp not in ('z', 'Z'): # close sub path shape.closePath() x, y = args[0] shape.moveTo(x, y) startX, startY = x, y # multiple moveto arge result in line for x, y in args[1:]: shape.lineTo(x, y) currentX, currentY = x, y elif op == 'm': if lastOp is not None and lastOp not in ('z', 'Z'): # close sub path shape.closePath() # moveto relative rx, ry = args[0] x, y = currentX + rx, currentY + ry shape.moveTo(x, y) startX, startY = x, y currentX, currentY = x, y # multiple moveto arge result in line for rx, ry in args[1:]: x, y = currentX + rx, currentY + ry shape.lineTo(x, y) currentX, currentY = x, y elif op == 'L': # lineto absolute for x, y in args: shape.lineTo(x, y) currentX, currentY = x, y elif op == 'l': # lineto relative for rx, ry in args: x, y = currentX + rx, currentY + ry shape.lineTo(x, y) currentX, currentY = x, y elif op == 'V': # vertical line absolute for y in args: shape.lineTo(currentX, y) currentY = y elif op == 'v': # vertical line relative for ry in args: y = currentY + ry shape.lineTo(currentX, y) currentY = y elif op == 'H': # horisontal line absolute for x in args: shape.lineTo(x, currentY) currentX = x elif op == 'h': # horisontal line relative for rx in args: x = currentX + rx shape.lineTo(x, currentY) currentX = x elif op == 'C': # cubic bezier absolute for p1, p2, p3 in zip(*([iter(args)] * 3)): shape.curveTo(*(p1 + p2 + p3)) currentX, currentY = p3 elif op == 'c': # cubic bezier relative for pnts in zip(*([iter(args)] * 3)): (x1, y1), (x2, y2), (x3, y3) = pnts pnts = tuple((p[0] + currentX, p[1] + currentY) for p in pnts) shape.curveTo(*(pnts[0] + pnts[1] + pnts[2])) currentX, currentY = pnts[2] lastOp = op lastArgs = pnts continue elif op == 'S': # shorthand cubic bezier absolute for p2, p3 in zip(*([iter(args)] * 2)): x1, y1 = prevCtrl(lastOp, lastArgs, currentX, currentY) x2, y2 = p2 x3, y3 = p3 shape.curveTo(x1, y1, x2, y2, x3, y3) lastOp = op lastArgs = (x2, y2), (x3, y3) currentX, currentY = x3, y3 continue elif op == 's': # shorthand cubic bezier relative for p2, p3 in zip(*([iter(args)] * 2)): x1, y1 = prevCtrl(lastOp, lastArgs, currentX, currentY) x2, y2 = p2 x2, y2 = x2 + currentX, y2 + currentY x3, y3 = p3 x3, y3 = x3 + currentX, y3 + currentY shape.curveTo(x1, y1, x2, y2, x3, y3) currentX, currentY = x3, y3 lastOp = op lastArgs = (x1, y1), (x2, y2), (x3, y3) continue elif op == 'Q': # quadratic bezier absolute for p2, p3 in zip(*([iter(args)] * 2)): x1, y1 = currentX, currentY x2, y2 = p2 x3, y3 = p3 ctrls = convertQuadratic((x1, y1), (x2, y2), (x3, y3)) shape.curveTo(*ctrls) currentX, currentY = x3, y3 lastOp = op lastArgs = (x2, y2), (x3, y3) continue elif op == 'q': # quadratic bezier relative for p2, p3 in zip(*([iter(args)] * 2)): x1, y1 = currentX, currentY x2, y2 = p2 x2, y2 = x2 + currentX, y2 + currentY x3, y3 = p3 x3, y3 = x3 + currentX, y3 + currentY ctrls = convertQuadratic((x1, y1), (x2, y2), (x3, y3)) shape.curveTo(*ctrls) currentX, currentY = x3, y3 lastOp = op lastArgs = (x2, y2), (x3, y3) continue elif op == 'T': # shorthand quadratic bezier absolute for i in range(len(args)): x1, y1 = currentX, currentY x2, y2 = prevCtrl(lastOp, lastArgs, currentX, currentY) x3, y3 = args[i] ctrls = convertQuadratic((x1, y1), (x2, y2), (x3, y3)) shape.curveTo(*ctrls) currentX, currentY = x3, y3 lastOp = op lastArgs = (x2, y2), (x3, y3) continue elif op == 't': # shorthand quadratic bezier relative for i in range(len(args)): x1, y1 = currentX, currentY x2, y2 = prevCtrl(lastOp, lastArgs, currentX, currentY) x3, y3 = args[i] x3, y3 = x3 + currentX, y3 + currentY ctrls = convertQuadratic((x1, y1), (x2, y2), (x3, y3)) shape.curveTo(*ctrls) currentX, currentY = x3, y3 lastOp = op lastArgs = (x2, y2), (x3, y3) continue elif op == 'A' or op == 'a': # elliptic arc missing continue lastOp = op lastArgs = args # check if fill applies to path fill = None if node.get('fill'): # inline style fill = node.get('fill') else: # try local style if node.get('style'): style = parseStyle.parse(node.get('style')) if 'fill' in style: fill = style['fill'] # try global style if fill is None: style = self.styles[self.level] if 'fill' in style: fill = style['fill'] else: fill = 'none' # hack because RLG has no "semi-closed" paths... if lastOp == 'z' or lastOp == 'Z' or fill == 'none': self.addShape(parent, node, shape) else: group = Group() strokeshape = shape.copy() self.addShape(group, node, strokeshape, fill='none') shape.closePath() self.addShape(group, node, shape, stroke='none') self.addShape(parent, node, group) elif node.tag == self.SVG_TITLE or node.tag == self.SVG_DESC: # Skip non-graphics elements return