slow-stochastic.src.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /**
  2. * @license Highstock JS v9.1.1 (2021-06-04)
  3. *
  4. * Slow Stochastic series type for Highcharts Stock
  5. *
  6. * (c) 2010-2021 Pawel Fus
  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/indicators', ['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/SlowStochastic/SlowStochasticIndicator.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 StochasticIndicator = SeriesRegistry.seriesTypes.stochastic;
  117. var seriesTypes = SeriesRegistry.seriesTypes;
  118. var extend = U.extend,
  119. merge = U.merge;
  120. /**
  121. * The Slow Stochastic series type.
  122. *
  123. * @private
  124. * @class
  125. * @name Highcharts.seriesTypes.slowstochastic
  126. *
  127. * @augments Highcharts.Series
  128. */
  129. var SlowStochasticIndicator = /** @class */ (function (_super) {
  130. __extends(SlowStochasticIndicator, _super);
  131. function SlowStochasticIndicator() {
  132. var _this = _super !== null && _super.apply(this,
  133. arguments) || this;
  134. _this.data = void 0;
  135. _this.options = void 0;
  136. _this.points = void 0;
  137. return _this;
  138. }
  139. SlowStochasticIndicator.prototype.init = function () {
  140. var args = arguments,
  141. ctx = this;
  142. RequiredIndicatorMixin.isParentLoaded(seriesTypes.stochastic, 'stochastic', ctx.type, function (indicator) {
  143. indicator.prototype.init.apply(ctx, args);
  144. return;
  145. });
  146. };
  147. SlowStochasticIndicator.prototype.getValues = function (series, params) {
  148. var periods = params.periods,
  149. fastValues = seriesTypes.stochastic.prototype.getValues.call(this,
  150. series,
  151. params),
  152. slowValues = {
  153. values: [],
  154. xData: [],
  155. yData: []
  156. };
  157. var i = 0;
  158. if (!fastValues) {
  159. return;
  160. }
  161. slowValues.xData = fastValues.xData.slice(periods[1] - 1);
  162. var fastYData = fastValues.yData.slice(periods[1] - 1);
  163. // Get SMA(%D)
  164. var smoothedValues = seriesTypes.sma.prototype.getValues.call(this, {
  165. xData: slowValues.xData,
  166. yData: fastYData
  167. }, {
  168. index: 1,
  169. period: periods[2]
  170. });
  171. if (!smoothedValues) {
  172. return;
  173. }
  174. var xDataLen = slowValues.xData.length;
  175. // Format data
  176. for (; i < xDataLen; i++) {
  177. slowValues.yData[i] = [
  178. fastYData[i][1],
  179. smoothedValues.yData[i - periods[2] + 1] || null
  180. ];
  181. slowValues.values[i] = [
  182. slowValues.xData[i],
  183. fastYData[i][1],
  184. smoothedValues.yData[i - periods[2] + 1] || null
  185. ];
  186. }
  187. return slowValues;
  188. };
  189. /**
  190. * Slow Stochastic oscillator. This series requires the `linkedTo` option
  191. * to be set and should be loaded after `stock/indicators/indicators.js`
  192. * and `stock/indicators/stochastic.js` files.
  193. *
  194. * @sample stock/indicators/slow-stochastic
  195. * Slow Stochastic oscillator
  196. *
  197. * @extends plotOptions.stochastic
  198. * @since 8.0.0
  199. * @product highstock
  200. * @requires stock/indicators/indicators
  201. * @requires stock/indicators/stochastic
  202. * @requires stock/indicators/slowstochastic
  203. * @optionparent plotOptions.slowstochastic
  204. */
  205. SlowStochasticIndicator.defaultOptions = merge(StochasticIndicator.defaultOptions, {
  206. params: {
  207. /**
  208. * Periods for Slow Stochastic oscillator: [%K, %D, SMA(%D)].
  209. *
  210. * @type {Array<number,number,number>}
  211. * @default [14, 3, 3]
  212. */
  213. periods: [14, 3, 3]
  214. }
  215. });
  216. return SlowStochasticIndicator;
  217. }(StochasticIndicator));
  218. extend(SlowStochasticIndicator.prototype, {
  219. nameBase: 'Slow Stochastic'
  220. });
  221. SeriesRegistry.registerSeriesType('slowstochastic', SlowStochasticIndicator);
  222. /* *
  223. *
  224. * Default Export
  225. *
  226. * */
  227. /**
  228. * A Slow Stochastic indicator. If the [type](#series.slowstochastic.type)
  229. * option is not specified, it is inherited from [chart.type](#chart.type).
  230. *
  231. * @extends series,plotOptions.slowstochastic
  232. * @since 8.0.0
  233. * @product highstock
  234. * @requires stock/indicators/indicators
  235. * @requires stock/indicators/stochastic
  236. * @requires stock/indicators/slowstochastic
  237. * @apioption series.slowstochastic
  238. */
  239. ''; // to include the above in the js output
  240. return SlowStochasticIndicator;
  241. });
  242. _registerModule(_modules, 'masters/indicators/slow-stochastic.src.js', [], function () {
  243. });
  244. }));