Labels for sequences
This commit is contained in:
parent
1cd3746109
commit
2fa6d71a27
3 changed files with 53 additions and 5 deletions
|
@ -29,7 +29,7 @@ ApplicationWindow {
|
||||||
width: 1000
|
width: 1000
|
||||||
height: 500
|
height: 500
|
||||||
color: sysPalette.window
|
color: sysPalette.window
|
||||||
title: "Logarithmic Plotter " + (settings.saveFilename != "" ? " - " + settings.saveFilename : "")
|
title: "Logarithmic Plotter " + (settings.saveFilename != "" ? " - " + settings.saveFilename.split('/')[0] : "")
|
||||||
|
|
||||||
SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active }
|
SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active }
|
||||||
SystemPalette { id: sysPaletteIn; colorGroup: SystemPalette.Disabled }
|
SystemPalette { id: sysPaletteIn; colorGroup: SystemPalette.Disabled }
|
||||||
|
|
|
@ -113,7 +113,6 @@ class Sequence extends Expression {
|
||||||
var expr = parser.parse(str).simplify()
|
var expr = parser.parse(str).simplify()
|
||||||
var l = {}
|
var l = {}
|
||||||
l[this.name] = this.calcValues
|
l[this.name] = this.calcValues
|
||||||
console.log(JSON.stringify(l), expr)
|
|
||||||
this.calcValues[n] = expr.evaluate(Object.assign(l, evalVariables))
|
this.calcValues[n] = expr.evaluate(Object.assign(l, evalVariables))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1030,23 +1030,27 @@ class Sequence extends ExecutableObject {
|
||||||
'defaultExpression': new P.Dictionary('string', 'int', /^.+$/, /^\d+$/, '{name}[n+', '] = ', true),
|
'defaultExpression': new P.Dictionary('string', 'int', /^.+$/, /^\d+$/, '{name}[n+', '] = ', true),
|
||||||
'comment1': 'Note: Use {name}[n] to refer to {name}ₙ, {name}[n+1] for {name}ₙ₊₁...',
|
'comment1': 'Note: Use {name}[n] to refer to {name}ₙ, {name}[n+1] for {name}ₙ₊₁...',
|
||||||
'baseValues': new P.Dictionary('string', 'int', /^.+$/, /^\d+$/, '{name}[', '] = '),
|
'baseValues': new P.Dictionary('string', 'int', /^.+$/, /^\d+$/, '{name}[', '] = '),
|
||||||
|
'labelPosition': new P.Enum('above', 'below', 'left', 'right', 'above-left', 'above-right', 'below-left', 'below-right'),
|
||||||
|
'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"},
|
drawPoints = true, drawDashedLines = true, defaultExp = {1: "n"},
|
||||||
baseValues = {0: 0}) {
|
baseValues = {0: 0}, labelPosition = 'above', labelX = 1) {
|
||||||
if(name == null) name = getNewName('uvwPSUVWabcde')
|
if(name == null) name = getNewName('uvwPSUVWabcde')
|
||||||
super(name, visible, color, labelContent)
|
super(name, visible, color, labelContent)
|
||||||
this.drawPoints = drawPoints
|
this.drawPoints = drawPoints
|
||||||
this.drawDashedLines = drawDashedLines
|
this.drawDashedLines = drawDashedLines
|
||||||
this.defaultExpression = defaultExp
|
this.defaultExpression = defaultExp
|
||||||
this.baseValues = baseValues
|
this.baseValues = baseValues
|
||||||
|
this.labelPosition = labelPosition
|
||||||
|
this.labelX = labelX
|
||||||
this.update()
|
this.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
export() {
|
export() {
|
||||||
return [this.name, this.visible, this.color.toString(), this.labelContent,
|
return [this.name, this.visible, this.color.toString(), this.labelContent,
|
||||||
this.drawPoints, this.drawDashedLines, this.defaultExpression, this.baseValues]
|
this.drawPoints, this.drawDashedLines, this.defaultExpression, this.baseValues, this.labelPosition, this.labelX]
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
|
@ -1082,8 +1086,53 @@ class Sequence extends ExecutableObject {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLabel() {
|
||||||
|
switch(this.labelContent) {
|
||||||
|
case 'name':
|
||||||
|
return `(${this.name}ₙ)`
|
||||||
|
case 'name + value':
|
||||||
|
return this.getReadableString()
|
||||||
|
case 'null':
|
||||||
|
return ''
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
draw(canvas, ctx) {
|
draw(canvas, ctx) {
|
||||||
Function.drawFunction(canvas, ctx, this.sequence, canvas.logscalex ? MathLib.Domain.NE : MathLib.Domain.N, MathLib.Domain.R, this.drawPoints, this.drawDashedLines)
|
Function.drawFunction(canvas, ctx, this.sequence, canvas.logscalex ? MathLib.Domain.NE : MathLib.Domain.N, MathLib.Domain.R, this.drawPoints, this.drawDashedLines)
|
||||||
|
|
||||||
|
// Label
|
||||||
|
var text = this.getLabel()
|
||||||
|
ctx.font = "14px sans-serif"
|
||||||
|
var textSize = canvas.measureText(ctx, text, 7)
|
||||||
|
var posX = canvas.x2px(this.labelX)
|
||||||
|
var posY = canvas.y2px(this.execute(this.labelX))
|
||||||
|
switch(this.labelPosition) {
|
||||||
|
case 'above':
|
||||||
|
canvas.drawVisibleText(ctx, text, posX-textSize.width/2, posY-textSize.height)
|
||||||
|
break;
|
||||||
|
case 'below':
|
||||||
|
canvas.drawVisibleText(ctx, text, posX-textSize.width/2, posY+textSize.height)
|
||||||
|
break;
|
||||||
|
case 'left':
|
||||||
|
canvas.drawVisibleText(ctx, text, posX-textSize.width, posY-textSize.height/2)
|
||||||
|
break;
|
||||||
|
case 'right':
|
||||||
|
canvas.drawVisibleText(ctx, text, posX, posY-textSize.height/2)
|
||||||
|
break;
|
||||||
|
case 'above-left':
|
||||||
|
canvas.drawVisibleText(ctx, text, posX-textSize.width, posY-textSize.height)
|
||||||
|
break;
|
||||||
|
case 'above-right':
|
||||||
|
canvas.drawVisibleText(ctx, text, posX, posY-textSize.height)
|
||||||
|
break;
|
||||||
|
case 'below-left':
|
||||||
|
canvas.drawVisibleText(ctx, text, posX-textSize.width, posY+textSize.height)
|
||||||
|
break;
|
||||||
|
case 'below-right':
|
||||||
|
canvas.drawVisibleText(ctx, text, posX, posY+textSize.height)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue