Skip to content

Commit

Permalink
Merge pull request #499 from u6052029/dendrogram-circular-support_text
Browse files Browse the repository at this point in the history
ENH: support text supported in circular dendrogram, fixes #451
  • Loading branch information
GavinHuttley committed Jan 20, 2020
2 parents 428398b + 9ceb1ba commit e4d9427
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions src/cogent3/draw/dendrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,19 @@ def support_text_coord(self, xshift, yshift, threshold=1, max_attr_length=4):
-------
None if threshold not met, else params['support'] and coords
"""
if xshift is None:
xshift = -14

if yshift is None:
yshift = 7

if self.is_tip():
return None

val = self.params.get("support", None)
if val is None or val > threshold or self.is_tip():
return None

x = self.x
data = UnionDict(
x=x,
Expand Down Expand Up @@ -431,10 +438,45 @@ def value_and_coordinate(self, attr="name", padding=0.05, max_attr_length=None):

@extend_docstring_from(TreeGeometryBase.support_text_coord)
def support_text_coord(self, xshift, yshift, threshold=1, max_attr_length=4):
from warnings import warn
if xshift is None:
xshift = -18

if yshift is None:
yshift = 3

if self.is_tip():
return None

val = self.params.get("support", None)
if val is None or val > threshold or self.is_tip():
return None

if 90 < self.theta <= 270:
textangle = 180 - self.theta
else:
textangle = 360 - self.theta
xshift = -xshift

c = np.cos(textangle * (np.pi / 180))
s = np.sin(textangle * (np.pi / 180))
m = np.matrix([[c, s], [-s, c]])
d = np.dot(m, [xshift, yshift])

new_xshift = float(d.T[0])
new_yshift = float(d.T[1])

warn("Display of support on circular/radial not implemented yet", UserWarning)
return None
x = self.x
data = UnionDict(
x=x,
y=self.y,
xshift=new_xshift,
yshift=new_yshift,
textangle=textangle,
showarrow=False,
text=f"{val:.2f}",
xanchor="center",
)
return data

def get_segment_to_child(self, child):
"""returns coordinates connecting a child to self and descendants"""
Expand Down Expand Up @@ -527,8 +569,8 @@ def __init__(
show_support = False
self._show_support = show_support
self._threshold = threshold
self._support_xshift = -14
self._support_yshift = 7
self._support_xshift = None
self._support_yshift = None
self._default_layout.autosize = True
self.layout = UnionDict(self._default_layout)

Expand Down

0 comments on commit e4d9427

Please sign in to comment.