-
Notifications
You must be signed in to change notification settings - Fork 370
Fix: Re-enable terrain elevation chart with Chart.js ESM support #2518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sensei-hacker
merged 9 commits into
iNavFlight:maintenance-9.x
from
sensei-hacker:fix/terrain-elevation-chart-esm
Jan 13, 2026
Merged
Fix: Re-enable terrain elevation chart with Chart.js ESM support #2518
sensei-hacker
merged 9 commits into
iNavFlight:maintenance-9.x
from
sensei-hacker:fix/terrain-elevation-chart-esm
Jan 13, 2026
+769
−335
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
The plotElevation() function was commented out in commit 8d5870b due to ESM module compatibility issues. This fix: - Adds Chart.js v4.4.1 with full ESM support to package.json - Imports Chart.js properly as ES module - Uncomments the plotElevation() function This restores the terrain elevation profile chart feature for mission planning safety checks.
The plotElevation() function calls `new Chart()` which expects Chart to be available in the global scope. While we correctly imported Chart.js as an ES module, it was only available within the module scope. This change exposes Chart on the window object so the elevation plotting function can access it.
The plotElevation() function had Chart.js code only for empty missions (dummy data). When missions had waypoints, it prepared elevation data but only had a commented-out Plotly.newPlot() call, so no chart rendered. Changes: - Add Chart.js rendering after elevation data preparation (line 4352+) - Convert Plotly trace data to Chart.js datasets format - Display WGS84 terrain elevation (orange, filled area) - Display mission altitude (blue line with waypoint markers) - Properly destroy existing chart before creating new one - Store chart instance globally for cleanup on subsequent calls Both empty and non-empty mission cases now create Chart.js charts.
Code review identified several issues that needed addressing: CRITICAL fixes: - Replace hardcoded test data in empty mission case with proper empty chart - Add canvas element validation before Chart instantiation - Remove all unused Plotly code structures (trace objects, layout vars) - Fix chart title to not depend on removed Plotly code IMPROVEMENTS: - Add try-catch error handling for async elevation data fetch - Add safe array checks for Math.min/max to prevent empty array errors - Change var to const for immutable values (modern JavaScript) - Clear chart instance reference (set to null) after destruction - Add console error messages for debugging The plotElevation() function is now a clean Chart.js-only implementation without any Plotly remnants, proper error handling, and validation.
…ctivity When waypoints are dragged, the elevation chart should update smoothly. The previous approach of destroying and recreating the chart on every update was causing the chart to not refresh when waypoints were moved. Chart.js update() method is designed for this use case: - Preserves the chart instance - Updates data and options - Triggers smooth re-render with animations - More efficient than destroy/recreate This fixes the issue where dragging a waypoint didn't update the elevation profile.
…cted Previously, plotElevation() was only called if the dragged waypoint matched selectedMarker. This meant dragging an unselected waypoint wouldn't update the chart. Now plotElevation() is called for all waypoint drags: - If waypoint is selected: updates elevation + runs full async logic - If waypoint is not selected: updates elevation chart only This ensures the elevation profile always reflects the current mission geometry after any waypoint is moved.
Per code review feedback, adds two important improvements:
1. Race condition protection:
- Track elevation update sequence number
- Ignore stale data from late-returning API calls
- Prevents chart showing outdated elevation when waypoints dragged rapidly
2. Disable chart animations during updates:
- Use chart.update('none') instead of chart.update()
- Improves performance during drag operations
- Prevents animation queueing and visual lag
These fixes ensure the chart always shows current data and responds
smoothly even with rapid waypoint dragging or slow network connections.
a0e1950 to
bef73fc
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
User description
Summary
Re-enables the terrain elevation chart feature in Mission Control that was disabled in December 2024 due to ESM module compatibility issues during the Vite migration.
Yarn rebuilt the yarn.lock file, reorganizing everything, when I added a dependency. Is that expected and correct?
Root Cause
The
plotElevation()function was commented out in commit8d5870b0aebecause the charting libraries (Chart.js/Plotly.js) were not compatible with the new ESM module system used by Vite.Changes
plotElevation()function in tabs/mission_control.jsTechnical Details
Testing
yarn startCode Review
Reviewed with inav-code-review agent. All critical and important issues addressed:
Impact
Restores mission planning safety feature that shows terrain clearance along flight paths, helping prevent ground collisions.
Fixes terrain elevation data not loading issue.
PR Type
Bug fix, Enhancement
Description
This description is generated by an AI tool. It may have inaccuracies
Re-enables terrain elevation chart with Chart.js ESM support
plotElevation()function with improved error handlingEnhances JavaScript transpiler validation to catch previously silent errors
Improves error reporting in JavaScript Programming tab
Adds regression test scripts for validation and examples
Diagram Walkthrough
File Walkthrough
1 files
Add Chart.js v4.4.1 dependency2 files
Re-enable elevation chart with Chart.jsFail transpilation on parser errors4 files
Detect invalid function calls with error messagesDetect intermediate objects and provide suggestionsGenerate improved writability error messagesAdd i18n localization for tab header1 files
Fix CSS spacing in note sections1 files
Update JavaScript beta warning message2 files
Add regression tests for validation fixesAdd regression tests for example compilation