slow-stochastic.src.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**
  2. * @license Highstock JS v8.2.0 (2020-08-20)
  3. *
  4. * Slow Stochastic series type for Highstock
  5. *
  6. * (c) 2010-2019 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-2020 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/SlowStochasticIndicator.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js'], _modules['Mixins/IndicatorRequired.js']], function (H, U, requiredIndicator) {
  93. /* *
  94. *
  95. * License: www.highcharts.com/license
  96. *
  97. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  98. *
  99. * */
  100. var seriesType = U.seriesType;
  101. var seriesTypes = H.seriesTypes;
  102. /**
  103. * The Slow Stochastic series type.
  104. *
  105. * @private
  106. * @class
  107. * @name Highcharts.seriesTypes.slowstochastic
  108. *
  109. * @augments Highcharts.Series
  110. */
  111. seriesType('slowstochastic', 'stochastic',
  112. /**
  113. * Slow Stochastic oscillator. This series requires the `linkedTo` option
  114. * to be set and should be loaded after `stock/indicators/indicators.js`
  115. * and `stock/indicators/stochastic.js` files.
  116. *
  117. * @sample stock/indicators/slow-stochastic
  118. * Slow Stochastic oscillator
  119. *
  120. * @extends plotOptions.stochastic
  121. * @since 8.0.0
  122. * @product highstock
  123. * @requires stock/indicators/indicators
  124. * @requires stock/indicators/stochastic
  125. * @requires stock/indicators/slowstochastic
  126. * @optionparent plotOptions.slowstochastic
  127. */
  128. {
  129. params: {
  130. /**
  131. * Periods for Slow Stochastic oscillator: [%K, %D, SMA(%D)].
  132. *
  133. * @type {Array<number,number,number>}
  134. * @default [14, 3, 3]
  135. */
  136. periods: [14, 3, 3]
  137. }
  138. },
  139. /**
  140. * @lends Highcharts.Series#
  141. */
  142. {
  143. nameBase: 'Slow Stochastic',
  144. init: function () {
  145. var args = arguments,
  146. ctx = this;
  147. requiredIndicator.isParentLoaded(H.seriesTypes.stochastic, 'stochastic', ctx.type, function (indicator) {
  148. indicator.prototype.init.apply(ctx, args);
  149. return;
  150. });
  151. },
  152. getValues: function (series, params) {
  153. var periods = params.periods,
  154. fastValues = seriesTypes.stochastic.prototype.getValues.call(this,
  155. series,
  156. params),
  157. slowValues = {
  158. values: [],
  159. xData: [],
  160. yData: []
  161. };
  162. var i = 0;
  163. if (!fastValues) {
  164. return;
  165. }
  166. slowValues.xData = fastValues.xData.slice(periods[1] - 1);
  167. var fastYData = fastValues.yData.slice(periods[1] - 1);
  168. // Get SMA(%D)
  169. var smoothedValues = seriesTypes.sma.prototype.getValues.call(this, {
  170. xData: slowValues.xData,
  171. yData: fastYData
  172. }, {
  173. index: 1,
  174. period: periods[2]
  175. });
  176. if (!smoothedValues) {
  177. return;
  178. }
  179. var xDataLen = slowValues.xData.length;
  180. // Format data
  181. for (; i < xDataLen; i++) {
  182. slowValues.yData[i] = [
  183. fastYData[i][1],
  184. smoothedValues.yData[i - periods[2] + 1] || null
  185. ];
  186. slowValues.values[i] = [
  187. slowValues.xData[i],
  188. fastYData[i][1],
  189. smoothedValues.yData[i - periods[2] + 1] || null
  190. ];
  191. }
  192. return slowValues;
  193. }
  194. });
  195. /**
  196. * A Slow Stochastic indicator. If the [type](#series.slowstochastic.type)
  197. * option is not specified, it is inherited from [chart.type](#chart.type).
  198. *
  199. * @extends series,plotOptions.slowstochastic
  200. * @since 8.0.0
  201. * @product highstock
  202. * @requires stock/indicators/indicators
  203. * @requires stock/indicators/stochastic
  204. * @requires stock/indicators/slowstochastic
  205. * @apioption series.slowstochastic
  206. */
  207. ''; // to include the above in the js output
  208. });
  209. _registerModule(_modules, 'masters/indicators/slow-stochastic.src.js', [], function () {
  210. });
  211. }));