mermaid/src/accessibility.js

31 lines
1009 B
JavaScript
Raw Normal View History

/**
* 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,
2022-04-07 13:20:58 +00:00
* which is generally not displayed and the accDescription is the description element on the chart,
* which is never displayed.
*
* The following charts display their title as a visual and accessibility element:
* gantt
*
* @param yy_parser
* @param svg
* @param id
*/
export default function addSVGAccessibilityFields(yy_parser, svg, id) {
2022-04-07 13:20:58 +00:00
if (typeof svg.insert === 'undefined') {
return;
}
2022-04-07 13:20:58 +00:00
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')
2022-02-24 13:31:27 -05:00
.attr('id', 'chart-title-' + id)
.text(title_string);
}