Annotations.js 49 KB

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