all files / chart/series/ histogram-series.js

98.32% Statements 117/119
89.83% Branches 53/59
95% Functions 19/20
99.12% Lines 113/114
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          34×   40× 40× 15×     39× 39× 39× 2157× 2157×   39× 39× 39×     39× 39× 39× 39× 39× 2157× 2157×   39×     39× 39× 39× 39× 39× 39× 10319× 173×     173×         173× 173×   39×   10× 10× 10× 10× 10× 10× 10× 10× 10× 10× 10× 10× 4500× 4500×   4500× 4500×       15× 15× 15× 15× 15× 15× 15× 15× 15× 15× 15× 15× 15× 15× 15× 14× 7000× 7000×   7000× 7000× 7000×     15× 15×   15× 14×                 41538×          
/* 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", "../../common/utils/helper", "@syncfusion/ej2-svg-base", "./column-series", "@syncfusion/ej2-base"], function (require, exports, helper_1, ej2_svg_base_1, column_series_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var HistogramSeries = (function (_super) {
        __extends(HistogramSeries, _super);
        function HistogramSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        HistogramSeries.prototype.render = function (series) {
            _super.prototype.render.call(this, series);
            if (series.showNormalDistribution) {
                this.renderNormalDistribution(series);
            }
        };
        HistogramSeries.prototype.calculateBinInterval = function (yValues, series) {
            var mean = helper_1.sum(yValues) / yValues.length;
            var sumValue = 0;
            for (var _i = 0, yValues_1 = yValues; _i < yValues_1.length; _i++) {
                var value = yValues_1[_i];
                sumValue += (value - mean) * (value - mean);
            }
            series.histogramValues.mean = mean;
            series.histogramValues.sDValue = Math.sqrt(Math.abs(sumValue / yValues.length));
            series.histogramValues.binWidth = series.binInterval ||
                Math.round((3.5 * series.histogramValues.sDValue) / Math.pow(yValues.length, 1 / 3)) || 1;
        };
        HistogramSeries.prototype.processInternalData = function (data, series) {
            var _a;
            var updatedData = [];
            var yValues = [];
            var keys = Object.keys(data);
            for (var i = 0; i < keys.length; i++) {
                var key = keys[i];
                yValues.push(data[key][series.yName]);
            }
            series.histogramValues = {
                yValues: yValues
            };
            var min = Math.min.apply(Math, series.histogramValues.yValues);
            var max = Math.max.apply(Math, series.histogramValues.yValues);
            this.calculateBinInterval(series.histogramValues.yValues, series);
            var binWidth = series.histogramValues.binWidth;
            var yCount;
            for (var j = 0; j < data.length;) {
                yCount = yValues.filter(function (y) { return y >= min && y < (min + (binWidth)); }).length;
                Iif ((min + binWidth) === max) {
                    yCount += yValues.filter(function (y) { return y >= max; }).length;
                }
                updatedData.push((_a = {
                        'x': min + binWidth / 2
                    },
                    _a[series.yName] = yCount,
                    _a));
                min = min + binWidth;
                j += yCount;
            }
            return updatedData;
        };
        HistogramSeries.prototype.calculateBinValues = function (series) {
            var yValuesCount = series.histogramValues.yValues.length;
            var binWidth = series.histogramValues.binWidth;
            var mean = series.histogramValues.mean;
            var sDValue = series.histogramValues.sDValue;
            var pointsCount = 500;
            var min = series.xAxis.minimum ? parseInt(series.xAxis.minimum.toString(), 10) : series.xMin;
            var max = series.xAxis.maximum ? parseInt(series.xAxis.maximum.toString(), 10) : series.xMax;
            var points = series.points.length;
            var xValue;
            var yValue;
            var del = (max - min) / (pointsCount - 1);
            if (points) {
                for (var i = 0; i < pointsCount; i++) {
                    xValue = min + i * del;
                    yValue = (Math.exp(-(xValue - mean) * (xValue - mean) / (2 * sDValue * sDValue)) /
                        (sDValue * Math.sqrt(2 * Math.PI))) * binWidth * yValuesCount;
                    series.yMin = series.yMin > yValue ? yValue : series.yMin;
                    series.yMax = series.yMax < yValue ? yValue : series.yMax;
                }
            }
        };
        HistogramSeries.prototype.renderNormalDistribution = function (series) {
            var min = series.xAxis.actualRange.min;
            var max = series.xAxis.actualRange.max;
            var xValue;
            var pointLocation;
            var yValue;
            var direction = '';
            var startPoint = 'M';
            var yValuesCount = series.histogramValues.yValues.length;
            var binWidth = series.histogramValues.binWidth;
            var mean = series.histogramValues.mean;
            var sDValue = series.histogramValues.sDValue;
            var pointsCount = 500;
            var del = (max - min) / (pointsCount - 1);
            var points = series.points.length;
            if (points) {
                for (var i = 0; i < pointsCount; i++) {
                    xValue = min + i * del;
                    yValue = Math.exp(-(xValue - mean) * (xValue - mean) / (2 * sDValue * sDValue)) /
                        (sDValue * Math.sqrt(2 * Math.PI));
                    pointLocation = helper_1.getPoint(xValue, yValue * binWidth * yValuesCount, series.xAxis, series.yAxis, series.chart.requireInvertedAxis);
                    direction += startPoint + ' ' + (pointLocation.x) + ' ' + (pointLocation.y) + ' ';
                    startPoint = 'L';
                }
            }
            var distributionLine = series.chart.renderer.drawPath(new ej2_svg_base_1.PathOption(series.chart.element.id + '_Series_' + series.index + '_NDLine', 'transparent', 2, series.chart.themeStyle.histogram || series.chart.themeStyle.errorBar, series.opacity, series.dashArray, direction), new Int32Array([series.clipRect.x, series.clipRect.y]));
            distributionLine.style.visibility = (!series.chart.enableCanvas) ? ((((series.animation.enable && ej2_base_1.animationMode !== 'Disable') || ej2_base_1.animationMode === 'Enable') &&
                series.chart.animateSeries) ? 'hidden' : 'visible') : null;
            if (!series.chart.enableCanvas) {
                series.seriesElement.appendChild(distributionLine);
            }
        };
        HistogramSeries.prototype.doAnimation = function (series) {
            _super.prototype.doAnimation.call(this, series);
            Eif (series.showNormalDistribution) {
                helper_1.templateAnimate(series.seriesElement.lastElementChild, ((series.animation.duration === 0) ? 1000 : series.animation.duration), 500, 'FadeIn');
            }
        };
        HistogramSeries.prototype.updateDirection = function (series) {
            this.render(series);
            Eif (series.marker.visible) {
                helper_1.appendChildElement(series.chart.enableCanvas, series.chart.seriesElements, series.symbolElement, true);
            }
            Eif (series.marker.dataLabel.visible && series.chart.dataLabelModule) {
                series.chart.dataLabelCollections = [];
                series.chart.dataLabelModule.render(series, series.chart, series.marker.dataLabel);
                Eif (series.textElement) {
                    helper_1.appendChildElement(series.chart.enableCanvas, series.chart.dataLabelElements, series.shapeElement, true);
                    helper_1.appendChildElement(series.chart.enableCanvas, series.chart.dataLabelElements, series.textElement, true);
                }
            }
        };
        HistogramSeries.prototype.getModuleName = function () {
            return 'HistogramSeries';
        };
        HistogramSeries.prototype.destroy = function () {
        };
        return HistogramSeries;
    }(column_series_1.ColumnSeries));
    exports.HistogramSeries = HistogramSeries;
});