apo.src.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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/apo', ['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, 'Mixins/IndicatorRequired.js', [_modules['Core/Utilities.js']], function (U) {
  32. /**
  33. *
  34. * (c) 2010-2021 Daniel Studencki
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. var error = U.error;
  42. /* eslint-disable no-invalid-this, valid-jsdoc */
  43. var requiredIndicatorMixin = {
  44. /**
  45. * Check whether given indicator is loaded,
  46. else throw error.
  47. * @private
  48. * @param {Highcharts.Indicator} indicator
  49. * Indicator constructor function.
  50. * @param {string} requiredIndicator
  51. * Required indicator type.
  52. * @param {string} type
  53. * Type of indicator where function was called (parent).
  54. * @param {Highcharts.IndicatorCallbackFunction} callback
  55. * Callback which is triggered if the given indicator is loaded.
  56. * Takes indicator as an argument.
  57. * @param {string} errMessage
  58. * Error message that will be logged in console.
  59. * @return {boolean}
  60. * Returns false when there is no required indicator loaded.
  61. */
  62. isParentLoaded: function (indicator,
  63. requiredIndicator,
  64. type,
  65. callback,
  66. errMessage) {
  67. if (indicator) {
  68. return callback ? callback(indicator) : true;
  69. }
  70. error(errMessage || this.generateMessage(type, requiredIndicator));
  71. return false;
  72. },
  73. /**
  74. * @private
  75. * @param {string} indicatorType
  76. * Indicator type
  77. * @param {string} required
  78. * Required indicator
  79. * @return {string}
  80. * Error message
  81. */
  82. generateMessage: function (indicatorType, required) {
  83. return 'Error: "' + indicatorType +
  84. '" indicator type requires "' + required +
  85. '" indicator loaded before. Please read docs: ' +
  86. 'https://api.highcharts.com/highstock/plotOptions.' +
  87. indicatorType;
  88. }
  89. };
  90. return requiredIndicatorMixin;
  91. });
  92. _registerModule(_modules, 'Stock/Indicators/APO/APOIndicator.js', [_modules['Mixins/IndicatorRequired.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (RequiredIndicatorMixin, SeriesRegistry, U) {
  93. /* *
  94. *
  95. * License: www.highcharts.com/license
  96. *
  97. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  98. *
  99. * */
  100. var __extends = (this && this.__extends) || (function () {
  101. var extendStatics = function (d,
  102. b) {
  103. extendStatics = Object.setPrototypeOf ||
  104. ({ __proto__: [] } instanceof Array && function (d,
  105. b) { d.__proto__ = b; }) ||
  106. function (d,
  107. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  108. return extendStatics(d, b);
  109. };
  110. return function (d, b) {
  111. extendStatics(d, b);
  112. function __() { this.constructor = d; }
  113. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  114. };
  115. })();
  116. var EMAIndicator = SeriesRegistry.seriesTypes.ema;
  117. var extend = U.extend,
  118. merge = U.merge,
  119. error = U.error;
  120. /* *
  121. *
  122. * Class
  123. *
  124. * */
  125. /**
  126. * The APO series type.
  127. *
  128. * @private
  129. * @class
  130. * @name Highcharts.seriesTypes.apo
  131. *
  132. * @augments Highcharts.Series
  133. */
  134. var APOIndicator = /** @class */ (function (_super) {
  135. __extends(APOIndicator, _super);
  136. function APOIndicator() {
  137. var _this = _super !== null && _super.apply(this,
  138. arguments) || this;
  139. /* *
  140. *
  141. * Properties
  142. *
  143. * */
  144. _this.data = void 0;
  145. _this.options = void 0;
  146. _this.points = void 0;
  147. return _this;
  148. }
  149. /* *
  150. *
  151. * Functions
  152. *
  153. * */
  154. APOIndicator.prototype.getValues = function (series, params) {
  155. var periods = params.periods,
  156. index = params.index,
  157. // 0- date, 1- Absolute price oscillator
  158. APO = [],
  159. xData = [],
  160. yData = [],
  161. periodsOffset,
  162. // Shorter Period EMA
  163. SPE,
  164. // Longer Period EMA
  165. LPE,
  166. oscillator,
  167. i;
  168. // Check if periods are correct
  169. if (periods.length !== 2 || periods[1] <= periods[0]) {
  170. error('Error: "APO requires two periods. Notice, first period ' +
  171. 'should be lower than the second one."');
  172. return;
  173. }
  174. SPE = EMAIndicator.prototype.getValues.call(this, series, {
  175. index: index,
  176. period: periods[0]
  177. });
  178. LPE = EMAIndicator.prototype.getValues.call(this, series, {
  179. index: index,
  180. period: periods[1]
  181. });
  182. // Check if ema is calculated properly, if not skip
  183. if (!SPE || !LPE) {
  184. return;
  185. }
  186. periodsOffset = periods[1] - periods[0];
  187. for (i = 0; i < LPE.yData.length; i++) {
  188. oscillator = (SPE.yData[i + periodsOffset] -
  189. LPE.yData[i]);
  190. APO.push([LPE.xData[i], oscillator]);
  191. xData.push(LPE.xData[i]);
  192. yData.push(oscillator);
  193. }
  194. return {
  195. values: APO,
  196. xData: xData,
  197. yData: yData
  198. };
  199. };
  200. APOIndicator.prototype.init = function () {
  201. var args = arguments,
  202. ctx = this;
  203. RequiredIndicatorMixin.isParentLoaded(EMAIndicator, 'ema', ctx.type, function (indicator) {
  204. indicator.prototype.init.apply(ctx, args);
  205. return;
  206. });
  207. };
  208. /**
  209. * Absolute Price Oscillator. This series requires the `linkedTo` option to
  210. * be set and should be loaded after the `stock/indicators/indicators.js`
  211. * and `stock/indicators/ema.js`.
  212. *
  213. * @sample {highstock} stock/indicators/apo
  214. * Absolute Price Oscillator
  215. *
  216. * @extends plotOptions.ema
  217. * @since 7.0.0
  218. * @product highstock
  219. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  220. * pointInterval, pointIntervalUnit, pointPlacement,
  221. * pointRange, pointStart, showInNavigator, stacking
  222. * @requires stock/indicators/indicators
  223. * @requires stock/indicators/ema
  224. * @requires stock/indicators/apo
  225. * @optionparent plotOptions.apo
  226. */
  227. APOIndicator.defaultOptions = merge(EMAIndicator.defaultOptions, {
  228. /**
  229. * Paramters used in calculation of Absolute Price Oscillator
  230. * series points.
  231. *
  232. * @excluding period
  233. */
  234. params: {
  235. period: void 0,
  236. /**
  237. * Periods for Absolute Price Oscillator calculations.
  238. *
  239. * @type {Array<number>}
  240. * @default [10, 20]
  241. * @since 7.0.0
  242. */
  243. periods: [10, 20]
  244. }
  245. });
  246. return APOIndicator;
  247. }(EMAIndicator));
  248. extend(APOIndicator.prototype, {
  249. nameBase: 'APO',
  250. nameComponents: ['periods']
  251. });
  252. SeriesRegistry.registerSeriesType('apo', APOIndicator);
  253. /* *
  254. *
  255. * Default Export
  256. *
  257. * */
  258. /**
  259. * An `Absolute Price Oscillator` series. If the [type](#series.apo.type) option
  260. * is not specified, it is inherited from [chart.type](#chart.type).
  261. *
  262. * @extends series,plotOptions.apo
  263. * @since 7.0.0
  264. * @product highstock
  265. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  266. * navigatorOptions, pointInterval, pointIntervalUnit,
  267. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  268. * @requires stock/indicators/indicators
  269. * @requires stock/indicators/ema
  270. * @requires stock/indicators/apo
  271. * @apioption series.apo
  272. */
  273. ''; // to include the above in the js output
  274. return APOIndicator;
  275. });
  276. _registerModule(_modules, 'masters/indicators/apo.src.js', [], function () {
  277. });
  278. }));