whychdw
2019-09-09 c0b9ce437d409b89ca0e5388344ca9c5a56d70a4
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
/* *
 *
 *  (c) 2010-2019 Torstein Honsi
 *
 *  License: www.highcharts.com/license
 *
 *  !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
 *
 * */
'use strict';
 
var _Globals = require('./Globals.js');
 
var _Globals2 = _interopRequireDefault(_Globals);
 
require('./Utilities.js');
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
var Axis = _Globals2.default.Axis,
    getMagnitude = _Globals2.default.getMagnitude,
    normalizeTickInterval = _Globals2.default.normalizeTickInterval,
    pick = _Globals2.default.pick;
/* ************************************************************************** *
 * Methods defined on the Axis prototype
 * ************************************************************************** */
/* eslint-disable valid-jsdoc */
/**
 * Set the tick positions of a logarithmic axis.
 *
 * @private
 * @function Highcharts.Axis#getLogTickPositions
 * @param {number} interval
 * @param {number} min
 * @param {number} max
 * @param {boolean} [minor]
 * @return {Array<number>}
 */
Axis.prototype.getLogTickPositions = function (interval, min, max, minor) {
    var axis = this,
        options = axis.options,
        axisLength = axis.len,
 
    // Since we use this method for both major and minor ticks,
    // use a local variable and return the result
    positions = [];
    // Reset
    if (!minor) {
        axis._minorAutoInterval = null;
    }
    // First case: All ticks fall on whole logarithms: 1, 10, 100 etc.
    if (interval >= 0.5) {
        interval = Math.round(interval);
        positions = axis.getLinearTickPositions(interval, min, max);
        // Second case: We need intermediary ticks. For example
        // 1, 2, 4, 6, 8, 10, 20, 40 etc.
    } else if (interval >= 0.08) {
        var roundedMin = Math.floor(min),
            intermediate,
            i,
            j,
            len,
            pos,
            lastPos,
            break2;
        if (interval > 0.3) {
            intermediate = [1, 2, 4];
            // 0.2 equals five minor ticks per 1, 10, 100 etc
        } else if (interval > 0.15) {
            intermediate = [1, 2, 4, 6, 8];
        } else {
            // 0.1 equals ten minor ticks per 1, 10, 100 etc
            intermediate = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        }
        for (i = roundedMin; i < max + 1 && !break2; i++) {
            len = intermediate.length;
            for (j = 0; j < len && !break2; j++) {
                pos = axis.log2lin(axis.lin2log(i) * intermediate[j]);
                // #1670, lastPos is #3113
                if (pos > min && (!minor || lastPos <= max) && lastPos !== undefined) {
                    positions.push(lastPos);
                }
                if (lastPos > max) {
                    break2 = true;
                }
                lastPos = pos;
            }
        }
        // Third case: We are so deep in between whole logarithmic values that
        // we might as well handle the tick positions like a linear axis. For
        // example 1.01, 1.02, 1.03, 1.04.
    } else {
        var realMin = axis.lin2log(min),
            realMax = axis.lin2log(max),
            tickIntervalOption = minor ? this.getMinorTickInterval() : options.tickInterval,
            filteredTickIntervalOption = tickIntervalOption === 'auto' ? null : tickIntervalOption,
            tickPixelIntervalOption = options.tickPixelInterval / (minor ? 5 : 1),
            totalPixelLength = minor ? axisLength / axis.tickPositions.length : axisLength;
        interval = pick(filteredTickIntervalOption, axis._minorAutoInterval, (realMax - realMin) * tickPixelIntervalOption / (totalPixelLength || 1));
        interval = normalizeTickInterval(interval, null, getMagnitude(interval));
        positions = axis.getLinearTickPositions(interval, realMin, realMax).map(axis.log2lin);
        if (!minor) {
            axis._minorAutoInterval = interval / 5;
        }
    }
    // Set the axis-level tickInterval variable
    if (!minor) {
        axis.tickInterval = interval;
    }
    return positions;
};
/**
 * @private
 * @function Highcharts.Axis#log2lin
 *
 * @param {number} num
 *
 * @return {number}
 */
Axis.prototype.log2lin = function (num) {
    return Math.log(num) / Math.LN10;
};
/**
 * @private
 * @function Highcharts.Axis#lin2log
 *
 * @param {number} num
 *
 * @return {number}
 */
Axis.prototype.lin2log = function (num) {
    return Math.pow(10, num);
};