mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-03 14:19:38 +02:00
feat: add accessibility title and description to pie chart
* Reuse the title as the title element * Add description to the parser and then render
This commit is contained in:
25
src/accessibility.js
Normal file
25
src/accessibility.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* This method will add a basic title and description element to a chart. The yy parser will need to
|
||||
* respond to getTitle and getAccDescription, where the title is the title element on the chart,
|
||||
* which is not displayed and the accDescription is the description element on the chart, which is
|
||||
* also not displayed.
|
||||
*
|
||||
* @param yy_parser
|
||||
* @param svg
|
||||
* @param id
|
||||
*/
|
||||
export default function addSVGAccessibilityFields(yy_parser, svg, id) {
|
||||
let title_string = yy_parser.getTitle();
|
||||
let description = yy_parser.getAccDescription();
|
||||
svg.attr('role', 'img').attr('aria-labelledby', 'chart-title-' + id + ' chart-desc-' + id);
|
||||
|
||||
svg
|
||||
.insert('desc', ':first-child')
|
||||
.attr('id', 'chart-desc-' + id)
|
||||
.text(description);
|
||||
|
||||
svg
|
||||
.insert('title', ':first-child')
|
||||
.attr('id', 'chart-desc-' + id)
|
||||
.text(title_string);
|
||||
}
|
Reference in New Issue
Block a user