trix.src.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * @license Highstock JS v8.2.0 (2020-08-20)
  3. *
  4. * Indicator series type for Highstock
  5. *
  6. * (c) 2010-2019 Rafal Sebestjanski
  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/trix', ['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, 'Mixins/IndicatorRequired.js', [_modules['Core/Utilities.js']], function (U) {
  32. /**
  33. *
  34. * (c) 2010-2020 Daniel Studencki
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. var error = U.error;
  42. /* eslint-disable no-invalid-this, valid-jsdoc */
  43. var requiredIndicatorMixin = {
  44. /**
  45. * Check whether given indicator is loaded,
  46. else throw error.
  47. * @private
  48. * @param {Highcharts.Indicator} indicator
  49. * Indicator constructor function.
  50. * @param {string} requiredIndicator
  51. * Required indicator type.
  52. * @param {string} type
  53. * Type of indicator where function was called (parent).
  54. * @param {Highcharts.IndicatorCallbackFunction} callback
  55. * Callback which is triggered if the given indicator is loaded.
  56. * Takes indicator as an argument.
  57. * @param {string} errMessage
  58. * Error message that will be logged in console.
  59. * @return {boolean}
  60. * Returns false when there is no required indicator loaded.
  61. */
  62. isParentLoaded: function (indicator,
  63. requiredIndicator,
  64. type,
  65. callback,
  66. errMessage) {
  67. if (indicator) {
  68. return callback ? callback(indicator) : true;
  69. }
  70. error(errMessage || this.generateMessage(type, requiredIndicator));
  71. return false;
  72. },
  73. /**
  74. * @private
  75. * @param {string} indicatorType
  76. * Indicator type
  77. * @param {string} required
  78. * Required indicator
  79. * @return {string}
  80. * Error message
  81. */
  82. generateMessage: function (indicatorType, required) {
  83. return 'Error: "' + indicatorType +
  84. '" indicator type requires "' + required +
  85. '" indicator loaded before. Please read docs: ' +
  86. 'https://api.highcharts.com/highstock/plotOptions.' +
  87. indicatorType;
  88. }
  89. };
  90. return requiredIndicatorMixin;
  91. });
  92. _registerModule(_modules, 'Stock/Indicators/TRIXIndicator.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js'], _modules['Mixins/IndicatorRequired.js']], function (H, U, requiredIndicator) {
  93. /* *
  94. *
  95. * License: www.highcharts.com/license
  96. *
  97. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  98. *
  99. * */
  100. var correctFloat = U.correctFloat,
  101. seriesType = U.seriesType;
  102. var TEMA = H.seriesTypes.tema;
  103. /**
  104. * The TRIX series type.
  105. *
  106. * @private
  107. * @class
  108. * @name Highcharts.seriesTypes.trix
  109. *
  110. * @augments Highcharts.Series
  111. */
  112. seriesType('trix', 'tema',
  113. /**
  114. * Triple exponential average (TRIX) oscillator. This series requires
  115. * `linkedTo` option to be set.
  116. *
  117. * Requires https://code.highcharts.com/stock/indicators/ema.js
  118. * and https://code.highcharts.com/stock/indicators/tema.js.
  119. *
  120. * @sample {highstock} stock/indicators/trix
  121. * TRIX indicator
  122. *
  123. * @extends plotOptions.tema
  124. * @since 7.0.0
  125. * @product highstock
  126. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  127. * navigatorOptions, pointInterval, pointIntervalUnit,
  128. * pointPlacement, pointRange, pointStart, showInNavigator,
  129. * stacking
  130. * @optionparent plotOptions.trix
  131. */
  132. {},
  133. /**
  134. * @lends Highcharts.Series#
  135. */
  136. {
  137. init: function () {
  138. var args = arguments,
  139. ctx = this;
  140. requiredIndicator.isParentLoaded(TEMA, 'tema', ctx.type, function (indicator) {
  141. indicator.prototype.init.apply(ctx, args);
  142. return;
  143. });
  144. },
  145. // TRIX is calculated using TEMA so we just extend getTemaPoint method.
  146. getTemaPoint: function (xVal, tripledPeriod, EMAlevels, i) {
  147. if (i > tripledPeriod) {
  148. var TRIXPoint = [
  149. xVal[i - 3],
  150. EMAlevels.prevLevel3 !== 0 ?
  151. correctFloat(EMAlevels.level3 - EMAlevels.prevLevel3) /
  152. EMAlevels.prevLevel3 * 100 : null
  153. ];
  154. }
  155. return TRIXPoint;
  156. }
  157. });
  158. /**
  159. * A `TRIX` series. If the [type](#series.tema.type) option is not specified, it
  160. * is inherited from [chart.type](#chart.type).
  161. *
  162. * @extends series,plotOptions.tema
  163. * @since 7.0.0
  164. * @product highstock
  165. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  166. * joinBy, keys, navigatorOptions, pointInterval, pointIntervalUnit,
  167. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  168. * @apioption series.trix
  169. */
  170. ''; // to include the above in the js output
  171. });
  172. _registerModule(_modules, 'masters/indicators/trix.src.js', [], function () {
  173. });
  174. }));