Implemented latex for distributions
This commit is contained in:
parent
c4ffcdaa35
commit
de0220fecf
2 changed files with 44 additions and 2 deletions
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
.import "common.js" as Common
|
.import "common.js" as Common
|
||||||
.import "../parameters.js" as P
|
.import "../parameters.js" as P
|
||||||
|
.import "../math/latex.js" as Latex
|
||||||
|
|
||||||
|
|
||||||
class RepartitionFunction extends Common.ExecutableObject {
|
class RepartitionFunction extends Common.ExecutableObject {
|
||||||
static type(){return 'Repartition'}
|
static type(){return 'Repartition'}
|
||||||
|
@ -66,6 +68,12 @@ class RepartitionFunction extends Common.ExecutableObject {
|
||||||
return `F_${this.name}(x) = P(${this.name} ≤ x)\n` + keys.map(idx => `P(${this.name}=${idx})=${this.probabilities[idx]}`).join("; ")
|
return `F_${this.name}(x) = P(${this.name} ≤ x)\n` + keys.map(idx => `P(${this.name}=${idx})=${this.probabilities[idx]}`).join("; ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toLatexString() {
|
||||||
|
let keys = Object.keys(this.probabilities).sort((a,b) => a-b);
|
||||||
|
let varName = Latex.variableToLatex(this.name)
|
||||||
|
return `\\begin{array}{l}F_{${varName}}(x) = P(${varName} \\le x)\\\\` + keys.map(idx => `P(${varName}=${idx})=${this.probabilities[idx]}`).join("; ") + '\\end{array}'
|
||||||
|
}
|
||||||
|
|
||||||
execute(x = 1) {
|
execute(x = 1) {
|
||||||
var ret = 0;
|
var ret = 0;
|
||||||
Object.keys(this.probabilities).sort((a,b) => a-b).forEach(idx => {
|
Object.keys(this.probabilities).sort((a,b) => a-b).forEach(idx => {
|
||||||
|
@ -150,6 +158,40 @@ class RepartitionFunction extends Common.ExecutableObject {
|
||||||
var textSize = canvas.measureText(ctx, text)
|
var textSize = canvas.measureText(ctx, text)
|
||||||
var posX = canvas.x2px(this.labelX)
|
var posX = canvas.x2px(this.labelX)
|
||||||
var posY = canvas.y2px(this.execute(this.labelX))
|
var posY = canvas.y2px(this.execute(this.labelX))
|
||||||
|
|
||||||
|
let drawLabel = function(canvas, ctx, ltxImg) {
|
||||||
|
switch(this.labelPosition) {
|
||||||
|
case 'above':
|
||||||
|
canvas.drawVisibleImage(ctx, ltxImg.source, posX-ltxImg.width/2, posY-(ltxImg.height+10), ltxImg.width, ltxImg.height)
|
||||||
|
break;
|
||||||
|
case 'below':
|
||||||
|
canvas.drawVisibleImage(ctx, ltxImg.source, posX-ltxImg.width/2, posY+10, ltxImg.width, ltxImg.height)
|
||||||
|
break;
|
||||||
|
case 'left':
|
||||||
|
canvas.drawVisibleImage(ctx, ltxImg.source, posX-(ltxImg.width+10), posY-ltxImg.height/2, ltxImg.width, ltxImg.height)
|
||||||
|
break;
|
||||||
|
case 'right':
|
||||||
|
canvas.drawVisibleImage(ctx, ltxImg.source, posX+10, posY-ltxImg.height/2, ltxImg.width, ltxImg.height)
|
||||||
|
break;
|
||||||
|
case 'above-left':
|
||||||
|
canvas.drawVisibleImage(ctx, ltxImg.source, posX-(ltxImg.width+10), posY-(ltxImg.height+10), ltxImg.width, ltxImg.height)
|
||||||
|
break;
|
||||||
|
case 'above-right':
|
||||||
|
canvas.drawVisibleImage(ctx, ltxImg.source, posX+10, posY-(ltxImg.height+10), ltxImg.width, ltxImg.height)
|
||||||
|
break;
|
||||||
|
case 'below-left':
|
||||||
|
canvas.drawVisibleImage(ctx, ltxImg.source, posX-(ltxImg.width+10), posY+10, ltxImg.width, ltxImg.height)
|
||||||
|
break;
|
||||||
|
case 'below-right':
|
||||||
|
canvas.drawVisibleImage(ctx, ltxImg.source, posX+10, posY+10, ltxImg.width, ltxImg.height)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ltxLabel = this.getLatexLabel();
|
||||||
|
console.log(ltxLabel)
|
||||||
|
if(ltxLabel != "")
|
||||||
|
canvas.renderLatexImage(ltxLabel, this.color, drawLabel.bind(this))
|
||||||
|
/*
|
||||||
switch(this.labelPosition) {
|
switch(this.labelPosition) {
|
||||||
case 'above':
|
case 'above':
|
||||||
canvas.drawVisibleText(ctx, text, posX-textSize.width/2, posY-textSize.height)
|
canvas.drawVisibleText(ctx, text, posX-textSize.width/2, posY-textSize.height)
|
||||||
|
@ -175,7 +217,7 @@ class RepartitionFunction extends Common.ExecutableObject {
|
||||||
case 'below-right':
|
case 'below-right':
|
||||||
canvas.drawVisibleText(ctx, text, posX, posY+textSize.height)
|
canvas.drawVisibleText(ctx, text, posX, posY+textSize.height)
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
LPFv1{"xzoom":100,"yzoom":485,"xmin":-1,"ymax":1,"xaxisstep":"1","yaxisstep":"0.1","xaxislabel":"ω (rad/s)","yaxislabel":"G (dB)","logscalex":false,"linewidth":2,"showxgrad":true,"showygrad":true,"textsize":22,"history":[[["EditedProperty",["h","Function","labelX",3,2.5,false]],["EditedProperty",["h","Function","labelPosition","above-left","above",false]],["EditedProperty",["h","Function","labelPosition","above","left",false]],["EditedProperty",["h","Function","labelX",2.5,2,false]],["EditedProperty",["h","Function","labelX",2,2.2,false]],["EditedProperty",["h","Function","labelX",2.2,9,false]],["EditedProperty",["f","Function","labelPosition","left","above-left",false]],["EditedProperty",["f","Function","labelX",7,7.4,false]],["EditedProperty",["A","Point","y","(-0.5)","(-0.6)",true]]],[["EditedProperty",["A","Point","labelPosition","top","above",false]]]],"width":1908,"height":1005,"objects":{"Sequence":[["u",true,"#ff5500","name + value",true,true,{"1":"cos(u[n])"},{"0":"-1"},"above-left",8]],"Function":[["f",true,"#2b156d","name + value","integral((x + 1), x, \"cos (t)\", \"t\")","ℝ⁺*","ℝ","application","above-left",7.4,true,true],["g",true,"#ac539c","null","0.739083","ℝ","ℝ","application","below",-1,true,false],["h",true,"#00aa00","name + value","derivative(\"cos t\", \"t\", x)","ℤ","ℝ","application","left",9,true,true]],"Repartition":[["X",true,"#1E1EAF","name",true,true,{"0":"0.2","1":"0.1","2":"0.2"},"above",2.5]],"Point":[["A",true,"#060759","name + value","4","(-0.6)","top","●"]]},"type":"logplotv1"}
|
LPFv1{"xzoom":100,"yzoom":485,"xmin":-1,"ymax":1,"xaxisstep":"1","yaxisstep":"0.1","xaxislabel":"ω (rad/s)","yaxislabel":"G (dB)","logscalex":false,"linewidth":2,"showxgrad":true,"showygrad":true,"textsize":22,"history":[[["EditedProperty",["h","Function","labelX",3,2.5,false]],["EditedProperty",["h","Function","labelPosition","above-left","above",false]],["EditedProperty",["h","Function","labelPosition","above","left",false]],["EditedProperty",["h","Function","labelX",2.5,2,false]],["EditedProperty",["h","Function","labelX",2,2.2,false]],["EditedProperty",["h","Function","labelX",2.2,9,false]],["EditedProperty",["f","Function","labelPosition","left","above-left",false]],["EditedProperty",["f","Function","labelX",7,7.4,false]],["EditedProperty",["A","Point","y","(-0.5)","(-0.6)",true]],["EditedProperty",["X","Repartition","labelX",2.5,5,false]],["EditedProperty",["u","Sequence","labelPosition","above-left","below-right",false]],["EditedProperty",["u","Sequence","labelPosition","below-right","below-left",false]],["EditedProperty",["u","Sequence","labelX",8,6,false]],["EditedProperty",["u","Sequence","baseValues",{"0":"-1"},{"0":"-1"},false]],["EditedProperty",["u","Sequence","labelX",6,7,false]],["EditedProperty",["u","Sequence","labelPosition","below-left","above-right",false]]],[]],"width":1908,"height":1005,"objects":{"Sequence":[["u",true,"#ff5500","name + value",true,true,{"1":"cos(u[n])"},{"0":"-1"},"above-right",7]],"Function":[["f",true,"#2b156d","name + value","integral((x + 1), x, \"cos (t)\", \"t\")","ℝ⁺*","ℝ","application","above-left",7.4,true,true],["g",true,"#ac539c","null","0.739083","ℝ","ℝ","application","below",-1,true,false],["h",true,"#00aa00","name + value","derivative(\"cos t\", \"t\", x)","ℤ","ℝ","application","left",9,true,true]],"Repartition":[["X",true,"#1E1EAF","name + value",true,true,{"0":"0.2","1":"0.1","2":"0.2"},"above",5]],"Point":[["A",true,"#060759","name + value","4","(-0.6)","top","●"]]},"type":"logplotv1"}
|
Loading…
Reference in a new issue