From a2fa16949ad10d096a361a53bc3bb49a5af5e0cb Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Tue, 17 Sep 2024 01:58:34 +0200 Subject: [PATCH] Fixing some bugs, including outzooming too much. --- .../LogarithmPlotter/LogGraphCanvas.qml | 6 ++++++ .../ViewPositionChangeOverlay.qml | 21 ++++++++++++------- .../eu/ad5001/LogarithmPlotter/js/canvas.mjs | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml index 2f7f259..8d4b2f2 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml @@ -120,6 +120,12 @@ Canvas { */ property bool showygrad: false + /*! + \qmlproperty int LogGraphCanvas::maxgradx + Max power of the logarithmic scaled on the x axis in logarithmic mode. + */ + property int maxgradx: 90 + /*! \qmlproperty var LogGraphCanvas::imageLoaders Dictionary of format {image: [callback.image data]} containing data for defered image loading. diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ViewPositionChangeOverlay.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ViewPositionChangeOverlay.qml index 3d5ff68..6ba180e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ViewPositionChangeOverlay.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ViewPositionChangeOverlay.qml @@ -94,9 +94,13 @@ Item { property int positionChangeTimer: 0 function updatePosition(deltaX, deltaY) { - settingsInstance.xmin = (Modules.Canvas.px2x(Modules.Canvas.x2px(settingsInstance.xmin)-deltaX)) - settingsInstance.ymax += deltaY/canvas.yzoom - settingsInstance.ymax = settingsInstance.ymax.toFixed(4) + const unauthorized = [NaN, Infinity, -Infinity] + const xmin = (Modules.Canvas.px2x(Modules.Canvas.x2px(settingsInstance.xmin)-deltaX)) + const ymax = settingsInstance.ymax + deltaY/canvas.yzoom + if(!unauthorized.includes(xmin)) + settingsInstance.xmin = xmin + if(!unauthorized.includes(ymax)) + settingsInstance.ymax = ymax.toFixed(4) settingsInstance.changed() parent.positionChanged(deltaX, deltaY) @@ -140,12 +144,15 @@ Item { } let newXZoom = (settingsInstance.xzoom+xZoomDelta).toFixed(0) let newYZoom = (settingsInstance.yzoom+yZoomDelta).toFixed(0) - if(newXZoom == settingsInstance.xzoom) // No change, allow more precision. + // Check if we need to have more precision + if(newXZoom < 10) newXZoom = (settingsInstance.xzoom+xZoomDelta).toFixed(4) - if(newYZoom == settingsInstance.yzoom) // No change, allow more precision. + if(newYZoom < 10) newYZoom = (settingsInstance.yzoom+yZoomDelta).toFixed(4) - settingsInstance.xzoom = newXZoom - settingsInstance.yzoom = newYZoom + if(newXZoom > 0.5) + settingsInstance.xzoom = newXZoom + if(newYZoom > 0.5) + settingsInstance.yzoom = newYZoom settingsInstance.changed() } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/canvas.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/canvas.mjs index 2892303..2a03677 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/canvas.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/canvas.mjs @@ -17,7 +17,7 @@ */ import { Module } from "./modules.mjs" -import { textsup, roundAwayFromZero } from "./utils.mjs" +import { textsup } from "./utils.mjs" import { Expression } from "./mathlib.mjs" import Latex from "./math/latex.mjs"