price-indicator.src.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * @license Highstock JS v8.2.0 (2020-08-20)
  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, 'Extensions/PriceIndication.js', [_modules['Core/Globals.js'], _modules['Core/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,
  43. isArray = U.isArray,
  44. merge = U.merge;
  45. /**
  46. * The line marks the last price from visible range of points.
  47. *
  48. * @sample {highstock} stock/indicators/last-visible-price
  49. * Last visible price
  50. *
  51. * @declare Highcharts.SeriesLastVisiblePriceOptionsObject
  52. * @product highstock
  53. * @requires modules/price-indicator
  54. * @apioption plotOptions.series.lastVisiblePrice
  55. */
  56. /**
  57. * Enable or disable the indicator.
  58. *
  59. * @type {boolean}
  60. * @product highstock
  61. * @default true
  62. * @apioption plotOptions.series.lastVisiblePrice.enabled
  63. */
  64. /**
  65. * @declare Highcharts.SeriesLastVisiblePriceLabelOptionsObject
  66. * @apioption plotOptions.series.lastVisiblePrice.label
  67. */
  68. /**
  69. * Enable or disable the label.
  70. *
  71. * @type {boolean}
  72. * @product highstock
  73. * @default true
  74. * @apioption plotOptions.series.lastVisiblePrice.label.enabled
  75. *
  76. */
  77. /**
  78. * The line marks the last price from all points.
  79. *
  80. * @sample {highstock} stock/indicators/last-price
  81. * Last price
  82. *
  83. * @declare Highcharts.SeriesLastPriceOptionsObject
  84. * @product highstock
  85. * @requires modules/price-indicator
  86. * @apioption plotOptions.series.lastPrice
  87. */
  88. /**
  89. * Enable or disable the indicator.
  90. *
  91. * @type {boolean}
  92. * @product highstock
  93. * @default true
  94. * @apioption plotOptions.series.lastPrice.enabled
  95. */
  96. /**
  97. * The color of the line of last price.
  98. *
  99. * @type {string}
  100. * @product highstock
  101. * @default red
  102. * @apioption plotOptions.series.lastPrice.color
  103. *
  104. */
  105. /* eslint-disable no-invalid-this */
  106. addEvent(H.Series, 'afterRender', function () {
  107. var serie = this,
  108. seriesOptions = serie.options,
  109. pointRange = seriesOptions.pointRange,
  110. lastVisiblePrice = seriesOptions.lastVisiblePrice,
  111. lastPrice = seriesOptions.lastPrice;
  112. if ((lastVisiblePrice || lastPrice) &&
  113. seriesOptions.id !== 'highcharts-navigator-series') {
  114. var xAxis = serie.xAxis,
  115. yAxis = serie.yAxis,
  116. origOptions = yAxis.crosshair,
  117. origGraphic = yAxis.cross,
  118. origLabel = yAxis.crossLabel,
  119. points = serie.points,
  120. yLength = serie.yData.length,
  121. pLength = points.length,
  122. x = serie.xData[serie.xData.length - 1],
  123. y = serie.yData[yLength - 1],
  124. lastPoint,
  125. yValue,
  126. crop;
  127. if (lastPrice && lastPrice.enabled) {
  128. yAxis.crosshair = yAxis.options.crosshair = seriesOptions.lastPrice;
  129. yAxis.cross = serie.lastPrice;
  130. yValue = isArray(y) ? y[3] : y;
  131. yAxis.drawCrosshair(null, ({
  132. x: x,
  133. y: yValue,
  134. plotX: xAxis.toPixels(x, true),
  135. plotY: yAxis.toPixels(yValue, true)
  136. }));
  137. // Save price
  138. if (serie.yAxis.cross) {
  139. serie.lastPrice = serie.yAxis.cross;
  140. serie.lastPrice.y = yValue;
  141. }
  142. }
  143. if (lastVisiblePrice &&
  144. lastVisiblePrice.enabled &&
  145. pLength > 0) {
  146. crop = (points[pLength - 1].x === x) || pointRange === null ? 1 : 2;
  147. yAxis.crosshair = yAxis.options.crosshair = merge({
  148. color: 'transparent'
  149. }, seriesOptions.lastVisiblePrice);
  150. yAxis.cross = serie.lastVisiblePrice;
  151. lastPoint = points[pLength - crop];
  152. if (serie.crossLabel) {
  153. serie.crossLabel.destroy();
  154. // Set to undefined to avoid collision with
  155. // the yAxis crosshair #11480
  156. delete yAxis.crossLabel;
  157. }
  158. // Save price
  159. yAxis.drawCrosshair(null, lastPoint);
  160. if (yAxis.cross) {
  161. serie.lastVisiblePrice = yAxis.cross;
  162. if (typeof lastPoint.y === 'number') {
  163. serie.lastVisiblePrice.y = lastPoint.y;
  164. }
  165. }
  166. serie.crossLabel = yAxis.crossLabel;
  167. }
  168. // Restore crosshair:
  169. yAxis.crosshair = origOptions;
  170. yAxis.cross = origGraphic;
  171. yAxis.crossLabel = origLabel;
  172. }
  173. });
  174. });
  175. _registerModule(_modules, 'masters/modules/price-indicator.src.js', [], function () {
  176. });
  177. }));