slow-stochastic.src.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /**
  2. * @license Highstock JS v8.0.0 (2019-12-10)
  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/indicator-required.js', [_modules['parts/Globals.js']], function (H) {
  32. /**
  33. *
  34. * (c) 2010-2019 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 = H.error;
  42. /* eslint-disable no-invalid-this, valid-jsdoc */
  43. var requiredIndicatorMixin = {
  44. /**
  45. * Check whether given indicator is loaded, else throw error.
  46. * @private
  47. * @param {Highcharts.Indicator} indicator
  48. * Indicator constructor function.
  49. * @param {string} requiredIndicator
  50. * Required indicator type.
  51. * @param {string} type
  52. * Type of indicator where function was called (parent).
  53. * @param {Highcharts.IndicatorCallbackFunction} callback
  54. * Callback which is triggered if the given indicator is loaded.
  55. * Takes indicator as an argument.
  56. * @param {string} errMessage
  57. * Error message that will be logged in console.
  58. * @return {boolean}
  59. * Returns false when there is no required indicator loaded.
  60. */
  61. isParentLoaded: function (indicator, requiredIndicator, type, callback, errMessage) {
  62. if (indicator) {
  63. return callback ? callback(indicator) : true;
  64. }
  65. error(errMessage || this.generateMessage(type, requiredIndicator));
  66. return false;
  67. },
  68. /**
  69. * @private
  70. * @param {string} indicatorType
  71. * Indicator type
  72. * @param {string} required
  73. * Required indicator
  74. * @return {string}
  75. * Error message
  76. */
  77. generateMessage: function (indicatorType, required) {
  78. return 'Error: "' + indicatorType +
  79. '" indicator type requires "' + required +
  80. '" indicator loaded before. Please read docs: ' +
  81. 'https://api.highcharts.com/highstock/plotOptions.' +
  82. indicatorType;
  83. }
  84. };
  85. return requiredIndicatorMixin;
  86. });
  87. _registerModule(_modules, 'indicators/slow-stochastic.src.js', [_modules['parts/Globals.js'], _modules['mixins/indicator-required.js']], function (H, requiredIndicator) {
  88. /* *
  89. *
  90. * License: www.highcharts.com/license
  91. *
  92. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  93. *
  94. * */
  95. var seriesTypes = H.seriesTypes;
  96. /**
  97. * The Slow Stochastic series type.
  98. *
  99. * @private
  100. * @class
  101. * @name Highcharts.seriesTypes.slowstochastic
  102. *
  103. * @augments Highcharts.Series
  104. */
  105. H.seriesType('slowstochastic', 'stochastic',
  106. /**
  107. * Slow Stochastic oscillator. This series requires the `linkedTo` option
  108. * to be set and should be loaded after `stock/indicators/indicators.js`
  109. * and `stock/indicators/stochastic.js` files.
  110. *
  111. * @sample stock/indicators/slow-stochastic
  112. * Slow Stochastic oscillator
  113. *
  114. * @extends plotOptions.stochastic
  115. * @since 8.0.0
  116. * @product highstock
  117. * @requires stock/indicators/indicators
  118. * @requires stock/indicators/stochastic
  119. * @requires stock/indicators/slowstochastic
  120. * @optionparent plotOptions.slowstochastic
  121. */
  122. {
  123. params: {
  124. /**
  125. * Periods for Slow Stochastic oscillator: [%K, %D, SMA(%D)].
  126. *
  127. * @type {Array<number,number,number>}
  128. * @default [14, 3, 3]
  129. */
  130. periods: [14, 3, 3]
  131. }
  132. },
  133. /**
  134. * @lends Highcharts.Series#
  135. */
  136. {
  137. nameBase: 'Slow Stochastic',
  138. init: function () {
  139. var args = arguments, ctx = this;
  140. requiredIndicator.isParentLoaded(H.seriesTypes.stochastic, 'stochastic', ctx.type, function (indicator) {
  141. indicator.prototype.init.apply(ctx, args);
  142. return;
  143. });
  144. },
  145. getValues: function (series, params) {
  146. var periods = params.periods, fastValues = seriesTypes.stochastic.prototype.getValues.call(this, series, params), slowValues = {
  147. values: [],
  148. xData: [],
  149. yData: []
  150. };
  151. var i = 0;
  152. if (!fastValues) {
  153. return;
  154. }
  155. slowValues.xData = fastValues.xData.slice(periods[1] - 1);
  156. var fastYData = fastValues.yData.slice(periods[1] - 1);
  157. // Get SMA(%D)
  158. var smoothedValues = seriesTypes.sma.prototype.getValues.call(this, {
  159. xData: slowValues.xData,
  160. yData: fastYData
  161. }, {
  162. index: 1,
  163. period: periods[2]
  164. });
  165. if (!smoothedValues) {
  166. return;
  167. }
  168. var xDataLen = slowValues.xData.length;
  169. // Format data
  170. for (; i < xDataLen; i++) {
  171. slowValues.yData[i] = [
  172. fastYData[i][1],
  173. smoothedValues.yData[i - periods[2] + 1] || null
  174. ];
  175. slowValues.values[i] = [
  176. slowValues.xData[i],
  177. fastYData[i][1],
  178. smoothedValues.yData[i - periods[2] + 1] || null
  179. ];
  180. }
  181. return slowValues;
  182. }
  183. });
  184. /**
  185. * A Slow Stochastic indicator. If the [type](#series.slowstochastic.type)
  186. * option is not specified, it is inherited from [chart.type](#chart.type).
  187. *
  188. * @extends series,plotOptions.slowstochastic
  189. * @since 8.0.0
  190. * @product highstock
  191. * @requires stock/indicators/indicators
  192. * @requires stock/indicators/stochastic
  193. * @requires stock/indicators/slowstochastic
  194. * @apioption series.slowstochastic
  195. */
  196. ''; // to include the above in the js output
  197. });
  198. _registerModule(_modules, 'masters/indicators/slow-stochastic.src.js', [], function () {
  199. });
  200. }));