From 7f548796f2cb4d3ccf6e23fb995ffe5baed923e3 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Thu, 20 Oct 2022 01:25:55 +0200 Subject: [PATCH] Slight change for Repartition for the name to be prefixed by F_ on creation. This makes it better when using it in tooltips for autocompletion. --- .../ObjectLists/Editor/CustomPropertyList.qml | 4 ++-- .../LogarithmPlotter/js/objs/repartition.js | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml index aa26594..18da95f 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml @@ -231,8 +231,8 @@ Repeater { dictionaryMode: paramTypeIn(propertyType, ['Dict']) keyType: dictionaryMode ? propertyType.keyType : 'string' valueType: propertyType.valueType - preKeyLabel: (dictionaryMode ? propertyType.preKeyLabel : propertyType.label).replace(/\{name\}/g, obj.name) - postKeyLabel: (dictionaryMode ? propertyType.postKeyLabel : '').replace(/\{name\}/g, obj.name) + preKeyLabel: (dictionaryMode ? propertyType.preKeyLabel : propertyType.label).replace(/\{name\}/g, obj.name).replace(/\{name_\}/g, obj.name.substring(obj.name.indexOf("_")+1)) + postKeyLabel: (dictionaryMode ? propertyType.postKeyLabel : '').replace(/\{name\}/g, obj.name).replace(/\{name_\}/g, obj.name.substring(obj.name.indexOf("_")+1)) keyRegexp: dictionaryMode ? propertyType.keyFormat : /^.+$/ valueRegexp: propertyType.format forbidAdding: propertyType.forbidAdding diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/repartition.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/repartition.js index 0f25c4c..dc20a73 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/repartition.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/repartition.js @@ -34,12 +34,12 @@ class RepartitionFunction extends Common.ExecutableObject { 'comment', 'Note: Specify the probability for each value.' ), - [QT_TRANSLATE_NOOP('prop','probabilities')]: new P.Dictionary('string', 'float', /^-?[\d.,]+$/, /^-?[\d\.,]+$/, 'P({name} = ', ') = '), + [QT_TRANSLATE_NOOP('prop','probabilities')]: new P.Dictionary('string', 'float', /^-?[\d.,]+$/, /^-?[\d\.,]+$/, 'P({name_} = ', ') = '), }} constructor(name = null, visible = true, color = null, labelContent = 'name + value', beginIncluded = true, drawLineEnds = true, probabilities = {'0': '0'}, labelPosition = 'above', labelX = 1) { - if(name == null) name = Common.getNewName('XYZUVW') + if(name == null) name = Common.getNewName('XYZUVW', "F_") super(name, visible, color, labelContent) this.beginIncluded = beginIncluded this.drawLineEnds = drawLineEnds @@ -56,14 +56,16 @@ class RepartitionFunction extends Common.ExecutableObject { getReadableString() { - var keys = Object.keys(this.probabilities).sort((a,b) => a-b); - return `F_${this.name}(x) = P(${this.name} ≤ x)\n` + keys.map(idx => `P(${this.name}=${idx})=${this.probabilities[idx]}`).join("; ") + 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 varName = Latex.variable(this.name) - return `\\begin{array}{l}F_{${varName}}(x) = P(${varName} \\le x)\\\\` + keys.map(idx => `P(${varName}=${idx})=${this.probabilities[idx]}`).join("; ") + '\\end{array}' + 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}' } execute(x = 1) { @@ -83,7 +85,7 @@ class RepartitionFunction extends Common.ExecutableObject { getLabel() { switch(this.labelContent) { case 'name': - return `P(${this.name} ≤ x)` + return `${this.name}(x)` case 'name + value': return this.getReadableString() case 'null':