price-indicator.src.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /**
  2. * @license Highstock JS v9.1.1 (2021-06-04)
  3. *
  4. * Advanced Highcharts Stock tools
  5. *
  6. * (c) 2010-2021 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/Series/Series.js'], _modules['Core/Utilities.js']], function (Series, U) {
  33. /**
  34. * (c) 2009-2021 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 false
  62. * @apioption plotOptions.series.lastVisiblePrice.enabled
  63. */
  64. /**
  65. * @declare Highcharts.SeriesLastVisiblePriceLabelOptionsObject
  66. * @extends yAxis.crosshair.label
  67. * @since 7.0.0
  68. * @apioption plotOptions.series.lastVisiblePrice.label
  69. */
  70. /**
  71. * @since 7.0.0
  72. * @apioption plotOptions.series.lastVisiblePrice.label.align
  73. */
  74. /**
  75. * @since 7.0.0
  76. * @apioption plotOptions.series.lastVisiblePrice.label.backgroundColor
  77. */
  78. /**
  79. * The border color for the `lastVisiblePrice` label.
  80. *
  81. * @type {Highcharts.ColorType}
  82. * @since 7.0.0
  83. * @product highstock
  84. * @apioption plotOptions.series.lastVisiblePrice.label.borderColor
  85. */
  86. /**
  87. * The border corner radius of the `lastVisiblePrice` label.
  88. *
  89. * @type {number}
  90. * @default 3
  91. * @since 7.0.0
  92. * @product highstock
  93. * @apioption plotOptions.series.lastVisiblePrice.label.borderRadius
  94. */
  95. /**
  96. * Flag to enable `lastVisiblePrice` label.
  97. *
  98. *
  99. * @type {boolean}
  100. * @default false
  101. * @since 7.0
  102. * @product highstock
  103. * @apioption plotOptions.series.lastVisiblePrice.label.enabled
  104. */
  105. /**
  106. * A format string for the `lastVisiblePrice` label. Defaults to `{value}` for
  107. * numeric axes and `{value:%b %d, %Y}` for datetime axes.
  108. *
  109. * @type {string}
  110. * @since 7.0
  111. * @product highstock
  112. * @apioption plotOptions.series.lastVisiblePrice.label.format
  113. */
  114. /**
  115. * @since 7.0.0
  116. * @apioption plotOptions.series.lastVisiblePrice.label.formatter
  117. */
  118. /**
  119. * @since 7.0.0
  120. * @apioption plotOptions.series.lastVisiblePrice.label.padding
  121. */
  122. /**
  123. * @since 7.0.0
  124. * @apioption plotOptions.series.lastVisiblePrice.label.shape
  125. */
  126. /**
  127. * Text styles for the `lastVisiblePrice` label.
  128. *
  129. * @type {Highcharts.CSSObject}
  130. * @default {"color": "white", "fontWeight": "normal", "fontSize": "11px", "textAlign": "center"}
  131. * @since 7.0
  132. * @product highstock
  133. * @apioption plotOptions.series.lastVisiblePrice.label.style
  134. */
  135. /**
  136. * The border width for the `lastVisiblePrice` label.
  137. *
  138. * @type {number}
  139. * @default 0
  140. * @since 7.0
  141. * @product highstock
  142. * @apioption plotOptions.series.lastVisiblePrice.label.borderWidth
  143. */
  144. /**
  145. * Padding inside the `lastVisiblePrice` label.
  146. *
  147. * @type {number}
  148. * @default 8
  149. * @since 7.0
  150. * @product highstock
  151. * @apioption plotOptions.series.lastVisiblePrice.label.padding
  152. */
  153. /**
  154. * The line marks the last price from all points.
  155. *
  156. * @sample {highstock} stock/indicators/last-price
  157. * Last price
  158. *
  159. * @declare Highcharts.SeriesLastPriceOptionsObject
  160. * @product highstock
  161. * @requires modules/price-indicator
  162. * @apioption plotOptions.series.lastPrice
  163. */
  164. /**
  165. * Enable or disable the indicator.
  166. *
  167. * @type {boolean}
  168. * @product highstock
  169. * @default false
  170. * @apioption plotOptions.series.lastPrice.enabled
  171. */
  172. /**
  173. * @declare Highcharts.SeriesLastPriceLabelOptionsObject
  174. * @extends yAxis.crosshair.label
  175. * @since 7.0.0
  176. * @apioption plotOptions.series.lastPrice.label
  177. */
  178. /**
  179. * @since 7.0.0
  180. * @apioption plotOptions.series.lastPrice.label.align
  181. * */
  182. /**
  183. * @since 7.0.0
  184. * @apioption plotOptions.series.lastPrice.label.backgroundColor
  185. * */
  186. /**
  187. * The border color of `lastPrice` label.
  188. * @since 7.0.0
  189. * @apioption plotOptions.series.lastPrice.label.borderColor
  190. * */
  191. /**
  192. * The border radius of `lastPrice` label.
  193. * @since 7.0.0
  194. * @apioption plotOptions.series.lastPrice.label.borderRadius
  195. * */
  196. /**
  197. * The border width of `lastPrice` label.
  198. * @since 7.0.0
  199. * @apioption plotOptions.series.lastPrice.label.borderWidth
  200. * */
  201. /**
  202. * Flag to enable `lastPrice` label.
  203. * @since 7.0.0
  204. * @apioption plotOptions.series.lastPrice.label.enabled
  205. * */
  206. /**
  207. * A format string for the `lastPrice` label. Defaults to `{value}` for
  208. * numeric axes and `{value:%b %d, %Y}` for datetime axes.
  209. *
  210. * @type {string}
  211. * @since 7.0
  212. * @product highstock
  213. * @apioption plotOptions.series.lastPrice.label.format
  214. */
  215. /**
  216. * @since 7.0.0
  217. * @apioption plotOptions.series.lastPrice.label.formatter
  218. */
  219. /**
  220. * @since 7.0.0
  221. * @apioption plotOptions.series.lastPrice.label.padding
  222. */
  223. /**
  224. * @since 7.0.0
  225. * @apioption plotOptions.series.lastPrice.label.shape
  226. */
  227. /**
  228. * Text styles for the `lastPrice` label.
  229. *
  230. * @type {Highcharts.CSSObject}
  231. * @default {"color": "white", "fontWeight": "normal", "fontSize": "11px", "textAlign": "center"}
  232. * @since 7.0
  233. * @product highstock
  234. * @apioption plotOptions.series.lastPrice.label.style
  235. */
  236. /**
  237. * The border width for the `lastPrice` label.
  238. *
  239. * @type {number}
  240. * @default 0
  241. * @since 7.0
  242. * @product highstock
  243. * @apioption plotOptions.series.lastPrice.label.borderWidth
  244. */
  245. /**
  246. * Padding inside the `lastPrice` label.
  247. *
  248. * @type {number}
  249. * @default 8
  250. * @since 7.0
  251. * @product highstock
  252. * @apioption plotOptions.series.lastPrice.label.padding
  253. */
  254. /**
  255. * The color of the line of last price.
  256. * By default, the line has the same color as the series.
  257. *
  258. * @type {string}
  259. * @product highstock
  260. * @apioption plotOptions.series.lastPrice.color
  261. *
  262. */
  263. /* eslint-disable no-invalid-this */
  264. addEvent(Series, 'afterRender', function () {
  265. var series = this,
  266. seriesOptions = series.options,
  267. pointRange = seriesOptions.pointRange,
  268. lastVisiblePrice = seriesOptions.lastVisiblePrice,
  269. lastPrice = seriesOptions.lastPrice;
  270. if ((lastVisiblePrice || lastPrice) &&
  271. seriesOptions.id !== 'highcharts-navigator-series') {
  272. var xAxis = series.xAxis,
  273. yAxis = series.yAxis,
  274. origOptions = yAxis.crosshair,
  275. origGraphic = yAxis.cross,
  276. origLabel = yAxis.crossLabel,
  277. points = series.points,
  278. yLength = series.yData.length,
  279. pLength = points.length,
  280. x = series.xData[series.xData.length - 1],
  281. y = series.yData[yLength - 1],
  282. lastPoint = void 0,
  283. yValue = void 0,
  284. crop = void 0;
  285. if (lastPrice && lastPrice.enabled) {
  286. yAxis.crosshair = yAxis.options.crosshair = seriesOptions.lastPrice;
  287. if (!series.chart.styledMode &&
  288. yAxis.crosshair &&
  289. yAxis.options.crosshair &&
  290. seriesOptions.lastPrice) {
  291. // Set the default color from the series, #14888.
  292. yAxis.crosshair.color = yAxis.options.crosshair.color = seriesOptions.lastPrice.color || series.color;
  293. }
  294. yAxis.cross = series.lastPrice;
  295. yValue = isArray(y) ? y[3] : y;
  296. yAxis.drawCrosshair(null, ({
  297. x: x,
  298. y: yValue,
  299. plotX: xAxis.toPixels(x, true),
  300. plotY: yAxis.toPixels(yValue, true)
  301. }));
  302. // Save price
  303. if (series.yAxis.cross) {
  304. series.lastPrice = series.yAxis.cross;
  305. series.lastPrice.addClass('highcharts-color-' + series.colorIndex); // #15222
  306. series.lastPrice.y = yValue;
  307. }
  308. }
  309. if (lastVisiblePrice && lastVisiblePrice.enabled && pLength > 0) {
  310. crop = (points[pLength - 1].x === x) || pointRange === null ? 1 : 2;
  311. yAxis.crosshair = yAxis.options.crosshair = merge({
  312. color: 'transparent' // line invisible by default
  313. }, seriesOptions.lastVisiblePrice);
  314. yAxis.cross = series.lastVisiblePrice;
  315. lastPoint = points[pLength - crop];
  316. if (series.crossLabel) {
  317. series.crossLabel.destroy();
  318. }
  319. // Set to undefined to avoid collision with
  320. // the yAxis crosshair #11480
  321. // Delete the crossLabel each time the code is invoked, #13876.
  322. delete yAxis.crossLabel;
  323. // Save price
  324. yAxis.drawCrosshair(null, lastPoint);
  325. if (yAxis.cross) {
  326. series.lastVisiblePrice = yAxis.cross;
  327. if (typeof lastPoint.y === 'number') {
  328. series.lastVisiblePrice.y = lastPoint.y;
  329. }
  330. }
  331. series.crossLabel = yAxis.crossLabel;
  332. }
  333. // Restore crosshair:
  334. yAxis.crosshair = yAxis.options.crosshair = origOptions;
  335. yAxis.cross = origGraphic;
  336. yAxis.crossLabel = origLabel;
  337. }
  338. });
  339. });
  340. _registerModule(_modules, 'masters/modules/price-indicator.src.js', [], function () {
  341. });
  342. }));