This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBarGraph.qml
145 lines (127 loc) · 5.02 KB
/
BarGraph.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/***************************************************************************
* Whatsoever ye do in word or deed, do all in the name of the *
* Lord Jesus, giving thanks to God and the Father by him. *
* - Colossians 3:17 *
* *
* Ubuntu UI Extras - A collection of QML widgets not available *
* in the default Ubuntu UI Toolkit *
* Copyright (C) 2013 Michael Spencer <sonrisesoftware@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
import QtQuick 2.0
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 1.0
Item {
id: root
property var colors: []
property var values: [[]]
property var names: []
property var labels: []
property bool autoSize: false // true to show more values the wider the graph
property int count: autoSize ? Math.round((graph.width + repeater.spacing)/(barWidth + repeater.spacing), 0) - 1 : values.length
property int maxValue
property int barWidth: autoSize ? units.gu(3) : units.gu(3) // TODO: Auto calculate?
property real scale: (graph.height - 2)/maxValue
function shouldDisplay(index) {
var max = 10
var total = count
//print("Should Display?", 10 % (index * 10/total))
var result = 10 % (index * 10/total)
return true
}
Row {
id: legendBar
anchors {
top: parent.top
horizontalCenter: parent.horizontalCenter
margins: units.gu(2)
}
spacing: units.gu(3)
Repeater {
model: names.length
delegate: Row {
spacing: units.gu(1)
UbuntuShape {
anchors.verticalCenter: parent.verticalCenter
width: units.gu(3)
height: width
color: colors[index]
}
Label {
anchors.verticalCenter: parent.verticalCenter
text: names[index]
//color: Theme.palette.normal.overlayText
}
}
}
}
UbuntuShape {
id: graph
color: "white"
//border.color: "darkgray"
radius: "medium"
anchors {
top: legendBar.bottom
left: parent.left
leftMargin: units.gu(4)
right: parent.right
bottom: parent.bottom
margins: units.gu(2)
bottomMargin: units.gu(9)
}
Repeater {
model: root.maxValue + 1
delegate: Rectangle {
visible: shouldDisplay(index)
color: index === root.maxValue || index === 0 ? "transparent" : "lightgray"
height: 1
y: root.scale * index + 1
anchors {
left: parent.left
right: parent.right
margins: 1
}
Label {
text: root.maxValue - modelData
visible: shouldDisplay(index)
//color: Theme.palette.normal.overlayText
anchors {
right: parent.left
rightMargin: units.gu(1)
verticalCenter: parent.verticalCenter
}
}
}
}
Row {
id: repeater
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
}
spacing: units.gu(1)
Repeater {
model: root.values
delegate: BarGraphBar {
graph: root
width: barWidth
height: graph.height
values: root.values[index]
label: labels[index] || ""
}
}
}
}
}