]> arthur.barton.de Git - netdata.git/blobdiff - web/dashboard.js
respect custom dashboards decimal digits settings
[netdata.git] / web / dashboard.js
index 6dcbce7f8085a3845328b453a6349191d7250dcf..a462f10faf63be6486cbac07b569090e9c6dc211 100644 (file)
@@ -1363,9 +1363,7 @@ var NETDATA = window.NETDATA || {};
         this.value_decimal_detail = -1;
         var d = self.data('decimal-digits');
         if(typeof d === 'number') {
-            this.value_decimal_detail = 1;
-            while(d-- > 0)
-                this.value_decimal_detail *= 10;
+            this.value_decimal_detail = d;
         }
 
         this.auto = {
@@ -2247,20 +2245,33 @@ var NETDATA = window.NETDATA || {};
             return ret;
         };
 
-        this.legendFormatValueChartDecimals = -1;
+        var __legendFormatValueChartDecimalsLastMin = undefined;
+        var __legendFormatValueChartDecimalsLastMax = undefined;
+        var __legendFormatValueChartDecimals = -1;
         this.legendFormatValueDecimalsFromMinMax = function(min, max) {
-            var delta;
+            if(min === __legendFormatValueChartDecimalsLastMin && max === __legendFormatValueChartDecimalsLastMax)
+                return;
 
-            if(min === max)
-                delta = Math.abs(min);
-            else
-                delta = Math.abs(max - min);
+            if(this.value_decimal_detail !== -1) {
+                __legendFormatValueChartDecimals = this.value_decimal_detail;
+            }
+            else {
+                __legendFormatValueChartDecimalsLastMin = min;
+                __legendFormatValueChartDecimalsLastMax = max;
+
+                var delta;
 
-            if(delta > 1000)      this.legendFormatValueChartDecimals = 0;
-            else if(delta > 10  ) this.legendFormatValueChartDecimals = 1;
-            else if(delta > 1   ) this.legendFormatValueChartDecimals = 2;
-            else if(delta > 0.1 ) this.legendFormatValueChartDecimals = 3;
-            else                  this.legendFormatValueChartDecimals = 4;
+                if (min === max)
+                    delta = Math.abs(min);
+                else
+                    delta = Math.abs(max - min);
+
+                if (delta > 1000)     __legendFormatValueChartDecimals = 0;
+                else if (delta > 10)  __legendFormatValueChartDecimals = 1;
+                else if (delta > 1)   __legendFormatValueChartDecimals = 2;
+                else if (delta > 0.1) __legendFormatValueChartDecimals = 3;
+                else                  __legendFormatValueChartDecimals = 4;
+            }
         };
 
         this.legendFormatValue = function(value) {
@@ -2268,11 +2279,7 @@ var NETDATA = window.NETDATA || {};
 
             var dmin, dmax;
 
-            if(this.value_decimal_detail !== -1) {
-                dmin = dmax = this.value_decimal_detail;
-            }
-
-            if(this.legendFormatValueChartDecimals < 0) {
+            if(__legendFormatValueChartDecimals < 0) {
                 dmin = 0;
                 var abs = value;
                 if(abs > 1000)      dmax = 0;
@@ -2282,7 +2289,11 @@ var NETDATA = window.NETDATA || {};
                 else                dmax = 4;
             }
             else {
-                dmin = dmax = this.legendFormatValueChartDecimals;
+                dmin = dmax = __legendFormatValueChartDecimals;
+            }
+
+            if(this.value_decimal_detail !== -1) {
+                dmin = dmax = this.value_decimal_detail;
             }
 
             return value.toLocaleString(undefined, {
@@ -4425,7 +4436,7 @@ var NETDATA = window.NETDATA || {};
                                     || 2,
 
             valueFormatter:         self.data('dygraph-valueformatter')
-                                    || function(x){ return x.toFixed(2); },
+                                    || undefined,
 
             highlightCircleSize:    self.data('dygraph-highlightcirclesize')
                                     || highlightCircleSize,
@@ -4440,6 +4451,7 @@ var NETDATA = window.NETDATA || {};
                                     || undefined,
 
             visibility:             state.dimensions_visibility.selected2BooleanArray(state.data.dimension_names),
+
             axes: {
                 x: {
                     pixelsPerLabel: 50,
@@ -4447,25 +4459,19 @@ var NETDATA = window.NETDATA || {};
                     axisLabelFormatter: function (d, gran) {
                         void(gran);
                         return NETDATA.zeropad(d.getHours()) + ":" + NETDATA.zeropad(d.getMinutes()) + ":" + NETDATA.zeropad(d.getSeconds());
-                    },
-                    valueFormatter: function (ms) {
-                        void(ms);
-                        //var d = new Date(ms);
-                        //return d.toLocaleDateString() + ' ' + d.toLocaleTimeString();
-
-                        // no need to return anything here
-                        return ' ';
-
                     }
                 },
                 y: {
                     pixelsPerLabel: 15,
-                    valueFormatter: function (x) {
-                        // we format legends with the state object
-                        // no need to do anything here
-                        // return (Math.round(x*100) / 100).toLocaleString();
-                        // return state.legendFormatValue(x);
-                        return x;
+                    axisLabelFormatter: function (y) {
+
+                        // unfortunately, we have to call this every single time
+                        state.legendFormatValueDecimalsFromMinMax(
+                            this.axes_[0].extremeRange[0],
+                            this.axes_[0].extremeRange[1]
+                        );
+
+                        return state.legendFormatValue(y);
                     }
                 }
             },