Moving last methods from LogGraphCanvas to Canvas JS module.

This commit is contained in:
Adsooi 2024-09-17 02:14:47 +02:00
parent a2fa16949a
commit d4e97f2860
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
3 changed files with 15 additions and 49 deletions

View file

@ -168,45 +168,4 @@ Canvas {
}
})
}
/*!
\qmlmethod double LogGraphCanvas::x2px(double x)
Converts an \c x coordinate to it's relative position on the canvas.
It supports both logarithmic and non logarithmic scale depending on the currently selected mode.
*/
function x2px(x) {
if(logscalex) {
var logxmin = Math.log(xmin)
return (Math.log(x)-logxmin)*xzoom
} else return (x - xmin)*xzoom
}
/*!
\qmlmethod double LogGraphCanvas::y2px(double y)
Converts an \c y coordinate to it's relative position on the canvas.
The y axis not supporting logarithmic scale, it only support linear convertion.
*/
function y2px(y) {
return (ymax-y)*yzoom
}
/*!
\qmlmethod double LogGraphCanvas::px2x(double px)
Converts an x \c px position on the canvas to it's corresponding coordinate on the plot.
It supports both logarithmic and non logarithmic scale depending on the currently selected mode.
*/
function px2x(px) {
if(logscalex) {
return Math.exp(px/xzoom+Math.log(xmin))
} else return (px/xzoom+xmin)
}
/*!
\qmlmethod double LogGraphCanvas::px2x(double px)
Converts an x \c px position on the canvas to it's corresponding coordinate on the plot.
It supports both logarithmic and non logarithmic scale depending on the currently selected mode.
*/
function px2y(px) {
return -(px/yzoom-ymax)
}
}

View file

@ -227,10 +227,10 @@ ScrollView {
label: qsTr("Max X")
icon: "settings/xmax.svg"
width: settings.settingWidth
defValue: canvas.px2x(canvas.width).toFixed(2)
defValue: Modules.Canvas.px2x(canvas.width).toFixed(2)
onChanged: function(xvaluemax) {
if(xvaluemax > settings.xmin) {
settings.xzoom = settings.xzoom * canvas.width/(canvas.x2px(xvaluemax)) // Adjusting zoom to fit. = (end)/(px of current point)
settings.xzoom = settings.xzoom * canvas.width/(Modules.Canvas.x2px(xvaluemax)) // Adjusting zoom to fit. = (end)/(px of current point)
settings.changed()
} else {
alert.show("Maximum x value must be superior to minimum.")
@ -246,10 +246,10 @@ ScrollView {
label: qsTr("Min Y")
icon: "settings/ymin.svg"
width: settings.settingWidth
defValue: canvas.px2y(canvas.height).toFixed(2)
defValue: Modules.Canvas.px2y(canvas.height).toFixed(2)
onChanged: function(yvaluemin) {
if(yvaluemin < settings.ymax) {
settings.yzoom = settings.yzoom * canvas.height/(canvas.y2px(yvaluemin)) // Adjusting zoom to fit. = (end)/(px of current point)
settings.yzoom = settings.yzoom * canvas.height/(Modules.Canvas.y2px(yvaluemin)) // Adjusting zoom to fit. = (end)/(px of current point)
settings.changed()
} else {
alert.show("Minimum y value must be inferior to maximum.")

View file

@ -388,7 +388,11 @@ class CanvasAPI extends Module {
* @returns {number}
*/
x2px(x) {
return this._canvas.x2px(x)
if(this.logscalex) {
const logxmin = Math.log(this.xmin)
return (Math.log(x)-logxmin)*this.xzoom
} else
return (x - this.xmin)*this.xzoom
}
/**
@ -398,7 +402,7 @@ class CanvasAPI extends Module {
* @returns {number}
*/
y2px(y) {
return this._canvas.y2px(y)
return (this.ymax - y) * this.yzoom
}
/**
@ -408,7 +412,10 @@ class CanvasAPI extends Module {
* @returns {number}
*/
px2x(px) {
return this._canvas.px2x(px)
if(this.logscalex) {
return Math.exp(px/this.xzoom+Math.log(this.xmin))
} else
return (px/this.xzoom+this.xmin)
}
/**
@ -418,7 +425,7 @@ class CanvasAPI extends Module {
* @returns {number}
*/
px2y(px) {
return this._canvas.px2y(px)
return -(px/this.yzoom-this.ymax)
}
/**