Skip to content

Commit

Permalink
ui: display numbers in a human readable form
Browse files Browse the repository at this point in the history
  • Loading branch information
andre8244 committed Jun 17, 2020
1 parent 52f6c6d commit 2a22545
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
55 changes: 50 additions & 5 deletions ui/src/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,69 @@ var Filters = {
break;

case size >= 1024 && size < Math.pow(1024, 2):
result = Math.round(size / 1024 * 100) / 100 + " K";
result = Math.round(size / 1024 * 100) / 100 + " KB";
break;

case size >= Math.pow(1024, 2) && size < Math.pow(1024, 3):
result = Math.round(size / Math.pow(1024, 2) * 100) / 100 + " M";
result = Math.round(size / Math.pow(1024, 2) * 100) / 100 + " MB";
break;

case size >= Math.pow(1024, 3) && size < Math.pow(1024, 4):
result = Math.round(size / Math.pow(1024, 3) * 100) / 100 + " G";
result = Math.round(size / Math.pow(1024, 3) * 100) / 100 + " GB";
break;

default:
result = Math.round(size / Math.pow(1024, 4) * 100) / 100 + " T";
result = Math.round(size / Math.pow(1024, 4) * 100) / 100 + " TB";
}

return result;
},
secondsInHour: function (value) {
humanFormat: function (number, decimals = false) {
var result;

switch (true) {
case number === null || number === "" || isNaN(number):
result = "-";
break;

case number >= 0 && number < 1000:
result = number;
break;

case number >= 1000 && number < Math.pow(1000, 2):
if (decimals) {
result = Math.round(number / 1000 * 10) / 10 + " K";
} else {
result = Math.round(number / 1000) + " K";
}
break;

case number >= Math.pow(1000, 2) && number < Math.pow(1000, 3):
if (decimals) {
result = Math.round(number / Math.pow(1000, 2) * 10) / 10 + " M";
} else {
result = Math.round(number / Math.pow(1000, 2)) + " M";
}
break;

case number >= Math.pow(1000, 3) && number < Math.pow(1000, 4):
if (decimals) {
result = Math.round(number / Math.pow(1000, 3) * 10) / 10 + " B";
} else {
result = Math.round(number / Math.pow(1000, 3)) + " B";
}
break;

default:
if (decimals) {
result = Math.round(number / Math.pow(1000, 4) * 10) / 10 + " T";
} else {
result = Math.round(number / Math.pow(1000, 4)) + " T";
}
}
return result;
},
secondsInHour: function (value) {
if (!value || value.length == 0) {
return '-'
}
Expand Down
12 changes: 9 additions & 3 deletions ui/src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
v-if="i != 'objects'"
class="stats-container col-xs-12 col-sm-4 col-md-3 col-lg-2"
>
<span class="card-pf-utilization-card-details-count stats-count">{{s}}</span>
<span class="card-pf-utilization-card-details-count stats-count" :title="s">
{{s | humanFormat}}
</span>
<span class="card-pf-utilization-card-details-description stats-description">
<span class="card-pf-utilization-card-details-line-2 stats-text">{{$t('dashboard.'+i)}}</span>
</span>
Expand All @@ -53,7 +55,9 @@
:key="i"
class="stats-container col-xs-12 col-sm-4 col-md-3 col-lg-2"
>
<span class="card-pf-utilization-card-details-count stats-count">{{o}}</span>
<span class="card-pf-utilization-card-details-count stats-count" :title="o">
{{o | humanFormat}}
</span>
<span class="card-pf-utilization-card-details-description stats-description">
<span class="card-pf-utilization-card-details-line-2 stats-text">{{$t('dashboard.'+i)}}</span>
</span>
Expand Down Expand Up @@ -95,7 +99,9 @@
v-if="i != 'total'"
class="stats-container col-xs-12 col-sm-4 col-md-3 col-lg-2"
>
<span class="card-pf-utilization-card-details-count stats-count">{{s}}</span>
<span class="card-pf-utilization-card-details-count stats-count" :title="s">
{{s | humanFormat}}
</span>
<span class="card-pf-utilization-card-details-description stats-description">
<span class="card-pf-utilization-card-details-line-2 stats-text">{{$t('dashboard.'+i)}}</span>
</span>
Expand Down

0 comments on commit 2a22545

Please sign in to comment.