system-monitor: Fix net speed
We use different formats for values above and below 10, to only include a fraction for the latter. However we use the same factor to determine the format and to compute the number to format, with the result that values above 10 are off by a factor of 10. Address this by adding a separate "unitFactor" value for computing the value. Spotted by Yannick Daveluy. Closes https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/issues/494 Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/313>
This commit is contained in:
committed by
Marge Bot
parent
cd9341adf1
commit
6d36da1ce6
@@ -193,6 +193,7 @@ class NetStatSection extends StatSection {
|
||||
|
||||
#formats = [{
|
||||
factor: 1000,
|
||||
unitFactor: 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'kilobyte',
|
||||
@@ -201,6 +202,7 @@ class NetStatSection extends StatSection {
|
||||
}),
|
||||
}, {
|
||||
factor: 1000 * 10,
|
||||
unitFactor: 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'kilobyte',
|
||||
@@ -208,6 +210,7 @@ class NetStatSection extends StatSection {
|
||||
}),
|
||||
}, {
|
||||
factor: 1000 * 1000,
|
||||
unitFactor: 1000 * 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'megabyte',
|
||||
@@ -216,6 +219,7 @@ class NetStatSection extends StatSection {
|
||||
}),
|
||||
}, {
|
||||
factor: 1000 * 1000 * 10,
|
||||
unitFactor: 1000 * 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'megabyte',
|
||||
@@ -223,6 +227,7 @@ class NetStatSection extends StatSection {
|
||||
}),
|
||||
}, {
|
||||
factor: 1000 * 1000 * 1000,
|
||||
unitFactor: 1000 * 1000 * 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'gigabyte',
|
||||
@@ -231,6 +236,7 @@ class NetStatSection extends StatSection {
|
||||
}),
|
||||
}, {
|
||||
factor: 1000 * 1000 * 1000 * 10,
|
||||
unitFactor: 1000 * 1000 * 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'gigabyte',
|
||||
@@ -238,6 +244,7 @@ class NetStatSection extends StatSection {
|
||||
}),
|
||||
}, {
|
||||
factor: 1000 * 1000 * 1000 * 1000,
|
||||
unitFactor: 1000 * 1000 * 1000 * 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'terabyte',
|
||||
@@ -246,6 +253,7 @@ class NetStatSection extends StatSection {
|
||||
}),
|
||||
}, {
|
||||
factor: 1000 * 1000 * 1000 * 1000 * 10,
|
||||
unitFactor: 1000 * 1000 * 1000 * 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'terabyte',
|
||||
@@ -253,6 +261,7 @@ class NetStatSection extends StatSection {
|
||||
}),
|
||||
}, {
|
||||
factor: 1000 * 1000 * 1000 * 1000 * 1000,
|
||||
unitFactor: 1000 * 1000 * 1000 * 1000 * 1000,
|
||||
formatter: new Intl.NumberFormat(undefined, {
|
||||
style: 'unit',
|
||||
unit: 'petabyte',
|
||||
@@ -313,8 +322,8 @@ class NetStatSection extends StatSection {
|
||||
this.#lastTime = time;
|
||||
this.#lastHash = hash;
|
||||
|
||||
const {factor, formatter} = this._getFormat(dbytes);
|
||||
this.label.text = formatter.format(dbytes / factor);
|
||||
const {unitFactor, formatter} = this._getFormat(dbytes);
|
||||
this.label.text = formatter.format(dbytes / unitFactor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user