Annotations.js 49 KB

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