From 23f96c214b68021fd84bca3b16a27481189dd564 Mon Sep 17 00:00:00 2001 From: "Jasper v. Blanckenburg" Date: Sat, 28 Jan 2023 17:51:10 +0100 Subject: [PATCH] Zoom & scroll profile chart --- ui/main_window.qml | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/ui/main_window.qml b/ui/main_window.qml index c8053c6..20c5ad3 100644 --- a/ui/main_window.qml +++ b/ui/main_window.qml @@ -30,15 +30,22 @@ ApplicationWindow { function onProfileChanged(data) { profile_handler.fill_series(profileSeries); - axisX.max = data[data.length - 1][0]; + var x_max = data[data.length - 1][0]; + axisX.max = x_max; axisX.applyNiceNumbers(); + profileView.zoomReset(); } } onProfileTimeChanged: { + var old_x = profileView.mapToPosition(currentTimeSeries.at(0)).x; currentTimeSeries.clear() currentTimeSeries.append(profileTime, 0) currentTimeSeries.append(profileTime, 100) + var new_x = profileView.mapToPosition(currentTimeSeries.at(0)).x; + if (new_x > profileView.plotArea.width / 2) { + profileView.scrollRight(new_x - old_x); + } } onBmsErrorChanged: { @@ -63,6 +70,8 @@ ApplicationWindow { } } ChartView { + id: profileView + Layout.fillWidth: true Layout.fillHeight: true Layout.minimumWidth: 400 @@ -97,6 +106,28 @@ ApplicationWindow { visible: true } } + RowLayout { + Button { + text: "+" + onClicked: { + var r = Qt.rect(profileView.plotArea.x, profileView.plotArea.y, profileView.plotArea.width / 2, profileView.plotArea.height); + profileView.zoomIn(r); + } + } + Button { + text: "-" + onClicked: { + var r = Qt.rect(profileView.plotArea.x, profileView.plotArea.y, profileView.plotArea.width * 2, profileView.plotArea.height); + profileView.zoomIn(r); + } + } + Button { + text: "Reset zoom" + onClicked: { + profileView.zoomReset(); + } + } + } RowLayout { Button { objectName: "start_pause"