Skip to content

Conversation

@tariqksoliman
Copy link
Member

Closes #826

With Claude.

D3.js DOM Manipulation Removal - Complete Migration (#826)

Summary

Successfully completed the removal of D3.js DOM manipulation from all 37 MMGIS frontend files, replacing with jQuery/vanilla JS while preserving D3 for specialized data visualization functions (charts, time formatting, coordinates).

Changes Made

Phase 4-8 Completion & Bug Fixes

Files Fixed (5):

  1. UserInterfaceMobile_.js - Converted all active .style() calls to .css()
  2. LegendTool.js - 171+ conversions across:
    - Header and container initialization
    - Image container rendering
    - Shape rendering (circle, square, rect, image, icon)
    - Gradient and scale rendering with tick marks
    - Units labels and positioning
    - Tooltip functionality
  3. Viewer_.js - 76 conversions across all viewer modes (images, panoramas, PDFs, videos, GIFs, 3D models)
  4. MeasureTool.js - Fixed 2 .style() calls causing runtime error (user-reported bug)
  5. SitesTool.js - Fixed incorrect .append('div') pattern

Files Verified Clean (32):

  • Phases 5-8: All tools, layers system, and advanced tools verified with 0 jQuery conversion bugs

Critical Bug Fixes

  1. ToolController_.js - Separated Tool DOM Structure (src/essence/Basics/ToolController_/ToolController_.js)
  • Issue: Icons were rendered as siblings instead of children of tool buttons
  • Root Cause: D3's .append() returns the new child element, jQuery's .append() returns the parent
  • Impact: Click handlers were attached to wrong element, causing interaction bugs
  • Fix: Restructured to create elements first, then append in correct hierarchy
  1. ScaleBar SVG Rendering (src/essence/Basics/Map_/Map_.js)
  • Issue: ScaleBar not rendering - D3 couldn't manipulate SVG elements created by jQuery
  • Root Cause: jQuery's $('') doesn't set proper XML namespace
  • Fix: Changed to document.createElementNS('http://www.w3.org/2000/svg', 'svg')
  1. Tooltip Rendering (src/essence/Tools/Legend/LegendTool.js)
  • Issue: Custom tooltips instead of native browser tooltips
  • Fix: Removed custom CSS that was overriding native title attribute rendering

D3 Retained (As Intended)

Full D3 Usage:

  • ChemistryTool (3 files) - Full D3 charts and data visualization
  • MetricsGraphics (external library) - Third-party dependency requires full D3

Selective D3 Functions:

  • ScaleBar.js - d3.scaleLinear(), d3.axisBottom() for scale charts (with proper SVG manipulation)
  • Time formatting (4 files) - d3.utcFormat() for UTC timestamps (LayerCapturer.js, TimeControl.js, IdentifierTool.js, ShadeTool.js)
  • CursorInfo.js - d3.pointer() for mouse coordinates

Migration Pattern Documentation

Key D3 vs jQuery Differences:
// D3: Returns NEW child element
const child = parent.append('div')

// jQuery: Returns PARENT element
const stillParent = parent.append($('

'))

Correct jQuery Pattern:
const child = $('

')
parent.append(child)
child.append($('')) // Icon inside child ✓

Testing

  • ✅ All 37 active files migrated
  • ✅ Zero jQuery conversion bugs in active code
  • ✅ User-reported runtime errors resolved
  • ✅ Separated tools render and function correctly
  • ✅ ScaleBar displays with proper D3 visualization
  • ✅ Native browser tooltips working
  • ✅ No console errors

Bundle Impact

While full D3 package remains due to external dependencies, we've achieved:

  • Eliminated redundant D3 DOM manipulation across 37 files
  • Standardized on jQuery for DOM operations
  • Reduced D3 usage to only necessary visualization functions
  • Cleaner, more maintainable codebase

Files Changed

Modified (7):

  • src/essence/Basics/ToolController_/ToolController_.js
  • src/essence/Basics/Map_/Map_.js
  • src/essence/Tools/Legend/LegendTool.js
  • src/essence/Tools/Measure/MeasureTool.js
  • src/essence/Tools/Sites/SitesTool.js
  • src/essence/Basics/Viewer_/Viewer_.js
  • src/essence/Basics/UserInterface_/UserInterfaceMobile_.js

Total Changes: ~2,720 lines added, ~2,263 lines removed

Success Criteria Met

✅ All 37 files migrated (ChemistryTool unchanged per plan)
✅ d3.utcFormat, d3.scaleLinear, d3.axisBottom, d3.pointer preserved
✅ No functional regressions
✅ All user-reported bugs fixed
✅ No console errors
✅ Cleaner, more consistent codebase

@github-actions
Copy link
Contributor

✅ Version Already Updated

This PR includes a manual version update to 4.2.1-20251222

No automatic version bump needed.

@tariqksoliman tariqksoliman merged commit 5205fc7 into development Dec 22, 2025
3 checks passed
@tariqksoliman tariqksoliman deleted the ts-826 branch December 22, 2025 23:40
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.

[Quality of Life]: Remove D3

2 participants