accessibility.d.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*!*
  2. *
  3. * Copyright (c) Highsoft AS. All rights reserved.
  4. *
  5. *!*/
  6. import * as globals from "../globals";
  7. import * as _Highcharts from "../highcharts";
  8. /**
  9. * Adds the module to the imported Highcharts namespace.
  10. *
  11. * @param highcharts
  12. * The imported Highcharts namespace to extend.
  13. */
  14. export function factory(highcharts: typeof Highcharts): void;
  15. declare module "../highcharts" {
  16. interface Chart {
  17. /**
  18. * Dismiss popup content in chart, including export menu and tooltip.
  19. */
  20. dismissPopupContent(): void;
  21. /**
  22. * Apply context to a format string from lang options of the chart.
  23. *
  24. * @param langKey
  25. * Key (using dot notation) into lang option structure.
  26. *
  27. * @param context
  28. * Context to apply to the format string.
  29. *
  30. * @return The formatted string.
  31. */
  32. langFormat(langKey: string, context: Dictionary<any>): string;
  33. }
  34. /**
  35. * Options for the keyboard navigation handler.
  36. */
  37. interface KeyboardNavigationHandlerOptionsObject {
  38. /**
  39. * Function to run on initialization of module.
  40. */
  41. init: Function;
  42. /**
  43. * An array containing pairs of an array of keycodes, mapped to a
  44. * handler function. When the keycode is received, the handler is called
  45. * with the keycode as parameter.
  46. */
  47. keyCodeMap: Array<[Array<number>, Function]>;
  48. /**
  49. * Function to run before moving to next/prev module. Receives moving
  50. * direction as parameter: +1 for next, -1 for previous.
  51. */
  52. terminate?: Function;
  53. /**
  54. * Function to run to validate module. Should return false if module
  55. * should not run, true otherwise. Receives chart as parameter.
  56. */
  57. validate?: Function;
  58. }
  59. interface PointAccessibilityOptionsObject {
  60. /**
  61. * Provide a description of the data point, announced to screen readers.
  62. */
  63. description?: string;
  64. }
  65. interface PointOptionsObject {
  66. accessibility?: PointAccessibilityOptionsObject;
  67. }
  68. /**
  69. * The AccessibilityComponent base class, representing a part of the chart
  70. * that has accessibility logic connected to it. This class can be inherited
  71. * from to create a custom accessibility component for a chart.
  72. *
  73. * Components should take care to destroy added elements and unregister
  74. * event handlers on destroy. This is handled automatically if using
  75. * this.addEvent and this.createElement.
  76. */
  77. class AccessibilityComponent {
  78. /**
  79. * Called when accessibility is disabled or chart is destroyed.
  80. */
  81. static destroy(): void;
  82. /**
  83. * Get keyboard navigation handler for this component.
  84. */
  85. static getKeyboardNavigation(): KeyboardNavigationHandler;
  86. /**
  87. * Called on component initialization.
  88. */
  89. static init(): void;
  90. /**
  91. * Called on every chart render.
  92. */
  93. static onChartRender(): void;
  94. /**
  95. * Called on updates to the chart, including options changes. Note that
  96. * this is also called on first render of chart.
  97. */
  98. static onChartUpdate(): void;
  99. }
  100. /**
  101. * Define a keyboard navigation handler for use with a
  102. * Highcharts.AccessibilityComponent instance. This functions as an
  103. * abstraction layer for keyboard navigation, and defines a map of keyCodes
  104. * to handler functions.
  105. */
  106. class KeyboardNavigationHandler {
  107. /**
  108. * Define a keyboard navigation handler for use with a
  109. * Highcharts.AccessibilityComponent instance. This functions as an
  110. * abstraction layer for keyboard navigation, and defines a map of
  111. * keyCodes to handler functions.
  112. *
  113. * @param chart
  114. * The chart this module should act on.
  115. *
  116. * @param options
  117. * Options for the keyboard navigation handler.
  118. */
  119. constructor(chart: Chart, options: KeyboardNavigationHandlerOptionsObject);
  120. }
  121. /**
  122. * i18n formatting function. Extends Highcharts.format() functionality by
  123. * also handling arrays and plural conditionals. Arrays can be indexed as
  124. * follows:
  125. *
  126. * - Format: 'This is the first index: {myArray[0]}. The last:
  127. * {myArray[-1]}.'
  128. *
  129. * - Context: { myArray: [0, 1, 2, 3, 4, 5] }
  130. *
  131. * - Result: 'This is the first index: 0. The last: 5.'
  132. *
  133. * They can also be iterated using the #each() function. This will repeat
  134. * the contents of the bracket expression for each element. Example:
  135. *
  136. * - Format: 'List contains: {#each(myArray)cm }'
  137. *
  138. * - Context: { myArray: [0, 1, 2] }
  139. *
  140. * - Result: 'List contains: 0cm 1cm 2cm '
  141. *
  142. * The #each() function optionally takes a length parameter. If positive,
  143. * this parameter specifies the max number of elements to iterate through.
  144. * If negative, the function will subtract the number from the length of the
  145. * array. Use this to stop iterating before the array ends. Example:
  146. *
  147. * - Format: 'List contains: {#each(myArray, -1) }and {myArray[-1]}.'
  148. *
  149. * - Context: { myArray: [0, 1, 2, 3] }
  150. *
  151. * - Result: 'List contains: 0, 1, 2, and 3.'
  152. *
  153. * Use the #plural() function to pick a string depending on whether or not a
  154. * context object is 1. Arguments are #plural(obj, plural, singular).
  155. * Example:
  156. *
  157. * - Format: 'Has {numPoints} {#plural(numPoints, points, point}.'
  158. *
  159. * - Context: { numPoints: 5 }
  160. *
  161. * - Result: 'Has 5 points.'
  162. *
  163. * Optionally there are additional parameters for dual and none:
  164. * #plural(obj, plural, singular, dual, none). Example:
  165. *
  166. * - Format: 'Has {#plural(numPoints, many points, one point, two points,
  167. * none}.'
  168. *
  169. * - Context: { numPoints: 2 }
  170. *
  171. * - Result: 'Has two points.'
  172. *
  173. * The dual or none parameters will take precedence if they are supplied.
  174. *
  175. * @param formatString
  176. * The string to format.
  177. *
  178. * @param context
  179. * Context to apply to the format string.
  180. *
  181. * @param chart
  182. * A `Chart` instance with a time object and numberFormatter, passed
  183. * on to format().
  184. *
  185. * @return The formatted string.
  186. */
  187. function i18nFormat(formatString: string, context: Dictionary<any>, chart: Chart): string;
  188. /**
  189. * If we have a clear root option node for old and new options and a mapping
  190. * between, we can use this generic function for the copy and warn logic.
  191. */
  192. function deprecateFromOptionsMap(): void;
  193. /**
  194. * Put accessible info on series and points of a series.
  195. *
  196. * @param series
  197. * The series to add info on.
  198. */
  199. function describeSeries(series: Series): void;
  200. function getAxisDescription(axis: Axis): string;
  201. function getChartTitle(): string;
  202. }
  203. export default factory;
  204. export let Highcharts: typeof _Highcharts;