momentum.src.js 4.5 KB

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