all files / chart3d/legend/ legend.js

97.3% Statements 324/333
90.38% Branches 235/260
97.06% Functions 33/34
97.22% Lines 315/324
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              54×                                                                                                                                     322× 322× 322× 322×   322×     322× 322× 322×   322× 28×   294× 294× 294×   43× 42× 42× 40×   40× 40× 40× 152× 152× 11× 11× 11×                   357× 357× 357× 357× 357× 357× 275×   357× 896× 896× 894× 894×   894×   20× 20× 90× 20×     20× 20×       357×     357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 297×     60×   357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 357× 914× 914×   914×   914×       914× 914× 914× 914× 914× 914× 914× 914× 914× 914× 912× 912×   912× 912× 17× 17×   912× 912× 156× 156× 16×   156× 156× 156× 156×   912× 912× 912×     912×     357× 357× 357× 357×           357× 357× 290×   357× 357×           912× 912× 912×                   912× 912×   912× 912×   204× 204× 94×   204×         708× 708×   912×     912×   912× 912× 903×     912× 877×     35×     15× 15× 15× 15× 15× 15× 15× 14×       14× 14× 14× 14× 11×   14×         14×                 10× 10×   10× 10× 76×   10×   10× 10× 10× 10× 10× 10× 10× 10× 10× 10× 10×   10×   10×         18×   10× 10×         10× 17× 17×     109×     109×   109×   109× 109× 309× 309× 15× 15× 15×     109×   105×     4177×   322×        
/* 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", "../../common/utils/helper", "../../common/utils/helper", "@syncfusion/ej2-svg-base", "../../common/model/constants", "../../common/utils/helper", "../../common/model/base"], function (require, exports, ej2_base_1, base_1, legend_1, helper_1, helper_2, ej2_svg_base_1, constants_1, helper_3, base_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Chart3DLegendSettings = (function (_super) {
        __extends(Chart3DLegendSettings, _super);
        function Chart3DLegendSettings() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property(true)
        ], Chart3DLegendSettings.prototype, "visible", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DLegendSettings.prototype, "height", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DLegendSettings.prototype, "width", void 0);
        __decorate([
            ej2_base_1.Complex({ x: 0, y: 0 }, base_2.Location)
        ], Chart3DLegendSettings.prototype, "location", void 0);
        __decorate([
            ej2_base_1.Property('Auto')
        ], Chart3DLegendSettings.prototype, "position", void 0);
        __decorate([
            ej2_base_1.Property('Series')
        ], Chart3DLegendSettings.prototype, "mode", void 0);
        __decorate([
            ej2_base_1.Property(8)
        ], Chart3DLegendSettings.prototype, "padding", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DLegendSettings.prototype, "itemPadding", void 0);
        __decorate([
            ej2_base_1.Property('Center')
        ], Chart3DLegendSettings.prototype, "alignment", void 0);
        __decorate([
            ej2_base_1.Complex({ fontFamily: null, size: null, fontStyle: null, fontWeight: null, color: null }, base_1.Font)
        ], Chart3DLegendSettings.prototype, "textStyle", void 0);
        __decorate([
            ej2_base_1.Property(10)
        ], Chart3DLegendSettings.prototype, "shapeHeight", void 0);
        __decorate([
            ej2_base_1.Property(10)
        ], Chart3DLegendSettings.prototype, "shapeWidth", void 0);
        __decorate([
            ej2_base_1.Complex({}, base_1.Border)
        ], Chart3DLegendSettings.prototype, "border", void 0);
        __decorate([
            ej2_base_1.Complex({ left: 0, right: 0, top: 0, bottom: 0 }, base_1.Margin)
        ], Chart3DLegendSettings.prototype, "margin", void 0);
        __decorate([
            ej2_base_1.Complex({ left: 0, right: 0, top: 0, bottom: 0 }, base_1.ContainerPadding)
        ], Chart3DLegendSettings.prototype, "containerPadding", void 0);
        __decorate([
            ej2_base_1.Property(8)
        ], Chart3DLegendSettings.prototype, "shapePadding", void 0);
        __decorate([
            ej2_base_1.Property('transparent')
        ], Chart3DLegendSettings.prototype, "background", void 0);
        __decorate([
            ej2_base_1.Property(1)
        ], Chart3DLegendSettings.prototype, "opacity", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], Chart3DLegendSettings.prototype, "toggleVisibility", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], Chart3DLegendSettings.prototype, "enableHighlight", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DLegendSettings.prototype, "description", void 0);
        __decorate([
            ej2_base_1.Property(3)
        ], Chart3DLegendSettings.prototype, "tabIndex", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DLegendSettings.prototype, "title", void 0);
        __decorate([
            ej2_base_1.Complex({ fontFamily: null, size: null, fontStyle: null, fontWeight: null, color: null }, base_1.Font)
        ], Chart3DLegendSettings.prototype, "titleStyle", void 0);
        __decorate([
            ej2_base_1.Property('Top')
        ], Chart3DLegendSettings.prototype, "titlePosition", void 0);
        __decorate([
            ej2_base_1.Property('Normal')
        ], Chart3DLegendSettings.prototype, "textWrap", void 0);
        __decorate([
            ej2_base_1.Property('Ellipsis')
        ], Chart3DLegendSettings.prototype, "textOverflow", void 0);
        __decorate([
            ej2_base_1.Property(100)
        ], Chart3DLegendSettings.prototype, "maximumTitleWidth", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DLegendSettings.prototype, "maximumLabelWidth", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], Chart3DLegendSettings.prototype, "enablePages", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], Chart3DLegendSettings.prototype, "isInversed", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], Chart3DLegendSettings.prototype, "reverse", void 0);
        return Chart3DLegendSettings;
    }(ej2_base_1.ChildProperty));
    exports.Chart3DLegendSettings = Chart3DLegendSettings;
    var Legend3D = (function (_super) {
        __extends(Legend3D, _super);
        function Legend3D(chart) {
            var _this = _super.call(this, chart) || this;
            _this.library = _this;
            _this.addEventListener();
            return _this;
        }
        Legend3D.prototype.addEventListener = function () {
            Iif (this.chart.isDestroyed) {
                return;
            }
            this.chart.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMove, this);
            this.chart.on('click', this.click, this);
            this.chart.on(ej2_base_1.Browser.touchEndEvent, this.mouseEnd, this);
        };
        Legend3D.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);
        };
        Legend3D.prototype.mouseMove = function (e) {
            if (this.chart.legendSettings.visible && !this.chart.isTouch) {
                this.move(e);
                if (this.chart.highlight3DModule && (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;
                    var index = void 0;
                    for (var _i = 0, legendItemsId_1 = legendItemsId; _i < legendItemsId_1.length; _i++) {
                        var id = legendItemsId_1[_i];
                        if (targetId.indexOf(id) > -1) {
                            index = parseInt(targetId.split(id)[1], 10);
                            this.chart.highlight3DModule.legendSelection(this.chart, index, e.target, e.type);
                            break;
                        }
                    }
                }
            }
        };
        Legend3D.prototype.mouseEnd = function (e) {
            if (this.chart.legendSettings.visible && this.chart.isTouch) {
                this.move(e);
            }
        };
        Legend3D.prototype.getLegendOptions = function (visibleSeriesCollection, chart) {
            this.legendCollections = [];
            var seriesType;
            var fill;
            this.isRtlEnable = chart.enableRtl;
            this.isReverse = !this.isRtlEnable && chart.legendSettings.reverse;
            if (visibleSeriesCollection.length > 1) {
                this.legend.mode = 'Series';
            }
            for (var _i = 0, visibleSeriesCollection_1 = visibleSeriesCollection; _i < visibleSeriesCollection_1.length; _i++) {
                var series = visibleSeriesCollection_1[_i];
                if (this.legend.mode === 'Series') {
                    seriesType = series.type;
                    fill = (series.pointColorMapping && series.points.length > 0) ?
                        (series.points[0].interior ? series.points[0].interior : series.interior) : series.interior;
                    this.legendCollections.push(new legend_1.LegendOptions(series.name, fill, series.legendShape, series.visible, seriesType, series.legendImageUrl ? series.legendImageUrl : '', 'None', false, null, null));
                }
                else Eif (this.legend.mode === 'Point') {
                    var _loop_1 = function (points) {
                        seriesType = series.type;
                        fill = points.interior ? points.interior : series.interior;
                        Eif (this_1.legendCollections.filter(function (i) { return i.text === points.x.toString(); }).length === 0) {
                            this_1.legendCollections.push(new legend_1.LegendOptions(points.x.toString(), fill, series.legendShape, points.visible, seriesType, '', 'None', false));
                        }
                    };
                    var this_1 = this;
                    for (var _a = 0, _b = series.points; _a < _b.length; _a++) {
                        var points = _b[_a];
                        _loop_1(points);
                    }
                }
            }
            if (this.isReverse) {
                this.legendCollections.reverse();
            }
        };
        Legend3D.prototype.get3DLegendBounds = function (availableSize, legendBounds, legend) {
            this.calculateLegendTitle(legend, legendBounds);
            this.isTitle = legend.title ? true : false;
            this.chartRowCount = 1;
            this.rowHeights = [];
            this.columnHeights = [];
            this.pageHeights = [];
            var padding = legend.padding;
            var titlePosition = legend.titlePosition;
            var extraHeight = 0;
            var legendOption;
            var extraWidth = 0;
            var arrowWidth = this.arrowWidth;
            var arrowHeight = this.arrowHeight;
            var verticalArrowSpace = this.isVertical && !legend.enablePages ? arrowHeight : 0;
            var titleSpace = this.isTitle && titlePosition === 'Top' ? this.legendTitleSize.height + this.fivePixel : 0;
            titleSpace = this.isTitle && this.isVertical && titlePosition !== 'Top' ? this.legendTitleSize.height + this.fivePixel : titleSpace;
            if (!this.isVertical) {
                extraHeight = !legend.height ? ((availableSize.height / 100) * 5) : 0;
            }
            else {
                extraWidth = !legend.width ? ((availableSize.width / 100) * 5) : 0;
            }
            legendBounds.height += (extraHeight);
            legendBounds.width += extraWidth;
            var shapeWidth = legend.shapeWidth;
            var shapePadding = legend.shapePadding;
            var maximumWidth = 0;
            var rowWidth = 0;
            var legendWidth = 0;
            var columnHeight = 0;
            var columnCount = 0;
            var rowCount = 0;
            var titlePlusArrowSpace = 0;
            var legendEventArgs;
            var render = false;
            this.maxItemHeight = Math.max(ej2_svg_base_1.measureText('MeasureText', legend.textStyle, this.chart.themeStyle.legendLabelFont).height, legend.shapeHeight);
            for (var i = 0; i < this.legendCollections.length; i++) {
                legendOption = this.legendCollections[i];
                if (constants_1.regSub.test(legendOption.text)) {
                    legendOption.text = helper_2.getUnicodeText(legendOption.text, constants_1.regSub);
                }
                if (constants_1.regSup.test(legendOption.text)) {
                    legendOption.text = helper_2.getUnicodeText(legendOption.text, constants_1.regSup);
                }
                legendEventArgs = {
                    fill: legendOption.fill, text: legendOption.text, shape: legendOption.shape,
                    cancel: false
                };
                this.chart.trigger(constants_1.legendRender, legendEventArgs);
                legendOption.render = !legendEventArgs.cancel;
                legendOption.text = legendEventArgs.text;
                legendOption.fill = legendEventArgs.fill;
                legendOption.shape = legendEventArgs.shape;
                legendOption.markerShape = 'None';
                legendOption.textSize = ej2_svg_base_1.measureText(legendOption.text, legend.textStyle, this.chart.themeStyle.legendLabelFont);
                shapeWidth = legendOption.text ? legend.shapeWidth : 0;
                shapePadding = legendOption.text ? legend.shapePadding : 0;
                if (legendOption.render && legendOption.text) {
                    render = true;
                    legendWidth = shapeWidth + shapePadding + (legend.maximumLabelWidth ? legend.maximumLabelWidth :
                        legendOption.textSize.width) + (!this.isVertical ? (i === 0) ? padding : this.itemPadding : padding);
                    rowWidth = rowWidth + legendWidth;
                    if (!legend.enablePages && !this.isVertical) {
                        titlePlusArrowSpace = this.isTitle && titlePosition !== 'Top' ? this.legendTitleSize.width + this.fivePixel : 0;
                        titlePlusArrowSpace += arrowWidth;
                    }
                    this.getLegendHeight(legendOption, legend, legendBounds, rowWidth, this.maxItemHeight, padding);
                    if (legendBounds.width < (padding + rowWidth + titlePlusArrowSpace) || this.isVertical) {
                        maximumWidth = Math.max(maximumWidth, (rowWidth + padding + titlePlusArrowSpace - (this.isVertical ? 0 : legendWidth)));
                        if (rowCount === 0 && (legendWidth !== rowWidth)) {
                            rowCount = 1;
                        }
                        rowWidth = this.isVertical ? 0 : legendWidth;
                        rowCount++;
                        columnCount = 0;
                        columnHeight = verticalArrowSpace;
                    }
                    var len = (rowCount > 0 ? (rowCount - 1) : 0);
                    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 + (this.isVertical ? (i === 0) ? padding : this.itemPadding : padding);
                    columnCount++;
                }
            }
            columnHeight = Math.max.apply(null, this.columnHeights) + padding + titleSpace;
            columnHeight = Math.max(columnHeight, (this.maxItemHeight + padding) + padding + titleSpace);
            this.isPaging = legendBounds.height < columnHeight;
            if (this.isPaging && !legend.enablePages) {
                Iif (this.isVertical) {
                    columnHeight += columnHeight;
                }
                else {
                    columnHeight = (this.maxItemHeight + padding) + padding + (titlePosition === 'Top' ? titleSpace : 0);
                }
            }
            this.totalPages = rowCount;
            if (!this.isPaging && !this.isVertical) {
                rowWidth += this.isTitle && titlePosition !== 'Top' ? (this.fivePixel + this.legendTitleSize.width + this.fivePixel) : 0;
            }
            Eif (render) {
                this.setBounds(Math.max((rowWidth + padding), maximumWidth), columnHeight, legend, legendBounds);
            }
            else {
                this.setBounds(0, 0, legend, legendBounds);
            }
        };
        Legend3D.prototype.getLegendHeight = function (legendOption, legend, legendBounds, rowWidth, legendHeight, padding) {
            var legendWidth = legendOption.textSize.width;
            var textPadding = legend.shapePadding + (padding * 2) + legend.shapeWidth;
            switch (legend.textWrap) {
                case 'Wrap':
                case 'AnyWhere':
                    Iif (legendWidth > legend.maximumLabelWidth || legendWidth + rowWidth > legendBounds.width) {
                        legendOption.textCollection = helper_3.textWrap(legendOption.text, (legend.maximumLabelWidth ? Math.min(legend.maximumLabelWidth, (legendBounds.width - textPadding)) :
                            (legendBounds.width - textPadding)), legend.textStyle, this.chart.enableRtl, null, null, this.chart.themeStyle.legendLabelFont);
                    }
                    else {
                        legendOption.textCollection.push(legendOption.text);
                    }
                    legendOption.textSize.height = (legendHeight * legendOption.textCollection.length);
                    break;
            }
        };
        Legend3D.prototype.getRenderPoint = function (legendOption, start, textPadding, prevLegend, rect, count, firstLegend) {
            var padding = this.legend.padding;
            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.isVertical) {
                legendOption.location.x = start.x;
                if (count !== firstLegend) {
                    this.chartRowCount++;
                }
                legendOption.location.y = (count === firstLegend) ? prevLegend.location.y :
                    prevLegend.location.y + (this.isVertical ? prevLegend.textSize.height :
                        this.rowHeights[(this.chartRowCount - 2)]) + (this.isVertical ? this.itemPadding : padding);
            }
            else {
                legendOption.location.x = (count === firstLegend) ? prevLegend.location.x : previousBound;
                legendOption.location.y = prevLegend.location.y;
            }
            var availwidth = (!this.isRtlEnable) ? (this.legendBounds.x + this.legendBounds.width) - (legendOption.location.x +
                textPadding - this.itemPadding - this.legend.shapeWidth / 2) :
                (legendOption.location.x - textPadding + this.itemPadding + (this.legend.shapeWidth / 2)) - this.legendBounds.x;
            if (!this.isVertical && this.isPaging && !this.legend.enablePages) {
                availwidth = this.legendBounds.width - legendOption.location.x - this.fivePixel;
            }
            availwidth = this.legend.maximumLabelWidth ? Math.min(this.legend.maximumLabelWidth, availwidth) : availwidth;
            if (this.legend.textOverflow === 'Ellipsis' && this.legend.textWrap === 'Normal') {
                legendOption.text = helper_1.textTrim(+availwidth.toFixed(4), legendOption.text, this.legend.textStyle, this.chart.enableRtl, this.chart.themeStyle.legendLabelFont);
            }
        };
        Legend3D.prototype.isWithinBounds = function (previousBound, textWidth, rect) {
            if (!this.isRtlEnable) {
                return (previousBound + textWidth) > (rect.x + rect.width + (this.legend.shapeWidth / 2));
            }
            else {
                return (previousBound - textWidth) < (rect.x - (this.legend.shapeWidth / 2));
            }
        };
        Legend3D.prototype.LegendClick = function (index, event) {
            var chart = this.chart;
            var seriesIndex = chart.legendSettings.mode === 'Series' ? index : 0;
            var legendIndex = !this.isReverse ? index : (this.legendCollections.length - 1) - index;
            var series = chart.visibleSeries[seriesIndex];
            var legend = this.legendCollections[legendIndex];
            var changeDetection = 'isProtectedOnChange';
            if (chart.legendSettings.mode === 'Series') {
                var legendClickArgs = {
                    legendText: legend.text, legendShape: legend.shape,
                    series: series, cancel: false
                };
                this.chart.trigger(constants_1.legendClick, legendClickArgs);
                series.legendShape = legendClickArgs.legendShape;
                Eif (!legendClickArgs.cancel) {
                    if (series.fill !== null) {
                        chart.visibleSeries[index].interior = series.fill;
                    }
                    if (chart.legendSettings.toggleVisibility) {
                        series.chart[changeDetection] = true;
                        this.changeSeriesVisiblity(series, series.visible);
                        legend.visible = series.visible;
                        this.refreshLegendToggle(chart, series);
                    }
                    else Iif (chart.highlight3DModule) {
                        chart.highlight3DModule.legendSelection(chart, index, event.target, event.type);
                    }
                    else Eif (chart.selection3DModule) {
                        chart.selection3DModule.legendSelection(chart, index, event.target, event.type);
                    }
                    series.chart[changeDetection] = false;
                }
            }
            else Eif (chart.legendSettings.mode === 'Point') {
                var point = series.points[index];
                var legendClickArgs = {
                    legendText: legend.text, legendShape: legend.shape,
                    series: series, cancel: false
                };
                this.chart.trigger(constants_1.legendClick, legendClickArgs);
                Eif (chart.legendSettings.toggleVisibility && !legendClickArgs.cancel) {
                    point.visible = !point.visible;
                    var legendOption = this.legendCollections[index];
                    legendOption.visible = point.visible;
                    this.refreshLegendToggle(chart, series);
                }
            }
        };
        Legend3D.prototype.refreshLegendToggle = function (chart, series) {
            var selectedDataIndexes = [];
            if (chart.selection3DModule) {
                selectedDataIndexes = ej2_base_1.extend([], chart.selection3DModule.selectedDataIndexes, null, true);
            }
            Eif ((chart.svgObject.childNodes.length > 0)) {
                while (chart.svgObject.lastChild) {
                    chart.svgObject.removeChild(chart.svgObject.lastChild);
                }
                ej2_base_1.remove(chart.svgObject);
            }
            chart.animateSeries = false;
            helper_1.removeElement(ej2_svg_base_1.getElement(chart.element.id + '_Secondary_Element').querySelectorAll('.ejSVGTooltip')[0]);
            this.redrawSeriesElements(series, chart);
            chart.removeSvg();
            chart.refreshAxis();
            series.refreshAxisLabel();
            this.refreshSeries(chart.visibleSeries);
            chart.polygons = [];
            chart.refreshBound();
            chart.trigger('loaded', { chart: chart });
            if (selectedDataIndexes.length > 0) {
                chart.selection3DModule.selectedDataIndexes = selectedDataIndexes;
                chart.selection3DModule.redrawSelection(chart, chart.selectionMode);
            }
            if (chart.highlight3DModule && chart.highlightMode !== 'None' || chart.legendSettings.enableHighlight) {
                chart.highlight3DModule.redrawSelection(chart, chart.highlightMode);
            }
            chart.redraw = false;
        };
        Legend3D.prototype.changeSeriesVisiblity = function (series, visibility) {
            series.visible = !visibility;
            if (this.isSecondaryAxis(series.xAxis)) {
                series.xAxis.internalVisibility = series.xAxis.series.some(function (value) { return (value.visible); });
            }
            if (this.isSecondaryAxis(series.yAxis)) {
                series.yAxis.internalVisibility = series.yAxis.series.some(function (value) { return (value.visible); });
            }
        };
        Legend3D.prototype.isSecondaryAxis = function (axis) {
            return (this.chart.axes.indexOf(axis) > -1);
        };
        Legend3D.prototype.redrawSeriesElements = function (series, chart) {
            Eif (!chart.redraw) {
                return null;
            }
            helper_1.removeElement(chart.element.id + '_Series_' + (series.index === undefined ? series.category : series.index) +
                '_DataLabelCollections');
        };
        Legend3D.prototype.refreshSeries = function (seriesCollection) {
            for (var _i = 0, seriesCollection_1 = seriesCollection; _i < seriesCollection_1.length; _i++) {
                var series = seriesCollection_1[_i];
                series.position = undefined;
            }
        };
        Legend3D.prototype.click = function (event) {
            Iif (!this.chart.legendSettings.visible) {
                return;
            }
            var targetId = event.target.id.indexOf('_chart_legend_g_') > -1 ?
                event.target.firstChild['id'] : event.target.id;
            var legendItemsId = [this.legendID + '_text_', this.legendID + '_shape_marker_',
                this.legendID + '_shape_'];
            var seriesIndex;
            for (var _i = 0, legendItemsId_2 = legendItemsId; _i < legendItemsId_2.length; _i++) {
                var id = legendItemsId_2[_i];
                if (targetId.indexOf(id) > -1) {
                    seriesIndex = parseInt(targetId.split(id)[1], 10);
                    this.LegendClick(seriesIndex, event);
                    break;
                }
            }
            if (targetId.indexOf(this.legendID + '_pageup') > -1) {
                this.changePage(event, true);
            }
            else if (targetId.indexOf(this.legendID + '_pagedown') > -1) {
                this.changePage(event, false);
            }
        };
        Legend3D.prototype.getModuleName = function () {
            return 'Legend3D';
        };
        Legend3D.prototype.destroy = function () {
            this.removeEventListener();
        };
        return Legend3D;
    }(legend_1.BaseLegend));
    exports.Legend3D = Legend3D;
});