Skip to content

Commit

Permalink
fix(graph): right aggregate and use network values
Browse files Browse the repository at this point in the history
fix #50
  • Loading branch information
orblazer committed May 14, 2023
1 parent a86d431 commit 0816363
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package/contents/ui/components/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ function getNetworkDialectInfo(dialect) {
suffix: i18nc("kilobyte suffix", "Bps"),
kiloChar: "k",
KiBDiff: 1.024,
multiplier: 1000,
multiplier: 1024,
};
case "kilobit":
return {
name: "kilobit",
suffix: i18nc("kilobit suffix", "bps"),
kiloChar: "k",
KiBDiff: 8.192,
multiplier: 1000,
KiBDiff: 8,
multiplier: 1024,
};
default:
return {
Expand Down
28 changes: 24 additions & 4 deletions package/contents/ui/components/graph/NetworkGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ RMBaseGraph.TwoSensorsGraph {
}

// Override methods, for commulate sensors and support custom dialect
property var _downloadValue
property var _uploadValue

_update: () => {
// Cummulate sensors by group
let data;
Expand All @@ -56,9 +59,9 @@ RMBaseGraph.TwoSensorsGraph {
}
}

// Fix dialect
downloadValue *= dialect.KiBDiff;
uploadValue *= dialect.KiBDiff;
// Fix dialect AND store it for update label
_downloadValue = downloadValue *= dialect.KiBDiff;
_uploadValue = uploadValue *= dialect.KiBDiff;

// Insert datas
root._insertChartData(0, downloadValue);
Expand All @@ -70,7 +73,24 @@ RMBaseGraph.TwoSensorsGraph {
_updateData(1);
}
}
_formatValue: (_, data) => Functions.formatByteValue(data.value, dialect)

function _updateData(index) {
// Cancel update if first data is not here
if (!sensorsModel.hasIndex(0, 0)) {
return;
}

// Retrieve label need to update
const label = _getLabel(index);
if (typeof label === "undefined" || !label.enabled) {
return;
}
const value = index === 0 ? _downloadValue : _uploadValue;

// Show value on label
label.text = Functions.formatByteValue(value, dialect);
label.visible = true;
}

function _updateSensors() {
if (typeof networkInterfaces.model.count === "undefined") {
Expand Down

0 comments on commit 0816363

Please sign in to comment.