Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use feature fill colour as label background on chromsome diagrams

Based on an earlier hack from Oct 2011, which like the recently
committed fill color, was used in figures in Jupe et al. (2012)
http://dx.doi.org/10.1186/1471-2164-13-75
  • Loading branch information...
commit c8ec2faf893905f781c9b6cc10a07b1359f8032d 1 parent 4aa11be
@peterjc peterjc authored
Showing with 14 additions and 2 deletions.
  1. +14 −2 Bio/Graphics/BasicChromosome.py
View
16 Bio/Graphics/BasicChromosome.py
@@ -33,6 +33,7 @@
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
from reportlab.lib import colors
+from reportlab.pdfbase.pdfmetrics import stringWidth
from reportlab.graphics.shapes import Drawing, String, Line, Rect, Wedge, ArcPath
from reportlab.graphics import renderPDF, renderPS
@@ -330,7 +331,7 @@ def _draw_labels(self, cur_drawing, left_labels, right_labels):
_place_labels(right_labels, y_min, y_max, h),
"start"),
]:
- for (y1, y2, color, name) in labels:
+ for (y1, y2, color, back_color, name) in labels:
cur_drawing.add(Line(x1, y1, x2, y2,
strokeColor = color,
strokeWidth = 0.25))
@@ -340,6 +341,13 @@ def _draw_labels(self, cur_drawing, left_labels, right_labels):
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)
@@ -676,7 +684,11 @@ def _overdraw_subcomponents(self, cur_drawing):
fill_rectangle.strokeColor = color
cur_drawing.add(fill_rectangle)
if name:
- value = (segment_y + segment_height - local_scale*start, color, 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:
Please sign in to comment.
Something went wrong with that request. Please try again.