web/fnordmetric-ui.js in fnordmetric-1.2.7 vs web/fnordmetric-ui.js in fnordmetric-1.2.9
- old
+ new
@@ -11381,20 +11381,32 @@
FnordMetric.util.decPrint = function(val){
return (val < 10 ? '0'+val : val);
}
-FnordMetric.util.formatValue = function(value){
+FnordMetric.util.formatValue = function(value, round_to){
if(value < 10){
- return value.toFixed(1);
+ if (typeof round_to != 'undefined')
+ return value.toFixed(round_to);
+ else
+ return value.toFixed(1);
}
if(value < 100){
- return value.toFixed(1);
+ if (typeof round_to != 'undefined')
+ return value.toFixed(round_to);
+ else
+ return value.toFixed(1);
} else if(value > 1000){
- return (value/1000.0).toFixed(1) + "k";
+ if (typeof round_to != 'undefined')
+ return (value/1000.0).toFixed(round_to) + "k";
+ else
+ return (value/1000.0).toFixed(1) + "k";
} else {
- return value.toFixed(0);
+ if (typeof round_to != 'undefined')
+ return value.toFixed(round_to);
+ else
+ return value.toFixed(0);
}
}
FnordMetric.util.formatTimeValue = function(value){
if (value < 60){
@@ -11495,10 +11507,17 @@
element: $('.fnordmetric_container', elem)[0],
padding: { top: 0.1, bottom: 0 },
stroke: true
};
+
+ if (elem.attr('data-y-max')) {
+ gconfig.max = parseFloat(elem.attr('data-y-max'));
+ } else {
+ delete gconfig.max;
+ }
+
if (elem.attr('data-cardinal') == "on") {
gconfig.interpolation = 'cardinal';
} else {
gconfig.interpolation = 'linear';
}
@@ -11659,11 +11678,11 @@
if (typeof FnordMetric.widgets == 'undefined')
FnordMetric.widgets = {};
FnordMetric.widgets.counter = function(elem){
- var gauge, at, refresh_timer, refresh_interval;
+ var gauge, at, scale_by, refresh_timer, refresh_interval;
var widget_key = elem.attr("data-widget-key");
function init() {
gauge = elem.attr('data-gauge');
@@ -11671,10 +11690,15 @@
return console.log("[FnordMetric] element is missing the data-gauge attribute");
at = elem.attr('data-at');
if (!at) at = "now";
+ if (scale_by = elem.attr('data-scale-by'))
+ scale_by = parseFloat(elem.attr('data-scale-by'));
+ else
+ scale_by = 1;
+
requestDataAsync();
if (refresh_interval = elem.attr('data-autoupdate'))
refresh_interval = parseFloat(refresh_interval);
@@ -11720,10 +11744,14 @@
var new_val = current_val + diff;
if((diff > 0) && (new_val > target_val)){ new_val = target_val; }
if((diff < 0) && (new_val < target_val)){ new_val = target_val; }
- var val_txt = FnordMetric.util.formatValue(new_val);
+ if (elem.attr('data-round-to'))
+ var val_txt = FnordMetric.util.formatValue(new_val * scale_by,
+ parseInt(elem.attr('data-round-to'), 10));
+ else
+ var val_txt = FnordMetric.util.formatValue(new_val * scale_by);
if (elem.attr('data-unit'))
val_txt += elem.attr('data-unit');
elem.attr('data-current', new_val);