diff --git a/docker/settings.json.tmpl b/docker/settings.json.tmpl index 51cdb60..cc50c3b 100644 --- a/docker/settings.json.tmpl +++ b/docker/settings.json.tmpl @@ -107,7 +107,7 @@ "line_color": "rgba(54,162,235,1)", "fill_color": "rgba(54,162,235,0.2)", "crosshair_color": "#aaa", - "block_line": { "enabled": true, "block_line_color": "rgba(0,128,0,0.2)" }, + "block_line": { "enabled": false, "block_line_color": "rgba(120,60,220,0.25)" }, "round_decimals": 3, "chart_height": 320, "full_row": false, @@ -123,7 +123,7 @@ "pos_line_color": "rgba(255,161,0,1)", "pos_fill_color": "rgba(255,161,0,0.2)", "crosshair_color": "#aaa", - "block_line": { "enabled": true, "block_line_color": "rgba(0,128,0,0.2)" }, + "block_line": { "enabled": false, "block_line_color": "rgba(120,60,220,0.25)" }, "round_decimals": 3, "chart_height": 320, "full_row": false, diff --git a/public/js/custom.js b/public/js/custom.js index 2577407..7756aa4 100644 --- a/public/js/custom.js +++ b/public/js/custom.js @@ -1,30 +1,30 @@ -$(document).ready(function() { +// ══════════════════════════════════════════════════════════════ +// HASHRATE AUTO-SCALING (global scope — reused by layout.pug chart scripts) +// The server sends hashrate already divided by nethash_units ("G"), +// so values arrive in GH/s. We scale to keep the display 1–999. +// ══════════════════════════════════════════════════════════════ - // ══════════════════════════════════════════════════════════════ - // HASHRATE AUTO-SCALING - // The server sends hashrate already divided by nethash_units ("G"), - // so values arrive in GH/s. We scale to keep the display 1–999. - // ══════════════════════════════════════════════════════════════ +var HASH_UNITS = [ + { div: 1e6, label: 'PH/s' }, + { div: 1e3, label: 'TH/s' }, + { div: 1, label: 'GH/s' }, + { div: 1e-3, label: 'MH/s' }, + { div: 1e-6, label: 'KH/s' }, + { div: 1e-9, label: 'H/s' } +]; - var HASH_UNITS = [ - { div: 1e6, label: 'PH/s' }, - { div: 1e3, label: 'TH/s' }, - { div: 1, label: 'GH/s' }, - { div: 1e-3, label: 'MH/s' }, - { div: 1e-6, label: 'KH/s' }, - { div: 1e-9, label: 'H/s' } - ]; - - // Returns {num, unit} where 1 ≤ |num| < 1000 (best fit) - function scaleFromGH(gh) { - var abs = Math.abs(gh); - for (var i = 0; i < HASH_UNITS.length; i++) { - if (abs >= HASH_UNITS[i].div) { - return { num: gh / HASH_UNITS[i].div, unit: HASH_UNITS[i].label }; - } +// Returns {num, unit} where 1 ≤ |num| < 1000 (best fit) +function scaleFromGH(gh) { + var abs = Math.abs(gh); + for (var i = 0; i < HASH_UNITS.length; i++) { + if (abs >= HASH_UNITS[i].div) { + return { num: gh / HASH_UNITS[i].div, unit: HASH_UNITS[i].label }; } - return { num: gh, unit: 'GH/s' }; } + return { num: gh, unit: 'GH/s' }; +} + +$(document).ready(function() { // ── Panel: reformat #hashrate + update unit label ───────────── function refreshHashratePanel() { @@ -58,7 +58,7 @@ $(document).ready(function() { }); // Start watching once #hashrate appears in the DOM - var _panelWatcher = new MutationObserver(function(mutations, obs) { + var _panelWatcher = new MutationObserver(function(_mutations, obs) { var el = document.getElementById('hashrate'); if (el) { obs.disconnect(); diff --git a/views/layout.pug b/views/layout.pug index baff04c..6bc5eb7 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -540,6 +540,15 @@ html(lang='en') return Math.floor(timestamp * 1000 / (60 * 1000)) * (60 * 1000); } function formatNetworkChartValue(val, roundDecimals, lbl, returnNum) { + if (returnNum) + return (val || 0); + + if (lbl == 'Hashrate' && typeof scaleFromGH === 'function') { + var s = scaleFromGH(val || 0); + var dec = Math.abs(s.num) >= 100 ? 0 : Math.abs(s.num) >= 10 ? 1 : 2; + return s.num.toFixed(dec) + ' ' + s.unit; + } + let max = 20; if (roundDecimals != -1) @@ -551,10 +560,7 @@ html(lang='en') max = decimalCount; } - if (returnNum) - return (val || 0); - else - return Number((val || 0)).toLocaleString('en',{'minimumFractionDigits':0,'maximumFractionDigits':max,'useGrouping':true}) + (lbl == 'Hashrate' ? ' ' + getNetHashUnits() : ''); + return Number((val || 0)).toLocaleString('en',{'minimumFractionDigits':0,'maximumFractionDigits':max,'useGrouping':true}); } function populateHourChartData(result) { const roundedDataMap = new Map();