all files / chart/axis/ multi-level-labels.js

94.63% Statements 317/335
87.8% Branches 288/328
100% Functions 22/22
94.63% Lines 317/335
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   97× 97× 97× 97× 97× 97× 97× 97×   97×     97×   228× 228× 228× 228× 228× 228× 228× 228× 228× 228× 228× 390× 1128× 1128× 1128× 1128×   1128×         1128× 1128× 1128× 10×   1128×       390× 390×   228×   228× 94× 94×     134× 134×     67× 67× 67× 67× 67× 67× 67×   67× 67× 67× 67× 67× 67× 67× 67× 67× 67× 67× 67× 67×   67×   67× 67× 104× 104× 104× 310× 310× 310× 310× 310× 310× 310× 310× 310× 310× 310× 310× 310×       310× 280× 280×   30× 18× 18×   18×     12× 12×   310×   310× 310× 310× 37×     28×                       22×                   28×     310×     310×   310×   310×         310× 307× 307× 306× 306×     310× 310×         67× 67×     307× 307× 307× 307× 307× 307× 307× 307× 307× 307× 307× 307×     307× 307×       275× 275× 275×   275× 275×   275× 275× 275×     12×         12× 12×       12×   19× 10× 10× 10×       19×         15×                   19×   307×   47× 47× 47× 47× 47× 47× 47×   47× 47× 47× 47× 47× 47× 47× 47× 47× 47× 47× 47× 47× 47×   47×   47× 91× 91× 91× 254× 254× 254× 254× 254× 254× 254× 254× 254×   254× 254× 254×   254× 254× 52×         202×     254× 248×         254×   254× 254×     254×     254× 52×   254×   254× 251× 251× 251× 251×     254× 254×         47× 47×     251× 251× 251× 251× 251× 251× 251× 251× 251× 251×     251×   251× 251×       209× 209×   209× 209× 209×   12× 12×       12×   30× 15× 15× 15×     15× 15× 15×   30× 24×                                 30×   251×   114×       114× 114×                     557× 557× 557× 557×   564×       564× 564×                           41538×          
define(["require", "exports", "@syncfusion/ej2-base", "../../common/utils/helper", "../../common/utils/helper", "@syncfusion/ej2-svg-base", "../../common/model/constants"], function (require, exports, ej2_base_1, helper_1, helper_2, ej2_svg_base_1, constants_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var MultiLevelLabel = (function () {
        function MultiLevelLabel(chart) {
            this.xAxisPrevHeight = [];
            this.xAxisMultiLabelHeight = [];
            this.yAxisPrevHeight = [];
            this.yAxisMultiLabelHeight = [];
            this.multiLevelLabelRectXRegion = [];
            this.xLabelCollection = [];
            this.chart = chart;
            this.addEventListener();
        }
        MultiLevelLabel.prototype.addEventListener = function () {
            Iif (this.chart.isDestroyed) {
                return;
            }
            this.chart.on('click', this.click, this);
        };
        MultiLevelLabel.prototype.getMultilevelLabelsHeight = function (axis) {
            var _this = this;
            var value = 0;
            var multiLevelLabelsHeight = [];
            var prevHeight = [];
            var isVertical = axis.orientation === 'Vertical';
            var axisValue = isVertical ? axis.rect.height : axis.rect.width;
            var labelSize;
            var height;
            var padding = 10;
            var gap;
            axis.multiLevelLabels.map(function (multiLevel, index) {
                multiLevel.categories.map(function (categoryLabel, i) {
                    Eif (categoryLabel.text !== '' && categoryLabel.start !== null && categoryLabel.end !== null) {
                        labelSize = ej2_svg_base_1.measureText(categoryLabel.text, multiLevel.textStyle, _this.chart.themeStyle.axisLabelFont);
                        height = isVertical ? labelSize.width : labelSize.height;
                        height += 2 * multiLevel.border.width +
                            (multiLevel.border.type === 'CurlyBrace' ? padding : 0);
                        gap = (categoryLabel.maximumTextWidth !== null) ? categoryLabel.maximumTextWidth :
                            (helper_2.valueToCoefficient(typeof categoryLabel.end === 'string' ? Number(new Date(categoryLabel.end)) :
                                categoryLabel.end, axis) * axisValue) -
                                (helper_2.valueToCoefficient(typeof categoryLabel.start === 'string' ? Number(new Date(categoryLabel.start)) :
                                    categoryLabel.start, axis) * axisValue);
                        var len = axis.multiLevelLabels[index].categories.length;
                        gap = ((i === 0 || i === len - 1) && axis.labelPlacement === 'OnTicks' && axis.edgeLabelPlacement === 'Shift') ? gap / 2 : gap;
                        if ((labelSize.width > gap - padding) && (_this.chart.enableRtl ? gap < 0 : gap > 0) && (multiLevel.overflow === 'Wrap') && !isVertical) {
                            height = (height * (helper_1.textWrap(categoryLabel.text, gap - padding, multiLevel.textStyle, _this.chart.enableRtl, null, null, _this.chart.themeStyle.axisLabelFont).length));
                        }
                        multiLevelLabelsHeight[index] = !multiLevelLabelsHeight[index] ? height :
                            ((multiLevelLabelsHeight[index] < height) ? height : multiLevelLabelsHeight[index]);
                    }
                });
                prevHeight[index] = value;
                value += multiLevelLabelsHeight[index] ? (multiLevelLabelsHeight[index] + padding) : 0;
            });
            axis.multiLevelLabelHeight = value + ((axis.title !== '' || (this.chart.legendModule && this.chart.legendSettings.visible))
                ? padding / 2 : 0);
            if (isVertical) {
                this.yAxisMultiLabelHeight = multiLevelLabelsHeight;
                this.yAxisPrevHeight = prevHeight;
            }
            else {
                this.xAxisMultiLabelHeight = multiLevelLabelsHeight;
                this.xAxisPrevHeight = prevHeight;
            }
        };
        MultiLevelLabel.prototype.renderXAxisMultiLevelLabels = function (axis, index, parent, axisRect) {
            var _this = this;
            var x;
            var y;
            var padding = 10;
            var startX;
            var pointIndex;
            var startY = (axis.labelPosition === axis.tickPosition ? axis.majorTickLines.height : 0) +
                (axis.maxLabelSize.height) + padding;
            var endX;
            var pathRect = '';
            var start;
            var end;
            var labelSize;
            var isOutside = axis.labelPosition === 'Outside';
            var gap;
            var anchor;
            var isInversed = axis.isAxisInverse;
            var argsData;
            var opposedPosition = axis.isAxisOpposedPosition;
            var len;
            var scrollBarHeight = axis.scrollbarSettings.enable || (isOutside && ej2_base_1.isNullOrUndefined(axis.crossesAt)) ?
                axis.scrollBarHeight : 0;
            var clipY = ((opposedPosition && !isOutside) || (!opposedPosition && isOutside)) ?
                (axisRect.y + startY - axis.majorTickLines.width) : (axisRect.y - startY - axis.multiLevelLabelHeight);
            this.createClipRect(axisRect.x - axis.majorTickLines.width, clipY + scrollBarHeight, axis.multiLevelLabelHeight + padding, axisRect.width + 2 * axis.majorTickLines.width, this.chart.element.id + '_XAxis_Clippath_' + index, this.chart.element.id + 'XAxisMultiLevelLabel' + index);
            axis.multiLevelLabels.map(function (multiLevel, level) {
                pointIndex = 0;
                _this.labelElement = _this.chart.renderer.createGroup({ id: _this.chart.element.id + index + '_MultiLevelLabel' + level });
                multiLevel.categories.map(function (categoryLabel, i) {
                    len = multiLevel.categories.length;
                    pathRect = '';
                    start = typeof categoryLabel.start === 'string' ? Number(new Date(categoryLabel.start)) : categoryLabel.start;
                    end = typeof categoryLabel.end === 'string' ? Number(new Date(categoryLabel.end)) : categoryLabel.end;
                    argsData = _this.triggerMultiLabelRender(axis, categoryLabel.text, axis.multiLevelLabels[level].textStyle, axis.multiLevelLabels[level].alignment, categoryLabel.customAttributes);
                    Eif (!argsData.cancel) {
                        startX = helper_2.valueToCoefficient(start, axis) * axisRect.width;
                        endX = helper_2.valueToCoefficient(end, axis) * axisRect.width;
                        endX = isInversed ? [startX, startX = endX][0] : endX;
                        labelSize = ej2_svg_base_1.measureText(argsData.text, argsData.textStyle, _this.chart.themeStyle.axisLabelFont);
                        gap = ((categoryLabel.maximumTextWidth === null) ? endX - startX : categoryLabel.maximumTextWidth) - padding;
                        x = startX + axisRect.x + padding;
                        y = (((opposedPosition && !isOutside) || (!opposedPosition && isOutside)) ? (startY + axisRect.y +
                            labelSize.height / 2 + padding + _this.xAxisPrevHeight[level]) :
                            (axisRect.y - startY + labelSize.height / 2 - _this.xAxisMultiLabelHeight[level] -
                                _this.xAxisPrevHeight[level])) + scrollBarHeight;
                        if (argsData.alignment === 'Center') {
                            x += (endX - startX - padding) / 2;
                            anchor = 'middle';
                        }
                        else if (argsData.alignment === 'Far') {
                            x = x + (endX - startX - padding) - multiLevel.border.width / 2;
                            if (axis.labelPlacement === 'OnTicks' && (i === 0 || i === len - 1)) {
                                x += (endX - startX - padding) / 2;
                                x = x - labelSize.width / 2;
                            }
                            anchor = 'end';
                        }
                        else {
                            anchor = 'start';
                            x += multiLevel.border.width / 2;
                        }
                        y = multiLevel.border.type === 'CurlyBrace' ?
                            (((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) ? y + padding : y - padding / 2) : y;
                        var options = new ej2_svg_base_1.TextOption(_this.chart.element.id + index + '_Axis_MultiLevelLabel_Level_' + level + '_Text_' + i, x, y, anchor, argsData.text);
                        Eif (multiLevel.overflow !== 'None') {
                            if (axis.edgeLabelPlacement && axis.labelPlacement === 'OnTicks') {
                                switch (axis.edgeLabelPlacement) {
                                    case 'None':
                                        break;
                                    case 'Shift':
                                        if ((i === 0 || (isInversed && i === len - 1))) {
                                            Iif (argsData.alignment === 'Center' && ((options.x < axisRect.x + padding) || (options.x - labelSize.width / 2)) < axis.rect.x) {
                                                options.x += axisRect.x / 2;
                                                if ((options.x / 2) < axisRect.x) {
                                                    options.x = axisRect.x + padding / 2;
                                                    options.anchor = 'start';
                                                }
                                            }
                                            else Iif (argsData.alignment === 'Far' && ((options.x < axisRect.x + padding) || (options.x > axisRect.x + padding))) {
                                                options.x += labelSize.width / 2 - gap / 2;
                                            }
                                            else Iif (argsData.alignment === 'Near' && ((options.x < axisRect.x + padding) || (options.x > axisRect.x + padding))) {
                                                options.x = axisRect.x + padding;
                                            }
                                            gap = gap / 2;
                                        }
                                        else if ((i === len - 1 || (isInversed && i === 0))) {
                                            Iif (argsData.alignment === 'Center' && (options.x) > axisRect.x + axisRect.width) {
                                                options.x -= padding;
                                                if (options.x > axisRect.width) {
                                                    options.x = axisRect.width + axisRect.x;
                                                    options.anchor = 'end';
                                                }
                                            }
                                            else Iif (argsData.alignment === 'Far') {
                                                options.x = axisRect.width + axisRect.x;
                                            }
                                            gap = gap / 2;
                                        }
                                        break;
                                }
                            }
                            options.text = (multiLevel.overflow === 'Wrap') ?
                                helper_1.textWrap(argsData.text, gap, argsData.textStyle, _this.chart.enableRtl, null, null, _this.chart.themeStyle.axisLabelFont) :
                                helper_2.textTrim(gap, argsData.text, argsData.textStyle, _this.chart.enableRtl, _this.chart.themeStyle.axisLabelFont);
                            options.x = options.x - padding / 2;
                        }
                        helper_2.textElement(_this.chart.renderer, options, argsData.textStyle, argsData.textStyle.color ||
                            _this.chart.themeStyle.axisLabelFont.color, _this.labelElement, false, _this.chart.redraw, true, null, null, null, null, null, _this.chart.enableCanvas, null, _this.chart.themeStyle.axisLabelFont);
                        Iif (_this.chart.enableCanvas) {
                            var textSize = ej2_svg_base_1.measureText(argsData.text, argsData.textStyle, _this.chart.themeStyle.axisLabelFont);
                            _this.multiLevelLabelRectXRegion.push(new ej2_svg_base_1.Rect(options.x, options.y, textSize.width, textSize.height));
                            _this.xLabelCollection.push(options);
                        }
                        if (multiLevel.border.width > 0 && multiLevel.border.type !== 'WithoutBorder') {
                            pathRect = _this.renderXAxisLabelBorder(level, endX - startX - padding, axis, startX, startY, labelSize, options, axisRect, argsData.alignment, pathRect, isOutside, opposedPosition, pointIndex);
                            if (pathRect !== '') {
                                _this.createBorderElement(level, index, axis, pathRect, pointIndex);
                                pointIndex++;
                            }
                        }
                        Eif (!_this.chart.enableCanvas) {
                            _this.multiElements.appendChild(_this.labelElement);
                        }
                    }
                });
            });
            Eif (!this.chart.enableCanvas) {
                parent.appendChild(this.multiElements);
            }
        };
        MultiLevelLabel.prototype.renderXAxisLabelBorder = function (labelIndex, gap, axis, startX, startY, labelSize, textOptions, axisRect, alignment, path, isOutside, opposedPosition, categoryIndex) {
            var padding = 10;
            var padding1;
            var padding2;
            var value;
            var value1;
            var groupLabel = axis.multiLevelLabels[labelIndex];
            var categoryType = groupLabel.categories[categoryIndex].type;
            var width = gap + padding;
            var height = this.xAxisMultiLabelHeight[labelIndex] + padding;
            var scrollBarHeight = axis.labelPosition === 'Outside' ? axis.scrollBarHeight : 0;
            var x = startX + axisRect.x;
            var y = ((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) ? (startY + axisRect.y +
                this.xAxisPrevHeight[labelIndex] + scrollBarHeight) : (axisRect.y - startY -
                this.xAxisPrevHeight[labelIndex] - scrollBarHeight);
            var borderType = categoryType ? categoryType : groupLabel.border.type;
            switch (borderType) {
                case 'WithoutTopandBottomBorder':
                case 'Rectangle':
                case 'WithoutTopBorder': {
                    var len = axis.multiLevelLabels[labelIndex].categories.length;
                    var lastX = (categoryIndex === len - 1 && (x + width > axisRect.width)) ? axisRect.width + axisRect.x : x + width;
                    var initialX = (categoryIndex === 0 &&
                        axis.multiLevelLabels[labelIndex].categories[0].start <= 0) ? axisRect.x : x;
                    height = ((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) ? height : -height;
                    path += 'M ' + initialX + ' ' + y + ' L ' + initialX + ' ' + (y + height) + ' M ' + (lastX) + ' '
                        + y + ' L ' + (lastX) + ' ' + (y + height);
                    path += (borderType !== 'WithoutTopandBottomBorder') ? (' L' + ' ' + (initialX) + ' ' + (y + height) + ' ') : ' ';
                    path += (borderType === 'Rectangle') ? ('M ' + initialX + ' ' + y + ' L ' + (lastX) + ' ' + y) : ' ';
                    break;
                }
                case 'Brace':
                    if (alignment === 'Near') {
                        value = textOptions.x;
                        value1 = textOptions.x + labelSize.width + 2;
                    }
                    else if (alignment === 'Center') {
                        value = textOptions.x - labelSize.width / 2 - 2;
                        value1 = textOptions.x + labelSize.width / 2 + 2;
                    }
                    else {
                        value = textOptions.x - labelSize.width - 2;
                        value1 = textOptions.x;
                    }
                    height = ((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) ? height : -height;
                    path += 'M ' + x + ' ' + y + ' L ' + x + ' ' + (y + height / 2) +
                        ' M ' + x + ' ' + (y + height / 2) + ' L ' + (value - 2) + ' ' + (y + height / 2) +
                        ' M ' + (value1) + ' ' + (y + height / 2) + ' L ' + (x + width) + ' ' + (y + height / 2) +
                        ' M ' + (x + width) + ' ' + (y + height / 2) + ' L ' + (x + width) + ' ' + (y);
                    break;
                case 'CurlyBrace':
                    if ((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) {
                        padding = 10;
                        padding1 = 15;
                        padding2 = 5;
                    }
                    else {
                        padding = -10;
                        padding1 = -15;
                        padding2 = -5;
                    }
                    if (alignment === 'Center') {
                        path += 'M ' + x + ' ' + y + ' C ' + x + ' ' + y + ' ' + (x + 5) + ' ' + (y + padding) + ' ' + (x + 10) + ' ' +
                            (y + padding) + ' L ' + (x + width / 2 - 5) + ' ' + (y + padding) + ' L ' + (x + width / 2) + ' ' + (y + padding1) +
                            ' L ' + (x + width / 2 + 5) + ' ' + (y + padding) + ' L ' + (x + width - 10) + ' ' + (y + padding) + ' C ' +
                            (x + width - 10) + ' ' + (y + padding) + ' ' + (x + width) + ' ' + (y + padding2) + ' ' + (x + width) + ' ' + (y);
                    }
                    else if (alignment === 'Near') {
                        path += 'M ' + x + ' ' + y + ' C ' + x + ' ' + y + ' ' + (x + 5) + ' ' + (y + padding) + ' ' + (x + 10) + ' ' +
                            (y + padding) + ' L ' + (x + 15) + ' ' + (y + padding1) + ' L ' + (x + 20) + ' ' + (y + padding) + ' L ' +
                            (x + width - 10) + ' ' + (y + padding) + ' C ' + (x + width - 10) + ' ' + (y + padding) + ' ' + (x + width) + ' '
                            + (y + padding2) + ' ' + (x + width) + ' ' + (y);
                    }
                    else {
                        path += 'M ' + x + ' ' + y + ' C ' + x + ' ' + y + ' ' + (x + 5) + ' ' + (y + padding) + ' ' + (x + 10) + ' ' +
                            (y + padding) + ' L ' + (x + width - 20) + ' ' + (y + padding) + ' L ' + (x + width - 15) + ' ' + (y + padding1) +
                            ' L ' + (x + width - 10) + ' ' + (y + padding) + ' L ' + (x + width - 10) + ' ' + (y + padding) + ' C '
                            + (x + width - 10) + ' ' + (y + padding) + ' ' + (x + width) + ' ' + (y + padding2) + ' ' + (x + width) + ' ' + (y);
                    }
                    break;
            }
            return path;
        };
        MultiLevelLabel.prototype.renderYAxisMultiLevelLabels = function (axis, index, parent, rect) {
            var _this = this;
            var labelSize;
            var isOutside = axis.labelPosition === 'Outside';
            var x;
            var y;
            var padding = 10;
            var startX = (axis.tickPosition === axis.labelPosition ? axis.majorTickLines.height : 0) +
                (axis.maxLabelSize.width) + padding;
            var startY;
            var path = '';
            var endY;
            var argsData;
            var pointIndex;
            var isInversed = axis.isAxisInverse;
            var start;
            var end;
            var gap;
            var anchor = 'middle';
            var opposedPosition = axis.isAxisOpposedPosition;
            var scrollBarHeight = isOutside && ej2_base_1.isNullOrUndefined(axis.crossesAt) ? axis.scrollBarHeight : 0;
            scrollBarHeight = scrollBarHeight * (opposedPosition ? 1 : -1);
            var clipX = ((opposedPosition && !isOutside) || (!opposedPosition && isOutside)) ?
                (rect.x - axis.multiLevelLabelHeight - startX - padding) : (rect.x + startX);
            this.createClipRect(clipX + scrollBarHeight, rect.y - axis.majorTickLines.width, rect.height + 2 * axis.majorTickLines.width, axis.multiLevelLabelHeight + padding, this.chart.element.id + '_YAxis_Clippath_' + index, this.chart.element.id
                + 'YAxisMultiLevelLabel' + index);
            axis.multiLevelLabels.map(function (multiLevel, level) {
                _this.labelElement = _this.chart.renderer.createGroup({ id: _this.chart.element.id + index + '_MultiLevelLabel' + level });
                pointIndex = 0;
                multiLevel.categories.map(function (categoryLabel, i) {
                    path = '';
                    end = typeof categoryLabel.end === 'string' ? Number(new Date(categoryLabel.end)) : categoryLabel.end;
                    start = typeof categoryLabel.start === 'string' ? Number(new Date(categoryLabel.start)) : categoryLabel.start;
                    startY = helper_2.valueToCoefficient((start), axis) * (rect.height);
                    endY = helper_2.valueToCoefficient((end), axis) * (rect.height);
                    endY = isInversed ? [startY, startY = endY][0] : endY;
                    argsData = _this.triggerMultiLabelRender(axis, categoryLabel.text, multiLevel.textStyle, multiLevel.alignment, categoryLabel.customAttributes);
                    Eif (!argsData.cancel) {
                        var maximumWidth = ((categoryLabel.maximumTextWidth === null ?
                            (_this.yAxisMultiLabelHeight[level] / 2) : categoryLabel.maximumTextWidth / 2));
                        labelSize = ej2_svg_base_1.measureText(argsData.text, argsData.textStyle, _this.chart.themeStyle.axisLabelFont);
                        gap = endY - startY;
                        x = rect.x - startX - _this.yAxisPrevHeight[level] -
                            (maximumWidth) - padding / 2;
                        y = rect.height + rect.y - startY - (gap / 2);
                        if (opposedPosition) {
                            x = isOutside ? rect.x + startX + padding / 2 + (maximumWidth) +
                                _this.yAxisPrevHeight[level] + scrollBarHeight : rect.x - startX - (maximumWidth) -
                                _this.yAxisPrevHeight[level] - padding / 2;
                        }
                        else {
                            x = isOutside ? x + scrollBarHeight : rect.x + startX + padding / 2 + (maximumWidth) +
                                _this.yAxisPrevHeight[level];
                        }
                        if (argsData.alignment === 'Center') {
                            y += labelSize.height / 4;
                        }
                        else if (argsData.alignment === 'Far') {
                            y += gap / 2 - labelSize.height / 2;
                        }
                        else {
                            y = y - gap / 2 + labelSize.height;
                        }
                        x = multiLevel.border.type === 'CurlyBrace' ? (((!opposedPosition && isOutside) ||
                            (opposedPosition && !isOutside)) ? x - padding : x + padding) : x;
                        var options = new ej2_svg_base_1.TextOption(_this.chart.element.id + index + '_Axis_MultiLevelLabel_Level_' + level + '_Text_' + i, x, y, anchor, argsData.text);
                        options.text = (multiLevel.overflow === 'Trim') ?
                            helper_2.textTrim((categoryLabel.maximumTextWidth === null ? _this.yAxisMultiLabelHeight[level] :
                                categoryLabel.maximumTextWidth), argsData.text, argsData.textStyle, _this.chart.enableRtl, _this.chart.themeStyle.axisLabelFont) : options.text;
                        options.text = (multiLevel.overflow === 'Wrap') ?
                            helper_1.textWrap(argsData.text, (categoryLabel.maximumTextWidth === null ? _this.yAxisMultiLabelHeight[level] :
                                categoryLabel.maximumTextWidth), argsData.textStyle, _this.chart.enableRtl, null, null, _this.chart.themeStyle.axisLabelFont) : options.text;
                        if (typeof options.text !== 'string' && options.text.length > 1) {
                            options.y -= (padding * options.text.length / 2);
                        }
                        helper_2.textElement(_this.chart.renderer, options, argsData.textStyle, argsData.textStyle.color ||
                            _this.chart.themeStyle.axisLabelFont.color, _this.labelElement, _this.chart.redraw, true, null, null, null, null, null, null, _this.chart.enableCanvas, null, _this.chart.themeStyle.axisLabelFont);
                        if (multiLevel.border.width > 0 && multiLevel.border.type !== 'WithoutBorder') {
                            path = _this.renderYAxisLabelBorder(level, gap, axis, endY, startX, startY, labelSize, options, rect, argsData.alignment, path, isOutside, opposedPosition, pointIndex);
                            Eif (path !== '') {
                                _this.createBorderElement(level, index, axis, path, pointIndex);
                                pointIndex++;
                            }
                        }
                        Eif (!_this.chart.enableCanvas) {
                            _this.multiElements.appendChild(_this.labelElement);
                        }
                    }
                });
            });
            Eif (!this.chart.enableCanvas) {
                parent.appendChild(this.multiElements);
            }
        };
        MultiLevelLabel.prototype.renderYAxisLabelBorder = function (labelIndex, gap, axis, endY, startX, startY, labelSize, textOptions, rect, alignment, path, isOutside, opposedPosition, categoryIndex) {
            var height = endY - startY;
            var padding = 10;
            var padding1;
            var padding2;
            var groupLabel = axis.multiLevelLabels[labelIndex];
            var categoryType = groupLabel.categories[categoryIndex].type;
            var y = rect.y + rect.height - endY;
            var scrollBarHeight = isOutside && ej2_base_1.isNullOrUndefined(axis.crossesAt) ? axis.scrollBarHeight : 0;
            scrollBarHeight = scrollBarHeight * (opposedPosition ? 1 : -1);
            var width = (groupLabel.categories[categoryIndex].maximumTextWidth === null ?
                this.yAxisMultiLabelHeight[labelIndex] :
                (groupLabel.categories[categoryIndex].maximumTextWidth)) + padding;
            var x = (((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) ? rect.x - startX -
                this.yAxisPrevHeight[labelIndex] : rect.x + startX + this.yAxisPrevHeight[labelIndex]) + scrollBarHeight;
            var borderType = categoryType ? categoryType : groupLabel.border.type;
            switch (borderType) {
                case 'WithoutTopandBottomBorder':
                case 'Rectangle':
                case 'WithoutTopBorder':
                    width = ((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) ? -width : width;
                    path += 'M ' + x + ' ' + y + ' L ' + (x + width) + ' ' + y +
                        ' M ' + x + ' ' + (y + height) + ' L ' + (x + width) + ' ' + (y + height);
                    path += (borderType !== 'WithoutTopandBottomBorder') ? (' L' + ' ' + (x + width) + ' ' + y + ' ') : ' ';
                    path += (borderType === 'Rectangle') ? ('M ' + (x) + ' ' + (y + height) + 'L' + ' ' + (x) + ' ' + y + ' ') : ' ';
                    break;
                case 'Brace':
                    width = ((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) ? width : -width;
                    path += 'M ' + (x) + ' ' + y + ' L ' + (x - width / 2) + ' ' + y + ' L ' + (x - width / 2) + ' ' +
                        (textOptions.y - labelSize.height / 2 - 4) + ' M ' + (x - width / 2) + ' ' +
                        (textOptions.y + labelSize.height / 4 + 2) +
                        ' L ' + (x - width / 2) + ' ' + (y + height) + ' L ' + (x) + ' ' + (y + height);
                    break;
                case 'CurlyBrace':
                    if ((!opposedPosition && isOutside) || (opposedPosition && !isOutside)) {
                        padding = -10;
                        padding1 = -15;
                        padding2 = -5;
                    }
                    else {
                        padding = 10;
                        padding1 = 15;
                        padding2 = 5;
                    }
                    if (alignment === 'Center') {
                        path += 'M ' + x + ' ' + y + ' C ' + x + ' ' + y + ' ' + (x + padding) + ' ' + y + ' ' + (x + padding) + ' ' + (y + 10)
                            + ' L ' + (x + padding) + ' ' + (y + (height - 10) / 2) + ' L ' + (x + padding1) + ' ' + (y + (height - 10) / 2 + 5)
                            + ' L ' + (x + padding) + ' ' + (y + (height - 10) / 2 + 10) + ' L ' + (x + padding) + ' ' + (y + (height - 10)) +
                            ' C ' + (x + padding) + ' ' + (y + (height - 10)) + ' ' + (x + padding2) + ' ' + (y + height) + ' '
                            + x + ' ' + (y + height);
                    }
                    else if (alignment === 'Far') {
                        path += 'M ' + x + ' ' + y + ' C ' + x + ' ' + y + ' ' + (x + padding) + ' ' + y + ' ' + (x + padding) + ' ' + (y + 10)
                            + ' L ' + (x + padding) + ' ' + (y + height - 20) + ' ' + ' L ' + (x + padding1) + ' ' + (y + (height - 15)) +
                            ' L ' + (x + padding) + ' ' + (y + (height - 10)) + ' L ' + (x + padding) + ' ' + (y + (height - 10)) +
                            ' C ' + (x + padding) + ' ' + (y + (height - 10)) + ' ' + (x + padding) + ' ' + (y + height) + ' ' + x + ' '
                            + (y + height);
                    }
                    else {
                        path += 'M ' + x + ' ' + y + ' C ' + x + ' ' + y + ' ' + (x + padding) + ' ' + y + ' ' + (x + padding) + ' ' + (y + 10)
                            + ' L ' + (x + padding1) + ' ' + (y + 15) +
                            ' L ' + (x + padding) + ' ' + (y + 20) + ' L ' + (x + padding) + ' ' + (y + (height - 10)) +
                            ' C ' + (x + padding) + ' ' + (y + (height - 10)) + ' ' + (x + padding2) + ' ' + (y + height) + ' ' + x +
                            ' ' + (y + height);
                    }
                    break;
            }
            return path;
        };
        MultiLevelLabel.prototype.createClipRect = function (x, y, height, width, clipId, axisId) {
            this.multiElements = this.chart.renderer.createGroup({
                'id': axisId,
                'clip-path': 'url(#' + clipId + ')'
            });
            Eif (!this.chart.enableCanvas) {
                this.multiElements.appendChild(helper_1.appendClipElement(this.chart.redraw, {
                    'id': clipId,
                    'x': x,
                    'y': y,
                    'width': width,
                    'height': height,
                    'fill': 'white',
                    'stroke-width': 1, 'stroke': 'Gray'
                }, this.chart.renderer));
            }
        };
        MultiLevelLabel.prototype.createBorderElement = function (borderIndex, axisIndex, axis, path, pointIndex) {
            var direction = path;
            var borderElement = this.chart.renderer.drawPath(new ej2_svg_base_1.PathOption(this.chart.element.id + axisIndex + '_Axis_MultiLevelLabel_Rect_' + borderIndex + '_' + pointIndex, 'Transparent', axis.multiLevelLabels[borderIndex].border.width, axis.multiLevelLabels[borderIndex].border.color || this.chart.themeStyle.axisLine, 1, '', path));
            borderElement.style.pointerEvents = 'none';
            helper_1.appendChildElement(this.chart.enableCanvas, this.labelElement, borderElement, this.chart.redraw, true, 'x', 'y', null, direction);
        };
        MultiLevelLabel.prototype.triggerMultiLabelRender = function (axis, text, textStyle, textAlignment, customAttributes) {
            var argsData = {
                cancel: false, name: constants_1.axisMultiLabelRender, axis: axis,
                text: text, textStyle: textStyle, alignment: textAlignment, customAttributes: customAttributes
            };
            this.chart.trigger(constants_1.axisMultiLabelRender, argsData);
            return argsData;
        };
        MultiLevelLabel.prototype.MultiLevelLabelClick = function (labelIndex, axisIndex) {
            var level = parseInt(labelIndex.substr(0, 1), 10);
            var textElement = parseInt(labelIndex.substr(7), 10);
            var chart = this.chart;
            var axis = chart.axisCollections[axisIndex];
            var categories = axis.multiLevelLabels[level].categories;
            var text = categories[textElement].text;
            var start = categories[textElement].start;
            var end = categories[textElement].end;
            var customAttributes = categories[textElement].customAttributes;
            var multilevelclickArgs = {
                axis: axis, level: level, text: text, customAttributes: customAttributes,
                start: start, end: end, name: constants_1.multiLevelLabelClick, cancel: false
            };
            this.chart.trigger(constants_1.multiLevelLabelClick, multilevelclickArgs);
            return multilevelclickArgs;
        };
        MultiLevelLabel.prototype.click = function (event) {
            var targetId = event.target.id;
            var multiLevelID = '_Axis_MultiLevelLabel_Level_';
            var textId;
            var elementId;
            var axisIndex;
            Iif (this.chart.enableCanvas) {
                for (var i = 0; i < this.multiLevelLabelRectXRegion.length; i++) {
                    if (helper_2.withInBounds(event['x'], event['y'], this.multiLevelLabelRectXRegion[i], this.multiLevelLabelRectXRegion[i].width, this.multiLevelLabelRectXRegion[i].height)) {
                        targetId = this.xLabelCollection[i].id;
                    }
                }
            }
            Eif (targetId.indexOf(multiLevelID) > -1) {
                textId = targetId.split(multiLevelID)[1];
                elementId = targetId.split(multiLevelID)[0];
                axisIndex = parseInt(elementId.charAt(elementId.length - 1), 10);
                this.MultiLevelLabelClick(textId, axisIndex);
            }
        };
        MultiLevelLabel.prototype.getModuleName = function () {
            return 'MultiLevelLabel';
        };
        MultiLevelLabel.prototype.destroy = function () {
        };
        return MultiLevelLabel;
    }());
    exports.MultiLevelLabel = MultiLevelLabel;
});