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

95.6% Statements 152/159
88.24% Branches 120/136
100% Functions 21/21
95.51% Lines 149/156
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          984×   4458× 4458× 4458× 4458× 4458× 4458× 4458× 4458× 4458× 4458× 4458× 4458× 4458× 4301× 4301× 4301× 4301× 4301× 4301× 4301× 4301× 4301×     157× 157× 11×   157× 157× 157× 157× 157× 157× 18× 18×   157× 157×     159× 159× 159× 159× 53× 53×   53×   106× 106× 106× 106×   106×   106× 106× 106×   106× 106× 106× 106× 106× 106× 106×           106× 106× 106× 106×       98× 98× 98× 98×     38× 38×   38×   98× 98× 82× 82× 82× 82× 44×   82× 82×                       157× 157× 157× 157× 157×   157× 157×       2554× 2554× 2554× 2554× 330× 330× 330× 330×     2224×   2554× 197×   2554×     157× 157× 157× 157×       7012× 235×   6777×         6777× 6777×   527× 527× 129× 129× 129× 129× 129× 129× 129×     3988×          
/* 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[series.index].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', series.accessibility.accessibilityRole ? series.accessibility.accessibilityRole : 'img');
                element.setAttribute('tabindex', (point.index === 0 && series.accessibility.focusable) ? String(series.accessibility.tabIndex) : '-1');
                element.style.outline = 'none';
                element.setAttribute('stroke-linejoin', 'round');
                element.setAttribute('aria-label', series.accessibility.accessibilityDescription ? series.accessibility.accessibilityDescription : (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', series.accessibility.accessibilityRole ? series.accessibility.accessibilityRole : 'img');
                element.setAttribute('tabindex', (point.index === 0 && series.accessibility.focusable) ? String(series.accessibility.tabIndex) : '-1');
                element.style.outline = 'none';
                element.setAttribute('stroke-linejoin', 'round');
                element.setAttribute('aria-label', series.accessibility.accessibilityDescription ? series.accessibility.accessibilityDescription : (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, series);
            }
        };
        PieSeries.prototype.findSeries = function (e, borderRadius) {
            var target = e.target;
            var id = helper_1.indexFinder(target.id, true);
            var seriesIndex = id.series;
            if (isNaN(seriesIndex) || !this.accumulation.visibleSeries[seriesIndex]) {
                var borderElement = document.querySelector('[id$="_PointHover_Border"]');
                if (borderElement) {
                    this.removeBorder(borderElement, 1000);
                }
                return;
            }
            var currentSeries = this.accumulation.visibleSeries[seriesIndex];
            var borderGap = 3;
            var width = 2;
            var currentRadius = !ej2_base_1.isNullOrUndefined(currentSeries._calculatedRadius) ?
                currentSeries._calculatedRadius : this.radius;
            var currentInnerRadius = !ej2_base_1.isNullOrUndefined(currentSeries._calculatedInnerRadius) ?
                currentSeries._calculatedInnerRadius : this.innerRadius;
            var radius = currentInnerRadius === 0 ? currentRadius + borderGap : currentInnerRadius - borderGap;
            var innerRadius = currentInnerRadius === 0 ? radius + width : radius - width;
            this.toggleInnerPoint(e, radius, innerRadius, borderRadius, seriesIndex);
        };
        PieSeries.prototype.toggleInnerPoint = function (event, radius, innerRadius, borderRadius, hoverSeriesIndex) {
            var target = event.target;
            var id = helper_1.indexFinder(target.id, true);
            var accumulationId = target.id.substring(0, target.id.indexOf('Series') - 1);
            var seriesIndex = !isNaN(hoverSeriesIndex) ? hoverSeriesIndex : id.series;
            var pointIndex = id.point;
            var borderElement = document.getElementById(this.accumulation.element.id + "_Series_" + seriesIndex + "_PointHover_Border");
            Iif (isNaN(seriesIndex) || isNaN(pointIndex) || !this.accumulation.visibleSeries[seriesIndex]) {
                if (borderElement) {
                    this.removeBorder(borderElement, 1000);
                }
                return;
            }
            var currentSeries = this.accumulation.visibleSeries[seriesIndex];
            var seriesPoints = currentSeries.points;
            var srcElem = helper_1.getElement(accumulationId + "_Series_" + seriesIndex + "_Point_" + pointIndex);
            if (!srcElem) {
                Iif (borderElement) {
                    this.removeBorder(borderElement, 1000);
                }
                return;
            }
            var point = currentSeries.points[pointIndex];
            var opacity = (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)) {
                Eif (borderElement.parentNode) {
                    borderElement.parentNode.removeChild(borderElement);
                }
                borderElement = null;
            }
            var seriesGroup = helper_1.getElement(accumulationId + "_Series_" + seriesIndex);
            if (!borderElement && seriesGroup && ((!point.isExplode) || (point.isExplode && event.type !== 'click'))) {
                var path = new ej2_svg_base_1.PathOption(this.accumulation.element.id + "_Series_" + seriesIndex + "_PointHover_Border", point.color, 1, point.color, opacity, '', innerPie);
                var createBorderEle = this.accumulation.renderer.drawPath(path);
                createBorderEle.removeAttribute('transform');
                if (this.accumulation.selectionMode !== 'None' && target.hasAttribute('class')) {
                    this.accumulation.accumulationSelectionModule.addSvgClass(createBorderEle, target.getAttribute('class'));
                }
                seriesGroup.appendChild(createBorderEle);
                Iif (point.isExplode) {
                    var borderExplode = srcElem.getAttribute('transform');
                    if (borderExplode) {
                        createBorderEle.setAttribute('transform', borderExplode);
                    }
                }
            }
        };
        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, series) {
            var _this = this;
            var seriesElement = helper_1.getElement(option.id);
            var duration = chart.duration ? chart.duration : 300;
            var capturedRadius = series && !ej2_base_1.isNullOrUndefined(series._calculatedRadius) ? series._calculatedRadius : this.radius;
            var capturedInnerRadius = series && !ej2_base_1.isNullOrUndefined(series._calculatedInnerRadius) ? series._calculatedInnerRadius
                : this.innerRadius;
            var capturedCenter = this.center;
            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, (capturedRadius - previousRadius), args.duration);
                        var previouCenterx = helper_1.linear(args.timeStamp, previouCenter.x, (capturedCenter.x - previouCenter.x), args.duration);
                        var previouCentery = helper_1.linear(args.timeStamp, previouCenter.y, (capturedCenter.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, null, null, null, capturedRadius, capturedInnerRadius));
                    }
                    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, capturedRadius, capturedInnerRadius) {
            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 : !ej2_base_1.isNullOrUndefined(capturedRadius)
                    ? capturedRadius : this.radius, !ej2_base_1.isNullOrUndefined(capturedInnerRadius) ? capturedInnerRadius :
                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;
});