PLOT and SURFACE xdl-charts Integration
Overview
The traditional PLOT and SURFACE procedures have been enhanced to use the modern xdl-charts/Tauri system by default, with automatic fallback to the original graphics rendering when Tauri is unavailable.
What Changed
Before
PLOTandSURFACEgenerated static PNG images- Required GUI callbacks for interactive display
- Limited interactivity
- 2D surface rendering for 3D plots
After
- Default: Interactive Tauri windows with ECharts rendering
- Fallback: Original PNG generation if Tauri unavailable
- Full 3D interactivity with rotation, zoom, pan
- WebGL acceleration for large datasets
- Modern web-based charting
Usage
No code changes required! Existing scripts continue to work:
; Simple line plot
x = FINDGEN(100) / 10.0
y = SIN(x)
PLOT, x, y
; Auto-generate X coordinates
y2 = COS(x)
PLOT, y2
; 3D surface plot
z = FLTARR(40, 40)
FOR i=0, 39 DO FOR j=0, 39 DO BEGIN
z[i,j] = SIN(SQRT((i-20)^2 + (j-20)^2) / 5.0)
ENDFOR
SURFACE, z
Benefits
- Better Interactivity: Tauri windows provide native desktop integration
- 3D Support: True 3D rendering with ECharts GL
- Performance: WebGL acceleration for large datasets
- Backwards Compatible: Automatic fallback ensures old scripts work
- Modern UI: Clean, responsive charts with built-in controls
Fallback Behavior
If xdl-chart-viewer is not available or fails to launch:
- Logs a message to stderr:
"PLOT: xdl-charts unavailable (...), using fallback renderer" - Automatically uses original graphics::plot_2d/surface_plot
- Generates PNG files as before
- Works with GUI callbacks if registered
Architecture
PLOT/SURFACE procedure
↓
try_chart_plot / try_surface3d (xdl-charts)
↓
Success? → Open Tauri window → Return
↓
Failure? → Log error → Continue
↓
graphics::plot_2d / surface_plot (fallback)
↓
Generate PNG file → Try GUI callbacks → Return
Implementation Details
Code Locations
- Main procedures:
xdl-stdlib/src/graphics_procs.rsplot_with_keywords()- Enhanced PLOT proceduresurface()- Enhanced SURFACE proceduretry_chart_plot()- xdl-charts helper for PLOTtry_surface3d()- xdl-charts helper for SURFACE
- Charting backend:
xdl-stdlib/src/charting_procs.rsplot()- ECharts line chart generatorsurface3d()- ECharts 3D surface generator
Key Functions
try_chart_plot(x_data, y_data, title) -> Result<(), XdlError>
- Converts arrays to XdlValue
- Calls charting_procs::plot()
- Returns error if unavailable (triggers fallback)
try_surface3d(z_data, title) -> Result<(), XdlError>
- Converts 2D array to XdlValue
- Calls charting_procs::surface3d()
- Returns error if unavailable (triggers fallback)
Testing
Run the test script:
./target/release/xdl examples/charting/test_plot_surface.xdl
Expected output:
- 3 Tauri windows open (2 line plots, 1 surface plot)
- Interactive charts with zoom, pan, rotation
- No fallback messages (if xdl-chart-viewer is available)
Future Enhancements
Potential improvements:
- Support keyword arguments (TITLE, XTITLE, YTITLE) in xdl-charts
- Add CONTOUR procedure support
- Multi-series plotting in single window
- Export charts from Tauri window (PNG, SVG, PDF)
- Real-time data updates
Compatibility
- ✅ Maintains full backward compatibility
- ✅ Works with existing XDL/IDL scripts
- ✅ No breaking changes
- ✅ Graceful degradation when Tauri unavailable
- ✅ Preserves GUI callback system for custom integrations
Related Procedures
New charting procedures that use xdl-charts directly:
CHART_PLOT- Direct access to ECharts line plottingCHART_SCATTER- Scatter plotsCHART_BAR- Bar chartsSURFACE3D- Direct 3D surface plottingSCATTER3D- 3D scatter plots
These provide the same underlying functionality but with explicit names.