Skip to content

Commit 1d0db38

Browse files
authored
Merge pull request #520 from EarthyScience/jp/tweaks
Allow window resizing in plot area
2 parents c70771b + 04327e7 commit 1d0db38

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

src/components/plots/plotarea/FixedTicks.tsx

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export function FixedTicks({
3535
yScale = 1,
3636
xScale=1,
3737
}: FixedTicksProps) {
38-
const { camera } = useThree()
38+
const { camera, size } = useThree()
39+
const initSize = useRef(size)
3940
const [bounds, setBounds] = useState<ViewportBounds>({ left: 0, right: 0, top: 0, bottom: 0 })
4041
const {dimCoords, dimArrays, plotDim, valueScales} = useGlobalStore(
4142
useShallow(state=>({
@@ -88,19 +89,6 @@ export function FixedTicks({
8889
}
8990
},[xDimArray,coords])
9091

91-
const initialBounds = useMemo<ViewportBounds>(()=>{
92-
const worldWidth = window.innerWidth
93-
const worldHeight = (window.innerHeight-height)
94-
95-
const newBounds = {
96-
left: -worldWidth / 2 + camera.position.x,
97-
right: worldWidth / 2 + camera.position.x,
98-
top: worldHeight / 2 + camera.position.y,
99-
bottom: -worldHeight / 2 + camera.position.y
100-
}
101-
return newBounds;
102-
},[])
103-
10492
const [zoom, setZoom] = useState(camera.zoom)
10593

10694
const sizes = useMemo(() => {
@@ -113,17 +101,13 @@ export function FixedTicks({
113101
}
114102
}, [camera.zoom, tickSize, fontSize])
115103

116-
// Update bounds when camera moves
117-
// TODO: update bounds when camera zooms
118-
119-
120104

121105
useFrame(() => {
122106
if (camera.zoom !== zoom) {
123-
setZoom(camera.zoom) // this is not working properly
107+
setZoom(camera.zoom)
124108
}
125-
const worldWidth = window.innerWidth / camera.zoom
126-
const worldHeight = (window.innerHeight-height) / camera.zoom
109+
const worldWidth = size.width / camera.zoom
110+
const worldHeight = size.height / camera.zoom
127111
const newBounds = {
128112
left: -worldWidth / 2 + camera.position.x,
129113
right: worldWidth / 2 + camera.position.x,
@@ -161,9 +145,12 @@ export function FixedTicks({
161145
}
162146
};
163147
}, [height]);
164-
const stickyLines = 1; //This is the amount of pixels you need to zoome before the ticks readjust
165148
const vertY = (bounds.top+bounds.bottom)/2
166149
const horX = (bounds.left+bounds.right)/2 //Moved calcs here to reduce calcs
150+
const rescaleSizes = {
151+
width: initSize.current.width/size.width,
152+
height: initSize.current.height/size.height
153+
}
167154
return (
168155
<group >
169156
{/* Grid Lines */}
@@ -172,9 +159,8 @@ export function FixedTicks({
172159
{/* Vertical grid lines */}
173160
{Array.from({ length: xTickCount }, (_, i) => {
174161
if (i === 0 || i === xTickCount-1) return null; // Skip edges
175-
const x = Math.round(bounds.left / stickyLines) * stickyLines +
176-
(Math.round(bounds.right / stickyLines) *stickyLines - Math.round(bounds.left / stickyLines) * stickyLines) * (i / (xTickCount-1))
177-
const normX = x/xScale/(initialBounds.right - initialBounds.left)+.5;
162+
const x = (size.width*(i / (xTickCount-1))-size.width/2 + camera.position.x)
163+
const normX = (x/(rescaleSizes.width))/xScale/size.width+.5;
178164
const y = vertY
179165
return (
180166
<Fragment key={`vert-group-${i}`}>
@@ -231,8 +217,8 @@ export function FixedTicks({
231217
{/* Horizontal grid lines */}
232218
{Array.from({ length: yTickCount }, (_, i) => {
233219
if (i === 0 || i === yTickCount-1) return null; // Skip edges
234-
const y = (bounds.bottom + (bounds.top - bounds.bottom) * (i / (yTickCount-1)))
235-
const normY = (y/yScale/(bounds.top - bounds.bottom)/zoom)+.5
220+
const y = (size.height*(i / (yTickCount-1))-size.height/2 + camera.position.y)
221+
const normY = (y/(rescaleSizes.height))/yScale/size.height+.5;
236222
const x = horX
237223
return (
238224
<Fragment key={`vert-group-${i}`}>

src/components/plots/plotarea/PlotPoints.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function PlotPoints({ points, tsID, pointSetters, scalers }: { points: THREE.Vec
4444
ref.current.setMatrixAt(i, dummy.matrix)
4545
}
4646
ref.current.instanceMatrix.needsUpdate = true
47+
ref.current.computeBoundingSphere();
4748
}
4849
}, [points, zoom, geometry, material, xScale, yScale, pointSize]) // Add xScale, yScale as dependencies
4950

src/components/ui/Colorbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React, {useRef, useEffect, useMemo, useState} from 'react'
77
import { useGlobalStore, usePlotStore, useAnalysisStore } from '@/utils/GlobalStates'
88
import { useShallow } from 'zustand/shallow'
99
import './css/Colorbar.css'
10-
import { linspace, TwoDecimals } from '@/utils/HelperFuncs';
10+
import { linspace } from '@/utils/HelperFuncs';
1111
import Metadata from "./MetaData";
1212

1313
const operationMap = {
@@ -40,7 +40,7 @@ const operationMap = {
4040

4141
function Num2String(value: number){
4242
if ((Math.abs(value) > 1e-3 && Math.abs(value) < 1e6) || value === 0){
43-
return value.toFixed(2)
43+
return parseFloat(value.toFixed(2)).toString() // This seems redundant but it removes trailing zeros
4444
} else{
4545
return value.toExponential(2)
4646
}

0 commit comments

Comments
 (0)