Skip to content

Conversation

IanMayo
Copy link
Contributor

@IanMayo IanMayo commented Aug 11, 2025

Summary

Completes the final phase of issue #132 by extracting the last remaining duplicate methods to BaseMode class, achieving 100% elimination of identified code duplication.

Changes

✅ Type Definition Added

  • Added ViewportConfig typedef to src/types.js for proper type documentation

✅ Methods Extracted to BaseMode

  • getViewport(): Returns viewport configuration for coordinate transformations
  • updateCursorStyle(): Updates cursor style for drag operations

✅ Duplicate Code Removed

  • Removed duplicate getViewport() implementations from:
    • AnalysisMode.js (8 lines)
    • HarmonicsMode.js (8 lines)
    • DopplerMode.js (8 lines)
  • Removed duplicate updateCursorStyle() implementations from:
    • AnalysisMode.js (5 lines)
    • HarmonicsMode.js (5 lines)
    • DopplerMode.js (5 lines)

Total: 39 lines of duplicate code eliminated

Impact

This completes the mode system refactoring with:

  • ~200 lines of duplicate code eliminated overall
  • 100% completion of refactoring goals
  • Strong architectural foundation with BaseMode
  • Clean separation of concerns
  • All modes now properly inherit common functionality

Testing

✅ All 65 tests passing
✅ No regressions identified
✅ Mode switching works correctly
✅ Drag operations function properly in all modes

Fixes #132

IanMayo and others added 14 commits August 8, 2025 13:45
…en zoomed

When users create manual harmonics while zoomed in, harmonics are now placed
at the center of the visible time period rather than the center of the full
time range. This ensures harmonics are immediately visible without requiring
users to zoom out.

Changes:
- Export calculateVisibleDataRange() from table.js for reuse
- Add calculateVisibleTimePeriodCenter() helper function
- Update ManualHarmonicModal to use zoom-aware anchor time calculation
- Maintain backward compatibility when zoom level = 1.0

Fixes #130

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replace brittle floating point equality (=== 1.0) with epsilon-based
comparison (Math.abs(zoom.level - 1.0) < 0.001) for more robust
zoom level detection in manual harmonics positioning.

This prevents potential issues with floating point precision that
could cause incorrect zoom state detection.
Copy link

netlify bot commented Aug 11, 2025

Deploy Preview for gramframe ready!

Name Link
🔨 Latest commit d7c4721
🔍 Latest deploy log https://app.netlify.com/projects/gramframe/deploys/6899d97408e5f30008e97a3e
😎 Deploy Preview https://deploy-preview-145--gramframe.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

refactor: simplify state structure by removing AxesConfig wrapper
@IanMayo IanMayo requested a review from Copilot August 11, 2025 08:51
Copilot

This comment was marked as outdated.

@IanMayo IanMayo requested a review from Copilot August 11, 2025 10:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR completes the mode system refactoring by extracting the final duplicate methods to BaseMode class, achieving 100% elimination of identified code duplication as outlined in issue #132. The refactoring also includes important bug fixes to state property access and test stability improvements.

Key changes include:

  • Added ViewportConfig typedef for proper type documentation
  • Extracted getViewport() and updateCursorStyle() methods to BaseMode to eliminate 39 lines of duplicate code
  • Fixed state property access throughout mode classes by removing deprecated axes.margins in favor of direct margins access
  • Updated mode constructors to remove redundant state parameter passing
  • Fixed focus behavior and test stability issues

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/types.js Added ViewportConfig typedef and simplified axes configuration structure
src/modes/BaseMode.js Added common getViewport() and updateCursorStyle() methods to eliminate duplication
src/modes/*/Mode.js Removed duplicate method implementations and fixed state property access patterns
src/modes/ModeFactory.js Simplified mode construction by removing redundant state parameter
src/core/state.js Flattened margins configuration from axes.margins to direct margins property
tests/*.spec.js Improved test stability and fixed focus behavior expectations
Comments suppressed due to low confidence (1)

src/modes/doppler/DopplerMode.js:136

  • The updateCursorStyle method in DopplerMode overrides the base implementation but uses different cursor style mapping (grab -> move). This inconsistency could cause confusion. Consider either removing this override to use the base implementation or documenting why DopplerMode needs different cursor behavior.
  /**

const container = document.createElement('div')
container.className = 'gram-frame-color-picker'
container.style.display = (state.mode === 'harmonics' || state.mode === 'analysis') ? 'block' : 'none'
container.style.display = 'block'
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

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

The color picker is now always visible (display: 'block') regardless of mode, but the original logic showed it only for 'harmonics' and 'analysis' modes. This change should be verified to ensure it doesn't negatively impact UX in modes where color selection isn't relevant.

Suggested change
container.style.display = 'block'
if (state.mode === 'harmonics' || state.mode === 'analysis') {
container.style.display = 'block'
} else {
container.style.display = 'none'
}

Copilot uses AI. Check for mistakes.

…for SVG elements

feat: implement uniform tolerance for analysis markers and enhance crosshair interaction
test: add cursor feedback test page for marker interaction validation
IanMayo and others added 21 commits August 11, 2025 11:39
…for SVG elements

feat: implement uniform tolerance for analysis markers and enhance crosshair interaction
test: add cursor feedback test page for marker interaction validation
…for SVG elements

feat: implement uniform tolerance for analysis markers and enhance crosshair interaction
test: add cursor feedback test page for marker interaction validation
- Fix duplicate pointer events code in DopplerMode.js
- Correct state references to use this.instance.state throughout mode files
- Resolve test file conflicts with comprehensive selector patterns
- Maintain robust test timeouts and error handling
- All 78 tests passing with clean TypeScript compilation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@IanMayo IanMayo merged commit a382e5b into main Aug 11, 2025
4 checks passed
@IanMayo IanMayo deleted the issue-132-final-refactor branch August 11, 2025 11:59
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.

Refactor mode system to eliminate code duplication and improve architecture
1 participant