all files / circularchart3d/legend/ legend.js

94.43% Statements 356/377
85.98% Branches 233/271
97.06% Functions 33/34
94.34% Lines 350/371
18 statements, 7 functions, 29 branches Ignored     
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              23×                                                                                                                                 192× 192× 192× 192× 192×   192×     192× 192× 192×   192× 15×   177× 177× 177×   62× 62× 62× 58×   58× 58× 222× 222×                     234× 234× 234× 234× 234× 1699× 1699× 1684×     234×       234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 65×     169×   234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 234× 1684× 1684×       1684× 1684× 1684×   1684× 1684× 1684× 1684× 1684× 1684×   1684× 1684× 1249× 1249×           1249×     1249× 1249×   1249×     435× 12× 12×   435× 435× 196× 196× 12×   196× 196× 196×   435× 435× 435×     435×       234× 234× 169× 169× 169× 169× 169× 169×     65× 65× 65× 65× 65× 65× 30×     234× 234×   234× 209×     25×           1684× 1684× 1684×     18× 18×           18× 18×     36× 36×   36×   169× 169× 169× 169× 169× 169×     169× 169× 24×   169× 169× 169× 169× 169× 169×           169×   1684× 1249×   435× 12×   1672×   1684× 1684×   1684× 1249× 150×   150× 150× 150×     1099× 1099×       435×   435× 435×   203× 170×   203×   203×     232× 232×     1684× 1684× 1684× 1660×     435× 435×           98× 98×             92× 92×   92×                           18× 18×         35×   35× 35× 35× 35× 105× 105× 13× 13×                                     35×     35×     35×                           1315×   192×        
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* istanbul ignore next */ 
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "@syncfusion/ej2-base", "../../common/model/base", "../../common/legend/legend", "@syncfusion/ej2-svg-base", "../../common/utils/helper", "../../common/utils/helper", "../../common/model/constants", "../../common/model/base"], function (require, exports, ej2_base_1, base_1, legend_1, ej2_svg_base_1, helper_1, helper_2, constants_1, base_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var CircularChart3DLegendSettings = (function (_super) {
        __extends(CircularChart3DLegendSettings, _super);
        function CircularChart3DLegendSettings() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property(true)
        ], CircularChart3DLegendSettings.prototype, "visible", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], CircularChart3DLegendSettings.prototype, "height", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], CircularChart3DLegendSettings.prototype, "width", void 0);
        __decorate([
            ej2_base_1.Complex({ x: 0, y: 0 }, base_2.Location)
        ], CircularChart3DLegendSettings.prototype, "location", void 0);
        __decorate([
            ej2_base_1.Property('Auto')
        ], CircularChart3DLegendSettings.prototype, "position", void 0);
        __decorate([
            ej2_base_1.Property(8)
        ], CircularChart3DLegendSettings.prototype, "padding", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], CircularChart3DLegendSettings.prototype, "itemPadding", void 0);
        __decorate([
            ej2_base_1.Property('Center')
        ], CircularChart3DLegendSettings.prototype, "alignment", void 0);
        __decorate([
            ej2_base_1.Complex({ fontFamily: null, size: null, fontStyle: null, fontWeight: null, color: null }, base_1.Font)
        ], CircularChart3DLegendSettings.prototype, "textStyle", void 0);
        __decorate([
            ej2_base_1.Property(10)
        ], CircularChart3DLegendSettings.prototype, "shapeHeight", void 0);
        __decorate([
            ej2_base_1.Property(10)
        ], CircularChart3DLegendSettings.prototype, "shapeWidth", void 0);
        __decorate([
            ej2_base_1.Complex({}, base_1.Border)
        ], CircularChart3DLegendSettings.prototype, "border", void 0);
        __decorate([
            ej2_base_1.Complex({ left: 0, right: 0, top: 0, bottom: 0 }, base_1.Margin)
        ], CircularChart3DLegendSettings.prototype, "margin", void 0);
        __decorate([
            ej2_base_1.Complex({ left: 0, right: 0, top: 0, bottom: 0 }, base_1.ContainerPadding)
        ], CircularChart3DLegendSettings.prototype, "containerPadding", void 0);
        __decorate([
            ej2_base_1.Property(8)
        ], CircularChart3DLegendSettings.prototype, "shapePadding", void 0);
        __decorate([
            ej2_base_1.Property('transparent')
        ], CircularChart3DLegendSettings.prototype, "background", void 0);
        __decorate([
            ej2_base_1.Property(1)
        ], CircularChart3DLegendSettings.prototype, "opacity", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], CircularChart3DLegendSettings.prototype, "toggleVisibility", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], CircularChart3DLegendSettings.prototype, "enableHighlight", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], CircularChart3DLegendSettings.prototype, "description", void 0);
        __decorate([
            ej2_base_1.Property(3)
        ], CircularChart3DLegendSettings.prototype, "tabIndex", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], CircularChart3DLegendSettings.prototype, "title", void 0);
        __decorate([
            ej2_base_1.Complex({ fontFamily: null, size: null, fontStyle: null, fontWeight: null, color: null }, base_1.Font)
        ], CircularChart3DLegendSettings.prototype, "titleStyle", void 0);
        __decorate([
            ej2_base_1.Property('Top')
        ], CircularChart3DLegendSettings.prototype, "titlePosition", void 0);
        __decorate([
            ej2_base_1.Property('Normal')
        ], CircularChart3DLegendSettings.prototype, "textWrap", void 0);
        __decorate([
            ej2_base_1.Property('Ellipsis')
        ], CircularChart3DLegendSettings.prototype, "textOverflow", void 0);
        __decorate([
            ej2_base_1.Property(100)
        ], CircularChart3DLegendSettings.prototype, "maximumTitleWidth", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], CircularChart3DLegendSettings.prototype, "maximumLabelWidth", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], CircularChart3DLegendSettings.prototype, "enablePages", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], CircularChart3DLegendSettings.prototype, "isInversed", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], CircularChart3DLegendSettings.prototype, "reverse", void 0);
        return CircularChart3DLegendSettings;
    }(ej2_base_1.ChildProperty));
    exports.CircularChart3DLegendSettings = CircularChart3DLegendSettings;
    var CircularChartLegend3D = (function (_super) {
        __extends(CircularChartLegend3D, _super);
        function CircularChartLegend3D(chart) {
            var _this = _super.call(this, chart) || this;
            _this.library = _this;
            _this.titleRect = new ej2_svg_base_1.Rect(0, chart.margin.top, 0, 0);
            _this.addEventListener();
            return _this;
        }
        CircularChartLegend3D.prototype.addEventListener = function () {
            Iif (this.chart.isDestroyed) {
                return;
            }
            this.chart.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMove, this);
            this.chart.on(ej2_base_1.Browser.touchEndEvent, this.mouseEnd, this);
            this.chart.on('click', this.click, this);
        };
        CircularChartLegend3D.prototype.removeEventListener = function () {
            if (this.chart.isDestroyed) {
                return;
            }
            this.chart.off(ej2_base_1.Browser.touchMoveEvent, this.mouseMove);
            this.chart.off('click', this.click);
            this.chart.off(ej2_base_1.Browser.touchEndEvent, this.mouseEnd);
        };
        CircularChartLegend3D.prototype.mouseMove = function (e) {
            Eif (this.chart.legendSettings.visible && !this.chart.isTouch) {
                this.move(e);
                if (this.chart.circularChartHighlight3DModule && (this.chart.highlightMode !== 'None' || this.chart.legendSettings.enableHighlight)) {
                    var legendItemsId = [this.legendID + '_text_', this.legendID + '_shape_marker_',
                        this.legendID + '_shape_', this.legendID + '_g_'];
                    var targetId = e.target.id;
                    for (var _i = 0, legendItemsId_1 = legendItemsId; _i < legendItemsId_1.length; _i++) {
                        var id = legendItemsId_1[_i];
                        if (targetId.indexOf(id) > -1) {
                            if (this.chart.circularChartSelection3DModule) {
                                this.chart.circularChartSelection3DModule.legendSelection(this.chart, e.target, e.type);
                            }
                            else Eif (this.chart.circularChartHighlight3DModule) {
                                this.chart.circularChartHighlight3DModule.legendSelection(this.chart, e.target, e.type);
                            }
                            break;
                        }
                    }
                }
            }
        };
        CircularChartLegend3D.prototype.mouseEnd = function (e) {
            Iif (this.chart.legendSettings.visible && this.chart.isTouch) {
                this.move(e);
            }
        };
        CircularChartLegend3D.prototype.getLegendOptions = function (chart, series) {
            this.legendCollections = [];
            this.isRtlEnable = chart.enableRtl;
            this.isReverse = !this.isRtlEnable && chart.legendSettings.reverse;
            for (var i = 0; i < 1; i++) {
                for (var _i = 0, _a = series[i].points; _i < _a.length; _i++) {
                    var point = _a[_i];
                    if (!ej2_base_1.isNullOrUndefined(point.x) && !ej2_base_1.isNullOrUndefined(point.y)) {
                        this.legendCollections.push(new legend_1.LegendOptions(point.x.toString(), point.color, series[i].legendShape, point.visible, 'Pie', series[0].legendImageUrl, null, null, point.index, series[i].index));
                    }
                }
                if (this.isReverse) {
                    this.legendCollections.reverse();
                }
            }
        };
        CircularChartLegend3D.prototype.getLegendBounds = function (availableSize, legendBounds, legend) {
            this.calculateLegendTitle(legend, legendBounds);
            this.isTitle = legend.title ? true : false;
            var extraWidth = 0;
            var extraHeight = 0;
            var legendOption;
            this.chartRowCount = 1;
            this.rowHeights = [];
            this.columnHeights = [];
            this.pageHeights = [];
            var padding = legend.padding;
            var titlePosition = legend.titlePosition;
            var titlePlusArrowSpace = 0;
            var arrowWidth = this.arrowWidth;
            var arrowHeight = legend.enablePages ? 0 : this.arrowHeight;
            if (!this.isVertical) {
                extraHeight = !legend.height ? ((availableSize.height / 100) * 5) : 0;
            }
            else {
                extraWidth = !legend.width ? ((availableSize.width / 100) * 5) : 0;
            }
            legendBounds.width += extraWidth;
            legendBounds.height += extraHeight;
            var shapePadding = legend.shapePadding;
            var maximumWidth = legend.maximumLabelWidth ? legend.maximumLabelWidth : 0;
            var shapeWidth = legend.shapeWidth;
            var rowWidth = 0;
            var columnCount = 0;
            var rowCount = 0;
            var columnWidth = [];
            var pageWidth = [];
            var pageRowWidth = 0;
            var previousRowCount = 0;
            var columnHeight = 0;
            var legendWidth = 0;
            var titleHeight = 0;
            this.maxItemHeight = Math.max(ej2_svg_base_1.measureText('MeasureText', legend.textStyle, this.chart.themeStyle.legendLabelFont).height, legend.shapeHeight);
            var legendEventArgs;
            var render = false;
            for (var i = 0; i < this.legendCollections.length; i++) {
                legendOption = this.legendCollections[i];
                legendEventArgs = {
                    fill: legendOption.fill, text: legendOption.text, shape: legendOption.shape,
                    name: 'legendRender', cancel: false
                };
                this.chart.trigger('legendRender', legendEventArgs);
                legendOption.render = !legendEventArgs.cancel;
                legendOption.text = ((legendEventArgs.text.indexOf('&') > -1) ?
                    this.convertHtmlEntities(legendEventArgs.text) : legendEventArgs.text);
                legendOption.fill = legendEventArgs.fill;
                legendOption.shape = legendEventArgs.shape;
                legendOption.textSize = ej2_svg_base_1.measureText(legendOption.text, legend.textStyle, this.chart.themeStyle.legendLabelFont);
                Eif (legendOption.render && legendOption.text !== '') {
                    render = true;
                    legendWidth = shapeWidth + shapePadding + (legend.maximumLabelWidth ? legend.maximumLabelWidth :
                        legendOption.textSize.width) + (!this.isVertical ? (i === 0) ? padding : this.itemPadding : padding);
                    this.getLegendHeight(legendOption, legend, legendBounds, rowWidth, this.maxItemHeight, padding);
                    if (this.isVertical) {
                        columnHeight += legendOption.textSize.height + ((i === 0) ? padding : this.itemPadding);
                        if (columnHeight + this.itemPadding + (arrowHeight / this.pageButtonSize) > (legendBounds.height)) {
                            rowWidth = rowWidth + maximumWidth;
                            pageRowWidth = this.getPageWidth(pageWidth);
                            this.totalPages = Math.max(rowCount, this.totalPages || 1);
                            Eif ((rowWidth - pageRowWidth + legendWidth) > legendBounds.width) {
                                pageWidth.push(rowWidth - pageRowWidth);
                                rowCount = this.rowHeights.length;
                                previousRowCount = rowCount;
                            }
                            else {
                                rowCount = previousRowCount;
                            }
                            columnWidth.push(maximumWidth);
                            maximumWidth = 0;
                            columnHeight = legendOption.textSize.height + padding;
                            columnCount++;
                        }
                        this.columnHeights[columnCount] = (this.columnHeights[columnCount] ?
                            this.columnHeights[columnCount] : 0) +
                            legendOption.textSize.height + ((i === 0) ? padding : this.itemPadding);
                        maximumWidth = Math.max(legendWidth, maximumWidth);
                        this.rowHeights[rowCount] = Math.max((this.rowHeights[rowCount] ?
                            this.rowHeights[rowCount] : 0), legendOption.textSize.height);
                        rowCount++;
                    }
                    else {
                        if (!legend.enablePages) {
                            titlePlusArrowSpace = this.isTitle && titlePosition !== 'Top' ? this.legendTitleSize.width + this.fivePixel : 0;
                            titlePlusArrowSpace += arrowWidth;
                        }
                        rowWidth = rowWidth + legendWidth;
                        if (legendBounds.width < (padding + rowWidth + titlePlusArrowSpace)) {
                            maximumWidth = Math.max(maximumWidth, (rowWidth + padding + titlePlusArrowSpace - legendWidth));
                            if (rowCount === 0 && (legendWidth !== rowWidth)) {
                                rowCount = 1;
                            }
                            rowWidth = legendWidth;
                            rowCount++;
                            columnCount = 0;
                        }
                        var len = rowCount ? (rowCount - 1) : rowCount;
                        this.rowHeights[len] = Math.max((this.rowHeights[len] ? this.rowHeights[len] : 0), legendOption.textSize.height);
                        this.columnHeights[columnCount] = (this.columnHeights[columnCount] ?
                            this.columnHeights[columnCount] : 0) +
                            legendOption.textSize.height + padding;
                        columnCount++;
                    }
                }
            }
            titleHeight = titlePosition === 'Top' ? this.legendTitleSize.height : 0;
            if (this.isVertical) {
                rowWidth = rowWidth + maximumWidth;
                this.isPaging = legendBounds.width < (rowWidth + padding);
                columnHeight = Math.max.apply(null, this.columnHeights) + padding + arrowHeight + titleHeight;
                columnHeight = Math.max(columnHeight, ((this.totalPages || 1) * (this.maxItemHeight + padding)) + padding + arrowHeight);
                this.isPaging = this.isPaging && (this.totalPages > 1);
                columnWidth.push(maximumWidth);
            }
            else {
                this.totalPages = rowCount;
                columnHeight = Math.max.apply(null, this.columnHeights) + padding + arrowHeight + titleHeight;
                this.isPaging = legendBounds.height < columnHeight;
                columnHeight = !legend.enablePages && this.isPaging ? (this.maxItemHeight + padding) + padding + titleHeight : columnHeight;
                columnHeight = Math.max(columnHeight, (this.maxItemHeight + padding) + padding + titleHeight);
                if (!this.isPaging) {
                    rowWidth += this.isTitle && titlePosition !== 'Top' ? (this.fivePixel + this.legendTitleSize.width + this.fivePixel) : 0;
                }
            }
            this.maxColumns = 0;
            var width = this.isVertical ? this.getMaxColumn(columnWidth, legendBounds.width, padding, rowWidth + padding) :
                Math.max(rowWidth + padding, maximumWidth);
            if (render) {
                this.setBounds(width, columnHeight, legend, legendBounds);
            }
            else {
                this.setBounds(0, 0, legend, legendBounds);
            }
        };
        CircularChartLegend3D.prototype.getPageWidth = function (pageWidth) {
            var sum = 0;
            for (var i = 0; i < pageWidth.length; i++) {
                sum += pageWidth[i];
            }
            return sum;
        };
        CircularChartLegend3D.prototype.getLegendHeight = function (option, legend, bounds, rowWidth, legendHeight, padding) {
            var legendWidth = option.textSize.width;
            var textPadding = legend.shapePadding + (padding * 2) + legend.shapeWidth;
            switch (legend.textWrap) {
                case 'Wrap':
                case 'AnyWhere':
                    Eif (legendWidth > legend.maximumLabelWidth || legendWidth + rowWidth > bounds.width) {
                        option.textCollection = helper_2.textWrap(option.text, (legend.maximumLabelWidth ? Math.min(legend.maximumLabelWidth, (bounds.width - textPadding)) :
                            (bounds.width - textPadding)), legend.textStyle, this.chart.enableRtl, null, null, this.chart.themeStyle.legendLabelFont);
                    }
                    else {
                        option.textCollection.push(option.text);
                    }
                    option.textSize.height = (legendHeight * option.textCollection.length);
                    break;
            }
        };
        CircularChartLegend3D.prototype.convertHtmlEntities = function (legendText) {
            var text = (legendText).replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('&nbsp;', ' ').replace('&cent;', '¢').replace('&pound;', '£').replace('&yen;', '¥').replace('&euro;', '€').replace('&copy;', '©').replace('&reg;', '®');
            text = (text).replace('&#38;', '&').replace('&#60;', '<').replace('&#62;', '>').replace('&#34;', '"').replace('&#160;', ' ').
                replace('&#162;', '¢').replace('&#163;', '£').replace('&#165;', '¥').replace('&#8364;', '€').replace('&#169;', '©').replace('&#174;', '®');
            return text;
        };
        CircularChartLegend3D.prototype.getMaxColumn = function (columns, width, padding, rowWidth) {
            var maxPageColumn = padding;
            this.maxColumnWidth = Math.max.apply(null, columns);
            for (var i = 0; i < columns.length; i++) {
                maxPageColumn += this.maxColumnWidth;
                this.maxColumns++;
                if (maxPageColumn + padding > width) {
                    maxPageColumn -= this.maxColumnWidth;
                    this.maxColumns--;
                    break;
                }
            }
            this.isPaging = (maxPageColumn < rowWidth) && (this.totalPages > 1);
            if (maxPageColumn === padding) {
                maxPageColumn = width;
            }
            this.maxColumns = Math.max(1, this.maxColumns);
            this.maxWidth = maxPageColumn;
            var columnWidth = this.maxColumnWidth + padding;
            var prevPage = 0;
            var columnCount = this.columnHeights.length;
            if (this.isPaging && this.isVertical) {
                for (var i = 1; i < columnCount; i++) {
                    columnWidth += (this.maxColumnWidth + padding);
                    Eif (columnWidth > width) {
                        this.pageHeights.push(((prevPage !== i - 1) ? Math.max.apply(null, this.columnHeights.slice(prevPage, i - 1)) :
                            this.columnHeights[prevPage]));
                        columnWidth = this.maxColumnWidth + padding;
                        prevPage = i;
                    }
                }
                this.pageHeights.push(((prevPage !== columnCount - 1) ?
                    Math.max.apply(null, this.columnHeights.slice(prevPage, columnCount - 1)) : this.columnHeights[prevPage]));
                this.totalPages = this.pageHeights.length;
            }
            return maxPageColumn;
        };
        CircularChartLegend3D.prototype.getAvailWidth = function (tx, width) {
            if (this.isVertical) {
                width = this.maxWidth;
            }
            else if (!this.isVertical && this.isPaging && !this.legend.enablePages) {
                return width - tx - this.fivePixel;
            }
            return width - ((this.legend.padding * 2) + this.legend.shapeWidth + this.legend.shapePadding);
        };
        CircularChartLegend3D.prototype.getRenderPoint = function (legendOption, start, textPadding, prevLegend, rect, count, firstLegend) {
            var padding = this.legend.padding;
            var previousLocation = prevLegend.location.y + this.maxItemHeight / 4 + (prevLegend.textCollection.length > 0 ?
                ((prevLegend.textCollection.length - 1) * this.maxItemHeight) : 0);
            if (this.isVertical) {
                if (count === firstLegend || (previousLocation + legendOption.textSize.height + padding > (rect.y + rect.height))) {
                    legendOption.location.x = prevLegend.location.x + ((count === firstLegend) ? 0 : (!this.isRtlEnable) ?
                        this.maxColumnWidth : -this.maxColumnWidth);
                    legendOption.location.y = start.y;
                    var textStartLoc = (this.legend.shapeWidth / 2) + padding;
                    this.pageXCollections.push(legendOption.location.x + ((!this.isRtlEnable) ? -textStartLoc : textStartLoc));
                }
                else {
                    legendOption.location.x = prevLegend.location.x;
                    legendOption.location.y = prevLegend.location.y + prevLegend.textSize.height + this.itemPadding;
                }
            }
            else {
                var textWidth = textPadding + (this.legend.maximumLabelWidth ?
                    this.legend.maximumLabelWidth : prevLegend.textSize.width);
                var previousBound = prevLegend.location.x + ((!this.isRtlEnable) ? textWidth : -textWidth);
                if (this.isWithinBounds(previousBound, (this.legend.maximumLabelWidth ? this.legend.maximumLabelWidth :
                    legendOption.textSize.width) + textPadding - this.itemPadding, rect, this.legend.shapeWidth / 2)) {
                    if (count !== firstLegend) {
                        this.chartRowCount++;
                    }
                    legendOption.location.y = (count === firstLegend) ? prevLegend.location.y :
                        prevLegend.location.y + this.rowHeights[(this.chartRowCount - 2)] + padding;
                    legendOption.location.x = start.x;
                }
                else {
                    legendOption.location.y = prevLegend.location.y;
                    legendOption.location.x = (count === firstLegend) ? prevLegend.location.x : previousBound;
                }
            }
            var availablewidth = this.getAvailWidth(legendOption.location.x, this.legendBounds.width);
            availablewidth = this.legend.maximumLabelWidth ? Math.min(this.legend.maximumLabelWidth, availablewidth) : availablewidth;
            if (this.legend.textOverflow === 'Ellipsis' && this.legend.textWrap === 'Normal') {
                legendOption.text = helper_1.textTrim(+availablewidth.toFixed(4), legendOption.text, this.legend.textStyle, this.chart.enableRtl, this.chart.themeStyle.legendLabelFont);
            }
        };
        CircularChartLegend3D.prototype.isWithinBounds = function (previousBound, textWidth, legendBounds, shapeWidth) {
            Eif (!this.isRtlEnable) {
                return (previousBound + textWidth) > (legendBounds.x + legendBounds.width + shapeWidth);
            }
            else {
                return (previousBound - textWidth) < (legendBounds.x - shapeWidth);
            }
        };
        CircularChartLegend3D.prototype.getSmartLegendLocation = function (labelBound, legendBound, margin) {
            var space;
            switch (this.position) {
                case 'Left':
                    space = ((labelBound.x - legendBound.width) - margin.left) / 2;
                    legendBound.x = (labelBound.x - legendBound.width) < margin.left ? legendBound.x :
                        (labelBound.x - legendBound.width) - space;
                    break;
                case 'Right':
                    space = ((this.chart.availableSize.width - margin.right) - (labelBound.x + labelBound.width + legendBound.width)) / 2;
                    legendBound.x = (labelBound.x + labelBound.width + legendBound.width) > (this.chart.availableSize.width - margin.right) ?
                        legendBound.x : (labelBound.x + labelBound.width + space);
                    break;
                case 'Top':
                    this.getTitleRect(this.chart);
                    space = ((labelBound.y - legendBound.height) - (this.titleRect.y + this.titleRect.height)) / 2;
                    legendBound.y = (labelBound.y - legendBound.height) < margin.top ? legendBound.y :
                        (labelBound.y - legendBound.height) - space;
                    break;
                case 'Bottom':
                    space = ((this.chart.availableSize.height - margin.bottom) - (labelBound.y + labelBound.height + legendBound.height)) / 2;
                    legendBound.y = labelBound.y + labelBound.height + legendBound.height > (this.chart.availableSize.height - margin.bottom) ?
                        legendBound.y : (labelBound.y + labelBound.height) + space;
                    break;
            }
        };
        CircularChartLegend3D.prototype.getTitleRect = function (circular) {
            Eif (!circular.title) {
                return null;
            }
            var titleSize = ej2_svg_base_1.measureText(circular.title, circular.titleStyle, this.chart.themeStyle.legendTitleFont);
            this.titleRect = new ej2_svg_base_1.Rect(circular.availableSize.width / 2 - titleSize.width / 2, circular.margin.top, titleSize.width, titleSize.height);
        };
        CircularChartLegend3D.prototype.legendByIndex = function (index, legendCollections) {
            for (var _i = 0, legendCollections_1 = legendCollections; _i < legendCollections_1.length; _i++) {
                var legend = legendCollections_1[_i];
                if (legend.pointIndex === index) {
                    return legend;
                }
            }
            return null;
        };
        CircularChartLegend3D.prototype.click = function (event) {
            var targetId = event.target.id.indexOf('_chart_legend_g_') > -1 ?
                event.target.firstChild['id'] : event.target.id;
            var chart = this.chart;
            var legendItemsId = [this.legendID + '_text_', this.legendID + '_shape_', this.legendID + '_shape_marker_'];
            this.chart.animateSeries = false;
            for (var _i = 0, legendItemsId_2 = legendItemsId; _i < legendItemsId_2.length; _i++) {
                var id = legendItemsId_2[_i];
                if (targetId.indexOf(id) > -1) {
                    var pointIndex = parseInt(targetId.split(id)[1], 10);
                    if (this.chart.legendSettings.toggleVisibility && !isNaN(pointIndex)) {
                        var currentSeries = this.chart.visibleSeries[0];
                        var point = currentSeries.points[pointIndex];
                        var legendOption = this.legendByIndex(pointIndex, this.legendCollections);
                        var legendClickArgs = {
                            legendText: legendOption.text, legendShape: legendOption.shape,
                            chart: chart,
                            series: currentSeries, point: point,
                            name: constants_1.legendClick, cancel: false
                        };
                        this.chart.trigger(constants_1.legendClick, legendClickArgs);
                        Eif (!legendClickArgs.cancel) {
                            point.visible = !point.visible;
                            legendOption.visible = point.visible;
                            currentSeries.sumOfPoints += point.visible ? point.y : -point.y;
                            chart.redraw = chart.enableAnimation;
                            this.sliceVisibility(pointIndex, point.visible);
                            chart.removeSeriesElements(chart);
                            chart.removeSvg();
                            var svgObject = document.getElementById(this.chart.element.id + '-svg-chart-3d');
                            Eif (svgObject) {
                                while (svgObject.childNodes.length > 0) {
                                    svgObject.removeChild(svgObject.firstChild);
                                }
                            }
                            this.chart.circular3DPolygon = [];
                            this.chart.visibleSeries[0].segments = [];
                            this.chart.animateSeries = false;
                            this.chart.calculateBounds();
                            this.chart.renderElements();
                            Iif (chart.circularChartHighlight3DModule && (chart.highlightMode !== 'None' || chart.legendSettings.enableHighlight)) {
                                chart.circularChartHighlight3DModule.redrawSelection(chart);
                            }
                        }
                    }
                    else {
                        if (this.chart.circularChartSelection3DModule && !isNaN(pointIndex)) {
                            this.chart.circularChartSelection3DModule.legendSelection(this.chart, event.target, event.type);
                        }
                        else if (this.chart.circularChartHighlight3DModule && !isNaN(pointIndex)) {
                            this.chart.circularChartHighlight3DModule.legendSelection(this.chart, event.target, event.type);
                        }
                    }
                }
            }
            Iif (targetId.indexOf(this.legendID + '_pageup') > -1) {
                this.changePage(event, true);
            }
            else Iif (targetId.indexOf(this.legendID + '_pagedown') > -1) {
                this.changePage(event, false);
            }
            chart.redraw = false;
        };
        CircularChartLegend3D.prototype.sliceVisibility = function (index, isVisible) {
            var sliceId = this.chart.element.id + '_Series_0_Point_';
            if (this.chart.visibleSeries[0].dataLabel.visible) {
                sliceId = this.chart.element.id + '_datalabel_Series_0_';
                this.sliceAnimate(helper_1.getElement(sliceId + 'g_' + index), isVisible);
            }
        };
        CircularChartLegend3D.prototype.sliceAnimate = function (element, isVisible) {
            Eif (!element) {
                return null;
            }
            new ej2_base_1.Animation({}).animate(element, {
                duration: 300,
                delay: 0,
                name: isVisible ? 'FadeIn' : 'FadeOut',
                end: function (args) {
                    args.element.style.visibility = isVisible ? 'visible' : 'hidden';
                }
            });
        };
        CircularChartLegend3D.prototype.getModuleName = function () {
            return 'CircularChartLegend3D';
        };
        CircularChartLegend3D.prototype.destroy = function () {
            this.removeEventListener();
        };
        return CircularChartLegend3D;
    }(legend_1.BaseLegend));
    exports.CircularChartLegend3D = CircularChartLegend3D;
});