screen-reader.src.js 26.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
/**
 * Accessibility module - Screen Reader support
 *
 * (c) 2010-2017 Highsoft AS
 * Author: Oystein Moseng
 *
 * License: www.highcharts.com/license
 */

'use strict';
import H from '../parts/Globals.js';
import '../parts/Utilities.js';
import '../parts/Chart.js';
import '../parts/Series.js';
import '../parts/Point.js';

var win = H.win,
    doc = win.document,
    each = H.each,
    map = H.map,
    erase = H.erase,
    addEvent = H.addEvent,
    merge = H.merge,
    // CSS style to hide element from visual users while still exposing it to
    // screen readers
    hiddenStyle = {
        position: 'absolute',
        left: '-9999px',
        top: 'auto',
        width: '1px',
        height: '1px',
        overflow: 'hidden'
    };

// If a point has one of the special keys defined, we expose all keys to the
// screen reader.
H.Series.prototype.commonKeys = ['name', 'id', 'category', 'x', 'value', 'y'];
H.Series.prototype.specialKeys = [
    'z', 'open', 'high', 'q3', 'median', 'q1', 'low', 'close'
];
if (H.seriesTypes.pie) {
    // A pie is always simple. Don't quote me on that.
    H.seriesTypes.pie.prototype.specialKeys = [];
}


/**
 * HTML encode some characters vulnerable for XSS.
 * @param  {string} html The input string
 * @return {string} The excaped string
 */
