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

98.96% Statements 95/96
93.18% Branches 41/44
100% Functions 17/17
98.92% Lines 92/93
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          45×   258× 258× 258× 258× 258× 258× 258× 258× 258× 258× 258× 258×       258×       258×       258×       258× 258× 258× 258×   50× 45×         16× 15× 15× 15×     16× 15× 15×       20× 20×   20× 20× 20× 20× 20× 20× 20× 20×       262×   258× 258× 258× 20×   258× 258× 258× 258× 258× 258× 258×     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", "./triangular-base"], function (require, exports, ej2_svg_base_1, helper_1, triangular_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PyramidSeries = (function (_super) {
        __extends(PyramidSeries, _super);
        function PyramidSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        PyramidSeries.prototype.getSegmentData = function (point, series, chart) {
            var area = series.triangleSize;
            var seriesTop = chart.initialClipRect.y + (chart.initialClipRect.height - area.height) / 2;
            var offset = 0;
            var extraSpace = (chart.initialClipRect.width - series.triangleSize.width) / 2;
            var emptySpaceAtLeft = extraSpace + chart.initialClipRect.x;
            var top = point.yRatio;
            var bottom = point.yRatio + point.heightRatio;
            var topRadius = 0.5 * (1 - point.yRatio);
            var bottomRadius = 0.5 * (1 - bottom);
            top += seriesTop / area.height;
            bottom += seriesTop / area.height;
            var line1 = {
                x: emptySpaceAtLeft + offset + topRadius * area.width,
                y: top * area.height
            };
            var line2 = {
                x: emptySpaceAtLeft + offset + (1 - topRadius) * area.width,
                y: top * area.height
            };
            var line3 = {
                x: emptySpaceAtLeft + offset + (1 - bottomRadius) * area.width,
                y: bottom * area.height
            };
            var line4 = {
                x: emptySpaceAtLeft + offset + bottomRadius * area.width,
                y: bottom * area.height
            };
            var polygon = [line1, line2, line3, line4];
            this.setLabelLocation(series, point, polygon);
            var direction = this.findPath(polygon, point, series);
            return direction;
        };
        PyramidSeries.prototype.initializeSizeRatio = function (points, series) {
            if (series.pyramidMode === 'Linear') {
                _super.prototype.initializeSizeRatio.call(this, points, series, true);
            }
            else {
                this.calculateSurfaceSegments(series);
            }
        };
        PyramidSeries.prototype.calculateSurfaceSegments = function (series) {
            var count = series.points.length;
            var sumOfValues = series.sumOfPoints;
            var y = [];
            var height = [];
            var gapRatio = Math.min(0, Math.max(series.gapRatio, 1));
            var gapHeight = series.points.length > 1 ? gapRatio / (count - 1) : 0;
            var preSum = this.getSurfaceHeight(0, sumOfValues);
            var currY = 0;
            for (var i = 0; i < count; i++) {
                if (series.points[i].visible) {
                    y[i] = currY;
                    height[i] = this.getSurfaceHeight(currY, Math.abs(series.points[i].y));
                    currY += height[i] + gapHeight * preSum;
                }
            }
            var coef = 1 / (currY - gapHeight * preSum);
            for (var i = 0; i < count; i++) {
                if (series.points[i].visible) {
                    series.points[i].yRatio = coef * y[i];
                    series.points[i].heightRatio = coef * height[i];
                }
            }
        };
        PyramidSeries.prototype.getSurfaceHeight = function (y, surface) {
            var result = this.solveQuadraticEquation(1, 2 * y, -surface);
            return result;
        };
        PyramidSeries.prototype.solveQuadraticEquation = function (a, b, c) {
            var root1;
            var root2;
            var d = b * b - 4 * a * c;
            Eif (d >= 0) {
                var sd = Math.sqrt(d);
                root1 = (-b - sd) / (2 * a);
                root2 = (-b + sd) / (2 * a);
                return Math.max(root1, root2);
            }
            return 0;
        };
        PyramidSeries.prototype.renderPoint = function (point, series, chart, options, seriesGroup, redraw, previousRadius, previousCenter, pointAnimation) {
            if (!point.visible) {
                ej2_svg_base_1.removeElement(options.id);
                return null;
            }
            var previousDirection;
            options.d = this.getSegmentData(point, series, chart);
            if (pointAnimation && document.getElementById(options.id)) {
                previousDirection = document.getElementById(options.id).getAttribute('d');
            }
            point.midAngle = 0;
            var element = chart.renderer.drawPath(options);
            element.setAttribute('role', 'img');
            element.setAttribute('tabindex', point.index === 0 ? '0' : '-1');
            element.setAttribute('aria-label', (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);
            }
        };
        PyramidSeries.prototype.getModuleName = function () {
            return 'PyramidSeries';
        };
        PyramidSeries.prototype.destroy = function () {
        };
        return PyramidSeries;
    }(triangular_base_1.TriangularBase));
    exports.PyramidSeries = PyramidSeries;
});