trix.src.js 6.5 KB

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