Annotations.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  1. /* *
  2. *
  3. * (c) 2009-2017 Highsoft, Black Label
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. 'use strict';
  11. import Chart from '../../Core/Chart/Chart.js';
  12. var chartProto = Chart.prototype;
  13. import ControllableMixin from './Mixins/ControllableMixin.js';
  14. import ControllableRect from './Controllables/ControllableRect.js';
  15. import ControllableCircle from './Controllables/ControllableCircle.js';
  16. import ControllablePath from './Controllables/ControllablePath.js';
  17. import ControllableImage from './Controllables/ControllableImage.js';
  18. import ControllableLabel from './Controllables/ControllableLabel.js';
  19. import ControlPoint from './ControlPoint.js';
  20. import EventEmitterMixin from './Mixins/EventEmitterMixin.js';
  21. import H from '../../Core/Globals.js';
  22. import MockPoint from './MockPoint.js';
  23. import Pointer from '../../Core/Pointer.js';
  24. import U from '../../Core/Utilities.js';
  25. var addEvent = U.addEvent, defined = U.defined, destroyObjectProperties = U.destroyObjectProperties, erase = U.erase, extend = U.extend, find = U.find, fireEvent = U.fireEvent, getDeferredAnimation = U.getDeferredAnimation, merge = U.merge, pick = U.pick, splat = U.splat, wrap = U.wrap;
  26. /* *********************************************************************
  27. *
  28. * ANNOTATION
  29. *
  30. ******************************************************************** */
  31. /**
  32. * Possible directions for draggable annotations. An empty string (`''`)
  33. * makes the annotation undraggable.
  34. *
  35. * @typedef {''|'x'|'xy'|'y'} Highcharts.AnnotationDraggableValue
  36. */
  37. /**
  38. * @private
  39. * @typedef {
  40. * Highcharts.AnnotationControllableCircle|
  41. * Highcharts.AnnotationControllableImage|
  42. * Highcharts.AnnotationControllablePath|
  43. * Highcharts.AnnotationControllableRect
  44. * }
  45. * Highcharts.AnnotationShapeType
  46. * @requires modules/annotations
  47. */
  48. /**
  49. * @private
  50. * @typedef {
  51. * Highcharts.AnnotationControllableLabel
  52. * }
  53. * Highcharts.AnnotationLabelType
  54. * @requires modules/annotations
  55. */
  56. /**
  57. * A point-like object, a mock point or a point used in series.
  58. * @private
  59. * @typedef {Highcharts.AnnotationMockPoint|Highcharts.Point} Highcharts.AnnotationPointType
  60. * @requires modules/annotations
  61. */
  62. /* eslint-disable no-invalid-this, valid-jsdoc */
  63. /**
  64. * An annotation class which serves as a container for items like labels or
  65. * shapes. Created items are positioned on the chart either by linking them to
  66. * existing points or created mock points
  67. *
  68. * @class
  69. * @name Highcharts.Annotation
  70. *
  71. * @param {Highcharts.Chart} chart a chart instance
  72. * @param {Highcharts.AnnotationsOptions} userOptions the options object
  73. */
  74. var Annotation = /** @class */ (function () {
  75. /* *
  76. *
  77. * Constructors
  78. *
  79. * */
  80. function Annotation(chart, userOptions) {
  81. /* *
  82. *
  83. * Properties
  84. *
  85. * */
  86. this.annotation = void 0;
  87. this.coll = 'annotations';
  88. this.collection = void 0;
  89. this.animationConfig = void 0;
  90. this.graphic = void 0;
  91. this.group = void 0;
  92. this.labelCollector = void 0;
  93. this.labelsGroup = void 0;
  94. this.shapesGroup = void 0;
  95. var labelsAndShapes;
  96. /**
  97. * The chart that the annotation belongs to.
  98. *
  99. * @type {Highcharts.Chart}
  100. */
  101. this.chart = chart;
  102. /**
  103. * The array of points which defines the annotation.
  104. *
  105. * @type {Array<Highcharts.Point>}
  106. */
  107. this.points = [];
  108. /**
  109. * The array of control points.
  110. *
  111. * @private
  112. * @name Highcharts.Annotation#controlPoints
  113. * @type {Array<Annotation.ControlPoint>}
  114. */
  115. this.controlPoints = [];
  116. this.coll = 'annotations';
  117. /**
  118. * The array of labels which belong to the annotation.
  119. *
  120. * @private
  121. * @name Highcharts.Annotation#labels
  122. * @type {Array<Highcharts.AnnotationLabelType>}
  123. */
  124. this.labels = [];
  125. /**
  126. * The array of shapes which belong to the annotation.
  127. *
  128. * @private
  129. * @name Highcharts.Annotation#shapes
  130. * @type {Array<Highcharts.AnnotationShapeType>}
  131. */
  132. this.shapes = [];
  133. /**
  134. * The options for the annotations.
  135. *
  136. * @name Highcharts.Annotation#options
  137. * @type {Highcharts.AnnotationsOptions}
  138. */
  139. this.options = merge(this.defaultOptions, userOptions);
  140. /**
  141. * The user options for the annotations.
  142. *
  143. * @name Highcharts.Annotation#userOptions
  144. * @type {Highcharts.AnnotationsOptions}
  145. */
  146. this.userOptions = userOptions;
  147. // Handle labels and shapes - those are arrays
  148. // Merging does not work with arrays (stores reference)
  149. labelsAndShapes = this.getLabelsAndShapesOptions(this.options, userOptions);
  150. this.options.labels = labelsAndShapes.labels;
  151. this.options.shapes = labelsAndShapes.shapes;
  152. /**
  153. * The callback that reports to the overlapping-labels module which
  154. * labels it should account for.
  155. * @private
  156. * @name Highcharts.Annotation#labelCollector
  157. * @type {Function}
  158. */
  159. /**
  160. * The group svg element.
  161. *
  162. * @name Highcharts.Annotation#group
  163. * @type {Highcharts.SVGElement}
  164. */
  165. /**
  166. * The group svg element of the annotation's shapes.
  167. *
  168. * @name Highcharts.Annotation#shapesGroup
  169. * @type {Highcharts.SVGElement}
  170. */
  171. /**
  172. * The group svg element of the annotation's labels.
  173. *
  174. * @name Highcharts.Annotation#labelsGroup
  175. * @type {Highcharts.SVGElement}
  176. */
  177. this.init(chart, this.options);
  178. }
  179. /**
  180. * Initialize the annotation.
  181. * @private
  182. */
  183. Annotation.prototype.init = function () {
  184. var chart = this.chart, animOptions = this.options.animation;
  185. this.linkPoints();
  186. this.addControlPoints();
  187. this.addShapes();
  188. this.addLabels();
  189. this.setLabelCollector();
  190. this.animationConfig = getDeferredAnimation(chart, animOptions);
  191. };
  192. Annotation.prototype.getLabelsAndShapesOptions = function (baseOptions, newOptions) {
  193. var mergedOptions = {};
  194. ['labels', 'shapes'].forEach(function (name) {
  195. if (baseOptions[name]) {
  196. mergedOptions[name] = splat(newOptions[name]).map(function (basicOptions, i) {
  197. return merge(baseOptions[name][i], basicOptions);
  198. });
  199. }
  200. });
  201. return mergedOptions;
  202. };
  203. Annotation.prototype.addShapes = function () {
  204. (this.options.shapes || []).forEach(function (shapeOptions, i) {
  205. var shape = this.initShape(shapeOptions, i);
  206. merge(true, this.options.shapes[i], shape.options);
  207. }, this);
  208. };
  209. Annotation.prototype.addLabels = function () {
  210. (this.options.labels || []).forEach(function (labelsOptions, i) {
  211. var labels = this.initLabel(labelsOptions, i);
  212. merge(true, this.options.labels[i], labels.options);
  213. }, this);
  214. };
  215. Annotation.prototype.addClipPaths = function () {
  216. this.setClipAxes();
  217. if (this.clipXAxis && this.clipYAxis) {
  218. this.clipRect = this.chart.renderer.clipRect(this.getClipBox());
  219. }
  220. };
  221. Annotation.prototype.setClipAxes = function () {
  222. var xAxes = this.chart.xAxis, yAxes = this.chart.yAxis, linkedAxes = (this.options.labels || [])
  223. .concat(this.options.shapes || [])
  224. .reduce(function (axes, labelOrShape) {
  225. return [
  226. xAxes[labelOrShape &&
  227. labelOrShape.point &&
  228. labelOrShape.point.xAxis] || axes[0],
  229. yAxes[labelOrShape &&
  230. labelOrShape.point &&
  231. labelOrShape.point.yAxis] || axes[1]
  232. ];
  233. }, []);
  234. this.clipXAxis = linkedAxes[0];
  235. this.clipYAxis = linkedAxes[1];
  236. };
  237. Annotation.prototype.getClipBox = function () {
  238. if (this.clipXAxis && this.clipYAxis) {
  239. return {
  240. x: this.clipXAxis.left,
  241. y: this.clipYAxis.top,
  242. width: this.clipXAxis.width,
  243. height: this.clipYAxis.height
  244. };
  245. }
  246. };
  247. Annotation.prototype.setLabelCollector = function () {
  248. var annotation = this;
  249. annotation.labelCollector = function () {
  250. return annotation.labels.reduce(function (labels, label) {
  251. if (!label.options.allowOverlap) {
  252. labels.push(label.graphic);
  253. }
  254. return labels;
  255. }, []);
  256. };
  257. annotation.chart.labelCollectors.push(annotation.labelCollector);
  258. };
  259. /**
  260. * Set an annotation options.
  261. * @private
  262. * @param {Highcharts.AnnotationsOptions} - user options for an annotation
  263. */
  264. Annotation.prototype.setOptions = function (userOptions) {
  265. this.options = merge(this.defaultOptions, userOptions);
  266. };
  267. Annotation.prototype.redraw = function (animation) {
  268. this.linkPoints();
  269. if (!this.graphic) {
  270. this.render();
  271. }
  272. if (this.clipRect) {
  273. this.clipRect.animate(this.getClipBox());
  274. }
  275. this.redrawItems(this.shapes, animation);
  276. this.redrawItems(this.labels, animation);
  277. ControllableMixin.redraw.call(this, animation);
  278. };
  279. /**
  280. * @private
  281. * @param {Array<Highcharts.AnnotationControllable>} items
  282. * @param {boolean} [animation]
  283. */
  284. Annotation.prototype.redrawItems = function (items, animation) {
  285. var i = items.length;
  286. // needs a backward loop
  287. // labels/shapes array might be modified
  288. // due to destruction of the item
  289. while (i--) {
  290. this.redrawItem(items[i], animation);
  291. }
  292. };
  293. /**
  294. * @private
  295. * @param {Array<Highcharts.AnnotationControllable>} items
  296. */
  297. Annotation.prototype.renderItems = function (items) {
  298. var i = items.length;
  299. while (i--) {
  300. this.renderItem(items[i]);
  301. }
  302. };
  303. Annotation.prototype.render = function () {
  304. var renderer = this.chart.renderer;
  305. this.graphic = renderer
  306. .g('annotation')
  307. .attr({
  308. opacity: 0,
  309. zIndex: this.options.zIndex,
  310. visibility: this.options.visible ?
  311. 'visible' :
  312. 'hidden'
  313. })
  314. .add();
  315. this.shapesGroup = renderer
  316. .g('annotation-shapes')
  317. .add(this.graphic)
  318. .clip(this.chart.plotBoxClip);
  319. this.labelsGroup = renderer
  320. .g('annotation-labels')
  321. .attr({
  322. // hideOverlappingLabels requires translation
  323. translateX: 0,
  324. translateY: 0
  325. })
  326. .add(this.graphic);
  327. this.addClipPaths();
  328. if (this.clipRect) {
  329. this.graphic.clip(this.clipRect);
  330. }
  331. // Render shapes and labels before adding events (#13070).
  332. this.renderItems(this.shapes);
  333. this.renderItems(this.labels);
  334. this.addEvents();
  335. ControllableMixin.render.call(this);
  336. };
  337. /**
  338. * Set the annotation's visibility.
  339. * @private
  340. * @param {boolean} [visible]
  341. * Whether to show or hide an annotation. If the param is omitted, the
  342. * annotation's visibility is toggled.
  343. */
  344. Annotation.prototype.setVisibility = function (visible) {
  345. var options = this.options, visibility = pick(visible, !options.visible);
  346. this.graphic.attr('visibility', visibility ? 'visible' : 'hidden');
  347. if (!visibility) {
  348. this.setControlPointsVisibility(false);
  349. }
  350. options.visible = visibility;
  351. };
  352. Annotation.prototype.setControlPointsVisibility = function (visible) {
  353. var setItemControlPointsVisibility = function (item) {
  354. item.setControlPointsVisibility(visible);
  355. };
  356. ControllableMixin.setControlPointsVisibility.call(this, visible);
  357. this.shapes.forEach(setItemControlPointsVisibility);
  358. this.labels.forEach(setItemControlPointsVisibility);
  359. };
  360. /**
  361. * Destroy the annotation. This function does not touch the chart
  362. * that the annotation belongs to (all annotations are kept in
  363. * the chart.annotations array) - it is recommended to use
  364. * {@link Highcharts.Chart#removeAnnotation} instead.
  365. * @private
  366. */
  367. Annotation.prototype.destroy = function () {
  368. var chart = this.chart, destroyItem = function (item) {
  369. item.destroy();
  370. };
  371. this.labels.forEach(destroyItem);
  372. this.shapes.forEach(destroyItem);
  373. this.clipXAxis = null;
  374. this.clipYAxis = null;
  375. erase(chart.labelCollectors, this.labelCollector);
  376. EventEmitterMixin.destroy.call(this);
  377. ControllableMixin.destroy.call(this);
  378. destroyObjectProperties(this, chart);
  379. };
  380. /**
  381. * See {@link Highcharts.Chart#removeAnnotation}.
  382. * @private
  383. */
  384. Annotation.prototype.remove = function () {
  385. // Let chart.update() remove annoations on demand
  386. return this.chart.removeAnnotation(this);
  387. };
  388. /**
  389. * Updates an annotation.
  390. *
  391. * @function Highcharts.Annotation#update
  392. *
  393. * @param {Partial<Highcharts.AnnotationsOptions>} userOptions
  394. * New user options for the annotation.
  395. *
  396. * @return {void}
  397. */
  398. Annotation.prototype.update = function (userOptions, redraw) {
  399. var chart = this.chart, labelsAndShapes = this.getLabelsAndShapesOptions(this.userOptions, userOptions), userOptionsIndex = chart.annotations.indexOf(this), options = merge(true, this.userOptions, userOptions);
  400. options.labels = labelsAndShapes.labels;
  401. options.shapes = labelsAndShapes.shapes;
  402. this.destroy();
  403. this.constructor(chart, options);
  404. // Update options in chart options, used in exporting (#9767):
  405. chart.options.annotations[userOptionsIndex] = options;
  406. this.isUpdating = true;
  407. if (pick(redraw, true)) {
  408. chart.redraw();
  409. }
  410. fireEvent(this, 'afterUpdate');
  411. this.isUpdating = false;
  412. };
  413. /* *************************************************************
  414. * ITEM SECTION
  415. * Contains methods for handling a single item in an annotation
  416. **************************************************************** */
  417. /**
  418. * Initialisation of a single shape
  419. * @private
  420. * @param {Object} shapeOptions - a confg object for a single shape
  421. */
  422. Annotation.prototype.initShape = function (shapeOptions, index) {
  423. var options = merge(this.options.shapeOptions, {
  424. controlPointOptions: this.options.controlPointOptions
  425. }, shapeOptions), shape = new Annotation.shapesMap[options.type](this, options, index);
  426. shape.itemType = 'shape';
  427. this.shapes.push(shape);
  428. return shape;
  429. };
  430. /**
  431. * Initialisation of a single label
  432. * @private
  433. */
  434. Annotation.prototype.initLabel = function (labelOptions, index) {
  435. var options = merge(this.options.labelOptions, {
  436. controlPointOptions: this.options.controlPointOptions
  437. }, labelOptions), label = new ControllableLabel(this, options, index);
  438. label.itemType = 'label';
  439. this.labels.push(label);
  440. return label;
  441. };
  442. /**
  443. * Redraw a single item.
  444. * @private
  445. * @param {Annotation.Label|Annotation.Shape} item
  446. * @param {boolean} [animation]
  447. */
  448. Annotation.prototype.redrawItem = function (item, animation) {
  449. item.linkPoints();
  450. if (!item.shouldBeDrawn()) {
  451. this.destroyItem(item);
  452. }
  453. else {
  454. if (!item.graphic) {
  455. this.renderItem(item);
  456. }
  457. item.redraw(pick(animation, true) && item.graphic.placed);
  458. if (item.points.length) {
  459. this.adjustVisibility(item);
  460. }
  461. }
  462. };
  463. /**
  464. * Hide or show annotaiton attached to points.
  465. * @private
  466. * @param {Annotation.Label|Annotation.Shape} item
  467. */
  468. Annotation.prototype.adjustVisibility = function (item) {
  469. var hasVisiblePoints = false, label = item.graphic;
  470. item.points.forEach(function (point) {
  471. if (point.series.visible !== false &&
  472. point.visible !== false) {
  473. hasVisiblePoints = true;
  474. }
  475. });
  476. if (!hasVisiblePoints) {
  477. label.hide();
  478. }
  479. else if (label.visibility === 'hidden') {
  480. label.show();
  481. }
  482. };
  483. /**
  484. * Destroy a single item.
  485. * @private
  486. * @param {Annotation.Label|Annotation.Shape} item
  487. */
  488. Annotation.prototype.destroyItem = function (item) {
  489. // erase from shapes or labels array
  490. erase(this[item.itemType + 's'], item);
  491. item.destroy();
  492. };
  493. /**
  494. * @private
  495. */
  496. Annotation.prototype.renderItem = function (item) {
  497. item.render(item.itemType === 'label' ?
  498. this.labelsGroup :
  499. this.shapesGroup);
  500. };
  501. /**
  502. * @private
  503. */
  504. Annotation.ControlPoint = ControlPoint;
  505. /**
  506. * @private
  507. */
  508. Annotation.MockPoint = MockPoint;
  509. /**
  510. * An object uses for mapping between a shape type and a constructor.
  511. * To add a new shape type extend this object with type name as a key
  512. * and a constructor as its value.
  513. */
  514. Annotation.shapesMap = {
  515. 'rect': ControllableRect,
  516. 'circle': ControllableCircle,
  517. 'path': ControllablePath,
  518. 'image': ControllableImage
  519. };
  520. /**
  521. * @private
  522. */
  523. Annotation.types = {};
  524. return Annotation;
  525. }());
  526. merge(true, Annotation.prototype, ControllableMixin, EventEmitterMixin,
  527. // restore original Annotation implementation after mixin overwrite
  528. merge(Annotation.prototype,
  529. /** @lends Highcharts.Annotation# */
  530. {
  531. /**
  532. * List of events for `annotation.options.events` that should not be
  533. * added to `annotation.graphic` but to the `annotation`.
  534. *
  535. * @private
  536. * @type {Array<string>}
  537. */
  538. nonDOMEvents: ['add', 'afterUpdate', 'drag', 'remove'],
  539. /**
  540. * A basic type of an annotation. It allows to add custom labels
  541. * or shapes. The items can be tied to points, axis coordinates
  542. * or chart pixel coordinates.
  543. *
  544. * @sample highcharts/annotations/basic/
  545. * Basic annotations
  546. * @sample highcharts/demo/annotations/
  547. * Advanced annotations
  548. * @sample highcharts/css/annotations
  549. * Styled mode
  550. * @sample highcharts/annotations-advanced/controllable
  551. * Controllable items
  552. * @sample {highstock} stock/annotations/fibonacci-retracements
  553. * Custom annotation, Fibonacci retracement
  554. *
  555. * @type {Array<*>}
  556. * @since 6.0.0
  557. * @requires modules/annotations
  558. * @optionparent annotations
  559. *
  560. * @private
  561. */
  562. defaultOptions: {
  563. /**
  564. * Sets an ID for an annotation. Can be user later when
  565. * removing an annotation in [Chart#removeAnnotation(id)](
  566. * /class-reference/Highcharts.Chart#removeAnnotation) method.
  567. *
  568. * @type {number|string}
  569. * @apioption annotations.id
  570. */
  571. /**
  572. * Whether the annotation is visible.
  573. *
  574. * @sample highcharts/annotations/visible/
  575. * Set annotation visibility
  576. */
  577. visible: true,
  578. /**
  579. * Enable or disable the initial animation when a series is
  580. * displayed for the `annotation`. The animation can also be set
  581. * as a configuration object. Please note that this option only
  582. * applies to the initial animation.
  583. * For other animations, see [chart.animation](#chart.animation)
  584. * and the animation parameter under the API methods.
  585. * The following properties are supported:
  586. *
  587. * - `defer`: The animation delay time in milliseconds.
  588. *
  589. * @sample {highcharts} highcharts/annotations/defer/
  590. * Animation defer settings
  591. * @type {boolean|Partial<Highcharts.AnimationOptionsObject>}
  592. * @since 8.2.0
  593. * @apioption annotations.animation
  594. */
  595. animation: {},
  596. /**
  597. * The animation delay time in milliseconds.
  598. * Set to `0` renders annotation immediately.
  599. * As `undefined` inherits defer time from the [series.animation.defer](#plotOptions.series.animation.defer).
  600. *
  601. * @type {number}
  602. * @since 8.2.0
  603. * @apioption annotations.animation.defer
  604. */
  605. /**
  606. * Allow an annotation to be draggable by a user. Possible
  607. * values are `'x'`, `'xy'`, `'y'` and `''` (disabled).
  608. *
  609. * @sample highcharts/annotations/draggable/
  610. * Annotations draggable: 'xy'
  611. *
  612. * @type {Highcharts.AnnotationDraggableValue}
  613. */
  614. draggable: 'xy',
  615. /**
  616. * Options for annotation's labels. Each label inherits options
  617. * from the labelOptions object. An option from the labelOptions
  618. * can be overwritten by config for a specific label.
  619. *
  620. * @requires modules/annotations
  621. */
  622. labelOptions: {
  623. /**
  624. * The alignment of the annotation's label. If right,
  625. * the right side of the label should be touching the point.
  626. *
  627. * @sample highcharts/annotations/label-position/
  628. * Set labels position
  629. *
  630. * @type {Highcharts.AlignValue}
  631. */
  632. align: 'center',
  633. /**
  634. * Whether to allow the annotation's labels to overlap.
  635. * To make the labels less sensitive for overlapping,
  636. * the can be set to 0.
  637. *
  638. * @sample highcharts/annotations/tooltip-like/
  639. * Hide overlapping labels
  640. */
  641. allowOverlap: false,
  642. /**
  643. * The background color or gradient for the annotation's
  644. * label.
  645. *
  646. * @sample highcharts/annotations/label-presentation/
  647. * Set labels graphic options
  648. *
  649. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  650. */
  651. backgroundColor: 'rgba(0, 0, 0, 0.75)',
  652. /**
  653. * The border color for the annotation's label.
  654. *
  655. * @sample highcharts/annotations/label-presentation/
  656. * Set labels graphic options
  657. *
  658. * @type {Highcharts.ColorString}
  659. */
  660. borderColor: 'black',
  661. /**
  662. * The border radius in pixels for the annotaiton's label.
  663. *
  664. * @sample highcharts/annotations/label-presentation/
  665. * Set labels graphic options
  666. */
  667. borderRadius: 3,
  668. /**
  669. * The border width in pixels for the annotation's label
  670. *
  671. * @sample highcharts/annotations/label-presentation/
  672. * Set labels graphic options
  673. */
  674. borderWidth: 1,
  675. /**
  676. * A class name for styling by CSS.
  677. *
  678. * @sample highcharts/css/annotations
  679. * Styled mode annotations
  680. *
  681. * @since 6.0.5
  682. */
  683. className: '',
  684. /**
  685. * Whether to hide the annotation's label
  686. * that is outside the plot area.
  687. *
  688. * @sample highcharts/annotations/label-crop-overflow/
  689. * Crop or justify labels
  690. */
  691. crop: false,
  692. /**
  693. * The label's pixel distance from the point.
  694. *
  695. * @sample highcharts/annotations/label-position/
  696. * Set labels position
  697. *
  698. * @type {number}
  699. * @apioption annotations.labelOptions.distance
  700. */
  701. /**
  702. * A
  703. * [format](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  704. * string for the data label.
  705. *
  706. * @see [plotOptions.series.dataLabels.format](plotOptions.series.dataLabels.format.html)
  707. *
  708. * @sample highcharts/annotations/label-text/
  709. * Set labels text
  710. *
  711. * @type {string}
  712. * @apioption annotations.labelOptions.format
  713. */
  714. /**
  715. * Alias for the format option.
  716. *
  717. * @see [format](annotations.labelOptions.format.html)
  718. *
  719. * @sample highcharts/annotations/label-text/
  720. * Set labels text
  721. *
  722. * @type {string}
  723. * @apioption annotations.labelOptions.text
  724. */
  725. /**
  726. * Callback JavaScript function to format the annotation's
  727. * label. Note that if a `format` or `text` are defined,
  728. * the format or text take precedence and the formatter is
  729. * ignored. `This` refers to a point object.
  730. *
  731. * @sample highcharts/annotations/label-text/
  732. * Set labels text
  733. *
  734. * @type {Highcharts.FormatterCallbackFunction<Highcharts.Point>}
  735. * @default function () { return defined(this.y) ? this.y : 'Annotation label'; }
  736. */
  737. formatter: function () {
  738. return defined(this.y) ? this.y : 'Annotation label';
  739. },
  740. /**
  741. * Whether the annotation is visible in the exported data
  742. * table.
  743. *
  744. * @sample highcharts/annotations/include-in-data-export/
  745. * Do not include in the data export
  746. *
  747. * @since 8.2.0
  748. * @requires modules/export-data
  749. */
  750. includeInDataExport: true,
  751. /**
  752. * How to handle the annotation's label that flow outside
  753. * the plot area. The justify option aligns the label inside
  754. * the plot area.
  755. *
  756. * @sample highcharts/annotations/label-crop-overflow/
  757. * Crop or justify labels
  758. *
  759. * @validvalue ["allow", "justify"]
  760. */
  761. overflow: 'justify',
  762. /**
  763. * When either the borderWidth or the backgroundColor is
  764. * set, this is the padding within the box.
  765. *
  766. * @sample highcharts/annotations/label-presentation/
  767. * Set labels graphic options
  768. */
  769. padding: 5,
  770. /**
  771. * The shadow of the box. The shadow can be an object
  772. * configuration containing `color`, `offsetX`, `offsetY`,
  773. * `opacity` and `width`.
  774. *
  775. * @sample highcharts/annotations/label-presentation/
  776. * Set labels graphic options
  777. *
  778. * @type {boolean|Highcharts.ShadowOptionsObject}
  779. */
  780. shadow: false,
  781. /**
  782. * The name of a symbol to use for the border around the
  783. * label. Symbols are predefined functions on the Renderer
  784. * object.
  785. *
  786. * @sample highcharts/annotations/shapes/
  787. * Available shapes for labels
  788. */
  789. shape: 'callout',
  790. /**
  791. * Styles for the annotation's label.
  792. *
  793. * @see [plotOptions.series.dataLabels.style](plotOptions.series.dataLabels.style.html)
  794. *
  795. * @sample highcharts/annotations/label-presentation/
  796. * Set labels graphic options
  797. *
  798. * @type {Highcharts.CSSObject}
  799. */
  800. style: {
  801. /** @ignore */
  802. fontSize: '11px',
  803. /** @ignore */
  804. fontWeight: 'normal',
  805. /** @ignore */
  806. color: 'contrast'
  807. },
  808. /**
  809. * Whether to [use HTML](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting#html)
  810. * to render the annotation's label.
  811. */
  812. useHTML: false,
  813. /**
  814. * The vertical alignment of the annotation's label.
  815. *
  816. * @sample highcharts/annotations/label-position/
  817. * Set labels position
  818. *
  819. * @type {Highcharts.VerticalAlignValue}
  820. */
  821. verticalAlign: 'bottom',
  822. /**
  823. * The x position offset of the label relative to the point.
  824. * Note that if a `distance` is defined, the distance takes
  825. * precedence over `x` and `y` options.
  826. *
  827. * @sample highcharts/annotations/label-position/
  828. * Set labels position
  829. */
  830. x: 0,
  831. /**
  832. * The y position offset of the label relative to the point.
  833. * Note that if a `distance` is defined, the distance takes
  834. * precedence over `x` and `y` options.
  835. *
  836. * @sample highcharts/annotations/label-position/
  837. * Set labels position
  838. */
  839. y: -16
  840. },
  841. /**
  842. * An array of labels for the annotation. For options that apply
  843. * to multiple labels, they can be added to the
  844. * [labelOptions](annotations.labelOptions.html).
  845. *
  846. * @type {Array<*>}
  847. * @extends annotations.labelOptions
  848. * @apioption annotations.labels
  849. */
  850. /**
  851. * This option defines the point to which the label will be
  852. * connected. It can be either the point which exists in the
  853. * series - it is referenced by the point's id - or a new point
  854. * with defined x, y properties and optionally axes.
  855. *
  856. * @sample highcharts/annotations/mock-point/
  857. * Attach annotation to a mock point
  858. *
  859. * @declare Highcharts.AnnotationMockPointOptionsObject
  860. * @type {string|*}
  861. * @requires modules/annotations
  862. * @apioption annotations.labels.point
  863. */
  864. /**
  865. * The x position of the point. Units can be either in axis
  866. * or chart pixel coordinates.
  867. *
  868. * @type {number}
  869. * @apioption annotations.labels.point.x
  870. */
  871. /**
  872. * The y position of the point. Units can be either in axis
  873. * or chart pixel coordinates.
  874. *
  875. * @type {number}
  876. * @apioption annotations.labels.point.y
  877. */
  878. /**
  879. * This number defines which xAxis the point is connected to.
  880. * It refers to either the axis id or the index of the axis in
  881. * the xAxis array. If the option is not configured or the axis
  882. * is not found the point's x coordinate refers to the chart
  883. * pixels.
  884. *
  885. * @type {number|string|null}
  886. * @apioption annotations.labels.point.xAxis
  887. */
  888. /**
  889. * This number defines which yAxis the point is connected to.
  890. * It refers to either the axis id or the index of the axis in
  891. * the yAxis array. If the option is not configured or the axis
  892. * is not found the point's y coordinate refers to the chart
  893. * pixels.
  894. *
  895. * @type {number|string|null}
  896. * @apioption annotations.labels.point.yAxis
  897. */
  898. /**
  899. * An array of shapes for the annotation. For options that apply
  900. * to multiple shapes, then can be added to the
  901. * [shapeOptions](annotations.shapeOptions.html).
  902. *
  903. * @type {Array<*>}
  904. * @extends annotations.shapeOptions
  905. * @apioption annotations.shapes
  906. */
  907. /**
  908. * This option defines the point to which the shape will be
  909. * connected. It can be either the point which exists in the
  910. * series - it is referenced by the point's id - or a new point
  911. * with defined x, y properties and optionally axes.
  912. *
  913. * @declare Highcharts.AnnotationMockPointOptionsObject
  914. * @type {string|Highcharts.AnnotationMockPointOptionsObject}
  915. * @extends annotations.labels.point
  916. * @apioption annotations.shapes.point
  917. */
  918. /**
  919. * An array of points for the shape. This option is available
  920. * for shapes which can use multiple points such as path. A
  921. * point can be either a point object or a point's id.
  922. *
  923. * @see [annotations.shapes.point](annotations.shapes.point.html)
  924. *
  925. * @declare Highcharts.AnnotationMockPointOptionsObject
  926. * @type {Array<string|*>}
  927. * @extends annotations.labels.point
  928. * @apioption annotations.shapes.points
  929. */
  930. /**
  931. * The URL for an image to use as the annotation shape. Note,
  932. * type has to be set to `'image'`.
  933. *
  934. * @see [annotations.shapes.type](annotations.shapes.type)
  935. * @sample highcharts/annotations/shape-src/
  936. * Define a marker image url for annotations
  937. *
  938. * @type {string}
  939. * @apioption annotations.shapes.src
  940. */
  941. /**
  942. * Id of the marker which will be drawn at the final vertex of
  943. * the path. Custom markers can be defined in defs property.
  944. *
  945. * @see [defs.markers](defs.markers.html)
  946. *
  947. * @sample highcharts/annotations/custom-markers/
  948. * Define a custom marker for annotations
  949. *
  950. * @type {string}
  951. * @apioption annotations.shapes.markerEnd
  952. */
  953. /**
  954. * Id of the marker which will be drawn at the first vertex of
  955. * the path. Custom markers can be defined in defs property.
  956. *
  957. * @see [defs.markers](defs.markers.html)
  958. *
  959. * @sample {highcharts} highcharts/annotations/custom-markers/
  960. * Define a custom marker for annotations
  961. *
  962. * @type {string}
  963. * @apioption annotations.shapes.markerStart
  964. */
  965. /**
  966. * Options for annotation's shapes. Each shape inherits options
  967. * from the shapeOptions object. An option from the shapeOptions
  968. * can be overwritten by config for a specific shape.
  969. *
  970. * @requires modules/annotations
  971. */
  972. shapeOptions: {
  973. /**
  974. * The width of the shape.
  975. *
  976. * @sample highcharts/annotations/shape/
  977. * Basic shape annotation
  978. *
  979. * @type {number}
  980. * @apioption annotations.shapeOptions.width
  981. **/
  982. /**
  983. * The height of the shape.
  984. *
  985. * @sample highcharts/annotations/shape/
  986. * Basic shape annotation
  987. *
  988. * @type {number}
  989. * @apioption annotations.shapeOptions.height
  990. */
  991. /**
  992. * The type of the shape, e.g. circle or rectangle.
  993. *
  994. * @sample highcharts/annotations/shape/
  995. * Basic shape annotation
  996. *
  997. * @type {string}
  998. * @default 'rect'
  999. * @apioption annotations.shapeOptions.type
  1000. */
  1001. /**
  1002. * The URL for an image to use as the annotation shape.
  1003. * Note, type has to be set to `'image'`.
  1004. *
  1005. * @see [annotations.shapeOptions.type](annotations.shapeOptions.type)
  1006. * @sample highcharts/annotations/shape-src/
  1007. * Define a marker image url for annotations
  1008. *
  1009. * @type {string}
  1010. * @apioption annotations.shapeOptions.src
  1011. */
  1012. /**
  1013. * Name of the dash style to use for the shape's stroke.
  1014. *
  1015. * @sample {highcharts} highcharts/plotoptions/series-dashstyle-all/
  1016. * Possible values demonstrated
  1017. *
  1018. * @type {Highcharts.DashStyleValue}
  1019. * @apioption annotations.shapeOptions.dashStyle
  1020. */
  1021. /**
  1022. * The color of the shape's stroke.
  1023. *
  1024. * @sample highcharts/annotations/shape/
  1025. * Basic shape annotation
  1026. *
  1027. * @type {Highcharts.ColorString}
  1028. */
  1029. stroke: 'rgba(0, 0, 0, 0.75)',
  1030. /**
  1031. * The pixel stroke width of the shape.
  1032. *
  1033. * @sample highcharts/annotations/shape/
  1034. * Basic shape annotation
  1035. */
  1036. strokeWidth: 1,
  1037. /**
  1038. * The color of the shape's fill.
  1039. *
  1040. * @sample highcharts/annotations/shape/
  1041. * Basic shape annotation
  1042. *
  1043. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1044. */
  1045. fill: 'rgba(0, 0, 0, 0.75)',
  1046. /**
  1047. * The radius of the shape.
  1048. *
  1049. * @sample highcharts/annotations/shape/
  1050. * Basic shape annotation
  1051. */
  1052. r: 0,
  1053. /**
  1054. * Defines additional snapping area around an annotation
  1055. * making this annotation to focus. Defined in pixels.
  1056. */
  1057. snap: 2
  1058. },
  1059. /**
  1060. * Options for annotation's control points. Each control point
  1061. * inherits options from controlPointOptions object.
  1062. * Options from the controlPointOptions can be overwritten
  1063. * by options in a specific control point.
  1064. *
  1065. * @declare Highcharts.AnnotationControlPointOptionsObject
  1066. * @requires modules/annotations
  1067. * @apioption annotations.controlPointOptions
  1068. */
  1069. controlPointOptions: {
  1070. /**
  1071. * @type {Highcharts.AnnotationControlPointPositionerFunction}
  1072. * @apioption annotations.controlPointOptions.positioner
  1073. */
  1074. symbol: 'circle',
  1075. width: 10,
  1076. height: 10,
  1077. style: {
  1078. stroke: 'black',
  1079. 'stroke-width': 2,
  1080. fill: 'white'
  1081. },
  1082. visible: false,
  1083. events: {}
  1084. },
  1085. /**
  1086. * Event callback when annotation is added to the chart.
  1087. *
  1088. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  1089. * @since 7.1.0
  1090. * @apioption annotations.events.add
  1091. */
  1092. /**
  1093. * Event callback when annotation is updated (e.g. drag and
  1094. * droppped or resized by control points).
  1095. *
  1096. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  1097. * @since 7.1.0
  1098. * @apioption annotations.events.afterUpdate
  1099. */
  1100. /**
  1101. * Event callback when annotation is removed from the chart.
  1102. *
  1103. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  1104. * @since 7.1.0
  1105. * @apioption annotations.events.remove
  1106. */
  1107. /**
  1108. * Events available in annotations.
  1109. *
  1110. * @requires modules/annotations
  1111. */
  1112. events: {},
  1113. /**
  1114. * The Z index of the annotation.
  1115. */
  1116. zIndex: 6
  1117. }
  1118. }));
  1119. H.extendAnnotation = function (Constructor, BaseConstructor, prototype, defaultOptions) {
  1120. BaseConstructor = BaseConstructor || Annotation;
  1121. merge(true, Constructor.prototype, BaseConstructor.prototype, prototype);
  1122. Constructor.prototype.defaultOptions = merge(Constructor.prototype.defaultOptions, defaultOptions || {});
  1123. };
  1124. /* *********************************************************************
  1125. *
  1126. * EXTENDING CHART PROTOTYPE
  1127. *
  1128. ******************************************************************** */
  1129. extend(chartProto, /** @lends Highcharts.Chart# */ {
  1130. initAnnotation: function (userOptions) {
  1131. var Constructor = Annotation.types[userOptions.type] || Annotation, annotation = new Constructor(this, userOptions);
  1132. this.annotations.push(annotation);
  1133. return annotation;
  1134. },
  1135. /**
  1136. * Add an annotation to the chart after render time.
  1137. *
  1138. * @param {Highcharts.AnnotationsOptions} options
  1139. * The annotation options for the new, detailed annotation.
  1140. * @param {boolean} [redraw]
  1141. *
  1142. * @return {Highcharts.Annotation} - The newly generated annotation.
  1143. */
  1144. addAnnotation: function (userOptions, redraw) {
  1145. var annotation = this.initAnnotation(userOptions);
  1146. this.options.annotations.push(annotation.options);
  1147. if (pick(redraw, true)) {
  1148. annotation.redraw();
  1149. annotation.graphic.attr({
  1150. opacity: 1
  1151. });
  1152. }
  1153. return annotation;
  1154. },
  1155. /**
  1156. * Remove an annotation from the chart.
  1157. *
  1158. * @param {number|string|Highcharts.Annotation} idOrAnnotation
  1159. * The annotation's id or direct annotation object.
  1160. */
  1161. removeAnnotation: function (idOrAnnotation) {
  1162. var annotations = this.annotations, annotation = idOrAnnotation.coll === 'annotations' ?
  1163. idOrAnnotation :
  1164. find(annotations, function (annotation) {
  1165. return annotation.options.id === idOrAnnotation;
  1166. });
  1167. if (annotation) {
  1168. fireEvent(annotation, 'remove');
  1169. erase(this.options.annotations, annotation.options);
  1170. erase(annotations, annotation);
  1171. annotation.destroy();
  1172. }
  1173. },
  1174. drawAnnotations: function () {
  1175. this.plotBoxClip.attr(this.plotBox);
  1176. this.annotations.forEach(function (annotation) {
  1177. annotation.redraw();
  1178. annotation.graphic.animate({
  1179. opacity: 1
  1180. }, annotation.animationConfig);
  1181. });
  1182. }
  1183. });
  1184. // Let chart.update() update annotations
  1185. chartProto.collectionsWithUpdate.push('annotations');
  1186. // Let chart.update() create annoations on demand
  1187. chartProto.collectionsWithInit.annotations = [chartProto.addAnnotation];
  1188. chartProto.callbacks.push(function (chart) {
  1189. chart.annotations = [];
  1190. if (!chart.options.annotations) {
  1191. chart.options.annotations = [];
  1192. }
  1193. chart.plotBoxClip = this.renderer.clipRect(this.plotBox);
  1194. chart.controlPointsGroup = chart.renderer
  1195. .g('control-points')
  1196. .attr({ zIndex: 99 })
  1197. .clip(chart.plotBoxClip)
  1198. .add();
  1199. chart.options.annotations.forEach(function (annotationOptions, i) {
  1200. var annotation = chart.initAnnotation(annotationOptions);
  1201. chart.options.annotations[i] = annotation.options;
  1202. });
  1203. chart.drawAnnotations();
  1204. addEvent(chart, 'redraw', chart.drawAnnotations);
  1205. addEvent(chart, 'destroy', function () {
  1206. chart.plotBoxClip.destroy();
  1207. chart.controlPointsGroup.destroy();
  1208. });
  1209. addEvent(chart, 'exportData', function (event) {
  1210. var _a, _b, _c, _d, _e, _f, _g, _h;
  1211. var annotations = chart.annotations, csvColumnHeaderFormatter = ((this.options.exporting &&
  1212. this.options.exporting.csv) ||
  1213. {}).columnHeaderFormatter,
  1214. // If second row doesn't have xValues
  1215. // then it is a title row thus multiple level header is in use.
  1216. multiLevelHeaders = !event.dataRows[1].xValues, annotationHeader = (_b = (_a = chart.options.lang) === null || _a === void 0 ? void 0 : _a.exportData) === null || _b === void 0 ? void 0 : _b.annotationHeader, columnHeaderFormatter = function (index) {
  1217. var s;
  1218. if (csvColumnHeaderFormatter) {
  1219. s = csvColumnHeaderFormatter(index);
  1220. if (s !== false) {
  1221. return s;
  1222. }
  1223. }
  1224. s = annotationHeader + ' ' + index;
  1225. if (multiLevelHeaders) {
  1226. return {
  1227. columnTitle: s,
  1228. topLevelColumnTitle: s
  1229. };
  1230. }
  1231. return s;
  1232. }, startRowLength = event.dataRows[0].length, annotationSeparator = (_e = (_d = (_c = chart.options.exporting) === null || _c === void 0 ? void 0 : _c.csv) === null || _d === void 0 ? void 0 : _d.annotations) === null || _e === void 0 ? void 0 : _e.itemDelimiter, joinAnnotations = (_h = (_g = (_f = chart.options.exporting) === null || _f === void 0 ? void 0 : _f.csv) === null || _g === void 0 ? void 0 : _g.annotations) === null || _h === void 0 ? void 0 : _h.join;
  1233. annotations.forEach(function (annotation) {
  1234. if (annotation.options.labelOptions.includeInDataExport) {
  1235. annotation.labels.forEach(function (label) {
  1236. if (label.options.text) {
  1237. var annotationText_1 = label.options.text;
  1238. label.points.forEach(function (points) {
  1239. var annotationX = points.x, xAxisIndex = points.series.xAxis ?
  1240. points.series.xAxis.options.index :
  1241. -1;
  1242. var wasAdded = false;
  1243. // Annotation not connected to any xAxis -
  1244. // add new row.
  1245. if (xAxisIndex === -1) {
  1246. var n = event.dataRows[0].length, newRow = new Array(n);
  1247. for (var i = 0; i < n; ++i) {
  1248. newRow[i] = '';
  1249. }
  1250. newRow.push(annotationText_1);
  1251. newRow.xValues = [];
  1252. newRow.xValues[xAxisIndex] = annotationX;
  1253. event.dataRows.push(newRow);
  1254. wasAdded = true;
  1255. }
  1256. // Annotation placed on a exported data point
  1257. // - add new column
  1258. if (!wasAdded) {
  1259. event.dataRows.forEach(function (row, rowIndex) {
  1260. if (!wasAdded &&
  1261. row.xValues &&
  1262. xAxisIndex !== void 0 &&
  1263. annotationX === row.xValues[xAxisIndex]) {
  1264. if (joinAnnotations &&
  1265. row.length > startRowLength) {
  1266. row[row.length - 1] +=
  1267. annotationSeparator + annotationText_1;
  1268. }
  1269. else {
  1270. row.push(annotationText_1);
  1271. }
  1272. wasAdded = true;
  1273. }
  1274. });
  1275. }
  1276. // Annotation not placed on any exported data point,
  1277. // but connected to the xAxis - add new row
  1278. if (!wasAdded) {
  1279. var n = event.dataRows[0].length, newRow = new Array(n);
  1280. for (var i = 0; i < n; ++i) {
  1281. newRow[i] = '';
  1282. }
  1283. newRow[0] = annotationX;
  1284. newRow.push(annotationText_1);
  1285. newRow.xValues = [];
  1286. if (xAxisIndex !== void 0) {
  1287. newRow.xValues[xAxisIndex] = annotationX;
  1288. }
  1289. event.dataRows.push(newRow);
  1290. }
  1291. });
  1292. }
  1293. });
  1294. }
  1295. });
  1296. var maxRowLen = 0;
  1297. event.dataRows.forEach(function (row) {
  1298. maxRowLen = Math.max(maxRowLen, row.length);
  1299. });
  1300. var newRows = maxRowLen - event.dataRows[0].length;
  1301. for (var i = 0; i < newRows; i++) {
  1302. var header = columnHeaderFormatter(i + 1);
  1303. if (multiLevelHeaders) {
  1304. event.dataRows[0].push(header.topLevelColumnTitle);
  1305. event.dataRows[1].push(header.columnTitle);
  1306. }
  1307. else {
  1308. event.dataRows[0].push(header);
  1309. }
  1310. }
  1311. });
  1312. });
  1313. wrap(Pointer.prototype, 'onContainerMouseDown', function (proceed) {
  1314. if (!this.chart.hasDraggedAnnotation) {
  1315. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  1316. }
  1317. });
  1318. H.Annotation = Annotation;
  1319. export default Annotation;