Settings for line width and text size

This commit is contained in:
Adsooi 2021-04-01 00:29:05 +02:00
parent 80d5051858
commit 8227d3974e
8 changed files with 287 additions and 46 deletions

View file

@ -42,6 +42,13 @@ parser.functions.integral = function(a, b, f, variable) {
return (b-a)/6*(f(a)+4*f((a+b)/2)+f(b))
}
const DERIVATION_PRECISION = 0.1
parser.functions.derivative = function(f, variable, x) {
f = parser.parse(f).toJSFunction(variable, currentVars)
return (f(x+DERIVATION_PRECISION/2)-f(x-DERIVATION_PRECISION/2))/DERIVATION_PRECISION
}
class Expression {
constructor(expr) {
this.expr = expr

View file

@ -163,7 +163,7 @@ class Point extends DrawableObject {
break;
}
var text = this.getLabel()
ctx.font = "14px sans-serif"
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = ctx.measureText(text).width
switch(this.labelPosition) {
case 'top':
@ -266,8 +266,8 @@ class Function extends ExecutableObject {
Function.drawFunction(canvas, ctx, this.expression, this.definitionDomain, this.destinationDomain, this.drawPoints, this.drawDashedLines)
// Label
var text = this.getLabel()
ctx.font = "14px sans-serif"
var textSize = canvas.measureText(ctx, text, 7)
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = canvas.measureText(ctx, text)
var posX = canvas.x2px(this.labelX)
var posY = canvas.y2px(this.execute(this.labelX))
switch(this.labelPosition) {
@ -439,8 +439,8 @@ class GainBode extends ExecutableObject {
// Label
var text = this.getLabel()
ctx.font = "14px sans-serif"
var textSize = canvas.measureText(ctx, text, 7)
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = canvas.measureText(ctx, text)
var posX = canvas.x2px(this.labelX)
var posY = canvas.y2px(this.execute(this.labelX))
switch(this.labelPosition) {
@ -588,8 +588,8 @@ class SommeGainsBode extends DrawableObject {
if(inDrawDom.includes(this.labelX)) {
// Label
var text = this.getLabel()
ctx.font = "14px sans-serif"
var textSize = canvas.measureText(ctx, text, 7)
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = canvas.measureText(ctx, text)
var posX = canvas.x2px(this.labelX)
var posY = canvas.y2px(dbfn.execute(this.labelX))
switch(this.labelPosition) {
@ -712,8 +712,8 @@ class PhaseBode extends ExecutableObject {
// Label
var text = this.getLabel()
ctx.font = "14px sans-serif"
var textSize = canvas.measureText(ctx, text, 7)
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = canvas.measureText(ctx, text)
var posX = canvas.x2px(this.labelX)
var posY = canvas.y2px(this.execute(this.labelX))
switch(this.labelPosition) {
@ -848,8 +848,8 @@ class SommePhasesBode extends ExecutableObject {
// Label
var text = this.getLabel()
ctx.font = "14px sans-serif"
var textSize = canvas.measureText(ctx, text, 7)
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = canvas.measureText(ctx, text)
var posX = canvas.x2px(this.labelX)
var posY = canvas.y2px(this.execute(this.labelX))
switch(this.labelPosition) {
@ -993,8 +993,8 @@ class CursorX extends DrawableObject {
// Label
var text = this.getLabel()
ctx.font = "14px sans-serif"
var textSize = canvas.measureText(ctx, text, 7)
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = canvas.measureText(ctx, text)
switch(this.labelPosition) {
case 'left':
@ -1007,7 +1007,7 @@ class CursorX extends DrawableObject {
if(this.targetValuePosition == 'Next to target' && this.getTargetElement() != null) {
var text = this.getTargetValueLabel()
var textSize = canvas.measureText(ctx, text, 7)
var textSize = canvas.measureText(ctx, text)
var ypox = canvas.y2px(this.getTargetElement().execute(this.x.execute()))
switch(this.labelPosition) {
case 'left':
@ -1103,8 +1103,8 @@ class Sequence extends ExecutableObject {
// Label
var text = this.getLabel()
ctx.font = "14px sans-serif"
var textSize = canvas.measureText(ctx, text, 7)
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = canvas.measureText(ctx, text)
var posX = canvas.x2px(this.labelX)
var posY = canvas.y2px(this.execute(this.labelX))
switch(this.labelPosition) {
@ -1253,8 +1253,8 @@ class RepartitionFunction extends ExecutableObject {
// Label
var text = this.getLabel()
ctx.font = "14px sans-serif"
var textSize = canvas.measureText(ctx, text, 7)
ctx.font = `${canvas.textsize}px sans-serif`
var textSize = canvas.measureText(ctx, text)
var posX = canvas.x2px(this.labelX)
var posY = canvas.y2px(this.execute(this.labelX))
switch(this.labelPosition) {

View file

@ -252,20 +252,22 @@ function makeExpressionReadable(str) {
[/ \* /g, '×'],
[/ \^ /g, '^'],
[/\^\(([^\^]+)\)/g, function(match, p1) { return textsup(p1) }],
[/\^([^ ]+)/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) }],
[/_([^ "]+)/g, function(match, p1) { return textsub(p1) }],
[/\[([^\[\]]+)\]/g, function(match, p1) { return textsub(p1) }],
[/(\d|\))×/g, '$1'],
//[/×(\d|\()/g, '$1'],
[/\(([^)(+.\/-]+)\)/g, "$1"],
[/integral\((.+), ?(.+), ("|')(.+)("|'), ?("|')(.+)("|')\)/g, function(match, a, b, p1, body, p2, p3, by, p4) {
console.log('Intégrale', a, b, body, by)
[/integral\((.+), ?(.+), ?("|')(.+)("|'), ?("|')(.+)("|')\)/g, function(match, a, b, p1, body, p2, p3, by, p4) {
if(a.length < b.length) {
return `${textsub(a)}${textsup(b)} ${body} d${by}`
} else {
return `${textsup(b)}${textsub(a)} ${body} d${by}`
}
}],
[/derivative\(?("|')(.+)("|'), ?("|')(.+)("|'), ?(.+)\)?/g, function(match, p1, body, p2, p3, by, p4, x) {
return `d(${body.replace(new RegExp(by, 'g'), 'x')})/dx`
}]
]
@ -315,7 +317,7 @@ function parseName(str, removeUnallowed = true) {
[/([^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) }],
// Array elements
[/\[([^\]\[]+)\]/g, function(match, p1) { return textsub(p1) }],
// Removing