Skip to content

Add Interactive Graphing Calculator Page#68

Open
ghanshyam2005singh wants to merge 3 commits into
alphaonelabs:mainfrom
ghanshyam2005singh:feat/graphing-calculator
Open

Add Interactive Graphing Calculator Page#68
ghanshyam2005singh wants to merge 3 commits into
alphaonelabs:mainfrom
ghanshyam2005singh:feat/graphing-calculator

Conversation

@ghanshyam2005singh

@ghanshyam2005singh ghanshyam2005singh commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a new Graphing Calculator experience for the Alpha One Labs Education Platform, modernizing and expanding the functionality of the legacy graphing calculator.

The implementation provides a responsive, browser-based graphing environment with real-time equation visualization, interactive controls, educational examples, and full dark mode support.


New Page

Added

  • public/graphing-calculator.html

Updated

  • public/partials/navbar.html

    • Added Graphing Calculator link in desktop LEARN dropdown
    • Added Graphing Calculator link in mobile navigation

Features

Graph Engine

  • Client-side graph rendering

  • Powered by Math.js

  • Supports:

    • Trigonometric functions
    • Logarithmic functions
    • Exponential functions
    • Square roots
    • Absolute values
    • Constants (pi, e)
    • Power operations (^)
    • Standard arithmetic expressions

Interactive Graph Canvas

  • Cartesian coordinate system
  • Dynamic grid rendering
  • Axis labels and origin marker
  • Hover coordinate display
  • Smooth discontinuity detection
  • Real-time graph updates

Navigation & Controls

  • Mouse wheel zoom
  • Click-and-drag panning
  • Touch pinch zoom support
  • Keyboard navigation support

Toolbar actions:

  • Zoom In
  • Zoom Out
  • Reset View
  • Center Origin
  • Toggle Grid
  • Export PNG
  • Fullscreen Mode

Equation Management

  • Multiple equations supported
  • Live editing
  • Show / hide individual equations
  • Remove equations
  • Color cycling support
  • Debounced rendering
  • Inline validation messages

Educational Features

Built-in examples:

  • Parabola
  • Sine Wave
  • Circle
  • Tangent
  • Logarithm
  • Exponential

Each example loads automatically into the graph editor.

Settings

  • Adjustable grid density
  • Adjustable line width
  • Persistent graph controls

UI Improvements

Sidebar Redesign

  • Expanded width for improved usability
  • Sticky viewport-height sidebar
  • Independent scrolling
  • Improved spacing and hierarchy
  • Cleaner section headers

Controls Layout

  • Dedicated zoom controls
  • D-pad style navigation cluster
  • Clear visual grouping

Responsive Design

  • Mobile friendly layout
  • Desktop optimized workspace
  • Full dark mode support

Accessibility

  • Keyboard accessible controls
  • ARIA labels added
  • Improved focus states
  • Accessible navigation patterns

Testing

Manually verified:

  • Graph rendering
  • Multiple equations
  • Zoom and pan behavior
  • Fullscreen mode
  • Export functionality
  • Example loading
  • Mobile responsiveness
  • Dark mode support
  • Error handling and invalid expressions

Screenshots

Screencast.from.2026-06-17.01-21-16.mp4
Screenshot from 2026-06-17 11-33-40

Interactive Graphing Calculator

This PR adds a new Interactive Graphing Calculator page to the Alpha One Labs Education Platform, delivering an interactive, Math.js-powered graphing experience with rich equation editing and accessibility-friendly controls.

Key Additions

  • New page: public/graphing-calculator.html
    • Split UI with a left equation sidebar and a main interactive canvas.
    • Client-side rendering using Math.js with support for:
      • Trig, logarithmic, and exponential functions
      • Square roots, absolute values, constants (π, e), power operations, and standard arithmetic
    • Dark mode support via a persisted localStorage theme class and canvas redraws when theme changes.

Interactive Graph & Controls (UX impact)

  • Cartesian coordinate grid with dynamic grid rendering, axis labels, and origin marker.
  • Hover coordinate readout and on-canvas view range display.
  • Navigation:
    • Zoom: mouse wheel, touch pinch, and keyboard +/-
    • Pan: drag and arrow-key panning (plus dedicated d-pad pan buttons)
  • Smooth rendering with discontinuity detection to improve curve quality.
  • Responsive canvas with device-pixel-ratio handling.

Equation Management & Learning Features

  • Multiple equations per view with:
    • Inline editing (debounced recompilation)
    • Show/hide toggles, removal, and color cycling
    • Inline validation with friendly error banner formatting
  • Built-in examples (6):
    • Parabola (x^2), Sine (sin(x)), Circle (x^2+y^2=9), Tangent (tan(x)), Log (log(x)), Exponential (e^x)
    • Examples auto-load into the editor.

Additional Capabilities

  • Export PNG of the current graph view.
  • Fullscreen mode with a separate fullscreen canvas and shared interaction/view logic.
  • Settings for grid density (fine/normal/coarse) and line width, with persistence.

