From 4881c76df97f6d2f919ec33ab29a10806bb360d8 Mon Sep 17 00:00:00 2001 From: erxclau Date: Thu, 28 Jul 2022 15:12:43 -0500 Subject: [PATCH 1/8] Add alttext parameter to createBase --- templates/__common__/app/scripts/utils/d3-base.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/templates/__common__/app/scripts/utils/d3-base.js b/templates/__common__/app/scripts/utils/d3-base.js index e4405d28..81a1c57b 100644 --- a/templates/__common__/app/scripts/utils/d3-base.js +++ b/templates/__common__/app/scripts/utils/d3-base.js @@ -8,6 +8,7 @@ export default function createBase({ height, x, y, + alttext, xAxis = axisBottom(), yAxis = axisLeft(), xAxisGap = 5, @@ -29,6 +30,17 @@ export default function createBase({ .attr('width', containerWidth) .attr('height', containerHeight); + if (!alttext) { + console.warn('Alternative text was not provided'); + } else { + svg + .attr('role', 'img') + .attr('aria-describedby', 'description') + .append('desc') + .attr('id', 'descrption') + .text(alttext); + } + const g = svg .append('g') .attr('transform', `translate(${margin.left},${margin.top})`); From 5e845d9339acf908104ff161ccdd2f56dc2cd461 Mon Sep 17 00:00:00 2001 From: erxclau Date: Thu, 28 Jul 2022 16:05:41 -0500 Subject: [PATCH 2/8] Add accessibility filter for ai2html files --- templates/__common__/config/tasks/nunjucks.js | 19 +++++++++++++++++++ .../graphic/app/templates/graphic-static.html | 8 ++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/templates/__common__/config/tasks/nunjucks.js b/templates/__common__/config/tasks/nunjucks.js index 56e0a347..2c9562ba 100644 --- a/templates/__common__/config/tasks/nunjucks.js +++ b/templates/__common__/config/tasks/nunjucks.js @@ -149,6 +149,25 @@ env.addGlobal( env.addFilter('makeArray', input => (Array.isArray(input) ? input : [input])); +/* + Adds accessibility tags to ai2html output + */ +env.addFilter('addA11yAttributes', (html, alttext) => { + return html + .replace( + /
/, + `