File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -161,6 +161,7 @@ def __init__(self):
161161 self ._clippath = None
162162 self ._clipon = True
163163 self ._label = ''
164+ self ._aria = None
164165 self ._picker = None
165166 self ._rasterized = False
166167 self ._agg_filter = None
@@ -1069,6 +1070,33 @@ def update(self, props):
10691070 self .stale = True
10701071 return ret
10711072
1073+ def get_aria (self ):
1074+ """Return any ARIA properties assigned to the artist"""
1075+ return dict (self ._aria )
1076+
1077+ def set_aria (self , aria ):
1078+ """
1079+ Set ARIA properties to the artist.
1080+
1081+ A primary use of this method is to attach aria-label to the artist to provide alt text to figures.
1082+
1083+ Parameters
1084+ ----------
1085+ aria : dict
1086+ """
1087+ # TODO validation
1088+ if not isinstance (aria , dict ):
1089+ if aria is not None :
1090+ raise TypeError (
1091+ f'aria must be dict or None, not { type (aria )} ' )
1092+ self ._aria = aria
1093+
1094+ def update_aria (self , ** aria ):
1095+ """Update WAI-ARIA properties on the artist"""
1096+ # TODO validation
1097+ for k , v in aria .items ():
1098+ self ._aria [k ] = v
1099+
10721100 def get_label (self ):
10731101 """Return the label used for this artist in the legend."""
10741102 return self ._label
Original file line number Diff line number Diff line change @@ -374,3 +374,9 @@ class MyArtist4(MyArtist3):
374374 pass
375375
376376 assert MyArtist4 .set is MyArtist3 .set
377+
378+ def test_set_aria ():
379+ art = martist .Artist ()
380+ with pytest .raises (TypeError , match = '^aria must be dict' ):
381+ art .set_aria ([])
382+ art .set_aria (dict (label = "artist alt text" ))
You can’t perform that action at this time.
0 commit comments