From 6ae32dffa9939ee2a8ba1241659a9540dd88496b Mon Sep 17 00:00:00 2001 From: dodoradio Date: Sun, 20 Aug 2023 16:32:47 +0100 Subject: steps preview: make step goal line change colour with target we also move the indicator line up in the z stack, as we want the line above the bars. This wasn't obvious before as the elements were all the same colour. The two processing functions, clamp and interpolateColors are probably not optimally placed in the code. These might move. --- src/graphs/BarGraph.qml | 12 ++++++++++-- src/stepCounter/StepCounterPreview.qml | 1 + src/stepCounter/StepsDetailPage.qml | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/graphs/BarGraph.qml b/src/graphs/BarGraph.qml index 9674832..08415a3 100644 --- a/src/graphs/BarGraph.qml +++ b/src/graphs/BarGraph.qml @@ -26,6 +26,7 @@ Item { property var labelsArr: [] property var maxValue: 0 property real indicatorLineHeight: 0 + property color indicatorLineColor: "#FFFFFF" signal barClicked(index: int) function dataLoadingDone() { barsRepeater.model = 0 @@ -47,15 +48,16 @@ Item { Rectangle { // indicator line id: indicatorLine height: 1 - z: 1 + z: 2 width: barsRepeater.count*(barGraph.width-markerParent.width)/Math.max(barGraph.valuesArr.length,3) - height/2 anchors.left: markerParent.right y: barsRow.height*(1-(barGraph,indicatorLineHeight/barGraph.maxValue)) visible: barGraph.indicatorLineHeight != 0 + color: barGraph.indicatorLineColor } Row { // bars id: barsRow - z: 2 + z: 1 anchors { left: markerParent.right top: parent.top @@ -100,4 +102,10 @@ Item { } } } + function interpolateColors(color1, color2, position) { + return Qt.rgba(color1.r + (color2.r-color1.r)*position, color1.g+ (color2.g-color1.g)*position, color1.b + (color2.b-color1.b)*position,1) + } + function clamp(num, min, max) { + return Math.min(Math.max(num, min), max) + } } diff --git a/src/stepCounter/StepCounterPreview.qml b/src/stepCounter/StepCounterPreview.qml index 9042dd7..823f739 100644 --- a/src/stepCounter/StepCounterPreview.qml +++ b/src/stepCounter/StepCounterPreview.qml @@ -83,6 +83,7 @@ MouseArea { dataLoadingDone() } indicatorLineHeight: loggerSettings.stepGoalEnabled ? loggerSettings.stepGoalTarget : 0 + indicatorLineColor: interpolateColors(Qt.rgba(1,0,0,1),Qt.rgba(0.06,1,0.11,1),clamp(stepsDataLoader.todayTotal/loggerSettings.stepGoalTarget,0,1)) onBarClicked: (index)=> { var d = new Date() d.setDate(d.getDate() - valuesArr.length + 1 + index) diff --git a/src/stepCounter/StepsDetailPage.qml b/src/stepCounter/StepsDetailPage.qml index 7949a2f..2862eea 100644 --- a/src/stepCounter/StepsDetailPage.qml +++ b/src/stepCounter/StepsDetailPage.qml @@ -91,6 +91,7 @@ Item { } } } + indicatorLineColor = interpolateColors(Qt.rgba(1,0,0,1),Qt.rgba(0.06,1,0.11,1),clamp(stepsDataLoader.getTotalForDate(stepsLineGraph.startTime)/loggerSettings.stepGoalTarget,0,1)) dataLoadingDone() } indicatorLineHeight: loggerSettings.stepGoalEnabled ? loggerSettings.stepGoalTarget : 0 -- cgit v1.2.3-70-g09d2