@@ -2,15 +2,14 @@ import { OrbitControls } from '@react-three/drei';
22import React , { useMemo } from 'react' ;
33import { useState , useEffect } from 'react' ;
44import * as THREE from 'three' ;
5- import { PointCloud , UVCube , DataCube } from '@/components/plots' ;
5+ import { PointCloud , UVCube , DataCube , FlatMap } from '@/components/plots' ;
66import { Canvas , useThree } from '@react-three/fiber' ;
77import { ArrayToTexture , DefaultCubeTexture } from '@/components/textures' ;
88import { ZarrDataset } from '../zarr/ZarrLoaderLRU' ;
99import { useGlobalStore , usePlotStore } from '@/utils/GlobalStates' ;
1010import { useShallow } from 'zustand/shallow' ;
1111import { Navbar , PlotLineButton } from '../ui' ;
1212
13-
1413interface PlotParameters {
1514 values :{
1615 ZarrDS : ZarrDataset ;
@@ -21,7 +20,6 @@ interface PlotParameters{
2120}
2221
2322const Plot = ( { values, setShowLoading} :PlotParameters ) => {
24-
2523 const {
2624 setShape,
2725 setFlipY,
@@ -39,11 +37,13 @@ const Plot = ({values,setShowLoading}:PlotParameters) => {
3937 setDimNames :state . setDimNames ,
4038 setDimUnits :state . setDimUnits }
4139 ) ) )
42- const { colormap, variable} = useGlobalStore ( useShallow ( state => ( { colormap : state . colormap , variable : state . variable } ) ) )
43-
40+ const { colormap, variable, isFlat, setIsFlat} = useGlobalStore ( useShallow ( state => ( {
41+ colormap : state . colormap , variable : state . variable , isFlat : state . isFlat , setIsFlat : state . setIsFlat
42+ } ) ) )
4443 const { ZarrDS, canvasWidth} = values ;
4544 const plotType = usePlotStore ( state => state . plotType )
4645
46+
4747 const [ texture , setTexture ] = useState < THREE . DataTexture | THREE . Data3DTexture | null > ( null )
4848 // const [currentBg, setCurrentBg] = useState(bgcolor || 'var(--background)')
4949 const [ show , setShow ] = useState < boolean > ( true )
@@ -100,6 +100,12 @@ const Plot = ({values,setShowLoading}:PlotParameters) => {
100100 setValueScales ( scaling as { maxVal : number ; minVal : number } ) ;
101101
102102 }
103+ if ( result . shape . length == 2 ) {
104+ setIsFlat ( true )
105+ }
106+ else {
107+ setIsFlat ( false )
108+ }
103109 const shapeRatio = result . shape [ 1 ] / result . shape [ 2 ] * 2 ;
104110 setShape ( new THREE . Vector3 ( 2 , shapeRatio , 2 ) ) ;
105111 setShowLoading ( false )
@@ -110,10 +116,18 @@ const Plot = ({values,setShowLoading}:PlotParameters) => {
110116 setMetadata ( result ) ;
111117 const [ dimArrs , dimMetas , dimNames ] = ZarrDS . GetDimArrays ( )
112118 setDimArrays ( dimArrs )
113- if ( dimArrs [ 1 ] [ 1 ] < dimArrs [ 1 ] [ 0 ] )
114- { setFlipY ( true ) }
115- else
116- { setFlipY ( false ) }
119+ if ( dimArrs . length > 2 ) {
120+ if ( dimArrs [ 1 ] [ 1 ] < dimArrs [ 1 ] [ 0 ] )
121+ { setFlipY ( true ) }
122+ else
123+ { setFlipY ( false ) }
124+ }
125+ else {
126+ if ( dimArrs [ 0 ] [ 1 ] < dimArrs [ 0 ] [ 0 ] )
127+ { setFlipY ( true ) }
128+ else
129+ { setFlipY ( false ) }
130+ }
117131 const tempDimUnits = [ ]
118132 for ( const meta of dimMetas ) {
119133 tempDimUnits . push ( meta . units )
@@ -135,26 +149,33 @@ const Plot = ({values,setShowLoading}:PlotParameters) => {
135149 width : windowWidth - canvasWidth
136150 } }
137151 >
138- { plotType == "volume" && < PlotLineButton /> }
152+ { plotType == "volume" && ! isFlat && < PlotLineButton /> }
139153 < Nav />
140- < Canvas camera = { { position : [ - 4.5 , 3 , 4.5 ] , fov : 50 } }
154+
155+ { ! isFlat && < >
156+ < Canvas camera = { { position : isFlat ? [ 0 , 0 , 5 ] : [ - 4.5 , 3 , 4.5 ] , fov : 50 } }
141157 frameloop = "demand"
142- style = { {
143- // background: currentBg
144- } }
145158 >
146- { /* Volume Plots */ }
147159 { plotType == "volume" && show && < >
148160 < DataCube volTexture = { texture } />
149161 < UVCube ZarrDS = { ZarrDS } />
150162 </ > }
151- { /* Point Clouds */ }
152163 { plotType == "point-cloud" && show && < PointCloud textures = { { texture, colormap} } /> }
153-
154- < OrbitControls minPolarAngle = { 0 } maxPolarAngle = { Math . PI / 2 } enablePan = { false }
155- maxDistance = { 50 }
156- />
164+ < OrbitControls minPolarAngle = { 0 } maxPolarAngle = { Math . PI / 2 } enablePan = { false } maxDistance = { 50 } />
157165 </ Canvas >
166+ </ > }
167+
168+
169+ { isFlat && < >
170+ < Canvas camera = { { position : [ 0 , 0 , 5 ] , zoom : 1000 } }
171+ frameloop = "demand"
172+ orthographic
173+ >
174+ < FlatMap texture = { texture as THREE . DataTexture } />
175+ < OrbitControls enableRotate = { false } enablePan = { true } maxDistance = { 50 } minZoom = { 50 } maxZoom = { 2000 } />
176+ </ Canvas >
177+ </ > }
178+
158179 </ div >
159180 )
160181}
0 commit comments