aroon-oscillator.src.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /**
  2. * @license Highstock JS v8.1.2 (2020-06-16)
  3. *
  4. * Indicator series type for Highstock
  5. *
  6. * (c) 2010-2019 Wojciech Chmiel
  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/aroon-oscillator', ['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/multipe-lines.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  32. /**
  33. *
  34. * (c) 2010-2020 Wojciech Chmiel
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. var defined = U.defined, error = U.error, merge = U.merge;
  42. var SMA = H.seriesTypes.sma;
  43. /**
  44. * Mixin useful for all indicators that have more than one line.
  45. * Merge it with your implementation where you will provide
  46. * getValues method appropriate to your indicator and pointArrayMap,
  47. * pointValKey, linesApiNames properites. Notice that pointArrayMap
  48. * should be consistent with amount of lines calculated in getValues method.
  49. *
  50. * @private
  51. * @mixin multipleLinesMixin
  52. */
  53. var multipleLinesMixin = {
  54. /* eslint-disable valid-jsdoc */
  55. /**
  56. * Lines ids. Required to plot appropriate amount of lines.
  57. * Notice that pointArrayMap should have more elements than
  58. * linesApiNames, because it contains main line and additional lines ids.
  59. * Also it should be consistent with amount of lines calculated in
  60. * getValues method from your implementation.
  61. *
  62. * @private
  63. * @name multipleLinesMixin.pointArrayMap
  64. * @type {Array<string>}
  65. */
  66. pointArrayMap: ['top', 'bottom'],
  67. /**
  68. * Main line id.
  69. *
  70. * @private
  71. * @name multipleLinesMixin.pointValKey
  72. * @type {string}
  73. */
  74. pointValKey: 'top',
  75. /**
  76. * Additional lines DOCS names. Elements of linesApiNames array should
  77. * be consistent with DOCS line names defined in your implementation.
  78. * Notice that linesApiNames should have decreased amount of elements
  79. * relative to pointArrayMap (without pointValKey).
  80. *
  81. * @private
  82. * @name multipleLinesMixin.linesApiNames
  83. * @type {Array<string>}
  84. */
  85. linesApiNames: ['bottomLine'],
  86. /**
  87. * Create translatedLines Collection based on pointArrayMap.
  88. *
  89. * @private
  90. * @function multipleLinesMixin.getTranslatedLinesNames
  91. * @param {string} [excludedValue]
  92. * Main line id
  93. * @return {Array<string>}
  94. * Returns translated lines names without excluded value.
  95. */
  96. getTranslatedLinesNames: function (excludedValue) {
  97. var translatedLines = [];
  98. (this.pointArrayMap || []).forEach(function (propertyName) {
  99. if (propertyName !== excludedValue) {
  100. translatedLines.push('plot' +
  101. propertyName.charAt(0).toUpperCase() +
  102. propertyName.slice(1));
  103. }
  104. });
  105. return translatedLines;
  106. },
  107. /**
  108. * @private
  109. * @function multipleLinesMixin.toYData
  110. * @param {Highcharts.Point} point
  111. * Indicator point
  112. * @return {Array<number>}
  113. * Returns point Y value for all lines
  114. */
  115. toYData: function (point) {
  116. var pointColl = [];
  117. (this.pointArrayMap || []).forEach(function (propertyName) {
  118. pointColl.push(point[propertyName]);
  119. });
  120. return pointColl;
  121. },
  122. /**
  123. * Add lines plot pixel values.
  124. *
  125. * @private
  126. * @function multipleLinesMixin.translate
  127. * @return {void}
  128. */
  129. translate: function () {
  130. var indicator = this, pointArrayMap = indicator.pointArrayMap, LinesNames = [], value;
  131. LinesNames = indicator.getTranslatedLinesNames();
  132. SMA.prototype.translate.apply(indicator, arguments);
  133. indicator.points.forEach(function (point) {
  134. pointArrayMap.forEach(function (propertyName, i) {
  135. value = point[propertyName];
  136. if (value !== null) {
  137. point[LinesNames[i]] = indicator.yAxis.toPixels(value, true);
  138. }
  139. });
  140. });
  141. },
  142. /**
  143. * Draw main and additional lines.
  144. *
  145. * @private
  146. * @function multipleLinesMixin.drawGraph
  147. * @return {void}
  148. */
  149. drawGraph: function () {
  150. var indicator = this, pointValKey = indicator.pointValKey, linesApiNames = indicator.linesApiNames, mainLinePoints = indicator.points, pointsLength = mainLinePoints.length, mainLineOptions = indicator.options, mainLinePath = indicator.graph, gappedExtend = {
  151. options: {
  152. gapSize: mainLineOptions.gapSize
  153. }
  154. },
  155. // additional lines point place holders:
  156. secondaryLines = [], secondaryLinesNames = indicator.getTranslatedLinesNames(pointValKey), point;
  157. // Generate points for additional lines:
  158. secondaryLinesNames.forEach(function (plotLine, index) {
  159. // create additional lines point place holders
  160. secondaryLines[index] = [];
  161. while (pointsLength--) {
  162. point = mainLinePoints[pointsLength];
  163. secondaryLines[index].push({
  164. x: point.x,
  165. plotX: point.plotX,
  166. plotY: point[plotLine],
  167. isNull: !defined(point[plotLine])
  168. });
  169. }
  170. pointsLength = mainLinePoints.length;
  171. });
  172. // Modify options and generate additional lines:
  173. linesApiNames.forEach(function (lineName, i) {
  174. if (secondaryLines[i]) {
  175. indicator.points = secondaryLines[i];
  176. if (mainLineOptions[lineName]) {
  177. indicator.options = merge(mainLineOptions[lineName].styles, gappedExtend);
  178. }
  179. else {
  180. error('Error: "There is no ' + lineName +
  181. ' in DOCS options declared. Check if linesApiNames' +
  182. ' are consistent with your DOCS line names."' +
  183. ' at mixin/multiple-line.js:34');
  184. }
  185. indicator.graph = indicator['graph' + lineName];
  186. SMA.prototype.drawGraph.call(indicator);
  187. // Now save lines:
  188. indicator['graph' + lineName] = indicator.graph;
  189. }
  190. else {
  191. error('Error: "' + lineName + ' doesn\'t have equivalent ' +
  192. 'in pointArrayMap. To many elements in linesApiNames ' +
  193. 'relative to pointArrayMap."');
  194. }
  195. });
  196. // Restore options and draw a main line:
  197. indicator.points = mainLinePoints;
  198. indicator.options = mainLineOptions;
  199. indicator.graph = mainLinePath;
  200. SMA.prototype.drawGraph.call(indicator);
  201. }
  202. };
  203. return multipleLinesMixin;
  204. });
  205. _registerModule(_modules, 'mixins/indicator-required.js', [_modules['parts/Utilities.js']], function (U) {
  206. /**
  207. *
  208. * (c) 2010-2020 Daniel Studencki
  209. *
  210. * License: www.highcharts.com/license
  211. *
  212. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  213. *
  214. * */
  215. var error = U.error;
  216. /* eslint-disable no-invalid-this, valid-jsdoc */
  217. var requiredIndicatorMixin = {
  218. /**
  219. * Check whether given indicator is loaded, else throw error.
  220. * @private
  221. * @param {Highcharts.Indicator} indicator
  222. * Indicator constructor function.
  223. * @param {string} requiredIndicator
  224. * Required indicator type.
  225. * @param {string} type
  226. * Type of indicator where function was called (parent).
  227. * @param {Highcharts.IndicatorCallbackFunction} callback
  228. * Callback which is triggered if the given indicator is loaded.
  229. * Takes indicator as an argument.
  230. * @param {string} errMessage
  231. * Error message that will be logged in console.
  232. * @return {boolean}
  233. * Returns false when there is no required indicator loaded.
  234. */
  235. isParentLoaded: function (indicator, requiredIndicator, type, callback, errMessage) {
  236. if (indicator) {
  237. return callback ? callback(indicator) : true;
  238. }
  239. error(errMessage || this.generateMessage(type, requiredIndicator));
  240. return false;
  241. },
  242. /**
  243. * @private
  244. * @param {string} indicatorType
  245. * Indicator type
  246. * @param {string} required
  247. * Required indicator
  248. * @return {string}
  249. * Error message
  250. */
  251. generateMessage: function (indicatorType, required) {
  252. return 'Error: "' + indicatorType +
  253. '" indicator type requires "' + required +
  254. '" indicator loaded before. Please read docs: ' +
  255. 'https://api.highcharts.com/highstock/plotOptions.' +
  256. indicatorType;
  257. }
  258. };
  259. return requiredIndicatorMixin;
  260. });
  261. _registerModule(_modules, 'indicators/aroon-oscillator.src.js', [_modules['parts/Globals.js'], _modules['mixins/multipe-lines.js'], _modules['mixins/indicator-required.js'], _modules['parts/Utilities.js']], function (H, multipleLinesMixin, requiredIndicatorMixin, U) {
  262. /* *
  263. *
  264. * License: www.highcharts.com/license
  265. *
  266. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  267. *
  268. * */
  269. var merge = U.merge, seriesType = U.seriesType;
  270. var AROON = H.seriesTypes.aroon, requiredIndicator = requiredIndicatorMixin;
  271. /**
  272. * The Aroon Oscillator series type.
  273. *
  274. * @private
  275. * @class
  276. * @name Highcharts.seriesTypes.aroonoscillator
  277. *
  278. * @augments Highcharts.Series
  279. */
  280. seriesType('aroonoscillator', 'aroon',
  281. /**
  282. * Aroon Oscillator. This series requires the `linkedTo` option to be set
  283. * and should be loaded after the `stock/indicators/indicators.js` and
  284. * `stock/indicators/aroon.js`.
  285. *
  286. * @sample {highstock} stock/indicators/aroon-oscillator
  287. * Aroon Oscillator
  288. *
  289. * @extends plotOptions.aroon
  290. * @since 7.0.0
  291. * @product highstock
  292. * @excluding allAreas, aroonDown, colorAxis, compare, compareBase,
  293. * joinBy, keys, navigatorOptions, pointInterval,
  294. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  295. * showInNavigator, stacking
  296. * @requires stock/indicators/indicators
  297. * @requires stock/indicators/aroon
  298. * @requires stock/indicators/aroon-oscillator
  299. * @optionparent plotOptions.aroonoscillator
  300. */
  301. {
  302. /**
  303. * Paramters used in calculation of aroon oscillator series points.
  304. *
  305. * @excluding periods, index
  306. */
  307. params: {
  308. /**
  309. * Period for Aroon Oscillator
  310. *
  311. * @since 7.0.0
  312. * @product highstock
  313. */
  314. period: 25
  315. },
  316. tooltip: {
  317. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b>: {point.y}'
  318. }
  319. },
  320. /**
  321. * @lends Highcharts.Series#
  322. */
  323. merge(multipleLinesMixin, {
  324. nameBase: 'Aroon Oscillator',
  325. pointArrayMap: ['y'],
  326. pointValKey: 'y',
  327. linesApiNames: [],
  328. init: function () {
  329. var args = arguments, ctx = this;
  330. requiredIndicator.isParentLoaded(AROON, 'aroon', ctx.type, function (indicator) {
  331. indicator.prototype.init.apply(ctx, args);
  332. return;
  333. });
  334. },
  335. getValues: function (series, params) {
  336. // 0- date, 1- Aroon Oscillator
  337. var ARO = [], xData = [], yData = [], aroon, aroonUp, aroonDown, oscillator, i;
  338. aroon = AROON.prototype.getValues.call(this, series, params);
  339. for (i = 0; i < aroon.yData.length; i++) {
  340. aroonUp = aroon.yData[i][0];
  341. aroonDown = aroon.yData[i][1];
  342. oscillator = aroonUp - aroonDown;
  343. ARO.push([aroon.xData[i], oscillator]);
  344. xData.push(aroon.xData[i]);
  345. yData.push(oscillator);
  346. }
  347. return {
  348. values: ARO,
  349. xData: xData,
  350. yData: yData
  351. };
  352. }
  353. }));
  354. /**
  355. * An `Aroon Oscillator` series. If the [type](#series.aroonoscillator.type)
  356. * option is not specified, it is inherited from [chart.type](#chart.type).
  357. *
  358. * @extends series,plotOptions.aroonoscillator
  359. * @since 7.0.0
  360. * @product highstock
  361. * @excluding allAreas, aroonDown, colorAxis, compare, compareBase, dataParser,
  362. * dataURL, joinBy, keys, navigatorOptions, pointInterval,
  363. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  364. * showInNavigator, stacking
  365. * @requires stock/indicators/indicators
  366. * @requires stock/indicators/aroon
  367. * @requires stock/indicators/aroon-oscillator
  368. * @apioption series.aroonoscillator
  369. */
  370. ''; // adds doclet above to the transpiled file
  371. });
  372. _registerModule(_modules, 'masters/indicators/aroon-oscillator.src.js', [], function () {
  373. });
  374. }));