momentum.src.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @license Highstock JS v8.0.0 (2019-12-10)
  3. *
  4. * Indicator series type for Highstock
  5. *
  6. * (c) 2010-2019 Sebastian Bochan
  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/momentum', ['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, 'indicators/momentum.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  32. /* *
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. *
  38. * */
  39. var isArray = U.isArray;
  40. var seriesType = H.seriesType;
  41. /* eslint-disable require-jsdoc */
  42. function populateAverage(points, xVal, yVal, i, period) {
  43. var mmY = yVal[i - 1][3] - yVal[i - period - 1][3], mmX = xVal[i - 1];
  44. points.shift(); // remove point until range < period
  45. return [mmX, mmY];
  46. }
  47. /* eslint-enable require-jsdoc */
  48. /**
  49. * The Momentum series type.
  50. *
  51. * @private
  52. * @class
  53. * @name Highcharts.seriesTypes.momentum
  54. *
  55. * @augments Highcharts.Series
  56. */
  57. seriesType('momentum', 'sma',
  58. /**
  59. * Momentum. This series requires `linkedTo` option to be set.
  60. *
  61. * @sample stock/indicators/momentum
  62. * Momentum indicator
  63. *
  64. * @extends plotOptions.sma
  65. * @since 6.0.0
  66. * @product highstock
  67. * @requires stock/indicators/indicators
  68. * @requires stock/indicators/momentum
  69. * @optionparent plotOptions.momentum
  70. */
  71. {
  72. params: {
  73. period: 14
  74. }
  75. },
  76. /**
  77. * @lends Highcharts.Series#
  78. */
  79. {
  80. nameBase: 'Momentum',
  81. getValues: function (series, params) {
  82. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, xValue = xVal[0], yValue = yVal[0], MM = [], xData = [], yData = [], index, i, points, MMPoint;
  83. if (xVal.length <= period) {
  84. return;
  85. }
  86. // Switch index for OHLC / Candlestick / Arearange
  87. if (isArray(yVal[0])) {
  88. yValue = yVal[0][3];
  89. }
  90. else {
  91. return;
  92. }
  93. // Starting point
  94. points = [
  95. [xValue, yValue]
  96. ];
  97. // Calculate value one-by-one for each period in visible data
  98. for (i = (period + 1); i < yValLen; i++) {
  99. MMPoint = populateAverage(points, xVal, yVal, i, period, index);
  100. MM.push(MMPoint);
  101. xData.push(MMPoint[0]);
  102. yData.push(MMPoint[1]);
  103. }
  104. MMPoint = populateAverage(points, xVal, yVal, i, period, index);
  105. MM.push(MMPoint);
  106. xData.push(MMPoint[0]);
  107. yData.push(MMPoint[1]);
  108. return {
  109. values: MM,
  110. xData: xData,
  111. yData: yData
  112. };
  113. }
  114. });
  115. /**
  116. * A `Momentum` series. If the [type](#series.momentum.type) option is not
  117. * specified, it is inherited from [chart.type](#chart.type).
  118. *
  119. * @extends series,plotOptions.momentum
  120. * @since 6.0.0
  121. * @excluding dataParser, dataURL
  122. * @product highstock
  123. * @requires stock/indicators/indicators
  124. * @requires stock/indicators/momentum
  125. * @apioption series.momentum
  126. */
  127. ''; // to include the above in the js output
  128. });
  129. _registerModule(_modules, 'masters/indicators/momentum.src.js', [], function () {
  130. });
  131. }));