Compare commits

..

3 commits

Author SHA1 Message Date
c32d70e9ed
Reformatting JS files
All checks were successful
continuous-integration/drone/push Build is passing
2024-09-27 02:54:20 +02:00
8cefc56ac7
Adding JS polyfills to avoid issues because core-js does not deal well with the environment it's given. 2024-09-27 02:34:42 +02:00
850d076268
Using more modern ECMAScript 2024-09-26 23:16:58 +02:00
49 changed files with 1583 additions and 1435 deletions

View file

@ -538,7 +538,7 @@ Item {
try {
expr = new JS.MathLib.Expression(value.toString())
// Check if the expression is valid, throws error otherwise.
if(!expr.allRequirementsFullfilled()) {
if(!expr.allRequirementsFulfilled()) {
let undefVars = expr.undefinedVariables()
if(undefVars.length > 1)
throw new Error(qsTranslate('error', 'No object found with names %1.').arg(undefVars.join(', ')))

View file

@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import js from "./lib/polyfills/js.mjs"
// Loading modules in order
import * as Objects from "./module/objects.mjs"
import * as ExprParser from "./module/expreval.mjs"

View file

@ -21,10 +21,13 @@ import Objects from "../module/objects.mjs"
export default class ColorChanged extends EditedProperty {
// Action used everytime when an object's color is changed
type(){return 'ColorChanged'}
icon(){return 'appearance'}
type() {
return "ColorChanged"
}
icon() {
return "appearance"
}
constructor(targetName = "", targetType = "Point", oldColor = "black", newColor = "white") {
super(targetName, targetType, "color", oldColor, newColor)
@ -34,7 +37,9 @@ export default class ColorChanged extends EditedProperty {
return [this.targetName, this.targetType, this.previousValue, this.newValue]
}
color(darkVer=false){return darkVer ? 'purple' : 'plum'}
color(darkVer = false) {
return darkVer ? "purple" : "plum"
}
getReadableString() {
return qsTranslate("color", "%1 %2's color changed from %3 to %4.")
@ -49,7 +54,7 @@ export default class ColorChanged extends EditedProperty {
getHTMLString() {
return qsTranslate("color", "%1 %2's color changed from %3 to %4.")
.arg(Objects.types[this.targetType].displayType())
.arg('<b style="font-size: 15px;">&nbsp;' + this.targetName + "&nbsp;</b>")
.arg("<b style=\"font-size: 15px;\">&nbsp;" + this.targetName + "&nbsp;</b>")
.arg(this.formatColor(this.previousValue)).arg(this.formatColor(this.newValue))
}
}

View file

@ -25,14 +25,18 @@ export class Action {
*
* @returns {string}
*/
type(){return 'Unknown'}
type() {
return "Unknown"
}
/**
* Icon associated with the action.
*
* @returns {string}
*/
icon(){return 'position'}
icon() {
return "position"
}
// TargetName is the name of the object that's targeted by the event.
constructor(targetName = "", targetType = "Point") {
@ -43,12 +47,14 @@ export class Action {
/**
* Undoes the action.
*/
undo() {}
undo() {
}
/**
* Redoes the action.
*/
redo() {}
redo() {
}
/**
* Export the action to a serializable format.
@ -61,12 +67,12 @@ export class Action {
}
/**
* Returns a string with the human readable description of the action.
* Returns a string with the human-readable description of the action.
*
* @returns {string}
*/
getReadableString() {
return 'Unknown action'
return "Unknown action"
}
/**
@ -76,7 +82,7 @@ export class Action {
* @returns {string}
*/
getIconRichText(type) {
return `<img source="../icons/objects/${type}.svg" style="color: ${History.themeTextColor};" width=18 height=18></img>`
return `<img src="../icons/objects/${type}.svg" style="color: ${History.themeTextColor};" width=18 height=18></img>`
}
/**
@ -85,20 +91,16 @@ export class Action {
* @param {string} latexString - Source string of the latex.
* @returns {Promise<string>}
*/
renderLatexAsHtml(latexString) {
async renderLatexAsHtml(latexString) {
if(!Latex.enabled)
throw new Error("Cannot render an item as LaTeX when LaTeX is disabled.")
return new Promise(resolve => {
let imgDepth = History.imageDepth
Latex.requestAsyncRender(
const imgDepth = History.imageDepth
const { source, width, height } = await Latex.requestAsyncRender(
latexString,
imgDepth * (History.fontSize + 2),
History.themeTextColor
).then((imgData) => {
const { source, width, height } = imgData
resolve(`<img src="${source}" width="${width/imgDepth}" height="${height/imgDepth}" style="vertical-align: middle"/>`)
})
})
)
return `<img src="${source}" width="${width / imgDepth}" height="${height / imgDepth}" style="vertical-align: middle"/>`
}
/**

View file

@ -19,13 +19,21 @@
import Objects from "../module/objects.mjs"
import { Action } from "./common.mjs"
/**
* Action used for the creation of an object.
*/
export default class CreateNewObject extends Action {
// Action used for the creation of an object
type(){return 'CreateNewObject'}
type() {
return "CreateNewObject"
}
icon(){return 'create'}
icon() {
return "create"
}
color(darkVer=false){return darkVer ? 'green' : 'lime'}
color(darkVer = false) {
return darkVer ? "green" : "lime"
}
constructor(targetName = "", targetType = "Point", properties = []) {
super(targetName, targetType)
@ -55,7 +63,7 @@ export default class CreateNewObject extends Action {
getHTMLString() {
return qsTranslate("create", "New %1 %2 created.")
.arg(Objects.types[this.targetType].displayType())
.arg('<b style="font-size: 15px;">' + this.targetName + "</b>")
.arg("<b style=\"font-size: 15px;\">" + this.targetName + "</b>")
}
}

View file

@ -20,10 +20,10 @@ import Objects from "../module/objects.mjs"
import CreateNewObject from "./create.mjs"
export default class DeleteObject extends CreateNewObject {
/**
* Action used at the deletion of an object. Basically the same thing as creating a new object, except Redo & Undo are reversed.
*/
export default class DeleteObject extends CreateNewObject {
type(){return 'DeleteObject'}
icon(){return 'delete'}

View file

@ -22,14 +22,20 @@ import * as MathLib from "../math/index.mjs"
import { Action } from "./common.mjs"
import { DrawableObject } from "../objs/common.mjs"
/**
* Action used everytime an object's property has been changed.
*/
export default class EditedProperty extends Action {
// Action used everytime an object's property has been changed
type(){return 'EditedProperty'}
type() {
return "EditedProperty"
}
icon(){return 'modify'}
icon() {
return "modify"
}
color(darkVer = false) {
return darkVer ? 'darkslateblue' : 'cyan';
return darkVer ? "darkslateblue" : "cyan"
}
/**
@ -49,12 +55,12 @@ export default class EditedProperty extends Action {
this.newValue = newValue
this.propertyType = Objects.types[targetType].properties()[targetProperty]
if(valueIsExpressionNeedingImport) {
if(typeof this.propertyType == 'object' && this.propertyType.type === "Expression") {
this.previousValue = new MathLib.Expression(this.previousValue);
this.newValue = new MathLib.Expression(this.newValue);
if(typeof this.propertyType == "object" && this.propertyType.type === "Expression") {
this.previousValue = new MathLib.Expression(this.previousValue)
this.newValue = new MathLib.Expression(this.newValue)
} else if(this.propertyType === "Domain") {
this.previousValue = MathLib.parseDomain(this.previousValue);
this.newValue = MathLib.parseDomain(this.newValue);
this.previousValue = MathLib.parseDomain(this.previousValue)
this.newValue = MathLib.parseDomain(this.newValue)
} else {
// Objects
this.previousValue = Objects.currentObjectsByName[this.previousValue] // Objects.getObjectByName(this.previousValue);
@ -93,42 +99,42 @@ export default class EditedProperty extends Action {
case "Enum":
this.prevString = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.previousValue)]
this.nextString = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.newValue)]
break;
break
case "ObjectType":
this.prevString = this.previousValue == null ? "null" : this.previousValue.name
this.nextString = this.newValue == null ? "null" : this.newValue.name
break;
break
case "List":
this.prevString = this.previousValue.join(",")
this.nextString = this.newValue.name.join(",")
break;
break
case "Dict":
this.prevString = JSON.stringify(this.previousValue)
this.nextString = JSON.stringify(this.newValue)
break;
break
case "Expression":
this.prevString = this.previousValue == null ? "null" : this.previousValue.toString()
this.nextString = this.newValue == null ? "null" : this.newValue.toString()
break;
break
}
} else {
this.prevString = this.previousValue == null ? "null" : this.previousValue.toString()
this.nextString = this.newValue == null ? "null" : this.newValue.toString()
}
// HTML
this.prevHTML = '<tt style="background: rgba(128,128,128,0.1);">&nbsp;'+this.prevString+'&nbsp;</tt>'
this.nextHTML = '<tt style="background: rgba(128,128,128,0.1);">&nbsp;'+this.nextString+'&nbsp;</tt>'
if(Latex.enabled && typeof this.propertyType == 'object' && this.propertyType.type === "Expression") {
this.prevHTML = "<tt style=\"background: rgba(128,128,128,0.1);\">&nbsp;" + this.prevString + "&nbsp;</tt>"
this.nextHTML = "<tt style=\"background: rgba(128,128,128,0.1);\">&nbsp;" + this.nextString + "&nbsp;</tt>"
if(Latex.enabled && typeof this.propertyType == "object" && this.propertyType.type === "Expression") {
// Store promises so that querying can wait for them to finish.
this._renderPromises = [
this.renderLatexAsHtml(this.previousValue.latexMarkup).then(prev => this.prevHTML = prev),
this.renderLatexAsHtml(this.newValue.latexMarkup).then(next => this.nextHTML = prev)
this.renderLatexAsHtml(this.newValue.latexMarkup).then(next => this.nextHTML = next)
]
}
}
getReadableString() {
return qsTranslate("editproperty", '%1 of %2 %3 changed from "%4" to "%5".')
return qsTranslate("editproperty", "%1 of %2 %3 changed from \"%4\" to \"%5\".")
.arg(this.targetPropertyReadable)
.arg(Objects.types[this.targetType].displayType())
.arg(this.targetName).arg(this.prevString).arg(this.nextString)
@ -138,22 +144,16 @@ export default class EditedProperty extends Action {
*
* @return {Promise<string>|string}
*/
getHTMLString() {
return new Promise(resolve => {
const translation = qsTranslate("editproperty", '%1 of %2 changed from %3 to %4.')
async getHTMLString() {
const translation = qsTranslate("editproperty", "%1 of %2 changed from %3 to %4.")
.arg(this.targetPropertyReadable)
.arg('<b style="font-size: 15px;">&nbsp;' + this.targetName + '&nbsp;</b>')
.arg("<b style=\"font-size: 15px;\">&nbsp;" + this.targetName + "&nbsp;</b>")
// Check if we need to wait for LaTeX HTML to be rendered.
if(this.prevHTML !== undefined && this.nextHTML !== undefined)
resolve(translation.arg(this.prevHTML).arg(this.nextHTML))
else
Promise.all(this._renderPromises).then((rendered) => {
// Rendered are (potentially) two HTML strings which are defined during rendering
this.prevHTML = this.prevHTML ?? rendered[0]
this.nextHTML = this.prevHTML ?? rendered[1]
resolve(translation.arg(this.prevHTML).arg(this.nextHTML))
})
})
if(this.prevHTML === undefined || this.nextHTML === undefined) {
const [prevHTML, nextHTML] = await Promise.all(this._renderPromises)
this.prevHTML = this.prevHTML ?? prevHTML
this.nextHTML = this.nextHTML ?? nextHTML
}
return translation.arg(this.prevHTML).arg(this.nextHTML)
}
}

View file

@ -19,9 +19,10 @@
import EditedProperty from "./editproperty.mjs"
import Objects from "../module/objects.mjs"
/**
* Action used everytime an object's name has been changed.
*/
export default class NameChanged extends EditedProperty {
// Action used everytime an object's property has been changed
type(){return 'NameChanged'}
icon(){return 'name'}

View file

@ -21,28 +21,33 @@ import Latex from "../module/latex.mjs"
import * as MathLib from "../math/index.mjs"
import { escapeHTML } from "../utils.mjs"
import { Action } from "./common.mjs"
import { DrawableObject } from "../objs/common.mjs"
/**
* Action used for objects that have a X and Y expression properties (points, texts...)
*/
export default class EditedPosition extends Action {
// Action used for objects that have a X and Y expression properties (points, texts...)
type(){return 'EditedPosition'}
type() {
return "EditedPosition"
}
icon(){return 'position'}
icon() {
return "position"
}
color(darkVer = false) {
return darkVer ? 'seagreen' : 'lightseagreen';
return darkVer ? "seagreen" : "lightseagreen"
}
constructor(targetName = "", targetType = "Point", previousXValue = "", newXValue = "", previousYValue = "", newYValue = "") {
super(targetName, targetType)
let imports = {
'previousXValue': previousXValue,
'previousYValue': previousYValue,
'newXValue': newXValue,
'newYValue': newYValue
"previousXValue": previousXValue,
"previousYValue": previousYValue,
"newXValue": newXValue,
"newYValue": newYValue
}
for(let name in imports)
this[name] = (typeof imports[name]) == 'string' ? new MathLib.Expression(imports[name]) : imports[name]
this[name] = (typeof imports[name]) == "string" ? new MathLib.Expression(imports[name]) : imports[name]
this.setReadableValues()
}
@ -71,8 +76,8 @@ export default class EditedPosition extends Action {
this.renderLatexAsHtml(nextMarkup)
]
} else {
this.prevHTML = '<tt style="background: rgba(128,128,128,0.1);">&nbsp;'+escapeHTML(this.prevString)+'&nbsp;</tt>'
this.nextHTML = '<tt style="background: rgba(128,128,128,0.1);">&nbsp;'+escapeHTML(this.nextString)+'&nbsp;</tt>'
this.prevHTML = "<tt style=\"background: rgba(128,128,128,0.1);\">&nbsp;" + escapeHTML(this.prevString) + "&nbsp;</tt>"
this.nextHTML = "<tt style=\"background: rgba(128,128,128,0.1);\">&nbsp;" + escapeHTML(this.nextString) + "&nbsp;</tt>"
}
}
@ -84,26 +89,21 @@ export default class EditedPosition extends Action {
}
getReadableString() {
return qsTranslate("position", 'Position of %1 %2 set from "%3" to "%4".')
return qsTranslate("position", "Position of %1 %2 set from \"%3\" to \"%4\".")
.arg(Objects.types[this.targetType].displayType())
.arg(this.targetName).arg(this.prevString).arg(this.nextString)
}
getHTMLString() {
return new Promise(resolve => {
const translation = qsTranslate("position", 'Position of %1 set from %2 to %3.')
.arg('<b style="font-size: 15px;">&nbsp;' + this.targetName + '&nbsp;</b>')
async getHTMLString() {
const translation = qsTranslate("position", "Position of %1 set from %2 to %3.")
.arg("<b style=\"font-size: 15px;\">&nbsp;" + this.targetName + "&nbsp;</b>")
// Check if we need to wait for LaTeX HTML to be rendered.
if(this.prevHTML !== undefined && this.nextHTML !== undefined)
resolve(translation.arg(this.prevHTML).arg(this.nextHTML))
else
Promise.all(this._renderPromises).then((rendered) => {
// Rendered are (potentially) two HTML strings which are defined during rendering
this.prevHTML = this.prevHTML ?? rendered[0]
this.nextHTML = this.nextHTML ?? rendered[1]
resolve(translation.arg(this.prevHTML).arg(this.nextHTML))
})
})
if(this.prevHTML === undefined || this.nextHTML === undefined) {
const [prevHTML, nextHTML] = await Promise.all(this._renderPromises)
this.prevHTML = this.prevHTML ?? prevHTML
this.nextHTML = this.nextHTML ?? nextHTML
}
return translation.arg(this.prevHTML).arg(this.nextHTML)
}
}

View file

@ -20,16 +20,22 @@ import EditedProperty from "./editproperty.mjs"
import Objects from "../module/objects.mjs"
/**
* Action used when an object's shown or hidden.
*/
export default class EditedVisibility extends EditedProperty {
// Action used when an object's shown or hidden.
type(){return 'EditedVisibility'}
type() {
return "EditedVisibility"
}
icon(){return 'visibility'}
icon() {
return "visibility"
}
color(darkVer = false) {
return this.newValue ?
(darkVer ? 'darkgray' : 'whitesmoke') :
(darkVer ? 'dimgray' : 'lightgray')
(darkVer ? "darkgray" : "whitesmoke") :
(darkVer ? "dimgray" : "lightgray")
}
constructor(targetName = "", targetType = "Point", newValue = true) {
@ -41,15 +47,15 @@ export default class EditedVisibility extends EditedProperty {
}
getReadableString() {
return (this.newValue ? qsTranslate('visibility', '%1 %2 shown.') : qsTranslate('visibility', '%1 %2 hidden.'))
return (this.newValue ? qsTranslate("visibility", "%1 %2 shown.") : qsTranslate("visibility", "%1 %2 hidden."))
.arg(Objects.types[this.targetType].displayType())
.arg(this.targetName)
}
getHTMLString() {
return (this.newValue ? qsTranslate('visibility', '%1 %2 shown.') : qsTranslate('visibility', '%1 %2 hidden.'))
return (this.newValue ? qsTranslate("visibility", "%1 %2 shown.") : qsTranslate("visibility", "%1 %2 hidden."))
.arg(Objects.types[this.targetType].displayType())
.arg('<b style="font-size: 15px;">' + this.targetName + "</b>")
.arg("<b style=\"font-size: 15px;\">" + this.targetName + "</b>")
}
}

View file

@ -482,7 +482,7 @@ export class ExprEvalExpression {
/**
* Calculates the value of the expression by giving all variables and their corresponding values.
* @param {Object<string, number>} values
* @param {Object<string, number|DrawableObject>} values
* @returns {number}
*/
evaluate(values) {
@ -512,8 +512,7 @@ export class ExprEvalExpression {
* as constants or functions.
* @returns {string[]}
*/
variables(options) {
options = options || {}
variables(options = {}) {
const vars = []
getSymbols(this.tokens, vars, options)
const functions = this.functions

View file

@ -0,0 +1,126 @@
/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 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/>.
*/
// JS polyfills to add because they're not implemented in the QML Scripting engine.
// CoreJS does not work well with it (as well as doubles the compiled size), so this is preferable.
function notPolyfilled(name) {
return function() { throw new Error(`${name} not polyfilled`) }
}
/**
* @param {number} depth
* @this {Array}
* @returns {Array}
*/
function arrayFlat(depth = 1) {
const newArray = []
for(const element of this) {
if(element instanceof Array)
newArray.push(...(depth > 1 ? element.flat(depth - 1) : element))
else
newArray.push(element)
}
return newArray
}
/**
* @param {function(any, number, Array): any} callbackFn
* @param {object} thisArg
* @this {Array}
* @returns {Array}
*/
function arrayFlatMap(callbackFn, thisArg) {
const newArray = []
for(let i = 0; i < this.length; i++) {
const value = callbackFn.call(thisArg ?? this, this[i], i, this)
if(value instanceof Array)
newArray.push(...value)
else
newArray.push(value)
}
return newArray
}
/**
* Replaces all instances of from by to.
* @param {string} from
* @param {string} to
* @this {string}
* @return {String}
*/
function stringReplaceAll(from, to) {
let str = this
while(str.includes(from))
str = str.replace(from, to)
return str
}
const polyfills = {
2017: [
[Object, "entries", notPolyfilled("Object.entries")],
[Object, "values", notPolyfilled("Object.values")],
[Object, "getOwnPropertyDescriptors", notPolyfilled("Object.getOwnPropertyDescriptors")],
[String.prototype, "padStart", notPolyfilled("String.prototype.padStart")],
[String.prototype, "padEnd", notPolyfilled("String.prototype.padEnd")]
],
2018: [
[Promise.prototype, "finally", notPolyfilled("Object.entries")]
],
2019: [
[String.prototype, "trimStart", notPolyfilled("String.prototype.trimStart")],
[String.prototype, "trimEnd", notPolyfilled("String.prototype.trimEnd")],
[Object, "fromEntries", notPolyfilled("Object.fromEntries")],
[Array.prototype, "flat", arrayFlat],
[Array.prototype, "flatMap", arrayFlatMap]
],
2020: [
[String.prototype, "matchAll", notPolyfilled("String.prototype.matchAll")],
[Promise, "allSettled", notPolyfilled("Promise.allSettled")]
],
2021: [
[Promise, "any", notPolyfilled("Promise.any")],
[String.prototype, "replaceAll", stringReplaceAll]
],
2022: [
[Array.prototype, "at", notPolyfilled("Array.prototype.at")],
[String.prototype, "at", notPolyfilled("String.prototype.at")],
[Object, "hasOwn", notPolyfilled("Object.hasOwn")]
],
2023: [
[Array.prototype, "findLast", notPolyfilled("Array.prototype.findLast")],
[Array.prototype, "toReversed", notPolyfilled("Array.prototype.toReversed")],
[Array.prototype, "toSorted", notPolyfilled("Array.prototype.toSorted")],
[Array.prototype, "toSpliced", notPolyfilled("Array.prototype.toSpliced")],
[Array.prototype, "with", notPolyfilled("Array.prototype.with")]
],
2024: [
[Object, "groupBy", notPolyfilled("Object.groupBy")],
[Map, "groupBy", notPolyfilled("Map.groupBy")]
]
}
// Fulfill polyfill.
for(const [year, entries] of Object.entries(polyfills)) {
const defined = entries.filter(x => x[0][x[1]] !== undefined)
console.info(`ES${year} support: ${defined.length === entries.length} (${defined.length}/${entries.length})`)
// Apply polyfills
for(const [context, functionName, polyfill] of entries.filter(x => x[0][x[1]] === undefined)) {
context[functionName] = polyfill
}
}

View file

@ -18,6 +18,7 @@
// Type polyfills for IDEs.
// Never directly imported.
// Might need to be reimplemented in other implemententations.
Modules = Modules || {}
/** @type {function(string, string): string} */
@ -25,7 +26,7 @@ qsTranslate = qsTranslate || function(category, string) { throw new Error('qsTra
/** @type {function(string): string} */
qsTr = qsTr || function(string) { throw new Error('qsTr not implemented.'); }
/** @type {function(string, string): string} */
QT_TRANSLATE_NOOP = QT_TRANSLATE_NOOP || function(string, string) { throw new Error('QT_TRANSLATE_NOOP not implemented.'); }
QT_TRANSLATE_NOOP = QT_TRANSLATE_NOOP || function(category, string) { throw new Error('QT_TRANSLATE_NOOP not implemented.'); }
/** @type {function(string): string} */
QT_TR_NOOP = QT_TR_NOOP || function(string) { throw new Error('QT_TR_NOOP not implemented.'); }
/** @type {function(string|boolean|int): string} */

View file

@ -23,34 +23,43 @@ import { Expression, executeExpression } from "./expression.mjs"
* It doesn't represent any kind of domain and is meant to be extended.
*/
export class Domain {
constructor() {}
constructor() {
}
/**
* Checks whether x is included in the domain.
* @param {number} x - The x value.
* @return {boolean} true if included, false otherwise.
*/
includes(x) { return false }
includes(x) {
return false
}
/**
* Returns a string representation of the domain.
* @return {string} String representation of the domain.
*/
toString() { return '???' }
toString() {
return "???"
}
/**
* Returns a new domain that is the union between this domain and another.
* @param {Domain} domain - Domain to unionise with this.
* @return {Domain} newly created domain.
*/
union(domain) { return domain }
union(domain) {
return domain
}
/**
* Returns a new domain that is the intersection between this domain and another.
* @param {Domain} domain - Domain to get the interscection with this.
* @return {Domain} newly created domain.
*/
intersection(domain) { return this }
intersection(domain) {
return this
}
/**
* Imports a domain from a string.
@ -61,24 +70,20 @@ export class Domain {
case "R":
case "":
return Domain.R
break;
case "RE":
case "R*":
case "*":
return Domain.RE
break;
case "RP":
case "R+":
case "ℝ⁺":
case "+":
return Domain.RP
break;
case "RM":
case "R-":
case "ℝ⁻":
case "-":
return Domain.RM
break;
case "RPE":
case "REP":
case "R+*":
@ -88,7 +93,6 @@ export class Domain {
case "*+":
case "+*":
return Domain.RPE
break;
case "RME":
case "REM":
case "R-*":
@ -98,7 +102,6 @@ export class Domain {
case "-*":
case "*-":
return Domain.RME
break;
case "":
case "N":
case "ZP":
@ -106,12 +109,10 @@ export class Domain {
case "ℤ⁺":
case "+":
return Domain.N
break;
case "NLOG":
case "ℕˡᵒᵍ":
case "LOG":
return Domain.NLog
break;
case "NE":
case "NP":
case "N*":
@ -128,17 +129,14 @@ export class Domain {
case "+*":
case "*+":
return Domain.NE
break;
case "Z":
case "":
return Domain.Z
break;
case "ZM":
case "Z-":
case "ℤ⁻":
case "-":
return Domain.ZM
break;
case "ZME":
case "ZEM":
case "Z-*":
@ -148,15 +146,12 @@ export class Domain {
case "-*":
case "*-":
return Domain.ZME
break;
case "ZE":
case "Z*":
case "*":
return Domain.ZE
break;
default:
return Domain.EmptySet
break;
}
}
}
@ -171,15 +166,25 @@ export class EmptySet extends Domain {
this.latexMarkup = "\\emptyset"
}
includes(x) { return false }
includes(x) {
return false
}
toString() { return this.displayName }
toString() {
return this.displayName
}
union(domain) { return domain }
union(domain) {
return domain
}
intersection(domain) { return this }
intersection(domain) {
return this
}
static import(frm) { return new EmptySet() }
static import(frm) {
return new EmptySet()
}
}
Domain.EmptySet = new EmptySet() // To prevent use prior to declaration.
@ -190,9 +195,9 @@ Domain.EmptySet = new EmptySet() // To prevent use prior to declaration.
export class Range extends Domain {
constructor(begin, end, openBegin, openEnd) {
super()
if(typeof begin == 'number' || typeof begin == 'string') begin = new Expression(begin.toString())
if(typeof begin == "number" || typeof begin == "string") begin = new Expression(begin.toString())
this.begin = begin
if(typeof end == 'number' || typeof end == 'string') end = new Expression(end.toString())
if(typeof end == "number" || typeof end == "string") end = new Expression(end.toString())
this.end = end
this.openBegin = openBegin
this.openEnd = openEnd
@ -202,7 +207,7 @@ export class Range extends Domain {
includes(x) {
if(x instanceof Expression) x = x.execute()
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
return ((this.openBegin && x > this.begin.execute()) || (!this.openBegin && x >= this.begin.execute())) &&
((this.openEnd && x < this.end.execute()) || (!this.openEnd && x <= this.end.execute()))
}
@ -232,7 +237,7 @@ export class Range extends Domain {
static import(frm) {
let openBegin = frm.trim().charAt(0) === "]"
let openEnd = frm.trim().charAt(frm.length - 1) === "["
let [begin, end] = frm.substr(1, frm.length-2).split(";")
let [begin, end] = frm.substring(1, frm.length - 1).split(";")
return new Range(begin.trim(), end.trim(), openBegin, openEnd)
}
}
@ -261,19 +266,19 @@ export class SpecialDomain extends Domain {
includes(x) {
if(x instanceof Expression) x = x.execute()
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
return this.isValid(x)
}
next(x) {
if(x instanceof Expression) x = x.execute()
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
return this.nextValue(x)
}
previous(x) {
if(x instanceof Expression) x = x.execute()
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
return this.prevValue(x)
}
@ -305,7 +310,7 @@ export class SpecialDomain extends Domain {
*/
export class DomainSet extends SpecialDomain {
constructor(values) {
super('', x => true, x => x, true)
super("", () => true, x => x, true)
let newVals = {}
this.executedValues = []
for(let value of values) {
@ -322,7 +327,7 @@ export class DomainSet extends SpecialDomain {
includes(x) {
if(x instanceof Expression) x = x.execute()
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
for(let value of this.values)
if(x === value.execute()) return true
return false
@ -330,7 +335,7 @@ export class DomainSet extends SpecialDomain {
next(x) {
if(x instanceof Expression) x = x.execute()
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
if(x < this.executedValues[0]) return this.executedValues[0]
for(let i = 1; i < this.values.length; i++) {
let prevValue = this.executedValues[i - 1]
@ -342,7 +347,7 @@ export class DomainSet extends SpecialDomain {
previous(x) {
if(x instanceof Expression) x = x.execute()
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
if(x > this.executedValues[this.executedValues.length - 1])
return this.executedValues[this.executedValues.length - 1]
for(let i = 1; i < this.values.length; i++) {
@ -414,7 +419,7 @@ export class DomainSet extends SpecialDomain {
}
static import(frm) {
return new DomainSet(frm.substr(1, frm.length-2).split(";"))
return new DomainSet(frm.substring(1, frm.length - 1).split(";"))
}
}
@ -459,7 +464,7 @@ export class UnionDomain extends Domain {
let domains = frm.trim().split("")
if(domains.length === 1) domains = frm.trim().split("U") // Fallback
let dom2 = parseDomain(domains.pop())
let dom1 = parseDomain(domains.join(''))
let dom1 = parseDomain(domains.join(""))
return dom1.union(dom2)
}
}
@ -504,7 +509,7 @@ export class IntersectionDomain extends Domain {
static import(frm) {
let domains = frm.trim().split("∩")
let dom1 = parseDomain(domains.pop())
let dom2 = parseDomain(domains.join('∩'))
let dom2 = parseDomain(domains.join("∩"))
return dom1.intersection(dom2)
}
}
@ -533,7 +538,7 @@ export class MinusDomain extends Domain {
let domains = frm.trim().split("")
if(domains.length === 1) domains = frm.trim().split("\\") // Fallback
let dom1 = parseDomain(domains.shift())
let dom2 = parseDomain(domains.join(''))
let dom2 = parseDomain(domains.join(""))
return new MinusDomain(dom1, dom2)
}
}
@ -557,29 +562,29 @@ Domain.RPE.latexMarkup = "\\mathbb{R}^{+*}"
Domain.RME = new Range(-Infinity, 0, true, true)
Domain.RME.displayName = "ℝ⁻*"
Domain.RME.latexMarkup = "\\mathbb{R}^{+*}"
Domain.N = new SpecialDomain('', x => x%1===0 && x >= 0,
Domain.N = new SpecialDomain("", x => x % 1 === 0 && x >= 0,
x => Math.max(Math.floor(x) + 1, 0),
x => Math.max(Math.ceil(x) - 1, 0))
Domain.N.latexMarkup = "\\mathbb{N}"
Domain.NE = new SpecialDomain('*', x => x%1===0 && x > 0,
Domain.NE = new SpecialDomain("*", x => x % 1 === 0 && x > 0,
x => Math.max(Math.floor(x) + 1, 1),
x => Math.max(Math.ceil(x) - 1, 1))
Domain.NE.latexMarkup = "\\mathbb{N}^{*}"
Domain.Z = new SpecialDomain('', x => x%1===0, x => Math.floor(x)+1, x => Math.ceil(x)-1)
Domain.Z = new SpecialDomain("", x => x % 1 === 0, x => Math.floor(x) + 1, x => Math.ceil(x) - 1)
Domain.Z.latexMarkup = "\\mathbb{Z}"
Domain.ZE = new SpecialDomain('*', x => x%1===0 && x !== 0,
Domain.ZE = new SpecialDomain("*", x => x % 1 === 0 && x !== 0,
x => Math.floor(x) + 1 === 0 ? Math.floor(x) + 2 : Math.floor(x) + 1,
x => Math.ceil(x) - 1 === 0 ? Math.ceil(x) - 2 : Math.ceil(x) - 1)
Domain.ZE.latexMarkup = "\\mathbb{Z}^{*}"
Domain.ZM = new SpecialDomain('ℤ⁻', x => x%1===0 && x <= 0,
Domain.ZM = new SpecialDomain("ℤ⁻", x => x % 1 === 0 && x <= 0,
x => Math.min(Math.floor(x) + 1, 0),
x => Math.min(Math.ceil(x) - 1, 0))
Domain.ZM.latexMarkup = "\\mathbb{Z}^{-}"
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.ceil(x) - 1, -1))
Domain.ZME.latexMarkup = "\\mathbb{Z}^{-*}"
Domain.NLog = new SpecialDomain('ℕˡᵒᵍ',
Domain.NLog = new SpecialDomain("ℕˡᵒᵍ",
x => x / Math.pow(10, x.toString().length - 1) % 1 === 0 && x > 0,
function(x) {
let x10pow = Math.pow(10, x.toString().length - 1)
@ -600,11 +605,11 @@ let refedDomains = []
* @returns {Domain} Parsed domain.
*/
export function parseDomain(domain) {
if(!domain.includes(')') && !domain.includes('(')) return parseDomainSimple(domain)
if(!domain.includes(")") && !domain.includes("(")) return parseDomainSimple(domain)
let domStr
while((domStr = /\(([^)(]+)\)/.exec(domain)) !== null) {
let dom = parseDomainSimple(domStr[1].trim());
domain = domain.replace(domStr[0], 'D' + refedDomains.length)
let dom = parseDomainSimple(domStr[1].trim())
domain = domain.replace(domStr[0], "D" + refedDomains.length)
refedDomains.push(dom)
}
return parseDomainSimple(domain)
@ -625,6 +630,6 @@ export function parseDomainSimple(domain) {
if(domain.includes("]") || domain.includes("[")) return Range.import(domain)
if(["R", "", "N", "", "Z", ""].some(str => domain.toUpperCase().includes(str)))
return Domain.import(domain)
if(domain[0] === 'D') return refedDomains[parseInt(domain.substr(1))]
if(domain[0] === "D") return refedDomains[parseInt(domain.substring(1))]
return new EmptySet()
}

View file

@ -37,28 +37,48 @@ export class Expression {
}
this.cached = this.isConstant()
this.cachedValue = null
if(this.cached && this.allRequirementsFullfilled())
if(this.cached && this.allRequirementsFulfilled())
this.cachedValue = this.calc.evaluate(Objects.currentObjectsByName)
this.latexMarkup = Latex.expression(this.calc.tokens)
}
/**
* Return all the variables used in calc
* @return {string[]}
*/
variables() {
return this.calc.variables()
}
/**
* Checks if the current expression is constant (does not depend on a variable, be it x or n).
* @return {boolean}
*/
isConstant() {
let vars = this.calc.variables()
return !vars.includes("x") && !vars.includes("n")
}
/**
* Returns the list of object names this expression is dependant on.
* @return {string[]}
*/
requiredObjects() {
return this.calc.variables().filter(objName => objName !== "x" && objName !== "n")
}
allRequirementsFullfilled() {
/**
* Checks if all the objects required for this expression are defined.
* @return {boolean}
*/
allRequirementsFulfilled() {
return this.requiredObjects().every(objName => objName in Objects.currentObjectsByName)
}
/**
* Returns a list of names whose corresponding objects this expression is dependant on and are missing.
* @return {boolean}
*/
undefinedVariables() {
return this.requiredObjects().filter(objName => !(objName in Objects.currentObjectsByName))
}
@ -74,13 +94,13 @@ export class Expression {
this.cachedValue = this.calc.evaluate(Objects.currentObjectsByName)
return this.cachedValue
}
ExprParser.currentVars = Object.assign({'x': x}, Objects.currentObjectsByName)
ExprParser.currentVars = Object.assign({ "x": x }, Objects.currentObjectsByName)
return this.calc.evaluate(ExprParser.currentVars)
}
simplify(x) {
let expr = this.calc.substitute('x', x).simplify()
if(expr.evaluate() === 0) expr = '0'
let expr = this.calc.substitute("x", x).simplify()
if(expr.evaluate() === 0) expr = "0"
return new Expression(expr)
}
@ -91,12 +111,12 @@ export class Expression {
toString(forceSign = false) {
let str = Utils.makeExpressionReadable(this.calc.toString())
if(str !== undefined && str.match(/^\d*\.\d+$/)) {
if(str.split('.')[1].split('0').length > 7) {
if(str.split(".")[1].split("0").length > 7) {
// Likely rounding error
str = parseFloat(str.substring(0, str.length-1)).toString();
str = parseFloat(str.substring(0, str.length - 1)).toString()
}
}
if(str[0] !== '-' && forceSign) str = '+' + str
if(str[0] !== "-" && forceSign) str = "+" + str
return str
}
}

View file

@ -17,7 +17,7 @@
*/
import { Module } from "./common.mjs"
import { FUNCTION, Interface, CanvasInterface, DialogInterface } from "./interface.mjs"
import { CanvasInterface, DialogInterface } from "./interface.mjs"
import { textsup } from "../utils.mjs"
import { Expression } from "../math/index.mjs"
import Latex from "./latex.mjs"
@ -227,7 +227,7 @@ class CanvasAPI extends Module {
// Drawing throws an error. Generally, it's due to a new modification (or the opening of a file)
console.error(e)
console.log(e.stack)
this._drawingErrorDialog.showDialog(objType, obj.name, e.message)
this._drawingErrorDialog.show(objType, obj.name, e.message)
History.undo()
}
}

View file

@ -26,7 +26,7 @@ export class Module {
/**
*
* @param {string} name - Name of the API
* @param {Object.<string, (Interface|string)>} initializationParameters - List of parameters for the initialize function.
* @param {Object.<string, (Interface|string|number|boolean)>} initializationParameters - List of parameters for the initialize function.
*/
constructor(name, initializationParameters = {}) {
console.log(`Loading module ${name}...`)

View file

@ -55,7 +55,7 @@ class ExprParserAPI extends Module {
* @return {function} JS function to call.
*/
parseArgumentsForFunction(args, usage1, usage2) {
let f, target, variable
let f, variable
if(args.length === 1) {
// Parse object
f = args[0]

View file

@ -17,7 +17,6 @@
*/
import { Module } from "./common.mjs"
import Latex from "./latex.mjs"
import { HistoryInterface, NUMBER, STRING } from "./interface.mjs"

View file

@ -69,65 +69,54 @@ export class Interface {
export class SettingsInterface extends Interface {
constructor() {
super()
this.width = NUMBER
this.height = NUMBER
this.xmin = NUMBER
this.ymax = NUMBER
this.xzoom = NUMBER
this.yzoom = NUMBER
this.xaxisstep = STRING
this.yaxisstep = STRING
this.xlabel = STRING
this.ylabel = STRING
this.linewidth = NUMBER
this.textsize = NUMBER
this.logscalex = BOOLEAN
this.showxgrad = BOOLEAN
this.showygrad = BOOLEAN
}
width = NUMBER
height = NUMBER
xmin = NUMBER
ymax = NUMBER
xzoom = NUMBER
yzoom = NUMBER
xaxisstep = STRING
yaxisstep = STRING
xlabel = STRING
ylabel = STRING
linewidth = NUMBER
textsize = NUMBER
logscalex = BOOLEAN
showxgrad = BOOLEAN
showygrad = BOOLEAN
}
export class CanvasInterface extends SettingsInterface {
constructor() {
super()
this.imageLoaders = OBJECT
imageLoaders = OBJECT
/** @type {function(string): CanvasRenderingContext2D} */
this.getContext = FUNCTION
getContext = FUNCTION
/** @type {function(rect)} */
this.markDirty = FUNCTION
markDirty = FUNCTION
/** @type {function(string)} */
this.loadImage = FUNCTION
loadImage = FUNCTION
/** @type {function(string)} */
isImageLoading = FUNCTION
/** @type {function(string)} */
isImageLoaded = FUNCTION
/** @type {function()} */
this.requestPaint = FUNCTION
}
requestPaint = FUNCTION
}
export class RootInterface extends Interface {
constructor() {
super()
this.width = NUMBER
this.height = NUMBER
this.updateObjectsLists = FUNCTION
}
width = NUMBER
height = NUMBER
updateObjectsLists = FUNCTION
}
export class DialogInterface extends Interface {
constructor() {
super()
this.show = FUNCTION
}
show = FUNCTION
}
export class HistoryInterface extends Interface {
constructor() {
super()
this.undo = FUNCTION
this.redo = FUNCTION
this.clear = FUNCTION
this.addToHistory = FUNCTION
this.unserialize = FUNCTION
this.serialize = FUNCTION
}
undo = FUNCTION
redo = FUNCTION
clear = FUNCTION
addToHistory = FUNCTION
unserialize = FUNCTION
serialize = FUNCTION
}

View file

@ -20,7 +20,7 @@ import { Module } from "./common.mjs"
import Objects from "./objects.mjs"
import History from "./history.mjs"
import Canvas from "./canvas.mjs"
import { DialogInterface, FUNCTION, Interface, RootInterface, SettingsInterface } from "./interface.mjs"
import { DialogInterface, RootInterface, SettingsInterface } from "./interface.mjs"
class IOAPI extends Module {
@ -97,7 +97,7 @@ class IOAPI extends Module {
* Loads the diagram from a certain \c filename.
* @param {string} filename
*/
loadDiagram(filename) {
async loadDiagram(filename) {
if(!this.initialized) throw new Error("Attempting loadDiagram before initialize!")
if(!History.initialized) throw new Error("Attempting loadDiagram before history is initialized!")
let basename = filename.split("/").pop()

View file

@ -20,7 +20,8 @@ import { Module } from "./common.mjs"
import * as Instruction from "../lib/expr-eval/instruction.mjs"
import { escapeValue } from "../lib/expr-eval/expression.mjs"
const unicodechars = ["α", "β", "γ", "δ", "ε", "ζ", "η",
const unicodechars = [
"α", "β", "γ", "δ", "ε", "ζ", "η",
"π", "θ", "κ", "λ", "μ", "ξ", "ρ",
"ς", "σ", "τ", "φ", "χ", "ψ", "ω",
"Γ", "Δ", "Θ", "Λ", "Ξ", "Π", "Σ",
@ -30,7 +31,8 @@ const unicodechars = ["α", "β", "γ", "δ", "ε", "ζ", "η",
"⁷", "⁸", "⁹", "⁰", "₁", "₂", "₃",
"₄", "₅", "₆", "₇", "₈", "₉", "₀",
"pi", "∞"]
const equivalchars = ["\\alpha", "\\beta", "\\gamma", "\\delta", "\\epsilon", "\\zeta", "\\eta",
const equivalchars = [
"\\alpha", "\\beta", "\\gamma", "\\delta", "\\epsilon", "\\zeta", "\\eta",
"\\pi", "\\theta", "\\kappa", "\\lambda", "\\mu", "\\xi", "\\rho",
"\\sigma", "\\sigma", "\\tau", "\\phi", "\\chi", "\\psi", "\\omega",
"\\Gamma", "\\Delta", "\\Theta", "\\Lambda", "\\Xi", "\\Pi", "\\Sigma",
@ -65,26 +67,13 @@ class LatexAPI extends Module {
this.enabled = Helper.getSettingBool("enable_latex")
}
/**
* Prepares and renders a latex string into a png file.
*
* @param {string} markup - LaTeX markup to render.
* @param {number} fontSize - Font size (in pt) to render.
* @param {color} color - Color of the text to render.
* @returns {LatexRenderResult}
*/
renderSync(markup, fontSize, color) {
let args = Latex.render(markup, fontSize, color).split(",")
return new LatexRenderResult(...args)
}
/**
* Checks if the given markup (with given font size and color) has already been
* rendered, and if so, returns its data. Otherwise, returns null.
*
* @param {string} markup - LaTeX markup to render.
* @param {number} fontSize - Font size (in pt) to render.
* @param {color} color - Color of the text to render.
* @param {string} color - Color of the text to render.
* @returns {LatexRenderResult|null}
*/
findPrerendered(markup, fontSize, color) {
@ -100,13 +89,12 @@ class LatexAPI extends Module {
*
* @param {string} markup - LaTeX markup to render.
* @param {number} fontSize - Font size (in pt) to render.
* @param {color} color - Color of the text to render.
* @param {string} color - Color of the text to render.
* @returns {Promise<LatexRenderResult>}
*/
requestAsyncRender(markup, fontSize, color) {
return new Promise(resolve => {
resolve(this.renderSync(markup, fontSize, color))
})
async requestAsyncRender(markup, fontSize, color) {
let args = Latex.render(markup, fontSize, color).split(",")
return new LatexRenderResult(...args)
}
/**
@ -133,7 +121,7 @@ class LatexAPI extends Module {
if(elem[0] !== "(" && elem[elem.length - 1] !== ")" && contents.some(x => elem.indexOf(x) > 0))
return this.par(elem)
if(elem[0] === "(" && elem[elem.length - 1] === ")")
return elem.substr(1, elem.length - 2)
return elem.removeEnclosure()
return elem
}
@ -148,24 +136,24 @@ class LatexAPI extends Module {
switch(f) {
case "derivative":
if(args.length === 3)
return "\\frac{d" + args[0].substr(1, args[0].length - 2).replace(new RegExp(args[1].substr(1, args[1].length - 2), "g"), "x") + "}{dx}"
return `\\frac{d${args[0].removeEnclosure().replaceAll(args[1].removeEnclosure(), "x")}}{dx}`
else
return "\\frac{d" + args[0] + "}{dx}(x)"
return `\\frac{d${args[0]}}{dx}(x)`
case "integral":
if(args.length === 4)
return "\\int\\limits_{" + args[0] + "}^{" + args[1] + "}" + args[2].substr(1, args[2].length - 2) + " d" + args[3].substr(1, args[3].length - 2)
return `\\int\\limits_{${args[0]}}^{${args[1]}}${args[2].removeEnclosure()} d${args[3].removeEnclosure()}`
else
return "\\int\\limits_{" + args[0] + "}^{" + args[1] + "}" + args[2] + "(t) dt"
return `\\int\\limits_{${args[0]}}^{${args[1]}}${args[2]}(t) dt`
case "sqrt":
return "\\sqrt\\left(" + args.join(", ") + "\\right)"
return `\\sqrt\\left(${args.join(", ")}\\right)`
case "abs":
return "\\left|" + args.join(", ") + "\\right|"
return `\\left|${args.join(", ")}\\right|`
case "floor":
return "\\left\\lfloor" + args.join(", ") + "\\right\\rfloor"
return `\\left\\lfloor${args.join(", ")}\\right\\rfloor`
case "ceil":
return "\\left\\lceil" + args.join(", ") + "\\right\\rceil"
return `\\left\\lceil${args.join(", ")}\\right\\rceil`
default:
return "\\mathrm{" + f + "}\\left(" + args.join(", ") + "\\right)"
return `\\mathrm{${f}}\\left(${args.join(", ")}\\right)`
}
}
@ -180,12 +168,12 @@ class LatexAPI extends Module {
if(wrapIn$)
for(let i = 0; i < unicodechars.length; i++) {
if(vari.includes(unicodechars[i]))
vari = vari.replace(new RegExp(unicodechars[i], "g"), "$" + equivalchars[i] + "$")
vari = vari.replaceAll(unicodechars[i], "$" + equivalchars[i] + "$")
}
else
for(let i = 0; i < unicodechars.length; i++) {
if(vari.includes(unicodechars[i]))
vari = vari.replace(new RegExp(unicodechars[i], "g"), equivalchars[i])
vari = vari.replaceAll(unicodechars[i], equivalchars[i])
}
return vari
}

View file

@ -16,13 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Module } from './common.mjs'
import { textsub } from '../utils.mjs'
import { Module } from "./common.mjs"
import { textsub } from "../utils.mjs"
class ObjectsAPI extends Module {
constructor() {
super('Objects')
super("Objects")
this.types = {}
/**
@ -45,7 +45,7 @@ class ObjectsAPI extends Module {
* @param {string} prefix - Prefix to the name.
* @return {string} New unused name for a new object.
*/
getNewName(allowedLetters, prefix='') {
getNewName(allowedLetters, prefix = "") {
// Allows to get a new name, based on the allowed letters,
// as well as adding a sub number when needs be.
let newid = 0
@ -53,7 +53,7 @@ class ObjectsAPI extends Module {
do {
let letter = allowedLetters[newid % allowedLetters.length]
let num = Math.floor((newid - (newid % allowedLetters.length)) / allowedLetters.length)
ret = prefix + letter + (num > 0 ? textsub(num-1) : '')
ret = prefix + letter + (num > 0 ? textsub(num - 1) : "")
newid += 1
} while(ret in this.currentObjectsByName)
return ret
@ -90,15 +90,10 @@ class ObjectsAPI extends Module {
* @returns {string[]} List of names of the objects.
*/
getObjectsName(objType) {
if(objType === "ExecutableObject") {
// NOTE: QMLJS does not support flatMap.
// return getExecutableTypes().flatMap(elemType => currentObjects[elemType].map(obj => obj.name))
let types = this.getExecutableTypes()
let elementNames = ['']
for(let elemType of types)
elementNames = elementNames.concat(this.currentObjects[elemType].map(obj => obj.name))
return elementNames
}
if(objType === "ExecutableObject")
return this.getExecutableTypes().flatMap(
elemType => this.currentObjects[elemType].map(obj => obj.name)
)
if(this.currentObjects[objType] === undefined) return []
return this.currentObjects[objType].map(obj => obj.name)
}
@ -119,7 +114,7 @@ class ObjectsAPI extends Module {
*/
createNewRegisteredObject(objType, args = []) {
if(Object.keys(this.types).indexOf(objType) === -1) return null // Object type does not exist.
let newobj = new this.types[objType](...args)
const newobj = new this.types[objType](...args)
if(Object.keys(this.currentObjects).indexOf(objType) === -1) {
this.currentObjects[objType] = []
}

View file

@ -22,12 +22,12 @@ import DefaultGraph from "../preferences/default.mjs"
class PreferencesAPI extends Module {
constructor() {
super('Preferences')
super("Preferences")
this.categories = {
[QT_TRANSLATE_NOOP('settingCategory', 'general')]: General,
[QT_TRANSLATE_NOOP('settingCategory', 'editor')]: Editor,
[QT_TRANSLATE_NOOP('settingCategory', 'default')]: DefaultGraph,
[QT_TRANSLATE_NOOP("settingCategory", "general")]: General,
[QT_TRANSLATE_NOOP("settingCategory", "editor")]: Editor,
[QT_TRANSLATE_NOOP("settingCategory", "default")]: DefaultGraph
}
}
}

View file

@ -27,39 +27,50 @@ import { ExecutableObject } from "./common.mjs"
import Function from "./function.mjs"
export default class BodeMagnitude extends ExecutableObject {
static type(){return 'Gain Bode'}
static displayType(){return qsTranslate("bodemagnitude", 'Bode Magnitude')}
static displayTypeMultiple(){return qsTranslate("bodemagnitude", 'Bode Magnitudes')}
static properties() {return {
[QT_TRANSLATE_NOOP('prop','om_0')]: new P.ObjectType('Point'),
[QT_TRANSLATE_NOOP('prop','pass')]: P.Enum.BodePass,
[QT_TRANSLATE_NOOP('prop','gain')]: new P.Expression(),
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number',
[QT_TRANSLATE_NOOP('prop','omGraduation')]: 'boolean'
}}
static type() {
return "Gain Bode"
}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
om_0 = '', pass = 'high', gain = '20', labelPosition = 'above', labelX = 1, omGraduation = false) {
if(name == null) name = Objects.getNewName('G')
if(name === 'G') name = 'G₀' // G is reserved for sum of BODE magnitudes (Somme gains Bode).
static displayType() {
return qsTranslate("bodemagnitude", "Bode Magnitude")
}
static displayTypeMultiple() {
return qsTranslate("bodemagnitude", "Bode Magnitudes")
}
static properties() {
return {
[QT_TRANSLATE_NOOP("prop", "om_0")]: new P.ObjectType("Point"),
[QT_TRANSLATE_NOOP("prop", "pass")]: P.Enum.BodePass,
[QT_TRANSLATE_NOOP("prop", "gain")]: new P.Expression(),
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Position,
[QT_TRANSLATE_NOOP("prop", "labelX")]: "number",
[QT_TRANSLATE_NOOP("prop", "omGraduation")]: "boolean"
}
}
constructor(name = null, visible = true, color = null, labelContent = "name + value",
om_0 = "", pass = "high", gain = "20", labelPosition = "above", labelX = 1, omGraduation = false) {
if(name == null) name = Objects.getNewName("G")
if(name === "G") name = "G₀" // G is reserved for sum of BODE magnitudes (Somme gains Bode).
super(name, visible, color, labelContent)
if(typeof om_0 == "string") {
// Point name or create one
om_0 = Objects.currentObjectsByName[om_0]
if(om_0 == null) {
// Create new point
om_0 = Objects.createNewRegisteredObject('Point', [Objects.getNewName('ω'), true, this.color, 'name'])
History.addToHistory(new CreateNewObject(om_0.name, 'Point', om_0.export()))
om_0 = Objects.createNewRegisteredObject("Point", [Objects.getNewName("ω"), true, this.color, "name"])
History.addToHistory(new CreateNewObject(om_0.name, "Point", om_0.export()))
om_0.update()
labelPosition = 'below'
labelPosition = "below"
}
om_0.requiredBy.push(this)
}
/** @type {Point} */
this.om_0 = om_0
this.pass = pass
if(typeof gain == 'number' || typeof gain == 'string') gain = new Expression(gain.toString())
if(typeof gain == "number" || typeof gain == "string") gain = new Expression(gain.toString())
this.gain = gain
this.labelPosition = labelPosition
this.labelX = labelX
@ -67,12 +78,12 @@ export default class BodeMagnitude extends ExecutableObject {
}
getReadableString() {
let pass = this.pass === "low" ? qsTranslate("bodemagnitude", "low-pass") : qsTranslate("bodemagnitude", "high-pass");
return `${this.name}: ${pass}; ${this.om_0.name} = ${this.om_0.x}\n ${' '.repeat(this.name.length)}${this.gain.toString(true)} dB/dec`
let pass = this.pass === "low" ? qsTranslate("bodemagnitude", "low-pass") : qsTranslate("bodemagnitude", "high-pass")
return `${this.name}: ${pass}; ${this.om_0.name} = ${this.om_0.x}\n ${" ".repeat(this.name.length)}${this.gain.toString(true)} dB/dec`
}
getLatexString() {
let pass = this.pass === "low" ? qsTranslate("bodemagnitude", "low-pass") : qsTranslate("bodemagnitude", "high-pass");
let pass = this.pass === "low" ? qsTranslate("bodemagnitude", "low-pass") : qsTranslate("bodemagnitude", "high-pass")
return `\\mathrm{${Latex.variable(this.name)}:}\\begin{array}{l}
\\textsf{${pass}};${Latex.variable(this.om_0.name)} = ${this.om_0.x.latexMarkup} \\\\
${this.gain.latexMarkup}\\textsf{ dB/dec}
@ -80,8 +91,8 @@ export default class BodeMagnitude extends ExecutableObject {
}
execute(x = 1) {
if(typeof x == 'string') x = executeExpression(x)
if((this.pass === 'high' && x < this.om_0.x) || (this.pass === 'low' && x > this.om_0.x)) {
if(typeof x == "string") x = executeExpression(x)
if((this.pass === "high" && x < this.om_0.x) || (this.pass === "low" && x > this.om_0.x)) {
let dbfn = new Expression(`${this.gain.execute()}*(ln(x)-ln(${this.om_0.x}))/ln(10)+${this.om_0.y}`)
return dbfn.execute(x)
} else {
@ -91,8 +102,8 @@ export default class BodeMagnitude extends ExecutableObject {
simplify(x = 1) {
let xval = x
if(typeof x == 'string') xval = executeExpression(x)
if((this.pass === 'high' && xval < this.om_0.x.execute()) || (this.pass === 'low' && xval > this.om_0.x.execute())) {
if(typeof x == "string") xval = executeExpression(x)
if((this.pass === "high" && xval < this.om_0.x.execute()) || (this.pass === "low" && xval > this.om_0.x.execute())) {
let dbfn = new Expression(`${this.gain.execute()}*(ln(x)-ln(${this.om_0.x}))/ln(10)+${this.om_0.y}`)
return dbfn.simplify(x)
} else {
@ -107,9 +118,9 @@ export default class BodeMagnitude extends ExecutableObject {
draw(canvas) {
let base = [canvas.x2px(this.om_0.x.execute()), canvas.y2px(this.om_0.y.execute())]
let dbfn = new Expression(`${this.gain.execute()}*(log10(x)-log10(${this.om_0.x}))+${this.om_0.y}`)
let inDrawDom = new EmptySet()
let inDrawDom
if(this.pass === 'high') {
if(this.pass === "high") {
// High pass, linear line from beginning, then constant to the end.
canvas.drawLine(base[0], base[1], canvas.width, base[1])
inDrawDom = parseDomain(`]-inf;${this.om_0.x}[`)
@ -131,17 +142,19 @@ export default class BodeMagnitude extends ExecutableObject {
update() {
super.update()
let sumObjs = Objects.currentObjects['Somme gains Bode']
/** @type {BodeMagnitudeSum[]} */
let sumObjs = Objects.currentObjects["Somme gains Bode"]
if(sumObjs !== undefined && sumObjs.length > 0) {
sumObjs[0].recalculateCache()
} else {
Objects.createNewRegisteredObject('Somme gains Bode')
Objects.createNewRegisteredObject("Somme gains Bode")
}
}
delete() {
super.delete()
let sumObjs = Objects.currentObjects['Somme gains Bode']
/** @type {BodeMagnitudeSum[]} */
let sumObjs = Objects.currentObjects["Somme gains Bode"]
if(sumObjs !== undefined && sumObjs.length > 0) {
sumObjs[0].recalculateCache()
}

View file

@ -26,18 +26,32 @@ import Function from "./function.mjs"
export default class BodeMagnitudeSum extends ExecutableObject {
static type(){return 'Somme gains Bode'}
static displayType(){return qsTranslate("bodemagnitudesum", 'Bode Magnitudes Sum')}
static displayTypeMultiple(){return qsTranslate("bodemagnitudesum", 'Bode Magnitudes Sum')}
static createable() {return false}
static properties() {return {
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number',
}}
static type() {
return "Somme gains Bode"
}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
labelPosition = 'above', labelX = 1) {
if(name == null) name = 'G'
static displayType() {
return qsTranslate("bodemagnitudesum", "Bode Magnitudes Sum")
}
static displayTypeMultiple() {
return qsTranslate("bodemagnitudesum", "Bode Magnitudes Sum")
}
static createable() {
return false
}
static properties() {
return {
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Position,
[QT_TRANSLATE_NOOP("prop", "labelX")]: "number"
}
}
constructor(name = null, visible = true, color = null, labelContent = "name + value",
labelPosition = "above", labelX = 1) {
if(name == null) name = "G"
super(name, visible, color, labelContent)
this.labelPosition = labelPosition
this.labelX = labelX
@ -45,11 +59,11 @@ export default class BodeMagnitudeSum extends ExecutableObject {
}
getReadableString() {
return `${this.name} = ${Objects.getObjectsName('Gain Bode').join(' + ')}`
return `${this.name} = ${Objects.getObjectsName("Gain Bode").join(" + ")}`
}
getLatexString() {
return `${Latex.variable(this.name)} = ${Objects.getObjectsName('Gain Bode').map(name => Latex.variable(name)).join(' + ')}`
return `${Latex.variable(this.name)} = ${Objects.getObjectsName("Gain Bode").map(name => Latex.variable(name)).join(" + ")}`
}
execute(x = 0) {
@ -71,17 +85,17 @@ export default class BodeMagnitudeSum extends ExecutableObject {
return limitedDrawFunction.simplify(x)
}
}
return ''
return ""
}
recalculateCache() {
this.cachedParts = []
// Calculating this is fairly resource expansive so it's cached.
let magnitudeObjects = Objects.currentObjects['Gain Bode']
let magnitudeObjects = Objects.currentObjects["Gain Bode"]
if(magnitudeObjects === undefined || magnitudeObjects.length < 1) {
Objects.deleteObject(this.name)
} else {
console.log('Recalculating cache gain')
console.log("Recalculating cache gain")
// Minimum to draw (can be expended if needed, just not infinite or it'll cause issues.
const MIN_DRAW = 1e-20
// Format: [[x value of where the filter transitions, magnitude, high-pass (bool)]]
@ -92,9 +106,9 @@ export default class BodeMagnitudeSum extends ExecutableObject {
magnitudes.push([Number.MAX_VALUE, 0, true]) // Draw the ending section
// Collect data from current magnitude (or gain in French) objects.
let baseY = 0
for(/** @type {Bodemagnitude} */ let magnitudeObj of magnitudeObjects) { // Sorting by their om_0 position.
for(/** @type {BodeMagnitude} */ let magnitudeObj of magnitudeObjects) { // Sorting by their om_0 position.
const om0x = magnitudeObj.om_0.x.execute()
magnitudes.push([om0x, magnitudeObj.gain.execute(), magnitudeObj.pass === 'high'])
magnitudes.push([om0x, magnitudeObj.gain.execute(), magnitudeObj.pass === "high"])
baseY += magnitudeObj.execute(MIN_DRAW)
}
// Sorting the data by their x transitions value

View file

@ -27,33 +27,44 @@ import { ExecutableObject } from "./common.mjs"
export default class BodePhase extends ExecutableObject {
static type(){return 'Phase Bode'}
static displayType(){return qsTranslate("bodephase", 'Bode Phase')}
static displayTypeMultiple(){return qsTranslate("bodephase", 'Bode Phases')}
static properties() {return {
[QT_TRANSLATE_NOOP('prop','om_0')]: new P.ObjectType('Point'),
[QT_TRANSLATE_NOOP('prop','phase')]: new P.Expression(),
[QT_TRANSLATE_NOOP('prop','unit')]: new P.Enum('°', 'deg', 'rad'),
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number'
}}
static type() {
return "Phase Bode"
}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
om_0 = '', phase = 90, unit = '°', labelPosition = 'above', labelX = 1) {
if(name == null) name = Objects.getNewName('φ')
if(name === 'φ') name = 'φ₀' // φ is reserved for sum of Bode phases.
static displayType() {
return qsTranslate("bodephase", "Bode Phase")
}
static displayTypeMultiple() {
return qsTranslate("bodephase", "Bode Phases")
}
static properties() {
return {
[QT_TRANSLATE_NOOP("prop", "om_0")]: new P.ObjectType("Point"),
[QT_TRANSLATE_NOOP("prop", "phase")]: new P.Expression(),
[QT_TRANSLATE_NOOP("prop", "unit")]: new P.Enum("°", "deg", "rad"),
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Position,
[QT_TRANSLATE_NOOP("prop", "labelX")]: "number"
}
}
constructor(name = null, visible = true, color = null, labelContent = "name + value",
om_0 = "", phase = 90, unit = "°", labelPosition = "above", labelX = 1) {
if(name == null) name = Objects.getNewName("φ")
if(name === "φ") name = "φ₀" // φ is reserved for sum of Bode phases.
super(name, visible, color, labelContent)
if(typeof phase == 'number' || typeof phase == 'string') phase = new Expression(phase.toString())
if(typeof phase == "number" || typeof phase == "string") phase = new Expression(phase.toString())
this.phase = phase
if(typeof om_0 == "string") {
// Point name or create one
om_0 = Objects.currentObjectsByName[om_0]
if(om_0 == null) {
// Create new point
om_0 = Objects.createNewRegisteredObject('Point', [Objects.getNewName('ω'), this.color, 'name'])
om_0.labelPosition = this.phase.execute() >= 0 ? 'above' : 'below'
History.history.addToHistory(new CreateNewObject(om_0.name, 'Point', om_0.export()))
labelPosition = 'below'
om_0 = Objects.createNewRegisteredObject("Point", [Objects.getNewName("ω"), this.color, "name"])
om_0.labelPosition = this.phase.execute() >= 0 ? "above" : "below"
History.history.addToHistory(new CreateNewObject(om_0.name, "Point", om_0.export()))
labelPosition = "below"
}
om_0.requiredBy.push(this)
}
@ -73,7 +84,7 @@ export default class BodePhase extends ExecutableObject {
}
execute(x = 1) {
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
if(x < this.om_0.x) {
return this.om_0.y.execute()
} else {
@ -83,11 +94,11 @@ export default class BodePhase extends ExecutableObject {
simplify(x = 1) {
let xval = x
if(typeof x == 'string') xval = executeExpression(x)
if(typeof x == "string") xval = executeExpression(x)
if(xval < this.om_0.x) {
return this.om_0.y.toString()
} else {
let newExp = this.om_0.y.toEditableString() + ' + ' + this.phase.toEditableString()
let newExp = this.om_0.y.toEditableString() + " + " + this.phase.toEditableString()
return new Expression(newExp)
}
}
@ -115,17 +126,19 @@ export default class BodePhase extends ExecutableObject {
update() {
super.update()
let sumObjs = Objects.currentObjects['Somme phases Bode']
/** @type {BodePhaseSum[]} */
let sumObjs = Objects.currentObjects["Somme phases Bode"]
if(sumObjs !== undefined && sumObjs.length > 0) {
sumObjs[0].recalculateCache()
} else {
Objects.createNewRegisteredObject('Somme phases Bode')
Objects.createNewRegisteredObject("Somme phases Bode")
}
}
delete() {
super.update()
let sumObjs = Objects.currentObjects['Somme phases Bode']
/** @type {BodePhaseSum[]} */
let sumObjs = Objects.currentObjects["Somme phases Bode"]
if(sumObjs !== undefined && sumObjs.length > 0) {
sumObjs[0].recalculateCache()
}

View file

@ -24,18 +24,32 @@ import Latex from "../module/latex.mjs"
import { ExecutableObject } from "./common.mjs"
export default class BodePhaseSum extends ExecutableObject {
static type(){return 'Somme phases Bode'}
static displayType(){return qsTranslate("bodephasesum", 'Bode Phases Sum')}
static displayTypeMultiple(){return qsTranslate("bodephasesum", 'Bode Phases Sum')}
static createable() {return false}
static properties() {return {
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number',
}}
static type() {
return "Somme phases Bode"
}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
labelPosition = 'above', labelX = 1) {
if(name == null) name = 'φ'
static displayType() {
return qsTranslate("bodephasesum", "Bode Phases Sum")
}
static displayTypeMultiple() {
return qsTranslate("bodephasesum", "Bode Phases Sum")
}
static createable() {
return false
}
static properties() {
return {
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Position,
[QT_TRANSLATE_NOOP("prop", "labelX")]: "number"
}
}
constructor(name = null, visible = true, color = null, labelContent = "name + value",
labelPosition = "above", labelX = 1) {
if(name == null) name = "φ"
super(name, visible, color, labelContent)
this.labelPosition = labelPosition
this.labelX = labelX
@ -43,15 +57,15 @@ export default class BodePhaseSum extends ExecutableObject {
}
getReadableString() {
return `${this.name} = ${Objects.getObjectsName('Phase Bode').join(' + ')}`
return `${this.name} = ${Objects.getObjectsName("Phase Bode").join(" + ")}`
}
getLatexString() {
return `${Latex.variable(this.name)} = ${Objects.getObjectsName('Phase Bode').map(name => Latex.variable(name)).join(' + ')}`
return `${Latex.variable(this.name)} = ${Objects.getObjectsName("Phase Bode").map(name => Latex.variable(name)).join(" + ")}`
}
execute(x = 1) {
if(typeof x == 'string') x = executeExpression(x)
if(typeof x == "string") x = executeExpression(x)
for(let i = 0; i < this.om0xList.length - 1; i++) {
if(x >= this.om0xList[i] && x < this.om0xList[i + 1]) return this.phasesList[i]
}
@ -59,13 +73,13 @@ export default class BodePhaseSum extends ExecutableObject {
simplify(x = 1) {
let xval = x
if(typeof x == 'string') xval = executeExpression(x)
if(typeof x == "string") xval = executeExpression(x)
for(let i = 0; i < this.om0xList.length - 1; i++) {
if(xval >= this.om0xList[i] && xval < this.om0xList[i + 1]) {
return (new Expression(this.phasesExprList[i])).simplify()
}
}
return '0'
return "0"
}
canExecute(x = 1) {
@ -78,33 +92,32 @@ export default class BodePhaseSum extends ExecutableObject {
let drawMax = 1e20
this.om0xList = [drawMin, drawMax]
this.phasesList = [0]
this.phasesExprList = ['0']
this.phasesExprList = ["0"]
let phasesDict = new Map()
let phasesExprDict = new Map()
phasesDict.set(drawMax, 0)
let phaseObjects = Objects.currentObjects['Phase Bode']
let phaseObjects = Objects.currentObjects["Phase Bode"]
if(phaseObjects === undefined || phaseObjects.length < 1) {
Objects.deleteObject(this.name)
} else {
console.log('Recalculating cache phase')
for(/** @type {Bodephase} */ let obj of phaseObjects) {
console.log("Recalculating cache phase")
for(/** @type {BodePhase} */ let obj of phaseObjects) {
this.om0xList.push(obj.om_0.x.execute())
if(!phasesDict.has(obj.om_0.x.execute())) {
phasesDict.set(obj.om_0.x.execute(), obj.phase.execute())
phasesExprDict.set(obj.om_0.x.execute(), obj.phase.toEditableString())
} else {
phasesDict.set(obj.om_0.x.execute(), obj.phase.execute() + phasesDict.get(obj.om_0.x.execute()))
phasesExprDict.set(obj.om_0.x.execute(), obj.phase.toEditableString() + '+' + phasesExprDict.get(obj.om_0.x.execute()))
phasesExprDict.set(obj.om_0.x.execute(), obj.phase.toEditableString() + "+" + phasesExprDict.get(obj.om_0.x.execute()))
}
this.phasesList[0] += obj.om_0.y.execute()
this.phasesExprList[0] += '+' + obj.om_0.y.toEditableString()
this.phasesExprList[0] += "+" + obj.om_0.y.toEditableString()
}
this.om0xList.sort((a, b) => a - b)
let totalAdded = this.phasesList[0]
for(let i = 1; i < this.om0xList.length; i++) {
this.phasesList[i] = this.phasesList[i - 1] + phasesDict.get(this.om0xList[i])
this.phasesExprList[i] = this.phasesExprList[i-1] + '+' + phasesDict.get(this.om0xList[i])
this.phasesExprList[i] = this.phasesExprList[i - 1] + "+" + phasesDict.get(this.om0xList[i])
}
}
}

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { getRandomColor, textsub } from "../utils.mjs"
import { getRandomColor } from "../utils.mjs"
import Objects from "../module/objects.mjs"
import Latex from "../module/latex.mjs"
import { ensureTypeSafety, serializesByPropertyType } from "../parameters.mjs"
@ -32,26 +32,34 @@ export class DrawableObject {
* Base name of the object. Needs to be constant over time.
* @return {string} Type of the object.
*/
static type(){return 'Unknown'}
static type() {
return "Unknown"
}
/**
* Translated name of the object to be shown to the user.
* @return {string}
*/
static displayType(){return 'Unknown'}
static displayType() {
return "Unknown"
}
/**
* Translated name of the object in plural form to be shown to the user.
* @return {string}
*/
static displayTypeMultiple(){return 'Unknowns'}
static displayTypeMultiple() {
return "Unknowns"
}
/**
* True if this object can be created by the user, false if it can only
* be instantiated by other objects
* @return {boolean}
*/
static createable() {return true}
static createable() {
return true
}
/**
* List of properties used in the Object Editor.
@ -70,14 +78,18 @@ export class DrawableObject {
*
* @return {Object.<string,string|Enum|List|ObjectType|Dictionary>}
*/
static properties() {return {}}
static properties() {
return {}
}
/**
* True if this object can be executed, so that an y value might be computed
* for an x value. Only ExecutableObjects have that property set to true.
* @return {boolean}
*/
static executable() {return false}
static executable() {
return false
}
/**
* Imports the object from its serialized form.
@ -85,9 +97,9 @@ export class DrawableObject {
*/
static import(name, visible, color, labelContent, ...args) {
let importedArgs = [name.toString(), visible === true, color.toString(), labelContent]
console.log('Importing', this.type(), name, args)
console.log("Importing", this.type(), name, args)
for(let [name, propType] of Object.entries(this.properties()))
if(!name.startsWith('comment')) {
if(!name.startsWith("comment")) {
importedArgs.push(ensureTypeSafety(propType, args[importedArgs.length - 4]))
}
return new this(...importedArgs)
@ -98,10 +110,10 @@ export class DrawableObject {
* @param {string} name - Name of the object
* @param {boolean} visible - true if the object is visible, false otherwise.
* @param {color|string} color - Color of the object (can be string or QColor)
* @param {'null'|'name'|'name + value'} labelContent - One of 'null', 'name' or 'name + value' describing the content of the label.
* @param {"null"|"name"|"name + value"} labelContent - One of 'null', 'name' or 'name + value' describing the content of the label.
* @constructor
*/
constructor(name, visible = true, color = null, labelContent = 'name + value') {
constructor(name, visible = true, color = null, labelContent = "name + value") {
if(color == null) color = getRandomColor()
this.type = this.constructor.type()
this.name = name
@ -120,7 +132,7 @@ export class DrawableObject {
export() {
let exportList = [this.name, this.visible, this.color.toString(), this.labelContent]
for(let [name, propType] of Object.entries(this.constructor.properties()))
if(!name.startsWith('comment'))
if(!name.startsWith("comment"))
exportList.push(serializesByPropertyType(propType, this[name]))
return exportList
}
@ -151,12 +163,12 @@ export class DrawableObject {
*/
getLabel() {
switch(this.labelContent) {
case 'name':
case "name":
return this.name
case 'name + value':
case "name + value":
return this.getReadableString()
case 'null':
return ''
case "null":
return ""
}
}
@ -170,12 +182,12 @@ export class DrawableObject {
*/
getLatexLabel() {
switch(this.labelContent) {
case 'name':
case "name":
return Latex.variable(this.name)
case 'name + value':
case "name + value":
return this.getLatexString()
case 'null':
return ''
case "null":
return ""
}
}
@ -203,8 +215,8 @@ export class DrawableObject {
let currentObjectsByName = Objects.currentObjectsByName
let properties = this.constructor.properties()
for(let property in properties)
if(typeof properties[property] == 'object' && 'type' in properties[property])
if(properties[property].type === 'Expression' && this[property] != null) {
if(typeof properties[property] == "object" && "type" in properties[property])
if(properties[property].type === "Expression" && this[property] != null) {
// Expressions with dependencies
for(let objName of this[property].requiredObjects()) {
if(objName in currentObjectsByName && !this.requires.includes(currentObjectsByName[objName])) {
@ -216,7 +228,7 @@ export class DrawableObject {
// Recalculate
this[property].recache()
} else if(properties[property].type === 'ObjectType' && this[property] != null) {
} else if(properties[property].type === "ObjectType" && this[property] != null) {
// Object dependency
this.requires.push(this[property])
this[property].requiredBy.push(this)
@ -242,7 +254,8 @@ export class DrawableObject {
* Abstract method. Draw the object onto the canvas with the.
* @param {CanvasAPI} canvas
*/
draw(canvas) {}
draw(canvas) {
}
/**
* Applicates a drawFunction with two position arguments depending on
@ -252,46 +265,46 @@ export class DrawableObject {
*
* @param {string|Enum} labelPosition - Position of the label relative to the marked position
* @param {number} offset - Margin between the position and the object to be drawn
* @param {Object.<string, int>} size - Size of the label item, containing two properties, "width" and "height"
* @param {{width: number, height: number}} size - Size of the label item, containing two properties, "width" and "height"
* @param {number} posX - Component of the marked position on the x-axis
* @param {number} posY - Component of the marked position on the y-axis
* @param {function} drawFunction - Function with two arguments (x, y) that will be called to draw the label
*/
drawPositionDivergence(labelPosition, offset, size, posX, posY, drawFunction) {
switch(labelPosition) {
case 'center':
case "center":
drawFunction(posX - size.width / 2, posY - size.height / 2)
break;
case 'top':
case 'above':
break
case "top":
case "above":
drawFunction(posX - size.width / 2, posY - size.height - offset)
break;
case 'bottom':
case 'below':
break
case "bottom":
case "below":
drawFunction(posX - size.width / 2, posY + offset)
break;
case 'left':
break
case "left":
drawFunction(posX - size.width - offset, posY - size.height / 2)
break;
case 'right':
break
case "right":
drawFunction(posX + offset, posY - size.height / 2)
break;
case 'top-left':
case 'above-left':
break
case "top-left":
case "above-left":
drawFunction(posX - size.width, posY - size.height - offset)
break;
case 'top-right':
case 'above-right':
break
case "top-right":
case "above-right":
drawFunction(posX + offset, posY - size.height - offset)
break;
case 'bottom-left':
case 'below-left':
break
case "bottom-left":
case "below-left":
drawFunction(posX - size.width - offset, posY + offset)
break;
case 'bottom-right':
case 'below-right':
break
case "bottom-right":
case "below-right":
drawFunction(posX + offset, posY + offset)
break;
break
}
}
@ -327,15 +340,14 @@ export class DrawableObject {
if(drawFunctionText == null)
drawFunctionText = (x, y, text, textSize) => canvas.drawVisibleText(text, x, y + textSize.height) // Positioned from left bottom
// Drawing the label
let offset
if(!forceText && Latex.enabled) {
// With latex
let drawLblCb = ((ltxImg) => {
this.drawPositionDivergence(labelPosition, 8 + canvas.linewidth / 2, ltxImg, posX, posY, (x, y) => drawFunctionLatex(x, y, ltxImg))
}).bind(this)
let ltxLabel = getLatexFunction();
})
let ltxLabel = getLatexFunction()
if(ltxLabel !== "")
canvas.renderLatexImage(ltxLabel, this.color, drawLblCb.bind(this))
canvas.renderLatexImage(ltxLabel, this.color, drawLblCb)
} else {
// Without latex
let text = getTextFunction()
@ -346,7 +358,7 @@ export class DrawableObject {
}
toString() {
return this.name;
return this.name
}
}
@ -367,28 +379,38 @@ export class ExecutableObject extends DrawableObject {
* @param {number} x
* @returns {number|null}
*/
execute(x = 1) {return 0}
execute(x = 1) {
return 0
}
/**
* Returns false if the object isn't defined on the given x, true otherwise.
*
* @param {number} x
* @returns {boolean}
*/
canExecute(x = 1) {return true}
canExecute(x = 1) {
return true
}
/**
* Returns the simplified expression string for a given x.
*
* @param {number} x
* @returns {string|Expression}
*/
simplify(x = 1) {return '0'}
simplify(x = 1) {
return "0"
}
/**
* True if this object can be executed, so that an y value might be computed
* for an x value. Only ExecutableObjects have that property set to true.
* @return {boolean}
*/
static executable() {return true}
static executable() {
return true
}
}

View file

@ -24,18 +24,30 @@ import { ExecutableObject } from "./common.mjs"
export default class DistributionFunction extends ExecutableObject {
static type(){return 'Repartition'}
static displayType(){return qsTranslate("distribution", 'Repartition')}
static displayTypeMultiple(){return qsTranslate("distribution", 'Repartition functions')}
static properties() {return {
'comment1': QT_TRANSLATE_NOOP(
'comment',
'Note: Specify the probability for each value.'
static type() {
return "Repartition"
}
static displayType() {
return qsTranslate("distribution", "Repartition")
}
static displayTypeMultiple() {
return qsTranslate("distribution", "Repartition functions")
}
static properties() {
return {
"comment1": QT_TRANSLATE_NOOP(
"comment",
"Note: Specify the probability for each value."
),
[QT_TRANSLATE_NOOP('prop','probabilities')]: new P.Dictionary('string', 'double', /^-?[\d.,]+$/, /^-?[\d.,]+$/, 'P({name_} = ', ') = '),
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number',
}}
[QT_TRANSLATE_NOOP("prop", "probabilities")]: new P.Dictionary("string", "double", /^-?[\d.,]+$/, /^-?[\d.,]+$/, "P({name_} = ", ") = "),
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Position,
[QT_TRANSLATE_NOOP("prop", "labelX")]: "number"
}
}
static import(name, visible, color, labelContent, ...args) {
console.log(args, args.length)
if(args.length === 5) {
@ -46,9 +58,9 @@ export default class DistributionFunction extends ExecutableObject {
return super.import(name, visible, color, labelContent, ...args)
}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
probabilities = {'0': '0'}, labelPosition = 'above', labelX = 1) {
if(name == null) name = Objects.getNewName('XYZUVW', "F_")
constructor(name = null, visible = true, color = null, labelContent = "name + value",
probabilities = { "0": "0" }, labelPosition = "above", labelX = 1) {
if(name == null) name = Objects.getNewName("XYZUVW", "F_")
super(name, visible, color, labelContent)
this.probabilities = probabilities
this.labelPosition = labelPosition
@ -57,27 +69,29 @@ export default class DistributionFunction extends ExecutableObject {
}
getReadableString() {
let keys = Object.keys(this.probabilities).sort((a,b) => a-b);
let keys = Object.keys(this.probabilities).sort((a, b) => a - b)
let varname = this.name.substring(this.name.indexOf("_") + 1)
return `${this.name}(x) = P(${varname} ≤ x)\n` + keys.map(idx => `P(${varname}=${idx})=${this.probabilities[idx]}`).join("; ")
}
getLatexString() {
let keys = Object.keys(this.probabilities).sort((a,b) => a-b);
let keys = Object.keys(this.probabilities).sort((a, b) => a - b)
let funcName = Latex.variable(this.name)
let varName = Latex.variable(this.name.substring(this.name.indexOf("_") + 1))
return `\\begin{array}{l}{${funcName}}(x) = P(${varName} \\le x)\\\\` + keys.map(idx => `P(${varName}=${idx})=${this.probabilities[idx]}`).join("; ") + '\\end{array}'
return `\\begin{array}{l}{${funcName}}(x) = P(${varName} \\le x)\\\\` + keys.map(idx => `P(${varName}=${idx})=${this.probabilities[idx]}`).join("; ") + "\\end{array}"
}
execute(x = 1) {
let ret = 0;
let ret = 0
Object.keys(this.probabilities).sort((a, b) => a - b).forEach(idx => {
if(x >= idx) ret += parseFloat(this.probabilities[idx].replace(/,/g, '.'))
if(x >= idx) ret += parseFloat(this.probabilities[idx].replace(/,/g, "."))
})
return ret
}
canExecute(x = 1) {return true}
canExecute(x = 1) {
return true
}
// Simplify returns the simplified string of the expression.
simplify(x = 1) {
@ -86,27 +100,27 @@ export default class DistributionFunction extends ExecutableObject {
getLabel() {
switch(this.labelContent) {
case 'name':
case "name":
return `${this.name}(x)`
case 'name + value':
case "name + value":
return this.getReadableString()
case 'null':
return ''
case "null":
return ""
}
}
draw(canvas) {
let currentY = 0;
let currentY = 0
let keys = Object.keys(this.probabilities).map(idx => parseInt(idx)).sort((a, b) => a - b)
if(canvas.isVisible(keys[0],this.probabilities[keys[0]].replace(/,/g, '.'))) {
if(canvas.isVisible(keys[0], this.probabilities[keys[0]].replace(/,/g, "."))) {
canvas.drawLine(0, canvas.y2px(0), canvas.x2px(keys[0]), canvas.y2px(0))
if(canvas.isVisible(keys[0], 0)) {
canvas.arc(canvas.x2px(keys[0])+4,canvas.y2px(0), 4, Math.PI / 2, 3 * Math.PI / 2);
canvas.arc(canvas.x2px(keys[0]) + 4, canvas.y2px(0), 4, Math.PI / 2, 3 * Math.PI / 2)
}
}
for(let i = 0; i < keys.length - 1; i++) {
let idx = keys[i];
currentY += parseFloat(this.probabilities[idx].replace(/,/g, '.'));
let idx = keys[i]
currentY += parseFloat(this.probabilities[idx].replace(/,/g, "."))
if(canvas.isVisible(idx, currentY) || canvas.isVisible(keys[i + 1], currentY)) {
canvas.drawLine(
Math.max(0, canvas.x2px(idx)),
@ -118,21 +132,21 @@ export default class DistributionFunction extends ExecutableObject {
canvas.disc(canvas.x2px(idx), canvas.y2px(currentY), 4)
}
if(canvas.isVisible(keys[i + 1], currentY)) {
canvas.arc(canvas.x2px(keys[i+1])+4,canvas.y2px(currentY), 4, Math.PI / 2, 3 * Math.PI / 2);
canvas.arc(canvas.x2px(keys[i + 1]) + 4, canvas.y2px(currentY), 4, Math.PI / 2, 3 * Math.PI / 2)
}
}
}
if(canvas.isVisible(keys[keys.length - 1], currentY + parseFloat(this.probabilities[keys[keys.length - 1]]))) {
canvas.drawLine(
Math.max(0, canvas.x2px(keys[keys.length - 1])),
canvas.y2px(currentY+parseFloat(this.probabilities[keys[keys.length-1]].replace(/,/g, '.'))),
canvas.y2px(currentY + parseFloat(this.probabilities[keys[keys.length - 1]].replace(/,/g, "."))),
canvas.width,
canvas.y2px(currentY+parseFloat(this.probabilities[keys[keys.length-1]].replace(/,/g, '.')))
canvas.y2px(currentY + parseFloat(this.probabilities[keys[keys.length - 1]].replace(/,/g, ".")))
)
canvas.disc(
canvas.x2px(keys[keys.length - 1]),
canvas.y2px(
currentY+parseFloat(this.probabilities[keys[keys.length-1]].replace(/,/g, '.'))
currentY + parseFloat(this.probabilities[keys[keys.length - 1]].replace(/,/g, "."))
),
4
)

View file

@ -25,39 +25,50 @@ import Latex from "../module/latex.mjs"
export default class Function extends ExecutableObject {
static type(){return 'Function'}
static displayType(){return qsTranslate("function", 'Function')}
static displayTypeMultiple(){return qsTranslate("function", 'Functions')}
static properties() {return {
[QT_TRANSLATE_NOOP('prop','expression')]: new P.Expression('x'),
[QT_TRANSLATE_NOOP('prop','definitionDomain')]: 'Domain',
[QT_TRANSLATE_NOOP('prop','destinationDomain')]: 'Domain',
'comment1': QT_TRANSLATE_NOOP(
'comment',
'Ex: R+* (ℝ⁺*), N (), Z-* (ℤ⁻*), ]0;1[, {3;4;5}'
),
[QT_TRANSLATE_NOOP('prop','displayMode')]: P.Enum.FunctionDisplayType,
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number',
'comment2': QT_TRANSLATE_NOOP(
'comment',
'The following parameters are used when the definition domain is a non-continuous set. (Ex: , , sets like {0;3}...)'
),
[QT_TRANSLATE_NOOP('prop','drawPoints')]: 'boolean',
[QT_TRANSLATE_NOOP('prop','drawDashedLines')]: 'boolean'
}}
static type() {
return "Function"
}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
expression = 'x', definitionDomain = 'RPE', destinationDomain = 'R',
displayMode = 'application', labelPosition = 'above', labelX = 1,
static displayType() {
return qsTranslate("function", "Function")
}
static displayTypeMultiple() {
return qsTranslate("function", "Functions")
}
static properties() {
return {
[QT_TRANSLATE_NOOP("prop", "expression")]: new P.Expression("x"),
[QT_TRANSLATE_NOOP("prop", "definitionDomain")]: "Domain",
[QT_TRANSLATE_NOOP("prop", "destinationDomain")]: "Domain",
"comment1": QT_TRANSLATE_NOOP(
"comment",
"Ex: R+* (ℝ⁺*), N (), Z-* (ℤ⁻*), ]0;1[, {3;4;5}"
),
[QT_TRANSLATE_NOOP("prop", "displayMode")]: P.Enum.FunctionDisplayType,
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Position,
[QT_TRANSLATE_NOOP("prop", "labelX")]: "number",
"comment2": QT_TRANSLATE_NOOP(
"comment",
"The following parameters are used when the definition domain is a non-continuous set. (Ex: , , sets like {0;3}...)"
),
[QT_TRANSLATE_NOOP("prop", "drawPoints")]: "boolean",
[QT_TRANSLATE_NOOP("prop", "drawDashedLines")]: "boolean"
}
}
constructor(name = null, visible = true, color = null, labelContent = "name + value",
expression = "x", definitionDomain = "RPE", destinationDomain = "R",
displayMode = "application", labelPosition = "above", labelX = 1,
drawPoints = true, drawDashedLines = true) {
if(name == null) name = Objects.getNewName('fghjqlmnopqrstuvwabcde')
if(name == null) name = Objects.getNewName("fghjqlmnopqrstuvwabcde")
super(name, visible, color, labelContent)
if(typeof expression == 'number' || typeof expression == 'string') expression = new Expression(expression.toString())
if(typeof expression == "number" || typeof expression == "string") expression = new Expression(expression.toString())
this.expression = expression
if(typeof definitionDomain == 'string') definitionDomain = parseDomain(definitionDomain)
if(typeof definitionDomain == "string") definitionDomain = parseDomain(definitionDomain)
this.definitionDomain = definitionDomain
if(typeof destinationDomain == 'string') destinationDomain = parseDomain(destinationDomain)
if(typeof destinationDomain == "string") destinationDomain = parseDomain(destinationDomain)
this.destinationDomain = destinationDomain
this.displayMode = displayMode
this.labelPosition = labelPosition
@ -67,15 +78,15 @@ export default class Function extends ExecutableObject {
}
getReadableString() {
if(this.displayMode === 'application') {
return `${this.name}: ${this.definitionDomain}${this.destinationDomain}\n ${' '.repeat(this.name.length)}x ⟼ ${this.expression.toString()}`
if(this.displayMode === "application") {
return `${this.name}: ${this.definitionDomain}${this.destinationDomain}\n ${" ".repeat(this.name.length)}x ⟼ ${this.expression.toString()}`
} else {
return `${this.name}(x) = ${this.expression.toString()}\nD${textsub(this.name)} = ${this.definitionDomain}`
}
}
getLatexString() {
if(this.displayMode === 'application') {
if(this.displayMode === "application") {
return `${Latex.variable(this.name)}:\\begin{array}{llll}${this.definitionDomain.latexMarkup}\\textrm{ } & \\rightarrow & \\textrm{ }${this.destinationDomain.latexMarkup}\\\\
x\\textrm{ } & \\mapsto & \\textrm{ }${this.expression.latexMarkup}\\end{array}`
} else {
@ -96,7 +107,7 @@ export default class Function extends ExecutableObject {
simplify(x = 1) {
if(this.definitionDomain.includes(x))
return this.expression.simplify(x)
return ''
return ""
}
draw(canvas) {
@ -112,7 +123,7 @@ export default class Function extends ExecutableObject {
static drawFunction(canvas, expr, definitionDomain, destinationDomain, drawPoints = true, drawDash = true) {
let pxprecision = 10
let previousX = canvas.px2x(0)
let previousY = null;
let previousY = null
if(definitionDomain instanceof SpecialDomain && definitionDomain.moveSupported) {
// Point based functions.
previousX = definitionDomain.next(previousX)
@ -121,9 +132,9 @@ export default class Function extends ExecutableObject {
if(!drawPoints && !drawDash) return
while(previousX !== null && canvas.x2px(previousX) < canvas.width) {
// Reconverted for canvas to fix for logarithmic scales.
let currentX = definitionDomain.next(canvas.px2x(canvas.x2px(previousX)+pxprecision));
let currentX = definitionDomain.next(canvas.px2x(canvas.x2px(previousX) + pxprecision))
let currentY = expr.execute(currentX)
if(currentX === null) break;
if(currentX === null) break
if((definitionDomain.includes(currentX) || definitionDomain.includes(previousX)) &&
(destinationDomain.includes(currentY) || destinationDomain.includes(previousY))) {
if(drawDash)
@ -156,7 +167,7 @@ export default class Function extends ExecutableObject {
// Need to find the starting point.
let tmpPx = px - pxprecision
do {
tmpPx++;
tmpPx++
previousX = canvas.px2x(tmpPx)
} while(!definitionDomain.includes(previousX))
// Recaclulate previousY
@ -166,7 +177,7 @@ export default class Function extends ExecutableObject {
// Augmenting the pixel precision until this condition is fulfilled.
let tmpPx = px
do {
tmpPx--;
tmpPx--
currentX = canvas.px2x(tmpPx)
} while(!definitionDomain.includes(currentX) && currentX !== previousX)
}

View file

@ -25,24 +25,34 @@ import { DrawableObject } from "./common.mjs"
export default class Point extends DrawableObject {
static type(){return 'Point'}
static displayType(){return qsTranslate("point", 'Point')}
static displayTypeMultiple(){return qsTranslate("point", 'Points')}
static type() {
return "Point"
}
static properties() {return {
[QT_TRANSLATE_NOOP('prop','x')]: new P.Expression(),
[QT_TRANSLATE_NOOP('prop','y')]: new P.Expression(),
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[QT_TRANSLATE_NOOP('prop','pointStyle')]: new P.Enum('●', '✕', '')
}}
static displayType() {
return qsTranslate("point", "Point")
}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
x = 1, y = 0, labelPosition = 'above', pointStyle = '●') {
if(name == null) name = Objects.getNewName('ABCDEFJKLMNOPQRSTUVW')
static displayTypeMultiple() {
return qsTranslate("point", "Points")
}
static properties() {
return {
[QT_TRANSLATE_NOOP("prop", "x")]: new P.Expression(),
[QT_TRANSLATE_NOOP("prop", "y")]: new P.Expression(),
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Position,
[QT_TRANSLATE_NOOP("prop", "pointStyle")]: new P.Enum("●", "✕", "")
}
}
constructor(name = null, visible = true, color = null, labelContent = "name + value",
x = 1, y = 0, labelPosition = "above", pointStyle = "●") {
if(name == null) name = Objects.getNewName("ABCDEFJKLMNOPQRSTUVW")
super(name, visible, color, labelContent)
if(typeof x == 'number' || typeof x == 'string') x = new Expression(x.toString())
if(typeof x == "number" || typeof x == "string") x = new Expression(x.toString())
this.x = x
if(typeof y == 'number' || typeof y == 'string') y = new Expression(y.toString())
if(typeof y == "number" || typeof y == "string") y = new Expression(y.toString())
this.y = y
this.labelPosition = labelPosition
this.pointStyle = pointStyle
@ -60,17 +70,17 @@ export default class Point extends DrawableObject {
let [canvasX, canvasY] = [canvas.x2px(this.x.execute()), canvas.y2px(this.y.execute())]
let pointSize = 8 + (canvas.linewidth * 2)
switch(this.pointStyle) {
case '●':
case "●":
canvas.disc(canvasX, canvasY, pointSize / 2)
break;
case '✕':
break
case "✕":
canvas.drawLine(canvasX - pointSize / 2, canvasY - pointSize / 2, canvasX + pointSize / 2, canvasY + pointSize / 2)
canvas.drawLine(canvasX - pointSize / 2, canvasY + pointSize / 2, canvasX + pointSize / 2, canvasY - pointSize / 2)
break;
case '':
break
case "":
canvas.fillRect(canvasX - pointSize / 2, canvasY - 1, pointSize, 2)
canvas.fillRect(canvasX - 1, canvasY - pointSize / 2, 2, pointSize)
break;
break
}
this.drawLabel(canvas, this.labelPosition, canvasX, canvasY)
}

View file

@ -26,27 +26,37 @@ import Function from "./function.mjs"
export default class Sequence extends ExecutableObject {
static type(){return 'Sequence'}
static displayType(){return qsTranslate("sequence", 'Sequence')}
static displayTypeMultiple(){return qsTranslate("sequence", 'Sequences')}
static type() {
return "Sequence"
}
static properties() {return {
[QT_TRANSLATE_NOOP('prop','drawPoints')]: 'boolean',
[QT_TRANSLATE_NOOP('prop','drawDashedLines')]: 'boolean',
[QT_TRANSLATE_NOOP('prop','defaultExpression')]: new P.Dictionary('string', 'int', /^.+$/, /^\d+$/, '{name}[n+', '] = ', true),
'comment1': QT_TRANSLATE_NOOP(
'comment',
'Note: Use %1[n] to refer to %1ₙ, %1[n+1] for %1ₙ₊₁...'
static displayType() {
return qsTranslate("sequence", "Sequence")
}
static displayTypeMultiple() {
return qsTranslate("sequence", "Sequences")
}
static properties() {
return {
[QT_TRANSLATE_NOOP("prop", "drawPoints")]: "boolean",
[QT_TRANSLATE_NOOP("prop", "drawDashedLines")]: "boolean",
[QT_TRANSLATE_NOOP("prop", "defaultExpression")]: new P.Dictionary("string", "int", /^.+$/, /^\d+$/, "{name}[n+", "] = ", true),
"comment1": QT_TRANSLATE_NOOP(
"comment",
"Note: Use %1[n] to refer to %1ₙ, %1[n+1] for %1ₙ₊₁..."
),
[QT_TRANSLATE_NOOP('prop','baseValues')]: new P.Dictionary('string', 'int', /^.+$/, /^\d+$/, '{name}[', '] = '),
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number',
}}
[QT_TRANSLATE_NOOP("prop", "baseValues")]: new P.Dictionary("string", "int", /^.+$/, /^\d+$/, "{name}[", "] = "),
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Position,
[QT_TRANSLATE_NOOP("prop", "labelX")]: "number"
}
}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
constructor(name = null, visible = true, color = null, labelContent = "name + value",
drawPoints = true, drawDashedLines = true, defaultExp = { 1: "n" },
baseValues = {0: 0}, labelPosition = 'above', labelX = 1) {
if(name == null) name = Objects.getNewName('uvwPSUVWabcde')
baseValues = { 0: 0 }, labelPosition = "above", labelX = 1) {
if(name == null) name = Objects.getNewName("uvwPSUVWabcde")
super(name, visible, color, labelContent)
this.drawPoints = drawPoints
this.drawDashedLines = drawDashedLines
@ -58,17 +68,17 @@ export default class Sequence extends ExecutableObject {
}
update() {
console.log('Updating sequence', this.sequence)
console.log("Updating sequence", this.sequence)
super.update()
if(
this.sequence == null || this.baseValues !== this.sequence.baseValues ||
this.sequence.name !== this.name ||
this.sequence.expr !== Object.values(this.defaultExpression)[0] ||
this.sequence.valuePlus !== Object.keys(this.defaultExpression)[0]
this.sequence.valuePlus.toString() !== Object.keys(this.defaultExpression)[0]
)
this.sequence = new MathSequence(
this.name, this.baseValues,
Object.keys(this.defaultExpression)[0],
parseFloat(Object.keys(this.defaultExpression)[0]),
Object.values(this.defaultExpression)[0]
)
}
@ -86,7 +96,10 @@ export default class Sequence extends ExecutableObject {
return this.sequence.execute(x)
return null
}
canExecute(x = 1) {return x%1 === 0}
canExecute(x = 1) {
return x % 1 === 0
}
// Simplify returns the simplified string of the expression.
simplify(x = 1) {
@ -97,23 +110,23 @@ export default class Sequence extends ExecutableObject {
getLabel() {
switch(this.labelContent) {
case 'name':
case "name":
return `(${this.name}ₙ)`
case 'name + value':
case "name + value":
return this.getReadableString()
case 'null':
return ''
case "null":
return ""
}
}
getLatexLabel() {
switch(this.labelContent) {
case 'name':
case "name":
return `(${Latex.variable(this.name)}_n)`
case 'name + value':
case "name + value":
return this.getLatexString()
case 'null':
return ''
case "null":
return ""
}
}

View file

@ -25,28 +25,39 @@ import { DrawableObject } from "./common.mjs"
export default class Text extends DrawableObject {
static type(){return 'Text'}
static displayType(){return qsTranslate("text", 'Text')}
static displayTypeMultiple(){return qsTranslate("text", 'Texts')}
static properties() {return {
[QT_TRANSLATE_NOOP('prop','x')]: new P.Expression(),
[QT_TRANSLATE_NOOP('prop','y')]: new P.Expression(),
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Positioning,
[QT_TRANSLATE_NOOP('prop','text')]: 'string',
'comment1': QT_TRANSLATE_NOOP(
'comment',
'If you have latex enabled, you can use use latex markup in between $$ to create equations.'
),
[QT_TRANSLATE_NOOP('prop','disableLatex')]: 'boolean'
}}
static type() {
return "Text"
}
constructor(name = null, visible = true, color = null, labelContent = 'null',
x = 1, y = 0, labelPosition = 'center', text = 'New text', disableLatex = false) {
if(name == null) name = Objects.getNewName('t')
static displayType() {
return qsTranslate("text", "Text")
}
static displayTypeMultiple() {
return qsTranslate("text", "Texts")
}
static properties() {
return {
[QT_TRANSLATE_NOOP("prop", "x")]: new P.Expression(),
[QT_TRANSLATE_NOOP("prop", "y")]: new P.Expression(),
[QT_TRANSLATE_NOOP("prop", "labelPosition")]: P.Enum.Positioning,
[QT_TRANSLATE_NOOP("prop", "text")]: "string",
"comment1": QT_TRANSLATE_NOOP(
"comment",
"If you have latex enabled, you can use use latex markup in between $$ to create equations."
),
[QT_TRANSLATE_NOOP("prop", "disableLatex")]: "boolean"
}
}
constructor(name = null, visible = true, color = null, labelContent = "null",
x = 1, y = 0, labelPosition = "center", text = "New text", disableLatex = false) {
if(name == null) name = Objects.getNewName("t")
super(name, visible, color, labelContent)
if(typeof x == 'number' || typeof x == 'string') x = new Expression(x.toString())
if(typeof x == "number" || typeof x == "string") x = new Expression(x.toString())
this.x = x
if(typeof y == 'number' || typeof y == 'string') y = new Expression(y.toString())
if(typeof y == "number" || typeof y == "string") y = new Expression(y.toString())
this.y = y
this.labelPosition = labelPosition
this.text = text
@ -60,15 +71,17 @@ export default class Text extends DrawableObject {
latexMarkupText() {
// Check whether the text contains latex escaped elements.
let txt = []
this.text.split('$$').forEach(function(t) { txt = txt.concat(Latex.variable(t, true).replace(/\$\$/g, '').split('$')) })
this.text.split("$$").forEach(function(t) {
txt = txt.concat(Latex.variable(t, true).replace(/\$\$/g, "").split("$"))
})
let newTxt = txt[0]
let i
// Split between normal text and latex escaped.
for(i = 0; i < txt.length - 1; i++)
if(i & 0x01) // Every odd number
newTxt += '\\textsf{'+Latex.variable(txt[i+1])
newTxt += "\\textsf{" + Latex.variable(txt[i + 1])
else
newTxt += '}'+txt[i+1]
newTxt += "}" + txt[i + 1]
// Finished by a }
if(i & 0x01)
newTxt += "{"

View file

@ -73,29 +73,28 @@ export default class XCursor extends DrawableObject {
\\end{array}`
}
getTargetValueLabel() {
var t = this.targetElement
var approx = ''
getApprox() {
let approx = ''
if(this.approximate) {
approx = (t.execute(this.x.execute()))
approx = (this.targetElement.execute(this.x.execute()))
let intLength = Math.round(approx).toString().length
let rounding = Math.min(this.rounding, approx.toString().length - intLength - 1)
approx = approx.toPrecision(rounding + intLength)
}
return approx
}
getTargetValueLabel() {
const t = this.targetElement
const approx = this.getApprox()
return `${t.name}(${this.name}) = ${t.simplify(this.x.toEditableString())}` +
(this.approximate ? ' ≈ ' + approx : '')
}
getTargetValueLatexLabel() {
let t = this.targetElement
let approx = ''
if(this.approximate) {
approx = (t.execute(this.x.execute()))
let intLength = Math.round(approx).toString().length
let rounding = Math.min(this.rounding, approx.toString().length - intLength - 1)
approx = approx.toPrecision(rounding + intLength)
}
let simpl = t.simplify(this.x.toEditableString())
const t = this.targetElement
const approx = this.getApprox()
const simpl = t.simplify(this.x.toEditableString())
return `${Latex.variable(t.name)}(${Latex.variable(this.name)}) = ${simpl.latexMarkup ? simpl.latexMarkup : Latex.variable(simpl)}` +
(this.approximate ? ' \\simeq ' + approx : '')
}
@ -104,16 +103,13 @@ export default class XCursor extends DrawableObject {
switch(this.labelContent) {
case 'name':
return this.name
break;
case 'name + value':
switch(this.targetValuePosition) {
case 'Next to target':
case 'Hidden':
return `${this.name} = ${this.x.toString()}`
break;
case 'With label':
return this.getReadableString()
break;
}
case 'null':
return ''
@ -124,16 +120,13 @@ export default class XCursor extends DrawableObject {
switch(this.labelContent) {
case 'name':
return Latex.variable(this.name)
break;
case 'name + value':
switch(this.targetValuePosition) {
case 'Next to target':
case 'Hidden':
return `${Latex.variable(this.name)} = ${this.x.latexMarkup}`
break;
case 'With label':
return this.getLatexString()
break;
}
case 'null':
return ''

View file

@ -18,12 +18,13 @@
import { parseDomain, Expression as Expr, Domain } from "./math/index.mjs"
import Objects from "./module/objects.mjs"
const NONE = class Empty {}
const NONE = class Empty {
}
let stringValuesValidators = {
'int': [parseInt, (x) => !isNaN(x)],
'double': [parseFloat, (x) => !isNaN(x)],
'string': [(x) => x, () => true]
"int": [parseInt, (x) => !isNaN(x)],
"double": [parseFloat, (x) => !isNaN(x)],
"string": [(x) => x, () => true]
}
let stringValidatorTypes = Object.keys(stringValuesValidators)
@ -52,17 +53,17 @@ class PropertyType {
export class Expression extends PropertyType {
constructor(...variables) {
super()
this.type = 'Expression'
this.type = "Expression"
this.variables = variables
}
toString() {
return this.variables.length === 0 ? 'Number' : `Expression(${this.variables.join(', ')})`
return this.variables.length === 0 ? "Number" : `Expression(${this.variables.join(", ")})`
}
parse(value) {
let result = NONE
if(typeof value == 'string')
if(typeof value == "string")
try {
result = new Expr(value)
} catch(e) {
@ -86,14 +87,14 @@ export class Expression extends PropertyType {
export class Enum extends PropertyType {
constructor(...values) {
super()
this.type = 'Enum'
this.type = "Enum"
this.values = values
this.legacyValues = {}
this.translatedValues = values.map(x => qsTranslate('parameters', x))
this.translatedValues = values.map(x => qsTranslate("parameters", x))
}
toString() {
return `${this.type}(${this.values.join(', ')})`
return `${this.type}(${this.values.join(", ")})`
}
parse(value) {
@ -111,7 +112,7 @@ export class Enum extends PropertyType {
else if(this.legacyValues[value])
return this.legacyValues[value]
else
throw new TypeError(`Exportation error: ${value} not one of ${this.values.join(', ')}.`)
throw new TypeError(`Exportation error: ${value} not one of ${this.values.join(", ")}.`)
}
}
@ -119,7 +120,7 @@ export class Enum extends PropertyType {
export class ObjectType extends PropertyType {
constructor(objType, allowNull = false) {
super()
this.type = 'ObjectType'
this.type = "ObjectType"
this.objType = objType
this.allowNull = allowNull
}
@ -130,9 +131,9 @@ export class ObjectType extends PropertyType {
parse(name) {
let result = NONE
if(typeof name == 'string' && name in Objects.currentObjectsByName) {
if(typeof name == "string" && name in Objects.currentObjectsByName) {
let obj = Objects.currentObjectsByName[name]
if (obj.type === this.objType || (this.objType === 'ExecutableObject' && obj.execute)) {
if(obj.type === this.objType || (this.objType === "ExecutableObject" && obj.execute)) {
result = obj
} else {
// Silently error and return null
@ -147,7 +148,7 @@ export class ObjectType extends PropertyType {
export(value) {
if(value == null && this.allowNull)
return null
else if(value.type === this.objType || (this.objType === 'ExecutableObject' && value.execute))
else if(value.type === this.objType || (this.objType === "ExecutableObject" && value.execute))
return value.name
else
throw new TypeError(`Exportation error: ${value} not a ${this.objType}.`)
@ -156,13 +157,13 @@ export class ObjectType extends PropertyType {
export class List extends PropertyType {
constructor(type, format = /^.+$/, label = '', forbidAdding = false) {
constructor(type, format = /^.+$/, label = "", forbidAdding = false) {
super()
// type can be string, int and double.
this.type = 'List'
this.type = "List"
this.valueType = type
if(!stringValidatorTypes.includes(this.valueType))
throw new TypeError(`${this.valueType} must be one of ${stringValidatorTypes.join(', ')}.`)
throw new TypeError(`${this.valueType} must be one of ${stringValidatorTypes.join(", ")}.`)
this.format = format
this.label = label
this.forbidAdding = forbidAdding
@ -174,7 +175,7 @@ export class List extends PropertyType {
parse(value) {
let result = NONE
if(typeof value == 'object' && value.__proto__ === Array) {
if(typeof value == "object" && value.__proto__ === Array) {
let valid = 0
for(let v of value) {
if(this.format.test(v)) {
@ -190,7 +191,7 @@ export class List extends PropertyType {
}
export(value) {
if(typeof value == 'object' && value.__proto__ === Array)
if(typeof value == "object" && value.__proto__ === Array)
return value
else
throw new TypeError(`Exportation error: ${value} not a list.`)
@ -200,10 +201,10 @@ export class List extends PropertyType {
export class Dictionary extends PropertyType {
constructor(type, keyType = 'string', format = /^.+$/, keyFormat = /^.+$/, preKeyLabel = '', postKeyLabel = ': ', forbidAdding = false) {
constructor(type, keyType = "string", format = /^.+$/, keyFormat = /^.+$/, preKeyLabel = "", postKeyLabel = ": ", forbidAdding = false) {
super()
// type & keyType can be string, int and double.
this.type = 'Dict'
this.type = "Dict"
this.valueType = type
this.keyType = keyType
this.format = format
@ -219,7 +220,7 @@ export class Dictionary extends PropertyType {
parse(value) {
let result = NONE
if(typeof value == 'object' && value.__proto__ !== Array) {
if(typeof value == "object" && value.__proto__ !== Array) {
let dict = []
for(let [k, v] of Object.entries(value)) {
if(this.format.test(v) && this.keyFormat.test(k)) {
@ -237,7 +238,7 @@ export class Dictionary extends PropertyType {
}
export(value) {
if(typeof value == 'object' && value.__proto__ !== Array)
if(typeof value == "object" && value.__proto__ !== Array)
return value
else
throw new TypeError(`Exportation error: ${value} not a dictionary.`)
@ -247,51 +248,51 @@ export class Dictionary extends PropertyType {
// Common parameters for Enums
Enum.Position = new Enum(
QT_TRANSLATE_NOOP('parameters', 'above'),
QT_TRANSLATE_NOOP('parameters', 'below'),
QT_TRANSLATE_NOOP('parameters', 'left'),
QT_TRANSLATE_NOOP('parameters', 'right'),
QT_TRANSLATE_NOOP('parameters', 'above-left'),
QT_TRANSLATE_NOOP('parameters', 'above-right'),
QT_TRANSLATE_NOOP('parameters', 'below-left'),
QT_TRANSLATE_NOOP('parameters', 'below-right')
QT_TRANSLATE_NOOP("parameters", "above"),
QT_TRANSLATE_NOOP("parameters", "below"),
QT_TRANSLATE_NOOP("parameters", "left"),
QT_TRANSLATE_NOOP("parameters", "right"),
QT_TRANSLATE_NOOP("parameters", "above-left"),
QT_TRANSLATE_NOOP("parameters", "above-right"),
QT_TRANSLATE_NOOP("parameters", "below-left"),
QT_TRANSLATE_NOOP("parameters", "below-right")
)
Enum.Position.legacyValues = {
'top': 'above',
'bottom': 'below',
'top-left': 'above-left',
'top-right': 'above-right',
'bottom-left': 'below-left',
'bottom-right': 'below-right',
"top": "above",
"bottom": "below",
"top-left": "above-left",
"top-right": "above-right",
"bottom-left": "below-left",
"bottom-right": "below-right"
}
Enum.Positioning = new Enum(
QT_TRANSLATE_NOOP('parameters', 'center'),
QT_TRANSLATE_NOOP('parameters', 'top'),
QT_TRANSLATE_NOOP('parameters', 'bottom'),
QT_TRANSLATE_NOOP('parameters', 'left'),
QT_TRANSLATE_NOOP('parameters', 'right'),
QT_TRANSLATE_NOOP('parameters', 'top-left'),
QT_TRANSLATE_NOOP('parameters', 'top-right'),
QT_TRANSLATE_NOOP('parameters', 'bottom-left'),
QT_TRANSLATE_NOOP('parameters', 'bottom-right')
QT_TRANSLATE_NOOP("parameters", "center"),
QT_TRANSLATE_NOOP("parameters", "top"),
QT_TRANSLATE_NOOP("parameters", "bottom"),
QT_TRANSLATE_NOOP("parameters", "left"),
QT_TRANSLATE_NOOP("parameters", "right"),
QT_TRANSLATE_NOOP("parameters", "top-left"),
QT_TRANSLATE_NOOP("parameters", "top-right"),
QT_TRANSLATE_NOOP("parameters", "bottom-left"),
QT_TRANSLATE_NOOP("parameters", "bottom-right")
)
Enum.FunctionDisplayType = new Enum(
QT_TRANSLATE_NOOP('parameters', 'application'),
QT_TRANSLATE_NOOP('parameters', 'function')
QT_TRANSLATE_NOOP("parameters", "application"),
QT_TRANSLATE_NOOP("parameters", "function")
)
Enum.BodePass = new Enum(
QT_TRANSLATE_NOOP('parameters', 'high'),
QT_TRANSLATE_NOOP('parameters', 'low')
QT_TRANSLATE_NOOP("parameters", "high"),
QT_TRANSLATE_NOOP("parameters", "low")
)
Enum.XCursorValuePosition = new Enum(
QT_TRANSLATE_NOOP('parameters', 'Next to target'),
QT_TRANSLATE_NOOP('parameters', 'With label'),
QT_TRANSLATE_NOOP('parameters', 'Hidden')
QT_TRANSLATE_NOOP("parameters", "Next to target"),
QT_TRANSLATE_NOOP("parameters", "With label"),
QT_TRANSLATE_NOOP("parameters", "Hidden")
)
/**
@ -303,23 +304,23 @@ Enum.XCursorValuePosition = new Enum(
export function ensureTypeSafety(propertyType, value) {
let result
let error = false
if(typeof propertyType == 'string')
if(typeof propertyType == "string")
switch(propertyType) {
case 'string':
case "string":
result = value
error = typeof value !== 'string'
error = typeof value !== "string"
break
case 'number':
case "number":
result = parseFloat(value)
error = isNaN(result)
break
case 'boolean':
case "boolean":
result = value
error = value !== true && value !== false
break
case 'Domain':
case "Domain":
try {
error = typeof value !== 'string'
error = typeof value !== "string"
if(!error)
result = parseDomain(value)
} catch(e) {
@ -353,18 +354,18 @@ export function ensureTypeSafety(propertyType, value) {
*/
export function serializesByPropertyType(propertyType, value) {
let result
if(typeof propertyType == 'string')
if(typeof propertyType == "string")
switch(propertyType) {
case 'string':
case "string":
result = value.toString()
break
case 'number':
case "number":
result = parseFloat(value)
break
case 'boolean':
case "boolean":
result = value === true
break
case 'Domain':
case "Domain":
if(value instanceof Domain)
result = value.toString()
else

View file

@ -19,28 +19,28 @@
export default class InputExpression {
constructor(expression) {
this.position = 0;
this.input = expression;
this.position = 0
this.input = expression
}
next() {
return this.input[this.position++];
return this.input[this.position++]
}
peek() {
return this.input[this.position];
return this.input[this.position]
}
skip(char) {
if(!this.atEnd() && this.peek() === char) {
this.position++;
this.position++
} else {
this.raise("Unexpected character " + this.peek() + ". Expected character " + char);
this.raise("Unexpected character " + this.peek() + ". Expected character " + char)
}
}
atEnd() {
return this.position >= this.input.length;
return this.position >= this.input.length
}
raise(message) {

View file

@ -25,8 +25,8 @@ export const CONSTANTS = {
"infinity": Infinity,
"∞": Infinity,
"e": Math.E
};
export const CONSTANTS_LIST = Object.keys(CONSTANTS);
}
export const CONSTANTS_LIST = Object.keys(CONSTANTS)
export const FUNCTIONS = {
// The functions commented are the one either not implemented
@ -36,66 +36,66 @@ export const FUNCTIONS = {
//'-': (x) => -x,
//'!'
// Other operations
'length': (s) => Array.isArray(s) ? s.length : String(s).length,
"length": (s) => Array.isArray(s) ? s.length : String(s).length,
// Boolean functions
'not': (x) => !x,
"not": (x) => !x,
// Math functions
'abs': Math.abs,
'acos': Math.acos,
'acosh': Math.acosh,
'asin': Math.asin,
'asinh': Math.asinh,
'atan': Math.atan,
'atan2': Math.atan2,
'atanh': Math.atanh,
'cbrt': Math.cbrt,
'ceil': Math.ceil,
"abs": Math.abs,
"acos": Math.acos,
"acosh": Math.acosh,
"asin": Math.asin,
"asinh": Math.asinh,
"atan": Math.atan,
"atan2": Math.atan2,
"atanh": Math.atanh,
"cbrt": Math.cbrt,
"ceil": Math.ceil,
//'clz32': Math.clz32,
'cos': Math.cos,
'cosh': Math.cosh,
'exp': Math.exp,
'expm1': Math.expm1,
'floor': Math.floor,
"cos": Math.cos,
"cosh": Math.cosh,
"exp": Math.exp,
"expm1": Math.expm1,
"floor": Math.floor,
//'fround': Math.fround,
'hypot': Math.hypot,
"hypot": Math.hypot,
//'imul': Math.imul,
'lg': Math.log10,
'ln': Math.log,
'log': Math.log,
'log10': Math.log10,
'log1p': Math.log1p,
'log2': Math.log2,
'max': Math.max,
'min': Math.min,
'pow': Math.log2,
'random': Math.random,
'round': Math.round,
'sign': Math.sign,
'sin': Math.sin,
'sinh': Math.sinh,
'sqrt': Math.sqrt,
'tan': Math.tan,
'tanh': Math.tanh,
'trunc': Math.trunc,
"lg": Math.log10,
"ln": Math.log,
"log": Math.log,
"log10": Math.log10,
"log1p": Math.log1p,
"log2": Math.log2,
"max": Math.max,
"min": Math.min,
"pow": Math.log2,
"random": Math.random,
"round": Math.round,
"sign": Math.sign,
"sin": Math.sin,
"sinh": Math.sinh,
"sqrt": Math.sqrt,
"tan": Math.tan,
"tanh": Math.tanh,
"trunc": Math.trunc,
// Functions in expr-eval, ported here.
'fac': Polyfill.factorial,
'gamma': Polyfill.gamma,
'Γ': Polyfill.gamma,
'roundTo': (x, exp) => Number(x).toFixed(exp),
"fac": Polyfill.factorial,
"gamma": Polyfill.gamma,
"Γ": Polyfill.gamma,
"roundTo": (x, exp) => Number(x).toFixed(exp),
// 'map': Polyfill.arrayMap,
// 'fold': Polyfill.arrayFold,
// 'filter': Polyfill.arrayFilter,
// 'indexOf': Polyfill.indexOf,
// 'join': Polyfill.arrayJoin,
// Integral & derivative (only here for autocomplete).
'integral': () => 0, // TODO: Implement
'derivative': () => 0,
"integral": () => 0, // TODO: Implement
"derivative": () => 0
}
export const FUNCTIONS_LIST = Object.keys(FUNCTIONS);
export const FUNCTIONS_LIST = Object.keys(FUNCTIONS)
export class P {
// Parameter class.
constructor(type, name = '', optional = false, multipleAllowed = false) {
constructor(type, name = "", optional = false, multipleAllowed = false) {
this.name = name
this.type = type
this.optional = optional
@ -104,10 +104,10 @@ export class P {
toString() {
let base_string = this.type
if(this.name !== '')
if(this.name !== "")
base_string = `${this.name}: ${base_string}`
if(this.multipleAllowed)
base_string += '...'
base_string += "..."
if(!this.optional)
base_string = `<${base_string}>`
else
@ -116,59 +116,59 @@ export class P {
}
}
export let string = new P('string')
export let bool = new P('bool')
export let number = new P('number')
export let array = new P('array')
export let string = new P("string")
export let bool = new P("bool")
export let number = new P("number")
export let array = new P("array")
export const FUNCTIONS_USAGE = {
'length': [string],
'not': [bool],
"length": [string],
"not": [bool],
// Math functions
'abs': [number],
'acos': [number],
'acosh': [number],
'asin': [number],
'asinh': [number],
'atan': [number],
'atan2': [number],
'atanh': [number],
'cbrt': [number],
'ceil': [number],
"abs": [number],
"acos": [number],
"acosh": [number],
"asin": [number],
"asinh": [number],
"atan": [number],
"atan2": [number],
"atanh": [number],
"cbrt": [number],
"ceil": [number],
//'clz32': [number],
'cos': [number],
'cosh': [number],
'exp': [number],
'expm1': [number],
'floor': [number],
"cos": [number],
"cosh": [number],
"exp": [number],
"expm1": [number],
"floor": [number],
//'fround': [number],
'hypot': [number],
"hypot": [number],
//'imul': [number],
'lg': [number],
'ln': [number],
'log': [number],
'log10': [number],
'log1p': [number],
'log2': [number],
'max': [number, number, new P('numbers', '', true, true)],
'min': [number, number, new P('numbers', '', true, true)],
'pow': [number, new P('number', 'exp')],
'random': [number, number],
'round': [number],
'sign': [number],
'sin': [number],
'sinh': [number],
'sqrt': [number],
'tan': [number],
'tanh': [number],
'trunc': [number],
"lg": [number],
"ln": [number],
"log": [number],
"log10": [number],
"log1p": [number],
"log2": [number],
"max": [number, number, new P("numbers", "", true, true)],
"min": [number, number, new P("numbers", "", true, true)],
"pow": [number, new P("number", "exp")],
"random": [number, number],
"round": [number],
"sign": [number],
"sin": [number],
"sinh": [number],
"sqrt": [number],
"tan": [number],
"tanh": [number],
"trunc": [number],
// Functions in expr-eval, ported here.
'fac': [number],
'gamma': [number],
'Γ': [number],
'roundTo': [number, new P('number')],
"fac": [number],
"gamma": [number],
"Γ": [number],
"roundTo": [number, new P("number")],
// Function manipulation
'derivative': [new P('f'), new P('string', 'var', true), number],
'integral': [new P('from'), new P('to'), new P('f'), new P('string', 'var', true)],
"derivative": [new P("f"), new P("string", "var", true), number],
"integral": [new P("from"), new P("to"), new P("f"), new P("string", "var", true)]
}

View file

@ -20,9 +20,9 @@
import * as Reference from "./reference.mjs"
const WHITESPACES = " \t\n\r"
const STRING_LIMITERS = '"\'`';
const OPERATORS = "+-*/^%?:=!><";
const PUNCTUATION = "()[]{},.";
const STRING_LIMITERS = "\"'`"
const OPERATORS = "+-*/^%?:=!><"
const PUNCTUATION = "()[]{},."
const NUMBER_CHARS = "0123456789"
const IDENTIFIER_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789_₀₁₂₃₄₅₆₇₈₉αβγδεζηθκλμξρςστφχψωₐₑₒₓₔₕₖₗₘₙₚₛₜ"
@ -41,8 +41,8 @@ export const TokenType = {
export class Token {
constructor(type, value, startPosition) {
this.type = type;
this.value = value;
this.type = type
this.value = value
this.startPosition = startPosition
}
}
@ -55,35 +55,35 @@ export class ExpressionTokenizer {
* @param {boolean} errorOnUnknown
*/
constructor(input, tokenizeWhitespaces = false, errorOnUnknown = true) {
this.input = input;
this.currentToken = null;
this.input = input
this.currentToken = null
this.tokenizeWhitespaces = tokenizeWhitespaces
this.errorOnUnknown = errorOnUnknown
}
skipWhitespaces() {
while(!this.input.atEnd() && WHITESPACES.includes(this.input.peek()))
this.input.next();
this.input.next()
}
readWhitespaces() {
let included = "";
let included = ""
while(!this.input.atEnd() && WHITESPACES.includes(this.input.peek())) {
included += this.input.next();
included += this.input.next()
}
return new Token(TokenType.WHITESPACE, included, this.input.position - included.length)
}
readString() {
let delimitation = this.input.peek();
let delimitation = this.input.peek()
if(STRING_LIMITERS.includes(delimitation)) {
this.input.skip(delimitation)
let included = "";
let justEscaped = false;
let included = ""
let justEscaped = false
while(!this.input.atEnd() && (!STRING_LIMITERS.includes(this.input.peek()) || justEscaped)) {
justEscaped = this.input.peek() === "\\"
if(!justEscaped)
included += this.input.next();
included += this.input.next()
}
this.input.skip(delimitation)
let token = new Token(TokenType.STRING, included, this.input.position - included.length)
@ -95,30 +95,30 @@ export class ExpressionTokenizer {
}
readNumber() {
let included = "";
let hasDot = false;
while(!this.input.atEnd() && (NUMBER_CHARS.includes(this.input.peek()) || this.input.peek() === '.')) {
let included = ""
let hasDot = false
while(!this.input.atEnd() && (NUMBER_CHARS.includes(this.input.peek()) || this.input.peek() === ".")) {
if(this.input.peek() === ".") {
if(hasDot) this.input.raise("Unexpected '.'. Expected digit")
hasDot = true;
hasDot = true
}
included += this.input.next();
included += this.input.next()
}
return new Token(TokenType.NUMBER, included, this.input.position - included.length)
}
readOperator() {
let included = "";
let included = ""
while(!this.input.atEnd() && OPERATORS.includes(this.input.peek())) {
included += this.input.next();
included += this.input.next()
}
return new Token(TokenType.OPERATOR, included, this.input.position - included.length)
}
readIdentifier() {
let identifier = "";
let identifier = ""
while(!this.input.atEnd() && IDENTIFIER_CHARS.includes(this.input.peek().toLowerCase())) {
identifier += this.input.next();
identifier += this.input.next()
}
if(Reference.CONSTANTS_LIST.includes(identifier.toLowerCase())) {
return new Token(TokenType.CONSTANT, identifier.toLowerCase(), this.input.position - identifier.length)
@ -132,43 +132,43 @@ export class ExpressionTokenizer {
readNextToken() {
if(!this.tokenizeWhitespaces)
this.skipWhitespaces()
if(this.input.atEnd()) return null;
let c = this.input.peek();
if(this.tokenizeWhitespaces && WHITESPACES.includes(c)) return this.readWhitespaces();
if(STRING_LIMITERS.includes(c)) return this.readString();
if(NUMBER_CHARS.includes(c)) return this.readNumber();
if(IDENTIFIER_CHARS.includes(c.toLowerCase())) return this.readIdentifier();
if(OPERATORS.includes(c)) return this.readOperator();
if(Reference.CONSTANTS_LIST.includes(c)) return new Token(TokenType.CONSTANT, this.input.next(), this.input.position-1);
if(PUNCTUATION.includes(c)) return new Token(TokenType.PUNCT, this.input.next(), this.input.position-1);
if(this.input.atEnd()) return null
let c = this.input.peek()
if(this.tokenizeWhitespaces && WHITESPACES.includes(c)) return this.readWhitespaces()
if(STRING_LIMITERS.includes(c)) return this.readString()
if(NUMBER_CHARS.includes(c)) return this.readNumber()
if(IDENTIFIER_CHARS.includes(c.toLowerCase())) return this.readIdentifier()
if(OPERATORS.includes(c)) return this.readOperator()
if(Reference.CONSTANTS_LIST.includes(c)) return new Token(TokenType.CONSTANT, this.input.next(), this.input.position - 1)
if(PUNCTUATION.includes(c)) return new Token(TokenType.PUNCT, this.input.next(), this.input.position - 1)
if(this.errorOnUnknown)
this.input.raise("Unknown token character " + c)
else
return new Token(TokenType.UNKNOWN, this.input.next(), this.input.position-1);
return new Token(TokenType.UNKNOWN, this.input.next(), this.input.position - 1)
}
peek() {
if(this.currentToken == null) this.currentToken = this.readNextToken();
return this.currentToken;
if(this.currentToken == null) this.currentToken = this.readNextToken()
return this.currentToken
}
next() {
let tmp;
let tmp
if(this.currentToken == null)
tmp = this.readNextToken();
tmp = this.readNextToken()
else
tmp = this.currentToken;
this.currentToken = null;
return tmp;
tmp = this.currentToken
this.currentToken = null
return tmp
}
atEnd() {
return this.peek() == null;
return this.peek() == null
}
skip(type) {
let next = this.next();
let next = this.next()
if(next.type !== type)
this.input.raise("Unexpected token " + next.type.toLowerCase() + ' "' + next.value + '". Expected ' + type.toLowerCase());
this.input.raise("Unexpected token " + next.type.toLowerCase() + " \"" + next.value + "\". Expected " + type.toLowerCase())
}
}

View file

@ -49,7 +49,7 @@ class Setting {
export class BoolSetting extends Setting {
constructor(name, nameInConfig, icon) {
super('bool', name, nameInConfig, icon)
super("bool", name, nameInConfig, icon)
}
value() {
@ -63,9 +63,9 @@ export class BoolSetting extends Setting {
export class NumberSetting extends Setting {
constructor(name, nameInConfig, icon, min = -Infinity, max = +Infinity) {
super('number', name, nameInConfig, icon)
this.min = typeof min == 'number' ? () => min : min
this.max = typeof max == 'number' ? () => max : max
super("number", name, nameInConfig, icon)
this.min = typeof min == "number" ? () => min : min
this.max = typeof max == "number" ? () => max : max
}
value() {
@ -79,7 +79,7 @@ export class NumberSetting extends Setting {
export class EnumIntSetting extends Setting {
constructor(name, nameInConfig, icon, values = []) {
super('enum', name, nameInConfig, icon)
super("enum", name, nameInConfig, icon)
this.values = values
}
@ -94,7 +94,7 @@ export class EnumIntSetting extends Setting {
export class ExpressionSetting extends Setting {
constructor(name, nameInConfig, icon, variables = []) {
super('expression', name, nameInConfig, icon)
super("expression", name, nameInConfig, icon)
this.variables = variables
}
@ -112,17 +112,17 @@ export class ExpressionSetting extends Setting {
Helper.setSetting(this.nameInConfig, value)
else {
let undefinedVars = vars.filter(x => !this.variables.includes(x))
let allowed = ''
let allowed = ""
if(this.variables.length > 0)
allowed = `Allowed variables: ${this.variables.join(', ')}.`
throw new TypeError(`Cannot use variable(s) ${undefinedVars.join(', or ')} to define ${this.displayName}. ${allowed}`)
allowed = `Allowed variables: ${this.variables.join(", ")}.`
throw new TypeError(`Cannot use variable(s) ${undefinedVars.join(", or ")} to define ${this.displayName}. ${allowed}`)
}
}
}
export class StringSetting extends Setting {
constructor(name, nameInConfig, icon, defaultValues = []) {
super('string', name, nameInConfig, icon)
super("string", name, nameInConfig, icon)
this.defaultValues = defaultValues
}

View file

@ -49,13 +49,13 @@ const YMAX = new NumberSetting(
const XAXISSTEP = new ExpressionSetting(
qsTranslate("Settings", "X Axis Step"),
"default_graph.xaxisstep",
"xaxisstep",
"xaxisstep"
)
const YAXISSTEP = new ExpressionSetting(
qsTranslate("Settings", "Y Axis Step"),
"default_graph.yaxisstep",
"yaxisstep",
"yaxisstep"
)
const LINE_WIDTH = new NumberSetting(
@ -72,33 +72,33 @@ const TEXT_SIZE = new NumberSetting(
)
const X_LABEL = new StringSetting(
qsTranslate("Settings", 'X Label'),
qsTranslate("Settings", "X Label"),
"default_graph.xlabel",
"xlabel",
["", "x", "ω (rad/s)"]
)
const Y_LABEL = new StringSetting(
qsTranslate("Settings", 'Y Label'),
qsTranslate("Settings", "Y Label"),
"default_graph.ylabel",
"xlabel",
["", "y", "G (dB)", "φ (°)", "φ (deg)", "φ (rad)"]
)
const LOG_SCALE_X = new BoolSetting(
qsTranslate("Settings", 'X Log scale'),
qsTranslate("Settings", "X Log scale"),
"default_graph.logscalex",
"logscalex"
)
const SHOW_X_GRAD = new BoolSetting(
qsTranslate("Settings", 'Show X graduation'),
qsTranslate("Settings", "Show X graduation"),
"default_graph.showxgrad",
"showxgrad"
)
const SHOW_Y_GRAD = new BoolSetting(
qsTranslate("Settings", 'Show Y graduation'),
qsTranslate("Settings", "Show Y graduation"),
"default_graph.showygrad",
"showygrad"
)

View file

@ -20,26 +20,26 @@ import {BoolSetting, EnumIntSetting} from "./common.mjs"
const AUTOCLOSE_FORMULA = new BoolSetting(
qsTranslate("expression", "Automatically close parenthesises and brackets"),
'expression_editor.autoclose',
'text'
"expression_editor.autoclose",
"text"
)
const ENABLE_SYNTAX_HIGHLIGHTING = new BoolSetting(
qsTranslate("expression", "Enable syntax highlighting"),
'expression_editor.colorize',
'appearance'
"expression_editor.colorize",
"appearance"
)
const ENABLE_AUTOCOMPLETE = new BoolSetting(
qsTranslate("expression", "Enable autocompletion"),
'autocompletion.enabled',
'label'
"autocompletion.enabled",
"label"
)
const PICK_COLOR_SCHEME = new EnumIntSetting(
qsTranslate("expression", "Color Scheme"),
'expression_editor.color_scheme',
'color',
"expression_editor.color_scheme",
"color",
["Breeze Light", "Breeze Dark", "Solarized", "Github Light", "Github Dark", "Nord", "Monokai"]
)

View file

@ -22,19 +22,19 @@ import LatexAPI from "../module/latex.mjs"
const CHECK_FOR_UPDATES = new BoolSetting(
qsTranslate("general", "Check for updates on startup"),
'check_for_updates',
'update'
"check_for_updates",
"update"
)
const RESET_REDO_STACK = new BoolSetting(
qsTranslate("general", "Reset redo stack automaticly"),
'reset_redo_stack',
'timeline'
"reset_redo_stack",
"timeline"
)
class EnableLatex extends BoolSetting {
constructor() {
super(qsTranslate("general","Enable LaTeX rendering"), 'enable_latex', 'Expression')
super(qsTranslate("general", "Enable LaTeX rendering"), "enable_latex", "Expression")
}
set(value) {

View file

@ -16,6 +16,25 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Add string methods
/**
* Replaces latin characters with their uppercase versions.
* @return {string}
*/
String.prototype.toLatinUppercase = String.prototype.toLatinUppercase || function() {
return this.replace(/[a-z]/g, function(match) {
return match.toUpperCase()
})
}
/**
* Removes the 'enclosers' of a string (e.g. quotes, parentheses, brackets...)
* @return {string}
*/
String.prototype.removeEnclosure = function() {
return this.substring(1, this.length - 1)
}
const powerpos = {
"-": "⁻",
"+": "⁺",
@ -350,10 +369,6 @@ export function parseName(str, removeUnallowed = true) {
return str
}
String.prototype.toLatinUppercase = function() {
return this.replace(/[a-z]/g, function(match){return match.toUpperCase()})
}
/**
* Transforms camel case strings to a space separated one.
*

View file

@ -29,7 +29,7 @@ class LOG_COLORS:
GRAY = "\033[90m"
BLUE = "\033[94m"
ORANGE = "\033[38;5;166m"
RED = "\033[e[38;5;204m"
RED = "\033[38;5;204m"
INVERT = "\033[7m"
RESET_INVERT = "\033[27m"
RESET = "\033[0m"

138
package-lock.json generated
View file

@ -13,7 +13,6 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-terser": "^0.4.4",
"install": "^0.13.0",
"rollup": "^4.22.4",
"rollup-plugin-cleanup": "^3.2.1"
@ -1724,16 +1723,6 @@
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/source-map": {
"version": "0.3.6",
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz",
"integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==",
"license": "MIT",
"dependencies": {
"@jridgewell/gen-mapping": "^0.3.5",
"@jridgewell/trace-mapping": "^0.3.25"
}
},
"node_modules/@jridgewell/sourcemap-codec": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz",
@ -1838,28 +1827,6 @@
}
}
},
"node_modules/@rollup/plugin-terser": {
"version": "0.4.4",
"resolved": "https://registry.npmjs.org/@rollup/plugin-terser/-/plugin-terser-0.4.4.tgz",
"integrity": "sha512-XHeJC5Bgvs8LfukDwWZp7yeqin6ns8RTl2B9avbejt6tZqsqvVoWI7ZTQrcNsfKEDWBTnTxM8nMDkO2IFFbd0A==",
"license": "MIT",
"dependencies": {
"serialize-javascript": "^6.0.1",
"smob": "^1.0.0",
"terser": "^5.17.4"
},
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"rollup": "^2.0.0||^3.0.0||^4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
}
},
"node_modules/@rollup/pluginutils": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.2.tgz",
@ -2114,18 +2081,6 @@
"integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==",
"license": "MIT"
},
"node_modules/acorn": {
"version": "8.12.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz",
"integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==",
"license": "MIT",
"bin": {
"acorn": "bin/acorn"
},
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
@ -2209,12 +2164,6 @@
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
}
},
"node_modules/buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"license": "MIT"
},
"node_modules/caniuse-lite": {
"version": "1.0.30001663",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001663.tgz",
@ -2264,12 +2213,6 @@
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"license": "MIT"
},
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"license": "MIT"
},
"node_modules/commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
@ -2602,15 +2545,6 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
"integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==",
"license": "MIT",
"dependencies": {
"safe-buffer": "^5.1.0"
}
},
"node_modules/regenerate": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz",
@ -2770,26 +2704,6 @@
"integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==",
"license": "MIT"
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/semver": {
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
@ -2799,15 +2713,6 @@
"semver": "bin/semver.js"
}
},
"node_modules/serialize-javascript": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz",
"integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==",
"license": "BSD-3-Clause",
"dependencies": {
"randombytes": "^2.1.0"
}
},
"node_modules/skip-regex": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/skip-regex/-/skip-regex-1.0.2.tgz",
@ -2817,31 +2722,6 @@
"node": ">=4.2"
}
},
"node_modules/smob": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/smob/-/smob-1.5.0.tgz",
"integrity": "sha512-g6T+p7QO8npa+/hNx9ohv1E5pVCmWrVCUzUXJyLdMmftX6ER0oiWY/w9knEonLpnOp6b6FenKnMfR8gqwWdwig==",
"license": "MIT"
},
"node_modules/source-map-support": {
"version": "0.5.21",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
"integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
"license": "MIT",
"dependencies": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
}
},
"node_modules/source-map-support/node_modules/source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"license": "BSD-3-Clause",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/sourcemap-codec": {
"version": "1.4.8",
"resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz",
@ -2873,24 +2753,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/terser": {
"version": "5.33.0",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.33.0.tgz",
"integrity": "sha512-JuPVaB7s1gdFKPKTelwUyRq5Sid2A3Gko2S0PncwdBq7kN9Ti9HPWDQ06MPsEDGsZeVESjKEnyGy68quBk1w6g==",
"license": "BSD-2-Clause",
"dependencies": {
"@jridgewell/source-map": "^0.3.3",
"acorn": "^8.8.2",
"commander": "^2.20.0",
"source-map-support": "~0.5.20"
},
"bin": {
"terser": "bin/terser"
},
"engines": {
"node": ">=10"
}
},
"node_modules/to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",

View file

@ -17,7 +17,6 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-terser": "^0.4.4",
"install": "^0.13.0",
"rollup": "^4.22.4",
"rollup-plugin-cleanup": "^3.2.1"

View file

@ -20,7 +20,6 @@ import { nodeResolve } from "@rollup/plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import { babel } from "@rollup/plugin-babel"
import cleanup from "rollup-plugin-cleanup"
import terser from "@rollup/plugin-terser"
const path = "LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js"
@ -39,9 +38,6 @@ export default {
babel({
babelHelpers: "bundled"
}),
// terser({
// ecma: 2015
// })
]
}