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

98.77% Statements 80/81
96% Branches 48/50
100% Functions 19/19
98.75% Lines 79/80
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   804×     15165×       180×           8131×       180×           1470×       180×         6283×   24× 14× 14×     13× 13×     48× 10× 10×     46×   48×         14× 14× 14× 93× 93× 79×       29× 29× 29× 29× 29× 29×     29× 11×     18×   29× 24×         29× 29×   23×         84× 84×   108× 108× 108× 108× 108× 108×     432× 432× 375×     24× 24×        
define(["require", "exports", "@syncfusion/ej2-base", "../../common/utils/helper", "../model/acc-base"], function (require, exports, ej2_base_1, helper_1, acc_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var AccumulationBase = (function () {
        function AccumulationBase(accumulation) {
            this.accumulation = accumulation;
        }
        Object.defineProperty(AccumulationBase.prototype, "center", {
            get: function () {
                return this.pieCenter || (this.accumulation.visibleSeries[0].type === 'Pie' ?
                    this.accumulation.pieSeriesModule.center : null);
            },
            set: function (value) {
                this.pieCenter = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AccumulationBase.prototype, "radius", {
            get: function () {
                return this.pieRadius !== undefined ? this.pieRadius :
                    this.accumulation.pieSeriesModule.radius;
            },
            set: function (value) {
                this.pieRadius = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AccumulationBase.prototype, "labelRadius", {
            get: function () {
                return this.pieLabelRadius !== undefined ? this.pieLabelRadius :
                    this.accumulation.pieSeriesModule.labelRadius;
            },
            set: function (value) {
                this.pieLabelRadius = value;
            },
            enumerable: true,
            configurable: true
        });
        AccumulationBase.prototype.isCircular = function () {
            return this.accumulation.type === 'Pie';
        };
        AccumulationBase.prototype.processExplode = function (event) {
            if (event.target.id.indexOf('_Series_') > -1 || event.target.id.indexOf('_datalabel_') > -1) {
                var pointIndex = helper_1.indexFinder(event.target.id).point;
                if (isNaN(pointIndex) || (event.target.id.indexOf('_datalabel_') > -1 &&
                    this.accumulation.visibleSeries[0].points[pointIndex].labelPosition === 'Outside')) {
                    return null;
                }
                this.explodePoints(pointIndex, this.accumulation);
                this.deExplodeAll(pointIndex);
            }
        };
        AccumulationBase.prototype.invokeExplode = function () {
            if (this.accumulation.visibleSeries[0].explodeAll) {
                for (var _i = 0, _a = this.accumulation.visibleSeries[0].points; _i < _a.length; _i++) {
                    var point = _a[_i];
                    this.explodePoints(point.index, this.accumulation);
                }
            }
            else if (!ej2_base_1.isNullOrUndefined(this.accumulation.visibleSeries[0].explodeIndex)) {
                this.explodePoints(this.accumulation.visibleSeries[0].explodeIndex, this.accumulation);
            }
            if (this.accumulation.accumulationSelectionModule && this.accumulation.selectionMode !== 'None' &&
                this.accumulation.accumulationSelectionModule.selectedDataIndexes.length) {
                for (var _b = 0, _c = this.accumulation.accumulationSelectionModule.selectedDataIndexes; _b < _c.length; _b++) {
                    var index = _c[_b];
                    this.explodePoints(index.point, this.accumulation, true);
                    this.deExplodeAll(index.point);
                }
            }
        };
        AccumulationBase.prototype.deExplodeAll = function (index) {
            var pointId = this.accumulation.element.id + '_Series_0_Point_';
            var points = this.accumulation.visibleSeries[0].points;
            for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
                var currentPoint = points_1[_i];
                if (index !== currentPoint.index) {
                    this.deExplodeSlice(currentPoint.index, pointId, this.center);
                }
            }
        };
        AccumulationBase.prototype.explodePoints = function (index, chart, explode) {
            if (explode === void 0) { explode = false; }
            var pointId = this.accumulation.element.id + '_Series_0_Point_';
            var translate;
            var points = this.accumulation.visibleSeries[0].points;
            var point = acc_base_1.pointByIndex(index, this.accumulation.visibleSeries[0].points);
            Iif (ej2_base_1.isNullOrUndefined(point)) {
                return null;
            }
            if (!this.isCircular()) {
                translate = { x: chart.explodeDistance, y: 0 };
            }
            else {
                translate = helper_1.degreeToLocation(point.midAngle, chart.explodeDistance, this.center);
            }
            if (this.isExplode(pointId + index) || explode) {
                this.explodeSlice(index, translate, pointId, this.center || { x: 0, y: 0 });
            }
            else {
                this.deExplodeSlice(index, pointId, this.center);
            }
        };
        AccumulationBase.prototype.isExplode = function (id) {
            var element = helper_1.getElement(id);
            if (element && (element.getAttribute('transform') === 'translate(0, 0)' || element.getAttribute('transform') === null ||
                element.getAttribute('transform') === 'translate(0)')) {
                return true;
            }
            else {
                return false;
            }
        };
        AccumulationBase.prototype.deExplodeSlice = function (index, sliceId, center) {
            var position = 'translate(0, 0)';
            this.setTranslate(index, sliceId, position);
        };
        AccumulationBase.prototype.setTranslate = function (index, sliceId, position) {
            this.setElementTransform(sliceId + index, position);
            Eif (this.accumulation.visibleSeries[0].dataLabel.visible) {
                sliceId = this.accumulation.element.id + '_datalabel_Series_0_';
                this.setElementTransform(sliceId + 'shape_' + index, position);
                this.setElementTransform(sliceId + 'text_' + index, position);
                this.setElementTransform(sliceId + 'connector_' + index, position);
            }
        };
        AccumulationBase.prototype.setElementTransform = function (id, position) {
            var element = helper_1.getElement(id);
            if (element) {
                element.setAttribute('transform', position);
            }
        };
        AccumulationBase.prototype.explodeSlice = function (index, translate, sliceId, center) {
            var position = 'translate(' + (translate.x - center.x) + ', ' + (translate.y - center.y) + ')';
            this.setTranslate(index, sliceId, position);
        };
        return AccumulationBase;
    }());
    exports.AccumulationBase = AccumulationBase;
});