Skip to content

Commit

Permalink
Merge pull request #351 from padix-key/issue-345
Browse files Browse the repository at this point in the history
Fix #345
  • Loading branch information
padix-key authored Aug 27, 2021
2 parents e147d65 + e8b9ea1 commit 7642539
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/biotite/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
from numpy.linalg import norm


# Biotite themed colors
colors = OrderedDict([
("brightorange" , "#ffb569ff"),
("lightorange" , "#ff982dff"),
("orange" , "#ff8405ff"),
("dimorange" , "#dc7000ff"),
("darkorange" , "#b45c00ff"),
("brightgreen" , "#98e97fff"),
("lightgreen" , "#6fe04cff"),
("green" , "#52da2aff"),
("dimgreen" , "#45bc20ff"),
("darkgreen" , "#389a1aff"),
])


def set_font_size_in_coord(text, width=None, height=None, mode="unlocked"):
"""
Specifiy the font size of an existing `Text` object in coordinates
Expand Down Expand Up @@ -61,7 +76,6 @@ def set_font_size_in_coord(text, width=None, height=None, mode="unlocked"):
the boundaries for an initial size of 1 'pt' seem to be most exact.
"""
from matplotlib.transforms import Bbox
from matplotlib.text import Text
from matplotlib.patheffects import AbstractPathEffect

class TextScaler(AbstractPathEffect):
Expand All @@ -73,8 +87,16 @@ def __init__(self, text, width, height, mode):

def draw_path(self, renderer, gc, tpath, affine, rgbFace=None):
ax = self._text.axes
renderer = ax.get_figure().canvas.get_renderer()
bbox = text.get_window_extent(renderer=renderer)
try:
renderer = ax.get_figure().canvas.get_renderer()
except:
# Use cached renderer for backends, where
# `get_renderer()` is not available
# Based on the strategy from `Text.get_window_extent()`
renderer = ax.get_figure()._cachedRenderer
if renderer is None:
raise
bbox = text.get_window_extent(renderer)
bbox = Bbox(ax.transData.inverted().transform(bbox))

if self._mode == "proportional":
Expand Down Expand Up @@ -225,19 +247,4 @@ def set_in_layout(self, in_layout):
__all__.append("AdaptiveFancyArrow")

except ImportError:
pass


# Biotite themed colors
colors = OrderedDict([
("brightorange" , "#ffb569ff"),
("lightorange" , "#ff982dff"),
("orange" , "#ff8405ff"),
("dimorange" , "#dc7000ff"),
("darkorange" , "#b45c00ff"),
("brightgreen" , "#98e97fff"),
("lightgreen" , "#6fe04cff"),
("green" , "#52da2aff"),
("dimgreen" , "#45bc20ff"),
("darkgreen" , "#389a1aff"),
])
pass

0 comments on commit 7642539

Please sign in to comment.