ao.src.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * @license Highstock JS v9.1.1 (2021-06-04)
  3. *
  4. * Indicator series type for Highcharts Stock
  5. *
  6. * (c) 2010-2021 Wojciech Chmiel
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/indicators/ao', ['highcharts', 'highcharts/modules/stock'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'Stock/Indicators/AO/AOIndicator.js', [_modules['Core/Globals.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js'], _modules['Core/Color/Palette.js']], function (H, SeriesRegistry, U, palette) {
  32. /* *
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. *
  38. * */
  39. var __extends = (this && this.__extends) || (function () {
  40. var extendStatics = function (d,
  41. b) {
  42. extendStatics = Object.setPrototypeOf ||
  43. ({ __proto__: [] } instanceof Array && function (d,
  44. b) { d.__proto__ = b; }) ||
  45. function (d,
  46. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  47. return extendStatics(d, b);
  48. };
  49. return function (d, b) {
  50. extendStatics(d, b);
  51. function __() { this.constructor = d; }
  52. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  53. };
  54. })();
  55. var noop = H.noop;
  56. var _a = SeriesRegistry.seriesTypes,
  57. SMAIndicator = _a.sma,
  58. ColumnSeries = _a.column;
  59. var extend = U.extend,
  60. merge = U.merge,
  61. correctFloat = U.correctFloat,
  62. isArray = U.isArray;
  63. /* *
  64. *
  65. * Class
  66. *
  67. * */
  68. /**
  69. * The AO series type
  70. *
  71. * @private
  72. * @class
  73. * @name Highcharts.seriesTypes.ao
  74. *
  75. * @augments Highcharts.Series
  76. */
  77. var AOIndicator = /** @class */ (function (_super) {
  78. __extends(AOIndicator, _super);
  79. function AOIndicator() {
  80. var _this = _super !== null && _super.apply(this,
  81. arguments) || this;
  82. /**
  83. *
  84. * Properties
  85. *
  86. */
  87. _this.data = void 0;
  88. _this.options = void 0;
  89. _this.points = void 0;
  90. return _this;
  91. }
  92. /**
  93. *
  94. * Functions
  95. *
  96. */
  97. AOIndicator.prototype.drawGraph = function () {
  98. var indicator = this,
  99. options = indicator.options,
  100. points = indicator.points,
  101. userColor = indicator.userOptions.color,
  102. positiveColor = options.greaterBarColor,
  103. negativeColor = options.lowerBarColor,
  104. firstPoint = points[0],
  105. i;
  106. if (!userColor && firstPoint) {
  107. firstPoint.color = positiveColor;
  108. for (i = 1; i < points.length; i++) {
  109. if (points[i].y > points[i - 1].y) {
  110. points[i].color = positiveColor;
  111. }
  112. else if (points[i].y < points[i - 1].y) {
  113. points[i].color = negativeColor;
  114. }
  115. else {
  116. points[i].color = points[i - 1].color;
  117. }
  118. }
  119. }
  120. };
  121. AOIndicator.prototype.getValues = function (series) {
  122. var shortPeriod = 5,
  123. longPeriod = 34,
  124. xVal = series.xData || [],
  125. yVal = series.yData || [],
  126. yValLen = yVal.length,
  127. AO = [], // 0- date, 1- Awesome Oscillator
  128. xData = [],
  129. yData = [],
  130. high = 1,
  131. low = 2,
  132. shortSum = 0,
  133. longSum = 0,
  134. shortSMA, // Shorter Period SMA
  135. longSMA, // Longer Period SMA
  136. awesome,
  137. shortLastIndex,
  138. longLastIndex,
  139. price,
  140. i,
  141. j;
  142. if (xVal.length <= longPeriod ||
  143. !isArray(yVal[0]) ||
  144. yVal[0].length !== 4) {
  145. return;
  146. }
  147. for (i = 0; i < longPeriod - 1; i++) {
  148. price = (yVal[i][high] + yVal[i][low]) / 2;
  149. if (i >= longPeriod - shortPeriod) {
  150. shortSum = correctFloat(shortSum + price);
  151. }
  152. longSum = correctFloat(longSum + price);
  153. }
  154. for (j = longPeriod - 1; j < yValLen; j++) {
  155. price = (yVal[j][high] + yVal[j][low]) / 2;
  156. shortSum = correctFloat(shortSum + price);
  157. longSum = correctFloat(longSum + price);
  158. shortSMA = shortSum / shortPeriod;
  159. longSMA = longSum / longPeriod;
  160. awesome = correctFloat(shortSMA - longSMA);
  161. AO.push([xVal[j], awesome]);
  162. xData.push(xVal[j]);
  163. yData.push(awesome);
  164. shortLastIndex = j + 1 - shortPeriod;
  165. longLastIndex = j + 1 - longPeriod;
  166. shortSum = correctFloat(shortSum -
  167. (yVal[shortLastIndex][high] +
  168. yVal[shortLastIndex][low]) / 2);
  169. longSum = correctFloat(longSum -
  170. (yVal[longLastIndex][high] +
  171. yVal[longLastIndex][low]) / 2);
  172. }
  173. return {
  174. values: AO,
  175. xData: xData,
  176. yData: yData
  177. };
  178. };
  179. /**
  180. * Awesome Oscillator. This series requires the `linkedTo` option to
  181. * be set and should be loaded after the `stock/indicators/indicators.js`
  182. *
  183. * @sample {highstock} stock/indicators/ao
  184. * Awesome
  185. *
  186. * @extends plotOptions.sma
  187. * @since 7.0.0
  188. * @product highstock
  189. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  190. * params, pointInterval, pointIntervalUnit, pointPlacement,
  191. * pointRange, pointStart, showInNavigator, stacking
  192. * @requires stock/indicators/indicators
  193. * @requires stock/indicators/ao
  194. * @optionparent plotOptions.ao
  195. */
  196. AOIndicator.defaultOptions = merge(SMAIndicator.defaultOptions, {
  197. params: {
  198. // Index and period are unchangeable, do not inherit (#15362)
  199. index: void 0,
  200. period: void 0
  201. },
  202. /**
  203. * Color of the Awesome oscillator series bar that is greater than the
  204. * previous one. Note that if a `color` is defined, the `color`
  205. * takes precedence and the `greaterBarColor` is ignored.
  206. *
  207. * @sample {highstock} stock/indicators/ao/
  208. * greaterBarColor
  209. *
  210. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  211. * @since 7.0.0
  212. */
  213. greaterBarColor: palette.positiveColor,
  214. /**
  215. * Color of the Awesome oscillator series bar that is lower than the
  216. * previous one. Note that if a `color` is defined, the `color`
  217. * takes precedence and the `lowerBarColor` is ignored.
  218. *
  219. * @sample {highstock} stock/indicators/ao/
  220. * lowerBarColor
  221. *
  222. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  223. * @since 7.0.0
  224. */
  225. lowerBarColor: palette.negativeColor,
  226. threshold: 0,
  227. groupPadding: 0.2,
  228. pointPadding: 0.2,
  229. crisp: false,
  230. states: {
  231. hover: {
  232. halo: {
  233. size: 0
  234. }
  235. }
  236. }
  237. });
  238. return AOIndicator;
  239. }(SMAIndicator));
  240. extend(AOIndicator.prototype, {
  241. nameBase: 'AO',
  242. nameComponents: false,
  243. // Columns support:
  244. markerAttribs: noop,
  245. getColumnMetrics: ColumnSeries.prototype.getColumnMetrics,
  246. crispCol: ColumnSeries.prototype.crispCol,
  247. translate: ColumnSeries.prototype.translate,
  248. drawPoints: ColumnSeries.prototype.drawPoints
  249. });
  250. SeriesRegistry.registerSeriesType('ao', AOIndicator);
  251. /* *
  252. *
  253. * Default Export
  254. *
  255. * */
  256. /**
  257. * An `AO` series. If the [type](#series.ao.type)
  258. * option is not specified, it is inherited from [chart.type](#chart.type).
  259. *
  260. * @extends series,plotOptions.ao
  261. * @since 7.0.0
  262. * @product highstock
  263. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  264. * navigatorOptions, pointInterval, pointIntervalUnit,
  265. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  266. * @requires stock/indicators/indicators
  267. * @requires stock/indicators/ao
  268. * @apioption series.ao
  269. */
  270. ''; // for including the above in the doclets
  271. return AOIndicator;
  272. });
  273. _registerModule(_modules, 'masters/indicators/ao.src.js', [], function () {
  274. });
  275. }));