@@ -33,6 +33,7 @@ var lastvolume = null;
3333var lastvolumedata = null ;
3434var lastvolumedim = [ ] ;
3535var lastclim = 0 ;
36+ var uplotInstance = null ;
3637var reqid = undefined ;
3738
3839var canvas = null ;
@@ -133,6 +134,12 @@ function destroyPreview() {
133134 lastvolume = null ;
134135 lastvolumedata = null ;
135136 texture = undefined ;
137+
138+ if ( uplotInstance !== null ) {
139+ uplotInstance . destroy ( ) ;
140+ uplotInstance = null ;
141+ }
142+ $ ( "#chartpanel" ) . hide ( ) . html ( "" ) ;
136143}
137144
138145function drawpreview ( cfg ) {
@@ -428,22 +435,32 @@ function dopreview(key, idx, isinternal, hastime) {
428435 ? "y" + i
429436 : hastime [ i ] ;
430437 }
431- let u = new uPlot ( opts , plotdata , document . getElementById ( "plotchart" ) ) ;
438+ // let u = new uPlot(opts, plotdata, document.getElementById("plotchart"));
439+ if ( uplotInstance !== null ) {
440+ uplotInstance . destroy ( ) ;
441+ uplotInstance = null ;
442+ }
443+ uplotInstance = new uPlot (
444+ opts ,
445+ plotdata ,
446+ document . getElementById ( "plotchart" )
447+ ) ;
432448 } else {
433- let u = new uPlot (
449+ // let u = new uPlot(
450+ // opts,
451+ // [[...Array(dataroot.length).keys()], dataroot],
452+ // document.getElementById("plotchart")
453+ // );
454+ if ( uplotInstance !== null ) {
455+ uplotInstance . destroy ( ) ;
456+ uplotInstance = null ;
457+ }
458+ uplotInstance = new uPlot (
434459 opts ,
435460 [ [ ...Array ( dataroot . length ) . keys ( ) ] , dataroot ] ,
436461 document . getElementById ( "plotchart" )
437462 ) ;
438463 }
439- // add spinner
440- // --- NEW LOGIC for 2D plot ---
441- // Signal that the 2D plot has just been created and is now visible.
442- // if (typeof window.__onPreviewReady === "function") {
443- // window.__onPreviewReady();
444- // window.__onPreviewReady = null; // Clean up to prevent accidental re-firing
445- // }
446- // --- END NEW LOGIC ---
447464
448465 // for spinner
449466 // --- Signal React that 2D preview is ready ---
0 commit comments