Skip to content

Commit c4f3d68

Browse files
author
Bryan Parker
committed
Adds docs
1 parent e12ffd3 commit c4f3d68

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/shapes/primitives/text.ts

+9
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,19 @@ class Text implements Shape {
283283
return [this._x, this._y];
284284
}
285285

286+
/**
287+
* Returns a boolean indicating whether the text is in TeX format
288+
* @returns true if the text is in TeX format, false otherwise
289+
*/
286290
isTex(): boolean {
287291
return this._tex;
288292
}
289293

294+
/**
295+
* Updates the text contents of the Text object
296+
* @param text the new text
297+
* @returns this (for chaining)
298+
*/
290299
changeText(text: string): this {
291300
this._text = text;
292301

test/script_test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ class TestScene extends Scene {
457457
const secant = new Line({ from: p, to: q, length: 6, lineColor: Colors.blue() });
458458
const tangent = new TangentLine({ plot, x: 0.5, length: 4, color: Colors.pink() });
459459
const tangentText = new Tex(`m`).changeColor(Colors.pink()).nextTo(tangent.to());
460-
const secantText = new Tex(`m_{\sec}`).nextTo(secant.to()).changeColor(Colors.blue());
460+
const secantText = new Tex(`m_{\sec} = `).nextTo(secant.to()).changeColor(Colors.blue());
461+
const secantSlope = new Text('').changeColor(Colors.blue()).nextTo(secantText, RIGHT());
461462
// const secantText = new Text(`m_{\\sec}`).nextTo(secant.to()).changeColor(Colors.blue());
462463

463464
this.add(
@@ -471,8 +472,10 @@ class TestScene extends Scene {
471472
pText, qText,
472473
tangentText,
473474
secantText,
475+
secantSlope,
474476
);
475477

478+
// Need to throttle how quickly tex is updated since an image is being generated and rendered
476479
const updateText = utils.throttle(text => secantText.changeText(text), 200);
477480

478481
this.add(new Updater((pctComplete: number, starting: boolean) => {
@@ -486,7 +489,8 @@ class TestScene extends Scene {
486489
secantText.nextTo(secant.to()) //.changeText(`m_{\\sec} = ${m.toFixed(2)}`);
487490

488491
// console.log(m, pctComplete)
489-
updateText(`m_{\\sec} = ${m.toFixed(2)}`);
492+
// updateText(`m_{\\sec} = ${m.toFixed(2)}`);
493+
secantSlope.nextTo(secantText, RIGHT()).changeText(`${m.toFixed(2)}`);
490494

491495
}, { duration: 5000, easing: Easing.linear, repeat: true, yoyo: true, }));
492496
// }, { duration: 5000, easing: x => Easing.easeStep(x, 10), repeat: true, yoyo: true, }));

0 commit comments

Comments
 (0)