price-indicator.src.js 6.0 KB

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