blob: 13280c67121363c08f2cf7650237604d008e2385 (
plain)
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
|
import $ from 'jquery';
/**
* jqplot formatter for byte values
*
* @package phpMyAdmin
*/
(function ($) {
'use strict';
var formatByte = function (value, index) {
var val = value;
var i = index;
var units = [
window.Messages.strB,
window.Messages.strKiB,
window.Messages.strMiB,
window.Messages.strGiB,
window.Messages.strTiB,
window.Messages.strPiB,
window.Messages.strEiB
];
while (val >= 1024 && i <= 6) {
val /= 1024;
i++;
}
var format = '%.1f';
if (Math.floor(val) === val) {
format = '%.0f';
}
return $.jqplot.sprintf(
format + ' ' + units[i], val
);
};
/**
* The index indicates what unit the incoming data will be in.
* 0 for bytes, 1 for kilobytes and so on...
*
* @param index
*
* @return {String}
*/
$.jqplot.byteFormatter = function (index) {
var i = index || 0;
return function (format, value) {
var val = value;
if (typeof val === 'number') {
val = parseFloat(val) || 0;
return formatByte(val, i);
} else {
return String(val);
}
};
};
}($));
|