Blame view

flaskr/static/js/plots/utils.js 655 Bytes
701dbf83   Antoine Goutenoir   feat: integrate t...
1
2
3
/** POLYFILLS **/
Math.log10 = Math.log10 || function(x) { return Math.log(x) * Math.LOG10E; };

289db173   Antoine Goutenoir   feat: add the dis...
4
5
6
Math.TAU = Math.TAU || Math.PI * 2;


701dbf83   Antoine Goutenoir   feat: integrate t...
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
/**
 * Useful for axes' domains on plots.
 * @param value
 * @returns {number}
 */
const ceil_value_to_magnitude = function (value) {
    let sign = 1;
    if (value < 0) {
        value = Math.abs(value);
        sign = -1;
    }
    if (value < 1) {
        return sign;
    }

    const low = Math.pow(10, Math.floor(Math.log10(value)));

    let cursor = low;
    let noloop = 0;
    while ((cursor < value) && (noloop <= 100)) {
        cursor += 0.1 * low;
        noloop += 1;
    }

    return sign * cursor;
};