aroon.src.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* *
  2. *
  3. * License: www.highcharts.com/license
  4. *
  5. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6. *
  7. * */
  8. 'use strict';
  9. import H from '../parts/Globals.js';
  10. import U from '../parts/Utilities.js';
  11. var pick = U.pick;
  12. import multipleLinesMixin from '../mixins/multipe-lines.js';
  13. /* eslint-disable valid-jsdoc */
  14. // Utils
  15. // Index of element with extreme value from array (min or max)
  16. /**
  17. * @private
  18. */
  19. function getExtremeIndexInArray(arr, extreme) {
  20. var extremeValue = arr[0], valueIndex = 0, i;
  21. for (i = 1; i < arr.length; i++) {
  22. if (extreme === 'max' && arr[i] >= extremeValue ||
  23. extreme === 'min' && arr[i] <= extremeValue) {
  24. extremeValue = arr[i];
  25. valueIndex = i;
  26. }
  27. }
  28. return valueIndex;
  29. }
  30. /* eslint-enable valid-jsdoc */
  31. /**
  32. * The Aroon series type.
  33. *
  34. * @private
  35. * @class
  36. * @name Highcharts.seriesTypes.aroon
  37. *
  38. * @augments Highcharts.Series
  39. */
  40. H.seriesType('aroon', 'sma',
  41. /**
  42. * Aroon. This series requires the `linkedTo` option to be
  43. * set and should be loaded after the `stock/indicators/indicators.js`.
  44. *
  45. * @sample {highstock} stock/indicators/aroon
  46. * Aroon
  47. *
  48. * @extends plotOptions.sma
  49. * @since 7.0.0
  50. * @product highstock
  51. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  52. * navigatorOptions, pointInterval, pointIntervalUnit,
  53. * pointPlacement, pointRange, pointStart, showInNavigator,
  54. * stacking
  55. * @requires stock/indicators/indicators
  56. * @requires stock/indicators/aroon
  57. * @optionparent plotOptions.aroon
  58. */
  59. {
  60. /**
  61. * Paramters used in calculation of aroon series points.
  62. *
  63. * @excluding periods, index
  64. */
  65. params: {
  66. /**
  67. * Period for Aroon indicator
  68. */
  69. period: 25
  70. },
  71. marker: {
  72. enabled: false
  73. },
  74. tooltip: {
  75. pointFormat: '<span style="color:{point.color}">\u25CF</span><b> {series.name}</b><br/>Aroon Up: {point.y}<br/>Aroon Down: {point.aroonDown}<br/>'
  76. },
  77. /**
  78. * aroonDown line options.
  79. */
  80. aroonDown: {
  81. /**
  82. * Styles for an aroonDown line.
  83. */
  84. styles: {
  85. /**
  86. * Pixel width of the line.
  87. */
  88. lineWidth: 1,
  89. /**
  90. * Color of the line. If not set, it's inherited from
  91. * [plotOptions.aroon.color](#plotOptions.aroon.color).
  92. *
  93. * @type {Highcharts.ColorString}
  94. */
  95. lineColor: void 0
  96. }
  97. },
  98. dataGrouping: {
  99. approximation: 'averages'
  100. }
  101. },
  102. /**
  103. * @lends Highcharts.Series#
  104. */
  105. H.merge(multipleLinesMixin, {
  106. nameBase: 'Aroon',
  107. pointArrayMap: ['y', 'aroonDown'],
  108. pointValKey: 'y',
  109. linesApiNames: ['aroonDown'],
  110. getValues: function (series, params) {
  111. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  112. // 0- date, 1- Aroon Up, 2- Aroon Down
  113. AR = [], xData = [], yData = [], slicedY, low = 2, high = 1, aroonUp, aroonDown, xLow, xHigh, i;
  114. // For a N-period, we start from N-1 point, to calculate Nth point
  115. // That is why we later need to comprehend slice() elements list
  116. // with (+1)
  117. for (i = period - 1; i < yValLen; i++) {
  118. slicedY = yVal.slice(i - period + 1, i + 2);
  119. xLow = getExtremeIndexInArray(slicedY.map(function (elem) {
  120. return pick(elem[low], elem);
  121. }), 'min');
  122. xHigh = getExtremeIndexInArray(slicedY.map(function (elem) {
  123. return pick(elem[high], elem);
  124. }), 'max');
  125. aroonUp = (xHigh / period) * 100;
  126. aroonDown = (xLow / period) * 100;
  127. if (xVal[i + 1]) {
  128. AR.push([xVal[i + 1], aroonUp, aroonDown]);
  129. xData.push(xVal[i + 1]);
  130. yData.push([aroonUp, aroonDown]);
  131. }
  132. }
  133. return {
  134. values: AR,
  135. xData: xData,
  136. yData: yData
  137. };
  138. }
  139. }));
  140. /**
  141. * A Aroon indicator. If the [type](#series.aroon.type) option is not
  142. * specified, it is inherited from [chart.type](#chart.type).
  143. *
  144. * @extends series,plotOptions.aroon
  145. * @since 7.0.0
  146. * @product highstock
  147. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  148. * joinBy, keys, navigatorOptions, pointInterval, pointIntervalUnit,
  149. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  150. * @requires stock/indicators/indicators
  151. * @requires stock/indicators/aroon
  152. * @apioption series.aroon
  153. */
  154. ''; // to avoid removal of the above jsdoc