Labels for bode gains, fixing bugs
This commit is contained in:
parent
37c9772e94
commit
8673c89c15
5 changed files with 61 additions and 37 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -15,6 +15,7 @@ build
|
|||
docs/html
|
||||
.directory
|
||||
loggraph.kdev4
|
||||
*.json
|
||||
.kdev4
|
||||
AccountFree.pro
|
||||
AccountFree.pro.user
|
||||
|
|
|
@ -72,6 +72,8 @@ ApplicationWindow {
|
|||
currentIndex: sidebarSelector.currentIndex
|
||||
anchors.top: sidebarSelector.bottom
|
||||
height: parent.height - sidebarSelector.height
|
||||
z: -1
|
||||
clip: true
|
||||
|
||||
Settings {
|
||||
id: settings
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick 2.12
|
||||
import "js/utils.js" as Utils
|
||||
|
||||
Grid {
|
||||
id: settings
|
||||
|
@ -133,7 +134,7 @@ Grid {
|
|||
width: settings.settingWidth
|
||||
defValue: settings.xaxislabel
|
||||
onChanged: function(newValue) {
|
||||
settings.xaxislabel = newValue
|
||||
settings.xaxislabel = Utils.parseName(newValue, false)
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +146,7 @@ Grid {
|
|||
width: settings.settingWidth
|
||||
defValue: settings.yaxislabel
|
||||
onChanged: function(newValue) {
|
||||
settings.yaxislabel = newValue
|
||||
settings.yaxislabel = Utils.parseName(newValue, false)
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,10 +46,10 @@ class DrawableObject {
|
|||
}
|
||||
|
||||
getRandomColor() {
|
||||
var x = '0123456789ABCDEF';
|
||||
var x = '0123456789'; // Removing ABCDEF for less flashy colors.
|
||||
var color = '#';
|
||||
for (var i = 0; i < 6; i++) {
|
||||
color += x[Math.floor(Math.random() * 16)];
|
||||
color += x[Math.floor(Math.random() * 10)];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ class GainBode extends DrawableObject {
|
|||
}
|
||||
|
||||
getReadableString() {
|
||||
return `${this.name}: ${this.pass}-pass, ω₀=${this.ω_0.x}, ${this.gain.toString(true)} dB/dec.`
|
||||
return `${this.name}: ${this.pass}-pass; ω₀ = ${this.ω_0.x}\n ${' '.repeat(this.name.length)}${this.gain.toString(true)} dB/dec.`
|
||||
}
|
||||
|
||||
export() {
|
||||
|
@ -282,6 +282,26 @@ class GainBode extends DrawableObject {
|
|||
inDrawDom = MathLib.parseDomain(`]${this.ω_0.x};+inf[`)
|
||||
}
|
||||
Function.drawFunction(canvas, ctx, dbfn, inDrawDom, MathLib.Domain.R)
|
||||
|
||||
// Label
|
||||
var text = this.getLabel()
|
||||
ctx.font = "14px sans-serif"
|
||||
var textSize = canvas.measureText(ctx, text)
|
||||
var posX = canvas.x2px(this.labelX)
|
||||
var posY
|
||||
if((this.pass == 'high' && this.labelX < this.ω_0.x) || (this.pass == 'low' && this.labelX > this.ω_0.x)) {
|
||||
posY = canvas.y2px(dbfn.evaluate(this.labelX))
|
||||
} else {
|
||||
posY = base[1]
|
||||
}
|
||||
switch(this.labelPos) {
|
||||
case 'above':
|
||||
canvas.drawVisibleText(ctx, text, posX-textSize.width/2, posY-textSize.height)
|
||||
break;
|
||||
case 'below':
|
||||
canvas.drawVisibleText(ctx, text, posX-textSize.width/2, posY+textSize.height)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,39 +147,39 @@ function makeExpressionReadable(str) {
|
|||
function parseName(str, removeUnallowed = true) {
|
||||
var replacements = [
|
||||
// Greek letters
|
||||
[/(\s|^)al(pha)?[^a-z]/g, 'α'],
|
||||
[/(\s|^)be(ta)?[^a-z]/g, 'β'],
|
||||
[/(\s|^)ga(mma)?[^a-z]/g, 'γ'],
|
||||
[/(\s|^)de(lta)?[^a-z]/g, 'δ'],
|
||||
[/(\s|^)ep(silon)?[^a-z]/g, 'ε'],
|
||||
[/(\s|^)ze(ta)?[^a-z]/g, 'ζ'],
|
||||
[/(\s|^)et(a)?[^a-z]/g, 'η'],
|
||||
[/(\s|^)th(eta)?[^a-z]/g, 'θ'],
|
||||
[/(\s|^)io(ta)?[^a-z]/g, 'ι'],
|
||||
[/(\s|^)ka(ppa)[^a-z]?/g, 'κ'],
|
||||
[/(\s|^)la(mbda)?[^a-z]/g, 'λ'],
|
||||
[/(\s|^)mu[^a-z]/g, 'μ'],
|
||||
[/(\s|^)nu[^a-z]/g, 'ν'],
|
||||
[/(\s|^)xi[^a-z]/g, 'ξ'],
|
||||
[/(\s|^)rh(o)?[^a-z]/g, 'ρ'],
|
||||
[/(\s|^)si(gma)?[^a-z]/g, 'σ'],
|
||||
[/(\s|^)ta(u)?[^a-z]/g, 'τ'],
|
||||
[/(\s|^)up(silon)?[^a-z]/g, 'υ'],
|
||||
[/(\s|^)ph(i)?[^a-z]/g, 'φ'],
|
||||
[/(\s|^)ch(i)?[^a-z]/g, 'χ'],
|
||||
[/(\s|^)ps(i)?[^a-z]/g, 'ψ'],
|
||||
[/(\s|^)om(ega)?[^a-z]/g, 'ω'],
|
||||
[/([^a-z]|^)al(pha)?([^a-z]|$)/g, '$1α$3'],
|
||||
[/([^a-z]|^)be(ta)?([^a-z]|$)/g, '$1β$3'],
|
||||
[/([^a-z]|^)ga(mma)?([^a-z]|$)/g, '$1γ$3'],
|
||||
[/([^a-z]|^)de(lta)?([^a-z]|$)/g, '$1δ$3'],
|
||||
[/([^a-z]|^)ep(silon)?([^a-z]|$)/g, '$1ε$3'],
|
||||
[/([^a-z]|^)ze(ta)?([^a-z]|$)/g, '$1ζ$3'],
|
||||
[/([^a-z]|^)et(a)?([^a-z]|$)/g, '$1η$3'],
|
||||
[/([^a-z]|^)th(eta)?([^a-z]|$)/g, '$1θ$3'],
|
||||
[/([^a-z]|^)io(ta)?([^a-z]|$)/g, '$1ι$3'],
|
||||
[/([^a-z]|^)ka(ppa)([^a-z]|$)?/g, '$1κ$3'],
|
||||
[/([^a-z]|^)la(mbda)?([^a-z]|$)/g, '$1λ$3'],
|
||||
[/([^a-z]|^)mu([^a-z]|$)/g, '$1μ$2'],
|
||||
[/([^a-z]|^)nu([^a-z]|$)/g, '$1ν$2'],
|
||||
[/([^a-z]|^)xi([^a-z]|$)/g, '$1ξ$2'],
|
||||
[/([^a-z]|^)rh(o)?([^a-z]|$)/g, '$1ρ$3'],
|
||||
[/([^a-z]|^)si(gma)?([^a-z]|$)/g, '$1σ$3'],
|
||||
[/([^a-z]|^)ta(u)?([^a-z]|$)/g, '$1τ$3'],
|
||||
[/([^a-z]|^)up(silon)?([^a-z]|$)/g, '$1υ$3'],
|
||||
[/([^a-z]|^)ph(i)?([^a-z]|$)/g, '$1φ$3'],
|
||||
[/([^a-z]|^)ch(i)?([^a-z]|$)/g, '$1χ$3'],
|
||||
[/([^a-z]|^)ps(i)?([^a-z]|$)/g, '$1ψ$3'],
|
||||
[/([^a-z]|^)om(ega)?([^a-z]|$)/g, '$1ω$3'],
|
||||
// Capital greek letters
|
||||
[/(\s|^)gga(mma)?[^a-z]/g, 'Γ'],
|
||||
[/(\s|^)gde(lta)?[^a-z]/g, 'Δ'],
|
||||
[/(\s|^)gth(eta)?[^a-z]/g, 'Θ'],
|
||||
[/(\s|^)gla(mbda)?[^a-z]/g, 'Λ'],
|
||||
[/(\s|^)gxi[^a-z]/g, 'Ξ'],
|
||||
[/(\s|^)gpi[^a-z]/g, 'Π'],
|
||||
[/(\s|^)gsi(gma)[^a-z]?/g, 'Σ'],
|
||||
[/(\s|^)gph(i)?[^a-z]/g, 'Φ'],
|
||||
[/(\s|^)gps(i)?[^a-z]/g, 'Ψ'],
|
||||
[/(\s|^)gom(ega)?[^a-z]/g, 'Ω'],
|
||||
[/([^a-z]|^)gga(mma)?([^a-z]|$)/g, '$1Γ$3'],
|
||||
[/([^a-z]|^)gde(lta)?([^a-z]|$)/g, '$1Δ$3'],
|
||||
[/([^a-z]|^)gth(eta)?([^a-z]|$)/g, '$1Θ$3'],
|
||||
[/([^a-z]|^)gla(mbda)?([^a-z]|$)/g, '$1Λ$3'],
|
||||
[/([^a-z]|^)gxi([^a-z]|$)/g, '$1Ξ$2'],
|
||||
[/([^a-z]|^)gpi([^a-z]|$)/g, '$1Π$2'],
|
||||
[/([^a-z]|^)gsi(gma)([^a-z]|$)?/g, '$1Σ$3'],
|
||||
[/([^a-z]|^)gph(i)?([^a-z]|$)/g, '$1Φ$3'],
|
||||
[/([^a-z]|^)gps(i)?([^a-z]|$)/g, '$1Ψ$3'],
|
||||
[/([^a-z]|^)gom(ega)?([^a-z]|$)/g, '$1Ω$3'],
|
||||
// Underscores
|
||||
[/_\(([^\^]+)\)/g, function(match, p1) { return textsub(p1) }],
|
||||
[/_([^ ]+)/g, function(match, p1) { return textsub(p1) }],
|
||||
|
|
Loading…
Reference in a new issue