Skip to content

Commit

Permalink
feat: improve analytics total transfer unit display (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiroaisen authored Jul 5, 2023
2 parents 42b1c5f + 274b5a8 commit 672d208
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions front/share/src/analytics/AnalyticsData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -772,16 +772,23 @@
const by_day_grid_data = get_by_day_grid();
const f = new Intl.NumberFormat(lang, {
notation: "compact",
style: "unit",
unit: "byte",
unitDisplay: "narrow",
minimumFractionDigits: 1,
maximumFractionDigits: 1,
});
const units = ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"]
const bytes = (n: number) => {
return f.format(n)
const unit_i = Math.min(units.length - 1, Math.floor(Math.log(n) / Math.log(1000)));
const unit_n = n / (1000 ** unit_i);
const f = new Intl.NumberFormat(lang, {
style: "unit",
unit: units[unit_i],
minimumFractionDigits: 1,
maximumFractionDigits: 1,
})
return f.format(unit_n);
}
</script>

Expand Down

0 comments on commit 672d208

Please sign in to comment.