price-indicator.src.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * @license Highcharts JS v7.0.2 (2019-01-17)
  3. * Advanced Highstock tools
  4. *
  5. * (c) 2010-2019 Highsoft AS
  6. * Author: Torstein Honsi
  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(function () {
  17. return factory;
  18. });
  19. } else {
  20. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  21. }
  22. }(function (Highcharts) {
  23. (function (H) {
  24. /**
  25. * (c) 2009-2019 Sebastian Bochann
  26. *
  27. * Price indicator for Highcharts
  28. *
  29. * License: www.highcharts.com/license
  30. */
  31. var addEvent = H.addEvent,
  32. merge = H.merge,
  33. isArray = H.isArray;
  34. /**
  35. * The line marks the last price from visible range of points.
  36. *
  37. * @product highstock
  38. * @sample {highstock} stock/indicators/last-visible-price
  39. * Last visible price
  40. * @apioption plotOptions.series.lastVisiblePrice
  41. */
  42. /**
  43. * Enable or disable the indicator.
  44. *
  45. * @type {boolean}
  46. * @product highstock
  47. * @default true
  48. * @apioption plotOptions.series.lastVisiblePrice.enabled
  49. */
  50. /**
  51. * Enable or disable the label.
  52. *
  53. * @type {boolean}
  54. * @product highstock
  55. * @default true
  56. * @apioption plotOptions.series.lastVisiblePrice.label.enabled
  57. *
  58. */
  59. /**
  60. * The line marks the last price from all points.
  61. *
  62. * @product highstock
  63. * @sample {highstock} stock/indicators/last-price
  64. * Last price
  65. * @apioption plotOptions.series.lastPrice
  66. */
  67. /**
  68. * Enable or disable the indicator.
  69. *
  70. * @type {boolean}
  71. * @product highstock
  72. * @default true
  73. * @apioption plotOptions.series.lastPrice.enabled
  74. */
  75. /**
  76. * The color of the line of last price.
  77. *
  78. * @type {string}
  79. * @product highstock
  80. * @default red
  81. * @apioption plotOptions.series.lastPrice.color
  82. *
  83. */
  84. addEvent(H.Series, 'afterRender', function () {
  85. var serie = this,
  86. seriesOptions = serie.options,
  87. lastVisiblePrice = seriesOptions.lastVisiblePrice,
  88. lastPrice = seriesOptions.lastPrice;
  89. if ((lastVisiblePrice || lastPrice) &&
  90. seriesOptions.id !== 'highcharts-navigator-series') {
  91. var xAxis = serie.xAxis,
  92. yAxis = serie.yAxis,
  93. origOptions = yAxis.crosshair,
  94. origGraphic = yAxis.cross,
  95. origLabel = yAxis.crossLabel,
  96. points = serie.points,
  97. x = serie.xData[serie.xData.length - 1],
  98. y = serie.yData[serie.yData.length - 1],
  99. lastPoint,
  100. yValue,
  101. crop;
  102. if (lastPrice && lastPrice.enabled) {
  103. yAxis.crosshair = yAxis.options.crosshair = seriesOptions.lastPrice;
  104. yAxis.cross = serie.lastPrice;
  105. yValue = isArray(y) ? y[3] : y;
  106. yAxis.drawCrosshair(null, {
  107. x: x,
  108. y: yValue,
  109. plotX: xAxis.toPixels(x, true),
  110. plotY: yAxis.toPixels(yValue, true)
  111. });
  112. // Save price
  113. serie.lastPrice = serie.yAxis.cross;
  114. serie.lastPrice.y = yValue;
  115. }
  116. if (lastVisiblePrice && lastVisiblePrice.enabled) {
  117. crop = points[points.length - 1].x === x ? 1 : 2;
  118. yAxis.crosshair = yAxis.options.crosshair = merge({
  119. color: 'transparent'
  120. }, seriesOptions.lastVisiblePrice);
  121. yAxis.cross = serie.lastVisiblePrice;
  122. lastPoint = points[points.length - crop];
  123. // Save price
  124. yAxis.drawCrosshair(null, lastPoint);
  125. serie.lastVisiblePrice = yAxis.cross;
  126. serie.lastVisiblePrice.y = lastPoint.y;
  127. if (serie.crossLabel) {
  128. serie.crossLabel.destroy();
  129. }
  130. serie.crossLabel = yAxis.crossLabel;
  131. }
  132. // Restore crosshair:
  133. yAxis.crosshair = origOptions;
  134. yAxis.cross = origGraphic;
  135. yAxis.crossLabel = origLabel;
  136. }
  137. });
  138. }(Highcharts));
  139. return (function () {
  140. }());
  141. }));