momentum.src.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * @license Highstock JS v9.0.1 (2021-02-16)
  3. *
  4. * Indicator series type for Highstock
  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(points, xVal, yVal, i, period) {
  61. var mmY = yVal[i - 1][3] - yVal[i - period - 1][3],
  62. mmX = xVal[i - 1];
  63. points.shift(); // remove point until range < period
  64. return [mmX, mmY];
  65. }
  66. /* eslint-enable require-jsdoc */
  67. /**
  68. * The Momentum series type.
  69. *
  70. * @private
  71. * @class
  72. * @name Highcharts.seriesTypes.momentum
  73. *
  74. * @augments Highcharts.Series
  75. */
  76. var MomentumIndicator = /** @class */ (function (_super) {
  77. __extends(MomentumIndicator, _super);
  78. function MomentumIndicator() {
  79. var _this = _super !== null && _super.apply(this,
  80. arguments) || this;
  81. _this.data = void 0;
  82. _this.options = void 0;
  83. _this.points = void 0;
  84. return _this;
  85. }
  86. MomentumIndicator.prototype.getValues = function (series, params) {
  87. var period = params.period,
  88. xVal = series.xData,
  89. yVal = series.yData,
  90. yValLen = yVal ? yVal.length : 0,
  91. xValue = xVal[0],
  92. yValue = yVal[0],
  93. MM = [],
  94. xData = [],
  95. yData = [],
  96. index,
  97. i,
  98. points,
  99. MMPoint;
  100. if (xVal.length <= period) {
  101. return;
  102. }
  103. // Switch index for OHLC / Candlestick / Arearange
  104. if (isArray(yVal[0])) {
  105. yValue = yVal[0][3];
  106. }
  107. else {
  108. return;
  109. }
  110. // Starting point
  111. points = [
  112. [xValue, yValue]
  113. ];
  114. // Calculate value one-by-one for each period in visible data
  115. for (i = (period + 1); i < yValLen; i++) {
  116. MMPoint = populateAverage(points, xVal, yVal, i, period, index);
  117. MM.push(MMPoint);
  118. xData.push(MMPoint[0]);
  119. yData.push(MMPoint[1]);
  120. }
  121. MMPoint = populateAverage(points, xVal, yVal, i, period, index);
  122. MM.push(MMPoint);
  123. xData.push(MMPoint[0]);
  124. yData.push(MMPoint[1]);
  125. return {
  126. values: MM,
  127. xData: xData,
  128. yData: yData
  129. };
  130. };
  131. /**
  132. * Momentum. This series requires `linkedTo` option to be set.
  133. *
  134. * @sample stock/indicators/momentum
  135. * Momentum indicator
  136. *
  137. * @extends plotOptions.sma
  138. * @since 6.0.0
  139. * @product highstock
  140. * @requires stock/indicators/indicators
  141. * @requires stock/indicators/momentum
  142. * @optionparent plotOptions.momentum
  143. */
  144. MomentumIndicator.defaultOptions = merge(SMAIndicator.defaultOptions, {
  145. params: {
  146. period: 14
  147. }
  148. });
  149. return MomentumIndicator;
  150. }(SMAIndicator));
  151. extend(MomentumIndicator.prototype, {
  152. nameBase: 'Momentum'
  153. });
  154. SeriesRegistry.registerSeriesType('momentum', MomentumIndicator);
  155. /* *
  156. *
  157. * Default Export
  158. *
  159. * */
  160. /**
  161. * A `Momentum` series. If the [type](#series.momentum.type) option is not
  162. * specified, it is inherited from [chart.type](#chart.type).
  163. *
  164. * @extends series,plotOptions.momentum
  165. * @since 6.0.0
  166. * @excluding dataParser, dataURL
  167. * @product highstock
  168. * @requires stock/indicators/indicators
  169. * @requires stock/indicators/momentum
  170. * @apioption series.momentum
  171. */
  172. ''; // to include the above in the js output
  173. return MomentumIndicator;
  174. });
  175. _registerModule(_modules, 'masters/indicators/momentum.src.js', [], function () {
  176. });
  177. }));