/*
   All emon_widgets code is released under the GNU General Public License v3.
   See COPYRIGHT.txt and LICENSE.txt.

    ---------------------------------------------------------------------
    Part of the OpenEnergyMonitor project:
    http://openenergymonitor.org

    Author: Trystan Lea: trystan.lea@googlemail.com
    If you have any questions please get in touch, try the forums here:
    http://openenergymonitor.org/emon/forum
 */

function feedvalue_widgetlist()
{
  var widgets = {
    "feedvalue":
    {
      "offsetx":-40,"offsety":-30,"width":80,"height":60,
      "menu":"Widgets",
      "options":["feedname","units"],
      "optionstype":["feed","value"],
      "optionsname":[_Tr("Feed"),_Tr("Units")],
      "optionshint":[_Tr("Feed value"),_Tr("Units to show")]
    }
  }
  return widgets;
}

function feedvalue_init()
{
  feedvalue_draw();
}

function feedvalue_draw()
{
  $('.feedvalue').each(function(index)
  {
    var feed = $(this).attr("feedname");
    if (feed==undefined) feed = $(this).attr("feed");

    var units = $(this).attr("units");
    var val = assoc[feed];

    if (feed==undefined) val = 0;
    if (units==undefined) units = '';
    if (val==undefined) val = 0;

    if (isNaN(val))  val = 0;

    else if (val>=100)
        val = (val*1).toFixed(0);
    else if (val>=10)
        val = (val*1).toFixed(1);
    else if (val<=-100)
        val = (val*1).toFixed(0);
    else if (val<=-10)
        val = (val*1).toFixed(1);
    else
        val = (val*1).toFixed(2);

    $(this).html(val+units);
  });
}

function feedvalue_slowupdate()
{
  feedvalue_draw();
}

function feedvalue_fastupdate()
{

}



@@ -629,16 +629,27 @@
 ,%22units%22
+,%22decimals%22
 %5D,%0A     
@@ -678,16 +678,27 @@
 ,%22value%22
+,%22decimals%22
 %5D,%0A     
@@ -737,16 +737,32 @@
 %22Units%22)
+,_Tr(%22Decimals%22)
 %5D,%0A     
@@ -815,16 +815,59 @@
 o show%22)
+,_Tr(%22Decimals to show (-1 for automatic)%22)
 %5D%0A    %7D%0A
@@ -1174,16 +1174,61 @@
 c%5Bfeed%5D;
+%0A    var decimals = $(this).attr(%22decimals%22);
 %0A%0A    if
@@ -1322,24 +1322,72 @@
 d) val = 0;%0A
+    if (decimals==undefined) decimals = -1;%0A    
 %0A    if (isN
@@ -1405,25 +1405,55 @@
 al = 0;%0A
+    
 %0A    
-else
+if (decimals==-1)%0A    %7B%0A%0A     
  if (val
@@ -1459,32 +1459,34 @@
 l%3E=100)%0A        
+ 
+ 
 val = (val*1).to
@@ -1491,32 +1491,34 @@
 toFixed(0);%0A    
+  
 else if (val%3E=10
@@ -1515,24 +1515,26 @@
 f (val%3E=10)%0A
+  
         val 
@@ -1555,24 +1555,26 @@
 xed(1);%0A    
+  
 else if (val
@@ -1577,24 +1577,26 @@
 (val%3C=-100)%0A
+  
         val 
@@ -1617,24 +1617,26 @@
 xed(0);%0A    
+ 
+ 
 else if (val
@@ -1638,24 +1638,26 @@
  (val%3C=-10)%0A
+  
         val 
@@ -1674,24 +1674,26 @@
 toFixed(1);%0A
+  
     else%0A   
@@ -1689,32 +1689,34 @@
    else%0A        
+  
 val = (val*1).to
@@ -1724,16 +1724,79 @@
 ixed(2);
+%0A    %7D%0A    else %0A    %7B%0A      val = val.toFixed(decimals);%0A    %7D
 %0A%0A    $(

Update feedvalue_render.js