Skip to content

Commit

Permalink
luci-mod-status: 29_ports.js: improve speed formatting
Browse files Browse the repository at this point in the history
Improve speed formatting to make it more flexible and support speeds
beyond 40 GbE.

Signed-off-by: Jonas Jelonek <[email protected]>
  • Loading branch information
jonasjelonek authored and systemcrash committed Jan 9, 2025
1 parent b0f8155 commit 20bf9a4
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,20 @@ function formatSpeed(carrier, speed, duplex) {
var d = (duplex == 'half') ? '\u202f(H)' : '',
e = E('span', { 'title': _('Speed: %d Mibit/s, Duplex: %s').format(speed, duplex) });

switch (speed) {
case 10: e.innerText = '10\u202fM' + d; break;
case 100: e.innerText = '100\u202fM' + d; break;
case 1000: e.innerText = '1\u202fGbE' + d; break;
case 2500: e.innerText = '2.5\u202fGbE'; break;
case 5000: e.innerText = '5\u202fGbE'; break;
case 10000: e.innerText = '10\u202fGbE'; break;
case 25000: e.innerText = '25\u202fGbE'; break;
case 40000: e.innerText = '40\u202fGbE'; break;
default: e.innerText = '%d\u202fMbE%s'.format(speed, d);
switch (true) {
case (speed < 1000):
e.innerText = '%d\u202fM%s'.format(speed, d);
break;
case (speed == 1000):
e.innerText = '1\u202fGbE' + d;
break;
case (speed >= 1e6 && speed < 1e9):
e.innerText = '%f\u202fTbE'.format(speed / 1e6);
break;
case (speed >= 1e9):
e.innerText = '%f\u202fPbE'.format(speed / 1e9);
break;
default: e.innerText = '%f\u202fGbE'.format(speed / 1000);
}

return e;
Expand Down

0 comments on commit 20bf9a4

Please sign in to comment.