all files / accumulation-chart/renderer/ pie-series.js

97.81% Statements 134/137
92.31% Branches 96/104
100% Functions 21/21
97.76% Lines 131/134
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          847×   3768× 3768× 3768× 3768× 3768× 3768× 3768× 3768× 3768× 3768× 3768× 3768× 3768× 3628× 3628× 3628× 3628× 3628× 3628× 3628×     140× 140× 11×   140× 140× 140× 140× 21× 21×   140× 140×     136× 136× 136× 136× 136×   136× 136× 136× 136× 136× 136× 136× 136× 136× 136× 89× 89× 89×   89× 89×   38× 38×   89× 89× 73× 73× 73× 73× 42×   73× 73×                 47×             140× 140× 140× 140×       2134× 2134× 2134× 2134× 264× 264× 264× 264×     1870×   2134× 158×   2134×     140× 140× 140× 140×       5902× 208×   5694× 5694× 5694×   422× 422× 71× 71× 71× 71× 71× 71× 71×     3272×          
/* 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-svg-base", "../../common/utils/helper", "../renderer/pie-base", "@syncfusion/ej2-base"], function (require, exports, ej2_svg_base_1, helper_1, pie_base_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PieSeries = (function (_super) {
        __extends(PieSeries, _super);
        function PieSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        PieSeries.prototype.renderPoint = function (point, series, chart, option, seriesGroup, redraw, previousRadius, previousCenter, pointAnimation) {
            var sum = series.sumOfPoints;
            var seriesPoints = this.accumulation.visibleSeries[0].points;
            var borderRadius = series.borderRadius;
            point.startAngle = this.startAngle;
            var yValue = point.visible ? point.y : 0;
            var degree = (sum) ? ((Math.abs(yValue) / sum) * (this.totalAngle)) : null;
            var start = Math.PI / 180 * ((90 - (360 - this.startAngle)) - 90);
            this.radius = this.isRadiusMapped ? helper_1.stringToNumber(point.sliceRadius, this.seriesRadius) : this.radius;
            option.d = this.getPathOption(point, degree, this.startAngle % 360, borderRadius, seriesPoints);
            point.midAngle = (this.startAngle - (degree / 2)) % 360;
            point.endAngle = this.startAngle % 360;
            point.symbolLocation = helper_1.degreeToLocation(point.midAngle, (this.radius + this.innerRadius) / 2, this.center);
            if (!redraw) {
                var element = chart.renderer.drawPath(option);
                element.setAttribute('role', 'img');
                element.setAttribute('tabindex', point.index === 0 ? '0' : '-1');
                element.setAttribute('aria-label', (point.x + ': ' + point.y + '%. ' + series.name));
                seriesGroup.appendChild(element);
                point.degree = degree;
                point.start = start;
            }
            else {
                var element = chart.renderer.drawPath(option);
                if (!point.isExplode && pointAnimation) {
                    element.setAttribute('transform', 'translate(0, 0)');
                }
                element.setAttribute('role', 'img');
                element.setAttribute('tabindex', point.index === 0 ? '0' : '-1');
                element.setAttribute('aria-label', (point.x + ': ' + point.y + '%. ' + series.name));
                if (point.degree === undefined) {
                    point.degree = degree;
                    point.start = start;
                }
                seriesGroup.appendChild(element);
                this.refresh(point, degree, start, chart, option, borderRadius, seriesPoints, previousRadius, previousCenter, pointAnimation);
            }
        };
        PieSeries.prototype.findSeries = function (e, borderRadius) {
            var borderGap = 3;
            var width = 2;
            var radius = this.innerRadius === 0 ? this.radius + borderGap : this.innerRadius - borderGap;
            var innerRadius = this.innerRadius === 0 ? radius + width : radius - width;
            this.toggleInnerPoint(e, radius, innerRadius, borderRadius);
        };
        PieSeries.prototype.toggleInnerPoint = function (event, radius, innerRadius, borderRadius) {
            var target = event.target;
            var id = helper_1.indexFinder(target.id, true);
            var accumulationId = event.target.id.substring(0, (event.target.id.indexOf('Series') - 1));
            var borderElement = document.getElementById(this.accumulation.element.id + 'PointHover_Border');
            var createBorderEle;
            var seriesPoints = this.accumulation.visibleSeries[0].points;
            var seriesIndex = id.series;
            var pointIndex = id.point;
            var srcElem = helper_1.getElement(accumulationId + '_Series_' + seriesIndex + '_Point_' + pointIndex);
            if (!isNaN(id.series) && srcElem) {
                Eif (!ej2_base_1.isNullOrUndefined(seriesIndex) && !isNaN(seriesIndex) && !ej2_base_1.isNullOrUndefined(pointIndex) && !isNaN(pointIndex)) {
                    var point = this.accumulation.visibleSeries[0].points[pointIndex];
                    var opacity = srcElem.getAttribute('class') === accumulationId + '_ej2_deselected' ?
                        this.accumulation.tooltip.enable ? 0.5 : 0.3 : this.accumulation.tooltip.enable ? 0.5 : 1;
                    var innerPie = this.getPathArc(this.accumulation.pieSeriesModule.center, point.startAngle % 360, (point.startAngle + point.degree) % 360, radius, innerRadius, borderRadius, true, seriesPoints);
                    if ((borderElement) && (accumulationId === this.accumulation.element.id) &&
                        (borderElement.getAttribute('d') !== innerPie || point.isExplode)) {
                        borderElement.parentNode.removeChild(borderElement);
                        borderElement = null;
                    }
                    var seriousGroup = helper_1.getElement(accumulationId + '_Series_' + seriesIndex);
                    if (!borderElement && ((!point.isExplode) || (point.isExplode && event.type !== 'click'))) {
                        var path = new ej2_svg_base_1.PathOption(accumulationId + 'PointHover_Border', point.color, 1, point.color, opacity, '', innerPie);
                        createBorderEle = this.accumulation.renderer.drawPath(path);
                        createBorderEle.removeAttribute('transform');
                        if (this.accumulation.selectionMode !== 'None' && event.target.hasAttribute('class')) {
                            this.accumulation.accumulationSelectionModule.addSvgClass(createBorderEle, event.target.getAttribute('class'));
                        }
                        seriousGroup.appendChild(createBorderEle);
                        Iif (point.isExplode && createBorderEle) {
                            var borderExplode = srcElem.getAttribute('transform');
                            if (borderExplode) {
                                createBorderEle.setAttribute('transform', borderExplode);
                            }
                        }
                    }
                }
            }
            else if (borderElement) {
                this.removeBorder(borderElement, 1000);
                borderElement = null;
            }
        };
        PieSeries.prototype.removeBorder = function (borderElement, duration) {
            Eif (borderElement) {
                setTimeout(function () {
                    Eif (borderElement.parentNode) {
                        borderElement.parentNode.removeChild(borderElement);
                    }
                }, duration);
            }
        };
        PieSeries.prototype.refresh = function (point, degree, start, chart, option, borderRadius, seriesPoints, previousRadius, previouCenter, pointAnimation) {
            var _this = this;
            var seriesElement = helper_1.getElement(option.id);
            var duration = chart.duration ? chart.duration : 300;
            new ej2_base_1.Animation({}).animate(ej2_base_1.createElement('div'), {
                duration: duration,
                delay: 0,
                progress: function (args) {
                    var curentDegree = helper_1.linear(args.timeStamp, point.degree, (degree - point.degree), args.duration);
                    var currentStartAngle = helper_1.linear(args.timeStamp, point.start, start - point.start, args.duration);
                    currentStartAngle = ((currentStartAngle / (Math.PI / 180)) + 360) % 360;
                    if (previousRadius && previouCenter) {
                        var currentRadius = helper_1.linear(args.timeStamp, previousRadius, (_this.radius - previousRadius), args.duration);
                        var previouCenterx = helper_1.linear(args.timeStamp, previouCenter.x, (_this.center.x - previouCenter.x), args.duration);
                        var previouCentery = helper_1.linear(args.timeStamp, previouCenter.y, (_this.center.y - previouCenter.y), args.duration);
                        seriesElement.setAttribute('d', _this.getPathOption(point, curentDegree, currentStartAngle, borderRadius, seriesPoints, currentRadius, previouCenterx, previouCentery));
                    }
                    else {
                        seriesElement.setAttribute('d', _this.getPathOption(point, curentDegree, currentStartAngle, borderRadius, seriesPoints));
                    }
                    if (point.isExplode) {
                        chart.accBaseModule.explodePoints(point.index, chart, true, pointAnimation);
                    }
                    seriesElement.style.visibility = 'visible';
                },
                end: function () {
                    seriesElement.style.visibility = point.visible ? 'visible' : 'hidden';
                    seriesElement.setAttribute('d', option.d);
                    point.degree = degree;
                    point.start = start;
                }
            });
        };
        PieSeries.prototype.getPathOption = function (point, degree, startAngle, borderRadius, seriesPoints, previouRadius, previousCenterX, previousCenterY) {
            if (!degree) {
                return '';
            }
            var path = this.getPathArc(previousCenterX ? { x: previousCenterX, y: previousCenterY } : this.center, startAngle % 360, (startAngle + degree) % 360, this.isRadiusMapped ? helper_1.stringToNumber(point.sliceRadius, this.size / 2) : previouRadius ? previouRadius : this.radius, this.innerRadius, borderRadius, false, seriesPoints);
            this.startAngle += degree;
            return path;
        };
        PieSeries.prototype.animateSeries = function (accumulation, option, series, slice, borderRadius, seriesPoints) {
            var groupId = accumulation.element.id + 'SeriesGroup' + series.index;
            if (((series.animation.enable && ej2_base_1.animationMode !== 'Disable') || ej2_base_1.animationMode === 'Enable') && accumulation.animateSeries) {
                var clippath = accumulation.renderer.createClipPath({ id: groupId + '_clipPath' });
                var path = new ej2_svg_base_1.PathOption(groupId + '_slice', 'transparent', 1, 'transparent', 1, '', '');
                var clipslice = accumulation.renderer.drawPath(path);
                clippath.appendChild(clipslice);
                accumulation.svgObject.appendChild(clippath);
                slice.style.cssText = 'clip-path:url(#' + clippath.id + '); -webkit-clip-path:url(#' + clippath.id + ');';
                this.doAnimation(clipslice, series, slice, borderRadius, seriesPoints);
            }
        };
        PieSeries.prototype.getModuleName = function () {
            return 'PieSeries';
        };
        PieSeries.prototype.destroy = function () {
        };
        return PieSeries;
    }(pie_base_1.PieBase));
    exports.PieSeries = PieSeries;
});