Skip to content

Commit

Permalink
Fixed zoom not adjusting line properly
Browse files Browse the repository at this point in the history
  • Loading branch information
zekemccrary committed Oct 23, 2023
1 parent 62432d0 commit 19e6279
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 24 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added static/.DS_Store
Binary file not shown.
Binary file added static/graphs/.DS_Store
Binary file not shown.
Binary file added static/graphs/js/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions static/graphs/js/dva_graphs/dva_graphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ function checkInput(expr, is_condition=false) {

// Zooms the graph by multiplying the axes
function zoom(factor) {
if (factor == -Infinity || factor == Infinity || factor == NaN || factor === 0) { return; }

domain[0] *= factor;
domain[1] *= factor;
range[0] *= factor;
Expand Down
28 changes: 4 additions & 24 deletions static/graphs/js/dva_graphs/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,9 @@ export class MathFunction {

// Generate an array of x,y pairs for graphing.
toPointsArray(points, min, max) {
let range = max - min; // What points to graph it in between.
let change = (max - min) / points; // What to increment the x value by, more points = a greater resolution

let pointsArr = new Array(max - min);

let change = range / points; // What to increment the x value by, more points = a greater resolution
let currentX = min;

for (let i = 0; i < range; i++) {
pointsArr[i] = [currentX, this.func(currentX)]; // Set pointsArr[i] to the x, y pair.
currentX += change;
}

return pointsArr;
return Array.from( { length: points }, (_, i) => [i * change, this.yAt(i * change)] );
}
}

Expand Down Expand Up @@ -65,18 +55,8 @@ export class PiecewiseFunction {

// Generate an array of x,y pairs for graphing.
toPointsArray(points, min, max) {
let range = max - min; // What points to graph it in between.

let pointsArr = new Array(max - min);

let change = range / points; // What to increment the x value by, more points = a greater resolution
let currentX = min;

for (let i = 0; i < range; i++) {
pointsArr[i] = [currentX, this.iterate(currentX)]; // Set pointsArr[i] to the x, y pair.
currentX += change;
}
let change = (max - min) / points; // What to increment the x value by, more points = a greater resolution

return pointsArr;
return Array.from( { length: points }, (_, i) => [i * change, this.iterate(i * change)] );
}
}

0 comments on commit 19e6279

Please sign in to comment.