@@ -2,29 +2,24 @@ import * as THREE from 'three'
22THREE . Cache . enabled = true ;
33import { Canvas } from '@react-three/fiber' ;
44import { Center , OrbitControls , Environment } from '@react-three/drei'
5- import { variables , ZarrDataset , parseUVCoords } from '@/components/ZarrLoaderLRU'
5+ import { variables , ZarrDataset } from '@/components/ZarrLoaderLRU'
66import { useEffect , useState , useMemo } from 'react' ;
77import { useControls } from 'leva'
8- import { DataCube , PointCloud , UVCube , PlotLine , PlotArea , FixedTicks } from './PlotObjects' ;
8+ import { PointCloud , UVCube , PlotArea , DataCube } from './PlotObjects' ;
99import { GetColorMapTexture , ArrayToTexture , DefaultCube , colormaps } from './Textures' ;
10- import { Metadata , ResizeBar } from './UI' ;
10+ import { Metadata } from './UI' ;
11+ import { plotContext , DimCoords } from './Contexts' ;
1112
1213const storeURL = "https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr"
1314
14- interface TimeSeriesLocs {
15- uv :THREE . Vector2 ;
16- normal :THREE . Vector3
17- }
18- interface Coord {
19- name : string ;
20- loc : number ;
21- units : string ;
22- }
23-
24- interface DimCoords {
25- first : Coord ;
26- second : Coord ;
27- plot : Pick < Coord , "units" > ; // Only units
15+ function Loading ( { showLoading} :{ showLoading :boolean } ) {
16+ return (
17+ < div className = 'messages' >
18+ { showLoading && < div className = 'loading' >
19+ Loading...
20+ </ div > }
21+ </ div >
22+ )
2823}
2924
3025export function CanvasGeometry ( ) {
@@ -53,22 +48,18 @@ export function CanvasGeometry() {
5348
5449 const [ texture , setTexture ] = useState < THREE . DataTexture | THREE . Data3DTexture | null > ( null ) //Main Texture
5550 const [ shape , setShape ] = useState < THREE . Vector3 | THREE . Vector3 > ( new THREE . Vector3 ( 2 , 2 , 2 ) )
56- const [ timeSeriesLocs , setTimeSeriesLocs ] = useState < TimeSeriesLocs > ( { uv :new THREE . Vector2 ( .5 , .5 ) , normal :new THREE . Vector3 ( 0 , 0 , 1 ) } )
5751 const [ valueScales , setValueScales ] = useState ( { maxVal :1 , minVal :- 1 } )
5852 const [ colormap , setColormap ] = useState < THREE . DataTexture > ( GetColorMapTexture ( ) )
5953 const [ timeSeries , setTimeSeries ] = useState < number [ ] > ( [ 0 ] ) ;
6054 const [ showLoading , setShowLoading ] = useState < boolean > ( false ) ;
61- const [ metadata , setMetadata ] = useState < Object [ ] > ( [ { } , { } ] )
55+ const [ metadata , setMetadata ] = useState < object [ ] | null > ( null )
6256
6357 //Timeseries Plotting Information
6458 const [ dimArrays , setDimArrays ] = useState ( [ [ 0 ] , [ 0 ] , [ 0 ] ] )
6559 const [ dimNames , setDimNames ] = useState < string [ ] > ( [ "default" ] )
6660 const [ dimUnits , setDimUnits ] = useState < string [ ] > ( [ "Default" ] ) ;
67- const [ dimCoords , setDimCoords ] = useState < Object | null > ( null ) ;
61+ const [ dimCoords , setDimCoords ] = useState < DimCoords > ( ) ;
6862 const [ plotDim , setPlotDim ] = useState < number > ( 0 )
69- const [ height , setHeight ] = useState < number > ( Math . round ( window . innerHeight - ( window . innerHeight * 0.15 ) - 48 ) )
70-
71-
7263 const ZarrDS = useMemo ( ( ) => new ZarrDataset ( storeURL ) , [ ] )
7364
7465 useEffect ( ( ) => {
@@ -104,6 +95,7 @@ export function CanvasGeometry() {
10495 setShape ( new THREE . Vector3 ( 2 , shapeRatio , 2 ) ) ;
10596 setShowLoading ( false )
10697 } )
98+ //Get Metadata
10799 ZarrDS . GetAttributes ( variable ) . then ( ( result ) => {
108100 setMetadata ( result ) ;
109101 const [ dimArrs , dimMetas ] = ZarrDS . GetDimArrays ( )
@@ -126,51 +118,48 @@ export function CanvasGeometry() {
126118 setTexture ( texture ) ;
127119 }
128120 setShape ( new THREE . Vector3 ( 2 , 2 , 2 ) )
129- setMetadata ( [ { } ] )
121+ setMetadata ( null )
130122 }
131123 } , [ variable ] )
132124
133- //TIMESERIES
134- useEffect ( ( ) => {
135- if ( ZarrDS && metadata ) {
136- ZarrDS . GetTimeSeries ( timeSeriesLocs ) . then ( ( e ) => setTimeSeries ( e ) )
137- const plotDim = ( timeSeriesLocs . normal . toArray ( ) ) . map ( ( val , idx ) => {
138- if ( Math . abs ( val ) > 0 ) {
139- return idx ;
140- }
141- return null ; } ) . filter ( idx => idx !== null ) ;
142- setPlotDim ( 2 - plotDim [ 0 ] ) //I think this 2 is only if there are 3-dims. Need to rework the logic
143-
144- const coordUV = parseUVCoords ( { normal :timeSeriesLocs . normal , uv :timeSeriesLocs . uv } )
145- let dimCoords = coordUV . map ( ( val , idx ) => val ? dimArrays [ idx ] [ Math . round ( val * dimArrays [ idx ] . length ) ] : null )
146- const thisDimNames = dimNames . filter ( ( _ , idx ) => dimCoords [ idx ] !== null )
147- const thisDimUnits = dimUnits . filter ( ( _ , idx ) => dimCoords [ idx ] !== null )
148- dimCoords = dimCoords . filter ( val => val !== null )
149- const dimObj = {
150- first :{
151- name :thisDimNames [ 0 ] ,
152- loc :dimCoords [ 0 ] ,
153- units :thisDimUnits [ 0 ]
154- } ,
155- second :{
156- name :thisDimNames [ 1 ] ,
157- loc :dimCoords [ 1 ] ,
158- units :thisDimUnits [ 1 ]
159- } ,
160- plot :{
161- units :dimUnits [ 2 - plotDim [ 0 ] ]
162- }
163- }
164- setDimCoords ( dimObj )
125+ //These are passed to the UVCube (will be renamed) to extract the timeseries info
126+ const timeSeriesObj = {
127+ setters :{
128+ setTimeSeries,
129+ setPlotDim,
130+ setDimCoords
131+ } ,
132+ values :{
133+ ZarrDS,
134+ shape,
135+ dimArrays,
136+ dimNames,
137+ dimUnits
165138 }
166- } , [ timeSeriesLocs ] )
139+ }
140+
141+ const defaultDimCoords : DimCoords = {
142+ first : { name : "" , loc : 0 , units : "" } ,
143+ second : { name : "" , loc : 0 , units : "" } ,
144+ plot : { units : "" }
145+ } ;
146+
147+ //This is the data being passed down the plot tree
148+ const plotObj = {
149+ coords : dimCoords ?? defaultDimCoords ,
150+ plotDim,
151+ dimNames,
152+ dimUnits,
153+ dimArrays,
154+ plotUnits :metadata ? ( metadata as any ) . units : "Default" ,
155+ yRange :[ valueScales . minVal , valueScales . maxVal ] ,
156+ timeSeries,
157+ scaling :{ ...valueScales , colormap}
158+ }
159+
167160 return (
168161 < >
169- < div className = 'messages' >
170- { showLoading && < div className = 'loading' >
171- Loading...
172- </ div > }
173- </ div >
162+ < Loading showLoading = { showLoading } />
174163 < div className = 'canvas' >
175164 < Canvas shadows camera = { { position : [ - 4.5 , 3 , 4.5 ] , fov : 50 } }
176165 frameloop = "demand"
@@ -180,7 +169,7 @@ export function CanvasGeometry() {
180169 { /* Volume Plots */ }
181170 { plotter == "volume" && < >
182171 < DataCube volTexture = { texture } shape = { shape } colormap = { colormap } />
183- < UVCube shape = { shape } setTimeSeriesLocs = { setTimeSeriesLocs } />
172+ < UVCube { ... timeSeriesObj } />
184173 </ > }
185174 { /* Point Clouds Plots */ }
186175 { plotter == "point-cloud" && < PointCloud textures = { { texture, colormap} } /> }
@@ -194,16 +183,9 @@ export function CanvasGeometry() {
194183
195184 { metadata && < Metadata data = { metadata } /> }
196185
197- < ResizeBar height = { height } setHeight = { setHeight } />
198- < PlotArea height = { height } coords = { dimCoords as DimCoords } >
199- < PlotLine
200- data = { timeSeries }
201- lineWidth = { 20 }
202- scaling = { { ...valueScales , colormap} }
203- height = { height }
204- />
205- { dimCoords && < FixedTicks color = 'white' xDimArray = { dimArrays [ plotDim ] } yRange = { [ valueScales . minVal , valueScales . maxVal ] } coords = { dimCoords as DimCoords } height = { height } /> }
206- </ PlotArea >
186+ < plotContext . Provider value = { plotObj } >
187+ < PlotArea />
188+ </ plotContext . Provider >
207189
208190 { /* <Leva theme={lightTheme} /> */ }
209191 </ >
0 commit comments