pragma ComponentBehavior: Bound import QtQuick import "../.." // One live metric: label, value, fill meter, and a sparkline filling the rest of the row. Item { id: root required property Theme theme property string label: "" property string value: "" // Shared by the rows of one card, so their meters align. property real labelWidth: 38 property int valueWidth: 132 property real fraction: 0 // Routine meters stay neutral; callers switch to the warning colour past a threshold. property color barColor: theme.ui.minor property var ring: [] property var ringDown: [] property color barColorDown: theme.withAlpha(barColor, 0.55) property bool splitSpark: false property real sparkScaleMax: 0 property bool showSpark: true // History restarts on opening; a few bars at the edge read as noise, so the // sparkline waits for a minute of samples (30 at the 2 s cadence). readonly property bool sparkShown: showSpark && ring.length >= 30 width: parent ? parent.width : 0 height: 24 NuguText { id: labelText anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter theme: root.theme variant: "meta" text: root.label width: root.labelWidth } NuguText { id: valueText anchors.left: labelText.right anchors.leftMargin: root.theme.spaceXs anchors.verticalCenter: parent.verticalCenter theme: root.theme variant: "meta" text: root.value width: root.valueWidth } Rectangle { id: meter anchors.left: valueText.right anchors.leftMargin: root.theme.spaceMd anchors.verticalCenter: parent.verticalCenter width: 120 height: 6 radius: height / 2 color: root.theme.withAlpha(root.theme.ui.minor, 0.28) Rectangle { width: parent.width * Math.max(0, Math.min(1, root.fraction)) height: parent.height radius: parent.radius color: root.barColor Behavior on width { NumberAnimation { duration: root.theme.lowPowerMode ? 0 : 160 easing.type: Easing.OutCubic } } } } // The sparkline's axis spans its whole region, so history that restarted on // opening reads as a timeline filling from the right, not as a gap. Rectangle { visible: root.sparkShown anchors.left: spark.left anchors.right: spark.right y: root.splitSpark ? Math.round(spark.y + spark.height / 2) : spark.y + spark.height - 1 height: 1 color: root.theme.withAlpha(root.theme.ui.minor, 0.24) } Sparkline { id: spark objectName: "spark " + root.label anchors.left: meter.right anchors.leftMargin: root.theme.spaceMd anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter theme: root.theme visible: root.sparkShown values: root.ring valuesDown: root.ringDown split: root.splitSpark scaleMax: root.sparkScaleMax barColor: root.barColor barColorDown: root.barColorDown height: 24 } }