data.src.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. /**
  17. * Callback function that returns the correspondig Date object to a match.
  18. */
  19. type DataDateFormatCallbackFunction = (match: Array<number>) => number;
  20. interface AjaxSettingsObject {
  21. /**
  22. * The payload to send.
  23. */
  24. data: (string|Dictionary<any>);
  25. /**
  26. * The data type expected.
  27. */
  28. dataType: ("json"|"octet"|"text"|"xml");
  29. /**
  30. * Function to call on error.
  31. */
  32. error: Function;
  33. /**
  34. * The headers; keyed on header name.
  35. */
  36. headers: Dictionary<string>;
  37. /**
  38. * Function to call on success.
  39. */
  40. success: Function;
  41. /**
  42. * The HTTP method to use. For example GET or POST.
  43. */
  44. type: string;
  45. /**
  46. * The URL to call.
  47. */
  48. url: string;
  49. }
  50. interface Chart {
  51. /**
  52. * The data parser for this chart.
  53. */
  54. data?: Data;
  55. }
  56. /**
  57. * Structure for alternative date formats to parse.
  58. */
  59. interface DataDateFormatObject {
  60. alternative?: string;
  61. parser: DataDateFormatCallbackFunction;
  62. regex: RegExp;
  63. }
  64. /**
  65. * The Data class
  66. */
  67. class Data {
  68. /**
  69. * The Data class
  70. */
  71. constructor(dataOptions: DataOptions, chartOptions?: Options, chart?: Chart);
  72. /**
  73. * A collection of available date formats, extendable from the outside
  74. * to support custom date formats.
  75. */
  76. dateFormats: Dictionary<DataDateFormatObject>;
  77. /**
  78. * If a complete callback function is provided in the options, interpret
  79. * the columns into a Highcharts options object.
  80. */
  81. complete(): void;
  82. /**
  83. * Fetch or refetch live data
  84. *
  85. * @return The URLs that were tried can be found in the options
  86. */
  87. fetchLiveData(): boolean;
  88. /**
  89. * Get the column distribution. For example, a line series takes a
  90. * single column for Y values. A range series takes two columns for low
  91. * and high values respectively, and an OHLC series takes four columns.
  92. */
  93. getColumnDistribution(): void;
  94. /**
  95. * Get the parsed data in a form that we can apply directly to the
  96. * `series.data` config. Array positions can be mapped using the
  97. * `series.keys` option.
  98. *
  99. * @return Data rows
  100. */
  101. getData(): (Array<Array<(number|string)>>|undefined);
  102. /**
  103. * Parse a single column. Set properties like .isDatetime and
  104. * .isNumeric.
  105. *
  106. * @param column
  107. * Column to parse
  108. *
  109. * @param col
  110. * Column index
  111. */
  112. parseColumn(column: Array<DataValueType>, col: number): void;
  113. /**
  114. * Parse a CSV input string
  115. */
  116. parseCSV(inOptions?: DataOptions): Array<Array<DataValueType>>;
  117. /**
  118. * A hook for working directly on the parsed columns
  119. */
  120. parsed(): (boolean|undefined);
  121. /**
  122. * Parse a date and return it as a number. Overridable through
  123. * `options.parseDate`.
  124. */
  125. parseDate(val: string): number;
  126. /**
  127. * Parse a Google spreadsheet.
  128. *
  129. * @return Always returns false, because it is an intermediate fetch.
  130. */
  131. parseGoogleSpreadsheet(): boolean;
  132. /**
  133. * Parse a HTML table
  134. */
  135. parseTable(): Array<Array<DataValueType>>;
  136. /**
  137. * Parse numeric cells in to number types and date types in to true
  138. * dates.
  139. */
  140. parseTypes(): void;
  141. /**
  142. * Reorganize rows into columns.
  143. */
  144. rowsToColumns(rows: Array<Array<DataValueType>>): (Array<Array<DataValueType>>|undefined);
  145. /**
  146. * Trim a string from whitespaces.
  147. *
  148. * @param str
  149. * String to trim
  150. *
  151. * @param inside
  152. * Remove all spaces between numbers.
  153. *
  154. * @return Trimed string
  155. */
  156. trim(str: string, inside?: boolean): string;
  157. /**
  158. * Updates the chart with new data options.
  159. */
  160. update(options: DataOptions, redraw?: boolean): void;
  161. }
  162. /**
  163. * Perform an Ajax call.
  164. *
  165. * @param attr
  166. * The Ajax settings to use.
  167. *
  168. * @return Returns false, if error occured.
  169. */
  170. function ajax(attr: Partial<AjaxSettingsObject>): (false|undefined);
  171. /**
  172. * Creates a data object to parse data for a chart.
  173. */
  174. function data(dataOptions: DataOptions, chartOptions?: Options, chart?: Chart): Data;
  175. /**
  176. * Get a JSON resource over XHR, also supporting CORS without preflight.
  177. *
  178. * @param url
  179. * The URL to load.
  180. *
  181. * @param success
  182. * The success callback. For error handling, use the
  183. * `Highcharts.ajax` function instead.
  184. */
  185. function getJSON(url: string, success: Function): void;
  186. }
  187. export default factory;
  188. export let Highcharts: typeof _Highcharts;