momentum.src.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * @license Highstock JS v9.1.0 (2021-05-04)
  3. *
  4. * Indicator series type for Highcharts Stock
  5. *
  6. * (c) 2010-2021 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, 'Stock/Indicators/Momentum/MomentumIndicator.js', [_modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (SeriesRegistry, U) {
  32. /* *
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. *
  38. * */
  39. var __extends = (this && this.__extends) || (function () {
  40. var extendStatics = function (d,
  41. b) {
  42. extendStatics = Object.setPrototypeOf ||
  43. ({ __proto__: [] } instanceof Array && function (d,
  44. b) { d.__proto__ = b; }) ||
  45. function (d,
  46. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  47. return extendStatics(d, b);
  48. };
  49. return function (d, b) {
  50. extendStatics(d, b);
  51. function __() { this.constructor = d; }
  52. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  53. };
  54. })();
  55. var SMAIndicator = SeriesRegistry.seriesTypes.sma;
  56. var extend = U.extend,
  57. isArray = U.isArray,
  58. merge = U.merge;
  59. /* eslint-disable require-jsdoc */
  60. function populateAverage(xVal, yVal, i, period, index) {
  61. var mmY = yVal[i - 1][index] - yVal[i - period - 1][index],
  62. mmX = xVal[i - 1];
  63. return [mmX, mmY];
  64. }
  65. /* eslint-enable require-jsdoc */
  66. /**
  67. * The Momentum series type.
  68. *
  69. * @private
  70. * @class
  71. * @name Highcharts.seriesTypes.momentum
  72. *
  73. * @augments Highcharts.Series
  74. */
  75. var MomentumIndicator = /** @class */ (function (_super) {
  76. __extends(MomentumIndicator, _super);
  77. function MomentumIndicator() {
  78. var _this = _super !== null && _super.apply(this,
  79. arguments) || this;
  80. _this.data = void 0;
  81. _this.options = void 0;
  82. _this.points = void 0;
  83. return _this;
  84. }
  85. MomentumIndicator.prototype.getValues = function (series, params) {
  86. var period = params.period,
  87. index = params.index,
  88. xVal = series.xData,
  89. yVal = series.yData,
  90. yValLen = yVal ? yVal.length : 0,
  91. yValue = yVal[0],
  92. MM = [],
  93. xData = [],
  94. yData = [],
  95. i,
  96. MMPoint;
  97. if (xVal.length <= period) {
  98. return;
  99. }
  100. // Switch index for OHLC / Candlestick / Arearange
  101. if (isArray(yVal[0])) {
  102. yValue = yVal[0][index];
  103. }
  104. else {
  105. return;
  106. }
  107. // Calculate value one-by-one for each period in visible data
  108. for (i = (period + 1); i < yValLen; i++) {
  109. MMPoint = populateAverage(xVal, yVal, i, period, index);
  110. MM.push(MMPoint);
  111. xData.push(MMPoint[0]);
  112. yData.push(MMPoint[1]);
  113. }
  114. MMPoint = populateAverage(xVal, yVal, i, period, index);
  115. MM.push(MMPoint);
  116. xData.push(MMPoint[0]);
  117. yData.push(MMPoint[1]);
  118. return {
  119. values: MM,
  120. xData: xData,
  121. yData: yData
  122. };
  123. };
  124. /**
  125. * Momentum. This series requires `linkedTo` option to be set.
  126. *
  127. * @sample stock/indicators/momentum
  128. * Momentum indicator
  129. *
  130. * @extends plotOptions.sma
  131. * @since 6.0.0
  132. * @product highstock
  133. * @requires stock/indicators/indicators
  134. * @requires stock/indicators/momentum
  135. * @optionparent plotOptions.momentum
  136. */
  137. MomentumIndicator.defaultOptions = merge(SMAIndicator.defaultOptions, {
  138. params: {
  139. index: 3
  140. }
  141. });
  142. return MomentumIndicator;
  143. }(SMAIndicator));
  144. extend(MomentumIndicator.prototype, {
  145. nameBase: 'Momentum'
  146. });
  147. SeriesRegistry.registerSeriesType('momentum', MomentumIndicator);
  148. /* *
  149. *
  150. * Default Export
  151. *
  152. * */
  153. /**
  154. * A `Momentum` series. If the [type](#series.momentum.type) option is not
  155. * specified, it is inherited from [chart.type](#chart.type).
  156. *
  157. * @extends series,plotOptions.momentum
  158. * @since 6.0.0
  159. * @excluding dataParser, dataURL
  160. * @product highstock
  161. * @requires stock/indicators/indicators
  162. * @requires stock/indicators/momentum
  163. * @apioption series.momentum
  164. */
  165. ''; // to include the above in the js output
  166. return MomentumIndicator;
  167. });
  168. _registerModule(_modules, 'masters/indicators/momentum.src.js', [], function () {
  169. });
  170. }));