2
2
import { Component } from "../component" ;
3
3
import { DOMUtils } from "../../services" ;
4
4
import { Tools } from "../../tools" ;
5
- import { CalloutDirections , TooltipTypes } from "../../interfaces/enums " ;
5
+ import { CalloutDirections , Roles , TooltipTypes } from "../../interfaces" ;
6
6
7
7
// D3 Imports
8
8
import { select } from "d3-selection" ;
@@ -81,7 +81,9 @@ export class Pie extends Component {
81
81
. sort ( ( a : any , b : any ) => a . index - b . index ) ;
82
82
83
83
// Update data on all slices
84
- const paths = DOMUtils . appendOrSelect ( svg , "g.slices" ) . selectAll ( "path.slice" )
84
+ const slicesGroup = DOMUtils . appendOrSelect ( svg , "g.slices" )
85
+ . attr ( "role" , Roles . GROUP ) ;
86
+ const paths = slicesGroup . selectAll ( "path.slice" )
85
87
. data ( pieLayoutData , d => d . data . label ) ;
86
88
87
89
// Remove slices that need to be exited
@@ -101,13 +103,18 @@ export class Pie extends Component {
101
103
. attr ( "d" , this . arc )
102
104
. transition ( this . services . transitions . getTransition ( "pie-slice-enter-update" , animate ) )
103
105
. attr ( "opacity" , 1 )
106
+ // a11y
107
+ . attr ( "role" , Roles . GRAPHICS_SYMBOL )
108
+ . attr ( "aria-roledescription" , "slice" )
109
+ . attr ( "aria-label" , d => `${ d . value } , ${ Tools . convertValueToPercentage ( d . data . value , dataList ) + "%" } ` )
110
+ // Tween
104
111
. attrTween ( "d" , function ( a ) {
105
112
return arcTween . bind ( this ) ( a , self . arc ) ;
106
113
} ) ;
107
114
108
115
// Draw the slice labels
109
- const labels = DOMUtils . appendOrSelect ( svg , "g.labels" )
110
- . selectAll ( "text.pie-label" )
116
+ const labelsGroup = DOMUtils . appendOrSelect ( svg , "g.labels" ) . attr ( "role" , Roles . GROUP ) ;
117
+ const labels = labelsGroup . selectAll ( "text.pie-label" )
111
118
. data ( pieLayoutData , ( d : any ) => d . data . label ) ;
112
119
113
120
// Remove labels that are existing
@@ -193,7 +200,8 @@ export class Pie extends Component {
193
200
}
194
201
195
202
renderCallouts ( calloutData : any [ ] ) {
196
- const svg = DOMUtils . appendOrSelect ( this . getContainerSVG ( ) , "g.callouts" ) ;
203
+ const svg = DOMUtils . appendOrSelect ( this . getContainerSVG ( ) , "g.callouts" )
204
+ . attr ( "role" , Roles . GROUP ) ;
197
205
const options = this . model . getOptions ( ) ;
198
206
199
207
// Update data on callouts
@@ -204,7 +212,10 @@ export class Pie extends Component {
204
212
205
213
const enteringCallouts = callouts . enter ( )
206
214
. append ( "g" )
207
- . classed ( "callout" , true ) ;
215
+ . classed ( "callout" , true )
216
+ // a11y
217
+ . attr ( "role" , `${ Roles . GRAPHICS_SYMBOL } ${ Roles . GROUP } ` )
218
+ . attr ( "aria-roledescription" , "label callout" ) ;
208
219
209
220
// Update data values for each callout
210
221
// For the horizontal and vertical lines to use
0 commit comments