From 8aa6ac7e8806f5a1952b4dca6394d2620f6ec358 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Fri, 25 Dec 2020 19:55:47 +0100 Subject: [PATCH] X Axis step & NLog set (all [1...9]*10^n) --- qml/Icon.qml | 17 +++++++++++++++++ qml/LogGraph.qml | 5 +++++ qml/LogGraphCanvas.qml | 13 ++++++++----- qml/Settings.qml | 15 ++++++++++++++- qml/js/mathlib.js | 15 ++++++++++++++- qml/js/objects.js | 1 - 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/qml/Icon.qml b/qml/Icon.qml index a29159f..3aee332 100644 --- a/qml/Icon.qml +++ b/qml/Icon.qml @@ -1,3 +1,20 @@ +/** + * Logarithm Graph Creator - Create graphs with logarithm scales. + * Copyright (C) 2020 Ad5001 + * + * 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 3 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 . + */ import QtQuick 2.7 import QtGraphicalEffects 1.0 diff --git a/qml/LogGraph.qml b/qml/LogGraph.qml index 960f3d8..5a8b2f5 100644 --- a/qml/LogGraph.qml +++ b/qml/LogGraph.qml @@ -105,6 +105,7 @@ ApplicationWindow { xlabel: settings.xaxislabel ylabel: settings.yaxislabel yaxisstep: settings.yaxisstep + xaxisstep: settings.xaxisstep logscalex: settings.logscalex onPaint: { @@ -125,9 +126,11 @@ ApplicationWindow { "yzoom": settings.yzoom, "xmin": settings.xmin, "ymax": settings.ymax, + "xaxisstep": settings.xaxisstep, "yaxisstep": settings.yaxisstep, "xaxislabel": settings.xaxislabel, "yaxislabel": settings.yaxislabel, + "logscalex": settings.logscalex, "width": root.width, "height": root.height, "objects": objs, @@ -142,9 +145,11 @@ ApplicationWindow { settings.yzoom = data["yzoom"] settings.xmin = data["xmin"] settings.ymax = data["ymax"] + settings.xaxisstep = data["xaxisstep"] settings.yaxisstep = data["yaxisstep"] settings.xaxislabel = data["xaxislabel"] settings.yaxislabel = data["yaxislabel"] + settings.logscalex = data["logscalex"] root.height = data["height"] root.width = data["width"] diff --git a/qml/LogGraphCanvas.qml b/qml/LogGraphCanvas.qml index f82c238..d50837c 100644 --- a/qml/LogGraphCanvas.qml +++ b/qml/LogGraphCanvas.qml @@ -33,7 +33,8 @@ Canvas { property double ymax: 0 property int xzoom: 10 property int yzoom: 10 - property string yaxisstep: "3" + property string xaxisstep: "4" + property string yaxisstep: "4" property string xlabel: "" property string ylabel: "" property int maxgradx: 8 @@ -42,6 +43,9 @@ Canvas { property var yaxisstepExpr: (new MathLib.Expression(`x*(${yaxisstep})`)) property double yaxisstep1: yaxisstepExpr.execute(1) property int drawMaxY: Math.ceil(Math.max(Math.abs(ymax), Math.abs(px2y(canvasSize.height)))/yaxisstep1) + property var xaxisstepExpr: (new MathLib.Expression(`x*(${xaxisstep})`)) + property double xaxisstep1: xaxisstepExpr.execute(1) + property int drawMaxX: Math.ceil(Math.max(Math.abs(xmin), Math.abs(px2x(canvasSize.width)))/xaxisstep1) onPaint: { @@ -79,10 +83,9 @@ Canvas { } } } else { - for(var x = 0; x < 40*maxgradx; x+=1) { - // TODO: Fill screen based - drawXLine(ctx, x*yaxisstep1) - drawXLine(ctx, -x*yaxisstep1) + for(var x = 0; x < drawMaxX; x+=1) { + drawXLine(ctx, x*xaxisstep1) + drawXLine(ctx, -x*xaxisstep1) } } for(var y = 0; y < drawMaxY; y+=1) { diff --git a/qml/Settings.qml b/qml/Settings.qml index 86715c8..21636ee 100644 --- a/qml/Settings.qml +++ b/qml/Settings.qml @@ -34,6 +34,7 @@ Column { property int yzoom: 10 property double xmin: 5/10 property double ymax: 25 + property string xaxisstep: "4" property string yaxisstep: "4" property string xaxislabel: "" property string yaxislabel: "" @@ -113,7 +114,6 @@ Column { TextSetting { id: yAxisStep height: 30 - //isInt: true label: "Y Axis Step" width: settings.settingWidth defValue: settings.yaxisstep @@ -123,6 +123,19 @@ Column { } } + TextSetting { + id: xAxisStep + height: 30 + label: "X Axis Step" + width: settings.settingWidth + defValue: settings.xaxisstep + visible: !settings.logscalex + onChanged: function(newValue) { + settings.xaxisstep = newValue + settings.changed() + } + } + ComboBoxSetting { id: xAxisLabel height: 30 diff --git a/qml/js/mathlib.js b/qml/js/mathlib.js index b2ead97..f5515e4 100644 --- a/qml/js/mathlib.js +++ b/qml/js/mathlib.js @@ -132,6 +132,10 @@ class Domain { case "ℤ⁺": return Domain.N break; + case "NLOG": + case "ℕˡᵒᵍ": + return Domain.NLog + break; case "NE": case "NP": case "N*": @@ -536,7 +540,16 @@ Domain.ZM = new SpecialDomain('ℤ⁻', x => x%1==0 && x <= 0, Domain.ZME = new SpecialDomain('ℤ⁻*', x => x%1==0 && x < 0, x => Math.min(Math.floor(x)+1, -1), x => Math.min(Math.ceil(x)-1, -1)) - +Domain.NLog = new SpecialDomain('ℕˡᵒᵍ', + x => x/Math.pow(10, x.toString().length-1) % 1 == 0 && x > 0, + function(x) { + var x10pow = Math.pow(10, x.toString().length-1) + return Math.max(1, (Math.floor(x/x10pow)+1)*x10pow) + }, + function(x) { + var x10pow = Math.pow(10, x.toString().length-1) + return Math.max(1, (Math.ceil(x/x10pow)-1)*x10pow) + }) var refedDomains = [] diff --git a/qml/js/objects.js b/qml/js/objects.js index a52c89d..b7fbf24 100644 --- a/qml/js/objects.js +++ b/qml/js/objects.js @@ -282,7 +282,6 @@ class Function extends ExecutableObject { var previousY; var draw = function(currentX) { } - console.log('Drawing', inDomain, inDomain instanceof MathLib.SpecialDomain) if(inDomain instanceof MathLib.SpecialDomain && inDomain.moveSupported) { previousX = inDomain.previous(previousX) if(previousX === null) previousX = inDomain.next(canvas.px2x(0))