Skip to content

Commit 4e2777e

Browse files
committed
One Canvas
1 parent 501b120 commit 4e2777e

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

src/components/plots/AxisLines.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,20 @@ const AXIS_CONSTANTS = {
2828
};
2929

3030
const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, flipDown: boolean}) =>{
31-
const {dimArrays, dimNames, dimUnits, dataShape, revY} = useGlobalStore(useShallow(state => ({
31+
const {dimArrays, dimNames, dimUnits, dataShape, revY, isFlat} = useGlobalStore(useShallow(state => ({
3232
dimArrays: state.dimArrays,
3333
dimNames: state.dimNames,
3434
dimUnits: state.dimUnits,
3535
dataShape: state.dataShape,
36-
revY: state.flipY
36+
revY: state.flipY, isFlat:state.isFlat
3737
})))
3838

3939
const {xRange, yRange, zRange, plotType, timeScale, animProg, zSlice, ySlice, xSlice} = usePlotStore(useShallow(state => ({
40-
xRange: state.xRange,
41-
yRange: state.yRange,
42-
zRange: state.zRange,
43-
plotType: state.plotType,
44-
timeScale: state.timeScale,
45-
animProg: state.animProg,
46-
zSlice: state.zSlice,
47-
ySlice: state.ySlice,
48-
xSlice: state.xSlice
40+
xRange: state.xRange, yRange: state.yRange,
41+
zRange: state.zRange, plotType: state.plotType,
42+
timeScale: state.timeScale, animProg: state.animProg,
43+
zSlice: state.zSlice, ySlice: state.ySlice,
44+
xSlice: state.xSlice,
4945
})))
5046

5147
const {hideAxis, hideAxisControls} = useImageExportStore(useShallow( state => ({
@@ -63,6 +59,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
6359
revY ? dimArrays[1].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined).reverse() : dimArrays[1].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined),
6460
dimArrays[2].slice(xSlice[0], xSlice[1] ? xSlice[1] : undefined),
6561
]
62+
const cursor = isFlat || plotType === "flat" ? "default" : "pointer"
6663

6764
const [xResolution, setXResolution] = useState<number>(AXIS_CONSTANTS.INITIAL_RESOLUTION)
6865
const [yResolution, setYResolution] = useState<number>(AXIS_CONSTANTS.INITIAL_RESOLUTION)
@@ -156,7 +153,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
156153
material-depthTest={false}
157154
position={[xTitleOffset, -AXIS_CONSTANTS.TITLE_FONT_SIZE_FACTOR * globalScale / 2, 0]}
158155
onClick={e=>setXResolution(x=> Math.min(x+1,AXIS_CONSTANTS.MAX_RESOLUTION))}
159-
onPointerEnter={e=>document.body.style.cursor = 'pointer'}
156+
onPointerEnter={e=>document.body.style.cursor = cursor}
160157
onPointerLeave={e=>document.body.style.cursor = 'default'}
161158
>
162159
+
@@ -307,7 +304,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
307304
material-depthTest={false}
308305
position={[0, -yTitleOffset, 0]}
309306
onClick={e=>setYResolution(x=> Math.max(x-1,AXIS_CONSTANTS.MIN_RESOLUTION))}
310-
onPointerEnter={e=>document.body.style.cursor = 'pointer'}
307+
onPointerEnter={e=>document.body.style.cursor = cursor}
311308
onPointerLeave={e=>document.body.style.cursor = 'default'}
312309
>
313310
-
@@ -387,6 +384,8 @@ const FlatAxis = () =>{
387384

388385
const [xResolution, setXResolution] = useState<number>(FLAT_AXIS_CONSTANTS.INITIAL_RESOLUTION)
389386
const [yResolution, setYResolution] = useState<number>(FLAT_AXIS_CONSTANTS.INITIAL_RESOLUTION)
387+
388+
const cursor = isFlat || plotType === "flat" ? "default" : "pointer"
390389

391390
const { axisArrays, axisUnits, axisNames } = useMemo(() => {
392391

@@ -499,7 +498,7 @@ const FlatAxis = () =>{
499498
material-depthTest={false}
500499
position={[-xTitleOffset, -0.05, 0]}
501500
onClick={e=>setXResolution(x=> Math.max(x-1,FLAT_AXIS_CONSTANTS.MIN_RESOLUTION))}
502-
onPointerEnter={e=>document.body.style.cursor = 'pointer'}
501+
onPointerEnter={e=>document.body.style.cursor = cursor}
503502
onPointerLeave={e=>document.body.style.cursor = 'default'}
504503
>
505504
-
@@ -547,7 +546,7 @@ const FlatAxis = () =>{
547546
material-depthTest={false}
548547
position={[ 0.0, yTitleOffset, 0]}
549548
onClick={e=>setYResolution(x=> Math.min(x+1,FLAT_AXIS_CONSTANTS.MAX_RESOLUTION))}
550-
onPointerEnter={e=>document.body.style.cursor = 'pointer'}
549+
onPointerEnter={e=>document.body.style.cursor = cursor}
551550
onPointerLeave={e=>document.body.style.cursor = 'default'}
552551
>
553552
+
@@ -562,7 +561,7 @@ const FlatAxis = () =>{
562561
material-depthTest={false}
563562
position={[0.0, -yTitleOffset, 0]}
564563
onClick={e=>setYResolution(x=> Math.max(x-1,FLAT_AXIS_CONSTANTS.MIN_RESOLUTION))}
565-
onPointerEnter={e=>document.body.style.cursor = 'pointer'}
564+
onPointerEnter={e=>document.body.style.cursor = cursor}
566565
onPointerLeave={e=>document.body.style.cursor = 'default'}
567566
>
568567
-
@@ -583,6 +582,9 @@ export const AxisLines = () => {
583582
const {isFlat} = useGlobalStore(useShallow(state => ({
584583
isFlat: state.isFlat
585584
})))
585+
const {plotType} = usePlotStore(useShallow(state=>({
586+
plotType:state.plotType
587+
})))
586588
useFrame(({camera})=>{
587589
const shouldFlipX = Math.abs(camera.rotation.z) > Math.PI / 2
588590
if (flipX !== shouldFlipX) {
@@ -601,11 +603,11 @@ export const AxisLines = () => {
601603
}
602604

603605
})
604-
606+
const cond = isFlat || plotType == "flat"
605607
return (
606608
<>
607-
{!isFlat && <CubeAxis flipX={flipX} flipY={flipY} flipDown={flipDown} />}
608-
<FlatAxis />
609+
{!cond && <CubeAxis flipX={flipX} flipY={flipY} flipDown={flipDown} />}
610+
{cond && <FlatAxis />}
609611
</>
610612
)
611613
}

src/components/plots/Plot.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const Orbiter = ({isFlat} : {isFlat : boolean}) =>{
7878

7979
return () => cancelAnimationFrame(frameId);
8080
}
81-
},[resetCamera])
81+
},[resetCamera, isFlat])
8282

8383
useEffect(()=>{
8484
if (hasMounted.current){
@@ -112,7 +112,6 @@ const Orbiter = ({isFlat} : {isFlat : boolean}) =>{
112112
orbitRef.current.update()
113113
}
114114
}
115-
116115
},[useOrtho])
117116

118117
return (
@@ -316,7 +315,6 @@ const Plot = ({ZarrDS}:{ZarrDS: ZarrDataset}) => {
316315
{show && <Colorbar units={stableMetadata?.units} metadata={stableMetadata} valueScales={valueScales}/>}
317316
<Nav />
318317
{(isFlat || plotType == "flat") && <AnalysisInfo loc={loc} show={showInfo} info={[...coords.current,val.current]}/> }
319-
{((!isFlat && plotType != "flat") || (isFlat && plotType === 'sphere')) && <>
320318
<Canvas id='main-canvas' camera={{ position: isFlat ? [0,0,5] : [-4.5, 3, 4.5], fov: 50 }}
321319
frameloop="demand"
322320
gl={{ preserveDrawingBuffer: true }}
@@ -340,22 +338,15 @@ const Plot = ({ZarrDS}:{ZarrDS: ZarrDataset}) => {
340338
{displaceSurface ? <Sphere textures={textures} ZarrDS={ZarrDS} /> : <SphereBlocks textures={textures} />}
341339
</>
342340
}
343-
<Orbiter isFlat={false} />
344-
</Canvas>
345-
</>}
346-
341+
<Orbiter isFlat={(isFlat || (!isFlat && plotType == "flat"))} />
347342
{(isFlat || (!isFlat && plotType == "flat")) && <>
348-
<Canvas id='main-canvas' camera={{ position: [0,0,5], zoom: 1000 }}
349-
orthographic frameloop="demand"
350-
>
351-
<ExportCanvas show={show}/>
352-
<CountryBorders/>
353-
{show && <AxisLines />}
354343
{displaceSurface && <FlatMap textures={textures as THREE.DataTexture | THREE.Data3DTexture[]} infoSetters={infoSetters} ZarrDS={ZarrDS}/> }
355344
{!displaceSurface && <FlatBlocks textures={textures} />}
356-
<Orbiter isFlat={true}/>
357-
</Canvas>
358-
</>}
345+
</>
346+
}
347+
348+
</Canvas>
349+
359350

360351
</div>
361352
)

0 commit comments

Comments
 (0)