diff options
author | Rouslan Placella <rouslan@placella.com> | 2012-12-08 18:44:28 +0400 |
---|---|---|
committer | Rouslan Placella <rouslan@placella.com> | 2012-12-14 23:05:04 +0400 |
commit | 9775d295da6de183b34a20162a50598aaebecc6d (patch) | |
tree | 6b0a2ca3bd2ddacabc310af22e08f8ba8a846795 /js/jqplot | |
parent | 19437c442ffc390f81c2e27f4dac8b7d93ed34e4 (diff) |
Improved formatting and display of data in server status monitor
Diffstat (limited to 'js/jqplot')
-rw-r--r-- | js/jqplot/plugins/jqplot.byteFormatter.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/js/jqplot/plugins/jqplot.byteFormatter.js b/js/jqplot/plugins/jqplot.byteFormatter.js new file mode 100644 index 0000000000..75c7a194be --- /dev/null +++ b/js/jqplot/plugins/jqplot.byteFormatter.js @@ -0,0 +1,37 @@ +/* global PMA_messages */ +(function($) { + "use strict"; + var formatByte = function (val, index) { + var units = [ + PMA_messages.strB, + PMA_messages.strKiB, + PMA_messages.strMiB, + PMA_messages.strGiB, + PMA_messages.strTiB, + PMA_messages.strPiB, + PMA_messages.strEiB + ]; + while (val >= 1024 && index <= 6) { + val /= 1024; + index++; + } + var format = '%.1f'; + if (Math.floor(val) === val) { + format = '%.0f'; + } + return $.jqplot.sprintf( + format + ' ' + units[index], val + ); + }; + $.jqplot.byteFormatter = function (index) { + index = index || 0; + return function (format, val) { + if (typeof val === 'number') { + val = parseFloat(val, 10) || 0; + return formatByte(val, index); + } else { + return String(val); + } + }; + }; +})(jQuery); |