UNPKG

1.29 kBJavaScriptView Raw
1(function ($) {
2 'use strict';
3 var saturated = {
4 saturate: function (a) {
5 if (a === Infinity) {
6 return Number.MAX_VALUE;
7 }
8
9 if (a === -Infinity) {
10 return -Number.MAX_VALUE;
11 }
12
13 return a;
14 },
15 delta: function(min, max, noTicks) {
16 return ((max - min) / noTicks) === Infinity ? (max / noTicks - min / noTicks) : (max - min) / noTicks
17 },
18 multiply: function (a, b) {
19 return saturated.saturate(a * b);
20 },
21 // returns c * bInt * a. Beahves properly in the case where c is negative
22 // and bInt * a is bigger that Number.MAX_VALUE (Infinity)
23 multiplyAdd: function (a, bInt, c) {
24 if (isFinite(a * bInt)) {
25 return saturated.saturate(a * bInt + c);
26 } else {
27 var result = c;
28
29 for (var i = 0; i < bInt; i++) {
30 result += a;
31 }
32
33 return saturated.saturate(result);
34 }
35 },
36 // round to nearby lower multiple of base
37 floorInBase: function(n, base) {
38 return base * Math.floor(n / base);
39 }
40 };
41
42 $.plot.saturated = saturated;
43})(jQuery);