Display/Hide scales (not saved yet)

This commit is contained in:
Adsooi 2021-01-26 18:36:21 +01:00
parent 6d1c3d5450
commit 018ad08348
3 changed files with 50 additions and 20 deletions

View file

@ -107,6 +107,8 @@ ApplicationWindow {
yaxisstep: settings.yaxisstep yaxisstep: settings.yaxisstep
xaxisstep: settings.xaxisstep xaxisstep: settings.xaxisstep
logscalex: settings.logscalex logscalex: settings.logscalex
showxgrad: settings.showxgrad
showygrad: settings.showygrad
onPaint: { onPaint: {
var ctx = getContext("2d"); var ctx = getContext("2d");

View file

@ -39,6 +39,8 @@ Canvas {
property string ylabel: "" property string ylabel: ""
property int maxgradx: 8 property int maxgradx: 8
property bool logscalex: false property bool logscalex: false
property bool showxgrad: false
property bool showygrad: false
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)
@ -121,28 +123,32 @@ Canvas {
ctx.font = "12px sans-serif" ctx.font = "12px sans-serif"
var txtMinus = ctx.measureText('-').width var txtMinus = ctx.measureText('-').width
if(logscalex) { if(showxgrad) {
for(var xpow = -maxgradx; xpow <= maxgradx; xpow+=1) { if(logscalex) {
var textSize = ctx.measureText("10"+Utils.textsup(xpow)).width for(var xpow = -maxgradx; xpow <= maxgradx; xpow+=1) {
if(xpow != 0) var textSize = ctx.measureText("10"+Utils.textsup(xpow)).width
drawVisibleText(ctx, "10"+Utils.textsup(xpow), x2px(Math.pow(10,xpow))-textSize/2, axisxpx+16+(6*(y==0))) if(xpow != 0)
} drawVisibleText(ctx, "10"+Utils.textsup(xpow), x2px(Math.pow(10,xpow))-textSize/2, axisxpx+16+(6*(y==0)))
} else { }
for(var x = 1; x < drawMaxX; x += 1) { } else {
var drawX = x*xaxisstep1 for(var x = 1; x < drawMaxX; x += 1) {
var txtX = xaxisstepExpr.simplify(x) var drawX = x*xaxisstep1
var textSize = measureText(ctx, txtX, 6).height var txtX = xaxisstepExpr.simplify(x)
drawVisibleText(ctx, txtX, x2px(drawX)-4, axisxpx+6+textSize) var textSize = measureText(ctx, txtX, 6).height
drawVisibleText(ctx, '-'+txtX, x2px(-drawX)-4, axisxpx+6+textSize) drawVisibleText(ctx, txtX, x2px(drawX)-4, axisxpx+6+textSize)
drawVisibleText(ctx, '-'+txtX, x2px(-drawX)-4, axisxpx+6+textSize)
}
} }
} }
for(var y = 0; y < drawMaxY; y += 1) { if(showygrad) {
var drawY = y*yaxisstep1 for(var y = 0; y < drawMaxY; y += 1) {
var txtY = yaxisstepExpr.simplify(y) var drawY = y*yaxisstep1
var textSize = ctx.measureText(txtY).width var txtY = yaxisstepExpr.simplify(y)
drawVisibleText(ctx, txtY, axisypx-6-textSize, y2px(drawY)+4+(10*(y==0))) var textSize = ctx.measureText(txtY).width
if(y != 0) drawVisibleText(ctx, txtY, axisypx-6-textSize, y2px(drawY)+4+(10*(y==0)))
drawVisibleText(ctx, '-'+txtY, axisypx-6-textSize-txtMinus, y2px(-drawY)+4) if(y != 0)
drawVisibleText(ctx, '-'+txtY, axisypx-6-textSize-txtMinus, y2px(-drawY)+4)
}
} }
ctx.fillStyle = "#FFFFFF" ctx.fillStyle = "#FFFFFF"
} }

View file

@ -40,6 +40,8 @@ Column {
property string yaxislabel: "" property string yaxislabel: ""
property bool logscalex: true property bool logscalex: true
property string saveFilename: "" property string saveFilename: ""
property bool showxgrad: true
property bool showygrad: true
FileDialog { FileDialog {
id: fdiag id: fdiag
@ -199,6 +201,26 @@ Column {
} }
} }
CheckBox {
id: showXGrad
checked: settings.showxgrad
text: 'Show X graduation'
onClicked: {
settings.showxgrad = checked
settings.changed()
}
}
CheckBox {
id: showYGrad
checked: settings.showygrad
text: 'Show Y graduation'
onClicked: {
settings.showygrad = checked
settings.changed()
}
}
Button { Button {
id: copyToClipboard id: copyToClipboard
height: 30 height: 30