all files / circular-gauge/axes/ gradient.js

96.43% Statements 108/112
89.92% Branches 116/129
84.62% Functions 22/26
96.23% Lines 102/106
5 statements, 2 functions, 11 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    26× 26× 26×       206× 206× 206× 206×                                                                                 662×   97×                               97×   97× 97×       97×         97× 97×             97× 97× 97×   58× 58× 58× 100×           100× 100×   58×   15× 15× 15× 15×                                             15× 15× 15×   54× 54× 108×           108×   54×   2125× 2125×   112× 97×     15×   112×     2013×   112×   1667×   653×        
/* 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;
    Iif (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) Eif (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", "@syncfusion/ej2-svg-base"], function (require, exports, ej2_base_1, ej2_svg_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ColorStop = (function (_super) {
        __extends(ColorStop, _super);
        function ColorStop() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property('#000000')
        ], ColorStop.prototype, "color", void 0);
        __decorate([
            ej2_base_1.Property(1)
        ], ColorStop.prototype, "opacity", void 0);
        __decorate([
            ej2_base_1.Property('0%')
        ], ColorStop.prototype, "offset", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], ColorStop.prototype, "style", void 0);
        return ColorStop;
    }(ej2_base_1.ChildProperty));
    exports.ColorStop = ColorStop;
    var GradientPosition = (function (_super) {
        __extends(GradientPosition, _super);
        function GradientPosition() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property('0%')
        ], GradientPosition.prototype, "x", void 0);
        __decorate([
            ej2_base_1.Property('0%')
        ], GradientPosition.prototype, "y", void 0);
        return GradientPosition;
    }(ej2_base_1.ChildProperty));
    exports.GradientPosition = GradientPosition;
    var LinearGradient = (function (_super) {
        __extends(LinearGradient, _super);
        function LinearGradient() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property(null)
        ], LinearGradient.prototype, "startValue", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], LinearGradient.prototype, "endValue", void 0);
        __decorate([
            ej2_base_1.Collection([{ color: '#000000', opacity: 1, offset: '0%', style: '' }], ColorStop)
        ], LinearGradient.prototype, "colorStop", void 0);
        return LinearGradient;
    }(ej2_base_1.ChildProperty));
    exports.LinearGradient = LinearGradient;
    var RadialGradient = (function (_super) {
        __extends(RadialGradient, _super);
        function RadialGradient() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property('0%')
        ], RadialGradient.prototype, "radius", void 0);
        __decorate([
            ej2_base_1.Complex({ x: '0%', y: '0%' }, GradientPosition)
        ], RadialGradient.prototype, "outerPosition", void 0);
        __decorate([
            ej2_base_1.Complex({ x: '0%', y: '0%' }, GradientPosition)
        ], RadialGradient.prototype, "innerPosition", void 0);
        __decorate([
            ej2_base_1.Collection([{ color: '#000000', opacity: 1, offset: '0%', style: '' }], ColorStop)
        ], RadialGradient.prototype, "colorStop", void 0);
        return RadialGradient;
    }(ej2_base_1.ChildProperty));
    exports.RadialGradient = RadialGradient;
    var Gradient = (function () {
        function Gradient(gauge) {
            this.gauge = gauge;
        }
        Gradient.prototype.calculateLinearGradientPosition = function (element, name, direction) {
            var linearPosition = {
                id: name,
                x1: (ej2_base_1.isNullOrUndefined(element.linearGradient.startValue) && name.indexOf('range') !== -1
                    ? (direction === 'right' ? '100%' : '0%')
                    : (!ej2_base_1.isNullOrUndefined(element.linearGradient.startValue) ? ((element.linearGradient.startValue.indexOf('%') === -1 ?
                        element.linearGradient.startValue :
                        parseFloat(element.linearGradient.startValue).toString()) + '%') : '0%')),
                x2: (ej2_base_1.isNullOrUndefined(element.linearGradient.endValue) && name.indexOf('range') !== -1 ?
                    (direction === 'left' ? '100%' : '0%') :
                    (!ej2_base_1.isNullOrUndefined(element.linearGradient.endValue) ? ((element.linearGradient.endValue.indexOf('%') === -1 ?
                        element.linearGradient.endValue : parseFloat(element.linearGradient.endValue).toString()) + '%') : '100%')),
                y1: (ej2_base_1.isNullOrUndefined(element.linearGradient.startValue) && name.indexOf('range') !== -1
                    ? (direction === 'bottom' ? '100%' : '0%') : '0%'),
                y2: (ej2_base_1.isNullOrUndefined(element.linearGradient.endValue) && name.indexOf('range') !== -1
                    ? (direction === 'top' ? '100%' : '0%') : '0%')
            };
            return linearPosition;
        };
        Gradient.prototype.getLinearGradientColor = function (element, index, direction, rangeIndex) {
            var render = new ej2_svg_base_1.SvgRenderer('');
            var colors = (ej2_base_1.isNullOrUndefined(element.linearGradient.startValue) &&
                ej2_base_1.isNullOrUndefined(element.linearGradient.endValue) && !ej2_base_1.isNullOrUndefined(rangeIndex)) ?
                this.getCircularGradientColor(element.linearGradient.colorStop, index) :
                this.getGradientColor(element.linearGradient.colorStop);
            var name = (ej2_base_1.isNullOrUndefined(element.linearGradient.startValue) &&
                ej2_base_1.isNullOrUndefined(element.linearGradient.endValue) && !ej2_base_1.isNullOrUndefined(rangeIndex)) ?
                '_' + this.gauge.svgObject.id + '_range_' +
                    rangeIndex + '_color_' + index + '_' + 'linearGradient'
                : '_' + this.gauge.svgObject.id + '_' + this.gauge.gradientCount + '_' + 'linearGradient';
            var gradientPosition = this.calculateLinearGradientPosition(element, name, direction);
            gradientPosition = {
                id: gradientPosition.id,
                x1: gradientPosition.x1,
                x2: gradientPosition.x2,
                y1: gradientPosition.y1,
                y2: gradientPosition.y2
            };
            var def = render.drawGradient('linearGradient', gradientPosition, colors);
            this.gauge.svgObject.appendChild(def);
            return 'url(#' + name + ')';
        };
        Gradient.prototype.getCircularGradientColor = function (colorStop, index) {
            var colors = [];
            var colorIndex = index;
            for (var j = colorIndex; j < (index === (colorStop.length - 1) ? index + 1 : index + 2); j++) {
                var color = {
                    color: colorStop[j].color,
                    colorStop: colorStop[j].offset,
                    opacity: colorStop[j].opacity ? colorStop[j].opacity.toString() : '1',
                    style: colorStop[j].style
                };
                colors.push(color);
                colorIndex++;
            }
            return colors;
        };
        Gradient.prototype.getRadialGradientColor = function (element) {
            var render = new ej2_svg_base_1.SvgRenderer('');
            var colors = this.getGradientColor(element.radialGradient.colorStop);
            var name = '_' + this.gauge.svgObject.id + '_' + this.gauge.gradientCount + '_' + 'radialGradient';
            var gradientPosition = {
                id: name,
                r: !ej2_base_1.isNullOrUndefined(element.radialGradient.radius) ?
                    (element.radialGradient.radius.indexOf('%') === -1 ?
                        element.radialGradient.radius :
                        parseFloat(element.radialGradient.radius).toString()) + '%' : '0%',
                cx: (!ej2_base_1.isNullOrUndefined(element.radialGradient.outerPosition) && !ej2_base_1.isNullOrUndefined(element.radialGradient.outerPosition.x)) ?
                    (element.radialGradient.outerPosition.x.indexOf('%') === -1 ?
                        element.radialGradient.outerPosition.x :
                        parseFloat(element.radialGradient.outerPosition.x).toString()) + '%' : '0%',
                cy: (!ej2_base_1.isNullOrUndefined(element.radialGradient.outerPosition) && !ej2_base_1.isNullOrUndefined(element.radialGradient.outerPosition.y)) ?
                    (element.radialGradient.outerPosition.y.indexOf('%') === -1 ?
                        element.radialGradient.outerPosition.y :
                        parseFloat(element.radialGradient.outerPosition.y).toString()) + '%' : '0%',
                fx: (!ej2_base_1.isNullOrUndefined(element.radialGradient.innerPosition) && !ej2_base_1.isNullOrUndefined(element.radialGradient.innerPosition.x)) ?
                    (element.radialGradient.innerPosition.x.indexOf('%') === -1 ?
                        element.radialGradient.innerPosition.x :
                        parseFloat(element.radialGradient.innerPosition.x).toString()) + '%' : '0%',
                fy: (!ej2_base_1.isNullOrUndefined(element.radialGradient.innerPosition) && !ej2_base_1.isNullOrUndefined(element.radialGradient.innerPosition.y)) ?
                    (element.radialGradient.innerPosition.y.indexOf('%') === -1 ?
                        element.radialGradient.innerPosition.y :
                        parseFloat(element.radialGradient.innerPosition.y).toString()) + '%' : '0%'
            };
            var def = render.drawGradient('radialGradient', gradientPosition, colors);
            this.gauge.svgObject.appendChild(def);
            return 'url(#' + name + ')';
        };
        Gradient.prototype.getGradientColor = function (colorStop) {
            var colors = [];
            for (var j = 0; j < colorStop.length; j++) {
                var color = {
                    color: colorStop[j].color,
                    colorStop: colorStop[j].offset,
                    opacity: colorStop[j].opacity ? colorStop[j].opacity.toString() : '1',
                    style: colorStop[j].style
                };
                colors.push(color);
            }
            return colors;
        };
        Gradient.prototype.getGradientColorString = function (element, index, direction, rangeIndex) {
            var gradientColor;
            if ((element.linearGradient && !ej2_base_1.isNullOrUndefined(element.linearGradient.colorStop)) ||
                (element.radialGradient && !ej2_base_1.isNullOrUndefined(element.radialGradient.colorStop))) {
                if (element.linearGradient) {
                    gradientColor = this.getLinearGradientColor(element, index, direction, rangeIndex);
                }
                else {
                    gradientColor = this.getRadialGradientColor(element);
                }
                this.gauge.gradientCount = this.gauge.gradientCount + 1;
            }
            else {
                return null;
            }
            return gradientColor;
        };
        Gradient.prototype.getModuleName = function () {
            return 'Gradient';
        };
        Gradient.prototype.destroy = function () {
            this.gauge = null;
        };
        return Gradient;
    }());
    exports.Gradient = Gradient;
});