PCIndicator.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 U from '../../Core/Utilities.js';
  10. var merge = U.merge, seriesType = U.seriesType;
  11. import reduceArrayMixin from '../../Mixins/ReduceArray.js';
  12. import multipleLinesMixin from '../../Mixins/MultipleLines.js';
  13. var getArrayExtremes = reduceArrayMixin.getArrayExtremes;
  14. /**
  15. * The Price Channel series type.
  16. *
  17. * @private
  18. * @class
  19. * @name Highcharts.seriesTypes.pc
  20. *
  21. * @augments Highcharts.Series
  22. */
  23. seriesType('pc', 'sma',
  24. /**
  25. * Price channel (PC). This series requires the `linkedTo` option to be
  26. * set and should be loaded after the `stock/indicators/indicators.js`.
  27. *
  28. * @sample {highstock} stock/indicators/price-channel
  29. * Price Channel
  30. *
  31. * @extends plotOptions.sma
  32. * @since 7.0.0
  33. * @product highstock
  34. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  35. * navigatorOptions, pointInterval, pointIntervalUnit,
  36. * pointPlacement, pointRange, pointStart, showInNavigator,
  37. * stacking
  38. * @requires stock/indicators/indicators
  39. * @requires stock/indicators/price-channel
  40. * @optionparent plotOptions.pc
  41. */
  42. {
  43. /**
  44. * @excluding index
  45. */
  46. params: {
  47. period: 20
  48. },
  49. lineWidth: 1,
  50. topLine: {
  51. styles: {
  52. /**
  53. * Color of the top line. If not set, it's inherited from
  54. * [plotOptions.pc.color](#plotOptions.pc.color).
  55. *
  56. * @type {Highcharts.ColorString}
  57. */
  58. lineColor: '#7cb5ec #434348 #90ed7d #f7a35c #8085e9 #f15c80 #e4d354 #2b908f #f45b5b #91e8e1'.split(' ')[2],
  59. /**
  60. * Pixel width of the line.
  61. */
  62. lineWidth: 1
  63. }
  64. },
  65. bottomLine: {
  66. styles: {
  67. /**
  68. * Color of the bottom line. If not set, it's inherited from
  69. * [plotOptions.pc.color](#plotOptions.pc.color).
  70. *
  71. * @type {Highcharts.ColorString}
  72. */
  73. lineColor: '#7cb5ec #434348 #90ed7d #f7a35c #8085e9 #f15c80 #e4d354 #2b908f #f45b5b #91e8e1'.split(' ')[8],
  74. /**
  75. * Pixel width of the line.
  76. */
  77. lineWidth: 1
  78. }
  79. },
  80. dataGrouping: {
  81. approximation: 'averages'
  82. }
  83. },
  84. /**
  85. * @lends Highcharts.Series#
  86. */
  87. merge(multipleLinesMixin, {
  88. pointArrayMap: ['top', 'middle', 'bottom'],
  89. pointValKey: 'middle',
  90. nameBase: 'Price Channel',
  91. nameComponents: ['period'],
  92. linesApiNames: ['topLine', 'bottomLine'],
  93. getValues: function (series, params) {
  94. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0,
  95. // 0- date, 1-top line, 2-middle line, 3-bottom line
  96. PC = [],
  97. // middle line, top line and bottom line
  98. ML, TL, BL, date, low = 2, high = 1, xData = [], yData = [], slicedY, extremes, i;
  99. if (yValLen < period) {
  100. return;
  101. }
  102. for (i = period; i <= yValLen; i++) {
  103. date = xVal[i - 1];
  104. slicedY = yVal.slice(i - period, i);
  105. extremes = getArrayExtremes(slicedY, low, high);
  106. TL = extremes[1];
  107. BL = extremes[0];
  108. ML = (TL + BL) / 2;
  109. PC.push([date, TL, ML, BL]);
  110. xData.push(date);
  111. yData.push([TL, ML, BL]);
  112. }
  113. return {
  114. values: PC,
  115. xData: xData,
  116. yData: yData
  117. };
  118. }
  119. }));
  120. /**
  121. * A Price channel indicator. If the [type](#series.pc.type) option is not
  122. * specified, it is inherited from [chart.type](#chart.type).
  123. *
  124. * @extends series,plotOptions.pc
  125. * @since 7.0.0
  126. * @product highstock
  127. * @excluding allAreas, colorAxis, compare, compareBase, dataParser, dataURL,
  128. * joinBy, keys, navigatorOptions, pointInterval,
  129. * pointIntervalUnit, pointPlacement, pointRange, pointStart,
  130. * showInNavigator, stacking
  131. * @requires stock/indicators/indicators
  132. * @requires stock/indicators/price-channel
  133. * @apioption series.pc
  134. */
  135. ''; // to include the above in the js output