本文整理汇总了Python中reportlab.graphics.shapes.String.textAnchor方法的典型用法代码示例。如果您正苦于以下问题:Python String.textAnchor方法的具体用法?Python String.textAnchor怎么用?Python String.textAnchor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.graphics.shapes.String
的用法示例。
在下文中一共展示了String.textAnchor方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_title
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
def _draw_title(self, cur_drawing, title, width, height):
"""Add the title of the figure to the drawing (PRIVATE)."""
title_string = String(width / 2, height - inch, title)
title_string.fontName = "Helvetica-Bold"
title_string.fontSize = self.title_size
title_string.textAnchor = "middle"
cur_drawing.add(title_string)
示例2: _rawDraw
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
def _rawDraw(self):
_text = self._text
self._text = _text or ""
self.computeSize()
self._text = _text
g = Group()
g.translate(self.x + self.dx, self.y + self.dy)
g.rotate(self.angle)
y = self._top - self._leading * self._baselineRatio
textAnchor = self._getTextAnchor()
if textAnchor == "start":
x = self._left
elif textAnchor == "middle":
x = self._left + self._ewidth * 0.5
else:
x = self._right
# paint box behind text just in case they
# fill it
if self.boxFillColor or (self.boxStrokeColor and self.boxStrokeWidth):
g.add(
Rect(
self._left - self.leftPadding,
self._bottom - self.bottomPadding,
self._width,
self._height,
strokeColor=self.boxStrokeColor,
strokeWidth=self.boxStrokeWidth,
fillColor=self.boxFillColor,
)
)
fillColor, fontName, fontSize = self.fillColor, self.fontName, self.fontSize
strokeColor, strokeWidth, leading = self.strokeColor, self.strokeWidth, self._leading
svgAttrs = getattr(self, "_svgAttrs", {})
if strokeColor:
for line in self._lines:
s = _text2Path(line, x, y, fontName, fontSize, textAnchor)
s.fillColor = fillColor
s.strokeColor = strokeColor
s.strokeWidth = strokeWidth
g.add(s)
y -= leading
else:
for line in self._lines:
s = String(x, y, line, _svgAttrs=svgAttrs)
s.textAnchor = textAnchor
s.fontName = fontName
s.fontSize = fontSize
s.fillColor = fillColor
g.add(s)
y -= leading
return g
示例3: _draw_label
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
def _draw_label(self, cur_drawing, label_name):
"""Draw a label for the chromosome."""
x_position = 0.5 * (self.start_x_position + self.end_x_position)
y_position = self.end_y_position
label_string = String(x_position, y_position, label_name)
label_string.fontName = 'Times-BoldItalic'
label_string.fontSize = self.title_size
label_string.textAnchor = 'middle'
cur_drawing.add(label_string)
示例4: _draw_label
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
def _draw_label(self, cur_drawing, label_name):
"""Draw a label for the chromosome.
"""
x_position = self.start_x_position
y_position = self.end_y_position
label_string = String(x_position, y_position, label_name)
label_string.fontName = "Times-BoldItalic"
label_string.fontSize = self.title_size
label_string.textAnchor = "start"
cur_drawing.add(label_string)
示例5: draw
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
def draw(self):
_text = self._text
self._text = _text or ''
self.computeSize()
self._text = _text
g = Group()
g.translate(self.x + self.dx, self.y + self.dy)
g.rotate(self.angle)
y = self._top - self.fontSize
textAnchor = self._getTextAnchor()
if textAnchor == 'start':
x = self._left
elif textAnchor == 'middle':
x = self._left + self._ewidth * 0.5
else:
x = self._right
# paint box behind text just in case they
# fill it
if self.boxFillColor or (self.boxStrokeColor and self.boxStrokeWidth):
g.add(
Rect(
self._left - self.leftPadding,
self._bottom - self.bottomPadding,
self._width,
self._height,
strokeColor=self.boxStrokeColor,
strokeWidth=self.boxStrokeWidth,
fillColor=self.boxFillColor))
fillColor, fontName, fontSize = self.fillColor, self.fontName, self.fontSize
strokeColor, strokeWidth, leading = self.strokeColor, self.strokeWidth, (
self.leading or 1.2 * fontSize)
if strokeColor:
for line in self._lines:
s = _text2Path(line, x, y, fontName, fontSize, textAnchor)
s.fillColor = fillColor
s.strokeColor = strokeColor
s.strokeWidth = strokeWidth
g.add(s)
y = y - leading
else:
for line in self._lines:
s = String(x, y, line)
s.textAnchor = textAnchor
s.fontName = fontName
s.fontSize = fontSize
s.fillColor = fillColor
g.add(s)
y = y - leading
return g
示例6: _addWedgeLabel
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
def _addWedgeLabel(self,text,angle,labelX,labelY,wedgeStyle,labelClass=WedgeLabel):
# now draw a label
if self.simpleLabels:
theLabel = String(labelX, labelY, text)
theLabel.textAnchor = "middle"
theLabel._pmv = angle
theLabel._simple_pointer = 0
else:
theLabel = labelClass()
theLabel._pmv = angle
theLabel.x = labelX
theLabel.y = labelY
theLabel.dx = wedgeStyle.label_dx
theLabel.dy = wedgeStyle.label_dy
theLabel.angle = wedgeStyle.label_angle
theLabel.boxAnchor = wedgeStyle.label_boxAnchor
theLabel.boxStrokeColor = wedgeStyle.label_boxStrokeColor
theLabel.boxStrokeWidth = wedgeStyle.label_boxStrokeWidth
theLabel.boxFillColor = wedgeStyle.label_boxFillColor
theLabel.strokeColor = wedgeStyle.label_strokeColor
theLabel.strokeWidth = wedgeStyle.label_strokeWidth
_text = wedgeStyle.label_text
if _text is None: _text = text
theLabel._text = _text
theLabel.leading = wedgeStyle.label_leading
theLabel.width = wedgeStyle.label_width
theLabel.maxWidth = wedgeStyle.label_maxWidth
theLabel.height = wedgeStyle.label_height
theLabel.textAnchor = wedgeStyle.label_textAnchor
theLabel.visible = wedgeStyle.label_visible
theLabel.topPadding = wedgeStyle.label_topPadding
theLabel.leftPadding = wedgeStyle.label_leftPadding
theLabel.rightPadding = wedgeStyle.label_rightPadding
theLabel.bottomPadding = wedgeStyle.label_bottomPadding
theLabel._simple_pointer = wedgeStyle.label_simple_pointer
theLabel.fontSize = wedgeStyle.fontSize
theLabel.fontName = wedgeStyle.fontName
theLabel.fillColor = wedgeStyle.fontColor
return theLabel
示例7: makeSectors
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
#.........这里部分代码省略.........
popdistance = sectorStyle.popout
cx = centerx + popdistance * cos(aveAngleRadians)
cy = centery + popdistance * sin(aveAngleRadians)
if type(n) in (ListType, TupleType):
theSector = Wedge(
cx,
cy,
xradius + (sn * iradius) - iradius,
a1,
a2,
yradius=yradius + (sn * iradius) - iradius,
radius1=yradius + (sn * iradius) - (2 * iradius),
)
else:
theSector = Wedge(cx, cy, xradius, a1, a2, yradius=yradius, radius1=iradius)
theSector.fillColor = sectorStyle.fillColor
theSector.strokeColor = sectorStyle.strokeColor
theSector.strokeWidth = sectorStyle.strokeWidth
theSector.strokeDashArray = sectorStyle.strokeDashArray
g.add(theSector)
startAngle = endAngle
if labels[i] != "":
averageAngle = (a1 + a2) / 2.0
aveAngleRadians = averageAngle * pi / 180.0
labelRadius = sectorStyle.labelRadius
labelX = centerx + (0.5 * self.width * cos(aveAngleRadians) * labelRadius)
labelY = centery + (0.5 * self.height * sin(aveAngleRadians) * labelRadius)
theLabel = String(labelX, labelY, labels[i])
theLabel.textAnchor = "middle"
theLabel.fontSize = sectorStyle.fontSize
theLabel.fontName = sectorStyle.fontName
theLabel.fillColor = sectorStyle.fontColor
g.add(theLabel)
i = i + 1
sn = sn + 1
else:
# single series doughnut
styleCount = len(self.slices)
iradius = self.height / 5.0
for angle in normData:
endAngle = startAngle + (angle * whichWay) #% 360
if abs(startAngle - endAngle) >= 1e-5:
if startAngle < endAngle:
a1 = startAngle
a2 = endAngle
else:
a1 = endAngle
a2 = startAngle
# if we didn't use %stylecount here we'd end up with the later sectors
# all having the default style
sectorStyle = self.slices[i % styleCount]
# is it a popout?
cx, cy = centerx, centery
if sectorStyle.popout != 0:
# pop out the sector
averageAngle = (a1 + a2) / 2.0
aveAngleRadians = averageAngle * pi / 180.0
popdistance = sectorStyle.popout
示例8: draw
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
def draw(self):
g = Group()
colorNamePairs = self.colorNamePairs
thisx = upperleftx = self.x
thisy = upperlefty = self.y - self.dy
dx, dy, alignment, columnMaximum = self.dx, self.dy, self.alignment, self.columnMaximum
deltax, deltay, dxTextSpace = self.deltax, self.deltay, self.dxTextSpace
fontName, fontSize, fillColor = self.fontName, self.fontSize, self.fillColor
strokeWidth, strokeColor = self.strokeWidth, self.strokeColor
leading = fontSize*1.2
if not deltay:
deltay = max(dy,leading)+self.autoYPadding
if not deltax:
maxWidth = self._calculateMaxWidth(colorNamePairs)
deltax = maxWidth+dx+dxTextSpace+self.autoXPadding
else:
if alignment=='left': maxWidth = self._calculateMaxWidth(colorNamePairs)
def gAdd(t,g=g,fontName=fontName,fontSize=fontSize,fillColor=fillColor):
t.fontName = fontName
t.fontSize = fontSize
t.fillColor = fillColor
return g.add(t)
ascent=getFont(fontName).face.ascent/1000.
if ascent==0: ascent=0.718 # default (from helvetica)
ascent=ascent*fontSize # normalize
columnCount = 0
count = 0
callout = getattr(self,'callout',None)
for col, name in colorNamePairs:
T = string.split(name and str(name) or '','\n')
S = []
# thisy+dy/2 = y+leading/2
y = thisy+(dy-ascent)*0.5
if callout: callout(self,g,thisx,y,colorNamePairs[count])
if alignment == "left":
for t in T:
# align text to left
s = String(thisx+maxWidth,y,t)
s.textAnchor = "end"
S.append(s)
y = y-leading
x = thisx+maxWidth+dxTextSpace
elif alignment == "right":
for t in T:
# align text to right
s = String(thisx+dx+dxTextSpace, y, t)
s.textAnchor = "start"
S.append(s)
y = y-leading
x = thisx
else:
raise ValueError, "bad alignment"
# Make a 'normal' color line-swatch...
if isinstance(col, colors.Color):
l = LineSwatch()
l.x = x
l.y = thisy
l.width = dx
l.height = dy
l.strokeColor = col
g.add(l)
else:
#try and see if we should do better.
try:
c = copy.deepcopy(col)
c.x = x
c.y = thisy
c.width = dx
c.height = dy
g.add(c)
except:
pass
map(gAdd,S)
if count%columnMaximum == columnMaximum-1:
thisx = thisx+deltax
thisy = upperlefty
columnCount = columnCount + 1
else:
thisy = thisy-max(deltay,len(S)*leading)
count = count+1
return g
示例9: make_graphs
# 需要导入模块: from reportlab.graphics.shapes import String [as 别名]
# 或者: from reportlab.graphics.shapes.String import textAnchor [as 别名]
#.........这里部分代码省略.........
for key in self.framework.keys():
plot_dxdy.lines[key].strokeColor = None
plot_dxdy.lines[key].symbol = makeMarker('Circle')
plot_dxdy.lines[key].symbol.strokeColor = None
plot_dxdy.lines[key].symbol.fillColor = self.framework[key]["color"]
plot_dxdy.lines[key].symbol.size = 1.2
plot_dxdy.lines[3].strokeColor = None
plot_dxdy.lines[3].symbol = makeMarker('Circle')
plot_dxdy.lines[3].symbol.strokeColor = colors.blue
plot_dxdy.lines[3].symbol.fillColor = None
plot_dxdy.lines[3].symbol.strokeWidth = 0.6
plot_dxdy.lines[3].symbol.size = plot_dim*(self.sqrtr2)
#print plot_dxdy.lines[3].symbol.getProperties()
plot_dxdy.width = plot_dim
plot_dxdy.height = plot_dim
plot_dxdy.xValueAxis.valueMax = 1.0
plot_dxdy.xValueAxis.valueMin = -1.0
plot_dxdy.xValueAxis.joinAxis = plot_dxdy.yValueAxis
plot_dxdy.xValueAxis.joinAxisMode = 'value'
plot_dxdy.xValueAxis.joinAxisPos = -1.0
plot_dxdy.yValueAxis.valueMax = 1.0
plot_dxdy.yValueAxis.valueMin = -1.0
d_dxdy = Drawing(plot_dim,plot_dim)
d_dxdy.add(plot_dxdy)
# construct cdf plot
plot_cdf_pos = (left_margin*inch, height - 2.0*(plot_dim + 0.5*inch))
plot_cdf = LinePlot()
plot_cdf.data = self.plot_cdf_data
plot_cdf.lines[0].strokeColor = colors.blue
for key in std_colors.keys():
plot_cdf.lines[key+1].strokeColor = None
plot_cdf.lines[key+1].symbol = makeMarker('Circle')
plot_cdf.lines[key+1].symbol.strokeColor = None
plot_cdf.lines[key+1].symbol.fillColor = std_colors[key]
plot_cdf.lines[key+1].symbol.size = 1.2
if (len(self.plot_cdf_data) == 5):
plot_cdf.lines[4].strokeColor = colors.green
plot_cdf.width = plot_dim
plot_cdf.height = plot_dim
plot_cdf.xValueAxis.valueMax = 1.0
plot_cdf.xValueAxis.valueMin = 0.0
plot_cdf.yValueAxis.valueMax = 1.0
plot_cdf.yValueAxis.valueMin = 0.0
d_cdf = Drawing(plot_dim,plot_dim)
d_cdf.add(plot_cdf)
# construct pdf plot
plot_pdf_pos = (left_margin*inch, height - 3.0*(plot_dim + 0.5*inch))
plot_pdf = LinePlot()
plot_pdf.data = self.plot_pdf_data
plot_pdf.lines[1].strokeColor = colors.blue
plot_pdf.lines[0].strokeColor = None
plot_pdf.lines[0].symbol = makeMarker('Circle')
plot_pdf.lines[0].symbol.strokeColor = colors.red
plot_pdf.lines[0].symbol.size = 1
plot_pdf.width = plot_dim
plot_pdf.height = plot_dim
plot_pdf.xValueAxis.valueMax = 1.0
plot_pdf.xValueAxis.valueMin = 0.0
d_pdf = Drawing(2*plot_dim,plot_dim)
d_pdf.add(plot_pdf)
# add legend
legend = Legend()
legend.alignment = 'right'
legend.colorNamePairs = [(std_colors[0],'Inliers (%d'%int(self.fraction*100.0) + '% used for fit)'),
(std_colors[1],'Other inliers'),
(std_colors[2],'Outliers, reject next round'),]
for key in self.framework.keys():
legend.colorNamePairs.append( (self.framework[key]["color"], "%s"%self.framework[key]["status"] ) )
legend.x = plot_dim - 1.0*inch
legend.y = plot_dim
legend.columnMaximum = 8
d_pdf.add(legend)
# add titles
title_pos = (plot_dim/2.0,plot_dim + 0.25*inch)
title_dxdy = String(title_pos[0],title_pos[1],'dx vs. dy (all)')
title_dxdy.fontSize = 15
title_dxdy.textAnchor = 'middle'
d_dxdy.add(title_dxdy)
title_cdf = String(title_pos[0],title_pos[1],'cdf (good)')
title_cdf.fontSize = 15
title_cdf.textAnchor = 'middle'
d_cdf.add(title_cdf)
title_pdf = String(title_pos[0],title_pos[1],'pdf (good)')
title_pdf.fontSize = 15
title_pdf.textAnchor = 'middle'
d_pdf.add(title_pdf)
# draw everything
renderPDF.draw(d_dxdy,canvas,plot_dxdy_pos[0],plot_dxdy_pos[1])
renderPDF.draw(d_cdf,canvas,plot_cdf_pos[0],plot_cdf_pos[1])
renderPDF.draw(d_pdf,canvas,plot_pdf_pos[0],plot_pdf_pos[1])