SeriesComponent.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* *
  2. *
  3. * (c) 2009-2021 Øystein Moseng
  4. *
  5. * Accessibility component for series and points.
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. import H from '../../../Core/Globals.js';
  14. import U from '../../../Core/Utilities.js';
  15. var extend = U.extend;
  16. import AccessibilityComponent from '../../AccessibilityComponent.js';
  17. import SeriesKeyboardNavigation from './SeriesKeyboardNavigation.js';
  18. import NewDataAnnouncer from './NewDataAnnouncer.js';
  19. import addForceMarkersEvents from './ForcedMarkers.js';
  20. import ChartUtilities from '../../Utils/ChartUtilities.js';
  21. var hideSeriesFromAT = ChartUtilities.hideSeriesFromAT;
  22. import SeriesDescriber from './SeriesDescriber.js';
  23. var describeSeries = SeriesDescriber.describeSeries;
  24. import Tooltip from '../../../Core/Tooltip.js';
  25. // Expose functionality to users
  26. H.SeriesAccessibilityDescriber = SeriesDescriber;
  27. // Handle forcing markers
  28. addForceMarkersEvents();
  29. /* eslint-disable no-invalid-this, valid-jsdoc */
  30. /**
  31. * The SeriesComponent class
  32. *
  33. * @private
  34. * @class
  35. * @name Highcharts.SeriesComponent
  36. */
  37. var SeriesComponent = function () { };
  38. SeriesComponent.prototype = new AccessibilityComponent();
  39. extend(SeriesComponent.prototype, /** @lends Highcharts.SeriesComponent */ {
  40. /**
  41. * Init the component.
  42. */
  43. init: function () {
  44. this.newDataAnnouncer = new NewDataAnnouncer(this.chart);
  45. this.newDataAnnouncer.init();
  46. this.keyboardNavigation = new SeriesKeyboardNavigation(this.chart, this.keyCodes);
  47. this.keyboardNavigation.init();
  48. this.hideTooltipFromATWhenShown();
  49. this.hideSeriesLabelsFromATWhenShown();
  50. },
  51. /**
  52. * @private
  53. */
  54. hideTooltipFromATWhenShown: function () {
  55. var component = this;
  56. this.addEvent(Tooltip, 'refresh', function () {
  57. if (this.chart === component.chart &&
  58. this.label &&
  59. this.label.element) {
  60. this.label.element.setAttribute('aria-hidden', true);
  61. }
  62. });
  63. },
  64. /**
  65. * @private
  66. */
  67. hideSeriesLabelsFromATWhenShown: function () {
  68. this.addEvent(this.chart, 'afterDrawSeriesLabels', function () {
  69. this.series.forEach(function (series) {
  70. if (series.labelBySeries) {
  71. series.labelBySeries.attr('aria-hidden', true);
  72. }
  73. });
  74. });
  75. },
  76. /**
  77. * Called on chart render. It is necessary to do this for render in case
  78. * markers change on zoom/pixel density.
  79. */
  80. onChartRender: function () {
  81. var chart = this.chart;
  82. chart.series.forEach(function (series) {
  83. var shouldDescribeSeries = (series.options.accessibility &&
  84. series.options.accessibility.enabled) !== false &&
  85. series.visible;
  86. if (shouldDescribeSeries) {
  87. describeSeries(series);
  88. }
  89. else {
  90. hideSeriesFromAT(series);
  91. }
  92. });
  93. },
  94. /**
  95. * Get keyboard navigation handler for this component.
  96. * @return {Highcharts.KeyboardNavigationHandler}
  97. */
  98. getKeyboardNavigation: function () {
  99. return this.keyboardNavigation.getKeyboardNavigationHandler();
  100. },
  101. /**
  102. * Remove traces
  103. */
  104. destroy: function () {
  105. this.newDataAnnouncer.destroy();
  106. this.keyboardNavigation.destroy();
  107. }
  108. });
  109. export default SeriesComponent;