Slight change for Repartition for the name to be prefixed by F_ on creation.
All checks were successful
continuous-integration/drone/push Build is passing

This makes it better when using it in tooltips for autocompletion.
This commit is contained in:
Adsooi 2022-10-20 01:25:55 +02:00
parent 15b87fc15d
commit 7f548796f2
Signed by: Ad5001
GPG key ID: 7251B1AF90B960F9
2 changed files with 11 additions and 9 deletions

View file

@ -231,8 +231,8 @@ Repeater {
dictionaryMode: paramTypeIn(propertyType, ['Dict']) dictionaryMode: paramTypeIn(propertyType, ['Dict'])
keyType: dictionaryMode ? propertyType.keyType : 'string' keyType: dictionaryMode ? propertyType.keyType : 'string'
valueType: propertyType.valueType valueType: propertyType.valueType
preKeyLabel: (dictionaryMode ? propertyType.preKeyLabel : propertyType.label).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) postKeyLabel: (dictionaryMode ? propertyType.postKeyLabel : '').replace(/\{name\}/g, obj.name).replace(/\{name_\}/g, obj.name.substring(obj.name.indexOf("_")+1))
keyRegexp: dictionaryMode ? propertyType.keyFormat : /^.+$/ keyRegexp: dictionaryMode ? propertyType.keyFormat : /^.+$/
valueRegexp: propertyType.format valueRegexp: propertyType.format
forbidAdding: propertyType.forbidAdding forbidAdding: propertyType.forbidAdding

View file

@ -34,12 +34,12 @@ class RepartitionFunction extends Common.ExecutableObject {
'comment', 'comment',
'Note: Specify the probability for each value.' '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', constructor(name = null, visible = true, color = null, labelContent = 'name + value',
beginIncluded = true, drawLineEnds = true, probabilities = {'0': '0'}, labelPosition = 'above', labelX = 1) { 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) super(name, visible, color, labelContent)
this.beginIncluded = beginIncluded this.beginIncluded = beginIncluded
this.drawLineEnds = drawLineEnds this.drawLineEnds = drawLineEnds
@ -56,14 +56,16 @@ class RepartitionFunction extends Common.ExecutableObject {
getReadableString() { getReadableString() {
var keys = Object.keys(this.probabilities).sort((a,b) => a-b); let 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 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() { getLatexString() {
let keys = Object.keys(this.probabilities).sort((a,b) => a-b); let keys = Object.keys(this.probabilities).sort((a,b) => a-b);
let varName = Latex.variable(this.name) let funcName = 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 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) { execute(x = 1) {
@ -83,7 +85,7 @@ class RepartitionFunction extends Common.ExecutableObject {
getLabel() { getLabel() {
switch(this.labelContent) { switch(this.labelContent) {
case 'name': case 'name':
return `P(${this.name}x)` return `${this.name}(x)`
case 'name + value': case 'name + value':
return this.getReadableString() return this.getReadableString()
case 'null': case 'null':