stock-tools.src.js 136 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075
  1. /**
  2. * @license Highstock JS v8.0.0 (2019-12-10)
  3. *
  4. * Advanced Highstock tools
  5. *
  6. * (c) 2010-2019 Highsoft AS
  7. * Author: Torstein Honsi
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. factory['default'] = factory;
  15. module.exports = factory;
  16. } else if (typeof define === 'function' && define.amd) {
  17. define('highcharts/modules/stock-tools', ['highcharts', 'highcharts/modules/stock'], function (Highcharts) {
  18. factory(Highcharts);
  19. factory.Highcharts = Highcharts;
  20. return factory;
  21. });
  22. } else {
  23. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  24. }
  25. }(function (Highcharts) {
  26. var _modules = Highcharts ? Highcharts._modules : {};
  27. function _registerModule(obj, path, args, fn) {
  28. if (!obj.hasOwnProperty(path)) {
  29. obj[path] = fn.apply(null, args);
  30. }
  31. }
  32. _registerModule(_modules, 'modules/stock-tools-bindings.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  33. /**
  34. *
  35. * Events generator for Stock tools
  36. *
  37. * (c) 2009-2019 Paweł Fus
  38. *
  39. * License: www.highcharts.com/license
  40. *
  41. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  42. *
  43. * */
  44. /**
  45. * A config object for bindings in Stock Tools module.
  46. *
  47. * @interface Highcharts.StockToolsBindingsObject
  48. */ /**
  49. * ClassName of the element for a binding.
  50. * @name Highcharts.StockToolsBindingsObject#className
  51. * @type {string|undefined}
  52. */ /**
  53. * Last event to be fired after last step event.
  54. * @name Highcharts.StockToolsBindingsObject#end
  55. * @type {Function|undefined}
  56. */ /**
  57. * Initial event, fired on a button click.
  58. * @name Highcharts.StockToolsBindingsObject#init
  59. * @type {Function|undefined}
  60. */ /**
  61. * Event fired on first click on a chart.
  62. * @name Highcharts.StockToolsBindingsObject#start
  63. * @type {Function|undefined}
  64. */ /**
  65. * Last event to be fired after last step event. Array of step events to be
  66. * called sequentially after each user click.
  67. * @name Highcharts.StockToolsBindingsObject#steps
  68. * @type {Array<Function>|undefined}
  69. */
  70. var correctFloat = U.correctFloat, defined = U.defined, extend = U.extend, isNumber = U.isNumber, pick = U.pick;
  71. var fireEvent = H.fireEvent, merge = H.merge, bindingsUtils = H.NavigationBindings.prototype.utils, PREFIX = 'highcharts-';
  72. /* eslint-disable no-invalid-this */
  73. /**
  74. * Generates function which will add a flag series using modal in GUI.
  75. * Method fires an event "showPopup" with config:
  76. * `{type, options, callback}`.
  77. *
  78. * Example: NavigationBindings.utils.addFlagFromForm('url(...)') - will
  79. * generate function that shows modal in GUI.
  80. *
  81. * @private
  82. * @function bindingsUtils.addFlagFromForm
  83. *
  84. * @param {string} type
  85. * Type of flag series, e.g. "squarepin"
  86. *
  87. * @return {Function}
  88. * Callback to be used in `start` callback
  89. */
  90. bindingsUtils.addFlagFromForm = function (type) {
  91. return function (e) {
  92. var navigation = this, chart = navigation.chart, toolbar = chart.stockTools, getFieldType = bindingsUtils.getFieldType, point = bindingsUtils.attractToPoint(e, chart), pointConfig = {
  93. x: point.x,
  94. y: point.y
  95. }, seriesOptions = {
  96. type: 'flags',
  97. onSeries: point.series.id,
  98. shape: type,
  99. data: [pointConfig],
  100. point: {
  101. events: {
  102. click: function () {
  103. var point = this, options = point.options;
  104. fireEvent(navigation, 'showPopup', {
  105. point: point,
  106. formType: 'annotation-toolbar',
  107. options: {
  108. langKey: 'flags',
  109. type: 'flags',
  110. title: [
  111. options.title,
  112. getFieldType(options.title)
  113. ],
  114. name: [
  115. options.name,
  116. getFieldType(options.name)
  117. ]
  118. },
  119. onSubmit: function (updated) {
  120. if (updated.actionType === 'remove') {
  121. point.remove();
  122. }
  123. else {
  124. point.update(navigation.fieldsToOptions(updated.fields, {}));
  125. }
  126. }
  127. });
  128. }
  129. }
  130. }
  131. };
  132. if (!toolbar || !toolbar.guiEnabled) {
  133. chart.addSeries(seriesOptions);
  134. }
  135. fireEvent(navigation, 'showPopup', {
  136. formType: 'flag',
  137. // Enabled options:
  138. options: {
  139. langKey: 'flags',
  140. type: 'flags',
  141. title: ['A', getFieldType('A')],
  142. name: ['Flag A', getFieldType('Flag A')]
  143. },
  144. // Callback on submit:
  145. onSubmit: function (data) {
  146. navigation.fieldsToOptions(data.fields, seriesOptions.data[0]);
  147. chart.addSeries(seriesOptions);
  148. }
  149. });
  150. };
  151. };
  152. bindingsUtils.manageIndicators = function (data) {
  153. var navigation = this, chart = navigation.chart, seriesConfig = {
  154. linkedTo: data.linkedTo,
  155. type: data.type
  156. }, indicatorsWithVolume = [
  157. 'ad',
  158. 'cmf',
  159. 'mfi',
  160. 'vbp',
  161. 'vwap'
  162. ], indicatorsWithAxes = [
  163. 'ad',
  164. 'atr',
  165. 'cci',
  166. 'cmf',
  167. 'macd',
  168. 'mfi',
  169. 'roc',
  170. 'rsi',
  171. 'ao',
  172. 'aroon',
  173. 'aroonoscillator',
  174. 'trix',
  175. 'apo',
  176. 'dpo',
  177. 'ppo',
  178. 'natr',
  179. 'williamsr',
  180. 'stochastic',
  181. 'slowstochastic',
  182. 'linearRegression',
  183. 'linearRegressionSlope',
  184. 'linearRegressionIntercept',
  185. 'linearRegressionAngle'
  186. ], yAxis, series;
  187. if (data.actionType === 'edit') {
  188. navigation.fieldsToOptions(data.fields, seriesConfig);
  189. series = chart.get(data.seriesId);
  190. if (series) {
  191. series.update(seriesConfig, false);
  192. }
  193. }
  194. else if (data.actionType === 'remove') {
  195. series = chart.get(data.seriesId);
  196. if (series) {
  197. yAxis = series.yAxis;
  198. if (series.linkedSeries) {
  199. series.linkedSeries.forEach(function (linkedSeries) {
  200. linkedSeries.remove(false);
  201. });
  202. }
  203. series.remove(false);
  204. if (indicatorsWithAxes.indexOf(series.type) >= 0) {
  205. yAxis.remove(false);
  206. navigation.resizeYAxes();
  207. }
  208. }
  209. }
  210. else {
  211. seriesConfig.id = H.uniqueKey();
  212. navigation.fieldsToOptions(data.fields, seriesConfig);
  213. if (indicatorsWithAxes.indexOf(data.type) >= 0) {
  214. yAxis = chart.addAxis({
  215. id: H.uniqueKey(),
  216. offset: 0,
  217. opposite: true,
  218. title: {
  219. text: ''
  220. },
  221. tickPixelInterval: 40,
  222. showLastLabel: false,
  223. labels: {
  224. align: 'left',
  225. y: -2
  226. }
  227. }, false, false);
  228. seriesConfig.yAxis = yAxis.options.id;
  229. navigation.resizeYAxes();
  230. }
  231. else {
  232. seriesConfig.yAxis = chart.get(data.linkedTo).options.yAxis;
  233. }
  234. if (indicatorsWithVolume.indexOf(data.type) >= 0) {
  235. seriesConfig.params.volumeSeriesID = chart.series.filter(function (series) {
  236. return series.options.type === 'column';
  237. })[0].options.id;
  238. }
  239. chart.addSeries(seriesConfig, false);
  240. }
  241. fireEvent(navigation, 'deselectButton', {
  242. button: navigation.selectedButtonElement
  243. });
  244. chart.redraw();
  245. };
  246. /**
  247. * Update height for an annotation. Height is calculated as a difference
  248. * between last point in `typeOptions` and current position. It's a value,
  249. * not pixels height.
  250. *
  251. * @private
  252. * @function bindingsUtils.updateHeight
  253. *
  254. * @param {global.Event} e
  255. * normalized browser event
  256. *
  257. * @param {Highcharts.Annotation} annotation
  258. * Annotation to be updated
  259. *
  260. * @return {void}
  261. */
  262. bindingsUtils.updateHeight = function (e, annotation) {
  263. annotation.update({
  264. typeOptions: {
  265. height: this.chart.pointer.getCoordinates(e).yAxis[0].value -
  266. annotation.options.typeOptions.points[1].y
  267. }
  268. });
  269. };
  270. // @todo
  271. // Consider using getHoverData(), but always kdTree (columns?)
  272. bindingsUtils.attractToPoint = function (e, chart) {
  273. var coords = chart.pointer.getCoordinates(e), x = coords.xAxis[0].value, y = coords.yAxis[0].value, distX = Number.MAX_VALUE, closestPoint;
  274. chart.series.forEach(function (series) {
  275. series.points.forEach(function (point) {
  276. if (point && distX > Math.abs(point.x - x)) {
  277. distX = Math.abs(point.x - x);
  278. closestPoint = point;
  279. }
  280. });
  281. });
  282. return {
  283. x: closestPoint.x,
  284. y: closestPoint.y,
  285. below: y < closestPoint.y,
  286. series: closestPoint.series,
  287. xAxis: closestPoint.series.xAxis.index || 0,
  288. yAxis: closestPoint.series.yAxis.index || 0
  289. };
  290. };
  291. /**
  292. * Shorthand to check if given yAxis comes from navigator.
  293. *
  294. * @private
  295. * @function bindingsUtils.isNotNavigatorYAxis
  296. *
  297. * @param {Highcharts.Axis} axis
  298. * Axis to check.
  299. *
  300. * @return {boolean}
  301. * True, if axis comes from navigator.
  302. */
  303. bindingsUtils.isNotNavigatorYAxis = function (axis) {
  304. return axis.userOptions.className !== PREFIX + 'navigator-yaxis';
  305. };
  306. /**
  307. * Update each point after specified index, most of the annotations use
  308. * this. For example crooked line: logic behind updating each point is the
  309. * same, only index changes when adding an annotation.
  310. *
  311. * Example: NavigationBindings.utils.updateNthPoint(1) - will generate
  312. * function that updates all consecutive points except point with index=0.
  313. *
  314. * @private
  315. * @function bindingsUtils.updateNthPoint
  316. *
  317. * @param {number} startIndex
  318. * Index from each point should udpated
  319. *
  320. * @return {Function}
  321. * Callback to be used in steps array
  322. */
  323. bindingsUtils.updateNthPoint = function (startIndex) {
  324. return function (e, annotation) {
  325. var options = annotation.options.typeOptions, coords = this.chart.pointer.getCoordinates(e), x = coords.xAxis[0].value, y = coords.yAxis[0].value;
  326. options.points.forEach(function (point, index) {
  327. if (index >= startIndex) {
  328. point.x = x;
  329. point.y = y;
  330. }
  331. });
  332. annotation.update({
  333. typeOptions: {
  334. points: options.points
  335. }
  336. });
  337. };
  338. };
  339. // Extends NavigationBindigs to support indicators and resizers:
  340. extend(H.NavigationBindings.prototype, {
  341. /* eslint-disable valid-jsdoc */
  342. /**
  343. * Get current positions for all yAxes. If new axis does not have position,
  344. * returned is default height and last available top place.
  345. *
  346. * @private
  347. * @function Highcharts.NavigationBindings#getYAxisPositions
  348. *
  349. * @param {Array<Highcharts.Axis>} yAxes
  350. * Array of yAxes available in the chart.
  351. *
  352. * @param {number} plotHeight
  353. * Available height in the chart.
  354. *
  355. * @param {number} defaultHeight
  356. * Default height in percents.
  357. *
  358. * @return {Array}
  359. * An array of calculated positions in percentages.
  360. * Format: `{top: Number, height: Number}`
  361. */
  362. getYAxisPositions: function (yAxes, plotHeight, defaultHeight) {
  363. var positions, allAxesHeight = 0;
  364. /** @private */
  365. function isPercentage(prop) {
  366. return defined(prop) && !isNumber(prop) && prop.match('%');
  367. }
  368. positions = yAxes.map(function (yAxis) {
  369. var height = isPercentage(yAxis.options.height) ?
  370. parseFloat(yAxis.options.height) / 100 :
  371. yAxis.height / plotHeight, top = isPercentage(yAxis.options.top) ?
  372. parseFloat(yAxis.options.top) / 100 :
  373. correctFloat(yAxis.top - yAxis.chart.plotTop) / plotHeight;
  374. // New yAxis does not contain "height" info yet
  375. if (!isNumber(height)) {
  376. height = defaultHeight / 100;
  377. }
  378. allAxesHeight = correctFloat(allAxesHeight + height);
  379. return {
  380. height: height * 100,
  381. top: top * 100
  382. };
  383. });
  384. positions.allAxesHeight = allAxesHeight;
  385. return positions;
  386. },
  387. /**
  388. * Get current resize options for each yAxis. Note that each resize is
  389. * linked to the next axis, except the last one which shouldn't affect
  390. * axes in the navigator. Because indicator can be removed with it's yAxis
  391. * in the middle of yAxis array, we need to bind closest yAxes back.
  392. *
  393. * @private
  394. * @function Highcharts.NavigationBindings#getYAxisResizers
  395. *
  396. * @param {Array<Highcharts.Axis>} yAxes
  397. * Array of yAxes available in the chart
  398. *
  399. * @return {Array<object>}
  400. * An array of resizer options.
  401. * Format: `{enabled: Boolean, controlledAxis: { next: [String]}}`
  402. */
  403. getYAxisResizers: function (yAxes) {
  404. var resizers = [];
  405. yAxes.forEach(function (yAxis, index) {
  406. var nextYAxis = yAxes[index + 1];
  407. // We have next axis, bind them:
  408. if (nextYAxis) {
  409. resizers[index] = {
  410. enabled: true,
  411. controlledAxis: {
  412. next: [
  413. pick(nextYAxis.options.id, nextYAxis.options.index)
  414. ]
  415. }
  416. };
  417. }
  418. else {
  419. // Remove binding:
  420. resizers[index] = {
  421. enabled: false
  422. };
  423. }
  424. });
  425. return resizers;
  426. },
  427. /**
  428. * Resize all yAxes (except navigator) to fit the plotting height. Method
  429. * checks if new axis is added, then shrinks other main axis up to 5 panes.
  430. * If added is more thatn 5 panes, it rescales all other axes to fit new
  431. * yAxis.
  432. *
  433. * If axis is removed, and we have more than 5 panes, rescales all other
  434. * axes. If chart has less than 5 panes, first pane receives all extra
  435. * space.
  436. *
  437. * @private
  438. * @function Highcharts.NavigationBindings#resizeYAxes
  439. * @param {number} defaultHeight
  440. * Default height for yAxis
  441. * @return {void}
  442. */
  443. resizeYAxes: function (defaultHeight) {
  444. defaultHeight = defaultHeight || 20; // in %, but as a number
  445. var chart = this.chart,
  446. // Only non-navigator axes
  447. yAxes = chart.yAxis.filter(this.utils.isNotNavigatorYAxis), plotHeight = chart.plotHeight, allAxesLength = yAxes.length,
  448. // Gather current heights (in %)
  449. positions = this.getYAxisPositions(yAxes, plotHeight, defaultHeight), resizers = this.getYAxisResizers(yAxes), allAxesHeight = positions.allAxesHeight, changedSpace = defaultHeight;
  450. // More than 100%
  451. if (allAxesHeight > 1) {
  452. // Simple case, add new panes up to 5
  453. if (allAxesLength < 6) {
  454. // Added axis, decrease first pane's height:
  455. positions[0].height = correctFloat(positions[0].height - changedSpace);
  456. // And update all other "top" positions:
  457. positions = this.recalculateYAxisPositions(positions, changedSpace);
  458. }
  459. else {
  460. // We have more panes, rescale all others to gain some space,
  461. // This is new height for upcoming yAxis:
  462. defaultHeight = 100 / allAxesLength;
  463. // This is how much we need to take from each other yAxis:
  464. changedSpace = defaultHeight / (allAxesLength - 1);
  465. // Now update all positions:
  466. positions = this.recalculateYAxisPositions(positions, changedSpace, true, -1);
  467. }
  468. // Set last position manually:
  469. positions[allAxesLength - 1] = {
  470. top: correctFloat(100 - defaultHeight),
  471. height: defaultHeight
  472. };
  473. }
  474. else {
  475. // Less than 100%
  476. changedSpace = correctFloat(1 - allAxesHeight) * 100;
  477. // Simple case, return first pane it's space:
  478. if (allAxesLength < 5) {
  479. positions[0].height = correctFloat(positions[0].height + changedSpace);
  480. positions = this.recalculateYAxisPositions(positions, changedSpace);
  481. }
  482. else {
  483. // There were more panes, return to each pane a bit of space:
  484. changedSpace /= allAxesLength;
  485. // Removed axis, add extra space to the first pane:
  486. // And update all other positions:
  487. positions = this.recalculateYAxisPositions(positions, changedSpace, true, 1);
  488. }
  489. }
  490. positions.forEach(function (position, index) {
  491. // if (index === 0) debugger;
  492. yAxes[index].update({
  493. height: position.height + '%',
  494. top: position.top + '%',
  495. resize: resizers[index]
  496. }, false);
  497. });
  498. },
  499. /**
  500. * Utility to modify calculated positions according to the remaining/needed
  501. * space. Later, these positions are used in `yAxis.update({ top, height })`
  502. *
  503. * @private
  504. * @function Highcharts.NavigationBindings#recalculateYAxisPositions
  505. * @param {Array<Highcharts.Dictionary<number>>} positions
  506. * Default positions of all yAxes.
  507. * @param {number} changedSpace
  508. * How much space should be added or removed.
  509. * @param {boolean} modifyHeight
  510. * Update only `top` or both `top` and `height`.
  511. * @param {number} adder
  512. * `-1` or `1`, to determine whether we should add or remove space.
  513. *
  514. * @return {Array<object>}
  515. * Modified positions,
  516. */
  517. recalculateYAxisPositions: function (positions, changedSpace, modifyHeight, adder) {
  518. positions.forEach(function (position, index) {
  519. var prevPosition = positions[index - 1];
  520. position.top = !prevPosition ? 0 :
  521. correctFloat(prevPosition.height + prevPosition.top);
  522. if (modifyHeight) {
  523. position.height = correctFloat(position.height + adder * changedSpace);
  524. }
  525. });
  526. return positions;
  527. }
  528. /* eslint-enable valid-jsdoc */
  529. });
  530. /**
  531. * @type {Highcharts.Dictionary<Highcharts.StockToolsBindingsObject>|*}
  532. * @since 7.0.0
  533. * @optionparent navigation.bindings
  534. */
  535. var stockToolsBindings = {
  536. // Line type annotations:
  537. /**
  538. * A segment annotation bindings. Includes `start` and one event in `steps`
  539. * array.
  540. *
  541. * @type {Highcharts.StockToolsBindingsObject}
  542. * @product highstock
  543. * @default {"className": "highcharts-segment", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  544. */
  545. segment: {
  546. /** @ignore*/
  547. className: 'highcharts-segment',
  548. // eslint-disable-next-line valid-jsdoc
  549. /** @ignore*/
  550. start: function (e) {
  551. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  552. langKey: 'segment',
  553. type: 'crookedLine',
  554. typeOptions: {
  555. points: [{
  556. x: coords.xAxis[0].value,
  557. y: coords.yAxis[0].value
  558. }, {
  559. x: coords.xAxis[0].value,
  560. y: coords.yAxis[0].value
  561. }]
  562. }
  563. }, navigation.annotationsOptions, navigation.bindings.segment.annotationsOptions);
  564. return this.chart.addAnnotation(options);
  565. },
  566. /** @ignore*/
  567. steps: [
  568. bindingsUtils.updateNthPoint(1)
  569. ]
  570. },
  571. /**
  572. * A segment with an arrow annotation bindings. Includes `start` and one
  573. * event in `steps` array.
  574. *
  575. * @type {Highcharts.StockToolsBindingsObject}
  576. * @product highstock
  577. * @default {"className": "highcharts-arrow-segment", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  578. */
  579. arrowSegment: {
  580. /** @ignore*/
  581. className: 'highcharts-arrow-segment',
  582. // eslint-disable-next-line valid-jsdoc
  583. /** @ignore*/
  584. start: function (e) {
  585. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  586. langKey: 'arrowSegment',
  587. type: 'crookedLine',
  588. typeOptions: {
  589. line: {
  590. markerEnd: 'arrow'
  591. },
  592. points: [{
  593. x: coords.xAxis[0].value,
  594. y: coords.yAxis[0].value
  595. }, {
  596. x: coords.xAxis[0].value,
  597. y: coords.yAxis[0].value
  598. }]
  599. }
  600. }, navigation.annotationsOptions, navigation.bindings.arrowSegment.annotationsOptions);
  601. return this.chart.addAnnotation(options);
  602. },
  603. /** @ignore*/
  604. steps: [
  605. bindingsUtils.updateNthPoint(1)
  606. ]
  607. },
  608. /**
  609. * A ray annotation bindings. Includes `start` and one event in `steps`
  610. * array.
  611. *
  612. * @type {Highcharts.StockToolsBindingsObject}
  613. * @product highstock
  614. * @default {"className": "highcharts-ray", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  615. */
  616. ray: {
  617. /** @ignore*/
  618. className: 'highcharts-ray',
  619. // eslint-disable-next-line valid-jsdoc
  620. /** @ignore*/
  621. start: function (e) {
  622. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  623. langKey: 'ray',
  624. type: 'crookedLine',
  625. typeOptions: {
  626. type: 'ray',
  627. points: [{
  628. x: coords.xAxis[0].value,
  629. y: coords.yAxis[0].value
  630. }, {
  631. x: coords.xAxis[0].value,
  632. y: coords.yAxis[0].value
  633. }]
  634. }
  635. }, navigation.annotationsOptions, navigation.bindings.ray.annotationsOptions);
  636. return this.chart.addAnnotation(options);
  637. },
  638. /** @ignore*/
  639. steps: [
  640. bindingsUtils.updateNthPoint(1)
  641. ]
  642. },
  643. /**
  644. * A ray with an arrow annotation bindings. Includes `start` and one event
  645. * in `steps` array.
  646. *
  647. * @type {Highcharts.StockToolsBindingsObject}
  648. * @product highstock
  649. * @default {"className": "highcharts-arrow-ray", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  650. */
  651. arrowRay: {
  652. /** @ignore*/
  653. className: 'highcharts-arrow-ray',
  654. // eslint-disable-next-line valid-jsdoc
  655. /** @ignore*/
  656. start: function (e) {
  657. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  658. langKey: 'arrowRay',
  659. type: 'infinityLine',
  660. typeOptions: {
  661. type: 'ray',
  662. line: {
  663. markerEnd: 'arrow'
  664. },
  665. points: [{
  666. x: coords.xAxis[0].value,
  667. y: coords.yAxis[0].value
  668. }, {
  669. x: coords.xAxis[0].value,
  670. y: coords.yAxis[0].value
  671. }]
  672. }
  673. }, navigation.annotationsOptions, navigation.bindings.arrowRay.annotationsOptions);
  674. return this.chart.addAnnotation(options);
  675. },
  676. /** @ignore*/
  677. steps: [
  678. bindingsUtils.updateNthPoint(1)
  679. ]
  680. },
  681. /**
  682. * A line annotation. Includes `start` and one event in `steps` array.
  683. *
  684. * @type {Highcharts.StockToolsBindingsObject}
  685. * @product highstock
  686. * @default {"className": "highcharts-infinity-line", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  687. */
  688. infinityLine: {
  689. /** @ignore*/
  690. className: 'highcharts-infinity-line',
  691. // eslint-disable-next-line valid-jsdoc
  692. /** @ignore*/
  693. start: function (e) {
  694. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  695. langKey: 'infinityLine',
  696. type: 'infinityLine',
  697. typeOptions: {
  698. type: 'line',
  699. points: [{
  700. x: coords.xAxis[0].value,
  701. y: coords.yAxis[0].value
  702. }, {
  703. x: coords.xAxis[0].value,
  704. y: coords.yAxis[0].value
  705. }]
  706. }
  707. }, navigation.annotationsOptions, navigation.bindings.infinityLine.annotationsOptions);
  708. return this.chart.addAnnotation(options);
  709. },
  710. /** @ignore*/
  711. steps: [
  712. bindingsUtils.updateNthPoint(1)
  713. ]
  714. },
  715. /**
  716. * A line with arrow annotation. Includes `start` and one event in `steps`
  717. * array.
  718. *
  719. * @type {Highcharts.StockToolsBindingsObject}
  720. * @product highstock
  721. * @default {"className": "highcharts-arrow-infinity-line", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  722. */
  723. arrowInfinityLine: {
  724. /** @ignore*/
  725. className: 'highcharts-arrow-infinity-line',
  726. // eslint-disable-next-line valid-jsdoc
  727. /** @ignore*/
  728. start: function (e) {
  729. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  730. langKey: 'arrowInfinityLine',
  731. type: 'infinityLine',
  732. typeOptions: {
  733. type: 'line',
  734. line: {
  735. markerEnd: 'arrow'
  736. },
  737. points: [{
  738. x: coords.xAxis[0].value,
  739. y: coords.yAxis[0].value
  740. }, {
  741. x: coords.xAxis[0].value,
  742. y: coords.yAxis[0].value
  743. }]
  744. }
  745. }, navigation.annotationsOptions, navigation.bindings.arrowInfinityLine.annotationsOptions);
  746. return this.chart.addAnnotation(options);
  747. },
  748. /** @ignore*/
  749. steps: [
  750. bindingsUtils.updateNthPoint(1)
  751. ]
  752. },
  753. /**
  754. * A horizontal line annotation. Includes `start` event.
  755. *
  756. * @type {Highcharts.StockToolsBindingsObject}
  757. * @product highstock
  758. * @default {"className": "highcharts-horizontal-line", "start": function() {}, "annotationsOptions": {}}
  759. */
  760. horizontalLine: {
  761. /** @ignore*/
  762. className: 'highcharts-horizontal-line',
  763. // eslint-disable-next-line valid-jsdoc
  764. /** @ignore*/
  765. start: function (e) {
  766. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  767. langKey: 'horizontalLine',
  768. type: 'infinityLine',
  769. draggable: 'y',
  770. typeOptions: {
  771. type: 'horizontalLine',
  772. points: [{
  773. x: coords.xAxis[0].value,
  774. y: coords.yAxis[0].value
  775. }]
  776. }
  777. }, navigation.annotationsOptions, navigation.bindings.horizontalLine.annotationsOptions);
  778. this.chart.addAnnotation(options);
  779. }
  780. },
  781. /**
  782. * A vertical line annotation. Includes `start` event.
  783. *
  784. * @type {Highcharts.StockToolsBindingsObject}
  785. * @product highstock
  786. * @default {"className": "highcharts-vertical-line", "start": function() {}, "annotationsOptions": {}}
  787. */
  788. verticalLine: {
  789. /** @ignore*/
  790. className: 'highcharts-vertical-line',
  791. // eslint-disable-next-line valid-jsdoc
  792. /** @ignore*/
  793. start: function (e) {
  794. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  795. langKey: 'verticalLine',
  796. type: 'infinityLine',
  797. draggable: 'x',
  798. typeOptions: {
  799. type: 'verticalLine',
  800. points: [{
  801. x: coords.xAxis[0].value,
  802. y: coords.yAxis[0].value
  803. }]
  804. }
  805. }, navigation.annotationsOptions, navigation.bindings.verticalLine.annotationsOptions);
  806. this.chart.addAnnotation(options);
  807. }
  808. },
  809. /**
  810. * Crooked line (three points) annotation bindings. Includes `start` and two
  811. * events in `steps` (for second and third points in crooked line) array.
  812. *
  813. * @type {Highcharts.StockToolsBindingsObject}
  814. * @product highstock
  815. * @default {"className": "highcharts-crooked3", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  816. */
  817. // Crooked Line type annotations:
  818. crooked3: {
  819. /** @ignore*/
  820. className: 'highcharts-crooked3',
  821. // eslint-disable-next-line valid-jsdoc
  822. /** @ignore*/
  823. start: function (e) {
  824. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  825. langKey: 'crooked3',
  826. type: 'crookedLine',
  827. typeOptions: {
  828. points: [{
  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. }
  839. }, navigation.annotationsOptions, navigation.bindings.crooked3.annotationsOptions);
  840. return this.chart.addAnnotation(options);
  841. },
  842. /** @ignore*/
  843. steps: [
  844. bindingsUtils.updateNthPoint(1),
  845. bindingsUtils.updateNthPoint(2)
  846. ]
  847. },
  848. /**
  849. * Crooked line (five points) annotation bindings. Includes `start` and four
  850. * events in `steps` (for all consequent points in crooked line) array.
  851. *
  852. * @type {Highcharts.StockToolsBindingsObject}
  853. * @product highstock
  854. * @default {"className": "highcharts-crooked3", "start": function() {}, "steps": [function() {}, function() {}, function() {}, function() {}], "annotationsOptions": {}}
  855. */
  856. crooked5: {
  857. /** @ignore*/
  858. className: 'highcharts-crooked5',
  859. // eslint-disable-next-line valid-jsdoc
  860. /** @ignore*/
  861. start: function (e) {
  862. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  863. langKey: 'crookedLine',
  864. type: 'crookedLine',
  865. typeOptions: {
  866. points: [{
  867. x: coords.xAxis[0].value,
  868. y: coords.yAxis[0].value
  869. }, {
  870. x: coords.xAxis[0].value,
  871. y: coords.yAxis[0].value
  872. }, {
  873. x: coords.xAxis[0].value,
  874. y: coords.yAxis[0].value
  875. }, {
  876. x: coords.xAxis[0].value,
  877. y: coords.yAxis[0].value
  878. }, {
  879. x: coords.xAxis[0].value,
  880. y: coords.yAxis[0].value
  881. }]
  882. }
  883. }, navigation.annotationsOptions, navigation.bindings.crooked5.annotationsOptions);
  884. return this.chart.addAnnotation(options);
  885. },
  886. /** @ignore*/
  887. steps: [
  888. bindingsUtils.updateNthPoint(1),
  889. bindingsUtils.updateNthPoint(2),
  890. bindingsUtils.updateNthPoint(3),
  891. bindingsUtils.updateNthPoint(4)
  892. ]
  893. },
  894. /**
  895. * Elliott wave (three points) annotation bindings. Includes `start` and two
  896. * events in `steps` (for second and third points) array.
  897. *
  898. * @type {Highcharts.StockToolsBindingsObject}
  899. * @product highstock
  900. * @default {"className": "highcharts-elliott3", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  901. */
  902. elliott3: {
  903. /** @ignore*/
  904. className: 'highcharts-elliott3',
  905. // eslint-disable-next-line valid-jsdoc
  906. /** @ignore*/
  907. start: function (e) {
  908. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  909. langKey: 'elliott3',
  910. type: 'elliottWave',
  911. typeOptions: {
  912. points: [{
  913. x: coords.xAxis[0].value,
  914. y: coords.yAxis[0].value
  915. }, {
  916. x: coords.xAxis[0].value,
  917. y: coords.yAxis[0].value
  918. }, {
  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. },
  926. labelOptions: {
  927. style: {
  928. color: '#666666'
  929. }
  930. }
  931. }, navigation.annotationsOptions, navigation.bindings.elliott3.annotationsOptions);
  932. return this.chart.addAnnotation(options);
  933. },
  934. /** @ignore*/
  935. steps: [
  936. bindingsUtils.updateNthPoint(1),
  937. bindingsUtils.updateNthPoint(2),
  938. bindingsUtils.updateNthPoint(3)
  939. ]
  940. },
  941. /**
  942. * Elliott wave (five points) annotation bindings. Includes `start` and four
  943. * event in `steps` (for all consequent points in Elliott wave) array.
  944. *
  945. * @type {Highcharts.StockToolsBindingsObject}
  946. * @product highstock
  947. * @default {"className": "highcharts-elliott3", "start": function() {}, "steps": [function() {}, function() {}, function() {}, function() {}], "annotationsOptions": {}}
  948. */
  949. elliott5: {
  950. /** @ignore*/
  951. className: 'highcharts-elliott5',
  952. // eslint-disable-next-line valid-jsdoc
  953. /** @ignore*/
  954. start: function (e) {
  955. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  956. langKey: 'elliott5',
  957. type: 'elliottWave',
  958. typeOptions: {
  959. points: [{
  960. x: coords.xAxis[0].value,
  961. y: coords.yAxis[0].value
  962. }, {
  963. x: coords.xAxis[0].value,
  964. y: coords.yAxis[0].value
  965. }, {
  966. x: coords.xAxis[0].value,
  967. y: coords.yAxis[0].value
  968. }, {
  969. x: coords.xAxis[0].value,
  970. y: coords.yAxis[0].value
  971. }, {
  972. x: coords.xAxis[0].value,
  973. y: coords.yAxis[0].value
  974. }, {
  975. x: coords.xAxis[0].value,
  976. y: coords.yAxis[0].value
  977. }]
  978. },
  979. labelOptions: {
  980. style: {
  981. color: '#666666'
  982. }
  983. }
  984. }, navigation.annotationsOptions, navigation.bindings.elliott5.annotationsOptions);
  985. return this.chart.addAnnotation(options);
  986. },
  987. /** @ignore*/
  988. steps: [
  989. bindingsUtils.updateNthPoint(1),
  990. bindingsUtils.updateNthPoint(2),
  991. bindingsUtils.updateNthPoint(3),
  992. bindingsUtils.updateNthPoint(4),
  993. bindingsUtils.updateNthPoint(5)
  994. ]
  995. },
  996. /**
  997. * A measure (x-dimension) annotation bindings. Includes `start` and one
  998. * event in `steps` array.
  999. *
  1000. * @type {Highcharts.StockToolsBindingsObject}
  1001. * @product highstock
  1002. * @default {"className": "highcharts-measure-x", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  1003. */
  1004. measureX: {
  1005. /** @ignore*/
  1006. className: 'highcharts-measure-x',
  1007. // eslint-disable-next-line valid-jsdoc
  1008. /** @ignore*/
  1009. start: function (e) {
  1010. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1011. langKey: 'measure',
  1012. type: 'measure',
  1013. typeOptions: {
  1014. selectType: 'x',
  1015. point: {
  1016. x: coords.xAxis[0].value,
  1017. y: coords.yAxis[0].value,
  1018. xAxis: 0,
  1019. yAxis: 0
  1020. },
  1021. crosshairX: {
  1022. strokeWidth: 1,
  1023. stroke: '#000000'
  1024. },
  1025. crosshairY: {
  1026. enabled: false,
  1027. strokeWidth: 0,
  1028. stroke: '#000000'
  1029. },
  1030. background: {
  1031. width: 0,
  1032. height: 0,
  1033. strokeWidth: 0,
  1034. stroke: '#ffffff'
  1035. }
  1036. },
  1037. labelOptions: {
  1038. style: {
  1039. color: '#666666'
  1040. }
  1041. }
  1042. }, navigation.annotationsOptions, navigation.bindings.measureX.annotationsOptions);
  1043. return this.chart.addAnnotation(options);
  1044. },
  1045. /** @ignore*/
  1046. steps: [
  1047. bindingsUtils.updateRectSize
  1048. ]
  1049. },
  1050. /**
  1051. * A measure (y-dimension) annotation bindings. Includes `start` and one
  1052. * event in `steps` array.
  1053. *
  1054. * @type {Highcharts.StockToolsBindingsObject}
  1055. * @product highstock
  1056. * @default {"className": "highcharts-measure-y", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  1057. */
  1058. measureY: {
  1059. /** @ignore*/
  1060. className: 'highcharts-measure-y',
  1061. // eslint-disable-next-line valid-jsdoc
  1062. /** @ignore*/
  1063. start: function (e) {
  1064. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1065. langKey: 'measure',
  1066. type: 'measure',
  1067. typeOptions: {
  1068. selectType: 'y',
  1069. point: {
  1070. x: coords.xAxis[0].value,
  1071. y: coords.yAxis[0].value,
  1072. xAxis: 0,
  1073. yAxis: 0
  1074. },
  1075. crosshairX: {
  1076. enabled: false,
  1077. strokeWidth: 0,
  1078. stroke: '#000000'
  1079. },
  1080. crosshairY: {
  1081. strokeWidth: 1,
  1082. stroke: '#000000'
  1083. },
  1084. background: {
  1085. width: 0,
  1086. height: 0,
  1087. strokeWidth: 0,
  1088. stroke: '#ffffff'
  1089. }
  1090. },
  1091. labelOptions: {
  1092. style: {
  1093. color: '#666666'
  1094. }
  1095. }
  1096. }, navigation.annotationsOptions, navigation.bindings.measureY.annotationsOptions);
  1097. return this.chart.addAnnotation(options);
  1098. },
  1099. /** @ignore*/
  1100. steps: [
  1101. bindingsUtils.updateRectSize
  1102. ]
  1103. },
  1104. /**
  1105. * A measure (xy-dimension) annotation bindings. Includes `start` and one
  1106. * event in `steps` array.
  1107. *
  1108. * @type {Highcharts.StockToolsBindingsObject}
  1109. * @product highstock
  1110. * @default {"className": "highcharts-measure-xy", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  1111. */
  1112. measureXY: {
  1113. /** @ignore*/
  1114. className: 'highcharts-measure-xy',
  1115. // eslint-disable-next-line valid-jsdoc
  1116. /** @ignore*/
  1117. start: function (e) {
  1118. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1119. langKey: 'measure',
  1120. type: 'measure',
  1121. typeOptions: {
  1122. selectType: 'xy',
  1123. point: {
  1124. x: coords.xAxis[0].value,
  1125. y: coords.yAxis[0].value,
  1126. xAxis: 0,
  1127. yAxis: 0
  1128. },
  1129. background: {
  1130. width: 0,
  1131. height: 0,
  1132. strokeWidth: 10
  1133. },
  1134. crosshairX: {
  1135. strokeWidth: 1,
  1136. stroke: '#000000'
  1137. },
  1138. crosshairY: {
  1139. strokeWidth: 1,
  1140. stroke: '#000000'
  1141. }
  1142. },
  1143. labelOptions: {
  1144. style: {
  1145. color: '#666666'
  1146. }
  1147. }
  1148. }, navigation.annotationsOptions, navigation.bindings.measureXY.annotationsOptions);
  1149. return this.chart.addAnnotation(options);
  1150. },
  1151. /** @ignore*/
  1152. steps: [
  1153. bindingsUtils.updateRectSize
  1154. ]
  1155. },
  1156. // Advanced type annotations:
  1157. /**
  1158. * A fibonacci annotation bindings. Includes `start` and two events in
  1159. * `steps` array (updates second point, then height).
  1160. *
  1161. * @type {Highcharts.StockToolsBindingsObject}
  1162. * @product highstock
  1163. * @default {"className": "highcharts-fibonacci", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  1164. */
  1165. fibonacci: {
  1166. /** @ignore*/
  1167. className: 'highcharts-fibonacci',
  1168. // eslint-disable-next-line valid-jsdoc
  1169. /** @ignore*/
  1170. start: function (e) {
  1171. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1172. langKey: 'fibonacci',
  1173. type: 'fibonacci',
  1174. typeOptions: {
  1175. points: [{
  1176. x: coords.xAxis[0].value,
  1177. y: coords.yAxis[0].value
  1178. }, {
  1179. x: coords.xAxis[0].value,
  1180. y: coords.yAxis[0].value
  1181. }]
  1182. },
  1183. labelOptions: {
  1184. style: {
  1185. color: '#666666'
  1186. }
  1187. }
  1188. }, navigation.annotationsOptions, navigation.bindings.fibonacci.annotationsOptions);
  1189. return this.chart.addAnnotation(options);
  1190. },
  1191. /** @ignore*/
  1192. steps: [
  1193. bindingsUtils.updateNthPoint(1),
  1194. bindingsUtils.updateHeight
  1195. ]
  1196. },
  1197. /**
  1198. * A parallel channel (tunnel) annotation bindings. Includes `start` and
  1199. * two events in `steps` array (updates second point, then height).
  1200. *
  1201. * @type {Highcharts.StockToolsBindingsObject}
  1202. * @product highstock
  1203. * @default {"className": "highcharts-parallel-channel", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  1204. */
  1205. parallelChannel: {
  1206. /** @ignore*/
  1207. className: 'highcharts-parallel-channel',
  1208. // eslint-disable-next-line valid-jsdoc
  1209. /** @ignore*/
  1210. start: function (e) {
  1211. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1212. langKey: 'parallelChannel',
  1213. type: 'tunnel',
  1214. typeOptions: {
  1215. points: [{
  1216. x: coords.xAxis[0].value,
  1217. y: coords.yAxis[0].value
  1218. }, {
  1219. x: coords.xAxis[0].value,
  1220. y: coords.yAxis[0].value
  1221. }]
  1222. }
  1223. }, navigation.annotationsOptions, navigation.bindings.parallelChannel.annotationsOptions);
  1224. return this.chart.addAnnotation(options);
  1225. },
  1226. /** @ignore*/
  1227. steps: [
  1228. bindingsUtils.updateNthPoint(1),
  1229. bindingsUtils.updateHeight
  1230. ]
  1231. },
  1232. /**
  1233. * An Andrew's pitchfork annotation bindings. Includes `start` and two
  1234. * events in `steps` array (sets second and third control points).
  1235. *
  1236. * @type {Highcharts.StockToolsBindingsObject}
  1237. * @product highstock
  1238. * @default {"className": "highcharts-pitchfork", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  1239. */
  1240. pitchfork: {
  1241. /** @ignore*/
  1242. className: 'highcharts-pitchfork',
  1243. // eslint-disable-next-line valid-jsdoc
  1244. /** @ignore*/
  1245. start: function (e) {
  1246. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  1247. langKey: 'pitchfork',
  1248. type: 'pitchfork',
  1249. typeOptions: {
  1250. points: [{
  1251. x: coords.xAxis[0].value,
  1252. y: coords.yAxis[0].value,
  1253. controlPoint: {
  1254. style: {
  1255. fill: 'red'
  1256. }
  1257. }
  1258. }, {
  1259. x: coords.xAxis[0].value,
  1260. y: coords.yAxis[0].value
  1261. }, {
  1262. x: coords.xAxis[0].value,
  1263. y: coords.yAxis[0].value
  1264. }],
  1265. innerBackground: {
  1266. fill: 'rgba(100, 170, 255, 0.8)'
  1267. }
  1268. },
  1269. shapeOptions: {
  1270. strokeWidth: 2
  1271. }
  1272. }, navigation.annotationsOptions, navigation.bindings.pitchfork.annotationsOptions);
  1273. return this.chart.addAnnotation(options);
  1274. },
  1275. /** @ignore*/
  1276. steps: [
  1277. bindingsUtils.updateNthPoint(1),
  1278. bindingsUtils.updateNthPoint(2)
  1279. ]
  1280. },
  1281. // Labels with arrow and auto increments
  1282. /**
  1283. * A vertical counter annotation bindings. Includes `start` event. On click,
  1284. * finds the closest point and marks it with a numeric annotation -
  1285. * incrementing counter on each add.
  1286. *
  1287. * @type {Highcharts.StockToolsBindingsObject}
  1288. * @product highstock
  1289. * @default {"className": "highcharts-vertical-counter", "start": function() {}, "annotationsOptions": {}}
  1290. */
  1291. verticalCounter: {
  1292. /** @ignore*/
  1293. className: 'highcharts-vertical-counter',
  1294. // eslint-disable-next-line valid-jsdoc
  1295. /** @ignore*/
  1296. start: function (e) {
  1297. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, verticalCounter = !defined(this.verticalCounter) ? 0 :
  1298. this.verticalCounter, options = merge({
  1299. langKey: 'verticalCounter',
  1300. type: 'verticalLine',
  1301. typeOptions: {
  1302. point: {
  1303. x: closestPoint.x,
  1304. y: closestPoint.y,
  1305. xAxis: closestPoint.xAxis,
  1306. yAxis: closestPoint.yAxis
  1307. },
  1308. label: {
  1309. offset: closestPoint.below ? 40 : -40,
  1310. text: verticalCounter.toString()
  1311. }
  1312. },
  1313. labelOptions: {
  1314. style: {
  1315. color: '#666666',
  1316. fontSize: '11px'
  1317. }
  1318. },
  1319. shapeOptions: {
  1320. stroke: 'rgba(0, 0, 0, 0.75)',
  1321. strokeWidth: 1
  1322. }
  1323. }, navigation.annotationsOptions, navigation.bindings.verticalCounter.annotationsOptions), annotation;
  1324. annotation = this.chart.addAnnotation(options);
  1325. verticalCounter++;
  1326. annotation.options.events.click.call(annotation, {});
  1327. }
  1328. },
  1329. /**
  1330. * A vertical arrow annotation bindings. Includes `start` event. On click,
  1331. * finds the closest point and marks it with an arrow and a label with
  1332. * value.
  1333. *
  1334. * @type {Highcharts.StockToolsBindingsObject}
  1335. * @product highstock
  1336. * @default {"className": "highcharts-vertical-label", "start": function() {}, "annotationsOptions": {}}
  1337. */
  1338. verticalLabel: {
  1339. /** @ignore*/
  1340. className: 'highcharts-vertical-label',
  1341. // eslint-disable-next-line valid-jsdoc
  1342. /** @ignore*/
  1343. start: function (e) {
  1344. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, options = merge({
  1345. langKey: 'verticalLabel',
  1346. type: 'verticalLine',
  1347. typeOptions: {
  1348. point: {
  1349. x: closestPoint.x,
  1350. y: closestPoint.y,
  1351. xAxis: closestPoint.xAxis,
  1352. yAxis: closestPoint.yAxis
  1353. },
  1354. label: {
  1355. offset: closestPoint.below ? 40 : -40
  1356. }
  1357. },
  1358. labelOptions: {
  1359. style: {
  1360. color: '#666666',
  1361. fontSize: '11px'
  1362. }
  1363. },
  1364. shapeOptions: {
  1365. stroke: 'rgba(0, 0, 0, 0.75)',
  1366. strokeWidth: 1
  1367. }
  1368. }, navigation.annotationsOptions, navigation.bindings.verticalLabel.annotationsOptions), annotation;
  1369. annotation = this.chart.addAnnotation(options);
  1370. annotation.options.events.click.call(annotation, {});
  1371. }
  1372. },
  1373. /**
  1374. * A vertical arrow annotation bindings. Includes `start` event. On click,
  1375. * finds the closest point and marks it with an arrow. Green arrow when
  1376. * pointing from above, red when pointing from below the point.
  1377. *
  1378. * @type {Highcharts.StockToolsBindingsObject}
  1379. * @product highstock
  1380. * @default {"className": "highcharts-vertical-arrow", "start": function() {}, "annotationsOptions": {}}
  1381. */
  1382. verticalArrow: {
  1383. /** @ignore*/
  1384. className: 'highcharts-vertical-arrow',
  1385. // eslint-disable-next-line valid-jsdoc
  1386. /** @ignore*/
  1387. start: function (e) {
  1388. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, options = merge({
  1389. langKey: 'verticalArrow',
  1390. type: 'verticalLine',
  1391. typeOptions: {
  1392. point: {
  1393. x: closestPoint.x,
  1394. y: closestPoint.y,
  1395. xAxis: closestPoint.xAxis,
  1396. yAxis: closestPoint.yAxis
  1397. },
  1398. label: {
  1399. offset: closestPoint.below ? 40 : -40,
  1400. format: ' '
  1401. },
  1402. connector: {
  1403. fill: 'none',
  1404. stroke: closestPoint.below ? 'red' : 'green'
  1405. }
  1406. },
  1407. shapeOptions: {
  1408. stroke: 'rgba(0, 0, 0, 0.75)',
  1409. strokeWidth: 1
  1410. }
  1411. }, navigation.annotationsOptions, navigation.bindings.verticalArrow.annotationsOptions), annotation;
  1412. annotation = this.chart.addAnnotation(options);
  1413. annotation.options.events.click.call(annotation, {});
  1414. }
  1415. },
  1416. // Flag types:
  1417. /**
  1418. * A flag series bindings. Includes `start` event. On click, finds the
  1419. * closest point and marks it with a flag with `'circlepin'` shape.
  1420. *
  1421. * @type {Highcharts.StockToolsBindingsObject}
  1422. * @product highstock
  1423. * @default {"className": "highcharts-flag-circlepin", "start": function() {}}
  1424. */
  1425. flagCirclepin: {
  1426. /** @ignore*/
  1427. className: 'highcharts-flag-circlepin',
  1428. /** @ignore*/
  1429. start: bindingsUtils
  1430. .addFlagFromForm('circlepin')
  1431. },
  1432. /**
  1433. * A flag series bindings. Includes `start` event. On click, finds the
  1434. * closest point and marks it with a flag with `'diamondpin'` shape.
  1435. *
  1436. * @type {Highcharts.StockToolsBindingsObject}
  1437. * @product highstock
  1438. * @default {"className": "highcharts-flag-diamondpin", "start": function() {}}
  1439. */
  1440. flagDiamondpin: {
  1441. /** @ignore*/
  1442. className: 'highcharts-flag-diamondpin',
  1443. /** @ignore*/
  1444. start: bindingsUtils
  1445. .addFlagFromForm('flag')
  1446. },
  1447. /**
  1448. * A flag series bindings. Includes `start` event.
  1449. * On click, finds the closest point and marks it with a flag with
  1450. * `'squarepin'` shape.
  1451. *
  1452. * @type {Highcharts.StockToolsBindingsObject}
  1453. * @product highstock
  1454. * @default {"className": "highcharts-flag-squarepin", "start": function() {}}
  1455. */
  1456. flagSquarepin: {
  1457. /** @ignore*/
  1458. className: 'highcharts-flag-squarepin',
  1459. /** @ignore*/
  1460. start: bindingsUtils
  1461. .addFlagFromForm('squarepin')
  1462. },
  1463. /**
  1464. * A flag series bindings. Includes `start` event.
  1465. * On click, finds the closest point and marks it with a flag without pin
  1466. * shape.
  1467. *
  1468. * @type {Highcharts.StockToolsBindingsObject}
  1469. * @product highstock
  1470. * @default {"className": "highcharts-flag-simplepin", "start": function() {}}
  1471. */
  1472. flagSimplepin: {
  1473. /** @ignore*/
  1474. className: 'highcharts-flag-simplepin',
  1475. /** @ignore*/
  1476. start: bindingsUtils
  1477. .addFlagFromForm('nopin')
  1478. },
  1479. // Other tools:
  1480. /**
  1481. * Enables zooming in xAxis on a chart. Includes `start` event which
  1482. * changes [chart.zoomType](#chart.zoomType).
  1483. *
  1484. * @type {Highcharts.StockToolsBindingsObject}
  1485. * @product highstock
  1486. * @default {"className": "highcharts-zoom-x", "init": function() {}}
  1487. */
  1488. zoomX: {
  1489. /** @ignore*/
  1490. className: 'highcharts-zoom-x',
  1491. // eslint-disable-next-line valid-jsdoc
  1492. /** @ignore*/
  1493. init: function (button) {
  1494. this.chart.update({
  1495. chart: {
  1496. zoomType: 'x'
  1497. }
  1498. });
  1499. fireEvent(this, 'deselectButton', { button: button });
  1500. }
  1501. },
  1502. /**
  1503. * Enables zooming in yAxis on a chart. Includes `start` event which
  1504. * changes [chart.zoomType](#chart.zoomType).
  1505. *
  1506. * @type {Highcharts.StockToolsBindingsObject}
  1507. * @product highstock
  1508. * @default {"className": "highcharts-zoom-y", "init": function() {}}
  1509. */
  1510. zoomY: {
  1511. /** @ignore*/
  1512. className: 'highcharts-zoom-y',
  1513. // eslint-disable-next-line valid-jsdoc
  1514. /** @ignore*/
  1515. init: function (button) {
  1516. this.chart.update({
  1517. chart: {
  1518. zoomType: 'y'
  1519. }
  1520. });
  1521. fireEvent(this, 'deselectButton', { button: button });
  1522. }
  1523. },
  1524. /**
  1525. * Enables zooming in xAxis and yAxis on a chart. Includes `start` event
  1526. * which changes [chart.zoomType](#chart.zoomType).
  1527. *
  1528. * @type {Highcharts.StockToolsBindingsObject}
  1529. * @product highstock
  1530. * @default {"className": "highcharts-zoom-xy", "init": function() {}}
  1531. */
  1532. zoomXY: {
  1533. /** @ignore*/
  1534. className: 'highcharts-zoom-xy',
  1535. // eslint-disable-next-line valid-jsdoc
  1536. /** @ignore*/
  1537. init: function (button) {
  1538. this.chart.update({
  1539. chart: {
  1540. zoomType: 'xy'
  1541. }
  1542. });
  1543. fireEvent(this, 'deselectButton', { button: button });
  1544. }
  1545. },
  1546. /**
  1547. * Changes main series to `'line'` type.
  1548. *
  1549. * @type {Highcharts.StockToolsBindingsObject}
  1550. * @product highstock
  1551. * @default {"className": "highcharts-series-type-line", "init": function() {}}
  1552. */
  1553. seriesTypeLine: {
  1554. /** @ignore*/
  1555. className: 'highcharts-series-type-line',
  1556. // eslint-disable-next-line valid-jsdoc
  1557. /** @ignore*/
  1558. init: function (button) {
  1559. this.chart.series[0].update({
  1560. type: 'line',
  1561. useOhlcData: true
  1562. });
  1563. fireEvent(this, 'deselectButton', { button: button });
  1564. }
  1565. },
  1566. /**
  1567. * Changes main series to `'ohlc'` type.
  1568. *
  1569. * @type {Highcharts.StockToolsBindingsObject}
  1570. * @product highstock
  1571. * @default {"className": "highcharts-series-type-ohlc", "init": function() {}}
  1572. */
  1573. seriesTypeOhlc: {
  1574. /** @ignore*/
  1575. className: 'highcharts-series-type-ohlc',
  1576. // eslint-disable-next-line valid-jsdoc
  1577. /** @ignore*/
  1578. init: function (button) {
  1579. this.chart.series[0].update({
  1580. type: 'ohlc'
  1581. });
  1582. fireEvent(this, 'deselectButton', { button: button });
  1583. }
  1584. },
  1585. /**
  1586. * Changes main series to `'candlestick'` type.
  1587. *
  1588. * @type {Highcharts.StockToolsBindingsObject}
  1589. * @product highstock
  1590. * @default {"className": "highcharts-series-type-candlestick", "init": function() {}}
  1591. */
  1592. seriesTypeCandlestick: {
  1593. /** @ignore*/
  1594. className: 'highcharts-series-type-candlestick',
  1595. // eslint-disable-next-line valid-jsdoc
  1596. /** @ignore*/
  1597. init: function (button) {
  1598. this.chart.series[0].update({
  1599. type: 'candlestick'
  1600. });
  1601. fireEvent(this, 'deselectButton', { button: button });
  1602. }
  1603. },
  1604. /**
  1605. * Displays chart in fullscreen.
  1606. *
  1607. * @type {Highcharts.StockToolsBindingsObject}
  1608. * @product highstock
  1609. * @default {"className": "highcharts-full-screen", "init": function() {}}
  1610. */
  1611. fullScreen: {
  1612. /** @ignore*/
  1613. className: 'highcharts-full-screen',
  1614. // eslint-disable-next-line valid-jsdoc
  1615. /** @ignore*/
  1616. init: function (button) {
  1617. var chart = this.chart;
  1618. chart.fullScreen = new H.FullScreen(chart.container);
  1619. fireEvent(this, 'deselectButton', { button: button });
  1620. }
  1621. },
  1622. /**
  1623. * Hides/shows two price indicators:
  1624. * - last price in the dataset
  1625. * - last price in the selected range
  1626. *
  1627. * @type {Highcharts.StockToolsBindingsObject}
  1628. * @product highstock
  1629. * @default {"className": "highcharts-current-price-indicator", "init": function() {}}
  1630. */
  1631. currentPriceIndicator: {
  1632. /** @ignore*/
  1633. className: 'highcharts-current-price-indicator',
  1634. // eslint-disable-next-line valid-jsdoc
  1635. /** @ignore*/
  1636. init: function (button) {
  1637. var chart = this.chart, series = chart.series[0], options = series.options, lastVisiblePrice = options.lastVisiblePrice &&
  1638. options.lastVisiblePrice.enabled, lastPrice = options.lastPrice && options.lastPrice.enabled, gui = chart.stockTools, iconsURL = gui.getIconsURL();
  1639. if (gui && gui.guiEnabled) {
  1640. if (lastPrice) {
  1641. button.firstChild.style['background-image'] =
  1642. 'url("' + iconsURL +
  1643. 'current-price-show.svg")';
  1644. }
  1645. else {
  1646. button.firstChild.style['background-image'] =
  1647. 'url("' + iconsURL +
  1648. 'current-price-hide.svg")';
  1649. }
  1650. }
  1651. series.update({
  1652. // line
  1653. lastPrice: {
  1654. enabled: !lastPrice,
  1655. color: 'red'
  1656. },
  1657. // label
  1658. lastVisiblePrice: {
  1659. enabled: !lastVisiblePrice,
  1660. label: {
  1661. enabled: true
  1662. }
  1663. }
  1664. });
  1665. fireEvent(this, 'deselectButton', { button: button });
  1666. }
  1667. },
  1668. /**
  1669. * Indicators bindings. Includes `init` event to show a popup.
  1670. *
  1671. * Note: In order to show base series from the chart in the popup's
  1672. * dropdown each series requires
  1673. * [series.id](https://api.highcharts.com/highstock/series.line.id) to be
  1674. * defined.
  1675. *
  1676. * @type {Highcharts.StockToolsBindingsObject}
  1677. * @product highstock
  1678. * @default {"className": "highcharts-indicators", "init": function() {}}
  1679. */
  1680. indicators: {
  1681. /** @ignore*/
  1682. className: 'highcharts-indicators',
  1683. // eslint-disable-next-line valid-jsdoc
  1684. /** @ignore*/
  1685. init: function () {
  1686. var navigation = this;
  1687. fireEvent(navigation, 'showPopup', {
  1688. formType: 'indicators',
  1689. options: {},
  1690. // Callback on submit:
  1691. onSubmit: function (data) {
  1692. navigation.utils.manageIndicators.call(navigation, data);
  1693. }
  1694. });
  1695. }
  1696. },
  1697. /**
  1698. * Hides/shows all annotations on a chart.
  1699. *
  1700. * @type {Highcharts.StockToolsBindingsObject}
  1701. * @product highstock
  1702. * @default {"className": "highcharts-toggle-annotations", "init": function() {}}
  1703. */
  1704. toggleAnnotations: {
  1705. /** @ignore*/
  1706. className: 'highcharts-toggle-annotations',
  1707. // eslint-disable-next-line valid-jsdoc
  1708. /** @ignore*/
  1709. init: function (button) {
  1710. var chart = this.chart, gui = chart.stockTools, iconsURL = gui.getIconsURL();
  1711. this.toggledAnnotations = !this.toggledAnnotations;
  1712. (chart.annotations || []).forEach(function (annotation) {
  1713. annotation.setVisibility(!this.toggledAnnotations);
  1714. }, this);
  1715. if (gui && gui.guiEnabled) {
  1716. if (this.toggledAnnotations) {
  1717. button.firstChild.style['background-image'] =
  1718. 'url("' + iconsURL +
  1719. 'annotations-hidden.svg")';
  1720. }
  1721. else {
  1722. button.firstChild.style['background-image'] =
  1723. 'url("' + iconsURL +
  1724. 'annotations-visible.svg")';
  1725. }
  1726. }
  1727. fireEvent(this, 'deselectButton', { button: button });
  1728. }
  1729. },
  1730. /**
  1731. * Save a chart in localStorage under `highcharts-chart` key.
  1732. * Stored items:
  1733. * - annotations
  1734. * - indicators (with yAxes)
  1735. * - flags
  1736. *
  1737. * @type {Highcharts.StockToolsBindingsObject}
  1738. * @product highstock
  1739. * @default {"className": "highcharts-save-chart", "init": function() {}}
  1740. */
  1741. saveChart: {
  1742. /** @ignore*/
  1743. className: 'highcharts-save-chart',
  1744. // eslint-disable-next-line valid-jsdoc
  1745. /** @ignore*/
  1746. init: function (button) {
  1747. var navigation = this, chart = navigation.chart, annotations = [], indicators = [], flags = [], yAxes = [];
  1748. chart.annotations.forEach(function (annotation, index) {
  1749. annotations[index] = annotation.userOptions;
  1750. });
  1751. chart.series.forEach(function (series) {
  1752. if (series instanceof H.seriesTypes.sma) {
  1753. indicators.push(series.userOptions);
  1754. }
  1755. else if (series.type === 'flags') {
  1756. flags.push(series.userOptions);
  1757. }
  1758. });
  1759. chart.yAxis.forEach(function (yAxis) {
  1760. if (navigation.utils.isNotNavigatorYAxis(yAxis)) {
  1761. yAxes.push(yAxis.options);
  1762. }
  1763. });
  1764. H.win.localStorage.setItem(PREFIX + 'chart', JSON.stringify({
  1765. annotations: annotations,
  1766. indicators: indicators,
  1767. flags: flags,
  1768. yAxes: yAxes
  1769. }));
  1770. fireEvent(this, 'deselectButton', { button: button });
  1771. }
  1772. }
  1773. };
  1774. H.setOptions({
  1775. navigation: {
  1776. bindings: stockToolsBindings
  1777. }
  1778. });
  1779. });
  1780. _registerModule(_modules, 'modules/stock-tools-gui.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  1781. /* *
  1782. *
  1783. * GUI generator for Stock tools
  1784. *
  1785. * (c) 2009-2017 Sebastian Bochan
  1786. *
  1787. * License: www.highcharts.com/license
  1788. *
  1789. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1790. *
  1791. * */
  1792. var extend = U.extend, isArray = U.isArray, pick = U.pick;
  1793. var addEvent = H.addEvent, createElement = H.createElement, fireEvent = H.fireEvent, getStyle = H.getStyle, merge = H.merge, css = H.css, win = H.win, DIV = 'div', SPAN = 'span', UL = 'ul', LI = 'li', PREFIX = 'highcharts-', activeClass = PREFIX + 'active';
  1794. H.setOptions({
  1795. /**
  1796. * @optionparent lang
  1797. */
  1798. lang: {
  1799. /**
  1800. * Configure the stockTools GUI titles(hints) in the chart. Requires
  1801. * the `stock-tools.js` module to be loaded.
  1802. *
  1803. * @product highstock
  1804. * @since 7.0.0
  1805. */
  1806. stockTools: {
  1807. gui: {
  1808. // Main buttons:
  1809. simpleShapes: 'Simple shapes',
  1810. lines: 'Lines',
  1811. crookedLines: 'Crooked lines',
  1812. measure: 'Measure',
  1813. advanced: 'Advanced',
  1814. toggleAnnotations: 'Toggle annotations',
  1815. verticalLabels: 'Vertical labels',
  1816. flags: 'Flags',
  1817. zoomChange: 'Zoom change',
  1818. typeChange: 'Type change',
  1819. saveChart: 'Save chart',
  1820. indicators: 'Indicators',
  1821. currentPriceIndicator: 'Current Price Indicators',
  1822. // Other features:
  1823. zoomX: 'Zoom X',
  1824. zoomY: 'Zoom Y',
  1825. zoomXY: 'Zooom XY',
  1826. fullScreen: 'Fullscreen',
  1827. typeOHLC: 'OHLC',
  1828. typeLine: 'Line',
  1829. typeCandlestick: 'Candlestick',
  1830. // Basic shapes:
  1831. circle: 'Circle',
  1832. label: 'Label',
  1833. rectangle: 'Rectangle',
  1834. // Flags:
  1835. flagCirclepin: 'Flag circle',
  1836. flagDiamondpin: 'Flag diamond',
  1837. flagSquarepin: 'Flag square',
  1838. flagSimplepin: 'Flag simple',
  1839. // Measures:
  1840. measureXY: 'Measure XY',
  1841. measureX: 'Measure X',
  1842. measureY: 'Measure Y',
  1843. // Segment, ray and line:
  1844. segment: 'Segment',
  1845. arrowSegment: 'Arrow segment',
  1846. ray: 'Ray',
  1847. arrowRay: 'Arrow ray',
  1848. line: 'Line',
  1849. arrowLine: 'Arrow line',
  1850. horizontalLine: 'Horizontal line',
  1851. verticalLine: 'Vertical line',
  1852. infinityLine: 'Infinity line',
  1853. // Crooked lines:
  1854. crooked3: 'Crooked 3 line',
  1855. crooked5: 'Crooked 5 line',
  1856. elliott3: 'Elliott 3 line',
  1857. elliott5: 'Elliott 5 line',
  1858. // Counters:
  1859. verticalCounter: 'Vertical counter',
  1860. verticalLabel: 'Vertical label',
  1861. verticalArrow: 'Vertical arrow',
  1862. // Advanced:
  1863. fibonacci: 'Fibonacci',
  1864. pitchfork: 'Pitchfork',
  1865. parallelChannel: 'Parallel channel'
  1866. }
  1867. },
  1868. navigation: {
  1869. popup: {
  1870. // Annotations:
  1871. circle: 'Circle',
  1872. rectangle: 'Rectangle',
  1873. label: 'Label',
  1874. segment: 'Segment',
  1875. arrowSegment: 'Arrow segment',
  1876. ray: 'Ray',
  1877. arrowRay: 'Arrow ray',
  1878. line: 'Line',
  1879. arrowLine: 'Arrow line',
  1880. horizontalLine: 'Horizontal line',
  1881. verticalLine: 'Vertical line',
  1882. crooked3: 'Crooked 3 line',
  1883. crooked5: 'Crooked 5 line',
  1884. elliott3: 'Elliott 3 line',
  1885. elliott5: 'Elliott 5 line',
  1886. verticalCounter: 'Vertical counter',
  1887. verticalLabel: 'Vertical label',
  1888. verticalArrow: 'Vertical arrow',
  1889. fibonacci: 'Fibonacci',
  1890. pitchfork: 'Pitchfork',
  1891. parallelChannel: 'Parallel channel',
  1892. infinityLine: 'Infinity line',
  1893. measure: 'Measure',
  1894. measureXY: 'Measure XY',
  1895. measureX: 'Measure X',
  1896. measureY: 'Measure Y',
  1897. // Flags:
  1898. flags: 'Flags',
  1899. // GUI elements:
  1900. addButton: 'add',
  1901. saveButton: 'save',
  1902. editButton: 'edit',
  1903. removeButton: 'remove',
  1904. series: 'Series',
  1905. volume: 'Volume',
  1906. connector: 'Connector',
  1907. // Field names:
  1908. innerBackground: 'Inner background',
  1909. outerBackground: 'Outer background',
  1910. crosshairX: 'Crosshair X',
  1911. crosshairY: 'Crosshair Y',
  1912. tunnel: 'Tunnel',
  1913. background: 'Background'
  1914. }
  1915. }
  1916. },
  1917. /**
  1918. * Configure the stockTools gui strings in the chart. Requires the
  1919. * [stockTools module]() to be loaded. For a description of the module
  1920. * and information on its features, see [Highcharts StockTools]().
  1921. *
  1922. * @product highstock
  1923. *
  1924. * @sample stock/demo/stock-tools-gui Stock Tools GUI
  1925. *
  1926. * @sample stock/demo/stock-tools-custom-gui Stock Tools customized GUI
  1927. *
  1928. * @since 7.0.0
  1929. * @optionparent stockTools
  1930. */
  1931. stockTools: {
  1932. /**
  1933. * Definitions of buttons in Stock Tools GUI.
  1934. */
  1935. gui: {
  1936. /**
  1937. * Path where Highcharts will look for icons. Change this to use
  1938. * icons from a different server.
  1939. *
  1940. * Since 7.1.3 use [iconsURL](#navigation.iconsURL) for popup and
  1941. * stock tools.
  1942. *
  1943. * @deprecated
  1944. * @apioption stockTools.gui.iconsURL
  1945. *
  1946. */
  1947. /**
  1948. * Enable or disable the stockTools gui.
  1949. */
  1950. enabled: true,
  1951. /**
  1952. * A CSS class name to apply to the stocktools' div,
  1953. * allowing unique CSS styling for each chart.
  1954. */
  1955. className: 'highcharts-bindings-wrapper',
  1956. /**
  1957. * A CSS class name to apply to the container of buttons,
  1958. * allowing unique CSS styling for each chart.
  1959. */
  1960. toolbarClassName: 'stocktools-toolbar',
  1961. /**
  1962. * A collection of strings pointing to config options for the
  1963. * toolbar items. Each name refers to unique key from definitions
  1964. * object.
  1965. *
  1966. * @default [
  1967. * 'indicators',
  1968. * 'separator',
  1969. * 'simpleShapes',
  1970. * 'lines',
  1971. * 'crookedLines',
  1972. * 'measure',
  1973. * 'advanced',
  1974. * 'toggleAnnotations',
  1975. * 'separator',
  1976. * 'verticalLabels',
  1977. * 'flags',
  1978. * 'separator',
  1979. * 'zoomChange',
  1980. * 'fullScreen',
  1981. * 'typeChange',
  1982. * 'separator',
  1983. * 'currentPriceIndicator',
  1984. * 'saveChart'
  1985. * ]
  1986. */
  1987. buttons: [
  1988. 'indicators',
  1989. 'separator',
  1990. 'simpleShapes',
  1991. 'lines',
  1992. 'crookedLines',
  1993. 'measure',
  1994. 'advanced',
  1995. 'toggleAnnotations',
  1996. 'separator',
  1997. 'verticalLabels',
  1998. 'flags',
  1999. 'separator',
  2000. 'zoomChange',
  2001. 'fullScreen',
  2002. 'typeChange',
  2003. 'separator',
  2004. 'currentPriceIndicator',
  2005. 'saveChart'
  2006. ],
  2007. /**
  2008. * An options object of the buttons definitions. Each name refers to
  2009. * unique key from buttons array.
  2010. */
  2011. definitions: {
  2012. separator: {
  2013. /**
  2014. * A predefined background symbol for the button.
  2015. */
  2016. symbol: 'separator.svg'
  2017. },
  2018. simpleShapes: {
  2019. /**
  2020. * A collection of strings pointing to config options for
  2021. * the items.
  2022. *
  2023. * @type {array}
  2024. * @default [
  2025. * 'label',
  2026. * 'circle',
  2027. * 'rectangle'
  2028. * ]
  2029. *
  2030. */
  2031. items: [
  2032. 'label',
  2033. 'circle',
  2034. 'rectangle'
  2035. ],
  2036. circle: {
  2037. /**
  2038. * A predefined background symbol for the button.
  2039. *
  2040. * @type {string}
  2041. *
  2042. */
  2043. symbol: 'circle.svg'
  2044. },
  2045. rectangle: {
  2046. /**
  2047. * A predefined background symbol for the button.
  2048. *
  2049. * @type {string}
  2050. *
  2051. */
  2052. symbol: 'rectangle.svg'
  2053. },
  2054. label: {
  2055. /**
  2056. * A predefined background symbol for the button.
  2057. *
  2058. * @type {string}
  2059. *
  2060. */
  2061. symbol: 'label.svg'
  2062. }
  2063. },
  2064. flags: {
  2065. /**
  2066. * A collection of strings pointing to config options for
  2067. * the items.
  2068. *
  2069. * @type {array}
  2070. * @default [
  2071. * 'flagCirclepin',
  2072. * 'flagDiamondpin',
  2073. * 'flagSquarepin',
  2074. * 'flagSimplepin'
  2075. * ]
  2076. *
  2077. */
  2078. items: [
  2079. 'flagCirclepin',
  2080. 'flagDiamondpin',
  2081. 'flagSquarepin',
  2082. 'flagSimplepin'
  2083. ],
  2084. flagSimplepin: {
  2085. /**
  2086. * A predefined background symbol for the button.
  2087. *
  2088. * @type {string}
  2089. *
  2090. */
  2091. symbol: 'flag-basic.svg'
  2092. },
  2093. flagDiamondpin: {
  2094. /**
  2095. * A predefined background symbol for the button.
  2096. *
  2097. * @type {string}
  2098. *
  2099. */
  2100. symbol: 'flag-diamond.svg'
  2101. },
  2102. flagSquarepin: {
  2103. /**
  2104. * A predefined background symbol for the button.
  2105. *
  2106. * @type {string}
  2107. */
  2108. symbol: 'flag-trapeze.svg'
  2109. },
  2110. flagCirclepin: {
  2111. /**
  2112. * A predefined background symbol for the button.
  2113. *
  2114. * @type {string}
  2115. */
  2116. symbol: 'flag-elipse.svg'
  2117. }
  2118. },
  2119. lines: {
  2120. /**
  2121. * A collection of strings pointing to config options for
  2122. * the items.
  2123. *
  2124. * @type {array}
  2125. * @default [
  2126. * 'segment',
  2127. * 'arrowSegment',
  2128. * 'ray',
  2129. * 'arrowRay',
  2130. * 'line',
  2131. * 'arrowLine',
  2132. * 'horizontalLine',
  2133. * 'verticalLine'
  2134. * ]
  2135. */
  2136. items: [
  2137. 'segment',
  2138. 'arrowSegment',
  2139. 'ray',
  2140. 'arrowRay',
  2141. 'line',
  2142. 'arrowLine',
  2143. 'horizontalLine',
  2144. 'verticalLine'
  2145. ],
  2146. segment: {
  2147. /**
  2148. * A predefined background symbol for the button.
  2149. *
  2150. * @type {string}
  2151. */
  2152. symbol: 'segment.svg'
  2153. },
  2154. arrowSegment: {
  2155. /**
  2156. * A predefined background symbol for the button.
  2157. *
  2158. * @type {string}
  2159. */
  2160. symbol: 'arrow-segment.svg'
  2161. },
  2162. ray: {
  2163. /**
  2164. * A predefined background symbol for the button.
  2165. *
  2166. * @type {string}
  2167. */
  2168. symbol: 'ray.svg'
  2169. },
  2170. arrowRay: {
  2171. /**
  2172. * A predefined background symbol for the button.
  2173. *
  2174. * @type {string}
  2175. */
  2176. symbol: 'arrow-ray.svg'
  2177. },
  2178. line: {
  2179. /**
  2180. * A predefined background symbol for the button.
  2181. *
  2182. * @type {string}
  2183. */
  2184. symbol: 'line.svg'
  2185. },
  2186. arrowLine: {
  2187. /**
  2188. * A predefined background symbol for the button.
  2189. *
  2190. * @type {string}
  2191. */
  2192. symbol: 'arrow-line.svg'
  2193. },
  2194. verticalLine: {
  2195. /**
  2196. * A predefined background symbol for the button.
  2197. *
  2198. * @type {string}
  2199. */
  2200. symbol: 'vertical-line.svg'
  2201. },
  2202. horizontalLine: {
  2203. /**
  2204. * A predefined background symbol for the button.
  2205. *
  2206. * @type {string}
  2207. */
  2208. symbol: 'horizontal-line.svg'
  2209. }
  2210. },
  2211. crookedLines: {
  2212. /**
  2213. * A collection of strings pointing to config options for
  2214. * the items.
  2215. *
  2216. * @type {array}
  2217. * @default [
  2218. * 'elliott3',
  2219. * 'elliott5',
  2220. * 'crooked3',
  2221. * 'crooked5'
  2222. * ]
  2223. *
  2224. */
  2225. items: [
  2226. 'elliott3',
  2227. 'elliott5',
  2228. 'crooked3',
  2229. 'crooked5'
  2230. ],
  2231. crooked3: {
  2232. /**
  2233. * A predefined background symbol for the button.
  2234. *
  2235. * @type {string}
  2236. */
  2237. symbol: 'crooked-3.svg'
  2238. },
  2239. crooked5: {
  2240. /**
  2241. * A predefined background symbol for the button.
  2242. *
  2243. * @type {string}
  2244. */
  2245. symbol: 'crooked-5.svg'
  2246. },
  2247. elliott3: {
  2248. /**
  2249. * A predefined background symbol for the button.
  2250. *
  2251. * @type {string}
  2252. */
  2253. symbol: 'elliott-3.svg'
  2254. },
  2255. elliott5: {
  2256. /**
  2257. * A predefined background symbol for the button.
  2258. *
  2259. * @type {string}
  2260. */
  2261. symbol: 'elliott-5.svg'
  2262. }
  2263. },
  2264. verticalLabels: {
  2265. /**
  2266. * A collection of strings pointing to config options for
  2267. * the items.
  2268. *
  2269. * @type {array}
  2270. * @default [
  2271. * 'verticalCounter',
  2272. * 'verticalLabel',
  2273. * 'verticalArrow'
  2274. * ]
  2275. */
  2276. items: [
  2277. 'verticalCounter',
  2278. 'verticalLabel',
  2279. 'verticalArrow'
  2280. ],
  2281. verticalCounter: {
  2282. /**
  2283. * A predefined background symbol for the button.
  2284. *
  2285. * @type {string}
  2286. */
  2287. symbol: 'vertical-counter.svg'
  2288. },
  2289. verticalLabel: {
  2290. /**
  2291. * A predefined background symbol for the button.
  2292. *
  2293. * @type {string}
  2294. */
  2295. symbol: 'vertical-label.svg'
  2296. },
  2297. verticalArrow: {
  2298. /**
  2299. * A predefined background symbol for the button.
  2300. *
  2301. * @type {string}
  2302. */
  2303. symbol: 'vertical-arrow.svg'
  2304. }
  2305. },
  2306. advanced: {
  2307. /**
  2308. * A collection of strings pointing to config options for
  2309. * the items.
  2310. *
  2311. * @type {array}
  2312. * @default [
  2313. * 'fibonacci',
  2314. * 'pitchfork',
  2315. * 'parallelChannel'
  2316. * ]
  2317. */
  2318. items: [
  2319. 'fibonacci',
  2320. 'pitchfork',
  2321. 'parallelChannel'
  2322. ],
  2323. pitchfork: {
  2324. /**
  2325. * A predefined background symbol for the button.
  2326. *
  2327. * @type {string}
  2328. */
  2329. symbol: 'pitchfork.svg'
  2330. },
  2331. fibonacci: {
  2332. /**
  2333. * A predefined background symbol for the button.
  2334. *
  2335. * @type {string}
  2336. */
  2337. symbol: 'fibonacci.svg'
  2338. },
  2339. parallelChannel: {
  2340. /**
  2341. * A predefined background symbol for the button.
  2342. *
  2343. * @type {string}
  2344. */
  2345. symbol: 'parallel-channel.svg'
  2346. }
  2347. },
  2348. measure: {
  2349. /**
  2350. * A collection of strings pointing to config options for
  2351. * the items.
  2352. *
  2353. * @type {array}
  2354. * @default [
  2355. * 'measureXY',
  2356. * 'measureX',
  2357. * 'measureY'
  2358. * ]
  2359. */
  2360. items: [
  2361. 'measureXY',
  2362. 'measureX',
  2363. 'measureY'
  2364. ],
  2365. measureX: {
  2366. /**
  2367. * A predefined background symbol for the button.
  2368. *
  2369. * @type {string}
  2370. */
  2371. symbol: 'measure-x.svg'
  2372. },
  2373. measureY: {
  2374. /**
  2375. * A predefined background symbol for the button.
  2376. *
  2377. * @type {string}
  2378. */
  2379. symbol: 'measure-y.svg'
  2380. },
  2381. measureXY: {
  2382. /**
  2383. * A predefined background symbol for the button.
  2384. *
  2385. * @type {string}
  2386. */
  2387. symbol: 'measure-xy.svg'
  2388. }
  2389. },
  2390. toggleAnnotations: {
  2391. /**
  2392. * A predefined background symbol for the button.
  2393. *
  2394. * @type {string}
  2395. */
  2396. symbol: 'annotations-visible.svg'
  2397. },
  2398. currentPriceIndicator: {
  2399. /**
  2400. * A predefined background symbol for the button.
  2401. *
  2402. * @type {string}
  2403. */
  2404. symbol: 'current-price-show.svg'
  2405. },
  2406. indicators: {
  2407. /**
  2408. * A predefined background symbol for the button.
  2409. *
  2410. * @type {string}
  2411. */
  2412. symbol: 'indicators.svg'
  2413. },
  2414. zoomChange: {
  2415. /**
  2416. * A collection of strings pointing to config options for
  2417. * the items.
  2418. *
  2419. * @type {array}
  2420. * @default [
  2421. * 'zoomX',
  2422. * 'zoomY',
  2423. * 'zoomXY'
  2424. * ]
  2425. */
  2426. items: [
  2427. 'zoomX',
  2428. 'zoomY',
  2429. 'zoomXY'
  2430. ],
  2431. zoomX: {
  2432. /**
  2433. * A predefined background symbol for the button.
  2434. *
  2435. * @type {string}
  2436. */
  2437. symbol: 'zoom-x.svg'
  2438. },
  2439. zoomY: {
  2440. /**
  2441. * A predefined background symbol for the button.
  2442. *
  2443. * @type {string}
  2444. */
  2445. symbol: 'zoom-y.svg'
  2446. },
  2447. zoomXY: {
  2448. /**
  2449. * A predefined background symbol for the button.
  2450. *
  2451. * @type {string}
  2452. */
  2453. symbol: 'zoom-xy.svg'
  2454. }
  2455. },
  2456. typeChange: {
  2457. /**
  2458. * A collection of strings pointing to config options for
  2459. * the items.
  2460. *
  2461. * @type {array}
  2462. * @default [
  2463. * 'typeOHLC',
  2464. * 'typeLine',
  2465. * 'typeCandlestick'
  2466. * ]
  2467. */
  2468. items: [
  2469. 'typeOHLC',
  2470. 'typeLine',
  2471. 'typeCandlestick'
  2472. ],
  2473. typeOHLC: {
  2474. /**
  2475. * A predefined background symbol for the button.
  2476. *
  2477. * @type {string}
  2478. */
  2479. symbol: 'series-ohlc.svg'
  2480. },
  2481. typeLine: {
  2482. /**
  2483. * A predefined background symbol for the button.
  2484. *
  2485. * @type {string}
  2486. */
  2487. symbol: 'series-line.svg'
  2488. },
  2489. typeCandlestick: {
  2490. /**
  2491. * A predefined background symbol for the button.
  2492. *
  2493. * @type {string}
  2494. */
  2495. symbol: 'series-candlestick.svg'
  2496. }
  2497. },
  2498. fullScreen: {
  2499. /**
  2500. * A predefined background symbol for the button.
  2501. *
  2502. * @type {string}
  2503. */
  2504. symbol: 'fullscreen.svg'
  2505. },
  2506. saveChart: {
  2507. /**
  2508. * A predefined background symbol for the button.
  2509. *
  2510. * @type {string}
  2511. */
  2512. symbol: 'save-chart.svg'
  2513. }
  2514. }
  2515. }
  2516. }
  2517. });
  2518. /* eslint-disable no-invalid-this, valid-jsdoc */
  2519. // Run HTML generator
  2520. addEvent(H.Chart, 'afterGetContainer', function () {
  2521. this.setStockTools();
  2522. });
  2523. addEvent(H.Chart, 'getMargins', function () {
  2524. var listWrapper = this.stockTools && this.stockTools.listWrapper, offsetWidth = listWrapper && ((listWrapper.startWidth +
  2525. H.getStyle(listWrapper, 'padding-left') +
  2526. H.getStyle(listWrapper, 'padding-right')) || listWrapper.offsetWidth);
  2527. if (offsetWidth && offsetWidth < this.plotWidth) {
  2528. this.plotLeft += offsetWidth;
  2529. }
  2530. });
  2531. addEvent(H.Chart, 'destroy', function () {
  2532. if (this.stockTools) {
  2533. this.stockTools.destroy();
  2534. }
  2535. });
  2536. addEvent(H.Chart, 'redraw', function () {
  2537. if (this.stockTools && this.stockTools.guiEnabled) {
  2538. this.stockTools.redraw();
  2539. }
  2540. });
  2541. /**
  2542. * Toolbar Class
  2543. * @private
  2544. * @constructor
  2545. * @param {Object} - options of toolbar
  2546. * @param {Chart} - Reference to chart
  2547. */
  2548. H.Toolbar = function (options, langOptions, chart) {
  2549. this.chart = chart;
  2550. this.options = options;
  2551. this.lang = langOptions;
  2552. // set url for icons.
  2553. this.iconsURL = this.getIconsURL();
  2554. this.guiEnabled = options.enabled;
  2555. this.visible = pick(options.visible, true);
  2556. this.placed = pick(options.placed, false);
  2557. // General events collection which should be removed upon destroy/update:
  2558. this.eventsToUnbind = [];
  2559. if (this.guiEnabled) {
  2560. this.createHTML();
  2561. this.init();
  2562. this.showHideNavigatorion();
  2563. }
  2564. fireEvent(this, 'afterInit');
  2565. };
  2566. extend(H.Chart.prototype, {
  2567. /**
  2568. * Verify if Toolbar should be added.
  2569. * @private
  2570. * @param {Highcharts.StockToolsOptions} - chart options
  2571. * @return {void}
  2572. */
  2573. setStockTools: function (options) {
  2574. var chartOptions = this.options, lang = chartOptions.lang, guiOptions = merge(chartOptions.stockTools && chartOptions.stockTools.gui, options && options.gui), langOptions = lang.stockTools && lang.stockTools.gui;
  2575. this.stockTools = new H.Toolbar(guiOptions, langOptions, this);
  2576. if (this.stockTools.guiEnabled) {
  2577. this.isDirtyBox = true;
  2578. }
  2579. }
  2580. });
  2581. H.Toolbar.prototype = {
  2582. /**
  2583. * Initialize the toolbar. Create buttons and submenu for each option
  2584. * defined in `stockTools.gui`.
  2585. * @private
  2586. */
  2587. init: function () {
  2588. var _self = this, lang = this.lang, guiOptions = this.options, toolbar = this.toolbar, addSubmenu = _self.addSubmenu, buttons = guiOptions.buttons, defs = guiOptions.definitions, allButtons = toolbar.childNodes, inIframe = this.inIframe(), button;
  2589. // create buttons
  2590. buttons.forEach(function (btnName) {
  2591. button = _self.addButton(toolbar, defs, btnName, lang);
  2592. if (inIframe && btnName === 'fullScreen') {
  2593. button.buttonWrapper.className +=
  2594. ' ' + PREFIX + 'disabled-btn';
  2595. }
  2596. _self.eventsToUnbind.push(addEvent(button.buttonWrapper, 'click', function () {
  2597. _self.eraseActiveButtons(allButtons, button.buttonWrapper);
  2598. }));
  2599. if (isArray(defs[btnName].items)) {
  2600. // create submenu buttons
  2601. addSubmenu.call(_self, button, defs[btnName]);
  2602. }
  2603. });
  2604. },
  2605. /**
  2606. * Create submenu (list of buttons) for the option. In example main button
  2607. * is Line, in submenu will be buttons with types of lines.
  2608. * @private
  2609. * @param {Highcharts.Dictionary<Highcharts.HTMLDOMElement>}
  2610. * button which has submenu
  2611. * @param {Highcharts.StockToolsGuiDefinitionsButtonsOptions}
  2612. * list of all buttons
  2613. */
  2614. addSubmenu: function (parentBtn, button) {
  2615. var _self = this, submenuArrow = parentBtn.submenuArrow, buttonWrapper = parentBtn.buttonWrapper, buttonWidth = getStyle(buttonWrapper, 'width'), wrapper = this.wrapper, menuWrapper = this.listWrapper, allButtons = this.toolbar.childNodes, topMargin = 0, submenuWrapper;
  2616. // create submenu container
  2617. this.submenu = submenuWrapper = createElement(UL, {
  2618. className: PREFIX + 'submenu-wrapper'
  2619. }, null, buttonWrapper);
  2620. // create submenu buttons and select the first one
  2621. this.addSubmenuItems(buttonWrapper, button);
  2622. // show / hide submenu
  2623. _self.eventsToUnbind.push(addEvent(submenuArrow, 'click', function (e) {
  2624. e.stopPropagation();
  2625. // Erase active class on all other buttons
  2626. _self.eraseActiveButtons(allButtons, buttonWrapper);
  2627. // hide menu
  2628. if (buttonWrapper.className.indexOf(PREFIX + 'current') >= 0) {
  2629. menuWrapper.style.width =
  2630. menuWrapper.startWidth + 'px';
  2631. buttonWrapper.classList.remove(PREFIX + 'current');
  2632. submenuWrapper.style.display = 'none';
  2633. }
  2634. else {
  2635. // show menu
  2636. // to calculate height of element
  2637. submenuWrapper.style.display = 'block';
  2638. topMargin = submenuWrapper.offsetHeight -
  2639. buttonWrapper.offsetHeight - 3;
  2640. // calculate position of submenu in the box
  2641. // if submenu is inside, reset top margin
  2642. if (
  2643. // cut on the bottom
  2644. !(submenuWrapper.offsetHeight +
  2645. buttonWrapper.offsetTop >
  2646. wrapper.offsetHeight &&
  2647. // cut on the top
  2648. buttonWrapper.offsetTop > topMargin)) {
  2649. topMargin = 0;
  2650. }
  2651. // apply calculated styles
  2652. css(submenuWrapper, {
  2653. top: -topMargin + 'px',
  2654. left: buttonWidth + 3 + 'px'
  2655. });
  2656. buttonWrapper.className += ' ' + PREFIX + 'current';
  2657. menuWrapper.startWidth = wrapper.offsetWidth;
  2658. menuWrapper.style.width = menuWrapper.startWidth +
  2659. H.getStyle(menuWrapper, 'padding-left') +
  2660. submenuWrapper.offsetWidth + 3 + 'px';
  2661. }
  2662. }));
  2663. },
  2664. /**
  2665. * Create buttons in submenu
  2666. * @private
  2667. * @param {Highcharts.HTMLDOMElement}
  2668. * button where submenu is placed
  2669. * @param {Highcharts.StockToolsGuiDefinitionsButtonsOptions}
  2670. * list of all buttons options
  2671. *
  2672. */
  2673. addSubmenuItems: function (buttonWrapper, button) {
  2674. var _self = this, submenuWrapper = this.submenu, lang = this.lang, menuWrapper = this.listWrapper, items = button.items, firstSubmenuItem, submenuBtn;
  2675. // add items to submenu
  2676. items.forEach(function (btnName) {
  2677. // add buttons to submenu
  2678. submenuBtn = _self.addButton(submenuWrapper, button, btnName, lang);
  2679. _self.eventsToUnbind.push(addEvent(submenuBtn.mainButton, 'click', function () {
  2680. _self.switchSymbol(this, buttonWrapper, true);
  2681. menuWrapper.style.width =
  2682. menuWrapper.startWidth + 'px';
  2683. submenuWrapper.style.display = 'none';
  2684. }));
  2685. });
  2686. // select first submenu item
  2687. firstSubmenuItem = submenuWrapper
  2688. .querySelectorAll('li > .' + PREFIX + 'menu-item-btn')[0];
  2689. // replace current symbol, in main button, with submenu's button style
  2690. _self.switchSymbol(firstSubmenuItem, false);
  2691. },
  2692. /*
  2693. * Erase active class on all other buttons.
  2694. *
  2695. * @param {Array} - Array of HTML buttons
  2696. * @param {HTMLDOMElement} - Current HTML button
  2697. *
  2698. */
  2699. eraseActiveButtons: function (buttons, currentButton, submenuItems) {
  2700. [].forEach.call(buttons, function (btn) {
  2701. if (btn !== currentButton) {
  2702. btn.classList.remove(PREFIX + 'current');
  2703. btn.classList.remove(PREFIX + 'active');
  2704. submenuItems =
  2705. btn.querySelectorAll('.' + PREFIX + 'submenu-wrapper');
  2706. // hide submenu
  2707. if (submenuItems.length > 0) {
  2708. submenuItems[0].style.display = 'none';
  2709. }
  2710. }
  2711. });
  2712. },
  2713. /**
  2714. * Create single button. Consist of HTML elements `li`, `span`, and (if
  2715. * exists) submenu container.
  2716. * @private
  2717. * @param {HTMLDOMElement} - HTML reference, where button should be added
  2718. * @param {Object} - all options, by btnName refer to particular button
  2719. * @param {String} - name of functionality mapped for specific class
  2720. * @param {Object} - All titles, by btnName refer to particular button
  2721. * @return {Object} - references to all created HTML elements
  2722. */
  2723. addButton: function (target, options, btnName, lang) {
  2724. var btnOptions = options[btnName], items = btnOptions.items, classMapping = H.Toolbar.prototype.classMapping, userClassName = btnOptions.className || '', mainButton, submenuArrow, buttonWrapper;
  2725. // main button wrapper
  2726. buttonWrapper = createElement(LI, {
  2727. className: pick(classMapping[btnName], '') + ' ' + userClassName,
  2728. title: lang[btnName] || btnName
  2729. }, null, target);
  2730. // single button
  2731. mainButton = createElement(SPAN, {
  2732. className: PREFIX + 'menu-item-btn'
  2733. }, null, buttonWrapper);
  2734. // submenu
  2735. if (items && items.length) {
  2736. // arrow is a hook to show / hide submenu
  2737. submenuArrow = createElement(SPAN, {
  2738. className: PREFIX + 'submenu-item-arrow ' +
  2739. PREFIX + 'arrow-right'
  2740. }, null, buttonWrapper);
  2741. submenuArrow.style['background-image'] = 'url(' +
  2742. this.iconsURL + 'arrow-bottom.svg)';
  2743. }
  2744. else {
  2745. mainButton.style['background-image'] = 'url(' +
  2746. this.iconsURL + btnOptions.symbol + ')';
  2747. }
  2748. return {
  2749. buttonWrapper: buttonWrapper,
  2750. mainButton: mainButton,
  2751. submenuArrow: submenuArrow
  2752. };
  2753. },
  2754. /*
  2755. * Create navigation's HTML elements: container and arrows.
  2756. *
  2757. */
  2758. addNavigation: function () {
  2759. var stockToolbar = this, wrapper = stockToolbar.wrapper;
  2760. // arrow wrapper
  2761. stockToolbar.arrowWrapper = createElement(DIV, {
  2762. className: PREFIX + 'arrow-wrapper'
  2763. });
  2764. stockToolbar.arrowUp = createElement(DIV, {
  2765. className: PREFIX + 'arrow-up'
  2766. }, null, stockToolbar.arrowWrapper);
  2767. stockToolbar.arrowUp.style['background-image'] =
  2768. 'url(' + this.iconsURL + 'arrow-right.svg)';
  2769. stockToolbar.arrowDown = createElement(DIV, {
  2770. className: PREFIX + 'arrow-down'
  2771. }, null, stockToolbar.arrowWrapper);
  2772. stockToolbar.arrowDown.style['background-image'] =
  2773. 'url(' + this.iconsURL + 'arrow-right.svg)';
  2774. wrapper.insertBefore(stockToolbar.arrowWrapper, wrapper.childNodes[0]);
  2775. // attach scroll events
  2776. stockToolbar.scrollButtons();
  2777. },
  2778. /*
  2779. * Add events to navigation (two arrows) which allows user to scroll
  2780. * top/down GUI buttons, if container's height is not enough.
  2781. *
  2782. */
  2783. scrollButtons: function () {
  2784. var targetY = 0, _self = this, wrapper = _self.wrapper, toolbar = _self.toolbar, step = 0.1 * wrapper.offsetHeight; // 0.1 = 10%
  2785. _self.eventsToUnbind.push(addEvent(_self.arrowUp, 'click', function () {
  2786. if (targetY > 0) {
  2787. targetY -= step;
  2788. toolbar.style['margin-top'] = -targetY + 'px';
  2789. }
  2790. }));
  2791. _self.eventsToUnbind.push(addEvent(_self.arrowDown, 'click', function () {
  2792. if (wrapper.offsetHeight + targetY <=
  2793. toolbar.offsetHeight + step) {
  2794. targetY += step;
  2795. toolbar.style['margin-top'] = -targetY + 'px';
  2796. }
  2797. }));
  2798. },
  2799. /*
  2800. * Create stockTools HTML main elements.
  2801. *
  2802. */
  2803. createHTML: function () {
  2804. var stockToolbar = this, chart = stockToolbar.chart, guiOptions = stockToolbar.options, container = chart.container, navigation = chart.options.navigation, bindingsClassName = navigation && navigation.bindingsClassName, listWrapper, toolbar, wrapper;
  2805. // create main container
  2806. stockToolbar.wrapper = wrapper = createElement(DIV, {
  2807. className: PREFIX + 'stocktools-wrapper ' +
  2808. guiOptions.className + ' ' + bindingsClassName
  2809. });
  2810. container.parentNode.insertBefore(wrapper, container);
  2811. // toolbar
  2812. stockToolbar.toolbar = toolbar = createElement(UL, {
  2813. className: PREFIX + 'stocktools-toolbar ' +
  2814. guiOptions.toolbarClassName
  2815. });
  2816. // add container for list of buttons
  2817. stockToolbar.listWrapper = listWrapper = createElement(DIV, {
  2818. className: PREFIX + 'menu-wrapper'
  2819. });
  2820. wrapper.insertBefore(listWrapper, wrapper.childNodes[0]);
  2821. listWrapper.insertBefore(toolbar, listWrapper.childNodes[0]);
  2822. stockToolbar.showHideToolbar();
  2823. // add navigation which allows user to scroll down / top GUI buttons
  2824. stockToolbar.addNavigation();
  2825. },
  2826. /**
  2827. * Function called in redraw verifies if the navigation should be visible.
  2828. * @private
  2829. */
  2830. showHideNavigatorion: function () {
  2831. // arrows
  2832. // 50px space for arrows
  2833. if (this.visible &&
  2834. this.toolbar.offsetHeight > (this.wrapper.offsetHeight - 50)) {
  2835. this.arrowWrapper.style.display = 'block';
  2836. }
  2837. else {
  2838. // reset margin if whole toolbar is visible
  2839. this.toolbar.style.marginTop = '0px';
  2840. // hide arrows
  2841. this.arrowWrapper.style.display = 'none';
  2842. }
  2843. },
  2844. /**
  2845. * Create button which shows or hides GUI toolbar.
  2846. * @private
  2847. */
  2848. showHideToolbar: function () {
  2849. var stockToolbar = this, chart = this.chart, wrapper = stockToolbar.wrapper, toolbar = this.listWrapper, submenu = this.submenu, visible = this.visible, showhideBtn;
  2850. // Show hide toolbar
  2851. this.showhideBtn = showhideBtn = createElement(DIV, {
  2852. className: PREFIX + 'toggle-toolbar ' + PREFIX + 'arrow-left'
  2853. }, null, wrapper);
  2854. showhideBtn.style['background-image'] =
  2855. 'url(' + this.iconsURL + 'arrow-right.svg)';
  2856. if (!visible) {
  2857. // hide
  2858. if (submenu) {
  2859. submenu.style.display = 'none';
  2860. }
  2861. showhideBtn.style.left = '0px';
  2862. stockToolbar.visible = visible = false;
  2863. toolbar.classList.add(PREFIX + 'hide');
  2864. showhideBtn.classList.toggle(PREFIX + 'arrow-right');
  2865. wrapper.style.height = showhideBtn.offsetHeight + 'px';
  2866. }
  2867. else {
  2868. wrapper.style.height = '100%';
  2869. showhideBtn.style.top = H.getStyle(toolbar, 'padding-top') + 'px';
  2870. showhideBtn.style.left = (wrapper.offsetWidth +
  2871. H.getStyle(toolbar, 'padding-left')) + 'px';
  2872. }
  2873. // Toggle menu
  2874. stockToolbar.eventsToUnbind.push(addEvent(showhideBtn, 'click', function () {
  2875. chart.update({
  2876. stockTools: {
  2877. gui: {
  2878. visible: !visible,
  2879. placed: true
  2880. }
  2881. }
  2882. });
  2883. }));
  2884. },
  2885. /*
  2886. * In main GUI button, replace icon and class with submenu button's
  2887. * class / symbol.
  2888. *
  2889. * @param {HTMLDOMElement} - submenu button
  2890. * @param {Boolean} - true or false
  2891. *
  2892. */
  2893. switchSymbol: function (button, redraw) {
  2894. var buttonWrapper = button.parentNode, buttonWrapperClass = buttonWrapper.classList.value,
  2895. // main button in first level og GUI
  2896. mainNavButton = buttonWrapper.parentNode.parentNode;
  2897. // set class
  2898. mainNavButton.className = '';
  2899. if (buttonWrapperClass) {
  2900. mainNavButton.classList.add(buttonWrapperClass.trim());
  2901. }
  2902. // set icon
  2903. mainNavButton
  2904. .querySelectorAll('.' + PREFIX + 'menu-item-btn')[0]
  2905. .style['background-image'] =
  2906. button.style['background-image'];
  2907. // set active class
  2908. if (redraw) {
  2909. this.selectButton(mainNavButton);
  2910. }
  2911. },
  2912. /*
  2913. * Set select state (active class) on button.
  2914. *
  2915. * @param {HTMLDOMElement} - button
  2916. *
  2917. */
  2918. selectButton: function (button) {
  2919. if (button.className.indexOf(activeClass) >= 0) {
  2920. button.classList.remove(activeClass);
  2921. }
  2922. else {
  2923. button.classList.add(activeClass);
  2924. }
  2925. },
  2926. /*
  2927. * Remove active class from all buttons except defined.
  2928. *
  2929. * @param {HTMLDOMElement} - button which should not be deactivated
  2930. *
  2931. */
  2932. unselectAllButtons: function (button) {
  2933. var activeButtons = button.parentNode
  2934. .querySelectorAll('.' + activeClass);
  2935. [].forEach.call(activeButtons, function (activeBtn) {
  2936. if (activeBtn !== button) {
  2937. activeBtn.classList.remove(activeClass);
  2938. }
  2939. });
  2940. },
  2941. /*
  2942. * Verify if chart is in iframe.
  2943. *
  2944. * @return {Object} - elements translations.
  2945. */
  2946. inIframe: function () {
  2947. try {
  2948. return win.self !== win.top;
  2949. }
  2950. catch (e) {
  2951. return true;
  2952. }
  2953. },
  2954. /*
  2955. * Update GUI with given options.
  2956. *
  2957. * @param {Object} - general options for Stock Tools
  2958. */
  2959. update: function (options) {
  2960. merge(true, this.chart.options.stockTools, options);
  2961. this.destroy();
  2962. this.chart.setStockTools(options);
  2963. // If Stock Tools are updated, then bindings should be updated too:
  2964. if (this.chart.navigationBindings) {
  2965. this.chart.navigationBindings.update();
  2966. }
  2967. },
  2968. /**
  2969. * Destroy all HTML GUI elements.
  2970. * @private
  2971. */
  2972. destroy: function () {
  2973. var stockToolsDiv = this.wrapper, parent = stockToolsDiv && stockToolsDiv.parentNode;
  2974. this.eventsToUnbind.forEach(function (unbinder) {
  2975. unbinder();
  2976. });
  2977. // Remove the empty element
  2978. if (parent) {
  2979. parent.removeChild(stockToolsDiv);
  2980. }
  2981. // redraw
  2982. this.chart.isDirtyBox = true;
  2983. this.chart.redraw();
  2984. },
  2985. /**
  2986. * Redraw, GUI requires to verify if the navigation should be visible.
  2987. * @private
  2988. */
  2989. redraw: function () {
  2990. this.showHideNavigatorion();
  2991. },
  2992. getIconsURL: function () {
  2993. return this.chart.options.navigation.iconsURL ||
  2994. this.options.iconsURL ||
  2995. 'https://code.highcharts.com/8.0.0/gfx/stock-icons/';
  2996. },
  2997. /**
  2998. * Mapping JSON fields to CSS classes.
  2999. * @private
  3000. */
  3001. classMapping: {
  3002. circle: PREFIX + 'circle-annotation',
  3003. rectangle: PREFIX + 'rectangle-annotation',
  3004. label: PREFIX + 'label-annotation',
  3005. segment: PREFIX + 'segment',
  3006. arrowSegment: PREFIX + 'arrow-segment',
  3007. ray: PREFIX + 'ray',
  3008. arrowRay: PREFIX + 'arrow-ray',
  3009. line: PREFIX + 'infinity-line',
  3010. arrowLine: PREFIX + 'arrow-infinity-line',
  3011. verticalLine: PREFIX + 'vertical-line',
  3012. horizontalLine: PREFIX + 'horizontal-line',
  3013. crooked3: PREFIX + 'crooked3',
  3014. crooked5: PREFIX + 'crooked5',
  3015. elliott3: PREFIX + 'elliott3',
  3016. elliott5: PREFIX + 'elliott5',
  3017. pitchfork: PREFIX + 'pitchfork',
  3018. fibonacci: PREFIX + 'fibonacci',
  3019. parallelChannel: PREFIX + 'parallel-channel',
  3020. measureX: PREFIX + 'measure-x',
  3021. measureY: PREFIX + 'measure-y',
  3022. measureXY: PREFIX + 'measure-xy',
  3023. verticalCounter: PREFIX + 'vertical-counter',
  3024. verticalLabel: PREFIX + 'vertical-label',
  3025. verticalArrow: PREFIX + 'vertical-arrow',
  3026. currentPriceIndicator: PREFIX + 'current-price-indicator',
  3027. indicators: PREFIX + 'indicators',
  3028. flagCirclepin: PREFIX + 'flag-circlepin',
  3029. flagDiamondpin: PREFIX + 'flag-diamondpin',
  3030. flagSquarepin: PREFIX + 'flag-squarepin',
  3031. flagSimplepin: PREFIX + 'flag-simplepin',
  3032. zoomX: PREFIX + 'zoom-x',
  3033. zoomY: PREFIX + 'zoom-y',
  3034. zoomXY: PREFIX + 'zoom-xy',
  3035. typeLine: PREFIX + 'series-type-line',
  3036. typeOHLC: PREFIX + 'series-type-ohlc',
  3037. typeCandlestick: PREFIX + 'series-type-candlestick',
  3038. fullScreen: PREFIX + 'full-screen',
  3039. toggleAnnotations: PREFIX + 'toggle-annotations',
  3040. saveChart: PREFIX + 'save-chart',
  3041. separator: PREFIX + 'separator'
  3042. }
  3043. };
  3044. // Comunication with bindings:
  3045. addEvent(H.NavigationBindings, 'selectButton', function (event) {
  3046. var button = event.button, className = PREFIX + 'submenu-wrapper', gui = this.chart.stockTools;
  3047. if (gui && gui.guiEnabled) {
  3048. // Unslect other active buttons
  3049. gui.unselectAllButtons(event.button);
  3050. // If clicked on a submenu, select state for it's parent
  3051. if (button.parentNode.className.indexOf(className) >= 0) {
  3052. button = button.parentNode.parentNode;
  3053. }
  3054. // Set active class on the current button
  3055. gui.selectButton(button);
  3056. }
  3057. });
  3058. addEvent(H.NavigationBindings, 'deselectButton', function (event) {
  3059. var button = event.button, className = PREFIX + 'submenu-wrapper', gui = this.chart.stockTools;
  3060. if (gui && gui.guiEnabled) {
  3061. // If deselecting a button from a submenu, select state for it's parent
  3062. if (button.parentNode.className.indexOf(className) >= 0) {
  3063. button = button.parentNode.parentNode;
  3064. }
  3065. gui.selectButton(button);
  3066. }
  3067. });
  3068. });
  3069. _registerModule(_modules, 'masters/modules/stock-tools.src.js', [], function () {
  3070. });
  3071. }));