diff --git a/web/templates/graphing_calculator.html b/web/templates/graphing_calculator.html
index fd7efb2cb..ece82c021 100644
--- a/web/templates/graphing_calculator.html
+++ b/web/templates/graphing_calculator.html
@@ -1,6 +1,8 @@
{% extends "base.html" %}
-{% block title %}Graphing Calculator{% endblock %}
+{% block title %}
+ Graphing Calculator
+{% endblock title %}
{% block content %}
@@ -156,7 +158,11 @@
SettingsSettings 0 ? 0.9 : 1.1;
- const newScale = scale * zoomFactor;
- origin.x = mouseX - mousePos.x * newScale;
- origin.y = mouseY + mousePos.y * newScale;
- scale = newScale;
+ baseScale = Math.min(MAX_SCALE, Math.max(MIN_SCALE, baseScale * zoomFactor));
+ scale = baseScale * gridDensity;
+ origin.x = mouseX - mousePos.x * scale;
+ origin.y = mouseY + mousePos.y * scale;
redraw();
});
@@ -315,21 +321,38 @@ Settings n.isSymbolNode && n.name.toLowerCase() === "y");
+ if (yNodes.length > 0) {
+ alert("Explicit equations cannot reference 'y' on the right-hand side.");
+ return;
+ }
+ } catch (err) {
+ console.warn("[plotExplicit] math.parse failed for expression:", exprStr, err);
}
let compiled;
try {
compiled = math.compile(exprStr);
} catch (err) {
- alert("Error in equation: " + err);
+ alert("Error in equation: " + err.message);
return;
}
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.beginPath();
let firstPoint = true;
+ let prevY = null;
const xMin = toMathCoords(0, 0).x;
const xMax = toMathCoords(canvas.width, 0).x;
const step = (xMax - xMin) / canvas.width;
@@ -341,12 +364,19 @@ Settings (canvas.height / scale)) {
+ firstPoint = true;
+ }
+ prevY = y;
const {
x: cx,
y: cy
@@ -373,14 +403,20 @@ SettingsSettings 0) index |= 8;
if (index === 0 || index === 15) continue;
let points = [];
- if ((index & 1) !== (index & 2)) {
+ const b1 = v1 > 0;
+ const b2 = v2 > 0;
+ const b3 = v3 > 0;
+ const b4 = v4 > 0;
+ if (b1 !== b2) {
points.push(interpolate({
x: i,
y: j
@@ -425,7 +465,7 @@ SettingsSettingsSettingsSettings 0) {
+ hasYVariable = true;
+ }
+ } catch (err) {
+ console.error("[plotEquation] Failed to parse expression:", equation, err);
+ hasYVariable = true; // treat parse failure as invalid to prevent falling through to plotExplicit
+ }
+
+ if (hasYVariable) {
+ alert("Invalid implicit equation format.");
+ } else {
+ plotExplicit("y=" + equation, color);
+ }
}
}
+ // Allow submitting an equation by pressing Enter
+ document.getElementById('equationInput').addEventListener('keydown', function(e) {
+ if (e.key === 'Enter') addEquation();
+ });
+
// Equation list manipulation
function addEquation() {
const eqInput = document.getElementById('equationInput');
@@ -561,19 +626,26 @@ SettingsSettingsSettings
-{% endblock %}
+{% endblock content %}