all files / chart/series/ data-label.js

98.09% Statements 359/366
94.11% Branches 447/475
100% Functions 24/24
98.08% Lines 358/365
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599   639× 639×   992× 992× 992× 992× 992×         992×           992× 992× 992× 992×     992× 978×   14× 13× 13× 13× 13×                                                     19195×   992× 992× 992× 992× 992× 992× 992× 992× 992× 992× 992×     992× 6495× 6495× 6495× 6495× 6495× 6495×   6268× 6268× 6268× 8164×         8164× 8164× 8164× 8164× 8164× 8164× 356×     7808× 7808× 7808× 7517× 7517× 3103×   7517× 7517× 7517×               992× 35×     356× 356× 356×           356× 356× 356× 356× 356× 356× 356× 356×   356×           281× 281× 281×       8164× 8164× 420×   8164× 8164× 8164× 8164× 8164× 8164× 6954× 6954×   6954×   6954×     6954× 322×       1210× 1210× 1210×   1210×   8164× 8164×   7528× 7528× 7528× 7528× 7528×   8164×   322× 322× 322× 322× 226×       96×     322× 322× 16×   306× 192×   322× 24×   298×   290× 32×   258×     250× 170×       80×     322× 322× 322×   8164× 8164× 8164× 840×   8164× 8164× 8164× 8164× 550× 550×   99× 99×   99× 99×   99× 99×   99× 99×   99× 99×   55× 55× 55×     550×   7614× 7038×   576× 156×   420×       420×   8164× 420×         420× 420×     8164×   8385× 322×   8063× 8063× 8063× 8063× 8063× 2460×   5603× 1206×   4397× 48×   8063×   599×         599×   525×     525×   2440× 2440×   4499× 4499× 4499×   8063×   8063×     8063×   4611× 4611×   161×   4611× 4611×     1661×   1661×   1198×   1198×   1397× 1397×   4611×   8164× 8164× 8164× 4732×     2440× 2440× 2440× 2440× 2440× 2440× 2440× 3080× 3080× 2455× 2455×     625× 625×     3080×   2440×   4125×   106×   106×   249×   249×   3770× 3770×   4125×   4499× 4499× 4499×       974× 974× 974×   330×   330× 330×   988× 436× 436×     552×       552×     988×   2207× 949×     1258×   2207×   4499×   1740× 1740× 1600× 804×     796×         140× 70×     70×       1740×   1397× 1397× 1397× 1397× 1397× 1397× 1397× 1397× 1397× 1397× 1397× 1397× 1397× 51×   1346× 71× 71× 61×       1275× 150× 69×   81× 54×     27× 27× 27×       1125× 172×     953× 164×       789×   788× 56×       732× 732× 732×         1397× 1397× 1397× 1725× 1725× 1725×   1725× 1725×   1397×   100× 100× 100× 100× 100× 100× 786×     778× 778× 778×         4805×   20665×          
define(["require", "exports", "../../common/utils/helper", "../../common/utils/helper", "../../common/model/constants", "../../common/utils/helper", "@syncfusion/ej2-base", "../../common/utils/helper"], function (require, exports, helper_1, helper_2, constants_1, helper_3, ej2_base_1, helper_4) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DataLabel = (function () {
        function DataLabel(chart) {
            this.errorHeight = 0;
            this.chart = chart;
        }
        DataLabel.prototype.initPrivateVariables = function (series, marker) {
            var transform;
            var render = series.chart.renderer;
            transform = series.chart.chartAreaType === 'Cartesian' ? 'translate(' + series.clipRect.x + ',' + (series.clipRect.y) + ')' : '';
            Eif (marker.dataLabel.visible) {
                series.shapeElement = render.createGroup({
                    'id': this.chart.element.id + 'ShapeGroup' + series.index,
                    'transform': transform,
                    'clip-path': 'url(#' + this.chart.element.id + '_ChartSeriesClipRect_' + series.index + ')'
                });
                series.textElement = render.createGroup({
                    'id': this.chart.element.id + 'TextGroup' + series.index,
                    'transform': transform,
                    'clip-path': 'url(#' + this.chart.element.id + '_ChartSeriesClipRect_' + series.index + ')'
                });
            }
            this.markerHeight = ((series.type === 'Scatter' || marker.visible) && !this.isRectSeries(series)) ? (marker.height / 2) : 0;
            this.commonId = this.chart.element.id + '_Series_' + series.index + '_Point_';
            this.calculateErrorHeight(series, series.marker.dataLabel.position);
            this.chartBackground = this.chart.chartArea.background === 'trasparent' ?
                this.chart.background || this.chart.themeStyle.background : this.chart.chartArea.background;
        };
        DataLabel.prototype.calculateErrorHeight = function (series, position) {
            if (!series.errorBar.visible) {
                return null;
            }
            else if (series.errorBar.visible && this.chart.chartAreaType !== 'PolarRadar') {
                var direction = series.errorBar.direction;
                var positiveHeight = this.chart.errorBarModule.positiveHeight;
                var negativeHeight = this.chart.errorBarModule.negativeHeight;
                if (this.isRectSeries(series)) {
                    if (position === 'Top' || position === 'Auto') {
                        Eif (direction === 'Both' || direction === 'Minus') {
                            this.errorHeight = negativeHeight;
                        }
                        else {
                            this.errorHeight = 0;
                        }
                    }
                    if (position === 'Outer' || position === 'Auto') {
                        Eif (direction === 'Both' || direction === 'Plus') {
                            this.errorHeight = positiveHeight;
                        }
                        else {
                            this.errorHeight = 0;
                        }
                    }
                }
                else {
                    if (position === 'Top' || position === 'Outer' || position === 'Auto') {
                        Eif ((direction === 'Both' || direction === 'Plus') && (!series.chart.isTransposed)) {
                            this.errorHeight = positiveHeight;
                        }
                        else {
                            this.errorHeight = 0;
                        }
                    }
                    if (position === 'Bottom' || position === 'Auto') {
                        if (direction === 'Both' || direction === 'Minus') {
                            this.errorHeight = negativeHeight;
                        }
                        else {
                            this.errorHeight = 0;
                        }
                    }
                }
            }
            else {
                this.errorHeight = 0;
            }
        };
        DataLabel.prototype.isRectSeries = function (series) {
            return series.isRectSeries || series.type === 'RangeArea';
        };
        DataLabel.prototype.render = function (series, chart, dataLabel) {
            var _this = this;
            this.initPrivateVariables(series, series.marker);
            var rect;
            var rgbValue;
            var contrast;
            var argsData;
            var border;
            var textSize;
            this.inverted = chart.requireInvertedAxis;
            this.yAxisInversed = series.yAxis.isInversed;
            var element = ej2_base_1.createElement('div', {
                id: chart.element.id + '_Series_' + series.index + '_DataLabelCollections'
            });
            series.points.map(function (point, index) {
                _this.margin = dataLabel.margin;
                var labelText = [];
                var labelLength;
                var clip = series.clipRect;
                border = { width: dataLabel.border.width, color: dataLabel.border.color };
                if ((point.symbolLocations.length && point.symbolLocations[0]) ||
                    (series.type === 'BoxAndWhisker' && point.regions.length)) {
                    labelText = helper_2.getLabelText(point, series, chart);
                    labelLength = labelText.length;
                    for (var i = 0; i < labelLength; i++) {
                        argsData = {
                            cancel: false, name: constants_1.textRender, series: series,
                            point: point, text: labelText[i], border: border,
                            color: dataLabel.fill, template: dataLabel.template
                        };
                        chart.trigger(constants_1.textRender, argsData);
                        Eif (!argsData.cancel) {
                            _this.fontBackground = argsData.color;
                            _this.isDataLabelShape(argsData);
                            _this.markerHeight = series.type === 'Bubble' ? (point.regions[0].height / 2) : _this.markerHeight;
                            if (argsData.template !== null) {
                                _this.createDataLabelTemplate(element, series, dataLabel, point, argsData, i);
                            }
                            else {
                                textSize = helper_2.measureText(argsData.text, dataLabel.font);
                                rect = _this.calculateTextPosition(point, series, textSize, dataLabel, i);
                                if (!helper_1.isCollide(rect, chart.dataLabelCollections, clip)) {
                                    chart.dataLabelCollections.push(new helper_1.Rect(rect.x + clip.x, rect.y + clip.y, rect.width, rect.height));
                                    if (_this.isShape) {
                                        series.shapeElement.appendChild(chart.renderer.drawRectangle(new helper_1.RectOption(_this.commonId + index + '_TextShape_' + i, argsData.color, argsData.border, dataLabel.opacity, rect, dataLabel.rx, dataLabel.ry)));
                                    }
                                    rgbValue = helper_2.convertHexToColor(helper_2.colorNameToHex(_this.fontBackground));
                                    contrast = Math.round((rgbValue.r * 299 + rgbValue.g * 587 + rgbValue.b * 114) / 1000);
                                    helper_2.textElement(new helper_1.TextOption(_this.commonId + index + '_Text_' + i, rect.x + _this.margin.left + textSize.width / 2, rect.y + _this.margin.top + textSize.height * 3 / 4, 'middle', argsData.text, 'rotate(0,' + (rect.x) + ',' + (rect.y) + ')', 'auto'), dataLabel.font, dataLabel.font.color ||
                                        ((contrast >= 128 || series.type === 'Hilo') ? 'black' : 'white'), series.textElement);
                                }
                            }
                        }
                    }
                }
            });
            if (element.childElementCount) {
                helper_3.getElement(chart.element.id + '_Secondary_Element').appendChild(element);
            }
        };
        DataLabel.prototype.createDataLabelTemplate = function (parentElement, series, dataLabel, point, data, labelIndex) {
            this.margin = { left: 0, right: 0, bottom: 0, top: 0 };
            var clip = series.clipRect;
            var childElement = helper_3.createTemplate(ej2_base_1.createElement('div', {
                id: this.chart.element.id + '_Series_' + series.index + '_DataLabel_'
                    + point.index + (labelIndex ? ('_' + labelIndex) : ''),
                styles: 'position: absolute;background-color:' + data.color + ';' +
                    helper_3.getFontStyle(dataLabel.font) + ';border:' + data.border.width + 'px solid ' + data.border.color + ';'
            }), point.index, data.template, this.chart, point, series);
            var elementRect = helper_3.measureElementRect(childElement);
            var rect = this.calculateTextPosition(point, series, { width: elementRect.width, height: elementRect.height }, dataLabel, labelIndex);
            childElement.style.left = ((this.chart.chartAreaType === 'PolarRadar' ? 0 : series.clipRect.x) + rect.x) + 'px';
            childElement.style.top = ((this.chart.chartAreaType === 'PolarRadar' ? 0 : series.clipRect.y) + rect.y) + 'px';
            var rgbValue = helper_2.convertHexToColor(helper_2.colorNameToHex(this.fontBackground));
            var vAxis = series.chart.requireInvertedAxis ? series.xAxis : series.yAxis;
            var hAxis = series.chart.requireInvertedAxis ? series.yAxis : series.xAxis;
            childElement.style.color = dataLabel.font.color ||
                ((Math.round((rgbValue.r * 299 + rgbValue.g * 587 + rgbValue.b * 114) / 1000)) >= 128 ? 'black' : 'white');
            if (childElement.childElementCount && !helper_1.isCollide(rect, this.chart.dataLabelCollections, clip)
                && (series.seriesType !== 'XY' || point.yValue === undefined || helper_3.withIn(point.yValue, series.yAxis.visibleRange) ||
                    (series.type.indexOf('100') > -1 && helper_3.withIn(series.stackedValues.endValues[point.index], series.yAxis.visibleRange)))
                && helper_3.withIn(point.xValue, series.xAxis.visibleRange) && parseFloat(childElement.style.top) >= vAxis.rect.y &&
                parseFloat(childElement.style.left) >= hAxis.rect.x && parseFloat(childElement.style.top) <= vAxis.rect.y + vAxis.rect.height &&
                parseFloat(childElement.style.left) <= hAxis.rect.x + hAxis.rect.width) {
                this.chart.dataLabelCollections.push(new helper_1.Rect(rect.x + clip.x, rect.y + clip.y, rect.width, rect.height));
                parentElement.appendChild(childElement);
                if (series.animation.enable && this.chart.animateSeries) {
                    this.doDataLabelAnimation(series, childElement);
                }
            }
        };
        DataLabel.prototype.calculateTextPosition = function (point, series, textSize, dataLabel, labelIndex) {
            var labelRegion = labelIndex > 1 ? (series.type === 'Candle') ? point.regions[1] : point.regions[0] : point.regions[0];
            if (labelIndex > 1 && series.type === 'HiloOpenClose') {
                labelRegion = (labelIndex === 2) ? point.regions[1] : point.regions[2];
            }
            var location;
            location = this.getLabelLocation(point, series, textSize, labelIndex);
            var padding = 5;
            var clipRect = series.clipRect;
            var rect;
            if (!this.chart.requireInvertedAxis || !this.isRectSeries(series) || series.type === 'BoxAndWhisker') {
                this.locationX = location.x;
                var alignmentValue = textSize.height + (this.borderWidth * 2) + this.markerHeight +
                    this.margin.bottom + this.margin.top + padding;
                location.y = (dataLabel.position === 'Auto') ? location.y :
                    this.calculateAlignment(alignmentValue, location.y, dataLabel.alignment, this.isRectSeries(series) ? point.yValue < 0 : false);
                location.y = (!this.isRectSeries(series) || series.type === 'BoxAndWhisker') ?
                    this.calculatePathPosition(location.y, dataLabel.position, series, point, textSize, labelIndex) :
                    this.calculateRectPosition(location.y, labelRegion, point.yValue < 0 !== this.yAxisInversed, dataLabel.position, series, textSize, labelIndex, point);
                if (this.isRectSeries(series) && this.chart.chartAreaType === 'PolarRadar') {
                    location = this.calculatePolarRectPosition(location, dataLabel.position, series, point, textSize, labelIndex);
                }
            }
            else {
                this.locationY = location.y;
                var alignmentValue = textSize.width + this.borderWidth + this.margin.left + this.margin.right - padding;
                location.x = dataLabel.position === 'Auto' ? location.x :
                    this.calculateAlignment(alignmentValue, location.x, dataLabel.alignment, point.yValue < 0);
                location.x = this.calculateRectPosition(location.x, labelRegion, point.yValue < 0 !== this.yAxisInversed, dataLabel.position, series, textSize, labelIndex, point);
            }
            rect = helper_2.calculateRect(location, textSize, this.margin);
            if (!((rect.y > clipRect.height) || (rect.x > clipRect.width) ||
                (rect.x + rect.width < 0) || (rect.y + rect.height < 0))) {
                rect.x = rect.x < 0 ? padding : rect.x;
                rect.y = rect.y < 0 ? padding : rect.y;
                rect.x -= (rect.x + rect.width) > clipRect.width ? (rect.x + rect.width) - clipRect.width + padding : 0;
                rect.y -= (rect.y + rect.height) > clipRect.height ? (rect.y + rect.height) - clipRect.height + padding : 0;
                this.fontBackground = this.fontBackground === 'transparent' ? this.chartBackground : this.fontBackground;
            }
            return rect;
        };
        DataLabel.prototype.calculatePolarRectPosition = function (location, position, series, point, size, labelIndex) {
            var padding = 5;
            var columnRadius;
            var angle = (point.regionData.startAngle - 0.5 * Math.PI) + (point.regionData.endAngle - point.regionData.startAngle) / 2;
            if (labelIndex === 0) {
                columnRadius = point.regionData.radius < point.regionData.innerRadius ? point.regionData.innerRadius
                    : point.regionData.radius;
            }
            else {
                columnRadius = point.regionData.radius > point.regionData.innerRadius ? point.regionData.innerRadius
                    : point.regionData.radius;
            }
            this.fontBackground = this.fontBackground === 'transparent' ? this.chartBackground : this.fontBackground;
            if (series.drawType.indexOf('Stacking') > -1) {
                position = position === 'Outer' ? 'Top' : position;
            }
            else if (series.drawType.indexOf('Range') > -1) {
                position = (position === 'Outer' || position === 'Top') ? position : 'Auto';
            }
            if (position === 'Outer') {
                columnRadius = labelIndex === 0 ? columnRadius + 2 * padding : columnRadius - 2 * padding;
            }
            else if (position === 'Middle') {
                columnRadius = columnRadius / 2 + padding;
            }
            else if (position === 'Top') {
                columnRadius = labelIndex === 0 ? columnRadius - 2 * padding : columnRadius + 2 * padding;
            }
            else if (position === 'Bottom') {
                columnRadius = padding;
            }
            else {
                if (labelIndex === 0) {
                    columnRadius = columnRadius >= series.chart.radius ? columnRadius - padding :
                        series.drawType === 'StackingColumn' ? columnRadius - 2 * padding : columnRadius + 2 * padding;
                }
                else {
                    columnRadius = columnRadius >= series.chart.radius ? columnRadius + padding : columnRadius - 2 * padding;
                }
            }
            location.x = series.clipRect.width / 2 + series.clipRect.x + columnRadius * Math.cos(angle);
            location.y = series.clipRect.height / 2 + series.clipRect.y + columnRadius * Math.sin(angle);
            return location;
        };
        DataLabel.prototype.getLabelLocation = function (point, series, textSize, labelIndex) {
            var location = new helper_1.ChartLocation(0, 0);
            var labelRegion = (series.type === 'Candle' && labelIndex > 1) ? point.regions[1] : point.regions[0];
            if (series.type === 'HiloOpenClose') {
                labelRegion = (labelIndex === 2) ? point.regions[1] : point.regions[2];
            }
            var xAxis = series.xAxis;
            var yAxis = series.yAxis;
            var isInverted = series.chart.requireInvertedAxis;
            if (series.type === 'BoxAndWhisker') {
                this.markerHeight = 0;
                switch (labelIndex) {
                    case 0:
                        location = helper_4.getPoint(point.xValue, point.median, xAxis, yAxis, isInverted);
                        break;
                    case 1:
                        location = helper_4.getPoint(point.xValue, point.maximum, xAxis, yAxis, isInverted);
                        break;
                    case 2:
                        location = helper_4.getPoint(point.xValue, point.minimum, xAxis, yAxis, isInverted);
                        break;
                    case 3:
                        location = helper_4.getPoint(point.xValue, point.upperQuartile, xAxis, yAxis, isInverted);
                        break;
                    case 4:
                        location = helper_4.getPoint(point.xValue, point.lowerQuartile, xAxis, yAxis, isInverted);
                        break;
                    default: {
                        location = helper_4.getPoint(point.xValue, point.outliers[labelIndex - 5], xAxis, yAxis, isInverted);
                        this.markerHeight = series.marker.height / 2;
                        break;
                    }
                }
                location.x = point.regions[0].x + (point.regions[0].width / 2);
            }
            else if (labelIndex === 0 || labelIndex === 1) {
                location = new helper_1.ChartLocation(point.symbolLocations[0].x, point.symbolLocations[0].y);
            }
            else if ((labelIndex === 2 || labelIndex === 3) && series.type === 'Candle') {
                location = new helper_1.ChartLocation(point.symbolLocations[1].x, point.symbolLocations[1].y);
            }
            else Iif (isInverted) {
                location = { x: labelRegion.x + (labelRegion.width) / 2, y: labelRegion.y };
            }
            else {
                location = { x: labelRegion.x + labelRegion.width, y: labelRegion.y + (labelRegion.height) / 2 };
            }
            if (labelIndex > 1 && series.type === 'HiloOpenClose') {
                Iif (series.chart.requireInvertedAxis) {
                    var height = labelRegion.height;
                    location.y = labelRegion.y + height / 2 + 2 * (labelIndex === 2 ? 1 : -1);
                }
                else {
                    var width = labelRegion.width;
                    location.x = labelRegion.x + width / 2 + 2 * (labelIndex === 2 ? 1 : -1);
                }
            }
            return location;
        };
        DataLabel.prototype.calculateRectPosition = function (labelLocation, rect, isMinus, position, series, textSize, labelIndex, point) {
            if (series.chart.chartAreaType === 'PolarRadar') {
                return null;
            }
            var padding = 5;
            var margin = this.margin;
            var textLength = !this.inverted ? textSize.height : textSize.width;
            var extraSpace = this.borderWidth + textLength / 2 + padding;
            if (series.type.indexOf('Stacking') > -1) {
                position = position === 'Outer' ? 'Top' : position;
            }
            else if (series.type.indexOf('Range') > -1) {
                position = (position === 'Outer' || position === 'Top') ? position : 'Auto';
            }
            else if (series.type === 'Waterfall') {
                position = position === 'Auto' ? 'Middle' : position;
            }
            switch (position) {
                case 'Bottom':
                    labelLocation = !this.inverted ?
                        isMinus ? (labelLocation - rect.height + extraSpace + margin.top) :
                            (labelLocation + rect.height - extraSpace - margin.bottom) :
                        isMinus ? (labelLocation + rect.width - extraSpace - margin.left) :
                            (labelLocation - rect.width + extraSpace + margin.right);
                    break;
                case 'Middle':
                    labelLocation = labelLocation = !this.inverted ?
                        (isMinus ? labelLocation - (rect.height / 2) : labelLocation + (rect.height / 2)) :
                        (isMinus ? labelLocation + (rect.width / 2) : labelLocation - (rect.width / 2));
                    break;
                case 'Auto':
                    labelLocation = this.calculateRectActualPosition(labelLocation, rect, isMinus, series, textSize, labelIndex, point);
                    break;
                default:
                    extraSpace += this.errorHeight;
                    labelLocation = this.calculateTopAndOuterPosition(labelLocation, rect, position, series, labelIndex, extraSpace, isMinus);
                    break;
            }
            var check = !this.inverted ? (labelLocation < rect.y || labelLocation > rect.y + rect.height) :
                (labelLocation < rect.x || labelLocation > rect.x + rect.width);
            this.fontBackground = check ?
                (this.fontBackground === 'transparent' ? this.chartBackground : this.fontBackground)
                : this.fontBackground === 'transparent' ? (point.color || series.interior) : this.fontBackground;
            return labelLocation;
        };
        DataLabel.prototype.calculatePathPosition = function (labelLocation, position, series, point, size, labelIndex) {
            var padding = 5;
            if ((series.type.indexOf('Area') > -1 && series.type !== 'RangeArea')
                && this.yAxisInversed && series.marker.dataLabel.position !== 'Auto') {
                position = position === 'Top' ? 'Bottom' : position === 'Bottom' ? 'Top' : position;
            }
            this.fontBackground = this.fontBackground === 'transparent' ? this.chartBackground : this.fontBackground;
            switch (position) {
                case 'Top':
                case 'Outer':
                    labelLocation = labelLocation - this.markerHeight - this.borderWidth - size.height / 2 - this.margin.bottom - padding -
                        this.errorHeight;
                    break;
                case 'Bottom':
                    labelLocation = labelLocation + this.markerHeight + this.borderWidth + size.height / 2 + this.margin.top + padding +
                        this.errorHeight;
                    break;
                case 'Auto':
                    labelLocation = this.calculatePathActualPosition(labelLocation, this.markerHeight, series, point, size, labelIndex);
                    break;
            }
            return labelLocation;
        };
        DataLabel.prototype.isDataLabelShape = function (style) {
            this.isShape = (style.color !== 'transparent' || style.border.width > 0);
            this.borderWidth = style.border.width;
            if (!this.isShape) {
                this.margin = { left: 0, right: 0, bottom: 0, top: 0 };
            }
        };
        DataLabel.prototype.calculateRectActualPosition = function (labelLocation, rect, isMinus, series, size, labelIndex, point) {
            var location;
            var labelRect;
            var isOverLap = true;
            var position = 0;
            var collection = this.chart.dataLabelCollections;
            var finalPosition = series.type.indexOf('Range') !== -1 || series.type === 'Hilo' ? 2 : 4;
            while (isOverLap && position < finalPosition) {
                location = this.calculateRectPosition(labelLocation, rect, isMinus, this.getPosition(position), series, size, labelIndex, point);
                if (!this.inverted) {
                    labelRect = helper_2.calculateRect(new helper_1.ChartLocation(this.locationX, location), size, this.margin);
                    isOverLap = labelRect.y < 0 || helper_1.isCollide(labelRect, collection, series.clipRect) || labelRect.y > series.clipRect.height;
                }
                else {
                    labelRect = helper_2.calculateRect(new helper_1.ChartLocation(location, this.locationY), size, this.margin);
                    isOverLap = labelRect.x < 0 || helper_1.isCollide(labelRect, collection, series.clipRect) ||
                        labelRect.x + labelRect.width > series.clipRect.width;
                }
                position++;
            }
            return location;
        };
        DataLabel.prototype.calculateAlignment = function (value, labelLocation, alignment, isMinus) {
            switch (alignment) {
                case 'Far':
                    labelLocation = !this.inverted ? (isMinus ? labelLocation + value : labelLocation - value) :
                        (isMinus ? labelLocation - value : labelLocation + value);
                    break;
                case 'Near':
                    labelLocation = !this.inverted ? (isMinus ? labelLocation - value : labelLocation + value) :
                        (isMinus ? labelLocation + value : labelLocation - value);
                    break;
                case 'Center':
                    labelLocation = labelLocation;
                    break;
            }
            return labelLocation;
        };
        DataLabel.prototype.calculateTopAndOuterPosition = function (location, rect, position, series, index, extraSpace, isMinus) {
            var margin = this.margin;
            var top;
            switch (series.type) {
                case 'RangeColumn':
                case 'RangeArea':
                case 'Hilo':
                    top = (index === 0 && !this.yAxisInversed) || (index === 1 && this.yAxisInversed);
                    location = this.updateLabelLocation(position, location, extraSpace, margin, rect, top);
                    break;
                case 'Candle':
                    top = (index === 0 || index === 2) && !this.yAxisInversed
                        || (index === 1 || index === 3) && this.yAxisInversed;
                    location = this.updateLabelLocation(position, location, extraSpace, margin, rect, top, index > 1);
                    break;
                case 'HiloOpenClose':
                    if (index <= 1) {
                        top = (index === 0 && !this.yAxisInversed) || (index === 1 && this.yAxisInversed);
                        location = this.updateLabelLocation(position, location, extraSpace, margin, rect, top);
                    }
                    else {
                        Iif (this.yAxisInversed) {
                            location = !this.inverted ? location + extraSpace + margin.top : location - extraSpace - margin.right;
                        }
                        else {
                            location = !this.inverted ? location - extraSpace - margin.bottom : location + extraSpace + margin.left;
                        }
                    }
                    break;
                default:
                    if ((isMinus && position === 'Top') || (!isMinus && position === 'Outer')) {
                        location = !this.inverted ? location - extraSpace - margin.bottom : location + extraSpace + margin.left;
                    }
                    else {
                        location = !this.inverted ? location + extraSpace + margin.top : location - extraSpace - margin.right;
                    }
                    break;
            }
            return location;
        };
        DataLabel.prototype.updateLabelLocation = function (position, location, extraSpace, margin, rect, top, inside) {
            if (inside === void 0) { inside = false; }
            if (!this.inverted) {
                if (top) {
                    location = (position === 'Outer' && !inside) ? location - extraSpace - margin.bottom : location + extraSpace + margin.top;
                }
                else {
                    location = (position === 'Outer' && !inside) ? location + rect.height + extraSpace + margin.top :
                        location + rect.height - extraSpace - margin.bottom;
                }
            }
            else {
                if (top) {
                    location = (position === 'Outer' && !inside) ? location + extraSpace + margin.left : location - extraSpace - margin.right;
                }
                else {
                    location = (position === 'Outer' && !inside) ? location - rect.width - extraSpace - margin.right :
                        location - rect.width + extraSpace + margin.left;
                }
            }
            return location;
        };
        DataLabel.prototype.calculatePathActualPosition = function (y, markerSize, series, point, size, labelIndex) {
            var points = series.points;
            var index = point.index;
            var yValue = points[index].yValue;
            var position;
            var nextPoint = points.length - 1 > index ? points[index + 1] : null;
            var previousPoint = index > 0 ? points[index - 1] : null;
            var yLocation;
            var isOverLap = true;
            var labelRect;
            var isBottom;
            var positionIndex;
            var collection = this.chart.dataLabelCollections;
            if (series.type === 'Bubble') {
                position = 'Top';
            }
            else if (series.type.indexOf('Step') > -1) {
                position = 'Top';
                if (index) {
                    position = (!previousPoint || !previousPoint.visible || (yValue > previousPoint.yValue !== this.yAxisInversed)
                        || yValue === previousPoint.yValue) ? 'Top' : 'Bottom';
                }
            }
            else if (series.type === 'BoxAndWhisker') {
                if (labelIndex === 1 || labelIndex === 3 || labelIndex > 4) {
                    position = series.yAxis.isInversed ? 'Bottom' : 'Top';
                }
                else if (labelIndex === 2 || labelIndex === 4) {
                    position = series.yAxis.isInversed ? 'Top' : 'Bottom';
                }
                else {
                    isOverLap = false;
                    position = 'Middle';
                    yLocation = this.calculatePathPosition(y, position, series, point, size, labelIndex);
                }
            }
            else {
                if (index === 0) {
                    position = (!nextPoint || !nextPoint.visible || yValue > nextPoint.yValue ||
                        (yValue < nextPoint.yValue && this.yAxisInversed)) ? 'Top' : 'Bottom';
                }
                else if (index === points.length - 1) {
                    position = (!previousPoint || !previousPoint.visible || yValue > previousPoint.yValue ||
                        (yValue < previousPoint.yValue && this.yAxisInversed)) ? 'Top' : 'Bottom';
                }
                else {
                    if (!nextPoint.visible && !(previousPoint && previousPoint.visible)) {
                        position = 'Top';
                    }
                    else if (!nextPoint.visible || !previousPoint) {
                        position = (nextPoint.yValue > yValue || (previousPoint && previousPoint.yValue > yValue)) ?
                            'Bottom' : 'Top';
                    }
                    else {
                        var slope = (nextPoint.yValue - previousPoint.yValue) / 2;
                        var intersectY = (slope * index) + (nextPoint.yValue - (slope * (index + 1)));
                        position = !this.yAxisInversed ? intersectY < yValue ? 'Top' : 'Bottom' :
                            intersectY < yValue ? 'Bottom' : 'Top';
                    }
                }
            }
            isBottom = position === 'Bottom';
            positionIndex = ['Outer', 'Top', 'Bottom', 'Middle', 'Auto'].indexOf(position);
            while (isOverLap && positionIndex < 4) {
                yLocation = this.calculatePathPosition(y, this.getPosition(positionIndex), series, point, size, labelIndex);
                labelRect = helper_2.calculateRect(new helper_1.ChartLocation(this.locationX, yLocation), size, this.margin);
                isOverLap = labelRect.y < 0 || helper_1.isCollide(labelRect, collection, series.clipRect)
                    || (labelRect.y + labelRect.height) > series.clipRect.height;
                positionIndex = isBottom ? positionIndex - 1 : positionIndex + 1;
                isBottom = false;
            }
            return yLocation;
        };
        DataLabel.prototype.doDataLabelAnimation = function (series, element) {
            var shapeElements = series.shapeElement.childNodes;
            var textNode = series.textElement.childNodes;
            var delay = series.animation.delay + series.animation.duration;
            var location;
            var length = element ? 1 : textNode.length;
            for (var i = 0; i < length; i++) {
                if (element) {
                    element.style.visibility = 'hidden';
                    helper_3.templateAnimate(element, delay, 200, 'ZoomIn');
                }
                else {
                    location = new helper_1.ChartLocation((+textNode[i].getAttribute('x')) + ((+textNode[i].getAttribute('width')) / 2), (+textNode[i].getAttribute('y')) + ((+textNode[i].getAttribute('height')) / 2));
                    helper_1.markerAnimate(textNode[i], delay, 200, series, null, location, true);
                    if (shapeElements[i]) {
                        location = new helper_1.ChartLocation((+shapeElements[i].getAttribute('x')) + ((+shapeElements[i].getAttribute('width')) / 2), (+shapeElements[i].getAttribute('y')) + ((+shapeElements[i].getAttribute('height')) / 2));
                        helper_1.markerAnimate(shapeElements[i], delay, 200, series, null, location, true);
                    }
                }
            }
        };
        DataLabel.prototype.getPosition = function (index) {
            return (['Outer', 'Top', 'Bottom', 'Middle', 'Auto'][index]);
        };
        DataLabel.prototype.getModuleName = function () {
            return 'DataLabel';
        };
        DataLabel.prototype.destroy = function (chart) {
        };
        return DataLabel;
    }());
    exports.DataLabel = DataLabel;
});