Fixing the (previously very broken) text renderer when using symbols.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
cf754a7a34
commit
038dd9f4a8
3 changed files with 8 additions and 7 deletions
|
@ -301,7 +301,7 @@ Canvas {
|
||||||
} else {
|
} else {
|
||||||
for(var x = 1; x < drawMaxX; x += 1) {
|
for(var x = 1; x < drawMaxX; x += 1) {
|
||||||
var drawX = x*xaxisstep1
|
var drawX = x*xaxisstep1
|
||||||
var txtX = xaxisstepExpr.simplify(x)
|
var txtX = xaxisstepExpr.simplify(x).replace(/^\((.+)\)$/, '$1')
|
||||||
var textSize = measureText(ctx, txtX, 6).height
|
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)
|
||||||
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) {
|
if(showygrad) {
|
||||||
for(var y = 0; y < drawMaxY; y += 1) {
|
for(var y = 0; y < drawMaxY; y += 1) {
|
||||||
var drawY = y*yaxisstep1
|
var drawY = y*yaxisstep1
|
||||||
var txtY = yaxisstepExpr.simplify(y)
|
var txtY = yaxisstepExpr.simplify(y).replace(/^\((.+)\)$/, '$1')
|
||||||
var textSize = ctx.measureText(txtY).width
|
var textSize = ctx.measureText(txtY).width
|
||||||
drawVisibleText(ctx, txtY, axisypx-6-textSize, y2px(drawY)+4+(10*(y==0)))
|
drawVisibleText(ctx, txtY, axisypx-6-textSize, y2px(drawY)+4+(10*(y==0)))
|
||||||
if(y != 0)
|
if(y != 0)
|
||||||
|
|
|
@ -68,6 +68,7 @@ class Expression {
|
||||||
|
|
||||||
simplify(x) {
|
simplify(x) {
|
||||||
var expr = this.calc.substitute('x', x).simplify()
|
var expr = this.calc.substitute('x', x).simplify()
|
||||||
|
print(this.expr, this.calc.substitute('x', x), expr)
|
||||||
if(expr.evaluate() == 0) return '0'
|
if(expr.evaluate() == 0) return '0'
|
||||||
var str = Utils.makeExpressionReadable(expr.toString());
|
var str = Utils.makeExpressionReadable(expr.toString());
|
||||||
if(str != undefined && str.match(/^\d*\.\d+$/)) {
|
if(str != undefined && str.match(/^\d*\.\d+$/)) {
|
||||||
|
|
|
@ -256,14 +256,14 @@ function makeExpressionReadable(str) {
|
||||||
// Other
|
// Other
|
||||||
[/ \* /g, '×'],
|
[/ \* /g, '×'],
|
||||||
[/ \^ /g, '^'],
|
[/ \^ /g, '^'],
|
||||||
[/\^\(([^\^]+)\)/g, function(match, p1) { return textsup(p1) }],
|
[/\^\(([\d\w+-]+)\)/g, function(match, p1) { return textsup(p1) }],
|
||||||
[/\^([^ "]+)/g, function(match, p1) { return textsup(p1) }],
|
[/\^([\d\w+-]+)/g, function(match, p1) { return textsup(p1) }],
|
||||||
[/_\(([^_]+)\)/g, function(match, p1) { return textsub(p1) }],
|
[/_\(([\d\w+-]+)\)/g, function(match, p1) { return textsub(p1) }],
|
||||||
[/_([^ "]+)/g, function(match, p1) { return textsub(p1) }],
|
[/_([\d\w+-]+)/g, function(match, p1) { return textsub(p1) }],
|
||||||
[/\[([^\[\]]+)\]/g, function(match, p1) { return textsub(p1) }],
|
[/\[([^\[\]]+)\]/g, function(match, p1) { return textsub(p1) }],
|
||||||
[/(\d|\))×/g, '$1'],
|
[/(\d|\))×/g, '$1'],
|
||||||
//[/×(\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) {
|
[/integral\((.+),\s?(.+),\s?("|')(.+)("|'),\s?("|')(.+)("|')\)/g, function(match, a, b, p1, body, p2, p3, by, p4) {
|
||||||
if(a.length < b.length) {
|
if(a.length < b.length) {
|
||||||
return `∫${textsub(a)}${textsup(b)} ${body} d${by}`
|
return `∫${textsub(a)}${textsup(b)} ${body} d${by}`
|
||||||
|
|
Loading…
Reference in a new issue