pub/fnordmetric.js in fnordmetric-0.5.8 vs pub/fnordmetric.js in fnordmetric-0.5.9

- old
+ new

@@ -64,10 +64,30 @@ } else { return value.toFixed(0); } } + function formatTimeValue(value){ + if (value < 60){ + return parseFloat(value).toFixed(1) + 's'; + } else if(value<3600){ + return parseFloat(value/60).toFixed(1) + 'm'; + } else if(value<(3600*24)){ + return parseFloat(value/3600).toFixed(1) + 'h'; + } else { + return parseFloat(value/(3600*24)).toFixed(1) + 'd'; + } + } + + function formatGaugeValue(gauge_key, value){ + if(gauge_key.slice(0,8) === '__time__'){ + return formatTimeValue(value); + } else { + return formatValue(value); + } + } + function getNextWidgetUID(){ return (currentWidgetUID += 1); } var toplistWidget = function(){ @@ -135,11 +155,11 @@ var _elem = $('.toplist_inner', opts.elem).removeClass('loading').html(''); $(gdata.values).each(function(n, _gd){ var _perc = (parseInt(gdata.values[n][1]) / parseFloat(gdata.count))*100; var _item = $('<div class="toplist_item"><div class="title"></div><div class="value"></div><div class="percent"></div></div>'); $('.title', _item).html(gdata.values[n][0]); - $('.value', _item).html(formatValue(parseInt(gdata.values[n][1]))); + $('.value', _item).html(formatGaugeValue(gkey, parseInt(gdata.values[n][1]))); $('.percent', _item).html(_perc.toFixed(1) + '%'); _elem.append(_item); }); } @@ -266,10 +286,10 @@ if(target_val > current_val){ still_running = true; var new_val = current_val+diff; if(new_val > target_val){ new_val = target_val; } $(this).attr('data-current', new_val); - $('.value', this).html(formatValue(new_val)); + $('.value', this).html(formatGaugeValue($(this).attr('rel'), new_val)); } }); if(still_running){ (function(df){ window.setTimeout(function(){ updateDisplay(opts, df); }, 30);