本文整理汇总了Python中SVGdraw.path方法的典型用法代码示例。如果您正苦于以下问题:Python SVGdraw.path方法的具体用法?Python SVGdraw.path怎么用?Python SVGdraw.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SVGdraw
的用法示例。
在下文中一共展示了SVGdraw.path方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assemble
# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import path [as 别名]
def assemble(self):
# Yes, everything with HEIGHT, so I'm working in a square.
# May have the colors backwards.
p=partLine(linetype=self.lineType)
if self.pieces == 8:
# No reason to do this as a special case, but it was working
# first, so why mess with it.
p.move(0,-blazon.Ordinary.HEIGHT)
p.makeline(0,blazon.Ordinary.HEIGHT)
p.hline(-blazon.Ordinary.HEIGHT)
p.makeline(blazon.Ordinary.HEIGHT,-blazon.Ordinary.HEIGHT)
p.closepath()
p.move(-blazon.Ordinary.HEIGHT,0)
p.makeline(blazon.Ordinary.HEIGHT,0)
p.vline(blazon.Ordinary.HEIGHT)
p.makeline(-blazon.Ordinary.HEIGHT,-blazon.Ordinary.HEIGHT)
p.closepath()
else:
angle=2*math.pi/self.pieces
pi_2=math.pi/2
for i in range(0,self.pieces,2):
p.move(blazon.Ordinary.HEIGHT*math.cos(pi_2+i*angle),
blazon.Ordinary.HEIGHT*math.sin(pi_2+i*angle))
p.makeline(0,0)
p.makeline(blazon.Ordinary.HEIGHT*math.cos(pi_2+(i+1)*angle),
blazon.Ordinary.HEIGHT*math.sin(pi_2+(i+1)*angle))
p.closepath()
self.path=SVGdraw.path(p)
self.path.attributes["fill-rule"]="evenodd"
示例2: build
# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import path [as 别名]
def build(self):
(x0,y0) = self._source.position('se')
(x5,y5) = self._dest.position('ne')
pd = SVG.pathdata()
pd.move(x0,y0)
(x1,y1) = (x0+UNIT,y0+UNIT)
(x2,y2) = (x0+UNIT,y0+2*UNIT)
(x3,y3) = (x5+UNIT,y5-2*UNIT)
(x4,y4) = (x5+UNIT,y5-UNIT)
if x2 < x4:
pd.qbezier(x1,y1,x2,y2)
pd.line(x3,y3)
pd.qbezier(x4,y4,x5,y5)
else:
pd.qbezier(x0+UNIT,(y5+y0)/2,x5,y5)
self._extent = (abs(x5-x0),abs(y5-y0))
self._widget = SVG.path(pd, 'none', self._color,
self._parent.strokewidth())
self._widget.attributes['stroke-dasharray']='5, 5'
示例3: build
# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import path [as 别名]
def build(self):
if self._source.branch() == self._dest.branch():
self._widget = None
self._parent.env.log.warn("Invalid operation")
return
# get the position of the changeset to tie
(xs,ys) = self._source.position()
(xe,ye) = self._dest.position()
# swap start and end points so that xs < xe
if xs > xe:
head = True
(self._source, self._dest) = (self._dest, self._source)
(xs,ys) = self._source.position()
(xe,ye) = self._dest.position()
else:
head = False
xbranches = self._parent.xsvgbranches(self._source, self._dest)
# find which points on the changeset widget are used for connections
if xs < xe:
ss = 'e'
se = 'w'
else:
ss = 'w'
se = 'e'
ps = self._source.position(ss)
pe = self._dest.position(se)
# compute the straight line from start to end widgets
a = (ye-ys)/(xe-xs)
b = ys-(a*xs)
bz = []
# compute the points through which the 'operation' curve should go
(xct,yct) = (ps[0],ps[1])
points = [(xct,yct)]
for br in xbranches:
x = br.vaxis()
y = (a*x)+b
ycu = ycd = None
schangesets = br.svgchangesets()
schangesets.sort()
# add an invisible changeset in place of the branch header to avoid
# special case for the first changeset
hpos = br.header().position()
hchg = SvgBaseChangeset(br, 0, (hpos[0], hpos[1]+3*UNIT/2))
schangesets.append(hchg)
schangesets.reverse()
pc = None
for c in schangesets:
# find the changesets which are right above and under the
# selected point, and store their vertical position
yc = c.position()[1]
if yc < y:
ycu = yc
if yc >= y:
ycd = yc
if not ycu:
if pc:
ycu = pc.position()[1]
elif c != schangesets[-1]:
ycu = schangesets[-1].position()[1]
break
pc = c
if not ycu or not ycd:
pass
# in this case, we need to create a virtual point (TODO)
else:
xt = x
yt = (ycu+ycd)/2
if a != 0:
a2 = -1/a
b2 = yt - a2*xt
xl = (b2-b)/(a-a2)
yl = a2*xl + b2
nx = xt-xl
ny = yt-yl
dist = sqrt(nx*nx+ny*ny)
radius = (3*c.extent()[1])/2
add_point = dist < radius
else:
add_point = True
# do not insert a point if the ideal curve is far enough from
# an existing changeset
if add_point:
# update the vertical position for the bezier control
# point with the point that stands between both closest
# changesets
(xt,yt) = self._parent.fixup_point((xt,yt))
points.append((xt,yt))
if head:
points.append(pe)
else:
points.append((pe[0]-UNIT,pe[1]))
# now compute the qbezier curve
pd = SVG.pathdata()
pd.move(points[0][0],points[0][1])
if head:
pd.line(points[0][0]+UNIT,points[0][1])
for i in range(len(points)-1):
(xl,yl) = points[i]
(xr,yr) = points[i+1]
(xi,yi) = ((xl+xr)/2,(yl+yr)/2)
#.........这里部分代码省略.........
示例4: getElements
# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import path [as 别名]
def getElements(self, x, y, map_node2height ):
t = self.mTree.get_terminals()
elements = []
## print locations
if self.mPrintLocation:
for i in range(len(t)):
node_id1 = t[i]
taxon1 = self.mTree.node(node_id1).data.taxon
y1 = map_node2height[node_id1] + y
elements.append( SVGdraw.text( x, y1,
str(self.mMapId2Location[taxon1]),
self.mFontSize,
self.mFont,
stroke = "rgb(%i,%i,%i)" % BLACK,
text_anchor = "left" ))
## print connectors
for i in range(len(t)-1):
node_id1 = t[i]
taxon1 = self.mTree.node(node_id1).data.taxon
y1 = map_node2height[node_id1] + y
for j in range(i+1, len(t)):
node_id2 = t[j]
taxon2 = self.mTree.node(node_id2).data.taxon
if self.mExtractSpecies:
species1 = self.mExtractSpecies(taxon1)
species2 = self.mExtractSpecies(taxon2)
if species1 != species2: continue
if species1 not in self.mMapSpecies2Colour:
self.mMapSpecies2Colour[species1] = COLOURS[len(self.mMapSpecies2Colour) % len(COLOURS) ]
colour = self.mMapSpecies2Colour[species1]
else:
colour = self.mDefaultColour
l1 = self.mMapId2Location[taxon1]
l2 = self.mMapId2Location[taxon2]
if l1.contig != l2.contig:
continue
if self.mMaxSeparation:
s = min( abs(l1.mFrom - l2.mTo), abs(l1.mTo - l2.mFrom))
if s >= self.mMaxSeparation: continue
y2 = map_node2height[node_id2] + y
distance = y2 - y1
d = SVGdraw.pathdata( x, y1 )
d.line( x + self.mTickWidth, y1 )
d.ellarc( distance, distance, 0, 0, 1, x + self.mTickWidth, y2 )
d.line( x, y2 )
e = SVGdraw.path( d,
fill = "none",
stroke = "rgb(%i,%i,%i)" % colour,
stroke_width = 1 )
elements.append( e )
return elements
示例5: addDuplication
# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import path [as 别名]
#.........这里部分代码省略.........
if gene in self.mPreviousPoints:
continue
new_points[gene] = (x, y, angle, quality, chr)
if symbol == "circle":
ee = SVGdraw.circle( x, y, self.mLinkSymbolSize,
fill = "rgb(%i,%i,%i)" % colour,
stroke="black",
stroke_width = self.mLinkStrokeWidthSymbol )
elif symbol == "rect":
ee = SVGdraw.rect( x-self.mLinkSymbolSize/2, y-self.mLinkSymbolSize/2,
self.mLinkSymbolSize, self.mLinkSymbolSize,
fill = "rgb(%i,%i,%i)" % colour,
stroke="black",
stroke_width = self.mLinkStrokeWidthSymbol )
if url:
e = SVGdraw.link( url % gene )
e.addElement( ee )
else:
e = ee
self.addWheelElement( e )
########################################################
########################################################
########################################################
## write all arcs in between old points and new points
## cis: circular arc
## trans: radial arc
########################################################
angles = []
for x1,y1,angle1,quality1,chr1 in new_points.values():
## reduce clutter by not writing arc to the same angle
for x2,y2,angle2,quality2,chr2 in self.mPreviousPoints.values():
for a in angles:
if a - self.mAngleResolution < angle2 < a + self.mAngleResolution:
break
else:
angles.append( angle2 )
d = SVGdraw.pathdata( x1, y1 )
if chr1 == chr2:
d.relellarc( self.mRadius, self.mRadius, 0, 0, 1, x2-x1, y2-y1 )
link_width = link_rad_width
else:
d.relellarc( self.mRadius * 2, self.mRadius * 2, 0, 0, 0, x2-x1, y2-y1 )
link_width = link_arc_width
e = SVGdraw.path( d,
fill = "none",
stroke = "rgb(%i,%i,%i)" % link_colour,
stroke_width = link_width )
self.addWheelElement(e, self.mPlaneLinks)
## plot lines between new points
new_genes = new_points.keys()
for g1 in range(len(new_genes)-1):
x1,y1,angle1,quality1,chr1 = new_points[new_genes[g1]]
for g2 in range(g1+1, len(new_genes)):
x2,y2,angle2,quality2,chr2 = new_points[new_genes[g2]]
for a in angles:
if a - self.mAngleResolution < angle2 < a + self.mAngleResolution:
break
else:
angles.append( angle2 )
d = SVGdraw.pathdata( x1, y1 )
if chr1 == chr2:
d.relellarc( self.mRadius, self.mRadius, 0, 0, 1, x2-x1, y2-y1 )
link_width = link_rad_width
else:
d.relellarc( self.mRadius * 2, self.mRadius * 2, 0, 0, 0, x2-x1, y2-y1 )
link_width = link_arc_width
e = SVGdraw.path( d,
fill = "none",
stroke = "rgb(%i,%i,%i)" % link_colour,
stroke_width = link_width )
self.addWheelElement(e, self.mPlaneLinks)
## add new points to old points
for k, v in new_points.items():
self.mPreviousPoints[k] = v
示例6: toSVG
# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import path [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)
示例7: svgout
# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import path [as 别名]
def svgout(self,stroke_width=0.3,scale=20,circle_radius=0.3,
startat=None,coloriter=None,crossings=True,circradius=None,circscale=1):
# if circradius is some positive number, try to draw a circular(!) diagram
# circscale is how much to scale the y-dimension by (how thick a circle)
# try:
# if type(SVGdraw)!=type(__builtins__):
# raise Exception("SVGdraw not a module?")
# return None
# except NameError:
# raise Exception("No SVGDraw found")
# return None
cols=['#000000',
'#800000', '#808000', '#008080', '#000080',
'#ff2000', '#ffff20', '#20ffff', '#0020ff',
'#ff0080', '#ff8000', '#8000ff', '#80ff00']
if circradius:
sz=(2*self.ymax*circscale+2+2*circradius)
svg=SVGdraw.svg(width="%dpx"%(sz*scale), height="%dpx"%(sz*scale),
viewBox=[-sz+self.xmodulus/2.0, -sz, 2*sz, 2*sz])
def transform(x,y):
# Have to flip it over...
r=self.ymax*circscale+circradius-y*circscale
theta=2*math.pi*x/self.xmodulus-math.pi
return [sz/2+r*math.cos(theta), sz/2+r*math.sin(theta)]
else:
svg=SVGdraw.svg(width="%dpx"%((self.xmodulus+2)*scale),
height="%dpx"%((self.ymax+2)*scale),
viewBox=[-1, -1, self.xmodulus+2,
self.ymax+2])
def transform(x,y):
return [x,y]
defs=SVGdraw.defs(id="defs")
plusmask=SVGdraw.SVGelement("mask",
attributes={"id":"plusmask"})
minusmask=SVGdraw.SVGelement("mask",
attributes={"id":"minusmask"})
if circradius:
sz=1+2*self.ymax*circscale+2*circradius # Whatever, something big.
r=SVGdraw.rect(x=-sz, y=-sz, width=sz*2,height=sz*2,fill='white')
else:
r=SVGdraw.rect(x=-1,y=-1,width=self.xmodulus+2,height=self.ymax+2,
fill='white')
plusmask.addElement(r)
minusmask.addElement(r)
defs.addElement(plusmask)
defs.addElement(minusmask)
svg.addElement(defs)
maingroup=SVGdraw.group(id="main")
# I've come to expect them this way up...
maingroup.attributes['transform']='scale(1,-1) translate(0,%d)'% \
(-self.ymax)
svg.addElement(maingroup)
# Positive slopes and negative slopes.
plus=SVGdraw.group(id="plus",mask="url(#plusmask)")
minus=SVGdraw.group(id="minus",mask="url(#minusmask)")
maingroup.addElement(plus)
maingroup.addElement(minus)
circgroup=SVGdraw.group(id="circgroup")
maingroup.addElement(circgroup)
strands=self.strands(self.pivots[0])
circuit=None
if coloriter is None:
if len(strands)>1:
# Multistranded; color it by strand.
def multicoloriter():
counter=0
lastcircuit=None
while True:
if circuit != lastcircuit:
lastcircuit=circuit
counter+=1
yield cols[counter%len(cols)]
coloriter=multicoloriter()
else:
def singlecoloriter(): # for singlestranders!
colcounter=0
colordiv=len(self.pivots)/6
while True:
yield cols[int(colcounter/colordiv)%len(cols)]
colcounter+=1
coloriter=singlecoloriter()
for circuit in strands:
# If there's a startat parameter, and it appears in this list,
# slosh the list around so it's first
if startat and startat in circuit:
ind=circuit.index(startat)
circuit=circuit[ind:]+circuit[0:ind]
for i in range(0,len(circuit)):
here=circuit[i]
nxt=circuit[(i+1)%len(circuit)]
col=coloriter.next()
if type(col)==int: # let iterator generate indexes
col=cols[col%len(cols)]
if circradius:
path=[here,nxt]
else:
#.........这里部分代码省略.........