function htmlencode(html) {
    return html
        .replace(/&/g, '&')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;')
        .replace(/'/g, '&#x27;')
        .replace(/\//g, '&#x2F;');
}


/**
 * Strip HTML tags away from a string. Used for aria-label attributes, painting
 * on a canvas will fail if the text contains tags.
 * @param  {String} s The input string
 * @return {String}   The filtered string
 */
function stripTags(s) {
    return typeof s === 'string' ? s.replace(/<\/?[^>]+(>|$)/g, '') : s;
}


/**
 * Accessibility options
 */
H.setOptions({

    /**
     * Options for configuring accessibility for the chart. Requires the
     * [accessibility module](//code.highcharts.com/modules/accessibility.
     * js) to be loaded. For a description of the module and information
     * on its features, see [Highcharts Accessibility](http://www.highcharts.
     * com/docs/chart-concepts/accessibility).
     *
     * @since 5.0.0
     * @type {Object}
     * @optionparent accessibility
     */
    accessibility: {

        /**
         * Whether or not to add series descriptions to charts with a single
         * series.
         *
         * @type {Boolean}
         * @default false
         * @since 5.0.0
         * @apioption accessibility.describeSingleSeries
         */

        /**
         * Function to run upon clicking the "View as Data Table" link in the
         * screen reader region.
         *
         * By default Highcharts will insert and set focus to a data table
         * representation of the chart.
         *
         * @type {Function}
         * @since 5.0.0
         * @apioption accessibility.onTableAnchorClick
         */

        /**
         * Date format to use for points on datetime axes when describing them
         * to screen reader users.
         *
         * Defaults to the same format as in tooltip.
         *
         * For an overview of the replacement codes, see
         * [dateFormat](/class-reference/Highcharts#dateFormat).
         *
         * @type {String}
         * @see [pointDateFormatter](#accessibility.pointDateFormatter)
         * @since 5.0.0
         * @apioption accessibility.pointDateFormat
         */

        /**
         * Formatter function to determine the date/time format used with
         * points on datetime axes when describing them to screen reader users.
         * Receives one argument, `point`, referring to the point to describe.
         * Should return a date format string compatible with
         * [dateFormat](/class-reference/Highcharts#dateFormat).
         *
         * @type {Function}
         * @see [pointDateFormat](#accessibility.pointDateFormat)
         * @since 5.0.0
         * @apioption accessibility.pointDateFormatter
         */

        /**
         * Formatter function to use instead of the default for point
         * descriptions.
         * Receives one argument, `point`, referring to the point to describe.
         * Should return a String with the description of the point for a screen
         * reader user.
         *
         * @type {Function}
         * @see [point.description](#series.line.data.description)
         * @since 5.0.0
         * @apioption accessibility.pointDescriptionFormatter
         */

        /**
         * Formatter function to use instead of the default for series
         * descriptions. Receives one argument, `series`, referring to the
         * series to describe. Should return a String with the description of
         * the series for a screen reader user.
         *
         * @type {Function}
         * @see [series.description](#plotOptions.series.description)
         * @since 5.0.0
         * @apioption accessibility.seriesDescriptionFormatter
         */

        /**
         * Enable accessibility features for the chart.
         *
         * @type {Boolean}
         * @default true
         * @since 5.0.0
         */
        enabled: true,

        /**
         * When a series contains more points than this, we no longer expose
         * information about individual points to screen readers.
         *
         * Set to `false` to disable.
         *
         * @type {Number|Boolean}
         * @since 5.0.0
         */
        pointDescriptionThreshold: false, // set to false to disable

        /**
         * A formatter function to create the HTML contents of the hidden screen
         * reader information region. Receives one argument, `chart`, referring
         * to the chart object. Should return a String with the HTML content
         * of the region.
         *
         * The link to view the chart as a data table will be added
         * automatically after the custom HTML content.
         *
         * @type {Function}
         * @default undefined
         * @since 5.0.0
         */
        screenReaderSectionFormatter: function (chart) {
            var options = chart.options,
                chartTypes = chart.types || [],
                formatContext = {
                    chart: chart,
                    numSeries: chart.series && chart.series.length
                },
                // Build axis info - but not for pies and maps. Consider not
                // adding for certain other types as well (funnel, pyramid?)
                axesDesc = (
                    chartTypes.length === 1 && chartTypes[0] === 'pie' ||
                    chartTypes[0] === 'map'
                ) && {} || chart.getAxesDescription();

            return '<div>' + chart.langFormat(
                        'accessibility.navigationHint', formatContext
                    ) + '</div><h3>' +
                    (
                        options.title.text ?
                            htmlencode(options.title.text) :
                            chart.langFormat(
                                'accessibility.defaultChartTitle', formatContext
                            )
                    ) +
                    (
                        options.subtitle && options.subtitle.text ?
                            '. ' + htmlencode(options.subtitle.text) :
                            ''
                    ) +
                    '</h3><h4>' + chart.langFormat(
                        'accessibility.longDescriptionHeading', formatContext
                    ) + '</h4><div>' +
                    (
                        options.chart.description || chart.langFormat(
                            'accessibility.noDescription', formatContext
                        )
                    ) +
                    '</div><h4>' + chart.langFormat(
                        'accessibility.structureHeading', formatContext
                    ) + '</h4><div>' +
                    (
                        options.chart.typeDescription ||
                        chart.getTypeDescription()
                    ) + '</div>' +
                    (axesDesc.xAxis ? (
                        '<div>' + axesDesc.xAxis + '</div>'
                    ) : '') +
                    (axesDesc.yAxis ? (
                        '<div>' + axesDesc.yAxis + '</div>'
                    ) : '');
        }
    }
});

/**
 * A text description of the chart.
 *
 * If the Accessibility module is loaded, this is included by default
 * as a long description of the chart and its contents in the hidden
 * screen reader information region.
 *
 * @type {String}
 * @see [typeDescription](#chart.typeDescription)
 * @default undefined
 * @since 5.0.0
 * @apioption chart.description
 */

 /**
 * A text description of the chart type.
 *
 * If the Accessibility module is loaded, this will be included in the
 * description of the chart in the screen reader information region.
 *
 *
 * Highcharts will by default attempt to guess the chart type, but for
 * more complex charts it is recommended to specify this property for
 * clarity.
 *
 * @type {String}
 * @default undefined
 * @since 5.0.0
 * @apioption chart.typeDescription
 */


// Utility function. Reverses child nodes of a DOM element
function reverseChildNodes(node) {
    var i = node.childNodes.length;
    while (i--) {
        node.appendChild(node.childNodes[i]);
    }
}


// Whenever drawing series, put info on DOM elements
H.addEvent(H.Series, 'afterRender', function () {
    if (this.chart.options.accessibility.enabled) {
        this.setA11yDescription();
    }
});


// Put accessible info on series and points of a series
H.Series.prototype.setA11yDescription = function () {
    var a11yOptions = this.chart.options.accessibility,
        firstPointEl = (
            this.points &&
            this.points.length &&
            this.points[0].graphic &&
            this.points[0].graphic.element
        ),
        seriesEl = (
            firstPointEl &&
            firstPointEl.parentNode || this.graph &&
            this.graph.element || this.group &&
            this.group.element
        ); // Could be tracker series depending on series type

    if (seriesEl) {
        // For some series types the order of elements do not match the order of
        // points in series. In that case we have to reverse them in order for
        // AT to read them out in an understandable order
        if (seriesEl.lastChild === firstPointEl) {
            reverseChildNodes(seriesEl);
        }
        // Make individual point elements accessible if possible. Note: If
        // markers are disabled there might not be any elements there to make
        // accessible.
        if (
            this.points && (
                this.points.length < a11yOptions.pointDescriptionThreshold ||
                a11yOptions.pointDescriptionThreshold === false
            )
        ) {
            each(this.points, function (point) {
                if (point.graphic) {
                    point.graphic.element.setAttribute('role', 'img');
                    point.graphic.element.setAttribute('tabindex', '-1');
                    point.graphic.element.setAttribute('aria-label', stripTags(
                        point.series.options.pointDescriptionFormatter &&
                        point.series.options.pointDescriptionFormatter(point) ||
                        a11yOptions.pointDescriptionFormatter &&
                        a11yOptions.pointDescriptionFormatter(point) ||
                        point.buildPointInfoString()
                    ));
                }
            });
        }
        // Make series element accessible
        if (this.chart.series.length > 1 || a11yOptions.describeSingleSeries) {
            seriesEl.setAttribute(
                'role',
                this.options.exposeElementToA11y ? 'img' : 'region'
            );
            seriesEl.setAttribute('tabindex', '-1');
            seriesEl.setAttribute(
                'aria-label',
                stripTags(
                    a11yOptions.seriesDescriptionFormatter &&
                    a11yOptions.seriesDescriptionFormatter(this) ||
                    this.buildSeriesInfoString()
                )
            );
        }
    }
};


// Return string with information about series
H.Series.prototype.buildSeriesInfoString = function () {
    var chart = this.chart,
        desc = this.description || this.options.description,
        description = desc && chart.langFormat(
            'accessibility.series.description', {
                description: desc,
                series: this
            }
        ),
        xAxisInfo = chart.langFormat(
            'accessibility.series.xAxisDescription',
            {
                name: this.xAxis && this.xAxis.getDescription(),
                series: this
            }
        ),
        yAxisInfo = chart.langFormat(
            'accessibility.series.yAxisDescription',
            {
                name: this.yAxis && this.yAxis.getDescription(),
                series: this
            }
        ),
        summaryContext = {
            name: this.name || '',
            ix: this.index + 1,
            numSeries: chart.series.length,
            numPoints: this.points.length,
            series: this
        },
        combination = chart.types.length === 1 ? '' : 'Combination',
        summary = chart.langFormat(
            'accessibility.series.summary.' + this.type + combination,
            summaryContext
        ) || chart.langFormat(
            'accessibility.series.summary.default' + combination,
            summaryContext
        );

    return summary + (description ? ' ' + description : '') + (
            chart.yAxis.length > 1 && this.yAxis ?
                ' ' + yAxisInfo : ''
        ) + (
            chart.xAxis.length > 1 && this.xAxis ?
                ' ' + xAxisInfo : ''
        );
};


// Return string with information about point
H.Point.prototype.buildPointInfoString = function () {
    var point = this,
        series = point.series,
        a11yOptions = series.chart.options.accessibility,
        infoString = '',
        dateTimePoint = series.xAxis && series.xAxis.isDatetimeAxis,
        timeDesc =
            dateTimePoint &&
            series.chart.time.dateFormat(
                a11yOptions.pointDateFormatter &&
                a11yOptions.pointDateFormatter(point) ||
                a11yOptions.pointDateFormat ||
                H.Tooltip.prototype.getXDateFormat.call(
                    {
                        getDateFormat: H.Tooltip.prototype.getDateFormat,
                        chart: series.chart
                    },
                    point,
                    series.chart.options.tooltip,
                    series.xAxis
                ),
                point.x
            ),
        hasSpecialKey = H.find(series.specialKeys, function (key) {
            return point[key] !== undefined;
        });

    // If the point has one of the less common properties defined, display all
    // that are defined
    if (hasSpecialKey) {
        if (dateTimePoint) {
            infoString = timeDesc;
        }
        each(series.commonKeys.concat(series.specialKeys), function (key) {
            if (point[key] !== undefined && !(dateTimePoint && key === 'x')) {
                infoString += (infoString ? '. ' : '') +
                    key + ', ' +
                    point[key];
            }
        });
    } else {
        // Pick and choose properties for a succint label
        infoString =
            (
                this.name ||
                timeDesc ||
                this.category ||
                this.id ||
                'x, ' + this.x
            ) + ', ' +
            (this.value !== undefined ? this.value : this.y);
    }

    return (this.index + 1) + '. ' + infoString + '.' +
        (this.description ? ' ' + this.description : '');
};


// Get descriptive label for axis
H.Axis.prototype.getDescription = function () {
    return (
        this.userOptions && this.userOptions.description ||
        this.axisTitle && this.axisTitle.textStr ||
        this.options.id ||
        this.categories && 'categories' ||
        this.isDatetimeAxis && 'Time' ||
        'values'
    );
};


// Whenever adding or removing series, keep track of types present in chart
addEvent(H.Series, 'afterInit', function () {
    var chart = this.chart;
    if (chart.options.accessibility.enabled) {
        chart.types = chart.types || [];

        // Add type to list if does not exist
        if (chart.types.indexOf(this.type) < 0) {
            chart.types.push(this.type);
        }
    }
});
addEvent(H.Series, 'remove', function () {
    var chart = this.chart,
        removedSeries = this,
        hasType = false;

    // Check if any of the other series have the same type as this one.
    // Otherwise remove it from the list.
    each(chart.series, function (s) {
        if (
            s !== removedSeries &&
            chart.types.indexOf(removedSeries.type) < 0
        ) {
            hasType = true;
        }
    });
    if (!hasType) {
        erase(chart.types, removedSeries.type);
    }
});


// Return simplified description of chart type. Some types will not be familiar
// to most screen reader users, but in those cases we try to add a description
// of the type.
H.Chart.prototype.getTypeDescription = function () {
    var firstType = this.types && this.types[0],
        firstSeries = this.series && this.series[0] || {},
        mapTitle = firstSeries.mapTitle,
        typeDesc = this.langFormat(
            'accessibility.seriesTypeDescriptions.' + firstType,
            { chart: this }
        ),
        formatContext = {
            numSeries: this.series.length,
            numPoints: firstSeries.points && firstSeries.points.length,
            chart: this,
            mapTitle: mapTitle
        },
        multi = this.series && this.series.length === 1 ? 'Single' : 'Multiple';

    if (!firstType) {
        return this.langFormat(
            'accessibility.chartTypes.emptyChart', formatContext
        );
    } else if (firstType === 'map') {
        return mapTitle ?
            this.langFormat(
                'accessibility.chartTypes.mapTypeDescription',
                formatContext
            ) :
            this.langFormat(
                'accessibility.chartTypes.unknownMap',
                formatContext
            );
    } else if (this.types.length > 1) {
        return this.langFormat(
            'accessibility.chartTypes.combinationChart', formatContext
        );
    }

    return (
        this.langFormat(
            'accessibility.chartTypes.' + firstType + multi,
            formatContext
        ) ||
        this.langFormat(
            'accessibility.chartTypes.default' + multi,
            formatContext
        )
    ) +
    (typeDesc ? ' ' + typeDesc : '');
};


// Return object with text description of each of the chart's axes
H.Chart.prototype.getAxesDescription = function () {
    var numXAxes = this.xAxis.length,
        numYAxes = this.yAxis.length,
        desc = {};

    if (numXAxes) {
        desc.xAxis = this.langFormat(
            'accessibility.axis.xAxisDescription' + (
                numXAxes > 1 ? 'Plural' : 'Singular'
            ),
            {
                chart: this,
                names: map(this.xAxis, function (axis) {
                    return axis.getDescription();
                }),
                numAxes: numXAxes
            }
        );
    }

    if (numYAxes) {
        desc.yAxis = this.langFormat(
            'accessibility.axis.yAxisDescription' + (
                numYAxes > 1 ? 'Plural' : 'Singular'
            ),
            {
                chart: this,
                names: map(this.yAxis, function (axis) {
                    return axis.getDescription();
                }),
                numAxes: numYAxes
            }
        );
    }

    return desc;
};


// Set a11y attribs on exporting menu
H.Chart.prototype.addAccessibleContextMenuAttribs = function () {
    var exportList = this.exportDivElements;
    if (exportList) {
        // Set tabindex on the menu items to allow focusing by script
        // Set role to give screen readers a chance to pick up the contents
        each(exportList, function (item) {
            if (item.tagName === 'DIV' &&
                !(item.children && item.children.length)) {
                item.setAttribute('role', 'menuitem');
                item.setAttribute('tabindex', -1);
            }
        });
        // Set accessibility properties on parent div
        exportList[0].parentNode.setAttribute('role', 'menu');
        exportList[0].parentNode.setAttribute('aria-label',
            this.langFormat(
                'accessibility.exporting.chartMenuLabel', { chart: this }
            )
        );
    }
};


// Add screen reader region to chart.
// tableId is the HTML id of the table to focus when clicking the table anchor
// in the screen reader region.
H.Chart.prototype.addScreenReaderRegion = function (id, tableId) {
    var chart = this,
        hiddenSection = chart.screenReaderRegion = doc.createElement('div'),
        tableShortcut = doc.createElement('h4'),
        tableShortcutAnchor = doc.createElement('a'),
        chartHeading = doc.createElement('h4');

    hiddenSection.setAttribute('id', id);
    hiddenSection.setAttribute('role', 'region');
    hiddenSection.setAttribute(
        'aria-label',
        chart.langFormat(
            'accessibility.screenReaderRegionLabel', { chart: this }
        )
    );

    hiddenSection.innerHTML = chart.options.accessibility
        .screenReaderSectionFormatter(chart);

    // Add shortcut to data table if export-data is loaded
    if (chart.getCSV) {
        tableShortcutAnchor.innerHTML = chart.langFormat(
            'accessibility.viewAsDataTable', { chart: chart }
        );
        tableShortcutAnchor.href = '#' + tableId;
        // Make this unreachable by user tabbing
        tableShortcutAnchor.setAttribute('tabindex', '-1');
        tableShortcutAnchor.onclick =
            chart.options.accessibility.onTableAnchorClick || function () {
                chart.viewData();
                doc.getElementById(tableId).focus();
            };
        tableShortcut.appendChild(tableShortcutAnchor);
        hiddenSection.appendChild(tableShortcut);
    }

    // Note: JAWS seems to refuse to read aria-label on the container, so add an
    // h4 element as title for the chart.
    chartHeading.innerHTML = chart.langFormat(
        'accessibility.chartHeading', { chart: chart }
    );
    chart.renderTo.insertBefore(chartHeading, chart.renderTo.firstChild);
    chart.renderTo.insertBefore(hiddenSection, chart.renderTo.firstChild);

    // Hide the section and the chart heading
    merge(true, chartHeading.style, hiddenStyle);
    merge(true, hiddenSection.style, hiddenStyle);
};


// Make chart container accessible, and wrap table functionality
H.Chart.prototype.callbacks.push(function (chart) {
    var options = chart.options,
        a11yOptions = options.accessibility;

    if (!a11yOptions.enabled) {
        return;
    }

    var titleElement,
        descElement = chart.container.getElementsByTagName('desc')[0],
        textElements = chart.container.getElementsByTagName('text'),
        titleId = 'highcharts-title-' + chart.index,
        tableId = 'highcharts-data-table-' + chart.index,
        hiddenSectionId = 'highcharts-information-region-' + chart.index,
        chartTitle = options.title.text || chart.langFormat(
            'accessibility.defaultChartTitle', { chart: chart }
        ),
        svgContainerTitle = stripTags(chart.langFormat(
            'accessibility.svgContainerTitle', {
                chartTitle: chartTitle
            }
        ));

    // Add SVG title tag if it is set
    if (svgContainerTitle.length) {
        titleElement = doc.createElementNS(
                'http://www.w3.org/2000/svg',
                'title'
            );
        titleElement.textContent = svgContainerTitle;
        titleElement.id = titleId;
        descElement.parentNode.insertBefore(titleElement, descElement);
    }

    chart.renderTo.setAttribute('role', 'region');
    chart.renderTo.setAttribute(
        'aria-label',
        chart.langFormat(
            'accessibility.chartContainerLabel',
            {
                title: stripTags(chartTitle),
                chart: chart
            }
        )
    );

    // Set screen reader properties on export menu
    if (
        chart.exportSVGElements &&
        chart.exportSVGElements[0] &&
        chart.exportSVGElements[0].element
    ) {
        // Set event handler on button
        var button = chart.exportSVGElements[0].element,
            oldExportCallback = button.onclick;
        button.onclick = function () {
            oldExportCallback.apply(
                this,
                Array.prototype.slice.call(arguments)
            );
            chart.addAccessibleContextMenuAttribs();
            chart.highlightExportItem(0);
        };

        // Set props on button
        button.setAttribute('role', 'button');
        button.setAttribute(
            'aria-label',
            chart.langFormat(
                'accessibility.exporting.menuButtonLabel', { chart: chart }
            )
        );

        // Set props on group
        chart.exportingGroup.element.setAttribute('role', 'region');
        chart.exportingGroup.element.setAttribute('aria-label',
            chart.langFormat(
                'accessibility.exporting.exportRegionLabel', { chart: chart }
            )
        );
    }

    // Set screen reader properties on input boxes for range selector. We need
    // to do this regardless of whether or not these are visible, as they are
    // by default part of the page's tabindex unless we set them to -1.
    if (chart.rangeSelector) {
        each(['minInput', 'maxInput'], function (key, i) {
            if (chart.rangeSelector[key]) {
                chart.rangeSelector[key].setAttribute('tabindex', '-1');
                chart.rangeSelector[key].setAttribute('role', 'textbox');
                chart.rangeSelector[key].setAttribute(
                    'aria-label',
                    chart.langFormat(
                        'accessibility.rangeSelector' +
                            (i ? 'MaxInput' : 'MinInput'), { chart: chart }
                    )
                );
            }
        });
    }

    // Hide text elements from screen readers
    each(textElements, function (el) {
        el.setAttribute('aria-hidden', 'true');
    });

    // Add top-secret screen reader region
    chart.addScreenReaderRegion(hiddenSectionId, tableId);

    // Add ID and summary attr to table HTML
    H.wrap(chart, 'getTable', function (proceed) {
        return proceed.apply(this, Array.prototype.slice.call(arguments, 1))
            .replace(
                '<table>',
                '<table id="' + tableId + '" summary="' + chart.langFormat(
                    'accessibility.tableSummary', { chart: chart }
                ) + '">'
            );
    });
});