Updated Navigation

  • public/partials/navbar.html: adds the Graphing Calculator link to the desktop and mobile “LEARN” menus, routing to /graphing-calculator.html.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@public/graphing-calculator.html`:
- Around line 264-268: The buttons throughout the file are missing the explicit
type="button" attribute. By default, HTML buttons have type="submit" which can
cause unexpected form submission behavior if these buttons are placed within a
form context. Add type="button" to all non-submit button elements, including the
button with onclick="addFromInput()" in the diff and all other buttons that
perform actions rather than submit forms. Ensure each button element includes
type="button" as an attribute to prevent any unintended form submission
behavior.
- Line 467: The variable declaration for lineWidth is missing a semicolon at the
end of the statement. Add a semicolon after the value 2 in the lineWidth
variable declaration to maintain consistency with the semicolon usage pattern
throughout the rest of the codebase.
- Around line 1-15: Remove the Tailwind Play CDN script tag that loads from
https://cdn.tailwindcss.com since it performs runtime CSS compilation in the
browser, which is unsuitable for production. Instead, replace it with a static
CSS file generated using the official Tailwind CLI, Vite plugin, or PostCSS
build tool. Additionally, add Subresource Integrity (SRI) hashes using sha384 or
sha512 algorithms to the two remaining external resources: the Font Awesome CSS
link and the math.js script tag. Generate the hashes using OpenSSL or an online
SRI Hash Generator and include them in the integrity attribute of each external
resource tag.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f4e893fb-6e53-49a5-917c-8fdf3cfe18f4

📥 Commits

Reviewing files that changed from the base of the PR and between 997b01e and 0afb97e.

📒 Files selected for processing (2)
  • public/graphing-calculator.html
  • public/partials/navbar.html

Comment thread public/graphing-calculator.html
Comment thread public/graphing-calculator.html Outdated
Comment thread public/graphing-calculator.html Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
public/graphing-calculator.html (2)

693-697: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Unused function: centerOrigin() is defined but never called.

The PR description mentions "center origin" as a toolbar action, but there's no button wired to this function. Either add a button to expose this feature or remove the dead code to keep the codebase clean.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@public/graphing-calculator.html` around lines 693 - 697, The centerOrigin()
function is defined but never invoked anywhere in the codebase, making it dead
code. Either add an HTML button element in the toolbar that calls centerOrigin()
when clicked (since the PR description mentions this as a toolbar action), or
remove the entire centerOrigin() function definition if this feature is not
needed. Choose based on whether the center origin functionality should be
exposed to users.

843-855: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Logic issue: array-based equations lose their structure during editing.

When a user edits a multi-part equation (like the circle example with ['sqrt(9-x^2)', '-sqrt(9-x^2)']), this function has a subtle bug:

  1. Line 846 immediately sets eq.raw = val (converting the array to a single comma-separated string)
  2. Line 849's check Array.isArray(eq.raw) will always be false since line 846 already overwrote it with a string
  3. This means compileEq receives a single string like "sqrt(9-x^2), -sqrt(9-x^2)" instead of an array

The result: editing a circle breaks it into an invalid single expression rather than two valid half-circle expressions.

🔧 Suggested fix: preserve array format
 function onRawInput(id, val) {
   const eq = equations.find(e => e.id === id);
   if (!eq) return;
-  eq.raw = val;
+  const wasArray = Array.isArray(eq.raw);
   clearTimeout(debounceTimer);
   debounceTimer = setTimeout(() => {
-    eq.raw = Array.isArray(eq.raw) ? eq.raw : val; // keep single
+    // For multi-part equations (like circles), split on comma
+    // For single expressions, keep as string
+    if (wasArray && val.includes(',')) {
+      eq.raw = val.split(',').map(s => s.trim()).filter(Boolean);
+    } else {
+      eq.raw = val;
+    }
     compileEq(eq);
     renderFunctionList();
     draw();
     showErrors();
   }, 280);
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@public/graphing-calculator.html` around lines 843 - 855, The onRawInput
function has a logic error where line 846 immediately overwrites eq.raw with the
string value, making the Array.isArray check on line 849 always evaluate to
false. To fix this, check if eq.raw is currently an array before overwriting it
on line 846, then preserve the array structure appropriately when assigning the
new value. Store the original array status before the assignment, and in the
debounce callback, use that stored information to correctly restore eq.raw to
either an array (if it was originally an array) or a single string value,
ensuring that multi-part equations like circles maintain their structure during
editing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@public/graphing-calculator.html`:
- Around line 693-697: The centerOrigin() function is defined but never invoked
anywhere in the codebase, making it dead code. Either add an HTML button element
in the toolbar that calls centerOrigin() when clicked (since the PR description
mentions this as a toolbar action), or remove the entire centerOrigin() function
definition if this feature is not needed. Choose based on whether the center
origin functionality should be exposed to users.
- Around line 843-855: The onRawInput function has a logic error where line 846
immediately overwrites eq.raw with the string value, making the Array.isArray
check on line 849 always evaluate to false. To fix this, check if eq.raw is
currently an array before overwriting it on line 846, then preserve the array
structure appropriately when assigning the new value. Store the original array
status before the assignment, and in the debounce callback, use that stored
information to correctly restore eq.raw to either an array (if it was originally
an array) or a single string value, ensuring that multi-part equations like
circles maintain their structure during editing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b8e1d606-9ee7-4e85-b063-6d2b41df536d

📥 Commits

Reviewing files that changed from the base of the PR and between 0afb97e and 5891401.

📒 Files selected for processing (1)
  • public/graphing-calculator.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant