slow-stochastic.src.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* *
  2. *
  3. * License: www.highcharts.com/license
  4. *
  5. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6. *
  7. * */
  8. 'use strict';
  9. import H from '../parts/Globals.js';
  10. import requiredIndicator from '../mixins/indicator-required.js';
  11. var seriesTypes = H.seriesTypes;
  12. /**
  13. * The Slow Stochastic series type.
  14. *
  15. * @private
  16. * @class
  17. * @name Highcharts.seriesTypes.slowstochastic
  18. *
  19. * @augments Highcharts.Series
  20. */
  21. H.seriesType('slowstochastic', 'stochastic',
  22. /**
  23. * Slow Stochastic oscillator. This series requires the `linkedTo` option
  24. * to be set and should be loaded after `stock/indicators/indicators.js`
  25. * and `stock/indicators/stochastic.js` files.
  26. *
  27. * @sample stock/indicators/slow-stochastic
  28. * Slow Stochastic oscillator
  29. *
  30. * @extends plotOptions.stochastic
  31. * @since 8.0.0
  32. * @product highstock
  33. * @requires stock/indicators/indicators
  34. * @requires stock/indicators/stochastic
  35. * @requires stock/indicators/slowstochastic
  36. * @optionparent plotOptions.slowstochastic
  37. */
  38. {
  39. params: {
  40. /**
  41. * Periods for Slow Stochastic oscillator: [%K, %D, SMA(%D)].
  42. *
  43. * @type {Array<number,number,number>}
  44. * @default [14, 3, 3]
  45. */
  46. periods: [14, 3, 3]
  47. }
  48. },
  49. /**
  50. * @lends Highcharts.Series#
  51. */
  52. {
  53. nameBase: 'Slow Stochastic',
  54. init: function () {
  55. var args = arguments, ctx = this;
  56. requiredIndicator.isParentLoaded(H.seriesTypes.stochastic, 'stochastic', ctx.type, function (indicator) {
  57. indicator.prototype.init.apply(ctx, args);
  58. return;
  59. });
  60. },
  61. getValues: function (series, params) {
  62. var periods = params.periods, fastValues = seriesTypes.stochastic.prototype.getValues.call(this, series, params), slowValues = {
  63. values: [],
  64. xData: [],
  65. yData: []
  66. };
  67. var i = 0;
  68. if (!fastValues) {
  69. return;
  70. }
  71. slowValues.xData = fastValues.xData.slice(periods[1] - 1);
  72. var fastYData = fastValues.yData.slice(periods[1] - 1);
  73. // Get SMA(%D)
  74. var smoothedValues = seriesTypes.sma.prototype.getValues.call(this, {
  75. xData: slowValues.xData,
  76. yData: fastYData
  77. }, {
  78. index: 1,
  79. period: periods[2]
  80. });
  81. if (!smoothedValues) {
  82. return;
  83. }
  84. var xDataLen = slowValues.xData.length;
  85. // Format data
  86. for (; i < xDataLen; i++) {
  87. slowValues.yData[i] = [
  88. fastYData[i][1],
  89. smoothedValues.yData[i - periods[2] + 1] || null
  90. ];
  91. slowValues.values[i] = [
  92. slowValues.xData[i],
  93. fastYData[i][1],
  94. smoothedValues.yData[i - periods[2] + 1] || null
  95. ];
  96. }
  97. return slowValues;
  98. }
  99. });
  100. /**
  101. * A Slow Stochastic indicator. If the [type](#series.slowstochastic.type)
  102. * option is not specified, it is inherited from [chart.type](#chart.type).
  103. *
  104. * @extends series,plotOptions.slowstochastic
  105. * @since 8.0.0
  106. * @product highstock
  107. * @requires stock/indicators/indicators
  108. * @requires stock/indicators/stochastic
  109. * @requires stock/indicators/slowstochastic
  110. * @apioption series.slowstochastic
  111. */
  112. ''; // to include the above in the js output