import QtQuick import QtQuick.Layouts import "../../components" import "../../services" import "../../theme" // Live download/upload rates with a one-minute history graph. Face { id: root usesMetrics: true readonly property var samples: MetricsService.history ColumnLayout { anchors.fill: parent anchors.margins: 12 spacing: 6 RowLayout { Layout.fillWidth: true spacing: 6 GlassIcon { size: 22 glyphSize: 12 glyph: "󰛳" fallback: "N" color: Theme.transparent border.width: 0 } Text { text: "Network" color: Theme.text font.pixelSize: 12 font.weight: Font.DemiBold Layout.fillWidth: true } } RowLayout { Layout.fillWidth: true spacing: 14 Repeater { model: [ { label: "↓", value: MetricsService.network.download, color: Theme.accentVivid }, { label: "↑", value: MetricsService.network.upload, color: Theme.text } ] Row { id: rate required property var modelData spacing: 4 Text { text: rate.modelData.label color: rate.modelData.color font.pixelSize: 15 font.weight: Font.DemiBold } Text { text: MetricsService.bytes(rate.modelData.value) + "/s" color: Theme.text font.pixelSize: 15 font.weight: Font.Light font.features: { "tnum": 1 } } } } } Canvas { id: graph Layout.fillWidth: true Layout.fillHeight: true readonly property var samples: root.samples readonly property color down: Theme.accentVivid readonly property color up: Theme.text onSamplesChanged: requestPaint() onWidthChanged: requestPaint() onHeightChanged: requestPaint() onPaint: { const ctx = getContext("2d"); ctx.reset(); const values = samples.filter(s => Number.isFinite(s.down) && Number.isFinite(s.up)); if (values.length < 2) return; const peak = Math.max(1024, ...values.map(s => Math.max(s.down, s.up))); const step = width / 59; const offset = width - (values.length - 1) * step; for (const [key, color, alpha] of [["down", down, 0.3], ["up", up, 0.12]]) { ctx.beginPath(); ctx.moveTo(offset, height); values.forEach((s, i) => ctx.lineTo(offset + i * step, height - s[key] / peak * (height - 2))); ctx.lineTo(offset + (values.length - 1) * step, height); ctx.closePath(); ctx.fillStyle = Qt.alpha(color, alpha); ctx.fill(); ctx.beginPath(); values.forEach((s, i) => { const y = height - s[key] / peak * (height - 2); if (i === 0) ctx.moveTo(offset, y); else ctx.lineTo(offset + i * step, y); }); ctx.strokeStyle = Qt.alpha(color, 0.9); ctx.lineWidth = 1.5; ctx.stroke(); } } } } }