@@ -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 } ` } >
0 commit comments