@@ -792,64 +792,64 @@ def addText(self,ax,target=None,x_attr=None,y_attr=None,text=None,zorder=None,**
792
792
ax .text (x ,y ,text (k ),zorder = z ,** kwargs )
793
793
return ax
794
794
795
- def addTextUnrooted (self ,ax ,target = None ,rotation = None ,x_attr = None ,y_attr = None ,text = None ,zorder = None ,** kwargs ):
796
- if target == None : target = lambda k : k .is_leaf ()
797
- if rotation == None : rotation = lambda k : 0.0
798
- if x_attr == None : x_attr = lambda k : k .x
799
- if y_attr == None : y_attr = lambda k : k .y
800
- if text == None : text = lambda k : k .name
801
- if zorder == None : zorder = 4
802
-
803
- for k in filter (target ,self .Objects ):
804
- local_kwargs = dict (kwargs )
805
-
806
- x ,y = x_attr (k ),y_attr (k )
807
- z = zorder
808
-
809
- assert 'tau' in k .traits , 'Branch does not have angle tau computed by drawUnrooted().'
810
- rot = np .rad2deg (k .traits ['tau' ])% 360
811
-
812
- if 'horizontalalignment' not in local_kwargs : local_kwargs ['horizontalalignment' ]= 'right' if 90 < rot < 270 else 'left'
813
- if 'verticalalignment' not in local_kwargs : local_kwargs ['verticalalignment' ]= 'center'
814
-
815
- rot = rot + 180 if 90 < rot < 270 else rot
816
-
817
- ax .text (x ,y ,text (k ),rotation = rot ,rotation_mode = 'anchor' ,zorder = z ,** local_kwargs )
818
-
819
- return ax
820
-
821
- 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 ):
822
- if target == None : target = lambda k : k .is_leaf ()
823
- if x_attr == None : x_attr = lambda k :k .x
824
- if y_attr == None : y_attr = lambda k :k .y
825
- if text == None : text = lambda k : k .name
826
- if zorder == None : zorder = 4
827
-
828
- circ_s = circStart * math .pi * 2
829
- circ = circFrac * math .pi * 2
830
-
831
- allXs = list (map (x_attr ,self .Objects ))
832
- if normaliseHeight == None : normaliseHeight = lambda value : (value - min (allXs ))/ (max (allXs )- min (allXs ))
833
-
834
- for k in filter (target ,self .Objects ): ## iterate over branches
835
- local_kwargs = dict (kwargs ) ## copy global kwargs into a local version
836
-
837
- x = normaliseHeight (x_attr (k )+ inwardSpace ) ## get branch x position
838
- y = y_attr (k ) ## get y position
795
+ def addTextUnrooted (self ,ax ,target = None ,rotation = None ,x_attr = None ,y_attr = None ,text = None ,zorder = None ,** kwargs ):
796
+ if target == None : target = lambda k : k .is_leaf ()
797
+ if rotation == None : rotation = lambda k : 0.0
798
+ if x_attr == None : x_attr = lambda k : k .x
799
+ if y_attr == None : y_attr = lambda k : k .y
800
+ if text == None : text = lambda k : k .name
801
+ if zorder == None : zorder = 4
839
802
840
- y = circ_s + circ * y / self .ySpan
841
- X = math .sin (y )
842
- Y = math .cos (y )
803
+ for k in filter (target ,self .Objects ):
804
+ local_kwargs = dict (kwargs )
805
+
806
+ x ,y = x_attr (k ),y_attr (k )
807
+ z = zorder
808
+
809
+ assert 'tau' in k .traits , 'Branch does not have angle tau computed by drawUnrooted().'
810
+ rot = np .rad2deg (k .traits ['tau' ])% 360
811
+
812
+ if 'horizontalalignment' not in local_kwargs : local_kwargs ['horizontalalignment' ]= 'right' if 90 < rot < 270 else 'left'
813
+ if 'verticalalignment' not in local_kwargs : local_kwargs ['verticalalignment' ]= 'center'
814
+
815
+ rot = rot + 180 if 90 < rot < 270 else rot
816
+
817
+ ax .text (x ,y ,text (k ),rotation = rot ,rotation_mode = 'anchor' ,zorder = z ,** local_kwargs )
818
+
819
+ return ax
820
+
821
+ 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 ):
822
+ if target == None : target = lambda k : k .is_leaf ()
823
+ if x_attr == None : x_attr = lambda k :k .x
824
+ if y_attr == None : y_attr = lambda k :k .y
825
+ if text == None : text = lambda k : k .name
826
+ if zorder == None : zorder = 4
843
827
844
- rot = np .rad2deg (y )% 360
828
+ circ_s = circStart * math .pi * 2
829
+ circ = circFrac * math .pi * 2
845
830
846
- if 'horizontalalignment' not in local_kwargs : local_kwargs ['horizontalalignment' ]= 'right' if 180 < rot < 360 else 'left' ## rotate labels to aid readability
847
- if 'verticalalignment' not in local_kwargs : local_kwargs ['verticalalignment' ]= 'center'
848
- rot = 360 - rot - 90 if 180 < rot < 360 else 360 - rot + 90
831
+ allXs = list (map (x_attr ,self .Objects ))
832
+ if normaliseHeight == None : normaliseHeight = lambda value : (value - min (allXs ))/ (max (allXs )- min (allXs ))
833
+
834
+ for k in filter (target ,self .Objects ): ## iterate over branches
835
+ local_kwargs = dict (kwargs ) ## copy global kwargs into a local version
836
+
837
+ x = normaliseHeight (x_attr (k )+ inwardSpace ) ## get branch x position
838
+ y = y_attr (k ) ## get y position
839
+
840
+ y = circ_s + circ * y / self .ySpan
841
+ X = math .sin (y )
842
+ Y = math .cos (y )
843
+
844
+ rot = np .rad2deg (y )% 360
845
+
846
+ if 'horizontalalignment' not in local_kwargs : local_kwargs ['horizontalalignment' ]= 'right' if 180 < rot < 360 else 'left' ## rotate labels to aid readability
847
+ if 'verticalalignment' not in local_kwargs : local_kwargs ['verticalalignment' ]= 'center'
848
+ rot = 360 - rot - 90 if 180 < rot < 360 else 360 - rot + 90
849
+
850
+ ax .text (X * x ,Y * x ,text (k ),rotation = rot ,rotation_mode = 'anchor' ,zorder = zorder ,** local_kwargs )
849
851
850
- ax .text (X * x ,Y * x ,text (k ),rotation = rot ,rotation_mode = 'anchor' ,zorder = zorder ,** local_kwargs )
851
-
852
- return ax
852
+ return ax
853
853
854
854
def plotPoints (self ,ax ,x_attr = None ,y_attr = None ,target = None ,size = None ,colour = None ,
855
855
zorder = None ,outline = None ,outline_size = None ,outline_colour = None ,** kwargs ):
0 commit comments