diff --git a/lib/settings.js b/lib/settings.js index 8120104..87a66d3 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -304,7 +304,10 @@ exports.shared_pages = { // crosshair_color: Change the vertical crosshair line color of the network hashrate chart // Set this to any valid html color // Ex: "#ffffff" or "rgba(255, 255, 255, 1)" or "white" - "crosshair_color": "#000000" + "crosshair_color": "#000000", + // round_decimals: Set how many decimal places the hash rates are rounded to (Max 20) + // NOTE: Set to a value of -1 to output the raw value without rounding + "round_decimals": 3 }, // difficulty_chart: A collection of settings that pertain to the network difficulty chart "difficulty_chart": { @@ -334,7 +337,10 @@ exports.shared_pages = { // crosshair_color: Change the vertical crosshair line color of the network difficulty chart // Set this to any valid html color // Ex: "#ffffff" or "rgba(255, 255, 255, 1)" or "white" - "crosshair_color": "#000000" + "crosshair_color": "#000000", + // round_decimals: Set how many decimal places the difficulty values are rounded to (Max 20) + // NOTE: Set to a value of -1 to output the raw value without rounding + "round_decimals": 3 }, // reload_chart_seconds: The time in seconds to automatically reload the network chart data from the server // Set to 0 to disable automatic reloading of chart data diff --git a/settings.json.template b/settings.json.template index 0ce290e..27e1998 100644 --- a/settings.json.template +++ b/settings.json.template @@ -303,7 +303,10 @@ // crosshair_color: Change the vertical crosshair line color of the network hashrate chart // Set this to any valid html color // Ex: "#ffffff" or "rgba(255, 255, 255, 1)" or "white" - "crosshair_color": "#000000" + "crosshair_color": "#000000", + // round_decimals: Set how many decimal places the hash rates are rounded to (Max 20) + // NOTE: Set to a value of -1 to output the raw value without rounding + "round_decimals": 3 }, // difficulty_chart: A collection of settings that pertain to the network difficulty chart "difficulty_chart": { @@ -333,7 +336,10 @@ // crosshair_color: Change the vertical crosshair line color of the network difficulty chart // Set this to any valid html color // Ex: "#ffffff" or "rgba(255, 255, 255, 1)" or "white" - "crosshair_color": "#000000" + "crosshair_color": "#000000", + // round_decimals: Set how many decimal places the difficulty values are rounded to (Max 20) + // NOTE: Set to a value of -1 to output the raw value without rounding + "round_decimals": 3 }, // reload_chart_seconds: The time in seconds to automatically reload the network chart data from the server // Set to 0 to disable automatic reloading of chart data diff --git a/views/layout.pug b/views/layout.pug index 61689ab..3e92e40 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -388,6 +388,18 @@ html(lang='en') } var nethashChart; var difficultyChart; + var countDecimals = function(value) { + let text = value.toString(); + + if (text.indexOf('e-') > -1) { + let [base, trail] = text.split('e-'); + let deg = parseInt(trail, 10); + return deg; + } else if (Math.floor(value) !== value) + return value.toString().split(".")[1].length || 0; + else + return 0; + } function update_network_charts() { $.ajax({ url: '/ext/getnetworkchartdata', @@ -448,7 +460,19 @@ html(lang='en') return 'Block ' + context[0].label + ' Hashrate'; }, label: function(context) { - return (context.raw || 0).toString() + ' ' + getNetHashUnits() + var val = #{settings.shared_pages.page_header.network_charts.nethash_chart.round_decimals}; + var max = 20; + + if (val != -1) + max = val; + else { + let decimalCount = countDecimals(context.raw || 0); + + if (decimalCount < max) + max = decimalCount; + } + + return Number((context.raw || 0)).toLocaleString('en',{'minimumFractionDigits':0,'maximumFractionDigits':max,'useGrouping':true}) + ' ' + getNetHashUnits(); } } }, @@ -554,7 +578,19 @@ html(lang='en') return 'Block ' + context[0].label + ' Difficulty'; }, label: function(context) { - return (context.raw || 0).toString(); + var val = #{settings.shared_pages.page_header.network_charts.difficulty_chart.round_decimals}; + var max = 20; + + if (val != -1) + max = val; + else { + let decimalCount = countDecimals(context.raw || 0); + + if (decimalCount < max) + max = decimalCount; + } + + return Number((context.raw || 0)).toLocaleString('en',{'minimumFractionDigits':0,'maximumFractionDigits':max,'useGrouping':true}); } } },