summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordodoradio <dodoradio@outlook.com>2023-07-21 15:31:54 +0100
committerdodoradio <dodoradio@outlook.com>2023-07-21 16:51:05 +0100
commitec655ab2d3a0c02af0a451e8862355ecd700671e (patch)
treee0d2f83dabf7f366b81147e2285d142b5c2f1d1c /src
parent69ee975bf761578f59ba41b21575f7c0764b3681 (diff)
Add interactive functionality to bar graph
Diffstat (limited to '')
-rw-r--r--src/graphs/BarGraph.qml8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/graphs/BarGraph.qml b/src/graphs/BarGraph.qml
index c55097f..9674832 100644
--- a/src/graphs/BarGraph.qml
+++ b/src/graphs/BarGraph.qml
@@ -22,10 +22,14 @@ import org.asteroid.controls 1.0
Item {
id: barGraph
property var valuesArr: []
+ property var colorsArr: []
property var labelsArr: []
property var maxValue: 0
property real indicatorLineHeight: 0
+ signal barClicked(index: int)
function dataLoadingDone() {
+ barsRepeater.model = 0
+ labelsRepeater.model = 0 // qml doesn't refresh arrays in the same way it does other properties, so this refresh is needed
barsRepeater.model = valuesArr.length
labelsRepeater.model = labelsArr.length
}
@@ -59,7 +63,7 @@ Item {
}
Repeater {
id: barsRepeater
- delegate: Item { //this contains the graph column and positions it correctly
+ delegate: MouseArea { //this contains the graph column and positions it correctly
width: (barGraph.width-markerParent.width)/Math.max(barGraph.valuesArr.length,3)
height: parent.height
Rectangle {
@@ -70,7 +74,9 @@ Item {
radius: width/2
property int value: barGraph.valuesArr[index]
height: (value/barGraph.maxValue)*parent.height
+ color: barGraph.colorsArr.length > index ? barGraph.colorsArr[index] : "#FFF"
}
+ onClicked: barGraph.barClicked(index)
}
}
}