本文整理汇总了Python中reportlab.graphics.charts.textlabels.Label类的典型用法代码示例。如果您正苦于以下问题:Python Label类的具体用法?Python Label怎么用?Python Label使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Label类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: draw
def draw(self):
# general widget bits
w = float(self.length)
h = float(self.height)
g = shapes.Group()
body = shapes.Polygon(
[self.x-0.5*w, self.y-0.5*w,
self.x-0.5*w, self.y+0.5*w,
self.x+0.5*w, self.y],
fillColor=self.fillColor,
strokeColor=self.strokeColor,
strokeWidth=self.strokeWidth)
g.add(body)
if self.label:
b = g.getBounds()
s = Label()
s.setText(self.label)
s.setOrigin(self.x+0.5*w, self.y-h/2+b[3]-b[1]+4)
s.boxAnchor = self.boxAnchor
s.textAnchor = self.textAnchor
s.fontName = 'Helvetica'
s.fontSize = self.fontSize
s.angle = self.labelAngle
g.add(s)
return g
开发者ID:SiriusShiu,项目名称:Mungo,代码行数:28,代码来源:Glyphs.py
示例2: colorTest
def colorTest(self):
from reportlab.graphics.shapes import Rect
from reportlab.graphics.charts.textlabels import Label
self.colorRangeStatic(130)
dim=25
width = self.PAGE_WIDTH-150
inrow = 8 #int(width/dim)
height = int(len(self.colors)/inrow)
if len(self.colors)%inrow > 0:
height +=1
height *= dim
drawing = Drawing(width, height)
for i,col in enumerate(self.colors):
x = (i%inrow)*dim
y = int(i/inrow)*dim
rec = Rect(x=x,y=y,width=dim,height=dim)
rec.fillColor = col
drawing.add(rec)
lab = Label()
lab.x=x+dim/2
lab.y=y+dim/2
lab.setText('%d'%i)
drawing.add(lab)
return drawing
开发者ID:jhuguetn,项目名称:WAD_Python,代码行数:25,代码来源:reporter.py
示例3: getTalkRect
def getTalkRect(self, startTime, duration, trackId, text):
"Return shapes for a specific talk"
g = Group()
y_bottom = self.scaleTime(startTime + duration)
y_top = self.scaleTime(startTime)
y_height = y_top - y_bottom
if trackId is None:
#spans all columns
x = self._colLeftEdges[1]
width = self.width - self._colWidths[0]
else:
#trackId is 1-based and these arrays have the margin info in column
#zero, so no need to add 1
x = self._colLeftEdges[trackId]
width = self._colWidths[trackId]
lab = Label()
lab.setText(text)
lab.setOrigin(x + 0.5*width, y_bottom+0.5*y_height)
lab.boxAnchor = 'c'
lab.width = width
lab.height = y_height
lab.fontSize = 6
r = Rect(x, y_bottom, width, y_height, fillColor=colors.cyan)
g.add(r)
g.add(lab)
#now for a label
# would expect to color-code and add text
return g
开发者ID:tschalch,项目名称:pyTray,代码行数:32,代码来源:eventcal.py
示例4: _test0
def _test0(self):
"Perform original test function."
pdfPath = outputfile('test_charts_textlabels.pdf')
c = Canvas(pdfPath)
label = Label()
demoLabel = label.demo()
demoLabel.drawOn(c, 0, 0)
c.save()
开发者ID:ShaulBarkan,项目名称:PRION,代码行数:11,代码来源:test_charts_textlabels.py
示例5: _drawLabels
def _drawLabels(self, label, labelCenter, y, width):
"""
Draw the label given in a given area originating at (x,y) with width 'width'
"""
fontName = 'Times-Roman'
fontSize = 10
#Limit the length of the label to the boundaries of the chartAreaWidth
strWidth = self._stringWidth(label, fontName, fontSize)
#Calculate the area taken by one character
oneCharWidth = self._stringWidth(label[0], fontName, fontSize)
#If the given string needs more size, reduce the string to a length which fits
#in the given area
if strWidth > width:
maxPossibleLen = int(width/oneCharWidth)
label = label[:maxPossibleLen]
strWidth = self._stringWidth(label, fontName, fontSize)
x = (labelCenter - ((strWidth)/2))
Label_Graph = Label()
Label_Graph.fontName = fontName
Label_Graph.fontSize = fontSize
#Label_Graph.angle = 0
Label_Graph.boxAnchor = 'n'
Label_Graph.x = x
Label_Graph.y = y
Label_Graph.setText(label)
self.drawing.add(Label_Graph)
开发者ID:roytest001,项目名称:PythonCode,代码行数:28,代码来源:Qlib.py
示例6: addScale
def addScale(drawing, xmap, y, start, end, tickLen=10, dx=3, dy=6,
textAnchor='middle', boxAnchor='s', fontSize=12,
strokeWidth=1, strokeColor=colors.black, scale=1.0, format='%ibp'):
x1 = xmap(start)
x2 = xmap(end)
line = Line(x1+dx,y,x2-dx,y,
strokeWidth=strokeWidth, strokeColor=strokeColor)
drawing.add(line)
leftTick = Line(x1+dx,y-0.5*tickLen,x1+dx,y+0.5*tickLen,
strokeWidth=strokeWidth, strokeColor=strokeColor)
drawing.add(leftTick)
rightTick = Line(x2-dx,y-0.5*tickLen,x2-dx,y+0.5*tickLen,
strokeWidth=strokeWidth, strokeColor=strokeColor)
drawing.add(rightTick)
label = Label()
label.setOrigin(0.5*(x1+x2), y+dy)
distance = float(end-start)/scale
label.setText(format % (distance/scale))
label.fontSize = fontSize
label.textAnchor = textAnchor
label.boxAnchor = boxAnchor
drawing.add(label)
开发者ID:SiriusShiu,项目名称:Mungo,代码行数:26,代码来源:__init__.py
示例7: setDescription
def setDescription(self):
desc = Label()
desc.fontName = 'Helvetica'
desc.fontSize = 12
desc.x = 230
desc.y = 10
desc._text = self._data_dict.get('description', '')
desc.maxWidth = 280
desc.height = 20
desc.textAnchor ='middle'
self.add(desc, name='Description')
开发者ID:upfrontsystems,项目名称:tarmii.theme,代码行数:11,代码来源:charts.py
示例8: setTitle
def setTitle(self):
title = Label()
title.fontName = 'Helvetica-Bold'
title.fontSize = 12
title.x = 300
title.y = 335
title._text = self._data_dict.get('title', '')
title.maxWidth = 180
title.height = 20
title.textAnchor ='middle'
self.add(title, name='Title')
开发者ID:upfrontsystems,项目名称:tarmii.theme,代码行数:11,代码来源:charts.py
示例9: title_draw
def title_draw(self, x, y, text):
chart_title = Label()
chart_title.x = x
chart_title.y = y
chart_title.fontName = 'FreeSansBold'
chart_title.fontSize = 16
chart_title.textAnchor = 'middle'
chart_title.setText(text)
return chart_title
开发者ID:jink8904,项目名称:mysite,代码行数:9,代码来源:pdf.py
示例10: draw_travels
def draw_travels(self):
for p in self.world.packets:
if self.detailed:
txt = p.command()
else:
txt = "(%d) %s" % (p.number, p.description)
last_action = (0,0)
for ts in p.trip:
action = self.packet_actions[ts.action]
if ts.actor not in self.verticals:
self.verticals[ts.actor] = self.verticals[ts.actor.node]
x2,y2 = self.verticals[ts.actor], -ts.time*self.yzoom
if action.sprite:
self.sequence_diagram.add(shapes.Circle(x2, y2,
action.size, fillColor=action.color, strokeWidth=1 ))
if action.travel:
if action.travel_desc:
# self.sequence_diagram.add(shapes.String((last_action[0] + x)/2,(last_action[1]+y)/2, label, fill=colors.black, textAnchor = 'middle'))
x1, y1 = last_action[0], last_action[1]
l = Label()
l.setText(txt)
l.angle = atan2((y2-y1)/2, (x2-x1))*360.0/pi
l.dy = 10
l.setOrigin((x1 + x2)/2,(y1+y2)/2)
self.sequence_diagram.add(l)
#anchor = Paragraph('<a name="diagram%d"/>' %p.number, styles['Normal'])
self.sequence_diagram.add(shapes.Line(last_action[0],last_action[1],x2,y2, strokeColor=colors.black, strokeWidth=1))
self.max_y = min(y2, self.max_y, last_action[1])
last_action = (x2,y2)
开发者ID:rayene,项目名称:netpylab,代码行数:31,代码来源:report.py
示例11: addPointyCompoundFeature
def addPointyCompoundFeature(drawing, xmap, y, gene,
strokeColor=None, fillColor=colors.blue, intronColor=colors.blue,
glyph=PointyBlock, height=12, utrHeight=6, rise=8,
labeldy=10, fontSize=10, textAnchor='middle', boxAnchor='s'):
"""Adds a pointy compound feature to the drawing. This is typically
several exons joined by zig-zag lines with an arrow showing strand."""
if gene.strand=='+':
x1,x2 = xmap(gene.start), xmap(gene.end)
else:
x2,x1 = xmap(gene.start), xmap(gene.end)
y = y+height/2
y1 = y
line = Line(x1,y1,x2,y1,strokeColor=intronColor)
drawing.add(line)
for exon in gene:
if exon.strand=='+':
x1,x2 = xmap(exon.start), xmap(exon.end)
else:
x2,x1 = xmap(exon.start), xmap(exon.end)
g = glyph()
g.x = x1
g.y = y
if exon.kind.lower()=='utr':
g.height = utrHeight
else:
g.height = height
g.length = x2-x1
g.fillColor = fillColor
if strokeColor:
g.strokeColor = strokeColor
else:
g.strokeColor = fillColor
g.fontSize = fontSize
drawing.add(g)
label = Label()
label.setText(gene.name)
x = 0.5*(gene.start+gene.end)
label.setOrigin(x,y)
label.dy = labeldy
label.textAnchor = textAnchor
label.boxAnchor = boxAnchor
drawing.add(label)
开发者ID:SiriusShiu,项目名称:Mungo,代码行数:45,代码来源:__init__.py
示例12: cn_process
def cn_process(self, text, x, y, pathnow) :
pdfmetrics.registerFont(ttfonts.TTFont("font1",'simsun.ttc'))
title = Label()
title.fontName = "font1"
title.fontSize = 14
title_text = text
title._text = title_text
title.x = x
title.y = y
return (title)
开发者ID:burningxiong,项目名称:WebZ,代码行数:11,代码来源:autoreport.py
示例13: _makeProtoLabel
def _makeProtoLabel(self):
"Return a label prototype for further modification."
protoLabel = Label()
protoLabel.dx = 0
protoLabel.dy = 0
protoLabel.boxStrokeWidth = 0.1
protoLabel.boxStrokeColor = colors.black
protoLabel.boxFillColor = colors.yellow
# protoLabel.text = 'Hello World!' # Does not work as expected.
return protoLabel
开发者ID:ShaulBarkan,项目名称:PRION,代码行数:12,代码来源:test_charts_textlabels.py
示例14: addAxis
def addAxis(drawing, xmap, y, fontSize=8, tickLen=4, minorTickLen=2,
nTicks=20, strokeWidth=1, minorStrokeWidth=0.5):
line = Line(xmap.x0, y, xmap.x1, y, strokeWidth=strokeWidth)
drawing.add(line)
ticks = tick_generator(xmap.start, xmap.end, n=nTicks, convert=int)
for p in ticks:
x = xmap(p)
line = Line(x, y, x, y-tickLen, strokeWidth=strokeWidth)
drawing.add(line)
s = Label()
s.setOrigin(x, y-tickLen)
s.setText(str(p))
s.fontName = 'Helvetica'
s.fontSize = fontSize
s.textAnchor = 'middle'
s.boxAnchor = 'n'
drawing.add(s)
minorticks = tick_generator(xmap.start, xmap.end, n=50, convert=int)
for p in minorticks:
x = xmap(p)
line = Line(x, y, x, y-minorTickLen, strokeWidth=minorStrokeWidth)
drawing.add(line)
开发者ID:SiriusShiu,项目名称:Mungo,代码行数:24,代码来源:draw_orig.py
示例15: addLabels
def addLabels(self,drawing,title=None,xlabel=None,ylabel=None):
from reportlab.graphics.charts.textlabels import Label
if not title is None:
Title = Label()
Title.fontName = 'Helvetica-Bold'
Title.fontSize = 7
Title.x = drawing.width/2
Title.y = drawing.height-25
Title._text = title
Title.maxWidth = 180
Title.height = 20
Title.textAnchor ='middle'
drawing.add(Title)
if not xlabel is None:
XLabel = Label()
XLabel.fontName = 'Helvetica'
XLabel.fontSize = 7
XLabel.x = drawing.width/2
XLabel.y = 10
XLabel.textAnchor ='middle'
XLabel.maxWidth = 100
XLabel.height = 20
XLabel._text = xlabel
drawing.add(XLabel)
if not ylabel is None:
YLabel = Label()
YLabel.fontName = 'Helvetica'
YLabel.fontSize = 7
YLabel.x = 12
YLabel.y = drawing.height/2
YLabel.angle = 90
YLabel.textAnchor ='middle'
YLabel.maxWidth = 100
YLabel.height = 20
YLabel._text = ylabel
drawing.add(YLabel)
开发者ID:jhuguetn,项目名称:WAD_Python,代码行数:38,代码来源:reporter.py
示例16: _rawDraw
def _rawDraw(self, x, y):
from reportlab.lib import colors
from reportlab.graphics.shapes import Drawing, Line, String, STATE_DEFAULTS
from reportlab.graphics.charts.axes import XCategoryAxis,YValueAxis
from reportlab.graphics.charts.textlabels import Label
from reportlab.graphics.charts.barcharts import VerticalBarChart
self.originX = x
self.originY = y
self._setScale([self.dataBar])
(x1, y1, Width, Height) = self._getGraphRegion(x, y)
#Build the graph
self.drawing = Drawing(self.width, self.height)
#Size of the Axis
SizeXaxis = 14
countSteps = int(self.valueMax / self.valueStep)
SizeYaxis = 0.0
for n in range(countSteps + 1):
eachValue = self.valueMin + n * self.valueStep
textString = self._customSecondsLabelFormat( eachValue )
SizeYaxis = max(SizeYaxis, self._stringWidth(textString, STATE_DEFAULTS['fontName'], STATE_DEFAULTS['fontSize']) )
bc = VerticalBarChart()
SizeYaxis += bc.valueAxis.tickLeft
bc.x = x1 - x + SizeYaxis
bc.y = y1 - y + SizeXaxis
bc.height = Height - SizeXaxis
bc.width = Width - SizeYaxis
self.graphCenterX = bc.x + bc.width/2
self.graphCenterY = bc.y + bc.height/2
if self.validData:
# add valid data to chart
bc.data = self.dataBar
bc.categoryAxis.categoryNames = self.dataNames
# axis values
bc.valueAxis.valueMin = self.valueMin
bc.valueAxis.valueMax = self.valueMax
bc.valueAxis.valueStep = self.valueStep
# add value labels above bars
bc.barLabelFormat = self._customSecondsLabelFormat
bc.barLabels.dy = 0.08*inch
bc.barLabels.fontSize = 6
else:
# no valid data
bc.data = [ (0, ), ]
bc.categoryAxis.categoryNames = [ '' ]
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = 1
bc.valueAxis.valueStep = 1
Nodata = Label()
Nodata.fontSize = 12
Nodata.angle = 0
Nodata.boxAnchor = 'c'
Nodata.dx = self.graphCenterX
Nodata.dy = self.graphCenterY
Nodata.setText("NO VALID DATA")
self.drawing.add(Nodata)
# chart formatting
(R,G,B) = VeriwaveYellow
bc.bars[0].fillColor = colors.Color(R,G,B)
bc.valueAxis.labelTextFormat = self._customSecondsLabelFormat
# axis labels
bc.categoryAxis.labels.boxAnchor = 'c'
bc.categoryAxis.labels.dx = 0
bc.categoryAxis.labels.dy = -10
bc.categoryAxis.labels.angle = 0
bc.categoryAxis.labels.fontSize = 8
# add chart
self.drawing.add(bc)
#Adjust the labels to be the center of the graph
self._drawLabels(self.title, "", "")
# Add Legend in upper right corner
legendHeight = 9
legendX = bc.x + 5
legendY = bc.y + bc.height - 12
self.drawing.add(Line(legendX, legendY + 3 , legendX + 20, legendY + 3, strokeColor=bc.bars[0].fillColor, strokeWidth=3 ))
self.drawing.add(String(legendX + 22, legendY, 'MIN', fontName='Helvetica', fontSize=8))
legendY -= legendHeight
self.drawing.add(Line(legendX, legendY + 3 , legendX + 20, legendY + 3, strokeColor=bc.bars[1].fillColor, strokeWidth=3 ))
self.drawing.add(String(legendX + 22, legendY, 'MAX', fontName='Helvetica', fontSize=8))
legendY -= legendHeight
self.drawing.add(Line(legendX, legendY + 3 , legendX + 20, legendY + 3, strokeColor=bc.bars[2].fillColor, strokeWidth=3 ))
self.drawing.add(String(legendX + 22, legendY, 'AVG', fontName='Helvetica', fontSize=8))
legendY -= legendHeight
开发者ID:roytest001,项目名称:PythonCode,代码行数:90,代码来源:mesh_self_healing_time.py
示例17: draw
def draw(self):
ascent=getFont(self.xValueAxis.labels.fontName).face.ascent
if ascent==0:
ascent=0.718 # default (from helvetica)
ascent=ascent*self.xValueAxis.labels.fontSize # normalize
#basic LinePlot - does the Axes, Ticks etc
lp = LinePlot.draw(self)
xLabel = self.xLabel
if xLabel: #Overall label for the X-axis
xl=Label()
xl.x = (self.x+self.width)/2.0
xl.y = 0
xl.fontName = self.xValueAxis.labels.fontName
xl.fontSize = self.xValueAxis.labels.fontSize
xl.setText(xLabel)
lp.add(xl)
yLabel = self.yLabel
if yLabel: #Overall label for the Y-axis
yl=Label()
yl.angle = 90
yl.x = 0
yl.y = (self.y+self.height/2.0)
yl.fontName = self.yValueAxis.labels.fontName
yl.fontSize = self.yValueAxis.labels.fontSize
yl.setText(yLabel)
lp.add(yl)
# do a bounding box - in the same style as the axes
if self.outerBorderOn:
lp.add(Rect(self.x, self.y, self.width, self.height,
strokeColor = self.outerBorderColor,
strokeWidth = self.yValueAxis.strokeWidth,
fillColor = None))
lp.shift(self.leftPadding, self.bottomPadding)
return lp
开发者ID:SongJLG,项目名称:johan-doc,代码行数:40,代码来源:lineplots.py
示例18: setAxesLabels
def setAxesLabels(self):
xlabel = Label()
xlabel.fontName = 'Helvetica'
xlabel.fontSize = 12
xlabel.x = 450
xlabel.y = 40
xlabel._text = self._data_dict.get('xlabel', '')
xlabel.maxWidth = 180
xlabel.height = 20
xlabel.textAnchor ='middle'
self.add(xlabel, name='xlabel')
ylabel = Label()
ylabel.fontName = 'Helvetica'
ylabel.fontSize = 12
ylabel.x = 20
ylabel.y = 210
ylabel.angle = 90
ylabel._text = self._data_dict.get('ylabel', '')
ylabel.maxWidth = 180
ylabel.height = 20
ylabel.textAnchor ='middle'
self.add(ylabel, name='ylabel')
开发者ID:upfrontsystems,项目名称:tarmii.theme,代码行数:23,代码来源:charts.py
示例19: half_year
def half_year(title,city, year, startmon):
'''startmon is the 1-indexed month to start the page on'''
reqd, mons = get_months(year, startmon)
LEFTMARGIN = 5
DAYCOLWIDTH = 50
CELLWIDTH = 80
CELLHEIGHT = 19
TOPROWHEIGHT = 18
WIDTH = LEFTMARGIN + DAYCOLWIDTH + CELLWIDTH*6
HEIGHT = reqd * CELLHEIGHT + TOPROWHEIGHT
d = shapes.Drawing(WIDTH, HEIGHT)
lab = Label()
lab.setOrigin(LEFTMARGIN,HEIGHT)
lab.boxAnchor = 'nw'
lab.setText(title)
lab.fontName = 'Times-Bold'
d.add(lab)
# Month headings
for i in range(6):
x = LEFTMARGIN + i*CELLWIDTH + DAYCOLWIDTH + CELLWIDTH/2
month_name = calendar.month_abbr[i + startmon]
d.add(shapes.String(x, HEIGHT-14, month_name,
fontSize=14, fontName='Times-Bold', textAnchor='middle'))
# Day row headings
for i in range(reqd):
y = HEIGHT - i*CELLHEIGHT - TOPROWHEIGHT
weekday_name = calendar.day_abbr[i%7]
d.add(shapes.String(LEFTMARGIN + 10, y-14, weekday_name,
fontSize=14))
# Draw the day cells, for each month
for j in range(6):
x = LEFTMARGIN + j*CELLWIDTH + DAYCOLWIDTH
# for each day
for i in range(reqd):
if i >= len(mons[j]) or not mons[j][i]:
continue
y = HEIGHT - i*CELLHEIGHT - TOPROWHEIGHT
# cells for each day, light grey background if weekend
weekend = i%7 > 4
lightgrey = colors.HexColor(0xD0B090)
color = weekend and lightgrey or colors.white
# Now we have (x, y, color) for (year, month=j+startmon, day=mons[j][i])
# Get the ephemerides for the date
date = datetime.datetime(year, j+startmon, mons[j][i])
(sunrise, sunset, moon_phase, moon_fm) = ephem3.ephem_one_day(city, date)
# Insert the date cell at x, y
d.add(shapes.Rect(x, y, CELLWIDTH, -CELLHEIGHT, fillColor=color))
d.add(shapes.String(x+1, y-10, str(mons[j][i]), fontSize=10))
green = colors.HexColor(0x207020)
# Insert the moon phase
if moon_fm:
d.add(shapes.String(x+15, y-10, moon_fm, fontSize=8, fillColor=green))
# for each day
# for each month
return d
开发者ID:moshahmed,项目名称:astronomy,代码行数:64,代码来源:caly.py
示例20: Drawing
lab.boxStrokeColor = colors.green
lab.setText('Some\nMulti-Line\nLabel')
d.add(lab)
""")
from reportlab.graphics import shapes
from reportlab.graphics.charts.textlabels import Label
d = Drawing(200, 100)
# mark the origin of the label
d.add(Circle(100,90, 5, fillColor=colors.green))
lab = Label()
lab.setOrigin(100,90)
lab.boxAnchor = 'ne'
lab.angle = 45
lab.dx = 0
lab.dy = -20
lab.boxStrokeColor = colors.green
lab.setText('Some\nMulti-Line\nLabel')
d.add(lab)
draw(d, 'Label example')
disc("""
开发者ID:makinacorpus,项目名称:reportlab-ecomobile,代码行数:31,代码来源:graph_charts.py
注:本文中的reportlab.graphics.charts.textlabels.Label类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论