Skip to content

Commit

Permalink
Fix indentation of unrooted and circular text functions
Browse files Browse the repository at this point in the history
  • Loading branch information
evogytis committed Jul 12, 2023
1 parent dbef32d commit 1264343
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
108 changes: 54 additions & 54 deletions baltic/baltic.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,64 +792,64 @@ def addText(self,ax,target=None,x_attr=None,y_attr=None,text=None,zorder=None,**
ax.text(x,y,text(k),zorder=z,**kwargs)
return ax

def addTextUnrooted(self,ax,target=None,rotation=None,x_attr=None,y_attr=None,text=None,zorder=None,**kwargs):
if target==None: target=lambda k: k.is_leaf()
if rotation==None: rotation=lambda k: 0.0
if x_attr==None: x_attr=lambda k: k.x
if y_attr==None: y_attr=lambda k: k.y
if text==None: text=lambda k: k.name
if zorder==None: zorder=4

for k in filter(target,self.Objects):
local_kwargs=dict(kwargs)

x,y=x_attr(k),y_attr(k)
z=zorder

assert 'tau' in k.traits, 'Branch does not have angle tau computed by drawUnrooted().'
rot=np.rad2deg(k.traits['tau'])%360

if 'horizontalalignment' not in local_kwargs: local_kwargs['horizontalalignment']='right' if 90<rot<270 else 'left'
if 'verticalalignment' not in local_kwargs: local_kwargs['verticalalignment']='center'

rot=rot+180 if 90<rot<270 else rot

ax.text(x,y,text(k),rotation=rot,rotation_mode='anchor',zorder=z,**local_kwargs)

return ax

def addTextCircular(self,ax,target=None,text=None,x_attr=None,y_attr=None,circStart=0.0,circFrac=1.0,inwardSpace=0.0,normaliseHeight=None,zorder=None,**kwargs):
if target==None: target=lambda k: k.is_leaf()
if x_attr==None: x_attr=lambda k:k.x
if y_attr==None: y_attr=lambda k:k.y
if text==None: text=lambda k: k.name
if zorder==None: zorder=4

circ_s=circStart*math.pi*2
circ=circFrac*math.pi*2

allXs=list(map(x_attr,self.Objects))
if normaliseHeight==None: normaliseHeight=lambda value: (value-min(allXs))/(max(allXs)-min(allXs))

for k in filter(target,self.Objects): ## iterate over branches
local_kwargs=dict(kwargs) ## copy global kwargs into a local version

x=normaliseHeight(x_attr(k)+inwardSpace) ## get branch x position
y=y_attr(k) ## get y position
def addTextUnrooted(self,ax,target=None,rotation=None,x_attr=None,y_attr=None,text=None,zorder=None,**kwargs):
if target==None: target=lambda k: k.is_leaf()
if rotation==None: rotation=lambda k: 0.0
if x_attr==None: x_attr=lambda k: k.x
if y_attr==None: y_attr=lambda k: k.y
if text==None: text=lambda k: k.name
if zorder==None: zorder=4

y=circ_s+circ*y/self.ySpan
X=math.sin(y)
Y=math.cos(y)
for k in filter(target,self.Objects):
local_kwargs=dict(kwargs)

x,y=x_attr(k),y_attr(k)
z=zorder

assert 'tau' in k.traits, 'Branch does not have angle tau computed by drawUnrooted().'
rot=np.rad2deg(k.traits['tau'])%360

if 'horizontalalignment' not in local_kwargs: local_kwargs['horizontalalignment']='right' if 90<rot<270 else 'left'
if 'verticalalignment' not in local_kwargs: local_kwargs['verticalalignment']='center'

rot=rot+180 if 90<rot<270 else rot

ax.text(x,y,text(k),rotation=rot,rotation_mode='anchor',zorder=z,**local_kwargs)

return ax

def addTextCircular(self,ax,target=None,text=None,x_attr=None,y_attr=None,circStart=0.0,circFrac=1.0,inwardSpace=0.0,normaliseHeight=None,zorder=None,**kwargs):
if target==None: target=lambda k: k.is_leaf()
if x_attr==None: x_attr=lambda k:k.x
if y_attr==None: y_attr=lambda k:k.y
if text==None: text=lambda k: k.name
if zorder==None: zorder=4

rot=np.rad2deg(y)%360
circ_s=circStart*math.pi*2
circ=circFrac*math.pi*2

if 'horizontalalignment' not in local_kwargs: local_kwargs['horizontalalignment']='right' if 180<rot<360 else 'left' ## rotate labels to aid readability
if 'verticalalignment' not in local_kwargs: local_kwargs['verticalalignment']='center'
rot=360-rot-90 if 180<rot<360 else 360-rot+90
allXs=list(map(x_attr,self.Objects))
if normaliseHeight==None: normaliseHeight=lambda value: (value-min(allXs))/(max(allXs)-min(allXs))

for k in filter(target,self.Objects): ## iterate over branches
local_kwargs=dict(kwargs) ## copy global kwargs into a local version

x=normaliseHeight(x_attr(k)+inwardSpace) ## get branch x position
y=y_attr(k) ## get y position

y=circ_s+circ*y/self.ySpan
X=math.sin(y)
Y=math.cos(y)

rot=np.rad2deg(y)%360

if 'horizontalalignment' not in local_kwargs: local_kwargs['horizontalalignment']='right' if 180<rot<360 else 'left' ## rotate labels to aid readability
if 'verticalalignment' not in local_kwargs: local_kwargs['verticalalignment']='center'
rot=360-rot-90 if 180<rot<360 else 360-rot+90

ax.text(X*x,Y*x,text(k),rotation=rot,rotation_mode='anchor',zorder=zorder,**local_kwargs)

ax.text(X*x,Y*x,text(k),rotation=rot,rotation_mode='anchor',zorder=zorder,**local_kwargs)

return ax
return ax

def plotPoints(self,ax,x_attr=None,y_attr=None,target=None,size=None,colour=None,
zorder=None,outline=None,outline_size=None,outline_colour=None,**kwargs):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

setup(
name="baltic",
version="0.2.0",
version="0.2.1",
packages=find_packages(),
url="https://github.com/evogytis/baltic",
download_url="https://github.com/evogytis/baltic/archive/v0.2.0.tar.gz",
download_url="https://github.com/evogytis/baltic/archive/v0.2.1.tar.gz",
keywords = ['phylogeny', 'visualization'],
license="gpl-3.0",
author="Gytis Dudas",
Expand Down

0 comments on commit 1264343

Please sign in to comment.