stock-tools-bindings.js 64 KB

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