Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/_assets/derivative.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { displayAlert } from './utils'
import { displayAlert, setCoordinatesInBox } from './utils'
import { DerivativeFxChart } from './fx/derivative_fx'
import { FxChart } from './fx/fx'
import { drawOffscreenAndTransferTo } from './canvas_utils'
Expand Down Expand Up @@ -60,6 +60,9 @@ export function init() {
fxFgCtx.clearRect(0, 0, fxFgCtx.canvas.width, fxFgCtx.canvas.height)
fx2FgCtx.clearRect(0, 0, fx2FgCtx.canvas.width, fx2FgCtx.canvas.height)

document.getElementById('fx-coordinates')!.innerText = ''
document.getElementById('fx2-coordinates')!.innerText = ''

const resolution: [number, number] = [fxCtx.canvas.width, fxCtx.canvas.height]

const fx = new FxChart(func, resolution, xMin, xMax, yMin, yMax)
Expand Down Expand Up @@ -150,9 +153,11 @@ function drawInteraction(x_px: number) {

// Draw fx(x)
fx.drawPointOnCanvas(ctx, x, fx.points![x_px]![1]!, { radius: 6 })
setCoordinatesInBox('fx-coordinates', x, fx.points![x_px]![1])
})

// Draw fx'(x)
fx2FgCtx.clearRect(0, 0, fx2FgCtx.canvas.width, fx2FgCtx.canvas.height)
fx2.drawPointOnCanvas(fx2FgCtx, x, y, { color, radius: 6 })
setCoordinatesInBox('fx2-coordinates', x, y)
}
5 changes: 4 additions & 1 deletion src/_assets/incremental_ratio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { displayAlert } from './utils'
import { displayAlert, setCoordinatesInBox } from './utils'
import { evaluate } from 'mathjs'
import config from './config'
import { FxChart } from './fx/fx'
Expand Down Expand Up @@ -51,6 +51,8 @@ export function init() {
fxCtx.clearRect(0, 0, fxCtx.canvas.width, fxCtx.canvas.height)
fxFgCtx.clearRect(0, 0, fxFgCtx.canvas.width, fxFgCtx.canvas.height)

document.getElementById('fx-coordinates')!.innerText = ''

const resolution: [number, number] = [fxCtx.canvas.width, fxCtx.canvas.height]
const fx = new FxChart(func, resolution, xMin, xMax, yMin, yMax)

Expand Down Expand Up @@ -143,6 +145,7 @@ export function drawInteraction(x: number) {
}
fx.drawPointOnCanvas(ctx, xMoving, yMoving)
fx.drawPointOnCanvas(ctx, xFixed, yFixed)
setCoordinatesInBox('fx-coordinates', xMoving, yMoving)
})
}

Expand Down
7 changes: 6 additions & 1 deletion src/_assets/sign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { displayAlert } from './utils'
import { displayAlert, setCoordinatesInBox } from './utils'
import { FxChart } from './fx/fx'
import { DerivativeFxChart } from './fx/derivative_fx'
import { evaluate } from 'mathjs'
Expand Down Expand Up @@ -61,6 +61,9 @@ export function init() {
fxFgCtx.clearRect(0, 0, fxFgCtx.canvas.width, fxFgCtx.canvas.height)
fx2FgCtx.clearRect(0, 0, fx2FgCtx.canvas.width, fx2FgCtx.canvas.height)

document.getElementById('fx-coordinates')!.innerText = ''
document.getElementById('fx2-coordinates')!.innerText = ''

const resolution: [number, number] = [fxCtx.canvas.width, fxCtx.canvas.height]

const fx = new FxChart(func, resolution, xMin, xMax, yMin, yMax)
Expand Down Expand Up @@ -154,9 +157,11 @@ function drawInteraction(x_px: number) {

// Draw fx(x)
fx.drawPointOnCanvas(ctx, x, fx.points![x_px]![1]!, { radius: 6 })
setCoordinatesInBox('fx-coordinates', x, fx.points![x_px]![1]!)
})

// Draw fx'(x)
fx2FgCtx.clearRect(0, 0, fx2FgCtx.canvas.width, fx2FgCtx.canvas.height)
fx2.drawPointOnCanvas(fx2FgCtx, x, y, { color, radius: 6 })
setCoordinatesInBox('fx2-coordinates', x, y)
}
5 changes: 5 additions & 0 deletions src/_assets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ export function copyLinkToClipboard() {
const toast = new Toast(toastElement, { delay: 2000 })
toast.show()
}

export function setCoordinatesInBox(id: string, x: number, y: number) {
const coordinatesBox = document.getElementById(id)!
coordinatesBox.innerText = `X: ${x.toFixed(2)}, Y: ${y.toFixed(2)}`
}
6 changes: 4 additions & 2 deletions src/functions/derivative.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
</div>
</div>
<div class="col-md-9">
<div id="fx-canvas-container">
<div id="fx-canvas-container" class="position-relative">
<div id="fx-coordinates" class="position-absolute end-0 top-0 fst-italic me-1 mt-1 text-muted"></div>
<canvas id="fx-layer-0" class="position-absolute border border-dark"></canvas>
<canvas id="fx-layer-1" class="position-absolute border border-dark"></canvas>
</div>
<hr>
<div id="fx2-canvas-container">
<div id="fx2-canvas-container" class="position-relative">
<div id="fx2-coordinates" class="position-absolute end-0 top-0 fst-italic me-1 mt-1 text-muted"></div>
<canvas id="fx2-layer-0" class="position-absolute border border-dark"></canvas>
<canvas id="fx2-layer-1" class="position-absolute border border-dark"></canvas>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/functions/incremental_ratio.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
</div>
</div>
<div class="col-md-9">
<div id="fx-canvas-container">
<div id="fx-canvas-container" class="position-relative">
<div id="fx-coordinates" class="position-absolute end-0 top-0 fst-italic me-1 mt-1 text-muted"></div>
<canvas id="fx-layer-0" class="position-absolute border border-dark"></canvas>
<canvas id="fx-layer-1" class="position-absolute border border-dark"></canvas>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/functions/sign.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
</div>
</div>
<div class="col-md-9">
<div id="fx-canvas-container">
<div id="fx-canvas-container" class="position-relative">
<div id="fx-coordinates" class="position-absolute end-0 top-0 fst-italic me-1 mt-1 text-muted"></div>
<canvas id="fx-layer-0" class="position-absolute border border-dark"></canvas>
<canvas id="fx-layer-1" class="position-absolute border border-dark"></canvas>
</div>
<hr>
<div id="fx2-canvas-container">
<div id="fx2-canvas-container" class="position-relative">
<div id="fx2-coordinates" class="position-absolute end-0 top-0 fst-italic me-1 mt-1 text-muted"></div>
<canvas id="fx2-layer-0" class="position-absolute border border-dark"></canvas>
<canvas id="fx2-layer-1" class="position-absolute border border-dark"></canvas>
</div>
Expand Down