| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2019 Marco Martin <[email protected]> |
| 3 |
SPDX-FileCopyrightText: 2019 David Edmundson <[email protected]> |
| 4 |
SPDX-FileCopyrightText: 2019 Arjen Hiemstra <[email protected]> |
| 5 |
SPDX-FileCopyrightText: 2020 David Redondo <[email protected]> |
| 6 |
|
| 7 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 8 |
*/ |
| 9 |
|
| 10 |
import QtQuick |
| 11 |
import QtQuick.Controls as QQC2 |
| 12 |
import QtQuick.Layouts |
| 13 |
|
| 14 |
import org.kde.kirigami as Kirigami |
| 15 |
|
| 16 |
import org.kde.ksysguard.sensors as Sensors |
| 17 |
import org.kde.ksysguard.faces as Faces |
| 18 |
import org.kde.ksysguard.formatter as Formatter |
| 19 |
|
| 20 |
import org.kde.quickcharts as Charts |
| 21 |
import org.kde.quickcharts.controls as ChartsControls |
| 22 |
|
| 23 |
Faces.SensorFace { |
| 24 |
id: root |
| 25 |
|
| 26 |
readonly property bool showLegend: controller.faceConfiguration.showLegend |
| 27 |
readonly property bool showGridLines: root.controller.faceConfiguration.showGridLines |
| 28 |
readonly property bool horizontalBars: root.controller.faceConfiguration.horizontalBars |
| 29 |
readonly property bool showYAxisLabels: root.controller.faceConfiguration.showYAxisLabels |
| 30 |
|
| 31 |
// Arbitrary minimumWidth to make easier to align plasmoids in a predictable way |
| 32 |
Layout.minimumWidth: Math.max(Kirigami.Units.gridUnit * compactRepresentation.barCount, Kirigami.Units.gridUnit * 8) |
| 33 |
Layout.preferredWidth: Math.max(titleMetrics.width, legend.preferredWidth) |
| 34 |
|
| 35 |
contentItem: ColumnLayout { |
| 36 |
spacing: Kirigami.Units.largeSpacing |
| 37 |
|
| 38 |
Kirigami.Heading { |
| 39 |
id: heading |
| 40 |
Layout.fillWidth: true |
| 41 |
horizontalAlignment: Text.AlignHCenter |
| 42 |
elide: Text.ElideRight |
| 43 |
text: root.controller.title |
| 44 |
visible: root.controller.showTitle && text.length > 0 |
| 45 |
level: 2 |
| 46 |
TextMetrics { |
| 47 |
id: titleMetrics |
| 48 |
font: heading.font |
| 49 |
text: heading.text |
| 50 |
} |
| 51 |
} |
| 52 |
RowLayout { |
| 53 |
spacing: Kirigami.Units.smallSpacing |
| 54 |
Layout.fillHeight: true |
| 55 |
Layout.topMargin: showYAxisLabels ? axisMetrics.height / 2 : 0 |
| 56 |
Layout.bottomMargin: Layout.topMargin |
| 57 |
|
| 58 |
Layout.minimumHeight: root.formFactor === Faces.SensorFace.Constrained |
| 59 |
? 3 * Kirigami.Units.gridUnit |
| 60 |
: 5 * Kirigami.Units.gridUnit |
| 61 |
Layout.preferredHeight: 8 * Kirigami.Units.gridUnit |
| 62 |
|
| 63 |
ChartsControls.AxisLabels { |
| 64 |
id: axisLabels |
| 65 |
visible: showYAxisLabels |
| 66 |
Layout.fillHeight: true |
| 67 |
constrainToBounds: false |
| 68 |
delegate: QQC2.Label { |
| 69 |
anchors.right: parent.right |
| 70 |
font: Kirigami.Theme.smallFont |
| 71 |
text: Formatter.Formatter.formatValueShowNull(ChartsControls.AxisLabels.label, |
| 72 |
compactRepresentation.sensorsModel.unit) |
| 73 |
opacity: 0.75 |
| 74 |
} |
| 75 |
direction: ChartsControls.AxisLabels.VerticalBottomTop |
| 76 |
source: Charts.ChartAxisSource { |
| 77 |
chart: compactRepresentation |
| 78 |
axis: Charts.ChartAxisSource.YAxis |
| 79 |
itemCount: 5 |
| 80 |
} |
| 81 |
TextMetrics { |
| 82 |
id: axisMetrics |
| 83 |
font: Kirigami.Theme.smallFont |
| 84 |
text: Formatter.Formatter.formatValueShowNull("0", |
| 85 |
compactRepresentation.sensorsModel.data(compactRepresentation.sensorsModel.index(0, 0), Sensors.SensorDataModel.Unit)) |
| 86 |
} |
| 87 |
} |
| 88 |
BarChart { |
| 89 |
id: compactRepresentation |
| 90 |
Layout.fillWidth: true |
| 91 |
Layout.fillHeight: true |
| 92 |
|
| 93 |
updateRateLimit: root.controller.updateRateLimit |
| 94 |
|
| 95 |
controller: root.controller |
| 96 |
|
| 97 |
highlight: legend.highlightedIndex |
| 98 |
|
| 99 |
ChartsControls.GridLines { |
| 100 |
id: horizontalLines |
| 101 |
visible: showGridLines |
| 102 |
direction: horizontalBars ? ChartsControls.GridLines.Horizontal : ChartsControls.GridLines.Vertical |
| 103 |
anchors.fill: compactRepresentation |
| 104 |
z: compactRepresentation.z - 1 |
| 105 |
chart: compactRepresentation |
| 106 |
|
| 107 |
major.count: 3 |
| 108 |
major.lineWidth: 1 |
| 109 |
// The same color as Kirigami.Separator |
| 110 |
major.color: Kirigami.ColorUtils.linearInterpolation(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.2) |
| 111 |
minor.visible: false |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
Faces.ExtendedLegend { |
| 117 |
id: legend |
| 118 |
|
| 119 |
Layout.fillWidth: true |
| 120 |
Layout.fillHeight: true |
| 121 |
Layout.minimumHeight: implicitHeight |
| 122 |
visible: root.showLegend |
| 123 |
chart: compactRepresentation |
| 124 |
sourceModel: root.showLegend ? compactRepresentation.sensorsModel : null |
| 125 |
sensorIds: root.showLegend ? root.controller.lowPrioritySensorIds : [] |
| 126 |
updateRateLimit: root.controller.updateRateLimit |
| 127 |
} |
| 128 |
} |
| 129 |
} |