diff --git a/src/components/plots/Plot.tsx b/src/components/plots/Plot.tsx index d2d27630..73f90932 100644 --- a/src/components/plots/Plot.tsx +++ b/src/components/plots/Plot.tsx @@ -72,8 +72,6 @@ const Orbiter = ({isFlat} : {isFlat : boolean}) =>{ ); } - - const Plot = ({ZarrDS}:{ZarrDS: ZarrDataset}) => { const { @@ -122,7 +120,7 @@ const Plot = ({ZarrDS}:{ZarrDS: ZarrDataset}) => { const [showInfo, setShowInfo] = useState(false) const [loc, setLoc] = useState([0,0]) - const [texture, setTexture] = useState(null) + const [textures, setTextures] = useState(null) const [show, setShow] = useState(true) //Prevents rendering of 3D objects until data is fully loaded in //DATA LOADING @@ -131,12 +129,18 @@ const Plot = ({ZarrDS}:{ZarrDS: ZarrDataset}) => { setShowLoading(true); setShow(false) try{ + if (textures) { + textures.forEach(tex =>{ + tex.dispose(); + tex.source.data = null + }); + } ZarrDS.GetArray(variable, {xSlice, ySlice, zSlice}).then((result) => { const [tempTexture, scaling] = ArrayToTexture({ data: result.data, shape: result.shape }) - setTexture(tempTexture) + setTextures(tempTexture) if (result.scalingFactor){ const {maxVal, minVal} = scaling setValueScales({ maxVal: maxVal*(Math.pow(10,result.scalingFactor)), minVal: minVal*(Math.pow(10,result.scalingFactor)) }); @@ -195,15 +199,16 @@ const Plot = ({ZarrDS}:{ZarrDS: ZarrDataset}) => { }else{ setMetadata(null) } - }, [reFetch]) useEffect(()=>{ // Reset after analysis mode - if(!analysisMode){ + if(!analysisMode && show){ const {dataShape} = useGlobalStore.getState(); setIsFlat(dataShape.length == 2) const newText = GetCurrentTexture(dataShape) - setTexture(newText) + if (newText){ + setTextures(newText) + } } },[analysisMode]) @@ -213,12 +218,13 @@ const Plot = ({ZarrDS}:{ZarrDS: ZarrDataset}) => { coords, val }),[]) + const Nav = useMemo(()=>Navbar,[]) return (
- + {show && }