diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-02-05 22:30:42 +0200 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-02-05 22:30:42 +0200 |
commit | b88d7cee8220ec068e7024f6ed868ef9e3a92ccf (patch) | |
tree | 4d9c48884cb0e71890bcae1c3d46cdca615d8e6d /web | |
parent | 5e7703963d55c78192befbc0cea2cc6c920bbcc3 (diff) |
legends now have uniform but dynamic number of fraction digits
Diffstat (limited to 'web')
-rw-r--r-- | web/dashboard.js | 70 | ||||
-rw-r--r-- | web/index.html | 2 |
2 files changed, 59 insertions, 13 deletions
diff --git a/web/dashboard.js b/web/dashboard.js index 4947426f2d..6dcbce7f80 100644 --- a/web/dashboard.js +++ b/web/dashboard.js @@ -2247,19 +2247,53 @@ var NETDATA = window.NETDATA || {}; return ret; }; + this.legendFormatValueChartDecimals = -1; + this.legendFormatValueDecimalsFromMinMax = function(min, max) { + var delta; + + if(min === max) + delta = Math.abs(min); + else + delta = Math.abs(max - min); + + 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; + }; + this.legendFormatValue = function(value) { - if(value === null || value === 'undefined') return '-'; - if(typeof value !== 'number') return value; - - if(this.value_decimal_detail !== -1) - return (Math.round(value * this.value_decimal_detail) / this.value_decimal_detail).toLocaleString(); - - var abs = Math.abs(value); - if(abs >= 1000) return (Math.round(value)).toLocaleString(); - if(abs >= 100 ) return (Math.round(value * 10) / 10).toLocaleString(); - if(abs >= 1 ) return (Math.round(value * 100) / 100).toLocaleString(); - if(abs >= 0.1 ) return (Math.round(value * 1000) / 1000).toLocaleString(); - return (Math.round(value * 10000) / 10000).toLocaleString(); + if(typeof value !== 'number') return '-'; + + var dmin, dmax; + + if(this.value_decimal_detail !== -1) { + dmin = dmax = this.value_decimal_detail; + } + + if(this.legendFormatValueChartDecimals < 0) { + dmin = 0; + var abs = value; + if(abs > 1000) dmax = 0; + else if(abs > 10 ) dmax = 1; + else if(abs > 1) dmax = 2; + else if(abs > 0.1) dmax = 3; + else dmax = 4; + } + else { + dmin = dmax = this.legendFormatValueChartDecimals; + } + + return value.toLocaleString(undefined, { + // style: 'decimal', + // minimumIntegerDigits: 1, + // minimumSignificantDigits: 1, + // maximumSignificantDigits: 1, + useGrouping: true, + minimumFractionDigits: dmin, + maximumFractionDigits: dmax + }); }; this.legendSetLabelValue = function(label, value) { @@ -4212,6 +4246,12 @@ var NETDATA = window.NETDATA || {}; dygraph.updateOptions(options); } + // decide the decimal points on the legend of the chart + state.legendFormatValueDecimalsFromMinMax( + state.dygraph_instance.axes_[0].extremeRange[0], + state.dygraph_instance.axes_[0].extremeRange[1] + ); + state.dygraph_last_rendered = Date.now(); return true; }; @@ -4819,6 +4859,12 @@ var NETDATA = window.NETDATA || {}; state.__commonMax = null; } + // decide the decimal points on the legend of the chart + state.legendFormatValueDecimalsFromMinMax( + state.dygraph_instance.axes_[0].extremeRange[0], + state.dygraph_instance.axes_[0].extremeRange[1] + ); + return true; }; diff --git a/web/index.html b/web/index.html index 860cd0307e..e7caad9fe2 100644 --- a/web/index.html +++ b/web/index.html @@ -3312,4 +3312,4 @@ </div> </body> </html> -<script type="text/javascript" src="dashboard.js?v20170205-10"></script> +<script type="text/javascript" src="dashboard.js?v20170205-28"></script> |