price-indicator.src.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. * @license Highstock JS v8.1.2 (2020-06-16)
  3. *
  4. * Advanced Highstock tools
  5. *
  6. * (c) 2010-2019 Highsoft AS
  7. * Author: Torstein Honsi
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. factory['default'] = factory;
  15. module.exports = factory;
  16. } else if (typeof define === 'function' && define.amd) {
  17. define('highcharts/modules/price-indicator', ['highcharts', 'highcharts/modules/stock'], function (Highcharts) {
  18. factory(Highcharts);
  19. factory.Highcharts = Highcharts;
  20. return factory;
  21. });
  22. } else {
  23. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  24. }
  25. }(function (Highcharts) {
  26. var _modules = Highcharts ? Highcharts._modules : {};
  27. function _registerModule(obj, path, args, fn) {
  28. if (!obj.hasOwnProperty(path)) {
  29. obj[path] = fn.apply(null, args);
  30. }
  31. }
  32. _registerModule(_modules, 'modules/price-indicator.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  33. /**
  34. * (c) 2009-2020 Sebastian Bochann
  35. *
  36. * Price indicator for Highcharts
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. */
  42. var addEvent = U.addEvent, isArray = U.isArray, merge = U.merge;
  43. /**
  44. * The line marks the last price from visible range of points.
  45. *
  46. * @sample {highstock} stock/indicators/last-visible-price
  47. * Last visible price
  48. *
  49. * @declare Highcharts.SeriesLastVisiblePriceOptionsObject
  50. * @product highstock
  51. * @requires modules/price-indicator
  52. * @apioption plotOptions.series.lastVisiblePrice
  53. */
  54. /**
  55. * Enable or disable the indicator.
  56. *
  57. * @type {boolean}
  58. * @product highstock
  59. * @default true
  60. * @apioption plotOptions.series.lastVisiblePrice.enabled
  61. */
  62. /**
  63. * @declare Highcharts.SeriesLastVisiblePriceLabelOptionsObject
  64. * @apioption plotOptions.series.lastVisiblePrice.label
  65. */
  66. /**
  67. * Enable or disable the label.
  68. *
  69. * @type {boolean}
  70. * @product highstock
  71. * @default true
  72. * @apioption plotOptions.series.lastVisiblePrice.label.enabled
  73. *
  74. */
  75. /**
  76. * The line marks the last price from all points.
  77. *
  78. * @sample {highstock} stock/indicators/last-price
  79. * Last price
  80. *
  81. * @declare Highcharts.SeriesLastPriceOptionsObject
  82. * @product highstock
  83. * @requires modules/price-indicator
  84. * @apioption plotOptions.series.lastPrice
  85. */
  86. /**
  87. * Enable or disable the indicator.
  88. *
  89. * @type {boolean}
  90. * @product highstock
  91. * @default true
  92. * @apioption plotOptions.series.lastPrice.enabled
  93. */
  94. /**
  95. * The color of the line of last price.
  96. *
  97. * @type {string}
  98. * @product highstock
  99. * @default red
  100. * @apioption plotOptions.series.lastPrice.color
  101. *
  102. */
  103. /* eslint-disable no-invalid-this */
  104. addEvent(H.Series, 'afterRender', function () {
  105. var serie = this, seriesOptions = serie.options, pointRange = seriesOptions.pointRange, lastVisiblePrice = seriesOptions.lastVisiblePrice, lastPrice = seriesOptions.lastPrice;
  106. if ((lastVisiblePrice || lastPrice) &&
  107. seriesOptions.id !== 'highcharts-navigator-series') {
  108. var xAxis = serie.xAxis, yAxis = serie.yAxis, origOptions = yAxis.crosshair, origGraphic = yAxis.cross, origLabel = yAxis.crossLabel, points = serie.points, yLength = serie.yData.length, pLength = points.length, x = serie.xData[serie.xData.length - 1], y = serie.yData[yLength - 1], lastPoint, yValue, crop;
  109. if (lastPrice && lastPrice.enabled) {
  110. yAxis.crosshair = yAxis.options.crosshair = seriesOptions.lastPrice;
  111. yAxis.cross = serie.lastPrice;
  112. yValue = isArray(y) ? y[3] : y;
  113. yAxis.drawCrosshair(null, ({
  114. x: x,
  115. y: yValue,
  116. plotX: xAxis.toPixels(x, true),
  117. plotY: yAxis.toPixels(yValue, true)
  118. }));
  119. // Save price
  120. if (serie.yAxis.cross) {
  121. serie.lastPrice = serie.yAxis.cross;
  122. serie.lastPrice.y = yValue;
  123. }
  124. }
  125. if (lastVisiblePrice &&
  126. lastVisiblePrice.enabled &&
  127. pLength > 0) {
  128. crop = (points[pLength - 1].x === x) || pointRange === null ? 1 : 2;
  129. yAxis.crosshair = yAxis.options.crosshair = merge({
  130. color: 'transparent'
  131. }, seriesOptions.lastVisiblePrice);
  132. yAxis.cross = serie.lastVisiblePrice;
  133. lastPoint = points[pLength - crop];
  134. if (serie.crossLabel) {
  135. serie.crossLabel.destroy();
  136. // Set to undefined to avoid collision with
  137. // the yAxis crosshair #11480
  138. delete yAxis.crossLabel;
  139. }
  140. // Save price
  141. yAxis.drawCrosshair(null, lastPoint);
  142. if (yAxis.cross) {
  143. serie.lastVisiblePrice = yAxis.cross;
  144. if (typeof lastPoint.y === 'number') {
  145. serie.lastVisiblePrice.y = lastPoint.y;
  146. }
  147. }
  148. serie.crossLabel = yAxis.crossLabel;
  149. }
  150. // Restore crosshair:
  151. yAxis.crosshair = origOptions;
  152. yAxis.cross = origGraphic;
  153. yAxis.crossLabel = origLabel;
  154. }
  155. });
  156. });
  157. _registerModule(_modules, 'masters/modules/price-indicator.src.js', [], function () {
  158. });
  159. }));