accessibility.d.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. * Enable or disable exposing the point to assistive technology
  66. */
  67. enabled?: boolean;
  68. }
  69. interface PointOptionsObject {
  70. accessibility?: PointAccessibilityOptionsObject;
  71. }
  72. /**
  73. * The AccessibilityComponent base class, representing a part of the chart
  74. * that has accessibility logic connected to it. This class can be inherited
  75. * from to create a custom accessibility component for a chart.
  76. *
  77. * Components should take care to destroy added elements and unregister
  78. * event handlers on destroy. This is handled automatically if using
  79. * this.addEvent and this.createElement.
  80. */
  81. class AccessibilityComponent {
  82. /**
  83. * Called when accessibility is disabled or chart is destroyed.
  84. */
  85. static destroy(): void;
  86. /**
  87. * Get keyboard navigation handler for this component.
  88. */
  89. static getKeyboardNavigation(): KeyboardNavigationHandler;
  90. /**
  91. * Called on component initialization.
  92. */
  93. static init(): void;
  94. /**
  95. * Called on every chart render.
  96. */
  97. static onChartRender(): void;
  98. /**
  99. * Called on updates to the chart, including options changes. Note that
  100. * this is also called on first render of chart.
  101. */
  102. static onChartUpdate(): void;
  103. }
  104. /**
  105. * Define a keyboard navigation handler for use with a
  106. * Highcharts.AccessibilityComponent instance. This functions as an
  107. * abstraction layer for keyboard navigation, and defines a map of keyCodes
  108. * to handler functions.
  109. */
  110. class KeyboardNavigationHandler {
  111. /**
  112. * Define a keyboard navigation handler for use with a
  113. * Highcharts.AccessibilityComponent instance. This functions as an
  114. * abstraction layer for keyboard navigation, and defines a map of
  115. * keyCodes to handler functions.
  116. *
  117. * @param chart
  118. * The chart this module should act on.
  119. *
  120. * @param options
  121. * Options for the keyboard navigation handler.
  122. */
  123. constructor(chart: Chart, options: KeyboardNavigationHandlerOptionsObject);
  124. }
  125. /**
  126. * i18n formatting function. Extends Highcharts.format() functionality by
  127. * also handling arrays and plural conditionals. Arrays can be indexed as
  128. * follows:
  129. *
  130. * - Format: 'This is the first index: {myArray[0]}. The last:
  131. * {myArray[-1]}.'
  132. *
  133. * - Context: { myArray: [0, 1, 2, 3, 4, 5] }
  134. *
  135. * - Result: 'This is the first index: 0. The last: 5.'
  136. *
  137. * They can also be iterated using the #each() function. This will repeat
  138. * the contents of the bracket expression for each element. Example:
  139. *
  140. * - Format: 'List contains: {#each(myArray)cm }'
  141. *
  142. * - Context: { myArray: [0, 1, 2] }
  143. *
  144. * - Result: 'List contains: 0cm 1cm 2cm '
  145. *
  146. * The #each() function optionally takes a length parameter. If positive,
  147. * this parameter specifies the max number of elements to iterate through.
  148. * If negative, the function will subtract the number from the length of the
  149. * array. Use this to stop iterating before the array ends. Example:
  150. *
  151. * - Format: 'List contains: {#each(myArray, -1) }and {myArray[-1]}.'
  152. *
  153. * - Context: { myArray: [0, 1, 2, 3] }
  154. *
  155. * - Result: 'List contains: 0, 1, 2, and 3.'
  156. *
  157. * Use the #plural() function to pick a string depending on whether or not a
  158. * context object is 1. Arguments are #plural(obj, plural, singular).
  159. * Example:
  160. *
  161. * - Format: 'Has {numPoints} {#plural(numPoints, points, point}.'
  162. *
  163. * - Context: { numPoints: 5 }
  164. *
  165. * - Result: 'Has 5 points.'
  166. *
  167. * Optionally there are additional parameters for dual and none:
  168. * #plural(obj, plural, singular, dual, none). Example:
  169. *
  170. * - Format: 'Has {#plural(numPoints, many points, one point, two points,
  171. * none}.'
  172. *
  173. * - Context: { numPoints: 2 }
  174. *
  175. * - Result: 'Has two points.'
  176. *
  177. * The dual or none parameters will take precedence if they are supplied.
  178. *
  179. * @param formatString
  180. * The string to format.
  181. *
  182. * @param context
  183. * Context to apply to the format string.
  184. *
  185. * @param chart
  186. * A `Chart` instance with a time object and numberFormatter, passed
  187. * on to format().
  188. *
  189. * @return The formatted string.
  190. */
  191. function i18nFormat(formatString: string, context: Dictionary<any>, chart: Chart): string;
  192. /**
  193. * If we have a clear root option node for old and new options and a mapping
  194. * between, we can use this generic function for the copy and warn logic.
  195. */
  196. function deprecateFromOptionsMap(): void;
  197. /**
  198. * Put accessible info on series and points of a series.
  199. *
  200. * @param series
  201. * The series to add info on.
  202. */
  203. function describeSeries(series: Series): void;
  204. /**
  205. * Return string with the axis name/title.
  206. */
  207. function getAxisDescription(axis: Axis): string;
  208. /**
  209. * Describe an axis from-to range.
  210. */
  211. function getAxisFromToDescription(axis: Axis): string;
  212. /**
  213. * Return string with text description of the axis range.
  214. *
  215. * @param axis
  216. * The axis to get range desc of.
  217. *
  218. * @return A string with the range description for the axis.
  219. */
  220. function getAxisRangeDescription(axis: Axis): string;
  221. /**
  222. * Describe the length of the time window shown on an axis.
  223. */
  224. function getAxisTimeLengthDesc(axis: Axis): string;
  225. /**
  226. * Describe the range of a category axis.
  227. */
  228. function getCategoryAxisRangeDesc(axis: Axis): string;
  229. function getChartTitle(): string;
  230. }
  231. export default factory;
  232. export let Highcharts: typeof _Highcharts;