本文整理匯總了Python中SVGdraw.text方法的典型用法代碼示例。如果您正苦於以下問題:Python SVGdraw.text方法的具體用法?Python SVGdraw.text怎麽用?Python SVGdraw.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SVGdraw
的用法示例。
在下文中一共展示了SVGdraw.text方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def build(self):
(sx, sy) = self._srcchgset.position()
h_offset = self._srcchgset.tag_offset(self._h)
self._position = (sx + (self._srcchgset.extent()[0])/2,
sy - (3*self._h)/2 + h_offset)
x = self._position[0]+(self._w-self._tw)/2
y = self._position[1]
r = UNIT/2
rect = SVG.rect(x,y,self._tw,self._h,
self._srcchgset.strokecolor(),
self._srcchgset.fillcolor(),
self._srcchgset.strokewidth())
rect.attributes['rx'] = r
rect.attributes['ry'] = r
rect.attributes['opacity'] = str(self._opacity/100.0)
text = SVG.text(self._position[0]+self._w/2,
self._position[1]+self._h/2+UNIT/4,
"%s" % self._title.encode('utf-8'),
self._srcchgset.fontsize(),
self._srcchgset.fontname())
txc = SvgColor('white')
text.attributes['style'] = 'fill:%s; text-anchor: middle' % txc.rgb()
name = self._title.encode('utf-8').replace('/','')
g = SVG.group('grp%d' % self._revision, elements=[rect, text])
link = "%s/changeset/%d" % (self._parent.urlbase(), self._revision)
self._link = SVG.link(link, elements=[g])
self._link.attributes['id'] = 'rev%d' % self._revision
self._link.attributes['style'] = \
'color: %s; background-color: %s' % \
(self._srcchgset.fillcolor(), self._srcchgset.strokecolor())
示例2: errorsvg
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def errorsvg(msg):
s=SVGdraw.svg(width='5cm', height='1cm')
s.addElement(SVGdraw.text(0,0,msg))
d=SVGdraw.drawing()
d.svg=s
print d.toXml()
return s
示例3: writeTitle
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def writeTitle( self ):
"""write title into plot."""
if self.mTitle:
e = SVGdraw.text( self.mPageWidth / 2,
self.mTitleFontSize ,
self.mTitle,
self.mTitleFontSize,
self.mTitleFont,
stroke = "rgb(%i,%i,%i)" % BLACK,
text_anchor = "middle" )
self.addElement(e)
示例4: writeScale
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def writeScale( self ):
"""write scales."""
current_x = self.mScaleX
current_y = self.mScaleY + self.mScaleHeight
nboxes = len(self.mColourThresholds)
# box size for legend in x-direction
# subtract size of right-most axis label so that it takes the
# same width as self.mDataWidth.
box_size_x = math.ceil( (self.mDataWidth -
(self.mScaleFontSize * len(self.mFormatNumberLegend % self.mColourThresholds[-1])))
/ nboxes )
# change font size such that it labels will fit between tick-marks
self.mScaleFontSize = min( self.mScaleFontSize,
(box_size_x * self.mScaleNumTicks * 1.5) / len(self.mFormatNumberLegend % self.mColourThresholds[-1]) )
for x in range(nboxes):
e = SVGdraw.rect( current_x,
current_y,
box_size_x,
self.mScaleBoxSizeY,
fill = "rgb(%i,%i,%i)" % self.mColours[x],
stroke = "rgb(%i,%i,%i)" % self.mColours[x])
self.addElement(e)
if x % self.mScaleNumTicks == 0:
e = SVGdraw.line( current_x,
current_y,
current_x,
current_y + self.mScaleBoxSizeY,
stroke = "rgb(%i,%i,%i)" % BLACK,
stroke_width = 5)
self.addElement(e)
e = SVGdraw.text( current_x,
current_y - self.mScaleBoxSizeY,
self.mFormatNumberLegend % self.mColourThresholds[x],
self.mScaleFontSize,
self.mScaleFont,
stroke = "rgb(%i,%i,%i)" % BLACK,
text_anchor = "start")
self.addElement(e)
current_x += box_size_x
示例5: getElements
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def getElements( self, node_id, x, y, x_label = None, y_label = None ):
e = NodeDecorator.getElements( self, node_id, x, y )
if x_label == None: x_label = x
if y_label == None: y_label = y
e.append( SVGdraw.text( x_label, y_label,
self.mTree.node(node_id).data.taxon,
self.mFontSize,
self.mFont,
stroke = "rgb(%i,%i,%i)" % BLACK,
font_style = self.mFontStyle,
text_anchor = "left" ))
return e
示例6: writeFooter
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def writeFooter( self ):
"""write footer."""
current_x = self.mFooterX
current_y = self.mFooterY
if self.mFooter:
current_y += max( self.mFooterFontSize, self.mMaxBoxSize) + self.mSeparator
e = SVGdraw.text( self.mPageWidth / 2,
current_y + self.mFooterFontSize,
self.mFooter,
self.mFooterFontSize,
self.mFooterFont,
stroke = "rgb(%i,%i,%i)" % BLACK,
text_anchor = "middle")
self.addElement(e)
示例7: writeGrid
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def writeGrid( self ):
"""add grid lines."""
middlex = self.mDataMiddleX
middley = self.mDataMiddleY
## print separators
for c in range(len(self.contigs)):
contig = self.contigs[c]
pos = self.getPosition( contig, "+", 0)
angle = self.getAngle( pos )
x,y = self.getPosOnArc( angle, self.mRadius )
e = SVGdraw.line( middlex,
middley,
x,
y,
stroke = "rgb(%i,%i,%i)" % BLACK,
stroke_width = self.mGridStrokeWidth )
self.addElement(e, self.mPlaneGrid )
if c < len(self.contigs) - 1:
next_angle = self.getAngle(self.getPosition( self.contigs[c+1], "+", 0 ) )
else:
next_angle = 360
x,y = self.getPosOnArc( angle + float(next_angle - angle) / 2, self.mRadiusStart / 2)
e = SVGdraw.text( x,
y,
contig,
self.mGridFontSize,
self.mGridFont,
stroke = "rgb(%i,%i,%i)" % BLACK,
text_anchor = "start" )
# do not rotate text:
# transform="rotate(%i,%i,%i)" % ( angle, x, y ))
self.addElement(e)
示例8: build
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def build(self):
self._position = self._parent.position()
x = self._position[0]+(self._w-self._tw)/2
y = self._position[1]
r = UNIT/2
rect = SVG.rect(x,y,self._tw,self._h,
self._parent.fillcolor(),
self._parent.strokecolor(),
self._parent.strokewidth())
rect.attributes['rx'] = r
rect.attributes['ry'] = r
text = SVG.text(self._position[0]++self._w/2,
self._position[1]+self._h/2+UNIT/6,
"/%s" % self._title.encode('utf-8'),
self._parent.fontsize(), self._parent.fontname())
text.attributes['style'] = 'text-anchor: middle'
name = self._title.encode('utf-8').replace('/','')
g = SVG.group('grp%s' % name, elements=[rect, text])
href = Href(self._parent.urlbase())
self._link = SVG.link(plink(href.browser(self._title)), elements=[g])
示例9: toSVG
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def toSVG(self):
#modification du maximum en X : depend du nombre d'element
global XMAX
XMAX = len(self.infos)*(BAR_THICKNESS+SPACE)
# creation du document
doc=SVGdraw.drawing()
svg=SVGdraw.svg(None, '100%','100%')
# creation des patterns pour les axes et la grille
axeX = SVGdraw.pattern(id="axeX",width="20",height="10",patternUnits="userSpaceOnUse")
axeX.addElement(SVGdraw.path("M 0 0, L 0 10","none","black","0.25"))
axeX.addElement(SVGdraw.path("M 10 10, V 5","none","lightgray","0.25"))
axeY = SVGdraw.pattern(id="axeY",width="10",height="20",patternUnits="userSpaceOnUse")
axeY.addElement(SVGdraw.path("M 0 0, L 10 0","none","black","0.25"))
axeY.addElement(SVGdraw.path("M 5 10, L 10 10","none","lightgray","0.25"))
grid = SVGdraw.pattern(id="grid",width="10",height="10",patternUnits="userSpaceOnUse")
grid.addElement(SVGdraw.path("M 0 0, L 10 0, L 10 10,L 0 10, L 0 0","none","lightgray","0.25"))
defs=SVGdraw.defs()
defs.addElement(axeX)
defs.addElement(axeY)
defs.addElement(grid)
svg.addElement(defs)
group=SVGdraw.group(transform="translate(130,130) scale(1,-1)")
# dessin de la grille de fond
group.addElement(SVGdraw.rect(0,0,XMAX,YMAX,"url(#grid)","lightgray","0.25"))
# dessin des axes
group.addElement(SVGdraw.rect(0,-10,XMAX,10,"url(#axeX)"))
group.addElement(SVGdraw.rect(-10,0,10,YMAX,"url(#axeY)"))
group.addElement(SVGdraw.line(0,0,XMAX,0,"black",1))
group.addElement(SVGdraw.line(0,0,0,YMAX,"black",1))
# dessin des fleches des axes
group.addElement(SVGdraw.polygon([[-3,YMAX],[3,YMAX],[0,YMAX+10]], "black","white"))
group.addElement(SVGdraw.polygon([[XMAX,-3],[XMAX,3],[XMAX+10,0]], "black","white"))
textgroup=SVGdraw.group(transform="scale(1,-1)")
# graduations
for y in range(0,YMAX+STEP,STEP):
textgroup.addElement(SVGdraw.text(-STEP,y, str(y), 8, text_anchor="middle", transform="translate(0,%d)"%(-y*2)))
textgroup.addElement(SVGdraw.text(0,YMAX+SPACE, r"%", 8, transform="translate(0,%d)"%(-(YMAX+SPACE)*2)))
# ajout de la legende principale
legendText = "Repertoire %s - taille %.02f ko"%(self.rootName,float(self.totalSize/1024.0))
textgroup.addElement(SVGdraw.text(XMAX,YMAX+3*SPACE, legendText,12, "verdana",
text_anchor="end", fill="darkblue",transform="translate(0,%d)"%(-(YMAX+3*SPACE)*2)))
group.addElement(textgroup)
# tri des elements selon la taille occupee
self.infos.sort(self.tupleCmp)
xincr=0
#self.infos
for (name,size) in self.infos:
# calcul du pourcentage de place occupe
pourcent = (100.0*float(size))/float(self.totalSize)
height=int(pourcent*YMAX/100);
# insertion du texte de l'emplacement sur le disque et de la taille occupee en Ko
legendText = "%s (%### ###.02f ko)"%(name,float(size/1024.0))
legend = SVGdraw.text(xincr+BAR_THICKNESS/2, -10,legendText,8,"verdana",text_anchor="begin",fill="blue")
legend.attributes["transform"]="scale(1,-1) translate(0,20) rotate(45,%d,-10)"%(xincr+BAR_THICKNESS/2)
group.addElement(legend)
#insertion de la barre representant le pourcentage
group.addElement(SVGdraw.rect(xincr,0,BAR_THICKNESS, height,"green","black",opacity=0.5))
#insertion de la taille en pourcentage a gauche de la barre
pourcentText=SVGdraw.text(xincr+BAR_THICKNESS/2, height+SPACE,"%02.01f%% "%pourcent,6,
"arial", text_anchor="middle", fill="black")
pourcentText.attributes["transform"]="scale(1,-1) translate(0,-%d)"%((height+SPACE)*2)
group.addElement(pourcentText)
# augmentation du l'abscisse en X
xincr = xincr+BAR_THICKNESS+SPACE
svg.addElement(group)
doc.setSVG(svg)
doc.toXml(self.svgURL)
示例10: writeFooter
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def writeFooter( self ):
"""write footer.
The footer contains the legend.
"""
total_branch_length = (max(self.mNodeWidthsEnd) - min(self.mNodeWidthsStart)) / self.mBranchScaleFactor
self.mFooterX = self.getHeaderWidth()
self.mFooterY = self.getHeaderHeight() + self.mDataHeight + self.mSeparatorHeight
ruler_start = self.mFooterX
ruler_end = self.mFooterX + int(total_branch_length * self.mBranchScaleFactor)
if "ruler" in self.mRulerElements:
## full length ruler with tick marks and labels
e = SVGdraw.line( ruler_start,
self.mFooterY + self.mRulerTickSize + 1,
ruler_end,
self.mFooterY + self.mRulerTickSize + 1,
stroke = "rgb(%i,%i,%i)" % BLACK,
stroke_width = 1 )
self.addElement( e )
## get reasonable intervalls
increment = self.mRulerIncrement * self.mBranchScaleFactor
## adjust increment for extremely long trees
if (ruler_end - ruler_start) / increment > 1000:
increment = (ruler_end - ruler_start) / 1000.0
self.mRulerIncrement = increment / self.mBranchScaleFactor
if "right-ticks" in self.mRulerElements:
x = ruler_end
while x >= ruler_start:
e = SVGdraw.line( x,
self.mFooterY,
x,
self.mFooterY + 2 * self.mRulerTickSize + 1,
stroke = "rgb(%i,%i,%i)" % BLACK,
stroke_width = 1 )
self.addElement( e )
x -= self.mRulerIncrement * self.mBranchScaleFactor
self.mFooterY += 2 * self.mRulerTickSize + 1 + self.mSeparatorHeight
if "left-ticks" in self.mRulerElements:
x = ruler_start
while x <= ruler_end:
e = SVGdraw.line( x,
self.mFooterY,
x,
self.mFooterY + 2 * self.mRulerTickSize + 1,
stroke = "rgb(%i,%i,%i)" % BLACK,
stroke_width = 1 )
self.addElement( e )
x += increment
self.mFooterY += 2 * self.mRulerTickSize + 1 + self.mSeparatorHeight
if "scale" in self.mRulerElements:
w = int(self.mRulerIncrement * self.mBranchScaleFactor)
e = SVGdraw.line( ruler_end,
self.mFooterY + self.mRulerTickSize + 1,
ruler_end - w,
self.mFooterY + self.mRulerTickSize + 1,
stroke = "rgb(%i,%i,%i)" % BLACK,
stroke_width = 1 )
self.addElement( e )
e = SVGdraw.line( ruler_end,
self.mFooterY,
ruler_end,
self.mFooterY + 2 * self.mRulerTickSize + 1,
stroke = "rgb(%i,%i,%i)" % BLACK,
stroke_width = 1 )
self.addElement( e )
e = SVGdraw.line( ruler_end - w,
self.mFooterY,
ruler_end - w,
self.mFooterY + 2 * self.mRulerTickSize + 1,
stroke = "rgb(%i,%i,%i)" % BLACK,
stroke_width = 1 )
self.addElement( e )
e = SVGdraw.text( ruler_end - w / 2,
self.mFooterY + 2 * self.mRulerTickSize + 1 + self.mRulerFontSize ,
self.mRulerFormat % self.mRulerIncrement,
self.mRulerFontSize,
self.mRulerFont,
stroke = "rgb(%i,%i,%i)" % BLACK,
text_anchor = "middle" )
#.........這裏部分代碼省略.........
示例11: doGrid
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
def doGrid(self, canvas, rows, verticalOffset, partHeight, columns, horizontalOffset, partWidth, gridsize, lineColor, fillColor, penWidth):
polySize = str(gridsize) + self.units
polyCount = 0
thebes = SVGdraw.text(20, 20, "Thebes")
canvas.addElement(thebes)
name = SVGdraw.text(200, 20, "Map For " + self.name)
canvas.addElement(name)
warning = SVGdraw.text(500, 20, "NOT IN GAME")
canvas.addElement(warning)
for polyRow in range(0, rows):
polyTop = verticalOffset + polyRow*partHeight
polyTopStr = str(polyTop) + self.units
#do stuff for hexagons
rowcolumns = columns
rowoffset = 0
if self.type == 'hex':
if polyRow % 2 == 0:
if (self.width-(horizontalOffset+self.rightMargin-.01)) >= (columns*partWidth + gridsize):
rowcolumns = columns + 1
else:
rowoffset = gridsize/2 + gridsize/4
for polyColumn in range(0, rowcolumns):
polyLeft = horizontalOffset + polyColumn*partWidth
polyLeft += rowoffset
polyLeftStr = str(polyLeft) + self.units
polyCount += 1
if self.type == 'hex':
nodeID = 100 * polyColumn + polyRow
if (nodeID in self.nodes) or (self.drawAll):
gridshape = hexagon(gridsize, polyLeft, polyTop, self.units, stroke=lineColor, fill=fillColor, stroke_width=penWidth)
if self.drawNumbers:
if (polyRow < 10):
polyRowStr = "0" + str(polyRow)
else:
polyRowStr = str(polyRow)
gridtext = SVGdraw.text(90 * (polyLeft + partHeight - .10), 90 * (polyTop + partHeight - .15),str(polyColumn)+polyRowStr,font_size=11);
canvas.addElement(gridtext)
canvas.addElement(gridshape)
if nodeID in self.nodes:
if self.drawDesc:
gridname = SVGdraw.text(90 * (polyLeft + partHeight - .16), 90 * (polyTop + partHeight + .13),self.nodes[nodeID]["name"],font_size=9);
canvas.addElement(gridname)
griddesc = SVGdraw.text(90 * (polyLeft + partHeight - .2), 90 * (polyTop + partHeight + .02),self.nodes[nodeID]["desc"],font_size=8);
canvas.addElement(griddesc)
else:
gridname = SVGdraw.text(90 * (polyLeft + partHeight - .16), 90 * (polyTop + partHeight + .02),self.nodes[nodeID]["name"],font_size=12);
canvas.addElement(gridname)
else:
gridshape = SVGdraw.rect(polyLeftStr, polyTopStr, polySize, polySize, stroke=lineColor, fill=fillColor, stroke_width=penWidth)
canvas.addElement(gridshape)
return canvas
示例12: svgout
# 需要導入模塊: import SVGdraw [as 別名]
# 或者: from SVGdraw import text [as 別名]
#.........這裏部分代碼省略.........
# circular plots, to curve around in the right direction.
if circradius:
betweens=self.pointsbetween(path[j],path[j+1])
pathstring+=" M %f %f "%tuple(transform(path[j].x,path[j].y))
for k in range(0,len(betweens)):
pathstring+=" L %f %f "% \
tuple(transform(betweens[k].x,betweens[k].y))
pathstring+="L %f %f "% \
tuple(transform(path[j+1].x, path[j+1].y))
else:
pathstring+=" M %f %f L %f %f"% \
(tuple(transform(path[j].x,path[j].y)+
transform(path[j+1].x,path[j+1].y)))
pathelt=SVGdraw.path(pathstring,stroke_width=stroke_width,
stroke=col,fill="none")
if self.slopebetween(here,nxt)>0:
plus.addElement(pathelt)
else:
minus.addElement(pathelt)
for i in self.pivots:
cr=transform(i.x, i.y)
c=SVGdraw.circle(cx=cr[0], cy=cr[1], r=circle_radius,
fill='black')
circgroup.addElement(c)
if not circradius:
# Mark the wraparound point.
circgroup.addElement(SVGdraw.path("M 0 -1 l 0 %d M %d -1 l 0 %d"% \
(self.ymax+2,self.xmodulus,
self.ymax+2),
stroke='black',
stroke_width=0.03))
# Somehow I want to *note* when a knot is single-strand or
# multistrand.
circgroup.addElement(SVGdraw.text(x=0.2,y=0,
text=str(len(strands)),
fill='#000408',
font_size=1,
font_family='sans-serif',
transform='scale(1,-1)'))
if crossings:
# Try multistrand crossings? (not working right)
# Need *ALL* the crossing points though.
oncircuit=[]
for circuit in strands:
oncircuit.extend(self.oncircuit(circuit))
masked=set()
over=0
masks=[minusmask,plusmask]
# How about this? For each horizontal line _that has intersections on it_,
# all crossings go in one direction, and that direction alternates.
#
# How do we find those lines?
points=[]
for circuit in strands:
for i in range(0,len(circuit)):
here=circuit[i]
nxt=circuit[(i+1)%len(circuit)]
points+=self.pointsbetween(here,nxt)
heights=[]
howmanyhits=dict()
for p in points:
howmanyhits[p]=howmanyhits.get(p,0)+1
howmanyhits=[(p,howmanyhits[p]) for p in howmanyhits.keys()]
howmanyhits=filter((lambda x: x[1]>1), howmanyhits)
heights=[x[0].y for x in howmanyhits]