Debian Codegraph @

src/imports/PerformanceMetrics/2.0/BarGraph.qml

raw
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components 2.0
19 import Lomiri.PerformanceMetrics 1.0 as PerformanceMetrics
20
21 Item {
22 id: graph
23
24 property var model
25 property real maximumValue
26 property alias labels: labelsRepeater.model
27 property alias backgroundColor: background.color
28 property color color: Qt.rgba(0.4, 0.73, 0.4, 1.0)
29 property real threshold: 16.0
30 property color aboveThresholdColor: "#ff4e00"
31 property string labelFormat: "%1"
32
33 implicitWidth: units.gu(38)
34 implicitHeight: units.gu(8)
35
36 Rectangle {
37 id: background
38 anchors.fill: parent
39 color: Qt.rgba(0.0, 0.0, 0.0, 0.8)
40 }
41
42 PerformanceMetrics.TextureFromImage {
43 id: texture
44 image: graph.model.image
45 }
46
47 ShaderEffect {
48 anchors.fill: parent
49
50 property var texture0: texture
51 property real shift: graph.model.shift / graph.model.samples
52 property real maximumValue: graph.maximumValue
53 property color color: graph.color
54 property real threshold: graph.threshold
55 property color aboveThresholdColor: graph.aboveThresholdColor
56
57 vertexShader: "qrc:/2.0/shaders/bargraph.vert.qsb"
58 fragmentShader: "qrc:/2.0/shaders/bargraph.frag.qsb"
59 }
60
61 Repeater {
62 id: labelsRepeater
63
64 Item {
65 anchors {
66 left: parent.left
67 right: parent.right
68 bottom: parent.bottom
69 bottomMargin: modelData.value / graph.maximumValue * parent.height
70 }
71
72 Label {
73 id: label
74 anchors {
75 left: parent.left
76 leftMargin: units.gu(0.5)
77 verticalCenter: parent.verticalCenter
78 }
79 text: modelData.label
80 color: modelData.color
81 textSize: Label.XSmall
82 }
83
84 Rectangle {
85 anchors {
86 left: label.right
87 leftMargin: units.gu(0.5)
88 right: parent.right
89 }
90 height: 1
91 color: modelData.color
92 }
93 }
94 }
95
96 Label {
97 anchors {
98 top: parent.top
99 topMargin: units.gu(1)
100 right: parent.right
101 rightMargin: units.gu(1)
102 }
103 text: graph.labelFormat.arg(graph.model.currentValue)
104 color: "white"
105 }
106 }