本文整理汇总了Python中CGAT.SVGdraw类的典型用法代码示例。如果您正苦于以下问题:Python SVGdraw类的具体用法?Python SVGdraw怎么用?Python SVGdraw使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SVGdraw类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeGrid
def writeGrid(self):
"""add grid lines."""
min_x = self.mHeaderWidth
max_x = min_x + self.mDataWidth
min_y = self.mHeaderHeight
max_y = min_y + self.mDataHeight
for contig in self.mSortedContigs1:
if contig not in self.mMapContig2Start1:
continue
x = self.mMapContig2Start1[contig]
e = SVGdraw.line(min_x + x, min_y, min_x + x, max_y,
stroke="rgb(%i,%i,%i)" % GREEN,
)
self.addElement(e)
self.addElement(SVGdraw.line(max_x, min_y, max_x, max_y,
stroke="rgb(%i,%i,%i)" % GREEN))
for contig in self.mSortedContigs2:
if contig not in self.mMapContig2Start2:
continue
y = self.mMapContig2Start2[contig]
e = SVGdraw.line(min_x, min_y + y, max_x, min_y + y,
stroke="rgb(%i,%i,%i)" % GREEN,
)
self.addElement(e)
self.addElement(SVGdraw.line(min_x, max_y, max_x, max_y,
stroke="rgb(%i,%i,%i)" % GREEN))
示例2: writeToFile
def writeToFile(self, outfile):
"""write svg image to file.
"""
self.finalizePlot()
self.mRoot = SVGdraw.drawing()
self.mDraw = SVGdraw.svg(
(0, 0, self.mPageWidth, self.mPageHeight), "100%", "100%")
kk = self.mElements.keys()
kk.sort()
kk.reverse()
for k in kk:
for e in self.mElements[k]:
self.mDraw.addElement(e)
self.mRoot.setSVG(self.mDraw)
tfile = tempfile.mktemp()
self.mRoot.toXml(tfile)
lines = open(tfile, "r").readlines()
outfile.write(string.join(lines, ""))
outfile.write("\n")
os.remove(tfile)
示例3: writeFooter
def writeFooter(self):
"""write footer.
The footer contains the legend.
"""
current_x = self.mFooterFrom
current_y = self.mHeaderHeight + self.mDataHeight + 2 * self.mSeparator
self.mFooterBoxSize = 30
self.mNumTicks = 20
for x in range(len(self.mColourThresholds)):
e = SVGdraw.rect(current_x,
current_y,
self.mFooterBoxSize,
self.mFooterBoxSize,
fill="rgb(%i,%i,%i)" % self.mColours[x],
stroke="rgb(%i,%i,%i)" % self.mColours[x])
self.addElement(e)
if x % self.mNumTicks == 0:
e = SVGdraw.line(current_x,
current_y,
current_x,
current_y + self.mFooterBoxSize,
stroke="rgb(%i,%i,%i)" % BLACK,
stroke_width=5)
self.addElement(e)
e = SVGdraw.text(current_x,
current_y - self.mFooterBoxSize,
self.mFormatNumberLegend % self.mColourThresholds[
x],
self.mFooterFontSize,
self.mFooterFont,
stroke="rgb(%i,%i,%i)" % BLACK,
text_anchor="start")
self.addElement(e)
current_x += self.mFooterBoxSize
###########################################################
if self.mFooter:
current_y += max(self.mFooterFontSize,
self.mMaxBoxSize) + self.mSeparator
e = SVGdraw.text(self.mPageWidth / 2,
current_y + self.mFooterFontSize,
self.mFooter,
self.mFooterFontSize,
self.mFooterFont,
stroke="rgb(%i,%i,%i)" % BLACK,
text_anchor="middle")
self.addElement(e)
示例4: writeToFile
def writeToFile(self, outfile):
"""write svg image to file.
"""
self.finalizePlot()
kk = self.mElements.keys()
kk.sort()
kk.reverse()
# make sure the image size is ok
min_x, min_y, max_x, max_y = 0, 0, 0, 0
for k in kk:
for e in self.mElements[k]:
for x in ('x', 'x2', 'x1'):
if x in e.attributes:
v = e.attributes[x]
min_x = min(min_x, v)
max_x = max(max_x, v)
for y in ('y', 'y2', 'y1'):
if y in e.attributes:
v = e.attributes[y]
min_y = min(min_y, v)
max_y = max(max_y, v)
min_x, min_y = int(math.floor(min_x)), int(math.floor(min_y))
max_x, max_y = int(math.floor(max_x)), int(math.floor(max_y))
for k in kk:
for e in self.mElements[k]:
for x in ('x', 'x2', 'x1'):
if x in e.attributes:
e.attributes[x] -= min_x
for x in ('y', 'y2', 'y1'):
if y in e.attributes:
e.attributes[y] -= min_y
# now add all the elements
self.mRoot = SVGdraw.drawing()
self.mDraw = SVGdraw.svg(
(0, 0, self.mPageWidth - min_x, self.mPageHeight - min_y), "100%", "100%")
for k in kk:
for e in self.mElements[k]:
self.mDraw.addElement(e)
self.mRoot.setSVG(self.mDraw)
tfile = tempfile.mktemp()
self.mRoot.toXml(tfile)
lines = open(tfile, "r").readlines()
outfile.write(string.join(lines, ""))
outfile.write("\n")
os.remove(tfile)
示例5: writeScale
def writeScale(self):
"""write scales."""
current_x = self.mScaleX
current_y = self.mScaleY + self.mScaleHeight
nboxes = len(self.mColourThresholds)
# box size for legend in x-direction
# subtract size of right-most axis label so that it takes the
# same width as self.mDataWidth.
box_size_x = math.ceil((self.mDataWidth -
(self.mScaleFontSize * len(
self.mFormatNumberLegend %
self.mColourThresholds[-1]))) / nboxes)
# change font size such that it labels will fit between tick-marks
self.mScaleFontSize = min(self.mScaleFontSize,
(box_size_x * self.mScaleNumTicks * 1.5) /
len(self.mFormatNumberLegend %
self.mColourThresholds[-1]))
for x in range(nboxes):
e = SVGdraw.rect(current_x,
current_y,
box_size_x,
self.mScaleBoxSizeY,
fill="rgb(%i,%i,%i)" % self.mColours[x],
stroke="rgb(%i,%i,%i)" % self.mColours[x])
self.addElement(e)
if x % self.mScaleNumTicks == 0:
e = SVGdraw.line(current_x,
current_y,
current_x,
current_y + self.mScaleBoxSizeY,
stroke="rgb(%i,%i,%i)" % BLACK,
stroke_width=5)
self.addElement(e)
e = SVGdraw.text(current_x,
current_y - self.mScaleBoxSizeY,
self.mFormatNumberLegend % self.mColourThresholds[
x],
self.mScaleFontSize,
self.mScaleFont,
stroke="rgb(%i,%i,%i)" % BLACK,
text_anchor="start")
self.addElement(e)
current_x += box_size_x
示例6: getElements
def getElements(self, node_id, x1, x2, y):
e = SVGTree.BranchDecoratorHorizontal.getElements(
self, node_id, x1, x2, y)
table_id = str(int(self.mTree.node(node_id).data.branchlength))
if table_id not in self.mTables:
return e
startx = x1 + self.mFontSize
y = y + self.mFontSize
table, column_widths = self.mTables[
table_id], self.mColumnWidths[table_id]
font_weight = "bold"
for r, row in enumerate(table):
x = startx
for c, col in enumerate(row):
e.append(SVGdraw.text(x, y,
col,
20,
self.mFont,
stroke="rgb(%i,%i,%i)" % self.mFontColour,
font_weight=font_weight,
text_anchor="left"))
x += column_widths[c] * self.mFontSize // 2
y += self.mFontSize
font_weight = "normal"
return e
示例7: writeRowHeader
def writeRowHeader(self):
"""write row header
The row header contains the species names
"""
x = 0
y = self.mHeaderHeight
max_l = 0
for species in self.mSpeciesList:
max_l = max(max_l, len(species) * self.mHeaderFontSize) * self.mFontFactor
e = SVGdraw.text(
x,
y,
species,
self.mHeaderFontSize,
self.mHeaderFont,
stroke="rgb(%i,%i,%i)" % BLACK,
text_anchor="left",
)
self.addElement(e)
y += self.mBlockSize + self.mHorizontalSeparator
self.mHeaderWidth = max_l
示例8: writeColHeaders
def writeColHeaders(self):
"""write row headers."""
current_x = self.mColWidth / 2
current_y = self.mHeaderHeight
for i in range(len(self.mColNames)):
if self.mMarkColumns and self.mMarkColumns[i]:
color = BLUE
name = self.mColNames[i] + "*"
else:
color = BLACK
name = self.mColNames[i]
e = SVGdraw.text(
current_x,
current_y,
name,
self.mHeaderFontSize,
self.mHeaderFont,
stroke="rgb(%i,%i,%i)" % color,
text_anchor="start",
transform="rotate(-45,%i,%i)" % (current_x, current_y))
self.mElements.append(e)
current_x += self.mColWidth
示例9: plotOrthologs
def plotOrthologs(self):
"""plot orthologs orthologwise."""
# Do the plot
for ortholog_id in self.mOrthologs1.keys():
for o1 in self.mOrthologs1[ortholog_id]:
try:
x = self.getCoords1(o1)
except KeyError:
continue
for o2 in self.mOrthologs2[ortholog_id]:
try:
y = self.getCoords2(o2)
except KeyError:
continue
e = SVGdraw.circle(x, y,
self.mDotRadius,
fill="rgb(%i,%i,%i)" % BLACK,
stroke="rgb(%i,%i,%i)" % BLACK,
stroke_width=1)
self.addElement(e)
示例10: addValue
def addValue(self, row, col, size, colour_value):
"""add a dot in row/col.
"""
# decide the size of the box
pos = bisect.bisect(self.mThresholdsSize, size)
if self.mRevertSize:
size = self.mMaxBoxSize * \
(1.0 - float(pos) / len(self.mThresholdsSize))
else:
size = self.mMaxBoxSize * float(pos) / len(self.mThresholdsSize)
d = (self.mMaxBoxSize - size) / 2
x = self.mMapCol2Position[col] + d
try:
y = self.mMapRow2Position[row] + d
except KeyError:
return
# determine the colour of the box
pos = bisect.bisect(self.mThresholdsColour, colour_value)
colour = self.mColours[pos]
e = SVGdraw.rect(x, y,
size, size,
stroke="black",
fill="rgb(%i,%i,%i)" % colour)
self.mElements.append(e)
示例11: getSVG
def getSVG(self, xoffset, yoffset):
return SVGdraw.image(self.mFilename,
self.mX + xoffset,
self.mY + yoffset,
self.mWidth,
self.mHeight,
opacity=self.mOpacity)
示例12: getElements
def getElements(self, node_id, x, y1, y2):
e = []
e.append(SVGdraw.line(x, y1, x, y2,
stroke="rgb(%i,%i,%i)" % BLACK,
stroke_width=1))
return e
示例13: addSeparator
def addSeparator(self):
"""add separator on circles."""
if self.mRadius not in self.mSeparators:
e = SVGdraw.circle(self.mDataMiddleX, self.mDataMiddleY, self.mRadius, fill="none",
stroke="rgb(%i,%i,%i)" % self.mGridColour,
stroke_width=self.mGridStrokeWidth)
self.addWheelElement(e, self.mPlaneGrid)
self.mSeparators[self.mRadius] = 1
示例14: addGroupStart
def addGroupStart(self, x, y, contig, start):
"""plot start of contig."""
t = "%s:%i" % (contig, start)
max_x = x + len(t) * self.contigFontSize * self.mFontFactor
# plot line
e = SVGdraw.line(x, y, max_x, y, stroke="rgb(%i,%i,%i)" % BLACK)
self.addElement(e)
e = SVGdraw.text(
x, y, t, self.contigFontSize, self.contigFont, stroke="rgb(%i,%i,%i)" % BLACK, text_anchor="left"
)
self.addElement(e)
return max_x
示例15: writeGrid
def writeGrid(self):
"""add grid lines."""
middlex = self.mDataMiddleX
middley = self.mDataMiddleY
# print separators
for c in range(len(self.contigs)):
contig = self.contigs[c]
pos = self.getPosition(contig, "+", 0)
angle = self.getAngle(pos)
x, y = self.getPosOnArc(angle, self.mRadius)
e = SVGdraw.line(middlex,
middley,
x,
y,
stroke="rgb(%i,%i,%i)" % BLACK,
stroke_width=self.mGridStrokeWidth)
self.addElement(e, self.mPlaneGrid)
if c < len(self.contigs) - 1:
next_angle = self.getAngle(
self.getPosition(self.contigs[c + 1], "+", 0))
else:
next_angle = 360
x, y = self.getPosOnArc(
angle + float(next_angle - angle) / 2, self.mRadiusStart / 2)
e = SVGdraw.text(x,
y,
contig,
self.mGridFontSize,
self.mGridFont,
stroke="rgb(%i,%i,%i)" % BLACK,
text_anchor="start")
# do not rotate text:
# transform="rotate(%i,%i,%i)" % ( angle, x, y ))
self.addElement(e)