Skip to content

Commit f614f6d

Browse files
committed
some types
1 parent 4657007 commit f614f6d

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

src/components/CanvasGeometry.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function CanvasGeometry() {
3636
}
3737
})
3838
const [texture, setTexture] = useState<THREE.DataTexture | THREE.Data3DTexture | null>(null)
39-
const [shape, setShape] = useState<THREE.Vector2 | THREE.Vector3>(new THREE.Vector3(2, 2, 2))
39+
const [shape, setShape] = useState<THREE.Vector3 | THREE.Vector3>(new THREE.Vector3(2, 2, 2))
4040
const [timeSeriesLocs,setTimeSeriesLocs] = useState<TimeSeriesLocs>({uv:new THREE.Vector2(.5,.5), normal:new THREE.Vector3(0,0,1)})
4141
const [valueScales,setValueScales] = useState({maxVal:1,minVal:-1})
4242
const [showTimeSeries,setShowTimeSeries] = useState<boolean>(false)
@@ -46,25 +46,35 @@ export function CanvasGeometry() {
4646
//Need to add a check somewhere here to swap to 2D or 3D based on shape. Probably export two variables from GetArray
4747
GetArray(storeURL, variable).then((result) => {
4848
// result now contains: { data: TypedArray, shape: number[], dtype: string }
49-
const [texture, _shape,scaling] = ArrayToTexture({
49+
const [texture, shape, scaling] = ArrayToTexture({
5050
data: result.data,
5151
shape: result.shape
5252
})
53-
console.log(_shape)
53+
console.log(shape)
5454
if (texture instanceof THREE.DataTexture || texture instanceof THREE.Data3DTexture) {
5555
setTexture(texture)
5656
} else {
5757
console.error("Invalid texture type returned from ArrayToTexture");
5858
setTexture(null);
5959
}
60-
setValueScales(scaling)
60+
// norrow down type before using it!
61+
if (
62+
typeof scaling === 'object' &&
63+
'maxVal' in scaling &&
64+
'minVal' in scaling
65+
) {
66+
setValueScales(scaling as { maxVal: number; minVal: number });
67+
}
6168
const shapeRatio = result.shape[1] / result.shape[2] * 2;
6269
setShape(new THREE.Vector3(2, shapeRatio, 2));
6370
})
6471
}
6572
else{
6673
const texture = DefaultCube();
67-
setTexture(texture)
74+
// again need to check type before using it
75+
if (texture instanceof THREE.Data3DTexture || texture instanceof THREE.DataTexture) {
76+
setTexture(texture);
77+
}
6878
setShape(new THREE.Vector3(2, 2, 2))
6979
}
7080
}, [variable])
@@ -80,7 +90,7 @@ export function CanvasGeometry() {
8090
<Center top position={[-1, 0, 1]}/>
8191
{plotter == "volume" && <>
8292
<DataCube volTexture={texture} shape={shape}/>
83-
<mesh onClick={()=>setShowTimeSeries(x=>true)}>
93+
<mesh onClick={() => setShowTimeSeries(true)}>
8494
<UVCube shape={shape} setTimeSeriesLocs={setTimeSeriesLocs}/>
8595
</mesh>
8696

src/components/TextureMakers.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export function DefaultCube() {
9494
const array: Array = {
9595
data,
9696
shape,
97-
stride:[1,1,1]
9897
}
99-
const [texture,scaling] = ArrayTo3D(array)
98+
const [texture, scaling] = ArrayTo3D(array)
99+
console.log(scaling)
100100
return texture
101101
}

src/components/TimeSeries.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as THREE from 'three'
2-
import { Canvas, createPortal, useThree } from '@react-three/fiber';
3-
import { Center, Html, Hud, OrthographicCamera, PerspectiveCamera, Text } from '@react-three/drei'
2+
// ! don't import things that are not used in the code, build will fail
3+
// import { Canvas, createPortal, useThree } from '@react-three/fiber';
4+
// import { Center, Html, Text } from '@react-three/drei'
5+
import { Hud, OrthographicCamera, Text } from '@react-three/drei'
46
import { useMemo, useState, useEffect } from 'react';
57
import { GetTimeSeries } from './ZarrLoaderLRU';
68

7-
8-
9-
const storeURL = "https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr"
9+
// const storeURL = "https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr"
1010

1111
interface timeSeriesLocs{
1212
uv:THREE.Vector2;
@@ -29,7 +29,7 @@ export function TimeSeries({timeSeriesLocs,DSInfo,scaling} : {timeSeriesLocs:tim
2929
const {variable, storePath} = DSInfo;
3030
const {maxVal,minVal} = scaling;
3131
const [timeSeries, setTimeSeries] = useState<number[]>([0]);
32-
const [xLabls,setXLabels] = useState();
32+
// const [xLabls,setXLabels] = useState();
3333
const [yLabels, setYLabels] = useState();
3434
const verticleScale = 2;
3535
const horizontalScale = 5;
@@ -72,12 +72,14 @@ export function TimeSeries({timeSeriesLocs,DSInfo,scaling} : {timeSeriesLocs:tim
7272
yMax = (yMax-0.5)*verticleScale
7373
const step = (maxVal-minVal)/3;
7474
let yLabels = Array.from({ length: 3 }, (_, i) => Math.round(minVal + step * i))
75-
let yPos = yLabels.map((val,ind)=>{
75+
let yPos = yLabels.map(val => {
7676
return (((val-minVal)/(maxVal-minVal))-0.5)*verticleScale
7777
})
7878
yPos = [yMin, ...yPos.slice(1), yMax]
7979
yLabels = [Math.ceil(minVal),...yLabels.slice(1), Math.floor(maxVal)]
80-
80+
// console unused variables
81+
console.log(xPos,xMin,xMax,yPos,yMin,yMax)
82+
8183
setYLabels({
8284
positions:yPos,
8385
labels:yLabels

src/components/ZarrLoaderLRU.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ export async function GetTimeSeries({TimeSeriesObject}:GetTimeSeries){
9494
//This is a complicated logic check but it works bb
9595
const sliceSize = parseUVCoords({normal,uv})
9696
const slice = sliceSize.map((value, index) =>
97-
value === null || shape[index] === null ? null : value * shape[index]
98-
);
97+
value === null || shape[index] === null ? null : value * shape[index]);
9998
const arr = await zarr.get(outVar,slice)
10099
return arr
101100
}

0 commit comments

Comments
 (0)