浏览代码

ux: use financial units instead of SI for credits

Instead of K, M, G, T, P it's K, M, B, T, Q.
KernelDeimos 3 天之前
父节点
当前提交
880760c602
共有 2 个文件被更改,包括 23 次插入6 次删除
  1. 4 4
      src/gui/src/UI/Settings/UITabUsage.js
  2. 19 2
      src/gui/src/helpers.js

+ 4 - 4
src/gui/src/UI/Settings/UITabUsage.js

@@ -88,8 +88,8 @@ export default {
                             <h3 style="margin-bottom: 5px; font-size: 14px;">${html_encode(name)}:</h3>
                             <span style="font-size: 13px; margin-bottom: 3px;">${i18n('used_of', {
                                 ...entry,
-                                used: window.format_SI(entry.used),
-                                available: window.format_SI(entry.available),
+                                used: window.format_credits(entry.used),
+                                available: window.format_credits(entry.available),
                             })}</span>
                             <div class="usage-progbar-wrapper" style="width: 100%;">
                                 <div class="usage-progbar" style="width: ${Number(entry.usage_percentage)}%;"><span class="usage-progbar-percent">${Number(entry.usage_percentage)}%</span></div>
@@ -116,8 +116,8 @@ export default {
                         .innerText = '' + Number(event.usage_percentage) + '%';
                     const used_of_str = i18n('used_of', {
                         ...event,
-                        used: window.format_SI(event.used),
-                        available: window.format_SI(event.available),
+                        used: window.format_credits(event.used),
+                        available: window.format_credits(event.available),
                     });
                     el_divContent
                         .querySelector(`[data-id=${sanitize_id(event.id)}] > span`)

+ 19 - 2
src/gui/src/helpers.js

@@ -2730,7 +2730,7 @@ window.get_profile_picture = async function(username){
     return icon;
 }
 
-window.format_SI = (num) => {
+window.format_with_units = (num, { mulUnits, divUnits, precision = 3 }) => {
   if ( num === 0 ) return "0";
 
   const mulUnits = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
@@ -2749,7 +2749,24 @@ window.format_SI = (num) => {
   }
 
   const scaled = num / Math.pow(10, exp * 3);
-  const rounded = Number.parseFloat(scaled.toPrecision(3));
+  const rounded = Number.parseFloat(scaled.toPrecision(precision));
 
   return `${rounded}${symbol}`;
 };
+
+window.format_SI = (num) => {
+  if ( num === 0 ) return "0";
+
+  const mulUnits = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
+  const divUnits = ["m", "µ", "n", "p", "f", "a", "z", "y"];
+  
+  return window.format_with_units(num, { mulUnits, divUnits });
+};
+
+window.format_credits = (num) => {
+  if ( num === 0 ) return "0";
+  
+  const mulUnits = ["", "K", "M", "B", "T", "Q"];
+
+  return window.format_with_units(num, { mulUnits })
+};