StockToolsBindings.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. /**
  2. *
  3. * Events generator for Stock tools
  4. *
  5. * (c) 2009-2020 Paweł Fus
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. import H from '../Core/Globals.js';
  14. import NavigationBindings from '../Extensions/Annotations/NavigationBindings.js';
  15. import U from '../Core/Utilities.js';
  16. var correctFloat = U.correctFloat, defined = U.defined, extend = U.extend, fireEvent = U.fireEvent, getOptions = U.getOptions, isNumber = U.isNumber, merge = U.merge, pick = U.pick, setOptions = U.setOptions, uniqueKey = U.uniqueKey;
  17. var bindingsUtils = NavigationBindings.prototype.utils, PREFIX = 'highcharts-';
  18. /* eslint-disable no-invalid-this, valid-jsdoc */
  19. /**
  20. * Generates function which will add a flag series using modal in GUI.
  21. * Method fires an event "showPopup" with config:
  22. * `{type, options, callback}`.
  23. *
  24. * Example: NavigationBindings.utils.addFlagFromForm('url(...)') - will
  25. * generate function that shows modal in GUI.
  26. *
  27. * @private
  28. * @function bindingsUtils.addFlagFromForm
  29. *
  30. * @param {Highcharts.FlagsShapeValue} type
  31. * Type of flag series, e.g. "squarepin"
  32. *
  33. * @return {Function}
  34. * Callback to be used in `start` callback
  35. */
  36. bindingsUtils.addFlagFromForm = function (type) {
  37. return function (e) {
  38. var navigation = this, chart = navigation.chart, toolbar = chart.stockTools, getFieldType = bindingsUtils.getFieldType, point = bindingsUtils.attractToPoint(e, chart), pointConfig = {
  39. x: point.x,
  40. y: point.y
  41. }, seriesOptions = {
  42. type: 'flags',
  43. onSeries: point.series.id,
  44. shape: type,
  45. data: [pointConfig],
  46. point: {
  47. events: {
  48. click: function () {
  49. var point = this, options = point.options;
  50. fireEvent(navigation, 'showPopup', {
  51. point: point,
  52. formType: 'annotation-toolbar',
  53. options: {
  54. langKey: 'flags',
  55. type: 'flags',
  56. title: [
  57. options.title,
  58. getFieldType(options.title)
  59. ],
  60. name: [
  61. options.name,
  62. getFieldType(options.name)
  63. ]
  64. },
  65. onSubmit: function (updated) {
  66. if (updated.actionType === 'remove') {
  67. point.remove();
  68. }
  69. else {
  70. point.update(navigation.fieldsToOptions(updated.fields, {}));
  71. }
  72. }
  73. });
  74. }
  75. }
  76. }
  77. };
  78. if (!toolbar || !toolbar.guiEnabled) {
  79. chart.addSeries(seriesOptions);
  80. }
  81. fireEvent(navigation, 'showPopup', {
  82. formType: 'flag',
  83. // Enabled options:
  84. options: {
  85. langKey: 'flags',
  86. type: 'flags',
  87. title: ['A', getFieldType('A')],
  88. name: ['Flag A', getFieldType('Flag A')]
  89. },
  90. // Callback on submit:
  91. onSubmit: function (data) {
  92. navigation.fieldsToOptions(data.fields, seriesOptions.data[0]);
  93. chart.addSeries(seriesOptions);
  94. }
  95. });
  96. };
  97. };
  98. bindingsUtils.manageIndicators = function (data) {
  99. var _a;
  100. var navigation = this, chart = navigation.chart, seriesConfig = {
  101. linkedTo: data.linkedTo,
  102. type: data.type
  103. }, indicatorsWithVolume = [
  104. 'ad',
  105. 'cmf',
  106. 'mfi',
  107. 'vbp',
  108. 'vwap'
  109. ], indicatorsWithAxes = [
  110. 'ad',
  111. 'atr',
  112. 'cci',
  113. 'cmf',
  114. 'macd',
  115. 'mfi',
  116. 'roc',
  117. 'rsi',
  118. 'ao',
  119. 'aroon',
  120. 'aroonoscillator',
  121. 'trix',
  122. 'apo',
  123. 'dpo',
  124. 'ppo',
  125. 'natr',
  126. 'williamsr',
  127. 'stochastic',
  128. 'slowstochastic',
  129. 'linearRegression',
  130. 'linearRegressionSlope',
  131. 'linearRegressionIntercept',
  132. 'linearRegressionAngle'
  133. ], yAxis, parentSeries, defaultOptions, series;
  134. if (data.actionType === 'edit') {
  135. navigation.fieldsToOptions(data.fields, seriesConfig);
  136. series = chart.get(data.seriesId);
  137. if (series) {
  138. series.update(seriesConfig, false);
  139. }
  140. }
  141. else if (data.actionType === 'remove') {
  142. series = chart.get(data.seriesId);
  143. if (series) {
  144. yAxis = series.yAxis;
  145. if (series.linkedSeries) {
  146. series.linkedSeries.forEach(function (linkedSeries) {
  147. linkedSeries.remove(false);
  148. });
  149. }
  150. series.remove(false);
  151. if (indicatorsWithAxes.indexOf(series.type) >= 0) {
  152. yAxis.remove(false);
  153. navigation.resizeYAxes();
  154. }
  155. }
  156. }
  157. else {
  158. seriesConfig.id = uniqueKey();
  159. navigation.fieldsToOptions(data.fields, seriesConfig);
  160. parentSeries = chart.get(seriesConfig.linkedTo);
  161. defaultOptions = getOptions().plotOptions;
  162. // Make sure that indicator uses the SUM approx if SUM approx is used
  163. // by parent series (#13950).
  164. if (typeof parentSeries !== 'undefined' &&
  165. parentSeries instanceof Highcharts.Series &&
  166. parentSeries.getDGApproximation() === 'sum' &&
  167. // If indicator has defined approx type, use it (e.g. "ranges")
  168. !defined(defaultOptions && defaultOptions[seriesConfig.type] && ((_a = defaultOptions.dataGrouping) === null || _a === void 0 ? void 0 : _a.approximation))) {
  169. seriesConfig.dataGrouping = {
  170. approximation: 'sum'
  171. };
  172. }
  173. if (indicatorsWithAxes.indexOf(data.type) >= 0) {
  174. yAxis = chart.addAxis({
  175. id: uniqueKey(),
  176. offset: 0,
  177. opposite: true,
  178. title: {
  179. text: ''
  180. },
  181. tickPixelInterval: 40,
  182. showLastLabel: false,
  183. labels: {
  184. align: 'left',
  185. y: -2
  186. }
  187. }, false, false);
  188. seriesConfig.yAxis = yAxis.options.id;
  189. navigation.resizeYAxes();
  190. }
  191. else {
  192. seriesConfig.yAxis = chart.get(data.linkedTo).options.yAxis;
  193. }
  194. if (indicatorsWithVolume.indexOf(data.type) >= 0) {
  195. seriesConfig.params.volumeSeriesID = chart.series.filter(function (series) {
  196. return series.options.type === 'column';
  197. })[0].options.id;
  198. }
  199. chart.addSeries(seriesConfig, false);
  200. }
  201. fireEvent(navigation, 'deselectButton', {
  202. button: navigation.selectedButtonElement
  203. });
  204. chart.redraw();
  205. };
  206. /**
  207. * Update height for an annotation. Height is calculated as a difference
  208. * between last point in `typeOptions` and current position. It's a value,
  209. * not pixels height.
  210. *
  211. * @private
  212. * @function bindingsUtils.updateHeight
  213. *
  214. * @param {Highcharts.PointerEventObject} e
  215. * normalized browser event
  216. *
  217. * @param {Highcharts.Annotation} annotation
  218. * Annotation to be updated
  219. *
  220. * @return {void}
  221. */
  222. bindingsUtils.updateHeight = function (e, annotation) {
  223. annotation.update({
  224. typeOptions: {
  225. height: this.chart.pointer.getCoordinates(e).yAxis[0].value -
  226. annotation.options.typeOptions.points[1].y
  227. }
  228. });
  229. };
  230. // @todo
  231. // Consider using getHoverData(), but always kdTree (columns?)
  232. bindingsUtils.attractToPoint = function (e, chart) {
  233. var coords = chart.pointer.getCoordinates(e), x = coords.xAxis[0].value, y = coords.yAxis[0].value, distX = Number.MAX_VALUE, closestPoint;
  234. chart.series.forEach(function (series) {
  235. series.points.forEach(function (point) {
  236. if (point && distX > Math.abs(point.x - x)) {
  237. distX = Math.abs(point.x - x);
  238. closestPoint = point;
  239. }
  240. });
  241. });
  242. return {
  243. x: closestPoint.x,
  244. y: closestPoint.y,
  245. below: y < closestPoint.y,
  246. series: closestPoint.series,
  247. xAxis: closestPoint.series.xAxis.index || 0,
  248. yAxis: closestPoint.series.yAxis.index || 0
  249. };
  250. };
  251. /**
  252. * Shorthand to check if given yAxis comes from navigator.
  253. *
  254. * @private
  255. * @function bindingsUtils.isNotNavigatorYAxis
  256. *
  257. * @param {Highcharts.Axis} axis
  258. * Axis to check.
  259. *
  260. * @return {boolean}
  261. * True, if axis comes from navigator.
  262. */
  263. bindingsUtils.isNotNavigatorYAxis = function (axis) {
  264. return axis.userOptions.className !== PREFIX + 'navigator-yaxis';
  265. };
  266. /**
  267. * Update each point after specified index, most of the annotations use
  268. * this. For example crooked line: logic behind updating each point is the
  269. * same, only index changes when adding an annotation.
  270. *
  271. * Example: NavigationBindings.utils.updateNthPoint(1) - will generate
  272. * function that updates all consecutive points except point with index=0.
  273. *
  274. * @private
  275. * @function bindingsUtils.updateNthPoint
  276. *
  277. * @param {number} startIndex
  278. * Index from each point should udpated
  279. *
  280. * @return {Function}
  281. * Callback to be used in steps array
  282. */
  283. bindingsUtils.updateNthPoint = function (startIndex) {
  284. return function (e, annotation) {
  285. var options = annotation.options.typeOptions, coords = this.chart.pointer.getCoordinates(e), x = coords.xAxis[0].value, y = coords.yAxis[0].value;
  286. options.points.forEach(function (point, index) {
  287. if (index >= startIndex) {
  288. point.x = x;
  289. point.y = y;
  290. }
  291. });
  292. annotation.update({
  293. typeOptions: {
  294. points: options.points
  295. }
  296. });
  297. };
  298. };
  299. // Extends NavigationBindigs to support indicators and resizers:
  300. extend(NavigationBindings.prototype, {
  301. /* eslint-disable valid-jsdoc */
  302. /**
  303. * Get current positions for all yAxes. If new axis does not have position,
  304. * returned is default height and last available top place.
  305. *
  306. * @private
  307. * @function Highcharts.NavigationBindings#getYAxisPositions
  308. *
  309. * @param {Array<Highcharts.Axis>} yAxes
  310. * Array of yAxes available in the chart.
  311. *
  312. * @param {number} plotHeight
  313. * Available height in the chart.
  314. *
  315. * @param {number} defaultHeight
  316. * Default height in percents.
  317. *
  318. * @return {Array}
  319. * An array of calculated positions in percentages.
  320. * Format: `{top: Number, height: Number}`
  321. */
  322. getYAxisPositions: function (yAxes, plotHeight, defaultHeight) {
  323. var positions, allAxesHeight = 0;
  324. /** @private */
  325. function isPercentage(prop) {
  326. return defined(prop) && !isNumber(prop) && prop.match('%');
  327. }
  328. positions = yAxes.map(function (yAxis) {
  329. var height = isPercentage(yAxis.options.height) ?
  330. parseFloat(yAxis.options.height) / 100 :
  331. yAxis.height / plotHeight, top = isPercentage(yAxis.options.top) ?
  332. parseFloat(yAxis.options.top) / 100 :
  333. correctFloat(yAxis.top - yAxis.chart.plotTop) / plotHeight;
  334. // New yAxis does not contain "height" info yet
  335. if (!isNumber(height)) {
  336. height = defaultHeight / 100;
  337. }
  338. allAxesHeight = correctFloat(allAxesHeight + height);
  339. return {
  340. height: height * 100,
  341. top: top * 100
  342. };
  343. });
  344. positions.allAxesHeight = allAxesHeight;
  345. return positions;
  346. },
  347. /**
  348. * Get current resize options for each yAxis. Note that each resize is
  349. * linked to the next axis, except the last one which shouldn't affect
  350. * axes in the navigator. Because indicator can be removed with it's yAxis
  351. * in the middle of yAxis array, we need to bind closest yAxes back.
  352. *
  353. * @private
  354. * @function Highcharts.NavigationBindings#getYAxisResizers
  355. *
  356. * @param {Array<Highcharts.Axis>} yAxes
  357. * Array of yAxes available in the chart
  358. *
  359. * @return {Array<object>}
  360. * An array of resizer options.
  361. * Format: `{enabled: Boolean, controlledAxis: { next: [String]}}`
  362. */
  363. getYAxisResizers: function (yAxes) {
  364. var resizers = [];
  365. yAxes.forEach(function (_yAxis, index) {
  366. var nextYAxis = yAxes[index + 1];
  367. // We have next axis, bind them:
  368. if (nextYAxis) {
  369. resizers[index] = {
  370. enabled: true,
  371. controlledAxis: {
  372. next: [
  373. pick(nextYAxis.options.id, nextYAxis.options.index)
  374. ]
  375. }
  376. };
  377. }
  378. else {
  379. // Remove binding:
  380. resizers[index] = {
  381. enabled: false
  382. };
  383. }
  384. });
  385. return resizers;
  386. },
  387. /**
  388. * Resize all yAxes (except navigator) to fit the plotting height. Method
  389. * checks if new axis is added, then shrinks other main axis up to 5 panes.
  390. * If added is more thatn 5 panes, it rescales all other axes to fit new
  391. * yAxis.
  392. *
  393. * If axis is removed, and we have more than 5 panes, rescales all other
  394. * axes. If chart has less than 5 panes, first pane receives all extra
  395. * space.
  396. *
  397. * @private
  398. * @function Highcharts.NavigationBindings#resizeYAxes
  399. * @param {number} [defaultHeight]
  400. * Default height for yAxis
  401. */
  402. resizeYAxes: function (defaultHeight) {
  403. defaultHeight = defaultHeight || 20; // in %, but as a number
  404. var chart = this.chart,
  405. // Only non-navigator axes
  406. yAxes = chart.yAxis.filter(bindingsUtils.isNotNavigatorYAxis), plotHeight = chart.plotHeight, allAxesLength = yAxes.length,
  407. // Gather current heights (in %)
  408. positions = this.getYAxisPositions(yAxes, plotHeight, defaultHeight), resizers = this.getYAxisResizers(yAxes), allAxesHeight = positions.allAxesHeight, changedSpace = defaultHeight;
  409. // More than 100%
  410. if (allAxesHeight > 1) {
  411. // Simple case, add new panes up to 5
  412. if (allAxesLength < 6) {
  413. // Added axis, decrease first pane's height:
  414. positions[0].height = correctFloat(positions[0].height - changedSpace);
  415. // And update all other "top" positions:
  416. positions = this.recalculateYAxisPositions(positions, changedSpace);
  417. }
  418. else {
  419. // We have more panes, rescale all others to gain some space,
  420. // This is new height for upcoming yAxis:
  421. defaultHeight = 100 / allAxesLength;
  422. // This is how much we need to take from each other yAxis:
  423. changedSpace = defaultHeight / (allAxesLength - 1);
  424. // Now update all positions:
  425. positions = this.recalculateYAxisPositions(positions, changedSpace, true, -1);
  426. }
  427. // Set last position manually:
  428. positions[allAxesLength - 1] = {
  429. top: correctFloat(100 - defaultHeight),
  430. height: defaultHeight
  431. };
  432. }
  433. else {
  434. // Less than 100%
  435. changedSpace = correctFloat(1 - allAxesHeight) * 100;
  436. // Simple case, return first pane it's space:
  437. if (allAxesLength < 5) {
  438. positions[0].height = correctFloat(positions[0].height + changedSpace);
  439. positions = this.recalculateYAxisPositions(positions, changedSpace);
  440. }
  441. else {
  442. // There were more panes, return to each pane a bit of space:
  443. changedSpace /= allAxesLength;
  444. // Removed axis, add extra space to the first pane:
  445. // And update all other positions:
  446. positions = this.recalculateYAxisPositions(positions, changedSpace, true, 1);
  447. }
  448. }
  449. positions.forEach(function (position, index) {
  450. // if (index === 0) debugger;
  451. yAxes[index].update({
  452. height: position.height + '%',
  453. top: position.top + '%',
  454. resize: resizers[index]
  455. }, false);
  456. });
  457. },
  458. /**
  459. * Utility to modify calculated positions according to the remaining/needed
  460. * space. Later, these positions are used in `yAxis.update({ top, height })`
  461. *
  462. * @private
  463. * @function Highcharts.NavigationBindings#recalculateYAxisPositions
  464. * @param {Array<Highcharts.Dictionary<number>>} positions
  465. * Default positions of all yAxes.
  466. * @param {number} changedSpace
  467. * How much space should be added or removed.
  468. * @param {boolean} modifyHeight
  469. * Update only `top` or both `top` and `height`.
  470. * @param {number} adder
  471. * `-1` or `1`, to determine whether we should add or remove space.
  472. *
  473. * @return {Array<object>}
  474. * Modified positions,
  475. */
  476. recalculateYAxisPositions: function (positions, changedSpace, modifyHeight, adder) {
  477. positions.forEach(function (position, index) {
  478. var prevPosition = positions[index - 1];
  479. position.top = !prevPosition ? 0 :
  480. correctFloat(prevPosition.height + prevPosition.top);
  481. if (modifyHeight) {
  482. position.height = correctFloat(position.height + adder * changedSpace);
  483. }
  484. });
  485. return positions;
  486. }
  487. /* eslint-enable valid-jsdoc */
  488. });
  489. /**
  490. * @type {Highcharts.Dictionary<Highcharts.NavigationBindingsOptionsObject>}
  491. * @since 7.0.0
  492. * @optionparent navigation.bindings
  493. */
  494. var stockToolsBindings = {
  495. // Line type annotations:
  496. /**
  497. * A segment annotation bindings. Includes `start` and one event in `steps`
  498. * array.
  499. *
  500. * @type {Highcharts.NavigationBindingsOptionsObject}
  501. * @product highstock
  502. * @default {"className": "highcharts-segment", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  503. */
  504. segment: {
  505. /** @ignore-option */
  506. className: 'highcharts-segment',
  507. // eslint-disable-next-line valid-jsdoc
  508. /** @ignore-option */
  509. start: function (e) {
  510. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  511. langKey: 'segment',
  512. type: 'crookedLine',
  513. typeOptions: {
  514. points: [{
  515. x: coords.xAxis[0].value,
  516. y: coords.yAxis[0].value
  517. }, {
  518. x: coords.xAxis[0].value,
  519. y: coords.yAxis[0].value
  520. }]
  521. }
  522. }, navigation.annotationsOptions, navigation.bindings.segment.annotationsOptions);
  523. return this.chart.addAnnotation(options);
  524. },
  525. /** @ignore-option */
  526. steps: [
  527. bindingsUtils.updateNthPoint(1)
  528. ]
  529. },
  530. /**
  531. * A segment with an arrow annotation bindings. Includes `start` and one
  532. * event in `steps` array.
  533. *
  534. * @type {Highcharts.NavigationBindingsOptionsObject}
  535. * @product highstock
  536. * @default {"className": "highcharts-arrow-segment", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  537. */
  538. arrowSegment: {
  539. /** @ignore-option */
  540. className: 'highcharts-arrow-segment',
  541. // eslint-disable-next-line valid-jsdoc
  542. /** @ignore-option */
  543. start: function (e) {
  544. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  545. langKey: 'arrowSegment',
  546. type: 'crookedLine',
  547. typeOptions: {
  548. line: {
  549. markerEnd: 'arrow'
  550. },
  551. points: [{
  552. x: coords.xAxis[0].value,
  553. y: coords.yAxis[0].value
  554. }, {
  555. x: coords.xAxis[0].value,
  556. y: coords.yAxis[0].value
  557. }]
  558. }
  559. }, navigation.annotationsOptions, navigation.bindings.arrowSegment.annotationsOptions);
  560. return this.chart.addAnnotation(options);
  561. },
  562. /** @ignore-option */
  563. steps: [
  564. bindingsUtils.updateNthPoint(1)
  565. ]
  566. },
  567. /**
  568. * A ray annotation bindings. Includes `start` and one event in `steps`
  569. * array.
  570. *
  571. * @type {Highcharts.NavigationBindingsOptionsObject}
  572. * @product highstock
  573. * @default {"className": "highcharts-ray", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  574. */
  575. ray: {
  576. /** @ignore-option */
  577. className: 'highcharts-ray',
  578. // eslint-disable-next-line valid-jsdoc
  579. /** @ignore-option */
  580. start: function (e) {
  581. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  582. langKey: 'ray',
  583. type: 'crookedLine',
  584. typeOptions: {
  585. type: 'ray',
  586. points: [{
  587. x: coords.xAxis[0].value,
  588. y: coords.yAxis[0].value
  589. }, {
  590. x: coords.xAxis[0].value,
  591. y: coords.yAxis[0].value
  592. }]
  593. }
  594. }, navigation.annotationsOptions, navigation.bindings.ray.annotationsOptions);
  595. return this.chart.addAnnotation(options);
  596. },
  597. /** @ignore-option */
  598. steps: [
  599. bindingsUtils.updateNthPoint(1)
  600. ]
  601. },
  602. /**
  603. * A ray with an arrow annotation bindings. Includes `start` and one event
  604. * in `steps` array.
  605. *
  606. * @type {Highcharts.NavigationBindingsOptionsObject}
  607. * @product highstock
  608. * @default {"className": "highcharts-arrow-ray", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  609. */
  610. arrowRay: {
  611. /** @ignore-option */
  612. className: 'highcharts-arrow-ray',
  613. // eslint-disable-next-line valid-jsdoc
  614. /** @ignore-option */
  615. start: function (e) {
  616. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  617. langKey: 'arrowRay',
  618. type: 'infinityLine',
  619. typeOptions: {
  620. type: 'ray',
  621. line: {
  622. markerEnd: 'arrow'
  623. },
  624. points: [{
  625. x: coords.xAxis[0].value,
  626. y: coords.yAxis[0].value
  627. }, {
  628. x: coords.xAxis[0].value,
  629. y: coords.yAxis[0].value
  630. }]
  631. }
  632. }, navigation.annotationsOptions, navigation.bindings.arrowRay.annotationsOptions);
  633. return this.chart.addAnnotation(options);
  634. },
  635. /** @ignore-option */
  636. steps: [
  637. bindingsUtils.updateNthPoint(1)
  638. ]
  639. },
  640. /**
  641. * A line annotation. Includes `start` and one event in `steps` array.
  642. *
  643. * @type {Highcharts.NavigationBindingsOptionsObject}
  644. * @product highstock
  645. * @default {"className": "highcharts-infinity-line", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  646. */
  647. infinityLine: {
  648. /** @ignore-option */
  649. className: 'highcharts-infinity-line',
  650. // eslint-disable-next-line valid-jsdoc
  651. /** @ignore-option */
  652. start: function (e) {
  653. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  654. langKey: 'infinityLine',
  655. type: 'infinityLine',
  656. typeOptions: {
  657. type: 'line',
  658. points: [{
  659. x: coords.xAxis[0].value,
  660. y: coords.yAxis[0].value
  661. }, {
  662. x: coords.xAxis[0].value,
  663. y: coords.yAxis[0].value
  664. }]
  665. }
  666. }, navigation.annotationsOptions, navigation.bindings.infinityLine.annotationsOptions);
  667. return this.chart.addAnnotation(options);
  668. },
  669. /** @ignore-option */
  670. steps: [
  671. bindingsUtils.updateNthPoint(1)
  672. ]
  673. },
  674. /**
  675. * A line with arrow annotation. Includes `start` and one event in `steps`
  676. * array.
  677. *
  678. * @type {Highcharts.NavigationBindingsOptionsObject}
  679. * @product highstock
  680. * @default {"className": "highcharts-arrow-infinity-line", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  681. */
  682. arrowInfinityLine: {
  683. /** @ignore-option */
  684. className: 'highcharts-arrow-infinity-line',
  685. // eslint-disable-next-line valid-jsdoc
  686. /** @ignore-option */
  687. start: function (e) {
  688. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  689. langKey: 'arrowInfinityLine',
  690. type: 'infinityLine',
  691. typeOptions: {
  692. type: 'line',
  693. line: {
  694. markerEnd: 'arrow'
  695. },
  696. points: [{
  697. x: coords.xAxis[0].value,
  698. y: coords.yAxis[0].value
  699. }, {
  700. x: coords.xAxis[0].value,
  701. y: coords.yAxis[0].value
  702. }]
  703. }
  704. }, navigation.annotationsOptions, navigation.bindings.arrowInfinityLine.annotationsOptions);
  705. return this.chart.addAnnotation(options);
  706. },
  707. /** @ignore-option */
  708. steps: [
  709. bindingsUtils.updateNthPoint(1)
  710. ]
  711. },
  712. /**
  713. * A horizontal line annotation. Includes `start` event.
  714. *
  715. * @type {Highcharts.NavigationBindingsOptionsObject}
  716. * @product highstock
  717. * @default {"className": "highcharts-horizontal-line", "start": function() {}, "annotationsOptions": {}}
  718. */
  719. horizontalLine: {
  720. /** @ignore-option */
  721. className: 'highcharts-horizontal-line',
  722. // eslint-disable-next-line valid-jsdoc
  723. /** @ignore-option */
  724. start: function (e) {
  725. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  726. langKey: 'horizontalLine',
  727. type: 'infinityLine',
  728. draggable: 'y',
  729. typeOptions: {
  730. type: 'horizontalLine',
  731. points: [{
  732. x: coords.xAxis[0].value,
  733. y: coords.yAxis[0].value
  734. }]
  735. }
  736. }, navigation.annotationsOptions, navigation.bindings.horizontalLine.annotationsOptions);
  737. this.chart.addAnnotation(options);
  738. }
  739. },
  740. /**
  741. * A vertical line annotation. Includes `start` event.
  742. *
  743. * @type {Highcharts.NavigationBindingsOptionsObject}
  744. * @product highstock
  745. * @default {"className": "highcharts-vertical-line", "start": function() {}, "annotationsOptions": {}}
  746. */
  747. verticalLine: {
  748. /** @ignore-option */
  749. className: 'highcharts-vertical-line',
  750. // eslint-disable-next-line valid-jsdoc
  751. /** @ignore-option */
  752. start: function (e) {
  753. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  754. langKey: 'verticalLine',
  755. type: 'infinityLine',
  756. draggable: 'x',
  757. typeOptions: {
  758. type: 'verticalLine',
  759. points: [{
  760. x: coords.xAxis[0].value,
  761. y: coords.yAxis[0].value
  762. }]
  763. }
  764. }, navigation.annotationsOptions, navigation.bindings.verticalLine.annotationsOptions);
  765. this.chart.addAnnotation(options);
  766. }
  767. },
  768. /**
  769. * Crooked line (three points) annotation bindings. Includes `start` and two
  770. * events in `steps` (for second and third points in crooked line) array.
  771. *
  772. * @type {Highcharts.NavigationBindingsOptionsObject}
  773. * @product highstock
  774. * @default {"className": "highcharts-crooked3", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  775. */
  776. // Crooked Line type annotations:
  777. crooked3: {
  778. /** @ignore-option */
  779. className: 'highcharts-crooked3',
  780. // eslint-disable-next-line valid-jsdoc
  781. /** @ignore-option */
  782. start: function (e) {
  783. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  784. langKey: 'crooked3',
  785. type: 'crookedLine',
  786. typeOptions: {
  787. points: [{
  788. x: coords.xAxis[0].value,
  789. y: coords.yAxis[0].value
  790. }, {
  791. x: coords.xAxis[0].value,
  792. y: coords.yAxis[0].value
  793. }, {
  794. x: coords.xAxis[0].value,
  795. y: coords.yAxis[0].value
  796. }]
  797. }
  798. }, navigation.annotationsOptions, navigation.bindings.crooked3.annotationsOptions);
  799. return this.chart.addAnnotation(options);
  800. },
  801. /** @ignore-option */
  802. steps: [
  803. bindingsUtils.updateNthPoint(1),
  804. bindingsUtils.updateNthPoint(2)
  805. ]
  806. },
  807. /**
  808. * Crooked line (five points) annotation bindings. Includes `start` and four
  809. * events in `steps` (for all consequent points in crooked line) array.
  810. *
  811. * @type {Highcharts.NavigationBindingsOptionsObject}
  812. * @product highstock
  813. * @default {"className": "highcharts-crooked3", "start": function() {}, "steps": [function() {}, function() {}, function() {}, function() {}], "annotationsOptions": {}}
  814. */
  815. crooked5: {
  816. /** @ignore-option */
  817. className: 'highcharts-crooked5',
  818. // eslint-disable-next-line valid-jsdoc
  819. /** @ignore-option */
  820. start: function (e) {
  821. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  822. langKey: 'crookedLine',
  823. type: 'crookedLine',
  824. typeOptions: {
  825. points: [{
  826. x: coords.xAxis[0].value,
  827. y: coords.yAxis[0].value
  828. }, {
  829. x: coords.xAxis[0].value,
  830. y: coords.yAxis[0].value
  831. }, {
  832. x: coords.xAxis[0].value,
  833. y: coords.yAxis[0].value
  834. }, {
  835. x: coords.xAxis[0].value,
  836. y: coords.yAxis[0].value
  837. }, {
  838. x: coords.xAxis[0].value,
  839. y: coords.yAxis[0].value
  840. }]
  841. }
  842. }, navigation.annotationsOptions, navigation.bindings.crooked5.annotationsOptions);
  843. return this.chart.addAnnotation(options);
  844. },
  845. /** @ignore-option */
  846. steps: [
  847. bindingsUtils.updateNthPoint(1),
  848. bindingsUtils.updateNthPoint(2),
  849. bindingsUtils.updateNthPoint(3),
  850. bindingsUtils.updateNthPoint(4)
  851. ]
  852. },
  853. /**
  854. * Elliott wave (three points) annotation bindings. Includes `start` and two
  855. * events in `steps` (for second and third points) array.
  856. *
  857. * @type {Highcharts.NavigationBindingsOptionsObject}
  858. * @product highstock
  859. * @default {"className": "highcharts-elliott3", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  860. */
  861. elliott3: {
  862. /** @ignore-option */
  863. className: 'highcharts-elliott3',
  864. // eslint-disable-next-line valid-jsdoc
  865. /** @ignore-option */
  866. start: function (e) {
  867. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  868. langKey: 'elliott3',
  869. type: 'elliottWave',
  870. typeOptions: {
  871. points: [{
  872. x: coords.xAxis[0].value,
  873. y: coords.yAxis[0].value
  874. }, {
  875. x: coords.xAxis[0].value,
  876. y: coords.yAxis[0].value
  877. }, {
  878. x: coords.xAxis[0].value,
  879. y: coords.yAxis[0].value
  880. }, {
  881. x: coords.xAxis[0].value,
  882. y: coords.yAxis[0].value
  883. }]
  884. },
  885. labelOptions: {
  886. style: {
  887. color: '#666666'
  888. }
  889. }
  890. }, navigation.annotationsOptions, navigation.bindings.elliott3.annotationsOptions);
  891. return this.chart.addAnnotation(options);
  892. },
  893. /** @ignore-option */
  894. steps: [
  895. bindingsUtils.updateNthPoint(1),
  896. bindingsUtils.updateNthPoint(2),
  897. bindingsUtils.updateNthPoint(3)
  898. ]
  899. },
  900. /**
  901. * Elliott wave (five points) annotation bindings. Includes `start` and four
  902. * event in `steps` (for all consequent points in Elliott wave) array.
  903. *
  904. * @type {Highcharts.NavigationBindingsOptionsObject}
  905. * @product highstock
  906. * @default {"className": "highcharts-elliott3", "start": function() {}, "steps": [function() {}, function() {}, function() {}, function() {}], "annotationsOptions": {}}
  907. */
  908. elliott5: {
  909. /** @ignore-option */
  910. className: 'highcharts-elliott5',
  911. // eslint-disable-next-line valid-jsdoc
  912. /** @ignore-option */
  913. start: function (e) {
  914. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  915. langKey: 'elliott5',
  916. type: 'elliottWave',
  917. typeOptions: {
  918. points: [{
  919. x: coords.xAxis[0].value,
  920. y: coords.yAxis[0].value
  921. }, {
  922. x: coords.xAxis[0].value,
  923. y: coords.yAxis[0].value
  924. }, {
  925. x: coords.xAxis[0].value,
  926. y: coords.yAxis[0].value
  927. }, {
  928. x: coords.xAxis[0].value,
  929. y: coords.yAxis[0].value
  930. }, {
  931. x: coords.xAxis[0].value,
  932. y: coords.yAxis[0].value
  933. }, {
  934. x: coords.xAxis[0].value,
  935. y: coords.yAxis[0].value
  936. }]
  937. },
  938. labelOptions: {
  939. style: {
  940. color: '#666666'
  941. }
  942. }
  943. }, navigation.annotationsOptions, navigation.bindings.elliott5.annotationsOptions);
  944. return this.chart.addAnnotation(options);
  945. },
  946. /** @ignore-option */
  947. steps: [
  948. bindingsUtils.updateNthPoint(1),
  949. bindingsUtils.updateNthPoint(2),
  950. bindingsUtils.updateNthPoint(3),
  951. bindingsUtils.updateNthPoint(4),
  952. bindingsUtils.updateNthPoint(5)
  953. ]
  954. },
  955. /**
  956. * A measure (x-dimension) annotation bindings. Includes `start` and one
  957. * event in `steps` array.
  958. *
  959. * @type {Highcharts.NavigationBindingsOptionsObject}
  960. * @product highstock
  961. * @default {"className": "highcharts-measure-x", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  962. */
  963. measureX: {
  964. /** @ignore-option */
  965. className: 'highcharts-measure-x',
  966. // eslint-disable-next-line valid-jsdoc
  967. /** @ignore-option */
  968. start: function (e) {
  969. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  970. langKey: 'measure',
  971. type: 'measure',
  972. typeOptions: {
  973. selectType: 'x',
  974. point: {
  975. x: coords.xAxis[0].value,
  976. y: coords.yAxis[0].value,
  977. xAxis: 0,
  978. yAxis: 0
  979. },
  980. crosshairX: {
  981. strokeWidth: 1,
  982. stroke: '#000000'
  983. },
  984. crosshairY: {
  985. enabled: false,
  986. strokeWidth: 0,
  987. stroke: '#000000'
  988. },
  989. background: {
  990. width: 0,
  991. height: 0,
  992. strokeWidth: 0,
  993. stroke: '#ffffff'
  994. }
  995. },
  996. labelOptions: {
  997. style: {
  998. color: '#666666'
  999. }
  1000. }
  1001. }, navigation.annotationsOptions, navigation.bindings.measureX.annotationsOptions);
  1002. return this.chart.addAnnotation(options);
  1003. },
  1004. /** @ignore-option */
  1005. steps: [
  1006. bindingsUtils.updateRectSize
  1007. ]
  1008. },
  1009. /**
  1010. * A measure (y-dimension) annotation bindings. Includes `start` and one
  1011. * event in `steps` array.
  1012. *
  1013. * @type {Highcharts.NavigationBindingsOptionsObject}
  1014. * @product highstock
  1015. * @default {"className": "highcharts-measure-y", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  1016. */
  1017. measureY: {
  1018. /** @ignore-option */
  1019. className: 'highcharts-measure-y',
  1020. // eslint-disable-next-line valid-jsdoc
  1021. /** @ignore-option */
  1022. start: function (e) {
  1023. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1024. langKey: 'measure',
  1025. type: 'measure',
  1026. typeOptions: {
  1027. selectType: 'y',
  1028. point: {
  1029. x: coords.xAxis[0].value,
  1030. y: coords.yAxis[0].value,
  1031. xAxis: 0,
  1032. yAxis: 0
  1033. },
  1034. crosshairX: {
  1035. enabled: false,
  1036. strokeWidth: 0,
  1037. stroke: '#000000'
  1038. },
  1039. crosshairY: {
  1040. strokeWidth: 1,
  1041. stroke: '#000000'
  1042. },
  1043. background: {
  1044. width: 0,
  1045. height: 0,
  1046. strokeWidth: 0,
  1047. stroke: '#ffffff'
  1048. }
  1049. },
  1050. labelOptions: {
  1051. style: {
  1052. color: '#666666'
  1053. }
  1054. }
  1055. }, navigation.annotationsOptions, navigation.bindings.measureY.annotationsOptions);
  1056. return this.chart.addAnnotation(options);
  1057. },
  1058. /** @ignore-option */
  1059. steps: [
  1060. bindingsUtils.updateRectSize
  1061. ]
  1062. },
  1063. /**
  1064. * A measure (xy-dimension) annotation bindings. Includes `start` and one
  1065. * event in `steps` array.
  1066. *
  1067. * @type {Highcharts.NavigationBindingsOptionsObject}
  1068. * @product highstock
  1069. * @default {"className": "highcharts-measure-xy", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  1070. */
  1071. measureXY: {
  1072. /** @ignore-option */
  1073. className: 'highcharts-measure-xy',
  1074. // eslint-disable-next-line valid-jsdoc
  1075. /** @ignore-option */
  1076. start: function (e) {
  1077. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1078. langKey: 'measure',
  1079. type: 'measure',
  1080. typeOptions: {
  1081. selectType: 'xy',
  1082. point: {
  1083. x: coords.xAxis[0].value,
  1084. y: coords.yAxis[0].value,
  1085. xAxis: 0,
  1086. yAxis: 0
  1087. },
  1088. background: {
  1089. width: 0,
  1090. height: 0,
  1091. strokeWidth: 10
  1092. },
  1093. crosshairX: {
  1094. strokeWidth: 1,
  1095. stroke: '#000000'
  1096. },
  1097. crosshairY: {
  1098. strokeWidth: 1,
  1099. stroke: '#000000'
  1100. }
  1101. },
  1102. labelOptions: {
  1103. style: {
  1104. color: '#666666'
  1105. }
  1106. }
  1107. }, navigation.annotationsOptions, navigation.bindings.measureXY.annotationsOptions);
  1108. return this.chart.addAnnotation(options);
  1109. },
  1110. /** @ignore-option */
  1111. steps: [
  1112. bindingsUtils.updateRectSize
  1113. ]
  1114. },
  1115. // Advanced type annotations:
  1116. /**
  1117. * A fibonacci annotation bindings. Includes `start` and two events in
  1118. * `steps` array (updates second point, then height).
  1119. *
  1120. * @type {Highcharts.NavigationBindingsOptionsObject}
  1121. * @product highstock
  1122. * @default {"className": "highcharts-fibonacci", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  1123. */
  1124. fibonacci: {
  1125. /** @ignore-option */
  1126. className: 'highcharts-fibonacci',
  1127. // eslint-disable-next-line valid-jsdoc
  1128. /** @ignore-option */
  1129. start: function (e) {
  1130. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1131. langKey: 'fibonacci',
  1132. type: 'fibonacci',
  1133. typeOptions: {
  1134. points: [{
  1135. x: coords.xAxis[0].value,
  1136. y: coords.yAxis[0].value
  1137. }, {
  1138. x: coords.xAxis[0].value,
  1139. y: coords.yAxis[0].value
  1140. }]
  1141. },
  1142. labelOptions: {
  1143. style: {
  1144. color: '#666666'
  1145. }
  1146. }
  1147. }, navigation.annotationsOptions, navigation.bindings.fibonacci.annotationsOptions);
  1148. return this.chart.addAnnotation(options);
  1149. },
  1150. /** @ignore-option */
  1151. steps: [
  1152. bindingsUtils.updateNthPoint(1),
  1153. bindingsUtils.updateHeight
  1154. ]
  1155. },
  1156. /**
  1157. * A parallel channel (tunnel) annotation bindings. Includes `start` and
  1158. * two events in `steps` array (updates second point, then height).
  1159. *
  1160. * @type {Highcharts.NavigationBindingsOptionsObject}
  1161. * @product highstock
  1162. * @default {"className": "highcharts-parallel-channel", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  1163. */
  1164. parallelChannel: {
  1165. /** @ignore-option */
  1166. className: 'highcharts-parallel-channel',
  1167. // eslint-disable-next-line valid-jsdoc
  1168. /** @ignore-option */
  1169. start: function (e) {
  1170. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1171. langKey: 'parallelChannel',
  1172. type: 'tunnel',
  1173. typeOptions: {
  1174. points: [{
  1175. x: coords.xAxis[0].value,
  1176. y: coords.yAxis[0].value
  1177. }, {
  1178. x: coords.xAxis[0].value,
  1179. y: coords.yAxis[0].value
  1180. }]
  1181. }
  1182. }, navigation.annotationsOptions, navigation.bindings.parallelChannel.annotationsOptions);
  1183. return this.chart.addAnnotation(options);
  1184. },
  1185. /** @ignore-option */
  1186. steps: [
  1187. bindingsUtils.updateNthPoint(1),
  1188. bindingsUtils.updateHeight
  1189. ]
  1190. },
  1191. /**
  1192. * An Andrew's pitchfork annotation bindings. Includes `start` and two
  1193. * events in `steps` array (sets second and third control points).
  1194. *
  1195. * @type {Highcharts.NavigationBindingsOptionsObject}
  1196. * @product highstock
  1197. * @default {"className": "highcharts-pitchfork", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  1198. */
  1199. pitchfork: {
  1200. /** @ignore-option */
  1201. className: 'highcharts-pitchfork',
  1202. // eslint-disable-next-line valid-jsdoc
  1203. /** @ignore-option */
  1204. start: function (e) {
  1205. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1206. langKey: 'pitchfork',
  1207. type: 'pitchfork',
  1208. typeOptions: {
  1209. points: [{
  1210. x: coords.xAxis[0].value,
  1211. y: coords.yAxis[0].value,
  1212. controlPoint: {
  1213. style: {
  1214. fill: 'red'
  1215. }
  1216. }
  1217. }, {
  1218. x: coords.xAxis[0].value,
  1219. y: coords.yAxis[0].value
  1220. }, {
  1221. x: coords.xAxis[0].value,
  1222. y: coords.yAxis[0].value
  1223. }],
  1224. innerBackground: {
  1225. fill: 'rgba(100, 170, 255, 0.8)'
  1226. }
  1227. },
  1228. shapeOptions: {
  1229. strokeWidth: 2
  1230. }
  1231. }, navigation.annotationsOptions, navigation.bindings.pitchfork.annotationsOptions);
  1232. return this.chart.addAnnotation(options);
  1233. },
  1234. /** @ignore-option */
  1235. steps: [
  1236. bindingsUtils.updateNthPoint(1),
  1237. bindingsUtils.updateNthPoint(2)
  1238. ]
  1239. },
  1240. // Labels with arrow and auto increments
  1241. /**
  1242. * A vertical counter annotation bindings. Includes `start` event. On click,
  1243. * finds the closest point and marks it with a numeric annotation -
  1244. * incrementing counter on each add.
  1245. *
  1246. * @type {Highcharts.NavigationBindingsOptionsObject}
  1247. * @product highstock
  1248. * @default {"className": "highcharts-vertical-counter", "start": function() {}, "annotationsOptions": {}}
  1249. */
  1250. verticalCounter: {
  1251. /** @ignore-option */
  1252. className: 'highcharts-vertical-counter',
  1253. // eslint-disable-next-line valid-jsdoc
  1254. /** @ignore-option */
  1255. start: function (e) {
  1256. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, verticalCounter = !defined(this.verticalCounter) ? 0 :
  1257. this.verticalCounter, options = merge({
  1258. langKey: 'verticalCounter',
  1259. type: 'verticalLine',
  1260. typeOptions: {
  1261. point: {
  1262. x: closestPoint.x,
  1263. y: closestPoint.y,
  1264. xAxis: closestPoint.xAxis,
  1265. yAxis: closestPoint.yAxis
  1266. },
  1267. label: {
  1268. offset: closestPoint.below ? 40 : -40,
  1269. text: verticalCounter.toString()
  1270. }
  1271. },
  1272. labelOptions: {
  1273. style: {
  1274. color: '#666666',
  1275. fontSize: '11px'
  1276. }
  1277. },
  1278. shapeOptions: {
  1279. stroke: 'rgba(0, 0, 0, 0.75)',
  1280. strokeWidth: 1
  1281. }
  1282. }, navigation.annotationsOptions, navigation.bindings.verticalCounter.annotationsOptions), annotation;
  1283. annotation = this.chart.addAnnotation(options);
  1284. verticalCounter++;
  1285. annotation.options.events.click.call(annotation, {});
  1286. }
  1287. },
  1288. /**
  1289. * A vertical arrow annotation bindings. Includes `start` event. On click,
  1290. * finds the closest point and marks it with an arrow and a label with
  1291. * value.
  1292. *
  1293. * @type {Highcharts.NavigationBindingsOptionsObject}
  1294. * @product highstock
  1295. * @default {"className": "highcharts-vertical-label", "start": function() {}, "annotationsOptions": {}}
  1296. */
  1297. verticalLabel: {
  1298. /** @ignore-option */
  1299. className: 'highcharts-vertical-label',
  1300. // eslint-disable-next-line valid-jsdoc
  1301. /** @ignore-option */
  1302. start: function (e) {
  1303. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, options = merge({
  1304. langKey: 'verticalLabel',
  1305. type: 'verticalLine',
  1306. typeOptions: {
  1307. point: {
  1308. x: closestPoint.x,
  1309. y: closestPoint.y,
  1310. xAxis: closestPoint.xAxis,
  1311. yAxis: closestPoint.yAxis
  1312. },
  1313. label: {
  1314. offset: closestPoint.below ? 40 : -40
  1315. }
  1316. },
  1317. labelOptions: {
  1318. style: {
  1319. color: '#666666',
  1320. fontSize: '11px'
  1321. }
  1322. },
  1323. shapeOptions: {
  1324. stroke: 'rgba(0, 0, 0, 0.75)',
  1325. strokeWidth: 1
  1326. }
  1327. }, navigation.annotationsOptions, navigation.bindings.verticalLabel.annotationsOptions), annotation;
  1328. annotation = this.chart.addAnnotation(options);
  1329. annotation.options.events.click.call(annotation, {});
  1330. }
  1331. },
  1332. /**
  1333. * A vertical arrow annotation bindings. Includes `start` event. On click,
  1334. * finds the closest point and marks it with an arrow. Green arrow when
  1335. * pointing from above, red when pointing from below the point.
  1336. *
  1337. * @type {Highcharts.NavigationBindingsOptionsObject}
  1338. * @product highstock
  1339. * @default {"className": "highcharts-vertical-arrow", "start": function() {}, "annotationsOptions": {}}
  1340. */
  1341. verticalArrow: {
  1342. /** @ignore-option */
  1343. className: 'highcharts-vertical-arrow',
  1344. // eslint-disable-next-line valid-jsdoc
  1345. /** @ignore-option */
  1346. start: function (e) {
  1347. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, options = merge({
  1348. langKey: 'verticalArrow',
  1349. type: 'verticalLine',
  1350. typeOptions: {
  1351. point: {
  1352. x: closestPoint.x,
  1353. y: closestPoint.y,
  1354. xAxis: closestPoint.xAxis,
  1355. yAxis: closestPoint.yAxis
  1356. },
  1357. label: {
  1358. offset: closestPoint.below ? 40 : -40,
  1359. format: ' '
  1360. },
  1361. connector: {
  1362. fill: 'none',
  1363. stroke: closestPoint.below ? 'red' : 'green'
  1364. }
  1365. },
  1366. shapeOptions: {
  1367. stroke: 'rgba(0, 0, 0, 0.75)',
  1368. strokeWidth: 1
  1369. }
  1370. }, navigation.annotationsOptions, navigation.bindings.verticalArrow.annotationsOptions), annotation;
  1371. annotation = this.chart.addAnnotation(options);
  1372. annotation.options.events.click.call(annotation, {});
  1373. }
  1374. },
  1375. // Flag types:
  1376. /**
  1377. * A flag series bindings. Includes `start` event. On click, finds the
  1378. * closest point and marks it with a flag with `'circlepin'` shape.
  1379. *
  1380. * @type {Highcharts.NavigationBindingsOptionsObject}
  1381. * @product highstock
  1382. * @default {"className": "highcharts-flag-circlepin", "start": function() {}}
  1383. */
  1384. flagCirclepin: {
  1385. /** @ignore-option */
  1386. className: 'highcharts-flag-circlepin',
  1387. /** @ignore-option */
  1388. start: bindingsUtils.addFlagFromForm('circlepin')
  1389. },
  1390. /**
  1391. * A flag series bindings. Includes `start` event. On click, finds the
  1392. * closest point and marks it with a flag with `'diamondpin'` shape.
  1393. *
  1394. * @type {Highcharts.NavigationBindingsOptionsObject}
  1395. * @product highstock
  1396. * @default {"className": "highcharts-flag-diamondpin", "start": function() {}}
  1397. */
  1398. flagDiamondpin: {
  1399. /** @ignore-option */
  1400. className: 'highcharts-flag-diamondpin',
  1401. /** @ignore-option */
  1402. start: bindingsUtils.addFlagFromForm('flag')
  1403. },
  1404. /**
  1405. * A flag series bindings. Includes `start` event.
  1406. * On click, finds the closest point and marks it with a flag with
  1407. * `'squarepin'` shape.
  1408. *
  1409. * @type {Highcharts.NavigationBindingsOptionsObject}
  1410. * @product highstock
  1411. * @default {"className": "highcharts-flag-squarepin", "start": function() {}}
  1412. */
  1413. flagSquarepin: {
  1414. /** @ignore-option */
  1415. className: 'highcharts-flag-squarepin',
  1416. /** @ignore-option */
  1417. start: bindingsUtils.addFlagFromForm('squarepin')
  1418. },
  1419. /**
  1420. * A flag series bindings. Includes `start` event.
  1421. * On click, finds the closest point and marks it with a flag without pin
  1422. * shape.
  1423. *
  1424. * @type {Highcharts.NavigationBindingsOptionsObject}
  1425. * @product highstock
  1426. * @default {"className": "highcharts-flag-simplepin", "start": function() {}}
  1427. */
  1428. flagSimplepin: {
  1429. /** @ignore-option */
  1430. className: 'highcharts-flag-simplepin',
  1431. /** @ignore-option */
  1432. start: bindingsUtils.addFlagFromForm('nopin')
  1433. },
  1434. // Other tools:
  1435. /**
  1436. * Enables zooming in xAxis on a chart. Includes `start` event which
  1437. * changes [chart.zoomType](#chart.zoomType).
  1438. *
  1439. * @type {Highcharts.NavigationBindingsOptionsObject}
  1440. * @product highstock
  1441. * @default {"className": "highcharts-zoom-x", "init": function() {}}
  1442. */
  1443. zoomX: {
  1444. /** @ignore-option */
  1445. className: 'highcharts-zoom-x',
  1446. // eslint-disable-next-line valid-jsdoc
  1447. /** @ignore-option */
  1448. init: function (button) {
  1449. this.chart.update({
  1450. chart: {
  1451. zoomType: 'x'
  1452. }
  1453. });
  1454. fireEvent(this, 'deselectButton', { button: button });
  1455. }
  1456. },
  1457. /**
  1458. * Enables zooming in yAxis on a chart. Includes `start` event which
  1459. * changes [chart.zoomType](#chart.zoomType).
  1460. *
  1461. * @type {Highcharts.NavigationBindingsOptionsObject}
  1462. * @product highstock
  1463. * @default {"className": "highcharts-zoom-y", "init": function() {}}
  1464. */
  1465. zoomY: {
  1466. /** @ignore-option */
  1467. className: 'highcharts-zoom-y',
  1468. // eslint-disable-next-line valid-jsdoc
  1469. /** @ignore-option */
  1470. init: function (button) {
  1471. this.chart.update({
  1472. chart: {
  1473. zoomType: 'y'
  1474. }
  1475. });
  1476. fireEvent(this, 'deselectButton', { button: button });
  1477. }
  1478. },
  1479. /**
  1480. * Enables zooming in xAxis and yAxis on a chart. Includes `start` event
  1481. * which changes [chart.zoomType](#chart.zoomType).
  1482. *
  1483. * @type {Highcharts.NavigationBindingsOptionsObject}
  1484. * @product highstock
  1485. * @default {"className": "highcharts-zoom-xy", "init": function() {}}
  1486. */
  1487. zoomXY: {
  1488. /** @ignore-option */
  1489. className: 'highcharts-zoom-xy',
  1490. // eslint-disable-next-line valid-jsdoc
  1491. /** @ignore-option */
  1492. init: function (button) {
  1493. this.chart.update({
  1494. chart: {
  1495. zoomType: 'xy'
  1496. }
  1497. });
  1498. fireEvent(this, 'deselectButton', { button: button });
  1499. }
  1500. },
  1501. /**
  1502. * Changes main series to `'line'` type.
  1503. *
  1504. * @type {Highcharts.NavigationBindingsOptionsObject}
  1505. * @product highstock
  1506. * @default {"className": "highcharts-series-type-line", "init": function() {}}
  1507. */
  1508. seriesTypeLine: {
  1509. /** @ignore-option */
  1510. className: 'highcharts-series-type-line',
  1511. // eslint-disable-next-line valid-jsdoc
  1512. /** @ignore-option */
  1513. init: function (button) {
  1514. this.chart.series[0].update({
  1515. type: 'line',
  1516. useOhlcData: true
  1517. });
  1518. fireEvent(this, 'deselectButton', { button: button });
  1519. }
  1520. },
  1521. /**
  1522. * Changes main series to `'ohlc'` type.
  1523. *
  1524. * @type {Highcharts.NavigationBindingsOptionsObject}
  1525. * @product highstock
  1526. * @default {"className": "highcharts-series-type-ohlc", "init": function() {}}
  1527. */
  1528. seriesTypeOhlc: {
  1529. /** @ignore-option */
  1530. className: 'highcharts-series-type-ohlc',
  1531. // eslint-disable-next-line valid-jsdoc
  1532. /** @ignore-option */
  1533. init: function (button) {
  1534. this.chart.series[0].update({
  1535. type: 'ohlc'
  1536. });
  1537. fireEvent(this, 'deselectButton', { button: button });
  1538. }
  1539. },
  1540. /**
  1541. * Changes main series to `'candlestick'` type.
  1542. *
  1543. * @type {Highcharts.NavigationBindingsOptionsObject}
  1544. * @product highstock
  1545. * @default {"className": "highcharts-series-type-candlestick", "init": function() {}}
  1546. */
  1547. seriesTypeCandlestick: {
  1548. /** @ignore-option */
  1549. className: 'highcharts-series-type-candlestick',
  1550. // eslint-disable-next-line valid-jsdoc
  1551. /** @ignore-option */
  1552. init: function (button) {
  1553. this.chart.series[0].update({
  1554. type: 'candlestick'
  1555. });
  1556. fireEvent(this, 'deselectButton', { button: button });
  1557. }
  1558. },
  1559. /**
  1560. * Displays chart in fullscreen.
  1561. *
  1562. * **Note**: Fullscreen is not supported on iPhone due to iOS limitations.
  1563. *
  1564. * @type {Highcharts.NavigationBindingsOptionsObject}
  1565. * @product highstock
  1566. * @default {"className": "highcharts-full-screen", "init": function() {}}
  1567. */
  1568. fullScreen: {
  1569. /** @ignore-option */
  1570. className: 'highcharts-full-screen',
  1571. // eslint-disable-next-line valid-jsdoc
  1572. /** @ignore-option */
  1573. init: function (button) {
  1574. this.chart.fullscreen.toggle();
  1575. fireEvent(this, 'deselectButton', { button: button });
  1576. }
  1577. },
  1578. /**
  1579. * Hides/shows two price indicators:
  1580. * - last price in the dataset
  1581. * - last price in the selected range
  1582. *
  1583. * @type {Highcharts.NavigationBindingsOptionsObject}
  1584. * @product highstock
  1585. * @default {"className": "highcharts-current-price-indicator", "init": function() {}}
  1586. */
  1587. currentPriceIndicator: {
  1588. /** @ignore-option */
  1589. className: 'highcharts-current-price-indicator',
  1590. // eslint-disable-next-line valid-jsdoc
  1591. /** @ignore-option */
  1592. init: function (button) {
  1593. var chart = this.chart, series = chart.series[0], options = series.options, lastVisiblePrice = (options.lastVisiblePrice &&
  1594. options.lastVisiblePrice.enabled), lastPrice = options.lastPrice && options.lastPrice.enabled, gui = chart.stockTools, iconsURL = gui.getIconsURL();
  1595. if (gui && gui.guiEnabled) {
  1596. if (lastPrice) {
  1597. button.firstChild.style['background-image'] =
  1598. 'url("' + iconsURL +
  1599. 'current-price-show.svg")';
  1600. }
  1601. else {
  1602. button.firstChild.style['background-image'] =
  1603. 'url("' + iconsURL +
  1604. 'current-price-hide.svg")';
  1605. }
  1606. }
  1607. series.update({
  1608. // line
  1609. lastPrice: {
  1610. enabled: !lastPrice,
  1611. color: 'red'
  1612. },
  1613. // label
  1614. lastVisiblePrice: {
  1615. enabled: !lastVisiblePrice,
  1616. label: {
  1617. enabled: true
  1618. }
  1619. }
  1620. });
  1621. fireEvent(this, 'deselectButton', { button: button });
  1622. }
  1623. },
  1624. /**
  1625. * Indicators bindings. Includes `init` event to show a popup.
  1626. *
  1627. * Note: In order to show base series from the chart in the popup's
  1628. * dropdown each series requires
  1629. * [series.id](https://api.highcharts.com/highstock/series.line.id) to be
  1630. * defined.
  1631. *
  1632. * @type {Highcharts.NavigationBindingsOptionsObject}
  1633. * @product highstock
  1634. * @default {"className": "highcharts-indicators", "init": function() {}}
  1635. */
  1636. indicators: {
  1637. /** @ignore-option */
  1638. className: 'highcharts-indicators',
  1639. // eslint-disable-next-line valid-jsdoc
  1640. /** @ignore-option */
  1641. init: function () {
  1642. var navigation = this;
  1643. fireEvent(navigation, 'showPopup', {
  1644. formType: 'indicators',
  1645. options: {},
  1646. // Callback on submit:
  1647. onSubmit: function (data) {
  1648. navigation.utils.manageIndicators.call(navigation, data);
  1649. }
  1650. });
  1651. }
  1652. },
  1653. /**
  1654. * Hides/shows all annotations on a chart.
  1655. *
  1656. * @type {Highcharts.NavigationBindingsOptionsObject}
  1657. * @product highstock
  1658. * @default {"className": "highcharts-toggle-annotations", "init": function() {}}
  1659. */
  1660. toggleAnnotations: {
  1661. /** @ignore-option */
  1662. className: 'highcharts-toggle-annotations',
  1663. // eslint-disable-next-line valid-jsdoc
  1664. /** @ignore-option */
  1665. init: function (button) {
  1666. var chart = this.chart, gui = chart.stockTools, iconsURL = gui.getIconsURL();
  1667. this.toggledAnnotations = !this.toggledAnnotations;
  1668. (chart.annotations || []).forEach(function (annotation) {
  1669. annotation.setVisibility(!this.toggledAnnotations);
  1670. }, this);
  1671. if (gui && gui.guiEnabled) {
  1672. if (this.toggledAnnotations) {
  1673. button.firstChild.style['background-image'] =
  1674. 'url("' + iconsURL +
  1675. 'annotations-hidden.svg")';
  1676. }
  1677. else {
  1678. button.firstChild.style['background-image'] =
  1679. 'url("' + iconsURL +
  1680. 'annotations-visible.svg")';
  1681. }
  1682. }
  1683. fireEvent(this, 'deselectButton', { button: button });
  1684. }
  1685. },
  1686. /**
  1687. * Save a chart in localStorage under `highcharts-chart` key.
  1688. * Stored items:
  1689. * - annotations
  1690. * - indicators (with yAxes)
  1691. * - flags
  1692. *
  1693. * @type {Highcharts.NavigationBindingsOptionsObject}
  1694. * @product highstock
  1695. * @default {"className": "highcharts-save-chart", "init": function() {}}
  1696. */
  1697. saveChart: {
  1698. /** @ignore-option */
  1699. className: 'highcharts-save-chart',
  1700. // eslint-disable-next-line valid-jsdoc
  1701. /** @ignore-option */
  1702. init: function (button) {
  1703. var navigation = this, chart = navigation.chart, annotations = [], indicators = [], flags = [], yAxes = [];
  1704. chart.annotations.forEach(function (annotation, index) {
  1705. annotations[index] = annotation.userOptions;
  1706. });
  1707. chart.series.forEach(function (series) {
  1708. if (series.is('sma')) {
  1709. indicators.push(series.userOptions);
  1710. }
  1711. else if (series.type === 'flags') {
  1712. flags.push(series.userOptions);
  1713. }
  1714. });
  1715. chart.yAxis.forEach(function (yAxis) {
  1716. if (bindingsUtils.isNotNavigatorYAxis(yAxis)) {
  1717. yAxes.push(yAxis.options);
  1718. }
  1719. });
  1720. H.win.localStorage.setItem(PREFIX + 'chart', JSON.stringify({
  1721. annotations: annotations,
  1722. indicators: indicators,
  1723. flags: flags,
  1724. yAxes: yAxes
  1725. }));
  1726. fireEvent(this, 'deselectButton', { button: button });
  1727. }
  1728. }
  1729. };
  1730. setOptions({
  1731. navigation: {
  1732. bindings: stockToolsBindings
  1733. }
  1734. });
  1735. NavigationBindings.prototype.utils = merge(bindingsUtils, NavigationBindings.prototype.utils);