本文整理汇总了Python中reportlab.graphics.shapes.Rect类的典型用法代码示例。如果您正苦于以下问题:Python Rect类的具体用法?Python Rect怎么用?Python Rect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_header
def create_header(self):
headerCanvas = Drawing()
headerRect = Rect(0, 0, width=self.width, height=50)
headerRect.fillColor = HexColor("#607D8B")
headerRect.strokeColor = HexColor("#607D8B")
headerCanvas.add(headerRect)
renderPDF.draw(headerCanvas, self.c, 0, self.height - 50)
_header_styles = ParagraphStyle(
"Header",
parent=self.styles["Heading1"],
textColor=white,
fontName='Helvetica'
)
p = Paragraph("Kit Trading Fund Report", style = _header_styles)
p.wrapOn(self.c, self.width, self.height - 50)
p.drawOn(self.c, *self.coord(75, 10, mm))
_sub_header_styles = ParagraphStyle(
"SubHeader",
parent=self.styles["Heading4"],
textColor=white,
fontName='Helvetica'
)
p = Paragraph("Monthly Report: January 2016", style = _sub_header_styles)
p.wrapOn(self.c, self.width, self.height - 50)
p.drawOn(self.c, *self.coord(85, 16, mm))
示例2: makeInnerTiles
def makeInnerTiles(self):
# inner grid lines
group = Group()
w, h = self.width, self.height
# inner grid stripes (solid rectangles)
if self.useRects == 1:
cols = self.stripeColors
if self.orientation == 'vertical':
r = self.makeLinePosList(self.x, isX=1)
elif self.orientation == 'horizontal':
r = self.makeLinePosList(self.y, isX=0)
dist = makeDistancesList(r)
i = 0
for j in range(len(dist)):
if self.orientation == 'vertical':
x = r[j]
stripe = Rect(x, self.y, dist[j], h)
elif self.orientation == 'horizontal':
y = r[j]
stripe = Rect(self.x, y, w, dist[j])
stripe.fillColor = cols[i % len(cols)]
stripe.strokeColor = None
group.add(stripe)
i = i + 1
return group
示例3: makeSwatchSample
def makeSwatchSample(self,rowNo, x, y, width, height):
baseStyle = self.lines
styleIdx = rowNo % len(baseStyle)
style = baseStyle[styleIdx]
color = style.strokeColor
yh2 = y+height/2.
lineStyle = getattr(style,'lineStyle',None)
if lineStyle=='bar':
dash = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None))
strokeWidth= getattr(style, 'strokeWidth', getattr(style, 'strokeWidth',None))
L = Rect(x,y,width,height,strokeWidth=strokeWidth,strokeColor=color,strokeLineCap=0,strokeDashArray=dash,fillColor=getattr(style,'fillColor',color))
elif self.joinedLines or lineStyle=='joinedLine':
dash = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None))
strokeWidth= getattr(style, 'strokeWidth', getattr(style, 'strokeWidth',None))
L = Line(x,yh2,x+width,yh2,strokeColor=color,strokeLineCap=0)
if strokeWidth: L.strokeWidth = strokeWidth
if dash: L.strokeDashArray = dash
else:
L = None
if hasattr(style, 'symbol'):
S = style.symbol
elif hasattr(baseStyle, 'symbol'):
S = baseStyle.symbol
else:
S = None
if S: S = uSymbol2Symbol(S,x+width/2.,yh2,color)
if S and L:
g = Group()
g.add(L)
g.add(S)
return g
return S or L
示例4: _draw_segment
def _draw_segment(self, cur_drawing):
"""Draw the current chromosome segment.
"""
# set the coordinates of the segment -- it'll take up the MIDDLE part
# of the space we have.
segment_y = self.end_y_position
segment_width = (self.end_x_position - self.start_x_position) \
* self.chr_percent
segment_height = self.start_y_position - self.end_y_position
segment_x = self.start_x_position \
+ 0.5 * (self.end_x_position - self.start_x_position - segment_width)
# first draw the sides of the segment
right_line = Line(segment_x, segment_y,
segment_x, segment_y + segment_height)
left_line = Line(segment_x + segment_width, segment_y,
segment_x + segment_width, segment_y + segment_height)
cur_drawing.add(right_line)
cur_drawing.add(left_line)
# now draw the box, if it is filled in
if self.fill_color is not None:
fill_rectangle = Rect(segment_x, segment_y,
segment_width, segment_height)
fill_rectangle.fillColor = self.fill_color
fill_rectangle.strokeColor = None
cur_drawing.add(fill_rectangle)
示例5: 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
示例6: _draw_square
def _draw_square(self, color):
"draws a square"
square = Drawing(5, 5)
sqr = Rect(0, 2.5, 5, 5)
sqr.fillColor = color
sqr.strokeColor = color
square.add(sqr)
return square
示例7: makeEmptySquare
def makeEmptySquare(x, y, size, color):
"Make an empty square marker."
d = size/2.0
rect = Rect(x-d, y-d, 2*d, 2*d)
rect.strokeColor = color
rect.fillColor = None
return rect
示例8: makeFilledSquare
def makeFilledSquare(x, y, size, color):
"Make a filled square marker."
d = size/2.0
rect = Rect(x-d, y-d, 2*d, 2*d)
rect.strokeColor = color
rect.fillColor = color
return rect
示例9: draw_square
def draw_square(color):
"draws a square"
from reportlab.graphics.shapes import Rect
from reportlab.graphics.shapes import Drawing
square = Drawing(5, 5)
sqr = Rect(0, 2.5, 5, 5)
sqr.fillColor = color
sqr.strokeColor = color
square.add(sqr)
return square
示例10: makeOuterRect
def makeOuterRect(self):
strokeColor = getattr(self,'rectStrokeColor',self.strokeColor)
strokeWidth = getattr(self,'rectStrokeWidth',self.strokeWidth)
if self.fillColor or (strokeColor and strokeWidth):
rect = Rect(self.x, self.y, self.width, self.height)
rect.fillColor = self.fillColor
rect.strokeColor = strokeColor
rect.strokeWidth = strokeWidth
return rect
else:
return None
示例11: draw
def draw(self):
# general widget bits
group = Group()
x, y, w, h, c0, c1 = self._flipRectCorners()
numShades = self.numShades
if self.cylinderMode:
if not numShades % 2: numShades = numShades + 1
halfNumShades = (numShades - 1) / 2 + 1
num = float(numShades) # must make it float!
vertical = self.orientation == 'vertical'
if vertical:
if numShades == 1:
V = [x]
else:
V = frange(x, x + w, w / num)
else:
if numShades == 1:
V = [y]
else:
V = frange(y, y + h, h / num)
for v in V:
stripe = vertical and Rect(v, y, w / num, h) or Rect(
x, v, w, h / num)
if self.cylinderMode:
if V.index(v) >= halfNumShades:
col = colors.linearlyInterpolatedColor(
c1, c0, V[halfNumShades], V[-1], v)
else:
col = colors.linearlyInterpolatedColor(
c0, c1, V[0], V[halfNumShades], v)
else:
col = colors.linearlyInterpolatedColor(c0, c1, V[0], V[-1], v)
stripe.fillColor = col
stripe.strokeColor = col
stripe.strokeWidth = 1
group.add(stripe)
if self.strokeColor and self.strokeWidth >= 0:
rect = Rect(x, y, w, h)
rect.strokeColor = self.strokeColor
rect.strokeWidth = self.strokeWidth
rect.fillColor = None
group.add(rect)
return group
示例12: create_risk_header
def create_risk_header(self):
_width = self.width / 2 - 10
_height = 20
headerCanvas = Drawing()
headerRect = Rect(0, 0, width = _width, height = _height)
headerRect.fillColor = HexColor("#607D8B")
headerRect.strokeColor = HexColor("#607D8B")
headerCanvas.add(headerRect)
renderPDF.draw(headerCanvas, self.c, x = _width + 20, y = self.height - 75)
_summary_styles = ParagraphStyle(
"RISKS",
parent=self.styles["Heading5"],
textColor=white,
fontName='Helvetica'
)
p = Paragraph("RISKS", style = _summary_styles)
p.wrapOn(self.c, _width, _height)
p.drawOn(self.c, *self.coord(115, 25, mm))
示例13: create_performance_chart_header
def create_performance_chart_header(self):
_width = self.width
_height = 20
headerCanvas = Drawing()
headerRect = Rect(0, 0, width = _width, height = _height)
headerRect.fillColor = HexColor("#607D8B")
headerRect.strokeColor = HexColor("#607D8B")
headerCanvas.add(headerRect)
renderPDF.draw(headerCanvas, self.c, 0, self.height - 217)
_summary_styles = ParagraphStyle(
"PERFORMANCE CHART",
parent=self.styles["Heading5"],
textColor=white,
fontName='Helvetica'
)
p = Paragraph("PERFORMANCE", style = _summary_styles)
p.wrapOn(self.c, _width, _height)
p.drawOn(self.c, *self.coord(4, 75, mm))
示例14: _overdraw_subcomponents
def _overdraw_subcomponents(self, cur_drawing):
"""Draw any annotated features on the chromosome segment.
Assumes _draw_segment already called to fill out the basic shape,
and assmes that uses the same boundaries.
"""
# set the coordinates of the segment -- it'll take up the MIDDLE part
# of the space we have.
segment_y = self.end_y_position
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_height = self.start_y_position - self.end_y_position
segment_x = self.start_x_position \
+ 0.5 * (self.end_x_position - self.start_x_position - segment_width)
left_labels = []
right_labels = []
for f in self.features:
try:
# Assume SeqFeature objects
start = f.location.start
end = f.location.end
strand = f.strand
try:
# Handles Artemis colour integers, HTML colors, etc
color = _color_trans.translate(f.qualifiers['color'][0])
except Exception: # TODO: ValueError?
color = self.default_feature_color
fill_color = color
name = ""
for qualifier in self.name_qualifiers:
if qualifier in f.qualifiers:
name = f.qualifiers[qualifier][0]
break
except AttributeError:
# Assume tuple of ints, string, and color
start, end, strand, name, color = f[:5]
color = _color_trans.translate(color)
if len(f) > 5:
fill_color = _color_trans.translate(f[5])
else:
fill_color = color
assert 0 <= start <= end <= self.bp_length
if strand == +1:
# Right side only
x = segment_x + segment_width * 0.6
w = segment_width * 0.4
elif strand == -1:
# Left side only
x = segment_x
w = segment_width * 0.4
else:
# Both or neither - full width
x = segment_x
w = segment_width
local_scale = segment_height / self.bp_length
fill_rectangle = Rect(x, segment_y + segment_height - local_scale * start,
w, local_scale * (start - end))
fill_rectangle.fillColor = fill_color
fill_rectangle.strokeColor = color
cur_drawing.add(fill_rectangle)
if name:
if fill_color == color:
back_color = None
else:
back_color = fill_color
value = (segment_y + segment_height - local_scale * start, color, back_color, name)
if strand == -1:
self._left_labels.append(value)
else:
self._right_labels.append(value)
示例15: __init__
def __init__(self, x, y, width, height, fillColor=colors.black):
Rect.__init__(self, x, y, width, height, fillColor=fillColor,
strokeColor=None, strokeWidth=0)