forked from bitcoin-core/gui-qml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkTrafficGraph.qml
More file actions
96 lines (83 loc) · 2.82 KB
/
Copy pathNetworkTrafficGraph.qml
File metadata and controls
96 lines (83 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2023 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import "../controls"
import "../components"
import org.bitcoincore.qt 1.0
Item {
id: root
property alias backgroundColor: trafficGraph.backgroundColor
property alias borderColor: trafficGraph.borderColor
property alias fillColor: trafficGraph.gradientColor
property alias lineColor: trafficGraph.lineColor
property alias markerLineColor: trafficGraph.markerLineColor
property alias maxSamples: trafficGraph.maxSamples
property alias maxValue: trafficGraph.maxValue
property alias valueList: trafficGraph.valueList
property double maxRateBps
property color unitLabelColor: Theme.color.neutral9
height: 250
LineGraph {
id: trafficGraph
height: root.height
width: root.width
backgroundColor: root.backgroundColor
borderColor: root.borderColor
gradientColor: root.fillColor
lineColor: root.lineColor
markerLineColor: root.markerLineColor
maxSamples: root.maxSamples
maxValue: root.maxValue
valueList: root.valueList
Behavior on backgroundColor {
ColorAnimation { duration: 150 }
}
Behavior on borderColor {
ColorAnimation { duration: 150 }
}
Behavior on gradientColor {
ColorAnimation { duration: 150 }
}
Behavior on lineColor {
ColorAnimation { duration: 150 }
}
Behavior on markerLineColor {
ColorAnimation { duration: 150 }
}
}
ColumnLayout {
anchors.fill: parent
CoreText {
text: formatBytes(formatMagnitude(root.maxRateBps)) + "/s"
color: root.unitLabelColor
font.pixelSize: 13
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
Layout.leftMargin: 5
Layout.bottomMargin: 6
}
CoreText {
text: formatBytes(formatMagnitude(root.maxRateBps / 10)) + "/s"
color: root.unitLabelColor
font.pixelSize: 13
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
Layout.leftMargin: 5
Layout.bottomMargin: 5
}
}
function formatMagnitude(max_rate) {
var base = Math.floor(Math.log10(max_rate));
return Math.pow(10.0, base);
}
function formatBytes(bytes) {
var suffixes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
var index = 0;
while (bytes >= 1000 && index < suffixes.length - 1) {
bytes /= 1000;
index++;
}
return bytes.toFixed(0) + " " + suffixes[index];
}
}