本文整理汇总了Python中reportlab.graphics.shapes.String类的典型用法代码示例。如果您正苦于以下问题:Python String类的具体用法?Python String怎么用?Python String使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了String类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_labels
def _draw_labels(self, cur_drawing, left_labels, right_labels):
"""Layout and draw sub-feature labels for the chromosome.
Tries to place each label at the same vertical position as the
feature it applies to, but will adjust the positions to avoid or
at least reduce label overlap.
Draws the label text and a coloured line linking it to the
location (i.e. feature) it applies to.
"""
if not self._sub_components:
return
color_label = self._color_labels
segment_width = (self.end_x_position - self.start_x_position) \
* self.chr_percent
label_sep = (self.end_x_position - self.start_x_position) \
* self.label_sep_percent
segment_x = self.start_x_position \
+ 0.5 * (self.end_x_position - self.start_x_position - segment_width)
y_limits = []
for sub_component in self._sub_components:
y_limits.extend((sub_component.start_y_position, sub_component.end_y_position))
y_min = min(y_limits)
y_max = max(y_limits)
del y_limits
# Now do some label placement magic...
# from reportlab.pdfbase import pdfmetrics
# font = pdfmetrics.getFont('Helvetica')
# h = (font.face.ascent + font.face.descent) * 0.90
h = self.label_size
for x1, x2, labels, anchor in [
(segment_x,
segment_x - label_sep,
_place_labels(left_labels, y_min, y_max, h),
"end"),
(segment_x + segment_width,
segment_x + segment_width + label_sep,
_place_labels(right_labels, y_min, y_max, h),
"start"),
]:
for (y1, y2, color, back_color, name) in labels:
cur_drawing.add(Line(x1, y1, x2, y2,
strokeColor=color,
strokeWidth=0.25))
label_string = String(x2, y2, name,
textAnchor=anchor)
label_string.fontName = 'Helvetica'
label_string.fontSize = h
if color_label:
label_string.fillColor = color
if back_color:
w = stringWidth(name, label_string.fontName, label_string.fontSize)
if x1 > x2:
w = w * -1.0
cur_drawing.add(Rect(x2, y2 - 0.1 * h, w, h,
strokeColor=back_color,
fillColor=back_color))
cur_drawing.add(label_string)
示例2: _draw_title
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)
示例3: _rawDraw
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
示例4: _draw_label
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)
示例5: _draw_label
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)
示例6: draw
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
示例7: _draw_label
def _draw_label(self, cur_drawing):
"""Add a label to the chromosome segment.
The label will be applied to the right of the segment.
This may be overlapped by any sub-feature labels on other segments!
"""
if self.label is not None:
label_x = 0.5 * (self.start_x_position + self.end_x_position) + \
(self.chr_percent + 0.05) * (self.end_x_position -
self.start_x_position)
label_y = ((self.start_y_position - self.end_y_position) / 2 +
self.end_y_position)
label_string = String(label_x, label_y, self.label)
label_string.fontName = 'Helvetica'
label_string.fontSize = self.label_size
cur_drawing.add(label_string)
示例8: _addWedgeLabel
def _addWedgeLabel(self,text,add,angle,labelX,labelY,wedgeStyle,labelClass=WedgeLabel):
# now draw a label
if self.simpleLabels:
theLabel = String(labelX, labelY, text)
theLabel.textAnchor = "middle"
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.fontSize = wedgeStyle.fontSize
theLabel.fontName = wedgeStyle.fontName
theLabel.fillColor = wedgeStyle.fontColor
add(theLabel)
示例9: makeSectors
#.........这里部分代码省略.........
aveAngleRadians = averageAngle * pi / 180.0
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
示例10: draw
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
示例11: make_graphs
def make_graphs(self,canvas=None,left_margin=None):#text=None):
from reportlab.graphics import renderPDF
from reportlab.lib.pagesizes import letter
from reportlab.graphics.shapes import Drawing,String
from reportlab.graphics.charts.legends import Legend
from reportlab.graphics.charts.lineplots import LinePlot
from reportlab.graphics.widgets.markers import makeMarker
from reportlab.lib import colors
from reportlab.lib.units import inch
#help(colors)
self.framework = {4:dict(status=SpotClass.SPINDLE,color=colors.black),
5:dict(status=SpotClass.OVERLAP,color=colors.limegreen),
6:dict(status=SpotClass.OUTLIER,color=colors.greenyellow),
7:dict(status=SpotClass.ICE,color=colors.skyblue),
}
# set size and position
width,height = letter
#letter_landscape = (width,height)
plot_dim = 3.0*inch
# construct scatter plot
plot_dxdy_pos = (left_margin*inch,height - plot_dim - 0.5*inch)
plot_dxdy = LinePlot()
plot_dxdy.data = self.plot_dxdy_data
std_colors = {0:colors.darkred, 1:colors.red, 2:colors.salmon}
for key in std_colors.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 = std_colors[key]
plot_dxdy.lines[key].symbol.size = 1.2
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)
#.........这里部分代码省略.........
示例12: __init__
def __init__(self, barcode_value, width=200, height=320, fontSize=30):
barcode = BarcodeGen(barcode_value)
barcode.translate((width-barcode.width)/2, 0)
Drawing.__init__(self, width, height)
self.add(barcode, name='barcode')
box = Box.objects.get(barcode=barcode_value)
box_category = String(10, 275, box.box_category.letter)
box_category.fontSize = 55
box_id = String(10, 230, box.box_id)
box_id.fontSize = 55
expiration = String(12, 195, "Exp: " + box.get_printable_expiration())
expiration.fontSize = 30
category = String(12, 165, box.box_category.name)
category.fontSize = 15
weight = String(12, 150, "Weight: " + "%.1f" % box.weight + ' lbs.')
weight.fontSize = 15
contents = String(12, 135, "Contents:")
contents.fontSize = 15
count = 120
for content in box.contents_set.all():
item = String(17, count, content.item.name)
item.fontSize = 15
self.add(item, "item")
count = count - 15
self.add(box_category, "box_category")
self.add(box_id, "boxId")
self.add(category, "category")
self.add(expiration, "expiration")
self.add(weight, "weight")
self.add(contents, name="contents_of_box")