Commit ee77fba9 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

implemented data-round-to for counters

parent 42f4aedb
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -69,6 +69,12 @@ These are the valid html attributes for counters:
      as cents, but want to display them as dollar/euro, use `data-scale-by="0.01"`
    </td>
  </tr>
  <tr>
    <th>data-round-to</th>
    <td>
      force rounding this value to the specified precision. e.g. 0 for integer / no floating point and 3 for three digits after the dot/comma.
    </td>
  </tr>
  <tr>
    <th>data-autoupdate</th>
    <td>
+17 −5
Original line number Diff line number Diff line
@@ -8,15 +8,27 @@ 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){
    if (typeof round_to != 'undefined')
      return value.toFixed(round_to);
    else
      return value.toFixed(1);
  }
  if(value < 100){
    if (typeof round_to != 'undefined')
      return value.toFixed(round_to);
    else
      return value.toFixed(1);
  } else if(value > 1000){
    if (typeof round_to != 'undefined')
      return (value/1000.0).toFixed(round_to) + "k";
    else
      return (value/1000.0).toFixed(1) + "k";
  } else {
    if (typeof round_to != 'undefined')
      return value.toFixed(round_to);
    else
      return value.toFixed(0);
  }
}
+5 −1
Original line number Diff line number Diff line
@@ -71,6 +71,10 @@ FnordMetric.widgets.counter = function(elem){
      if((diff > 0) && (new_val > target_val)){ new_val = target_val; }
      if((diff < 0) && (new_val < target_val)){ new_val = target_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'))
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
  <body class="dark">


        <div class="value large" data-fnordmetric="counter" data-gauge="orders_sum" data-at="sum(-1hour)" data-autopudate="1" data-unit="&euro;" data-scale-by="0.01" style="color:#fff; font-size:48px;">0</div>
        <div class="value large" data-fnordmetric="counter" data-gauge="orders_sum" data-at="sum(-1hour)" data-autopudate="1" data-unit="&euro;" data-scale-by="0.01" data-round-to="0" style="color:#fff; font-size:48px;">0</div>

    <span
      data-fnordmetric="counter"