DataLabels.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. /* *
  2. *
  3. * (c) 2010-2020 Torstein Honsi
  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 H from '../Globals.js';
  12. var noop = H.noop, seriesTypes = H.seriesTypes;
  13. import U from '../Utilities.js';
  14. var arrayMax = U.arrayMax, clamp = U.clamp, defined = U.defined, extend = U.extend, fireEvent = U.fireEvent, format = U.format, getDeferredAnimation = U.getDeferredAnimation, isArray = U.isArray, merge = U.merge, objectEach = U.objectEach, pick = U.pick, relativeLength = U.relativeLength, splat = U.splat, stableSort = U.stableSort;
  15. /**
  16. * Callback JavaScript function to format the data label as a string. Note that
  17. * if a `format` is defined, the format takes precedence and the formatter is
  18. * ignored.
  19. *
  20. * @callback Highcharts.DataLabelsFormatterCallbackFunction
  21. *
  22. * @param {Highcharts.PointLabelObject} this
  23. * Data label context to format
  24. *
  25. * @param {Highcharts.DataLabelsOptions} options
  26. * [API options](/highcharts/plotOptions.series.dataLabels) of the data label
  27. *
  28. * @return {number|string|null|undefined}
  29. * Formatted data label text
  30. */
  31. /**
  32. * Values for handling data labels that flow outside the plot area.
  33. *
  34. * @typedef {"allow"|"justify"} Highcharts.DataLabelsOverflowValue
  35. */
  36. import './Series.js';
  37. var Series = H.Series;
  38. /* eslint-disable valid-jsdoc */
  39. /**
  40. * General distribution algorithm for distributing labels of differing size
  41. * along a confined length in two dimensions. The algorithm takes an array of
  42. * objects containing a size, a target and a rank. It will place the labels as
  43. * close as possible to their targets, skipping the lowest ranked labels if
  44. * necessary.
  45. *
  46. * @private
  47. * @function Highcharts.distribute
  48. * @param {Highcharts.DataLabelsBoxArray} boxes
  49. * @param {number} len
  50. * @param {number} [maxDistance]
  51. * @return {void}
  52. */
  53. H.distribute = function (boxes, len, maxDistance) {
  54. var i, overlapping = true, origBoxes = boxes, // Original array will be altered with added .pos
  55. restBoxes = [], // The outranked overshoot
  56. box, target, total = 0, reducedLen = origBoxes.reducedLen || len;
  57. /**
  58. * @private
  59. */
  60. function sortByTarget(a, b) {
  61. return a.target - b.target;
  62. }
  63. // If the total size exceeds the len, remove those boxes with the lowest
  64. // rank
  65. i = boxes.length;
  66. while (i--) {
  67. total += boxes[i].size;
  68. }
  69. // Sort by rank, then slice away overshoot
  70. if (total > reducedLen) {
  71. stableSort(boxes, function (a, b) {
  72. return (b.rank || 0) - (a.rank || 0);
  73. });
  74. i = 0;
  75. total = 0;
  76. while (total <= reducedLen) {
  77. total += boxes[i].size;
  78. i++;
  79. }
  80. restBoxes = boxes.splice(i - 1, boxes.length);
  81. }
  82. // Order by target
  83. stableSort(boxes, sortByTarget);
  84. // So far we have been mutating the original array. Now
  85. // create a copy with target arrays
  86. boxes = boxes.map(function (box) {
  87. return {
  88. size: box.size,
  89. targets: [box.target],
  90. align: pick(box.align, 0.5)
  91. };
  92. });
  93. while (overlapping) {
  94. // Initial positions: target centered in box
  95. i = boxes.length;
  96. while (i--) {
  97. box = boxes[i];
  98. // Composite box, average of targets
  99. target = (Math.min.apply(0, box.targets) +
  100. Math.max.apply(0, box.targets)) / 2;
  101. box.pos = clamp(target - box.size * box.align, 0, len - box.size);
  102. }
  103. // Detect overlap and join boxes
  104. i = boxes.length;
  105. overlapping = false;
  106. while (i--) {
  107. // Overlap
  108. if (i > 0 &&
  109. boxes[i - 1].pos + boxes[i - 1].size >
  110. boxes[i].pos) {
  111. // Add this size to the previous box
  112. boxes[i - 1].size += boxes[i].size;
  113. boxes[i - 1].targets = boxes[i - 1]
  114. .targets
  115. .concat(boxes[i].targets);
  116. boxes[i - 1].align = 0.5;
  117. // Overlapping right, push left
  118. if (boxes[i - 1].pos + boxes[i - 1].size > len) {
  119. boxes[i - 1].pos = len - boxes[i - 1].size;
  120. }
  121. boxes.splice(i, 1); // Remove this item
  122. overlapping = true;
  123. }
  124. }
  125. }
  126. // Add the rest (hidden boxes)
  127. origBoxes.push.apply(origBoxes, restBoxes);
  128. // Now the composite boxes are placed, we need to put the original boxes
  129. // within them
  130. i = 0;
  131. boxes.some(function (box) {
  132. var posInCompositeBox = 0;
  133. if (box.targets.some(function () {
  134. origBoxes[i].pos = box.pos + posInCompositeBox;
  135. // If the distance between the position and the target exceeds
  136. // maxDistance, abort the loop and decrease the length in increments
  137. // of 10% to recursively reduce the number of visible boxes by
  138. // rank. Once all boxes are within the maxDistance, we're good.
  139. if (typeof maxDistance !== 'undefined' &&
  140. Math.abs(origBoxes[i].pos - origBoxes[i].target) > maxDistance) {
  141. // Reset the positions that are already set
  142. origBoxes.slice(0, i + 1).forEach(function (box) {
  143. delete box.pos;
  144. });
  145. // Try with a smaller length
  146. origBoxes.reducedLen =
  147. (origBoxes.reducedLen || len) - (len * 0.1);
  148. // Recurse
  149. if (origBoxes.reducedLen > len * 0.1) {
  150. H.distribute(origBoxes, len, maxDistance);
  151. }
  152. // Exceeded maxDistance => abort
  153. return true;
  154. }
  155. posInCompositeBox += origBoxes[i].size;
  156. i++;
  157. })) {
  158. // Exceeded maxDistance => abort
  159. return true;
  160. }
  161. });
  162. // Add the rest (hidden) boxes and sort by target
  163. stableSort(origBoxes, sortByTarget);
  164. };
  165. /**
  166. * Draw the data labels
  167. *
  168. * @private
  169. * @function Highcharts.Series#drawDataLabels
  170. * @return {void}
  171. * @fires Highcharts.Series#event:afterDrawDataLabels
  172. */
  173. Series.prototype.drawDataLabels = function () {
  174. var series = this, chart = series.chart, seriesOptions = series.options, seriesDlOptions = seriesOptions.dataLabels, points = series.points, pointOptions, hasRendered = series.hasRendered || 0, dataLabelsGroup, dataLabelAnim = seriesDlOptions.animation, animationConfig = seriesDlOptions.defer ?
  175. getDeferredAnimation(chart, dataLabelAnim, series) :
  176. { defer: 0, duration: 0 }, renderer = chart.renderer;
  177. /**
  178. * Handle the dataLabels.filter option.
  179. * @private
  180. */
  181. function applyFilter(point, options) {
  182. var filter = options.filter, op, prop, val;
  183. if (filter) {
  184. op = filter.operator;
  185. prop = point[filter.property];
  186. val = filter.value;
  187. if ((op === '>' && prop > val) ||
  188. (op === '<' && prop < val) ||
  189. (op === '>=' && prop >= val) ||
  190. (op === '<=' && prop <= val) ||
  191. (op === '==' && prop == val) || // eslint-disable-line eqeqeq
  192. (op === '===' && prop === val)) {
  193. return true;
  194. }
  195. return false;
  196. }
  197. return true;
  198. }
  199. /**
  200. * Merge two objects that can be arrays. If one of them is an array, the
  201. * other is merged into each element. If both are arrays, each element is
  202. * merged by index. If neither are arrays, we use normal merge.
  203. * @private
  204. */
  205. function mergeArrays(one, two) {
  206. var res = [], i;
  207. if (isArray(one) && !isArray(two)) {
  208. res = one.map(function (el) {
  209. return merge(el, two);
  210. });
  211. }
  212. else if (isArray(two) && !isArray(one)) {
  213. res = two.map(function (el) {
  214. return merge(one, el);
  215. });
  216. }
  217. else if (!isArray(one) && !isArray(two)) {
  218. res = merge(one, two);
  219. }
  220. else {
  221. i = Math.max(one.length, two.length);
  222. while (i--) {
  223. res[i] = merge(one[i], two[i]);
  224. }
  225. }
  226. return res;
  227. }
  228. // Merge in plotOptions.dataLabels for series
  229. seriesDlOptions = mergeArrays(mergeArrays(chart.options.plotOptions &&
  230. chart.options.plotOptions.series &&
  231. chart.options.plotOptions.series.dataLabels, chart.options.plotOptions &&
  232. chart.options.plotOptions[series.type] &&
  233. chart.options.plotOptions[series.type].dataLabels), seriesDlOptions);
  234. fireEvent(this, 'drawDataLabels');
  235. if (isArray(seriesDlOptions) ||
  236. seriesDlOptions.enabled ||
  237. series._hasPointLabels) {
  238. // Create a separate group for the data labels to avoid rotation
  239. dataLabelsGroup = series.plotGroup('dataLabelsGroup', 'data-labels', !hasRendered ? 'hidden' : 'inherit', // #5133, #10220
  240. seriesDlOptions.zIndex || 6);
  241. dataLabelsGroup.attr({ opacity: +hasRendered }); // #3300
  242. if (!hasRendered) {
  243. var group = series.dataLabelsGroup;
  244. if (group) {
  245. if (series.visible) { // #2597, #3023, #3024
  246. dataLabelsGroup.show(true);
  247. }
  248. group[seriesOptions.animation ? 'animate' : 'attr']({ opacity: 1 }, animationConfig);
  249. }
  250. }
  251. // Make the labels for each point
  252. points.forEach(function (point) {
  253. // Merge in series options for the point.
  254. // @note dataLabelAttribs (like pointAttribs) would eradicate
  255. // the need for dlOptions, and simplify the section below.
  256. pointOptions = splat(mergeArrays(seriesDlOptions, point.dlOptions || // dlOptions is used in treemaps
  257. (point.options && point.options.dataLabels)));
  258. // Handle each individual data label for this point
  259. pointOptions.forEach(function (labelOptions, i) {
  260. // Options for one datalabel
  261. var labelEnabled = (labelOptions.enabled &&
  262. // #2282, #4641, #7112, #10049
  263. (!point.isNull || point.dataLabelOnNull) &&
  264. applyFilter(point, labelOptions)), labelConfig, formatString, labelText, style, rotation, attr, dataLabel = point.dataLabels ? point.dataLabels[i] :
  265. point.dataLabel, connector = point.connectors ? point.connectors[i] :
  266. point.connector, labelDistance = pick(labelOptions.distance, point.labelDistance), isNew = !dataLabel;
  267. if (labelEnabled) {
  268. // Create individual options structure that can be extended
  269. // without affecting others
  270. labelConfig = point.getLabelConfig();
  271. formatString = pick(labelOptions[point.formatPrefix + 'Format'], labelOptions.format);
  272. labelText = defined(formatString) ?
  273. format(formatString, labelConfig, chart) :
  274. (labelOptions[point.formatPrefix + 'Formatter'] ||
  275. labelOptions.formatter).call(labelConfig, labelOptions);
  276. style = labelOptions.style;
  277. rotation = labelOptions.rotation;
  278. if (!chart.styledMode) {
  279. // Determine the color
  280. style.color = pick(labelOptions.color, style.color, series.color, '#000000');
  281. // Get automated contrast color
  282. if (style.color === 'contrast') {
  283. point.contrastColor = renderer.getContrast((point.color || series.color));
  284. style.color = (!defined(labelDistance) &&
  285. labelOptions.inside) ||
  286. labelDistance < 0 ||
  287. !!seriesOptions.stacking ?
  288. point.contrastColor :
  289. '#000000';
  290. }
  291. else {
  292. delete point.contrastColor;
  293. }
  294. if (seriesOptions.cursor) {
  295. style.cursor = seriesOptions.cursor;
  296. }
  297. }
  298. attr = {
  299. r: labelOptions.borderRadius || 0,
  300. rotation: rotation,
  301. padding: labelOptions.padding,
  302. zIndex: 1
  303. };
  304. if (!chart.styledMode) {
  305. attr.fill = labelOptions.backgroundColor;
  306. attr.stroke = labelOptions.borderColor;
  307. attr['stroke-width'] = labelOptions.borderWidth;
  308. }
  309. // Remove unused attributes (#947)
  310. objectEach(attr, function (val, name) {
  311. if (typeof val === 'undefined') {
  312. delete attr[name];
  313. }
  314. });
  315. }
  316. // If the point is outside the plot area, destroy it. #678, #820
  317. if (dataLabel && (!labelEnabled || !defined(labelText))) {
  318. point.dataLabel =
  319. point.dataLabel && point.dataLabel.destroy();
  320. if (point.dataLabels) {
  321. // Remove point.dataLabels if this was the last one
  322. if (point.dataLabels.length === 1) {
  323. delete point.dataLabels;
  324. }
  325. else {
  326. delete point.dataLabels[i];
  327. }
  328. }
  329. if (!i) {
  330. delete point.dataLabel;
  331. }
  332. if (connector) {
  333. point.connector = point.connector.destroy();
  334. if (point.connectors) {
  335. // Remove point.connectors if this was the last one
  336. if (point.connectors.length === 1) {
  337. delete point.connectors;
  338. }
  339. else {
  340. delete point.connectors[i];
  341. }
  342. }
  343. }
  344. // Individual labels are disabled if the are explicitly disabled
  345. // in the point options, or if they fall outside the plot area.
  346. }
  347. else if (labelEnabled && defined(labelText)) {
  348. if (!dataLabel) {
  349. // Create new label element
  350. point.dataLabels = point.dataLabels || [];
  351. dataLabel = point.dataLabels[i] = rotation ?
  352. // Labels don't rotate, use text element
  353. renderer.text(labelText, 0, -9999, labelOptions.useHTML)
  354. .addClass('highcharts-data-label') :
  355. // We can use label
  356. renderer.label(labelText, 0, -9999, labelOptions.shape, null, null, labelOptions.useHTML, null, 'data-label');
  357. // Store for backwards compatibility
  358. if (!i) {
  359. point.dataLabel = dataLabel;
  360. }
  361. dataLabel.addClass(' highcharts-data-label-color-' + point.colorIndex +
  362. ' ' + (labelOptions.className || '') +
  363. ( // #3398
  364. labelOptions.useHTML ?
  365. ' highcharts-tracker' :
  366. ''));
  367. }
  368. else {
  369. // Use old element and just update text
  370. attr.text = labelText;
  371. }
  372. // Store data label options for later access
  373. dataLabel.options = labelOptions;
  374. dataLabel.attr(attr);
  375. if (!chart.styledMode) {
  376. // Styles must be applied before add in order to read
  377. // text bounding box
  378. dataLabel.css(style).shadow(labelOptions.shadow);
  379. }
  380. if (!dataLabel.added) {
  381. dataLabel.add(dataLabelsGroup);
  382. }
  383. if (labelOptions.textPath && !labelOptions.useHTML) {
  384. dataLabel.setTextPath((point.getDataLabelPath &&
  385. point.getDataLabelPath(dataLabel)) || point.graphic, labelOptions.textPath);
  386. if (point.dataLabelPath &&
  387. !labelOptions.textPath.enabled) {
  388. // clean the DOM
  389. point.dataLabelPath = point.dataLabelPath.destroy();
  390. }
  391. }
  392. // Now the data label is created and placed at 0,0, so we
  393. // need to align it
  394. series.alignDataLabel(point, dataLabel, labelOptions, null, isNew);
  395. }
  396. });
  397. });
  398. }
  399. fireEvent(this, 'afterDrawDataLabels');
  400. };
  401. /**
  402. * Align each individual data label.
  403. *
  404. * @private
  405. * @function Highcharts.Series#alignDataLabel
  406. * @param {Highcharts.Point} point
  407. * @param {Highcharts.SVGElement} dataLabel
  408. * @param {Highcharts.DataLabelsOptions} options
  409. * @param {Highcharts.BBoxObject} alignTo
  410. * @param {boolean} [isNew]
  411. * @return {void}
  412. */
  413. Series.prototype.alignDataLabel = function (point, dataLabel, options, alignTo, isNew) {
  414. var series = this, chart = this.chart, inverted = this.isCartesian && chart.inverted, enabledDataSorting = this.enabledDataSorting, plotX = pick(point.dlBox && point.dlBox.centerX, point.plotX, -9999), plotY = pick(point.plotY, -9999), bBox = dataLabel.getBBox(), baseline, rotation = options.rotation, normRotation, negRotation, align = options.align, rotCorr, // rotation correction
  415. isInsidePlot = chart.isInsidePlot(plotX, Math.round(plotY), inverted),
  416. // Math.round for rounding errors (#2683), alignTo to allow column
  417. // labels (#2700)
  418. alignAttr, // the final position;
  419. justify = pick(options.overflow, (enabledDataSorting ? 'none' : 'justify')) === 'justify', visible = this.visible &&
  420. point.visible !== false &&
  421. (point.series.forceDL ||
  422. (enabledDataSorting && !justify) ||
  423. isInsidePlot ||
  424. (
  425. // If the data label is inside the align box, it is enough
  426. // that parts of the align box is inside the plot area
  427. // (#12370)
  428. options.inside && alignTo && chart.isInsidePlot(plotX, inverted ?
  429. alignTo.x + 1 :
  430. alignTo.y + alignTo.height - 1, inverted))), setStartPos = function (alignOptions) {
  431. if (enabledDataSorting && series.xAxis && !justify) {
  432. series.setDataLabelStartPos(point, dataLabel, isNew, isInsidePlot, alignOptions);
  433. }
  434. };
  435. if (visible) {
  436. baseline = chart.renderer.fontMetrics(chart.styledMode ? void 0 : options.style.fontSize, dataLabel).b;
  437. // The alignment box is a singular point
  438. alignTo = extend({
  439. x: inverted ? this.yAxis.len - plotY : plotX,
  440. y: Math.round(inverted ? this.xAxis.len - plotX : plotY),
  441. width: 0,
  442. height: 0
  443. }, alignTo);
  444. // Add the text size for alignment calculation
  445. extend(options, {
  446. width: bBox.width,
  447. height: bBox.height
  448. });
  449. // Allow a hook for changing alignment in the last moment, then do the
  450. // alignment
  451. if (rotation) {
  452. justify = false; // Not supported for rotated text
  453. rotCorr = chart.renderer.rotCorr(baseline, rotation); // #3723
  454. alignAttr = {
  455. x: (alignTo.x +
  456. (options.x || 0) +
  457. alignTo.width / 2 +
  458. rotCorr.x),
  459. y: (alignTo.y +
  460. (options.y || 0) +
  461. { top: 0, middle: 0.5, bottom: 1 }[options.verticalAlign] *
  462. alignTo.height)
  463. };
  464. setStartPos(alignAttr); // data sorting
  465. dataLabel[isNew ? 'attr' : 'animate'](alignAttr)
  466. .attr({
  467. align: align
  468. });
  469. // Compensate for the rotated label sticking out on the sides
  470. normRotation = (rotation + 720) % 360;
  471. negRotation = normRotation > 180 && normRotation < 360;
  472. if (align === 'left') {
  473. alignAttr.y -= negRotation ? bBox.height : 0;
  474. }
  475. else if (align === 'center') {
  476. alignAttr.x -= bBox.width / 2;
  477. alignAttr.y -= bBox.height / 2;
  478. }
  479. else if (align === 'right') {
  480. alignAttr.x -= bBox.width;
  481. alignAttr.y -= negRotation ? 0 : bBox.height;
  482. }
  483. dataLabel.placed = true;
  484. dataLabel.alignAttr = alignAttr;
  485. }
  486. else {
  487. setStartPos(alignTo); // data sorting
  488. dataLabel.align(options, null, alignTo);
  489. alignAttr = dataLabel.alignAttr;
  490. }
  491. // Handle justify or crop
  492. if (justify && alignTo.height >= 0) { // #8830
  493. this.justifyDataLabel(dataLabel, options, alignAttr, bBox, alignTo, isNew);
  494. // Now check that the data label is within the plot area
  495. }
  496. else if (pick(options.crop, true)) {
  497. visible =
  498. chart.isInsidePlot(alignAttr.x, alignAttr.y) &&
  499. chart.isInsidePlot(alignAttr.x + bBox.width, alignAttr.y + bBox.height);
  500. }
  501. // When we're using a shape, make it possible with a connector or an
  502. // arrow pointing to thie point
  503. if (options.shape && !rotation) {
  504. dataLabel[isNew ? 'attr' : 'animate']({
  505. anchorX: inverted ?
  506. chart.plotWidth - point.plotY :
  507. point.plotX,
  508. anchorY: inverted ?
  509. chart.plotHeight - point.plotX :
  510. point.plotY
  511. });
  512. }
  513. }
  514. // To use alignAttr property in hideOverlappingLabels
  515. if (isNew && enabledDataSorting) {
  516. dataLabel.placed = false;
  517. }
  518. // Show or hide based on the final aligned position
  519. if (!visible && (!enabledDataSorting || justify)) {
  520. dataLabel.hide(true);
  521. dataLabel.placed = false; // don't animate back in
  522. }
  523. };
  524. /**
  525. * Set starting position for data label sorting animation.
  526. *
  527. * @private
  528. * @function Highcharts.Series#setDataLabelStartPos
  529. * @param {Highcharts.SVGElement} dataLabel
  530. * @param {Highcharts.ColumnPoint} point
  531. * @param {boolean | undefined} [isNew]
  532. * @param {boolean} [isInside]
  533. * @param {Highcharts.AlignObject} [alignOptions]
  534. *
  535. * @return {void}
  536. */
  537. Series.prototype.setDataLabelStartPos = function (point, dataLabel, isNew, isInside, alignOptions) {
  538. var chart = this.chart, inverted = chart.inverted, xAxis = this.xAxis, reversed = xAxis.reversed, labelCenter = inverted ? dataLabel.height / 2 : dataLabel.width / 2, pointWidth = point.pointWidth, halfWidth = pointWidth ? pointWidth / 2 : 0, startXPos, startYPos;
  539. startXPos = inverted ?
  540. alignOptions.x :
  541. (reversed ?
  542. -labelCenter - halfWidth :
  543. xAxis.width - labelCenter + halfWidth);
  544. startYPos = inverted ?
  545. (reversed ?
  546. this.yAxis.height - labelCenter + halfWidth :
  547. -labelCenter - halfWidth) : alignOptions.y;
  548. dataLabel.startXPos = startXPos;
  549. dataLabel.startYPos = startYPos;
  550. // We need to handle visibility in case of sorting point outside plot area
  551. if (!isInside) {
  552. dataLabel
  553. .attr({ opacity: 1 })
  554. .animate({ opacity: 0 }, void 0, dataLabel.hide);
  555. }
  556. else if (dataLabel.visibility === 'hidden') {
  557. dataLabel.show();
  558. dataLabel
  559. .attr({ opacity: 0 })
  560. .animate({ opacity: 1 });
  561. }
  562. // Save start position on first render, but do not change position
  563. if (!chart.hasRendered) {
  564. return;
  565. }
  566. // Set start position
  567. if (isNew) {
  568. dataLabel.attr({ x: dataLabel.startXPos, y: dataLabel.startYPos });
  569. }
  570. dataLabel.placed = true;
  571. };
  572. /**
  573. * If data labels fall partly outside the plot area, align them back in, in a
  574. * way that doesn't hide the point.
  575. *
  576. * @private
  577. * @function Highcharts.Series#justifyDataLabel
  578. * @param {Highcharts.SVGElement} dataLabel
  579. * @param {Highcharts.DataLabelsOptions} options
  580. * @param {Highcharts.SVGAttributes} alignAttr
  581. * @param {Highcharts.BBoxObject} bBox
  582. * @param {Highcharts.BBoxObject} [alignTo]
  583. * @param {boolean} [isNew]
  584. * @return {boolean|undefined}
  585. */
  586. Series.prototype.justifyDataLabel = function (dataLabel, options, alignAttr, bBox, alignTo, isNew) {
  587. var chart = this.chart, align = options.align, verticalAlign = options.verticalAlign, off, justified, padding = dataLabel.box ? 0 : (dataLabel.padding || 0);
  588. var _a = options.x, x = _a === void 0 ? 0 : _a, _b = options.y, y = _b === void 0 ? 0 : _b;
  589. // Off left
  590. off = alignAttr.x + padding;
  591. if (off < 0) {
  592. if (align === 'right' && x >= 0) {
  593. options.align = 'left';
  594. options.inside = true;
  595. }
  596. else {
  597. x -= off;
  598. }
  599. justified = true;
  600. }
  601. // Off right
  602. off = alignAttr.x + bBox.width - padding;
  603. if (off > chart.plotWidth) {
  604. if (align === 'left' && x <= 0) {
  605. options.align = 'right';
  606. options.inside = true;
  607. }
  608. else {
  609. x += chart.plotWidth - off;
  610. }
  611. justified = true;
  612. }
  613. // Off top
  614. off = alignAttr.y + padding;
  615. if (off < 0) {
  616. if (verticalAlign === 'bottom' && y >= 0) {
  617. options.verticalAlign = 'top';
  618. options.inside = true;
  619. }
  620. else {
  621. y -= off;
  622. }
  623. justified = true;
  624. }
  625. // Off bottom
  626. off = alignAttr.y + bBox.height - padding;
  627. if (off > chart.plotHeight) {
  628. if (verticalAlign === 'top' && y <= 0) {
  629. options.verticalAlign = 'bottom';
  630. options.inside = true;
  631. }
  632. else {
  633. y += chart.plotHeight - off;
  634. }
  635. justified = true;
  636. }
  637. if (justified) {
  638. options.x = x;
  639. options.y = y;
  640. dataLabel.placed = !isNew;
  641. dataLabel.align(options, void 0, alignTo);
  642. }
  643. return justified;
  644. };
  645. if (seriesTypes.pie) {
  646. seriesTypes.pie.prototype.dataLabelPositioners = {
  647. // Based on the value computed in Highcharts' distribute algorithm.
  648. radialDistributionY: function (point) {
  649. return point.top + point.distributeBox.pos;
  650. },
  651. // get the x - use the natural x position for labels near the
  652. // top and bottom, to prevent the top and botton slice
  653. // connectors from touching each other on either side
  654. // Based on the value computed in Highcharts' distribute algorithm.
  655. radialDistributionX: function (series, point, y, naturalY) {
  656. return series.getX(y < point.top + 2 || y > point.bottom - 2 ?
  657. naturalY :
  658. y, point.half, point);
  659. },
  660. // dataLabels.distance determines the x position of the label
  661. justify: function (point, radius, seriesCenter) {
  662. return seriesCenter[0] + (point.half ? -1 : 1) *
  663. (radius + point.labelDistance);
  664. },
  665. // Left edges of the left-half labels touch the left edge of the plot
  666. // area. Right edges of the right-half labels touch the right edge of
  667. // the plot area.
  668. alignToPlotEdges: function (dataLabel, half, plotWidth, plotLeft) {
  669. var dataLabelWidth = dataLabel.getBBox().width;
  670. return half ? dataLabelWidth + plotLeft :
  671. plotWidth - dataLabelWidth - plotLeft;
  672. },
  673. // Connectors of each side end in the same x position. Labels are
  674. // aligned to them. Left edge of the widest left-half label touches the
  675. // left edge of the plot area. Right edge of the widest right-half label
  676. // touches the right edge of the plot area.
  677. alignToConnectors: function (points, half, plotWidth, plotLeft) {
  678. var maxDataLabelWidth = 0, dataLabelWidth;
  679. // find widest data label
  680. points.forEach(function (point) {
  681. dataLabelWidth = point.dataLabel.getBBox().width;
  682. if (dataLabelWidth > maxDataLabelWidth) {
  683. maxDataLabelWidth = dataLabelWidth;
  684. }
  685. });
  686. return half ? maxDataLabelWidth + plotLeft :
  687. plotWidth - maxDataLabelWidth - plotLeft;
  688. }
  689. };
  690. /**
  691. * Override the base drawDataLabels method by pie specific functionality
  692. *
  693. * @private
  694. * @function Highcharts.seriesTypes.pie#drawDataLabels
  695. * @return {void}
  696. */
  697. seriesTypes.pie.prototype.drawDataLabels = function () {
  698. var series = this, data = series.data, point, chart = series.chart, options = series.options.dataLabels || {}, connectorPadding = options.connectorPadding, connectorWidth, plotWidth = chart.plotWidth, plotHeight = chart.plotHeight, plotLeft = chart.plotLeft, maxWidth = Math.round(chart.chartWidth / 3), connector, seriesCenter = series.center, radius = seriesCenter[2] / 2, centerY = seriesCenter[1], dataLabel, dataLabelWidth,
  699. // labelPos,
  700. labelPosition, labelHeight,
  701. // divide the points into right and left halves for anti collision
  702. halves = [
  703. [],
  704. [] // left
  705. ], x, y, visibility, j, overflow = [0, 0, 0, 0], // top, right, bottom, left
  706. dataLabelPositioners = series.dataLabelPositioners, pointDataLabelsOptions;
  707. // get out if not enabled
  708. if (!series.visible ||
  709. (!options.enabled &&
  710. !series._hasPointLabels)) {
  711. return;
  712. }
  713. // Reset all labels that have been shortened
  714. data.forEach(function (point) {
  715. if (point.dataLabel && point.visible && point.dataLabel.shortened) {
  716. point.dataLabel
  717. .attr({
  718. width: 'auto'
  719. }).css({
  720. width: 'auto',
  721. textOverflow: 'clip'
  722. });
  723. point.dataLabel.shortened = false;
  724. }
  725. });
  726. // run parent method
  727. Series.prototype.drawDataLabels.apply(series);
  728. data.forEach(function (point) {
  729. if (point.dataLabel) {
  730. if (point.visible) { // #407, #2510
  731. // Arrange points for detection collision
  732. halves[point.half].push(point);
  733. // Reset positions (#4905)
  734. point.dataLabel._pos = null;
  735. // Avoid long labels squeezing the pie size too far down
  736. if (!defined(options.style.width) &&
  737. !defined(point.options.dataLabels &&
  738. point.options.dataLabels.style &&
  739. point.options.dataLabels.style.width)) {
  740. if (point.dataLabel.getBBox().width > maxWidth) {
  741. point.dataLabel.css({
  742. // Use a fraction of the maxWidth to avoid
  743. // wrapping close to the end of the string.
  744. width: Math.round(maxWidth * 0.7) + 'px'
  745. });
  746. point.dataLabel.shortened = true;
  747. }
  748. }
  749. }
  750. else {
  751. point.dataLabel = point.dataLabel.destroy();
  752. // Workaround to make pies destroy multiple datalabels
  753. // correctly. This logic needs rewriting to support multiple
  754. // datalabels fully.
  755. if (point.dataLabels && point.dataLabels.length === 1) {
  756. delete point.dataLabels;
  757. }
  758. }
  759. }
  760. });
  761. /* Loop over the points in each half, starting from the top and bottom
  762. * of the pie to detect overlapping labels.
  763. */
  764. halves.forEach(function (points, i) {
  765. var top, bottom, length = points.length, positions = [], naturalY, sideOverflow, size, distributionLength;
  766. if (!length) {
  767. return;
  768. }
  769. // Sort by angle
  770. series.sortByAngle(points, i - 0.5);
  771. // Only do anti-collision when we have dataLabels outside the pie
  772. // and have connectors. (#856)
  773. if (series.maxLabelDistance > 0) {
  774. top = Math.max(0, centerY - radius - series.maxLabelDistance);
  775. bottom = Math.min(centerY + radius + series.maxLabelDistance, chart.plotHeight);
  776. points.forEach(function (point) {
  777. // check if specific points' label is outside the pie
  778. if (point.labelDistance > 0 && point.dataLabel) {
  779. // point.top depends on point.labelDistance value
  780. // Used for calculation of y value in getX method
  781. point.top = Math.max(0, centerY - radius - point.labelDistance);
  782. point.bottom = Math.min(centerY + radius + point.labelDistance, chart.plotHeight);
  783. size = point.dataLabel.getBBox().height || 21;
  784. // point.positionsIndex is needed for getting index of
  785. // parameter related to specific point inside positions
  786. // array - not every point is in positions array.
  787. point.distributeBox = {
  788. target: point.labelPosition.natural.y -
  789. point.top + size / 2,
  790. size: size,
  791. rank: point.y
  792. };
  793. positions.push(point.distributeBox);
  794. }
  795. });
  796. distributionLength = bottom + size - top;
  797. H.distribute(positions, distributionLength, distributionLength / 5);
  798. }
  799. // Now the used slots are sorted, fill them up sequentially
  800. for (j = 0; j < length; j++) {
  801. point = points[j];
  802. // labelPos = point.labelPos;
  803. labelPosition = point.labelPosition;
  804. dataLabel = point.dataLabel;
  805. visibility = point.visible === false ? 'hidden' : 'inherit';
  806. naturalY = labelPosition.natural.y;
  807. y = naturalY;
  808. if (positions && defined(point.distributeBox)) {
  809. if (typeof point.distributeBox.pos === 'undefined') {
  810. visibility = 'hidden';
  811. }
  812. else {
  813. labelHeight = point.distributeBox.size;
  814. // Find label's y position
  815. y = dataLabelPositioners
  816. .radialDistributionY(point);
  817. }
  818. }
  819. // It is needed to delete point.positionIndex for
  820. // dynamically added points etc.
  821. delete point.positionIndex; // @todo unused
  822. // Find label's x position
  823. // justify is undocumented in the API - preserve support for it
  824. if (options.justify) {
  825. x = dataLabelPositioners.justify(point, radius, seriesCenter);
  826. }
  827. else {
  828. switch (options.alignTo) {
  829. case 'connectors':
  830. x = dataLabelPositioners.alignToConnectors(points, i, plotWidth, plotLeft);
  831. break;
  832. case 'plotEdges':
  833. x = dataLabelPositioners.alignToPlotEdges(dataLabel, i, plotWidth, plotLeft);
  834. break;
  835. default:
  836. x = dataLabelPositioners.radialDistributionX(series, point, y, naturalY);
  837. }
  838. }
  839. // Record the placement and visibility
  840. dataLabel._attr = {
  841. visibility: visibility,
  842. align: labelPosition.alignment
  843. };
  844. pointDataLabelsOptions = point.options.dataLabels || {};
  845. dataLabel._pos = {
  846. x: (x +
  847. pick(pointDataLabelsOptions.x, options.x) + // (#12985)
  848. ({
  849. left: connectorPadding,
  850. right: -connectorPadding
  851. }[labelPosition.alignment] || 0)),
  852. // 10 is for the baseline (label vs text)
  853. y: (y +
  854. pick(pointDataLabelsOptions.y, options.y) - // (#12985)
  855. 10)
  856. };
  857. // labelPos.x = x;
  858. // labelPos.y = y;
  859. labelPosition.final.x = x;
  860. labelPosition.final.y = y;
  861. // Detect overflowing data labels
  862. if (pick(options.crop, true)) {
  863. dataLabelWidth = dataLabel.getBBox().width;
  864. sideOverflow = null;
  865. // Overflow left
  866. if (x - dataLabelWidth < connectorPadding &&
  867. i === 1 // left half
  868. ) {
  869. sideOverflow = Math.round(dataLabelWidth - x + connectorPadding);
  870. overflow[3] = Math.max(sideOverflow, overflow[3]);
  871. // Overflow right
  872. }
  873. else if (x + dataLabelWidth > plotWidth - connectorPadding &&
  874. i === 0 // right half
  875. ) {
  876. sideOverflow = Math.round(x + dataLabelWidth - plotWidth + connectorPadding);
  877. overflow[1] = Math.max(sideOverflow, overflow[1]);
  878. }
  879. // Overflow top
  880. if (y - labelHeight / 2 < 0) {
  881. overflow[0] = Math.max(Math.round(-y + labelHeight / 2), overflow[0]);
  882. // Overflow left
  883. }
  884. else if (y + labelHeight / 2 > plotHeight) {
  885. overflow[2] = Math.max(Math.round(y + labelHeight / 2 - plotHeight), overflow[2]);
  886. }
  887. dataLabel.sideOverflow = sideOverflow;
  888. }
  889. } // for each point
  890. }); // for each half
  891. // Do not apply the final placement and draw the connectors until we
  892. // have verified that labels are not spilling over.
  893. if (arrayMax(overflow) === 0 ||
  894. this.verifyDataLabelOverflow(overflow)) {
  895. // Place the labels in the final position
  896. this.placeDataLabels();
  897. this.points.forEach(function (point) {
  898. // #8864: every connector can have individual options
  899. pointDataLabelsOptions =
  900. merge(options, point.options.dataLabels);
  901. connectorWidth =
  902. pick(pointDataLabelsOptions.connectorWidth, 1);
  903. // Draw the connector
  904. if (connectorWidth) {
  905. var isNew;
  906. connector = point.connector;
  907. dataLabel = point.dataLabel;
  908. if (dataLabel &&
  909. dataLabel._pos &&
  910. point.visible &&
  911. point.labelDistance > 0) {
  912. visibility = dataLabel._attr.visibility;
  913. isNew = !connector;
  914. if (isNew) {
  915. point.connector = connector = chart.renderer
  916. .path()
  917. .addClass('highcharts-data-label-connector ' +
  918. ' highcharts-color-' + point.colorIndex +
  919. (point.className ?
  920. ' ' + point.className :
  921. ''))
  922. .add(series.dataLabelsGroup);
  923. if (!chart.styledMode) {
  924. connector.attr({
  925. 'stroke-width': connectorWidth,
  926. 'stroke': (pointDataLabelsOptions.connectorColor ||
  927. point.color ||
  928. '#666666')
  929. });
  930. }
  931. }
  932. connector[isNew ? 'attr' : 'animate']({
  933. d: point.getConnectorPath()
  934. });
  935. connector.attr('visibility', visibility);
  936. }
  937. else if (connector) {
  938. point.connector = connector.destroy();
  939. }
  940. }
  941. });
  942. }
  943. };
  944. /**
  945. * Extendable method for getting the path of the connector between the data
  946. * label and the pie slice.
  947. *
  948. * @private
  949. * @function Highcharts.seriesTypes.pie#connectorPath
  950. *
  951. * @param {*} labelPos
  952. *
  953. * @return {Highcharts.SVGPathArray}
  954. */
  955. // TODO: depracated - remove it
  956. /*
  957. seriesTypes.pie.prototype.connectorPath = function (labelPos) {
  958. var x = labelPos.x,
  959. y = labelPos.y;
  960. return pick(this.options.dataLabels.softConnector, true) ? [
  961. 'M',
  962. // end of the string at the label
  963. x + (labelPos[6] === 'left' ? 5 : -5), y,
  964. 'C',
  965. x, y, // first break, next to the label
  966. 2 * labelPos[2] - labelPos[4], 2 * labelPos[3] - labelPos[5],
  967. labelPos[2], labelPos[3], // second break
  968. 'L',
  969. labelPos[4], labelPos[5] // base
  970. ] : [
  971. 'M',
  972. // end of the string at the label
  973. x + (labelPos[6] === 'left' ? 5 : -5), y,
  974. 'L',
  975. labelPos[2], labelPos[3], // second break
  976. 'L',
  977. labelPos[4], labelPos[5] // base
  978. ];
  979. };
  980. */
  981. /**
  982. * Perform the final placement of the data labels after we have verified
  983. * that they fall within the plot area.
  984. *
  985. * @private
  986. * @function Highcharts.seriesTypes.pie#placeDataLabels
  987. * @return {void}
  988. */
  989. seriesTypes.pie.prototype.placeDataLabels = function () {
  990. this.points.forEach(function (point) {
  991. var dataLabel = point.dataLabel, _pos;
  992. if (dataLabel && point.visible) {
  993. _pos = dataLabel._pos;
  994. if (_pos) {
  995. // Shorten data labels with ellipsis if they still overflow
  996. // after the pie has reached minSize (#223).
  997. if (dataLabel.sideOverflow) {
  998. dataLabel._attr.width =
  999. Math.max(dataLabel.getBBox().width -
  1000. dataLabel.sideOverflow, 0);
  1001. dataLabel.css({
  1002. width: dataLabel._attr.width + 'px',
  1003. textOverflow: ((this.options.dataLabels.style || {})
  1004. .textOverflow ||
  1005. 'ellipsis')
  1006. });
  1007. dataLabel.shortened = true;
  1008. }
  1009. dataLabel.attr(dataLabel._attr);
  1010. dataLabel[dataLabel.moved ? 'animate' : 'attr'](_pos);
  1011. dataLabel.moved = true;
  1012. }
  1013. else if (dataLabel) {
  1014. dataLabel.attr({ y: -9999 });
  1015. }
  1016. }
  1017. // Clear for update
  1018. delete point.distributeBox;
  1019. }, this);
  1020. };
  1021. seriesTypes.pie.prototype.alignDataLabel = noop;
  1022. /**
  1023. * Verify whether the data labels are allowed to draw, or we should run more
  1024. * translation and data label positioning to keep them inside the plot area.
  1025. * Returns true when data labels are ready to draw.
  1026. *
  1027. * @private
  1028. * @function Highcharts.seriesTypes.pie#verifyDataLabelOverflow
  1029. * @param {Array<number>} overflow
  1030. * @return {boolean}
  1031. */
  1032. seriesTypes.pie.prototype.verifyDataLabelOverflow = function (overflow) {
  1033. var center = this.center, options = this.options, centerOption = options.center, minSize = options.minSize || 80, newSize = minSize,
  1034. // If a size is set, return true and don't try to shrink the pie
  1035. // to fit the labels.
  1036. ret = options.size !== null;
  1037. if (!ret) {
  1038. // Handle horizontal size and center
  1039. if (centerOption[0] !== null) { // Fixed center
  1040. newSize = Math.max(center[2] -
  1041. Math.max(overflow[1], overflow[3]), minSize);
  1042. }
  1043. else { // Auto center
  1044. newSize = Math.max(
  1045. // horizontal overflow
  1046. center[2] - overflow[1] - overflow[3], minSize);
  1047. // horizontal center
  1048. center[0] += (overflow[3] - overflow[1]) / 2;
  1049. }
  1050. // Handle vertical size and center
  1051. if (centerOption[1] !== null) { // Fixed center
  1052. newSize = clamp(newSize, minSize, center[2] - Math.max(overflow[0], overflow[2]));
  1053. }
  1054. else { // Auto center
  1055. newSize = clamp(newSize, minSize,
  1056. // vertical overflow
  1057. center[2] - overflow[0] - overflow[2]);
  1058. // vertical center
  1059. center[1] += (overflow[0] - overflow[2]) / 2;
  1060. }
  1061. // If the size must be decreased, we need to run translate and
  1062. // drawDataLabels again
  1063. if (newSize < center[2]) {
  1064. center[2] = newSize;
  1065. center[3] = Math.min(// #3632
  1066. relativeLength(options.innerSize || 0, newSize), newSize);
  1067. this.translate(center);
  1068. if (this.drawDataLabels) {
  1069. this.drawDataLabels();
  1070. }
  1071. // Else, return true to indicate that the pie and its labels is
  1072. // within the plot area
  1073. }
  1074. else {
  1075. ret = true;
  1076. }
  1077. }
  1078. return ret;
  1079. };
  1080. }
  1081. if (seriesTypes.column) {
  1082. /**
  1083. * Override the basic data label alignment by adjusting for the position of
  1084. * the column.
  1085. *
  1086. * @private
  1087. * @function Highcharts.seriesTypes.column#alignDataLabel
  1088. * @param {Highcharts.Point} point
  1089. * @param {Highcharts.SVGElement} dataLabel
  1090. * @param {Highcharts.DataLabelsOptions} options
  1091. * @param {Highcharts.BBoxObject} alignTo
  1092. * @param {boolean} [isNew]
  1093. * @return {void}
  1094. */
  1095. seriesTypes.column.prototype.alignDataLabel = function (point, dataLabel, options, alignTo, isNew) {
  1096. var inverted = this.chart.inverted, series = point.series,
  1097. // data label box for alignment
  1098. dlBox = point.dlBox || point.shapeArgs, below = pick(point.below, // range series
  1099. point.plotY >
  1100. pick(this.translatedThreshold, series.yAxis.len)),
  1101. // draw it inside the box?
  1102. inside = pick(options.inside, !!this.options.stacking), overshoot;
  1103. // Align to the column itself, or the top of it
  1104. if (dlBox) { // Area range uses this method but not alignTo
  1105. alignTo = merge(dlBox);
  1106. if (alignTo.y < 0) {
  1107. alignTo.height += alignTo.y;
  1108. alignTo.y = 0;
  1109. }
  1110. // If parts of the box overshoots outside the plot area, modify the
  1111. // box to center the label inside
  1112. overshoot = alignTo.y + alignTo.height - series.yAxis.len;
  1113. if (overshoot > 0 && overshoot < alignTo.height) {
  1114. alignTo.height -= overshoot;
  1115. }
  1116. if (inverted) {
  1117. alignTo = {
  1118. x: series.yAxis.len - alignTo.y - alignTo.height,
  1119. y: series.xAxis.len - alignTo.x - alignTo.width,
  1120. width: alignTo.height,
  1121. height: alignTo.width
  1122. };
  1123. }
  1124. // Compute the alignment box
  1125. if (!inside) {
  1126. if (inverted) {
  1127. alignTo.x += below ? 0 : alignTo.width;
  1128. alignTo.width = 0;
  1129. }
  1130. else {
  1131. alignTo.y += below ? alignTo.height : 0;
  1132. alignTo.height = 0;
  1133. }
  1134. }
  1135. }
  1136. // When alignment is undefined (typically columns and bars), display the
  1137. // individual point below or above the point depending on the threshold
  1138. options.align = pick(options.align, !inverted || inside ? 'center' : below ? 'right' : 'left');
  1139. options.verticalAlign = pick(options.verticalAlign, inverted || inside ? 'middle' : below ? 'top' : 'bottom');
  1140. // Call the parent method
  1141. Series.prototype.alignDataLabel.call(this, point, dataLabel, options, alignTo, isNew);
  1142. // If label was justified and we have contrast, set it:
  1143. if (options.inside && point.contrastColor) {
  1144. dataLabel.css({
  1145. color: point.contrastColor
  1146. });
  1147. }
  1148. };
  1149. }