From a7a8b397f9d972f7844883852763bc378d64781e Mon Sep 17 00:00:00 2001 From: Jonas de Luna Skulberg Date: Tue, 11 Jul 2023 10:49:33 +0200 Subject: [PATCH] Support for custom font on latex component --- index.html | 9 +++++++++ src/Components/Latex.ts | 1 - src/index.ts | 33 +++------------------------------ 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/index.html b/index.html index cb4b20f..2d359f6 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,11 @@ Graphica Demo diff --git a/src/Components/Latex.ts b/src/Components/Latex.ts index 3026611..ebbf926 100644 --- a/src/Components/Latex.ts +++ b/src/Components/Latex.ts @@ -46,7 +46,6 @@ class Latex extends Component { this.position.set(pos.x, pos.y, 1); container.scale.set(fontSize, fontSize, 1); container.element.style.color = color; - container.element.style.fontFamily = "sans-serif"; container.element.style.fontSize = `${fontSize}px`; container.element.style.fontWeight = "normal"; container.element.style.textAlign = anchorX; diff --git a/src/index.ts b/src/index.ts index 835b347..3d0620d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,42 +11,15 @@ const graphica = new Graphica(document.body); const grid = new Grid(); - const p = new Plot("cos(x)* sin(x) + sin(x)"); const s = new Slider({ maxValue: 99, minValue: 1 }); -let a = new Component(); - -const l = new Latex( - " \\sum_{i=1}^{n} [\\sin(x_i)\\cdot\\cos(x_i)+\\sin(x_i)] \\Delta x", - { - position: [5, 5], - fontSize: 30 - } -); -s.addObserver((v) => { - graphica.remove(a); - a = new Component(); - const range = 20; - const stepSize = range / v; - for (let i = 0; i < range; i += stepSize) { - a.add( - new Polygon( - [ - new Vector2(i, 0), - new Vector2(i + stepSize, 0), - new Vector2(i + stepSize, Math.sin(i) * Math.cos(i) + Math.sin(i)), - new Vector2(i, Math.sin(i) * Math.cos(i) + Math.sin(i)), - ], - { fill: false } - ) - ); - } - graphica.add(a); +const l = new Latex(" hei test", { + position: [5, 5], + fontSize: 30, }); graphica.add(l); -graphica.addGui(s); graphica.add(p); graphica.add(grid); graphica.run();