aroon.src.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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', ['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, 'indicators/aroon.src.js', [_modules['parts/Utilities.js'], _modules['mixins/multipe-lines.js']], function (U, multipleLinesMixin) {
  206. /* *
  207. *
  208. * License: www.highcharts.com/license
  209. *
  210. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  211. *
  212. * */
  213. var merge = U.merge, pick = U.pick, seriesType = U.seriesType;
  214. /* eslint-disable valid-jsdoc */
  215. // Utils
  216. // Index of element with extreme value from array (min or max)
  217. /**
  218. * @private
  219. */
  220. function getExtremeIndexInArray(arr, extreme) {
  221. var extremeValue = arr[0], valueIndex = 0, i;
  222. for (i = 1; i < arr.length; i++) {
  223. if (extreme === 'max' && arr[i] >= extremeValue ||
  224. extreme === 'min' && arr[i] <= extremeValue) {
  225. extremeValue = arr[i];
  226. valueIndex = i;
  227. }
  228. }
  229. return valueIndex;
  230. }
  231. /* eslint-enable valid-jsdoc */
  232. /**
  233. * The Aroon series type.
  234. *
  235. * @private
  236. * @class
  237. * @name Highcharts.seriesTypes.aroon
  238. *
  239. * @augments Highcharts.Series
  240. */
  241. seriesType('aroon', 'sma',
  242. /**
  243. * Aroon. This series requires the `linkedTo` option to be
  244. * set and should be loaded after the `stock/indicators/indicators.js`.
  245. *
  246. * @sample {highstock} stock/indicators/aroon
  247. * Aroon
  248. *
  249. * @extends plotOptions.sma
  250. * @since 7.0.0
  251. * @product highstock
  252. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  253. * navigatorOptions, pointInterval, pointIntervalUnit,
  254. * pointPlacement, pointRange, pointStart, showInNavigator,
  255. * stacking
  256. * @requires stock/indicators/indicators
  257. * @requires stock/indicators/aroon
  258. * @optionparent plotOptions.aroon
  259. */
  260. {
  261. /**
  262. * Paramters used in calculation of aroon series points.
  263. *
  264. * @excluding periods, index
  265. */
  266. params: {
  267. /**
  268. * Period for Aroon indicator
  269. */
  270. period: 25
  271. },
  272. marker: {
  273. enabled: false
  274. },
  275. tooltip: {
  276. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b><br/>Aroon Up: {point.y}<br/>Aroon Down: {point.aroonDown}<br/>'
  277. },
  278. /**
  279. * aroonDown line options.
  280. */
  281. aroonDown: {
  282. /**
  283. * Styles for an aroonDown line.
  284. */
  285. styles: {
  286. /**
  287. * Pixel width of the line.
  288. */
  289. lineWidth: 1,
  290. /**
  291. * Color of the line. If not set, it's inherited from
  292. * [plotOptions.aroon.color](#plotOptions.aroon.color).
  293. *
  294. * @type {Highcharts.ColorString}
  295. */
  296. lineColor: void 0
  297. }
  298. },
  299. dataGrouping: {
  300. approximation: 'averages'
  301. }
  302. },
  303. /**
  304. * @lends Highcharts.Series#
  305. */
  306. merge(multipleLinesMixin, {
  307. nameBase: 'Aroon',
  308. pointArrayMap: ['y', 'aroonDown'],
  309. pointValKey: 'y',
  310. linesApiNames: ['aroonDown'],
  311. getValues: function (series, params) {
  312. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  313. // 0- date, 1- Aroon Up, 2- Aroon Down
  314. AR = [], xData = [], yData = [], slicedY, low = 2, high = 1, aroonUp, aroonDown, xLow, xHigh, i;
  315. // For a N-period, we start from N-1 point, to calculate Nth point
  316. // That is why we later need to comprehend slice() elements list
  317. // with (+1)
  318. for (i = period - 1; i < yValLen; i++) {
  319. slicedY = yVal.slice(i - period + 1, i + 2);
  320. xLow = getExtremeIndexInArray(slicedY.map(function (elem) {
  321. return pick(elem[low], elem);
  322. }), 'min');
  323. xHigh = getExtremeIndexInArray(slicedY.map(function (elem) {
  324. return pick(elem[high], elem);
  325. }), 'max');
  326. aroonUp = (xHigh / period) * 100;
  327. aroonDown = (xLow / period) * 100;
  328. if (xVal[i + 1]) {
  329. AR.push([xVal[i + 1], aroonUp, aroonDown]);
  330. xData.push(xVal[i + 1]);
  331. yData.push([aroonUp, aroonDown]);
  332. }
  333. }
  334. return {
  335. values: AR,
  336. xData: xData,
  337. yData: yData
  338. };
  339. }
  340. }));
  341. /**
  342. * A Aroon indicator. If the [type](#series.aroon.type) option is not
  343. * specified, it is inherited from [chart.type](#chart.type).
  344. *
  345. * @extends series,plotOptions.aroon
  346. * @since 7.0.0
  347. * @product highstock
  348. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  349. * joinBy, keys, navigatorOptions, pointInterval, pointIntervalUnit,
  350. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  351. * @requires stock/indicators/indicators
  352. * @requires stock/indicators/aroon
  353. * @apioption series.aroon
  354. */
  355. ''; // to avoid removal of the above jsdoc
  356. });
  357. _registerModule(_modules, 'masters/indicators/aroon.src.js', [], function () {
  358. });
  359. }));