DataLabels.js 49 KB

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