File tree 2 files changed +34
-0
lines changed 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,7 @@ def __init__(self):
161
161
self ._clippath = None
162
162
self ._clipon = True
163
163
self ._label = ''
164
+ self ._aria = None
164
165
self ._picker = None
165
166
self ._rasterized = False
166
167
self ._agg_filter = None
@@ -1069,6 +1070,33 @@ def update(self, props):
1069
1070
self .stale = True
1070
1071
return ret
1071
1072
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
+
1072
1100
def get_label (self ):
1073
1101
"""Return the label used for this artist in the legend."""
1074
1102
return self ._label
Original file line number Diff line number Diff line change @@ -374,3 +374,9 @@ class MyArtist4(MyArtist3):
374
374
pass
375
375
376
376
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