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

97.18% Statements 138/142
91.18% Branches 62/68
100% Functions 16/16
97.1% Lines 134/138
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          59×   385× 385× 385× 385× 385× 385× 385× 385× 385× 385× 385× 385× 385× 385× 385× 385× 385×   385× 385× 385× 95×     290×     385× 385× 385× 67× 67×   318× 28× 28× 28×   385× 385× 385× 385× 385× 385× 385× 385× 385× 385× 28× 28×   385× 385× 385× 385×   388×   385× 385× 385× 385× 385× 20×   385× 385× 385× 385× 385× 385×     21×   21× 21× 21×         21× 21× 21× 21× 21×   21× 21× 21× 21×                   21× 21× 21× 21× 21× 21× 21× 21× 18× 18×           18×         18× 18× 18×       21× 21× 21×       21×       21×         36× 36×   3436×          
/* 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", "./triangular-base"], function (require, exports, ej2_svg_base_1, helper_1, triangular_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var FunnelSeries = (function (_super) {
        __extends(FunnelSeries, _super);
        function FunnelSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        FunnelSeries.prototype.getSegmentData = function (point, series, chart) {
            var lineWidth;
            var topRadius;
            var bottomRadius;
            var endTop;
            var endBottom;
            var minRadius;
            var endMin;
            var bottomY;
            var area = series.triangleSize;
            var offset = 0;
            var extraSpace = (chart.initialClipRect.width - series.triangleSize.width) / 2;
            var emptySpaceAtLeft = extraSpace + chart.initialClipRect.x;
            var seriesTop = chart.initialClipRect.y + (chart.initialClipRect.height - area.height) / 2;
            var top = point.yRatio * area.height;
            var bottom = top + point.heightRatio * area.height;
            var neckSize = series.neckSize;
            lineWidth = neckSize.width + (area.width - neckSize.width) * ((area.height - neckSize.height - top) /
                (area.height - neckSize.height));
            topRadius = (area.width / 2) - lineWidth / 2;
            endTop = topRadius + lineWidth;
            if (bottom > area.height - neckSize.height || area.height === neckSize.height) {
                lineWidth = neckSize.width;
            }
            else {
                lineWidth = neckSize.width + (area.width - neckSize.width) *
                    ((area.height - neckSize.height - bottom) / (area.height - neckSize.height));
            }
            bottomRadius = (area.width / 2) - (lineWidth / 2);
            endBottom = bottomRadius + lineWidth;
            if (top >= area.height - neckSize.height) {
                topRadius = bottomRadius = minRadius = (area.width / 2) - neckSize.width / 2;
                endTop = endBottom = endMin = (area.width / 2) + neckSize.width / 2;
            }
            else if (bottom > (area.height - neckSize.height)) {
                minRadius = bottomRadius = (area.width / 2) - lineWidth / 2;
                endMin = endBottom = minRadius + lineWidth;
                bottomY = area.height - neckSize.height;
            }
            top += seriesTop;
            bottom += seriesTop;
            bottomY += seriesTop;
            var line1 = { x: emptySpaceAtLeft + offset + topRadius, y: top };
            var line2 = { x: emptySpaceAtLeft + offset + endTop, y: top };
            var line4 = { x: emptySpaceAtLeft + offset + endBottom, y: bottom };
            var line5 = { x: emptySpaceAtLeft + offset + bottomRadius, y: bottom };
            var line3 = { x: emptySpaceAtLeft + offset + endBottom, y: bottom };
            var line6 = { x: emptySpaceAtLeft + offset + bottomRadius, y: bottom };
            if (bottomY) {
                line3 = { x: emptySpaceAtLeft + offset + endMin, y: bottomY };
                line6 = { x: emptySpaceAtLeft + offset + minRadius, y: bottomY };
            }
            var polygon = [line1, line2, line3, line4, line5, line6];
            this.setLabelLocation(series, point, polygon);
            var direction = this.findPath(polygon, point, series);
            return direction;
        };
        FunnelSeries.prototype.renderPoint = function (point, series, chart, options, seriesGroup, redraw, previousRadius, previousCenter, pointAnimation) {
            if (!point.visible) {
                helper_1.removeElement(options.id);
                return null;
            }
            var previousDirection;
            var direction = this.getSegmentData(point, series, chart);
            point.midAngle = 0;
            options.d = direction;
            if (pointAnimation && document.getElementById(options.id)) {
                previousDirection = document.getElementById(options.id).getAttribute('d');
            }
            var element = chart.renderer.drawPath(options);
            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.setAttribute('aria-label', series.accessibility.accessibilityDescription ? series.accessibility.accessibilityDescription : (point.x + ':' + point.y + '%. ' + series.name));
            helper_1.appendChildElement(false, seriesGroup, element, redraw, pointAnimation ? pointAnimation : undefined, pointAnimation ? 'x' : undefined, pointAnimation ? 'y' : undefined, undefined, pointAnimation ? previousDirection : undefined, undefined, undefined, undefined, pointAnimation ? chart.duration : undefined);
            if (point.isExplode) {
                chart.accBaseModule.explodePoints(point.index, chart, true);
            }
        };
        FunnelSeries.prototype.renderTrapezoidalFunnel = function (series, points, chart, options, seriesGroup, redraw) {
            var funnelWidth = series.triangleSize.width;
            var funnelHeight = series.triangleSize.height;
            var horizontalMargin = (chart.initialClipRect.width - funnelWidth) / 2;
            var leftMargin = horizontalMargin + chart.initialClipRect.x;
            var funnelTop = chart.initialClipRect.y + (chart.initialClipRect.height - funnelHeight) / 2;
            var maxPointValue = Math.max.apply(Math, points.map(function (d) { return d.y; }));
            var barPadding = 10;
            var currentVerticalOffset = 0;
            var polygonGroup = redraw ? helper_1.getElement(chart.element.id + '_Series_' + series.index + '_Polygon') :
                chart.renderer.createGroup({ id: chart.element.id + '_Series_' + series.index + '_Polygon' });
            for (var i = 0; i < series.points.length; i++) {
                var point = series.points[i];
                var pathOption = options[point.index];
                Iif (!point.visible) {
                    helper_1.removeElement(pathOption.id);
                    helper_1.removeElement(pathOption.id + '_polygon');
                    continue;
                }
                var availableHeight = funnelHeight - barPadding * (points.length - 1);
                var barHeight = availableHeight / points.length;
                var barWidth = funnelWidth * (point.y / maxPointValue);
                var visiblePointIndex = points.indexOf(point);
                var nextBarWidth = visiblePointIndex < points.length - 1 ?
                    funnelWidth * (points[visiblePointIndex + 1].y / maxPointValue) : 0;
                var x = leftMargin + (funnelWidth - barWidth) / 2;
                var y = funnelTop + currentVerticalOffset;
                var cornerRadius = Math.min(series.borderRadius, barHeight / 2);
                var rectPath = 'M' + (x + cornerRadius) + ' ' + y + ' ' +
                    'L' + (x + barWidth - cornerRadius) + ' ' + y + ' ' +
                    'A' + cornerRadius + ' ' + cornerRadius + ' 0 0 1 ' + (x + barWidth) + ' ' + (y + cornerRadius) + ' ' +
                    'L' + (x + barWidth) + ' ' + (y + barHeight - cornerRadius) + ' ' +
                    'A' + cornerRadius + ' ' + cornerRadius + ' 0 0 1 ' + (x + barWidth - cornerRadius) + ' ' + (y + barHeight) + ' ' +
                    'L' + (x + cornerRadius) + ' ' + (y + barHeight) + ' ' +
                    'A' + cornerRadius + ' ' + cornerRadius + ' 0 0 1 ' + x + ' ' + (y + barHeight - cornerRadius) + ' ' +
                    'L' + x + ' ' + (y + cornerRadius) + ' ' +
                    'A' + cornerRadius + ' ' + cornerRadius + ' 0 0 1 ' + (x + cornerRadius) + ' ' + y + ' ' +
                    'Z';
                point.midAngle = 0;
                pathOption.d = rectPath;
                var element = chart.renderer.drawPath(pathOption);
                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.setAttribute('aria-label', series.accessibility.accessibilityDescription ? series.accessibility.accessibilityDescription : (point.x + ':' + point.y + '%. ' + series.name));
                helper_1.appendChildElement(false, seriesGroup, element, redraw);
                if (visiblePointIndex < points.length - 1) {
                    var polygonOption = new ej2_svg_base_1.PathOption(pathOption.id + '_polygon', this.lightenColor(pathOption.fill), pathOption['stroke-width'] * 0.4, this.lightenColor(pathOption.stroke), pathOption.opacity, pathOption['stroke-dasharray'], '');
                    var trapezoidPoints = [
                        [(funnelWidth - barWidth) / 2 + leftMargin + cornerRadius, y + barHeight],
                        [(funnelWidth + barWidth) / 2 + leftMargin - cornerRadius, y + barHeight],
                        [(funnelWidth + nextBarWidth) / 2 + leftMargin, y + barHeight + barPadding],
                        [(funnelWidth - nextBarWidth) / 2 + leftMargin, y + barHeight + barPadding]
                    ];
                    var trapezoidPath = '' +
                        'M' + trapezoidPoints[0][0] + ' ' + trapezoidPoints[0][1] + ' ' +
                        'L' + trapezoidPoints[1][0] + ' ' + trapezoidPoints[1][1] + ' ' +
                        'L' + trapezoidPoints[2][0] + ' ' + trapezoidPoints[2][1] + ' ' +
                        'L' + trapezoidPoints[3][0] + ' ' + trapezoidPoints[3][1] + ' ' + 'Z';
                    polygonOption.d = trapezoidPath;
                    var polygon = chart.renderer.drawPath(polygonOption);
                    helper_1.appendChildElement(false, polygonGroup, polygon, redraw);
                }
                else {
                    helper_1.removeElement(pathOption.id + '_polygon');
                }
                currentVerticalOffset += barHeight + barPadding;
                point.region = new ej2_svg_base_1.Rect(x, y, barWidth, barHeight);
                point.symbolLocation = {
                    x: point.region.x + point.region.width / 2,
                    y: point.region.y + point.region.height / 2
                };
                point.labelOffset = {
                    x: point.symbolLocation.x + point.region.width / 2,
                    y: point.symbolLocation.y + point.region.height / 2
                };
                Iif (point.isExplode) {
                    chart.accBaseModule.explodePoints(point.index, chart, true);
                }
            }
            helper_1.appendChildElement(false, chart.getSeriesElement(), seriesGroup, redraw);
            helper_1.appendChildElement(false, chart.getSeriesElement(), polygonGroup, redraw);
        };
        FunnelSeries.prototype.lightenColor = function (color) {
            var rgbValue = helper_1.convertHexToColor(helper_1.colorNameToHex(color));
            return 'rgb(' + rgbValue.r + ',' + rgbValue.g + ',' + rgbValue.b + ',' + 0.4 + ')';
        };
        FunnelSeries.prototype.getModuleName = function () {
            return 'FunnelSeries';
        };
        FunnelSeries.prototype.destroy = function () {
        };
        return FunnelSeries;
    }(triangular_base_1.TriangularBase));
    exports.FunnelSeries = FunnelSeries;
});