X Axis step & NLog set (all [1...9]*10^n)

This commit is contained in:
Adsooi 2020-12-25 19:55:47 +01:00
parent ef87b8362c
commit 8aa6ac7e88
6 changed files with 58 additions and 8 deletions

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.7 import QtQuick 2.7
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0

View file

@ -105,6 +105,7 @@ ApplicationWindow {
xlabel: settings.xaxislabel xlabel: settings.xaxislabel
ylabel: settings.yaxislabel ylabel: settings.yaxislabel
yaxisstep: settings.yaxisstep yaxisstep: settings.yaxisstep
xaxisstep: settings.xaxisstep
logscalex: settings.logscalex logscalex: settings.logscalex
onPaint: { onPaint: {
@ -125,9 +126,11 @@ ApplicationWindow {
"yzoom": settings.yzoom, "yzoom": settings.yzoom,
"xmin": settings.xmin, "xmin": settings.xmin,
"ymax": settings.ymax, "ymax": settings.ymax,
"xaxisstep": settings.xaxisstep,
"yaxisstep": settings.yaxisstep, "yaxisstep": settings.yaxisstep,
"xaxislabel": settings.xaxislabel, "xaxislabel": settings.xaxislabel,
"yaxislabel": settings.yaxislabel, "yaxislabel": settings.yaxislabel,
"logscalex": settings.logscalex,
"width": root.width, "width": root.width,
"height": root.height, "height": root.height,
"objects": objs, "objects": objs,
@ -142,9 +145,11 @@ ApplicationWindow {
settings.yzoom = data["yzoom"] settings.yzoom = data["yzoom"]
settings.xmin = data["xmin"] settings.xmin = data["xmin"]
settings.ymax = data["ymax"] settings.ymax = data["ymax"]
settings.xaxisstep = data["xaxisstep"]
settings.yaxisstep = data["yaxisstep"] settings.yaxisstep = data["yaxisstep"]
settings.xaxislabel = data["xaxislabel"] settings.xaxislabel = data["xaxislabel"]
settings.yaxislabel = data["yaxislabel"] settings.yaxislabel = data["yaxislabel"]
settings.logscalex = data["logscalex"]
root.height = data["height"] root.height = data["height"]
root.width = data["width"] root.width = data["width"]

View file

@ -33,7 +33,8 @@ Canvas {
property double ymax: 0 property double ymax: 0
property int xzoom: 10 property int xzoom: 10
property int yzoom: 10 property int yzoom: 10
property string yaxisstep: "3" property string xaxisstep: "4"
property string yaxisstep: "4"
property string xlabel: "" property string xlabel: ""
property string ylabel: "" property string ylabel: ""
property int maxgradx: 8 property int maxgradx: 8
@ -42,6 +43,9 @@ Canvas {
property var yaxisstepExpr: (new MathLib.Expression(`x*(${yaxisstep})`)) property var yaxisstepExpr: (new MathLib.Expression(`x*(${yaxisstep})`))
property double yaxisstep1: yaxisstepExpr.execute(1) property double yaxisstep1: yaxisstepExpr.execute(1)
property int drawMaxY: Math.ceil(Math.max(Math.abs(ymax), Math.abs(px2y(canvasSize.height)))/yaxisstep1) 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: { onPaint: {
@ -79,10 +83,9 @@ Canvas {
} }
} }
} else { } else {
for(var x = 0; x < 40*maxgradx; x+=1) { for(var x = 0; x < drawMaxX; x+=1) {
// TODO: Fill screen based drawXLine(ctx, x*xaxisstep1)
drawXLine(ctx, x*yaxisstep1) drawXLine(ctx, -x*xaxisstep1)
drawXLine(ctx, -x*yaxisstep1)
} }
} }
for(var y = 0; y < drawMaxY; y+=1) { for(var y = 0; y < drawMaxY; y+=1) {

View file

@ -34,6 +34,7 @@ Column {
property int yzoom: 10 property int yzoom: 10
property double xmin: 5/10 property double xmin: 5/10
property double ymax: 25 property double ymax: 25
property string xaxisstep: "4"
property string yaxisstep: "4" property string yaxisstep: "4"
property string xaxislabel: "" property string xaxislabel: ""
property string yaxislabel: "" property string yaxislabel: ""
@ -113,7 +114,6 @@ Column {
TextSetting { TextSetting {
id: yAxisStep id: yAxisStep
height: 30 height: 30
//isInt: true
label: "Y Axis Step" label: "Y Axis Step"
width: settings.settingWidth width: settings.settingWidth
defValue: settings.yaxisstep 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 { ComboBoxSetting {
id: xAxisLabel id: xAxisLabel
height: 30 height: 30

View file

@ -132,6 +132,10 @@ class Domain {
case "ℤ⁺": case "ℤ⁺":
return Domain.N return Domain.N
break; break;
case "NLOG":
case "ℕˡᵒᵍ":
return Domain.NLog
break;
case "NE": case "NE":
case "NP": case "NP":
case "N*": 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, Domain.ZME = new SpecialDomain('ℤ⁻*', x => x%1==0 && x < 0,
x => Math.min(Math.floor(x)+1, -1), x => Math.min(Math.floor(x)+1, -1),
x => Math.min(Math.ceil(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 = [] var refedDomains = []

View file

@ -282,7 +282,6 @@ class Function extends ExecutableObject {
var previousY; var previousY;
var draw = function(currentX) { var draw = function(currentX) {
} }
console.log('Drawing', inDomain, inDomain instanceof MathLib.SpecialDomain)
if(inDomain instanceof MathLib.SpecialDomain && inDomain.moveSupported) { if(inDomain instanceof MathLib.SpecialDomain && inDomain.moveSupported) {
previousX = inDomain.previous(previousX) previousX = inDomain.previous(previousX)
if(previousX === null) previousX = inDomain.next(canvas.px2x(0)) if(previousX === null) previousX = inDomain.next(canvas.px2x(0))