From b519e3401617650ce5889ff074c0dec23108a75e Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Wed, 19 Oct 2022 01:49:30 +0200 Subject: [PATCH] Fixed bugs. 1. X Cursors pointing to an object when LaTeX is enabled make LogarithmPlotter crash due to invalid LaTeX. 2. Invalid class-property types are now directly generated from the static instance. 3. Sequences didn't include sequence value properly anymore. --- .../eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml | 2 -- .../qml/eu/ad5001/LogarithmPlotter/js/math/sequence.js | 3 ++- .../qml/eu/ad5001/LogarithmPlotter/js/objs/common.js | 2 +- .../qml/eu/ad5001/LogarithmPlotter/js/objs/function.js | 1 - .../qml/eu/ad5001/LogarithmPlotter/js/objs/gainbode.js | 1 - .../qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.js | 1 - .../qml/eu/ad5001/LogarithmPlotter/js/objs/point.js | 1 - .../qml/eu/ad5001/LogarithmPlotter/js/objs/text.js | 1 - .../qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js | 4 ++-- 9 files changed, 5 insertions(+), 11 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml index 11a191a..45c5e0a 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml @@ -252,7 +252,6 @@ Item { let tokenizer = new Parsing.Tokenizer(new Parsing.Input(text), true, false) let parsedText = "" let token - console.log("Parsing text:", parsedText) while((token = tokenizer.next()) != null) { switch(token.type) { case Parsing.TokenType.VARIABLE: @@ -280,7 +279,6 @@ Item { break; } } - console.log("Parsed text:", parsedText) return parsedText } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/sequence.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/sequence.js index ddfe4e0..0c43b30 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/sequence.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/sequence.js @@ -66,9 +66,10 @@ class Sequence extends Expr.Expression { var str = Utils.simplifyExpression(this.calc.substitute('n', n-this.valuePlus).toString()) var expr = C.parser.parse(str).simplify() C.currentVars = Object.assign( - {'n': n-this.valuePlus, [this.name]: this.calcValues}, // Just in case, add n (for custom functions) + {'n': n-this.valuePlus}, // Just in case, add n (for custom functions) C.currentObjectsByName ) + C.currentVars[this.name] = this.calcValues this.calcValues[n] = expr.evaluate(C.currentVars) } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js index b966d55..6c15ce5 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js @@ -112,7 +112,7 @@ class DrawableObject { */ constructor(name, visible = true, color = null, labelContent = 'name + value') { if(color == null) color = Utils.getRandomColor() - this.type = 'Unknown' + this.type = this.constructor.type() this.name = name this.visible = visible this.color = color diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.js index 44dc1f4..746d880 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.js @@ -54,7 +54,6 @@ class Function extends Common.ExecutableObject { drawPoints = true, drawDashedLines = true) { if(name == null) name = Common.getNewName('fghjqlmnopqrstuvwabcde') super(name, visible, color, labelContent) - this.type = 'Function' if(typeof expression == 'number' || typeof expression == 'string') expression = new MathLib.Expression(expression.toString()) this.expression = expression if(typeof definitionDomain == 'string') definitionDomain = MathLib.parseDomain(definitionDomain) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/gainbode.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/gainbode.js index 265c9e9..72d583f 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/gainbode.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/gainbode.js @@ -46,7 +46,6 @@ class GainBode extends Common.ExecutableObject { if(name == null) name = Common.getNewName('G') if(name == 'G') name = 'G₀' // G is reserved for sum of BODE magnitudes (Somme gains Bode). super(name, visible, color, labelContent) - this.type = 'Gain Bode' if(typeof om_0 == "string") { // Point name or create one om_0 = Objects.currentObjectsByName[om_0] diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.js index 5cbd4a9..f8d2aaf 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/phasebode.js @@ -43,7 +43,6 @@ class PhaseBode extends Common.ExecutableObject { if(name == null) name = Common.getNewName('φ') if(name == 'φ') name = 'φ₀' // φ is reserved for sum of BODE phases (Somme phases Bode). super(name, visible, color, labelContent) - this.type = 'Phase Bode' if(typeof phase == 'number' || typeof phase == 'string') phase = new MathLib.Expression(phase.toString()) this.phase = phase if(typeof om_0 == "string") { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/point.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/point.js index 66ba301..1f35192 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/point.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/point.js @@ -40,7 +40,6 @@ class Point extends Common.DrawableObject { x = 1, y = 0, labelPosition = 'above', pointStyle = '●') { if(name == null) name = Common.getNewName('ABCDEFJKLMNOPQRSTUVW') super(name, visible, color, labelContent) - this.type = 'Point' if(typeof x == 'number' || typeof x == 'string') x = new MathLib.Expression(x.toString()) this.x = x if(typeof y == 'number' || typeof y == 'string') y = new MathLib.Expression(y.toString()) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.js index a8dcd4e..5d98e4e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.js @@ -45,7 +45,6 @@ class Text extends Common.DrawableObject { x = 1, y = 0, labelPosition = 'center', text = 'New text', disableLatex = false) { if(name == null) name = Common.getNewName('t') super(name, visible, color, labelContent) - this.type = 'Text' if(typeof x == 'number' || typeof x == 'string') x = new MathLib.Expression(x.toString()) this.x = x if(typeof y == 'number' || typeof y == 'string') y = new MathLib.Expression(y.toString()) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js index 0199b6a..4d6eb60 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js @@ -49,7 +49,6 @@ class XCursor extends Common.DrawableObject { rounding = 3, displayStyle = '— — — — — — —', targetValuePosition = 'Next to target') { if(name == null) name = Common.getNewName('X') super(name, visible, color, labelContent) - this.type = 'X Cursor' this.approximate = approximate this.rounding = rounding if(typeof x == 'number' || typeof x == 'string') x = new MathLib.Expression(x.toString()) @@ -78,7 +77,8 @@ class XCursor extends Common.DrawableObject { if(this.targetElement == null) return `${Latex.variable(this.name)} = ${this.x.latexMarkup}` return `\\begin{array}{l} ${Latex.variable(this.name)} = ${this.x.latexMarkup} \\\\ - ${this.getTargetValueLatexLabel()}` + ${this.getTargetValueLatexLabel()} + \\end{array}` } getTargetValueLabel() {