all files / chart/axis/ logarithmic-axis.js

100% Statements 72/72
95.12% Branches 39/41
100% Functions 15/15
100% Lines 69/69
9 statements, 5 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        125×   262× 262× 262× 262×   272× 272× 272× 272× 272× 272× 272× 272× 272× 272× 272× 272×   262×       262×         206× 206× 206× 206× 824× 824×   821×   206×   272× 272× 272×   272× 272× 272×       272× 272× 272× 974× 972×     272× 262×     21177×          
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var 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 function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../axis/double-axis", "../../common/utils/helper", "../../common/utils/helper"], function (require, exports, double_axis_1, helper_1, helper_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Logarithmic = (function (_super) {
        __extends(Logarithmic, _super);
        function Logarithmic(chart) {
            return _super.call(this, chart) || this;
        }
        Logarithmic.prototype.calculateRangeAndInterval = function (size, axis) {
            this.calculateRange(axis, size);
            this.getActualRange(axis, size);
            this.calculateVisibleRange(size, axis);
            this.calculateVisibleLabels(axis, this.chart);
        };
        Logarithmic.prototype.getActualRange = function (axis, size) {
            this.initializeDoubleRange(axis);
            this.min = this.min < 0 ? 0 : this.min;
            var logStart = helper_2.logBase(this.min, axis.logBase);
            logStart = isFinite(logStart) ? logStart : this.min;
            var logEnd = helper_2.logBase(this.max, axis.logBase);
            logEnd = isFinite(logStart) ? logEnd : this.max;
            this.min = Math.floor(logStart / 1);
            this.max = Math.ceil(logEnd / 1);
            axis.actualRange.interval = axis.interval || this.calculateLogNiceInterval(this.max - this.min, size, axis);
            axis.actualRange.min = this.min;
            axis.actualRange.max = this.max;
            axis.actualRange.delta = this.max - this.min;
        };
        Logarithmic.prototype.calculateVisibleRange = function (size, axis) {
            axis.visibleRange = {
                interval: axis.actualRange.interval, max: axis.actualRange.max,
                min: axis.actualRange.min, delta: axis.actualRange.delta
            };
            if (axis.zoomFactor < 1 || axis.zoomPosition > 0) {
                axis.calculateVisibleRange(size);
                axis.visibleRange.interval = (axis.enableAutoIntervalOnZooming) ?
                    this.calculateLogNiceInterval(axis.doubleRange.delta, size, axis)
                    : axis.visibleRange.interval;
                axis.visibleRange.interval = Math.floor(axis.visibleRange.interval) === 0 ? 1 : Math.floor(axis.visibleRange.interval);
                axis.triggerRangeRender(this.chart, axis.visibleRange.min, axis.visibleRange.max, axis.visibleRange.interval);
            }
        };
        Logarithmic.prototype.calculateLogNiceInterval = function (delta, size, axis) {
            var actualDesiredIntervalsCount = helper_1.getActualDesiredIntervalsCount(size, axis);
            var niceInterval = delta;
            var minInterval = Math.pow(10, Math.floor(helper_2.logBase(niceInterval, 10)));
            for (var j = 0, len = axis.intervalDivs.length; j < len; j++) {
                var currentInterval = minInterval * axis.intervalDivs[j];
                if (actualDesiredIntervalsCount < (delta / currentInterval)) {
                    break;
                }
                niceInterval = currentInterval;
            }
            return niceInterval;
        };
        Logarithmic.prototype.calculateVisibleLabels = function (axis, chart) {
            var tempInterval = axis.visibleRange.min;
            axis.visibleLabels = [];
            if (axis.zoomFactor < 1 || axis.zoomPosition > 0) {
                tempInterval = axis.visibleRange.min - (axis.visibleRange.min % axis.visibleRange.interval);
            }
            var axisFormat = this.getFormat(axis);
            var isCustomFormat = axisFormat.match('{value}') !== null;
            axis.format = chart.intl.getNumberFormat({
                format: isCustomFormat ? '' : axisFormat,
                useGrouping: chart.useGroupingSeparator
            });
            axis.startLabel = axis.format(Math.pow(axis.logBase, axis.visibleRange.min));
            axis.endLabel = axis.format(Math.pow(axis.logBase, axis.visibleRange.max));
            for (; tempInterval <= axis.visibleRange.max; tempInterval += axis.visibleRange.interval) {
                if (helper_2.withIn(tempInterval, axis.visibleRange)) {
                    helper_1.triggerLabelRender(this.chart, tempInterval, this.formatValue(axis, isCustomFormat, axisFormat, Math.pow(axis.logBase, tempInterval)), axis.labelStyle, axis);
                }
            }
            if (axis.getMaxLabelWidth) {
                axis.getMaxLabelWidth(this.chart);
            }
        };
        Logarithmic.prototype.getModuleName = function () {
            return 'Logarithmic';
        };
        Logarithmic.prototype.destroy = function (chart) {
        };
        return Logarithmic;
    }(double_axis_1.Double));
    exports.Logarithmic = Logarithmic;
});