Fixing the (previously very broken) text renderer when using symbols.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Adsooi 2023-10-09 18:50:34 +02:00
parent cf754a7a34
commit 038dd9f4a8
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
3 changed files with 8 additions and 7 deletions

View file

@ -301,7 +301,7 @@ Canvas {
} else {
for(var x = 1; x < drawMaxX; x += 1) {
var drawX = x*xaxisstep1
var txtX = xaxisstepExpr.simplify(x)
var txtX = xaxisstepExpr.simplify(x).replace(/^\((.+)\)$/, '$1')
var textSize = measureText(ctx, txtX, 6).height
drawVisibleText(ctx, txtX, x2px(drawX)-4, axisxpx+textsize/2+textSize)
drawVisibleText(ctx, '-'+txtX, x2px(-drawX)-4, axisxpx+textsize/2+textSize)
@ -311,7 +311,7 @@ Canvas {
if(showygrad) {
for(var y = 0; y < drawMaxY; y += 1) {
var drawY = y*yaxisstep1
var txtY = yaxisstepExpr.simplify(y)
var txtY = yaxisstepExpr.simplify(y).replace(/^\((.+)\)$/, '$1')
var textSize = ctx.measureText(txtY).width
drawVisibleText(ctx, txtY, axisypx-6-textSize, y2px(drawY)+4+(10*(y==0)))
if(y != 0)

View file

@ -68,6 +68,7 @@ class Expression {
simplify(x) {
var expr = this.calc.substitute('x', x).simplify()
print(this.expr, this.calc.substitute('x', x), expr)
if(expr.evaluate() == 0) return '0'
var str = Utils.makeExpressionReadable(expr.toString());
if(str != undefined && str.match(/^\d*\.\d+$/)) {

View file

@ -256,14 +256,14 @@ function makeExpressionReadable(str) {
// Other
[/ \* /g, '×'],
[/ \^ /g, '^'],
[/\^\(([^\^]+)\)/g, function(match, p1) { return textsup(p1) }],
[/\^([^ "]+)/g, function(match, p1) { return textsup(p1) }],
[/_\(([^_]+)\)/g, function(match, p1) { return textsub(p1) }],
[/_([^ "]+)/g, function(match, p1) { return textsub(p1) }],
[/\^\(([\d\w+-]+)\)/g, function(match, p1) { return textsup(p1) }],
[/\^([\d\w+-]+)/g, function(match, p1) { return textsup(p1) }],
[/_\(([\d\w+-]+)\)/g, function(match, p1) { return textsub(p1) }],
[/_([\d\w+-]+)/g, function(match, p1) { return textsub(p1) }],
[/\[([^\[\]]+)\]/g, function(match, p1) { return textsub(p1) }],
[/(\d|\))×/g, '$1'],
//[/×(\d|\()/g, '$1'],
[/[^a-z]\(([^)(+.\/-]+)\)/g, "$1"],
[/([^a-z])\(([^)(+.\/-]+)\)/g, "$1×$2"],
[/integral\((.+),\s?(.+),\s?("|')(.+)("|'),\s?("|')(.+)("|')\)/g, function(match, a, b, p1, body, p2, p3, by, p4) {
if(a.length < b.length) {
return `${textsub(a)}${textsup(b)} ${body} d${by}`