Warning, /plasma/libksysguard/faces/facepackages/barchart/contents/ui/FullRepresentation.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
0004     SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
0005     SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 import QtQuick
0011 import QtQuick.Controls as QQC2
0012 import QtQuick.Layouts
0013 
0014 import org.kde.kirigami as Kirigami
0015 
0016 import org.kde.ksysguard.sensors as Sensors
0017 import org.kde.ksysguard.faces as Faces
0018 import org.kde.ksysguard.formatter as Formatter
0019 
0020 import org.kde.quickcharts as Charts
0021 import org.kde.quickcharts.controls as ChartsControls
0022 
0023 Faces.SensorFace {
0024     id: root
0025 
0026     readonly property bool showLegend: controller.faceConfiguration.showLegend
0027     readonly property bool showGridLines: root.controller.faceConfiguration.showGridLines
0028     readonly property bool showYAxisLabels: root.controller.faceConfiguration.showYAxisLabels
0029 
0030     // Arbitrary minimumWidth to make easier to align plasmoids in a predictable way
0031     Layout.minimumWidth: Math.max(Kirigami.Units.gridUnit * compactRepresentation.barCount, Kirigami.Units.gridUnit * 8)
0032     Layout.preferredWidth: titleMetrics.width
0033 
0034     contentItem: ColumnLayout {
0035         spacing: Kirigami.Units.largeSpacing
0036 
0037         Kirigami.Heading {
0038             id: heading
0039             Layout.fillWidth: true
0040             horizontalAlignment: Text.AlignHCenter
0041             elide: Text.ElideRight
0042             text: root.controller.title
0043             visible: root.controller.showTitle && text.length > 0
0044             level: 2
0045             TextMetrics {
0046                 id: titleMetrics
0047                 font: heading.font
0048                 text: heading.text
0049             }
0050         }
0051         RowLayout {
0052             spacing: Kirigami.Units.smallSpacing
0053             Layout.fillHeight: true
0054             Layout.topMargin: showYAxisLabels ? axisMetrics.height / 2 : 0
0055             Layout.bottomMargin: Layout.topMargin
0056 
0057             Layout.minimumHeight: root.formFactor === Faces.SensorFace.Constrained
0058                 ? 3 * Kirigami.Units.gridUnit
0059                 : 5 * Kirigami.Units.gridUnit
0060             Layout.preferredHeight: 8 * Kirigami.Units.gridUnit
0061 
0062             ChartsControls.AxisLabels {
0063                 id: axisLabels
0064                 visible: showYAxisLabels
0065                 Layout.fillHeight: true
0066                 constrainToBounds: false
0067                 delegate: QQC2.Label {
0068                     anchors.right: parent.right
0069                     font: Kirigami.Theme.smallFont
0070                     text: Formatter.Formatter.formatValueShowNull(ChartsControls.AxisLabels.label,
0071                                                                   compactRepresentation.sensorsModel.unit)
0072                     color: Kirigami.Theme.disabledTextColor
0073                 }
0074                 direction: ChartsControls.AxisLabels.VerticalBottomTop
0075                 source: Charts.ChartAxisSource {
0076                     chart: compactRepresentation
0077                     axis: Charts.ChartAxisSource.YAxis
0078                     itemCount: 5
0079                 }
0080                 TextMetrics {
0081                     id: axisMetrics
0082                     font: Kirigami.Theme.smallFont
0083                     text: Formatter.Formatter.formatValueShowNull("0",
0084                         compactRepresentation.sensorsModel.data(compactRepresentation.sensorsModel.index(0, 0), Sensors.SensorDataModel.Unit))
0085                 }
0086             }
0087             BarChart {
0088                 id: compactRepresentation
0089                 Layout.fillWidth: true
0090                 Layout.fillHeight: true
0091 
0092                 updateRateLimit: root.controller.updateRateLimit
0093 
0094                 controller: root.controller
0095 
0096                 ChartsControls.GridLines {
0097                     id: horizontalLines
0098                     visible: showGridLines
0099                     direction: ChartsControls.GridLines.Vertical
0100                     anchors.fill: compactRepresentation
0101                     z: compactRepresentation.z - 1
0102                     chart: compactRepresentation
0103 
0104                     major.count: 3
0105                     major.lineWidth: 1
0106                     // The same color as Kirigami.Separator
0107                     major.color: Kirigami.ColorUtils.linearInterpolation(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.2)
0108                     minor.visible: false
0109                 }
0110             }
0111         }
0112 
0113         Faces.ExtendedLegend {
0114             Layout.fillWidth: true
0115             Layout.fillHeight: true
0116             Layout.minimumHeight: implicitHeight
0117             visible: root.showLegend
0118             chart: compactRepresentation
0119             sourceModel: root.showLegend ? compactRepresentation.sensorsModel : null
0120             sensorIds: root.showLegend ? root.controller.lowPrioritySensorIds : []
0121             updateRateLimit: root.controller.updateRateLimit
0122         }
0123     }
0124 }