Fixing several issues with repartition

+ Underscores being automatically removed from the name the moment it's edited.
+ Fixing issue with function name change.
This commit is contained in:
Adsooi 2023-05-24 03:17:21 +02:00
parent d6dee6a2be
commit 5cef8e23fa
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
4 changed files with 11 additions and 9 deletions

View file

@ -106,6 +106,7 @@ Popup.BaseDialog {
value: objEditor.obj.name
onChanged: function(newValue) {
let newName = Utils.parseName(newValue)
console.log(newValue, newName)
if(newName != '' && objEditor.obj.name != newName) {
if(newName in Objects.currentObjectsByName) {
invalidNameDialog.showDialog(newName)

View file

@ -119,12 +119,13 @@ Item {
focus: true
text: control.defValue
selectByMouse: true
onEditingFinished: {
onEditingFinished: function() {
if(insertButton.focus || insertPopup.focus) return
var value = text
if(control.isInt) value = Math.max(control.min,parseInt(value).toString()=="NaN"?control.min:parseInt(value))
if(control.isDouble) value = Math.max(control.min,parseFloat(value).toString()=="NaN"?control.min:parseFloat(value))
if(value != "" && value.toString() != defValue) {
console.log(value, value.toString())
control.changed(value)
defValue = value.toString()
}

View file

@ -96,14 +96,14 @@ class RepartitionFunction extends Common.ExecutableObject {
draw(canvas, ctx) {
var currentY = 0;
var keys = Object.keys(this.probabilities).map(idx => parseInt(idx)).sort((a,b) => a-b)
if(canvas.visible(keys[0],this.probabilities[keys[0]].replace(/,/g, '.'))) {
if(canvas.isVisible(keys[0],this.probabilities[keys[0]].replace(/,/g, '.'))) {
canvas.drawLine(ctx,
0,
canvas.y2px(0),
canvas.x2px(keys[0]),
canvas.y2px(0)
)
if(canvas.visible(keys[0],0)) {
if(canvas.isVisible(keys[0],0)) {
ctx.beginPath();
ctx.arc(canvas.x2px(keys[0])+4,canvas.y2px(0), 4, Math.PI / 2, 3 * Math.PI / 2);
ctx.stroke();
@ -112,26 +112,26 @@ class RepartitionFunction extends Common.ExecutableObject {
for(var i = 0; i < keys.length-1; i++) {
var idx = keys[i];
currentY += parseFloat(this.probabilities[idx].replace(/,/g, '.'));
if(canvas.visible(idx,currentY) || canvas.visible(keys[i+1],currentY)) {
if(canvas.isVisible(idx,currentY) || canvas.isVisible(keys[i+1],currentY)) {
canvas.drawLine(ctx,
Math.max(0,canvas.x2px(idx)),
canvas.y2px(currentY),
Math.min(canvas.canvasSize.width,canvas.x2px(keys[i+1])),
canvas.y2px(currentY)
)
if(canvas.visible(idx,currentY)) {
if(canvas.isVisible(idx,currentY)) {
ctx.beginPath();
ctx.arc(canvas.x2px(idx),canvas.y2px(currentY), 4, 0, 2 * Math.PI);
ctx.fill();
}
if(canvas.visible(keys[i+1],currentY)) {
if(canvas.isVisible(keys[i+1],currentY)) {
ctx.beginPath();
ctx.arc(canvas.x2px(keys[i+1])+4,canvas.y2px(currentY), 4, Math.PI / 2, 3 * Math.PI / 2);
ctx.stroke();
}
}
}
if(canvas.visible(keys[keys.length-1],currentY+parseFloat(this.probabilities[keys[keys.length-1]]))) {
if(canvas.isVisible(keys[keys.length-1],currentY+parseFloat(this.probabilities[keys[keys.length-1]]))) {
canvas.drawLine(ctx,
Math.max(0,canvas.x2px(keys[keys.length-1])),
canvas.y2px(currentY+parseFloat(this.probabilities[keys[keys.length-1]].replace(/,/g, '.'))),

View file

@ -316,8 +316,8 @@ function parseName(str, removeUnallowed = true) {
[/([^a-z]|^)gps(i)?([^a-z]|$)/g, '$1Ψ$3'],
[/([^a-z]|^)gom(ega)?([^a-z]|$)/g, '$1Ω$3'],
// Underscores
[/_\(([^_]+)\)/g, function(match, p1) { return textsub(p1) }],
[/_([^" ]+)/g, function(match, p1) { return textsub(p1) }],
// [/_\(([^_]+)\)/g, function(match, p1) { return textsub(p1) }],
// [/_([^" ]+)/g, function(match, p1) { return textsub(p1) }],
// Array elements
[/\[([^\]\[]+)\]/g, function(match, p1) { return textsub(p1) }],
// Removing