@@ -174,7 +174,7 @@ def __init__(
174
174
self .tooltip_styles = None # VERSION ADDED 1.X
175
175
self .tooltip_class = None
176
176
self .tooltip_class_styles = None
177
- self .set_tooltip_class (name = ' pd-t' , properties = None )
177
+ self .set_tooltip_class (name = " pd-t" , properties = None )
178
178
179
179
# display_funcs maps (row, col) -> formatting function
180
180
@@ -835,25 +835,46 @@ def set_tooltips(self, ttips: DataFrame):
835
835
:return:
836
836
"""
837
837
if not (self .columns .equals (ttips .columns ) and self .index .equals (ttips .index )):
838
- raise AttributeError ('Tooltips DataFrame must have identical column and index labelling to underlying.' )
838
+ raise AttributeError (
839
+ "Tooltips DataFrame must have identical column and index labelling to underlying."
840
+ )
839
841
840
842
self .cell_ids = True # tooltips only work with individual cell_ids
841
843
self .tooltip_styles = []
842
844
for i , rn in enumerate (ttips .index ):
843
845
for j , cn in enumerate (ttips .columns ):
844
- if ttips .iloc [i , j ] in [np .nan , '' , None ]:
846
+ if ttips .iloc [i , j ] in [np .nan , "" , None ]:
845
847
continue
846
848
else :
847
849
# add pseudo-class and pseudo-elements to css to create tips
848
- self .tooltip_styles .extend ([
849
- {'selector' : '#T_' + self .uuid + 'row' + str (i ) + '_col' + str (j ) + f':hover .{ self .tooltip_class } ' ,
850
- 'props' : [('visibility' , 'visible' )]},
851
- {'selector' : '#T_' + self .uuid + 'row' + str (i ) + '_col' + str (j ) + f' .{ self .tooltip_class } ::after' ,
852
- 'props' : [('content' , f'"{ str (ttips .iloc [i , j ])} "' )]}])
850
+ self .tooltip_styles .extend (
851
+ [
852
+ {
853
+ "selector" : "#T_"
854
+ + self .uuid
855
+ + "row"
856
+ + str (i )
857
+ + "_col"
858
+ + str (j )
859
+ + f":hover .{ self .tooltip_class } " ,
860
+ "props" : [("visibility" , "visible" )],
861
+ },
862
+ {
863
+ "selector" : "#T_"
864
+ + self .uuid
865
+ + "row"
866
+ + str (i )
867
+ + "_col"
868
+ + str (j )
869
+ + f" .{ self .tooltip_class } ::after" ,
870
+ "props" : [("content" , f'"{ str (ttips .iloc [i , j ])} "' )],
871
+ },
872
+ ]
873
+ )
853
874
854
875
return self
855
876
856
- def set_tooltip_class (self , name = ' pd-t' , properties = None ):
877
+ def set_tooltip_class (self , name = " pd-t" , properties = None ):
857
878
"""
858
879
Method to set the name and properties of the class for creating tooltips on hover.
859
880
@@ -888,20 +909,18 @@ def set_tooltip_class(self, name='pd-t', properties=None):
888
909
... ('z-index', 1)])
889
910
"""
890
911
if properties is None :
891
- properties = [ # set default
892
- (' visibility' , ' hidden' ),
893
- (' position' , ' absolute' ),
894
- (' z-index' , 1 ),
895
- (' background-color' , ' black' ),
896
- (' color' , ' white' ),
897
- (' transform' , ' translate(-20px, -20px)' )
912
+ properties = [ # set default
913
+ (" visibility" , " hidden" ),
914
+ (" position" , " absolute" ),
915
+ (" z-index" , 1 ),
916
+ (" background-color" , " black" ),
917
+ (" color" , " white" ),
918
+ (" transform" , " translate(-20px, -20px)" ),
898
919
]
899
920
self .tooltip_class = name
900
921
901
922
self .tooltip_class_styles = [
902
- {'selector' : f'.{ self .tooltip_class } ' ,
903
- 'props' : properties
904
- }
923
+ {"selector" : f".{ self .tooltip_class } " , "props" : properties }
905
924
]
906
925
return self
907
926
@@ -918,12 +937,15 @@ def _render_tooltips(self, d):
918
937
The dictionary prior to rendering
919
938
"""
920
939
if self .tooltip_styles :
921
- for row in d [' body' ]:
940
+ for row in d [" body" ]:
922
941
for item in row :
923
- if item ['type' ] == 'td' :
924
- item ['display_value' ] = str (item ['display_value' ]) + f'<span class="{ self .tooltip_class } "></span>'
925
- d ['table_styles' ].extend (self .tooltip_class_styles )
926
- d ['table_styles' ].extend (self .tooltip_styles )
942
+ if item ["type" ] == "td" :
943
+ item ["display_value" ] = (
944
+ str (item ["display_value" ])
945
+ + f'<span class="{ self .tooltip_class } "></span>'
946
+ )
947
+ d ["table_styles" ].extend (self .tooltip_class_styles )
948
+ d ["table_styles" ].extend (self .tooltip_styles )
927
949
928
950
def set_precision (self , precision : int ) -> "Styler" :
929
951
"""
0 commit comments