accessibility.src.d.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*!*
  2. *
  3. * Copyright (c) Highsoft AS. All rights reserved.
  4. *
  5. *!*/
  6. import * as globals from "../globals.src";
  7. import * as _Highcharts from "../highcharts.src";
  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.src" {
  16. interface Chart {
  17. /**
  18. * Apply context to a format string from lang options of the chart.
  19. *
  20. * @param langKey
  21. * Key (using dot notation) into lang option structure.
  22. *
  23. * @param context
  24. * Context to apply to the format string.
  25. *
  26. * @return The formatted string.
  27. */
  28. langFormat(langKey: string, context: Dictionary<any>): string;
  29. }
  30. /**
  31. * Options for the keyboard navigation handler.
  32. */
  33. interface KeyboardNavigationHandlerOptionsObject {
  34. /**
  35. * Function to run on initialization of module.
  36. */
  37. init: Function;
  38. /**
  39. * An array containing pairs of an array of keycodes, mapped to a
  40. * handler function. When the keycode is received, the handler is called
  41. * with the keycode as parameter.
  42. */
  43. keyCodeMap: Array<[Array<number>, Function]>;
  44. /**
  45. * Function to run before moving to next/prev module. Receives moving
  46. * direction as parameter: +1 for next, -1 for previous.
  47. */
  48. terminate?: Function;
  49. /**
  50. * Function to run to validate module. Should return false if module
  51. * should not run, true otherwise. Receives chart as parameter.
  52. */
  53. validate?: Function;
  54. }
  55. interface PointAccessibilityOptionsObject {
  56. /**
  57. * Provide a description of the data point, announced to screen readers.
  58. */
  59. description?: string;
  60. /**
  61. * Enable or disable exposing the point to assistive technology
  62. */
  63. enabled?: boolean;
  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. /**
  201. * Return string with the axis name/title.
  202. */
  203. function getAxisDescription(axis: Axis): string;
  204. /**
  205. * Describe an axis from-to range.
  206. */
  207. function getAxisFromToDescription(axis: Axis): string;
  208. /**
  209. * Return string with text description of the axis range.
  210. *
  211. * @param axis
  212. * The axis to get range desc of.
  213. *
  214. * @return A string with the range description for the axis.
  215. */
  216. function getAxisRangeDescription(axis: Axis): string;
  217. /**
  218. * Describe the length of the time window shown on an axis.
  219. */
  220. function getAxisTimeLengthDesc(axis: Axis): string;
  221. /**
  222. * Describe the range of a category axis.
  223. */
  224. function getCategoryAxisRangeDesc(axis: Axis): string;
  225. function getChartTitle(): string;
  226. }
  227. export default factory;
  228. export let Highcharts: typeof _Highcharts;