all files / range-navigator/utils/ helper.js

100% Statements 35/35
91.67% Branches 11/12
100% Functions 10/10
100% Lines 34/34
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   1782× 1782×   1782× 1782×   45× 45×   532× 532× 73570× 20403×           532×   28× 270×     68713× 68713× 68713× 68713× 68713×        
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function rangeValueToCoefficient(value, range, inversed) {
        var result = (value - range.min) / (range.delta);
        return inversed ? (1 - result) : result;
    }
    exports.rangeValueToCoefficient = rangeValueToCoefficient;
    function getXLocation(x, range, size, inversed) {
        x = rangeValueToCoefficient(x, range, inversed);
        return x * size;
    }
    exports.getXLocation = getXLocation;
    function getRangeValueXByPoint(value, size, range, inversed) {
        var actualValue = !inversed ? value / size : (1 - (value / size));
        return actualValue * (range.delta) + range.min;
    }
    exports.getRangeValueXByPoint = getRangeValueXByPoint;
    function getExactData(points, start, end) {
        var selectedData = [];
        points.map(function (point) {
            if (point.xValue >= start && point.xValue <= end) {
                selectedData.push({
                    'x': point.x,
                    'y': point.y
                });
            }
        });
        return selectedData;
    }
    exports.getExactData = getExactData;
    function getNearestValue(values, point) {
        return values.reduce(function (prev, curr) {
            return (Math.abs(curr - point) < Math.abs(prev - point) ? curr : prev);
        });
    }
    exports.getNearestValue = getNearestValue;
    var DataPoint = (function () {
        function DataPoint(x, y, xValue, yValue, visible) {
            Eif (visible === void 0) { visible = true; }
            this.x = x;
            this.y = y;
            this.xValue = xValue;
            this.visible = visible;
        }
        return DataPoint;
    }());
    exports.DataPoint = DataPoint;
});