all files / accumulation-chart/renderer/ legend.js

96.95% Statements 318/328
88.8% Branches 222/250
100% Functions 31/31
96.92% Lines 315/325
11 statements, 6 functions, 9 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          349× 349× 349× 349× 349×   349×     349× 349× 349×   351× 25×   326× 326× 326×   53× 53× 14×   14×   14× 14× 14× 54× 54×               392× 392× 392× 392× 392× 392× 300×     392× 3258× 3258× 3220×       392×         407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 152×     255×   407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 407× 3389× 3389×   3389× 3389× 3389×   3389× 3389× 3389× 3389× 3389× 3389×   3389× 3389× 2256× 2256× 23× 23× 23× 23× 16× 16× 16×       23× 23× 23× 23×   2256×     2256× 2256×   2256×     1133× 70× 70×   1133× 1133× 134× 134× 51×   134× 134× 134×   1133× 1133× 1133×     1133×       407× 407× 255× 255× 255× 255× 255× 255×     152× 152× 152× 152× 152× 152× 132×     407× 407×   407× 380×     27×     23× 23×   23×   3389× 3389× 3389×                               255× 255× 255× 267× 267× 267× 267× 23× 23× 23×     255× 255× 36×   255× 255× 255× 255× 255× 255× 14× 23× 23× 20×   20× 20×     14×   14×   255×   3367× 2254×   1113× 70×   3297×   3367× 3367×   3367× 2254× 252×   252× 252× 252×     2002× 2002×       1113×   1113× 1113×   124× 117×   124×   124×     989× 989×     3367× 3367× 3367× 3367×     1113× 1063×     50×     282× 282×       219× 219×   219×   11× 11× 11×   11×   44× 44×   44×     11× 11×         15× 38× 38× 15×         94×   94× 94× 94× 94× 282× 282× 21× 21× 15× 15× 15× 15×         15× 15× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14×             94×   93×   94×   14× 14× 10× 10×     10×                 3272×   351×        
/* 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 __());
    };
})();
define(["require", "exports", "@syncfusion/ej2-base", "../model/acc-base", "../../common/legend/legend", "@syncfusion/ej2-svg-base", "../../common/utils/helper", "../../common/utils/helper", "../../common/model/constants"], function (require, exports, ej2_base_1, acc_base_1, legend_1, ej2_svg_base_1, helper_1, helper_2, constants_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var AccumulationLegend = (function (_super) {
        __extends(AccumulationLegend, _super);
        function AccumulationLegend(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;
        }
        AccumulationLegend.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);
        };
        AccumulationLegend.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);
        };
        AccumulationLegend.prototype.mouseMove = function (e) {
            Eif (this.chart.legendSettings.visible && !this.chart.isTouch) {
                if (this.chart.accumulationHighlightModule && this.chart.highlightMode !== 'None') {
                    if (!this.chart.legendSettings.toggleVisibility) {
                        this.click(e);
                    }
                    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.accumulationHighlightModule.legendSelection(this.chart, 0, index, e.target, e.type);
                            break;
                        }
                    }
                }
            }
        };
        AccumulationLegend.prototype.mouseEnd = function (e) {
            if (this.chart.legendSettings.visible && this.chart.isTouch) {
                this.move(e);
            }
        };
        AccumulationLegend.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++) {
                var seriesType = series[i].type;
                if (seriesType === 'Pie' || seriesType === 'Doughnut') {
                    seriesType = (series[i].innerRadius !== '0' && series[i].innerRadius !== '0%') ?
                        'Doughnut' : 'Pie';
                }
                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((chart.useGroupingSeparator && typeof point.x === 'number') ? chart.intl.formatNumber(point.x, { useGrouping: true })
                            : point.x.toString(), point.color, series[i].legendShape, point.visible, seriesType, point.legendImageUrl, null, null, point.index, series[i].index, null, point.x.toString()));
                    }
                }
                Iif (this.isReverse) {
                    this.legendCollections.reverse();
                }
            }
        };
        AccumulationLegend.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 = legendOption.originalText = ((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);
                            if ((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 = this.totalRowCount = 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);
            }
        };
        AccumulationLegend.prototype.getPageWidth = function (pageWidth) {
            var sum = 0;
            for (var i = 0; i < pageWidth.length; i++) {
                sum += pageWidth[i];
            }
            return sum;
        };
        AccumulationLegend.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':
                    if (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, legend.textWrap === 'AnyWhere', null, this.chart.themeStyle.legendLabelFont);
                    }
                    else {
                        option.textCollection.push(option.text);
                    }
                    option.textSize.height = (legendHeight * option.textCollection.length);
                    break;
            }
        };
        AccumulationLegend.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;
        };
        AccumulationLegend.prototype.getMaxColumn = function (columns, width, padding, rowWidth) {
            var maxPageColumn = padding;
            this.maxColumnWidth = Math.max.apply(null, columns);
            for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
                var column = columns_1[_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);
                    if (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;
        };
        AccumulationLegend.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);
        };
        AccumulationLegend.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;
            Eif (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);
            }
        };
        AccumulationLegend.prototype.isWithinBounds = function (previousBound, textWidth, legendBounds, shapeWidth) {
            if (!this.isRtlEnable) {
                return (previousBound + textWidth) > (legendBounds.x + legendBounds.width + shapeWidth);
            }
            else {
                return (previousBound - textWidth) < (legendBounds.x - shapeWidth);
            }
        };
        AccumulationLegend.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;
            }
        };
        AccumulationLegend.prototype.getTitleRect = function (accumulation) {
            Eif (!accumulation.title) {
                return null;
            }
            var titleSize = ej2_svg_base_1.measureText(accumulation.title, accumulation.titleStyle, this.chart.themeStyle.legendTitleFont);
            this.titleRect = new ej2_svg_base_1.Rect(accumulation.availableSize.width / 2 - titleSize.width / 2, accumulation.margin.top, titleSize.width, titleSize.height);
        };
        AccumulationLegend.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;
        };
        AccumulationLegend.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 = acc_base_1.pointByIndex(pointIndex, currentSeries.points);
                        var legendOption = this.legendByIndex(pointIndex, this.legendCollections);
                        var legendClickArgs = {
                            legendText: legendOption.text, legendShape: legendOption.shape,
                            chart: chart.isBlazor ? {} : chart, series: currentSeries, point: point,
                            name: constants_1.legendClick, cancel: false
                        };
                        this.chart.trigger(constants_1.legendClick, legendClickArgs);
                        if (!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.removeSvg();
                            helper_1.blazorTemplatesReset(chart);
                            this.chart.refreshPoints(currentSeries.points);
                            this.chart.calculateBounds();
                            this.chart.renderElements();
                        }
                    }
                    else if (this.chart.accumulationSelectionModule && !isNaN(pointIndex)) {
                        this.chart.accumulationSelectionModule.legendSelection(this.chart, 0, pointIndex, event.target, event.type);
                    }
                    else Eif (this.chart.accumulationHighlightModule && !isNaN(pointIndex)) {
                        this.chart.accumulationHighlightModule.legendSelection(this.chart, 0, pointIndex, event.target, event.type);
                    }
                }
            }
            if (targetId.indexOf(this.legendID + '_pageup') > -1) {
                this.changePage(event, true);
            }
            else if (targetId.indexOf(this.legendID + '_pagedown') > -1) {
                this.changePage(event, false);
            }
            chart.redraw = false;
        };
        AccumulationLegend.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);
            }
        };
        AccumulationLegend.prototype.sliceAnimate = function (element, isVisible) {
            if (!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';
                }
            });
        };
        AccumulationLegend.prototype.getModuleName = function () {
            return 'AccumulationLegend';
        };
        AccumulationLegend.prototype.destroy = function () {
            this.removeEventListener();
        };
        return AccumulationLegend;
    }(legend_1.BaseLegend));
    exports.AccumulationLegend = AccumulationLegend;
});