@@ -822,24 +822,33 @@ def _perform_select_traces(self, filter_by_subplot, grid_subplot_refs, selector)
822
822
def _selector_matches (obj , selector ):
823
823
if selector is None :
824
824
return True
825
+ # If selector is a dict, compare the fields
826
+ if type (selector ) == type (dict ()):
827
+ # This returns True if selector is an empty dict
828
+ for k in selector :
829
+ if k not in obj :
830
+ return False
825
831
826
- for k in selector :
827
- if k not in obj :
828
- return False
829
-
830
- obj_val = obj [k ]
831
- selector_val = selector [k ]
832
-
833
- if isinstance (obj_val , BasePlotlyType ):
834
- obj_val = obj_val .to_plotly_json ()
832
+ obj_val = obj [k ]
833
+ selector_val = selector [k ]
835
834
836
- if isinstance (selector_val , BasePlotlyType ):
837
- selector_val = selector_val .to_plotly_json ()
835
+ if isinstance (obj_val , BasePlotlyType ):
836
+ obj_val = obj_val .to_plotly_json ()
838
837
839
- if obj_val != selector_val :
840
- return False
838
+ if isinstance ( selector_val , BasePlotlyType ) :
839
+ selector_val = selector_val . to_plotly_json ()
841
840
842
- return True
841
+ if obj_val != selector_val :
842
+ return False
843
+ return True
844
+ # If selector is a function, call it with the obj as the argument
845
+ elif type (selector ) == type (lambda x : True ):
846
+ return selector (obj )
847
+ else :
848
+ raise TypeError (
849
+ "selector must be dict or a function "
850
+ "accepting a trace returning a boolean."
851
+ )
843
852
844
853
def for_each_trace (self , fn , selector = None , row = None , col = None , secondary_y = None ):
845
854
"""
0 commit comments