@@ -15,6 +15,7 @@ interface CanvasProps {
1515 selectedBits : BitSelection ;
1616 isDisplay : boolean ;
1717 canvasCount ?: number ;
18+ currentValue ?:number ;
1819 Zoom : number ;
1920 currentSnapshot : number ;
2021 snapShotRef : React . MutableRefObject < boolean [ ] > ;
@@ -27,6 +28,7 @@ const Canvas = forwardRef(
2728 selectedBits,
2829 isDisplay,
2930 canvasCount = 6 , // default value in case not provided
31+ currentValue= 4 ,
3032 Zoom,
3133 currentSnapshot,
3234 snapShotRef,
@@ -37,14 +39,14 @@ const Canvas = forwardRef(
3739 let previousCounter : number | null = null ; // Variable to store the previous counter value for loss detection
3840 const canvasContainerRef = useRef < HTMLDivElement > ( null ) ;
3941 const [ numChannels , setNumChannels ] = useState < number > ( canvasCount ) ;
42+ const numXRef = useRef < number > ( 2000 ) ; // To track the calculated value
4043 const [ canvases , setCanvases ] = useState < HTMLCanvasElement [ ] > ( [ ] ) ;
44+ const [ samplingRate , setSamplingRate ] = useState < number > ( 500 ) ;
4145 const [ wglPlots , setWglPlots ] = useState < WebglPlot [ ] > ( [ ] ) ;
4246 const [ lines , setLines ] = useState < WebglLine [ ] > ( [ ] ) ;
4347 const linesRef = useRef < WebglLine [ ] > ( [ ] ) ;
44- const samplingRate = 500 ; // Set the sampling rate in Hz
4548 const sweepPositions = useRef < number [ ] > ( new Array ( 6 ) . fill ( 0 ) ) ; // Array for sweep positions
4649 const currentSweepPos = useRef < number [ ] > ( new Array ( 6 ) . fill ( 0 ) ) ; // Array for sweep positions
47- let numX : number ;
4850 const array3DRef = useRef < number [ ] [ ] [ ] > (
4951 Array . from ( { length : 6 } , ( ) =>
5052 Array . from ( { length : 6 } , ( ) => Array ( ) )
@@ -53,21 +55,26 @@ const Canvas = forwardRef(
5355 const activebuffer = useRef ( 0 ) ; // Initialize useRef with 0
5456 const indicesRef = useRef < number [ ] > ( [ ] ) ; // Use `useRef` for indices
5557
58+ //select point
5659 const getpoints = useCallback ( ( bits : BitSelection ) : number => {
5760 switch ( bits ) {
5861 case "ten" :
59- return samplingRate * 2 ;
62+ return 250 ;
6063 case "twelve" :
61- return samplingRate * 4 ;
6264 case "fourteen" :
63- return samplingRate * 4 ;
6465 case "sixteen" :
65- return samplingRate * 4 ;
66+ return 500 ;
6667 default :
67- return 0 ; // Or any other fallback value you'd like
68+ return 500 ; // Default fallback
6869 }
6970 } , [ ] ) ;
70- numX = getpoints ( selectedBits ) ;
71+
72+
73+ useEffect ( ( ) => {
74+ numXRef . current = ( getpoints ( selectedBits ) * currentValue ) + 1 ;
75+
76+ } , [ currentValue ] ) ;
77+
7178 const prevCanvasCountRef = useRef < number > ( canvasCount ) ;
7279
7380 const processIncomingData = ( incomingData : number [ ] ) => {
@@ -81,18 +88,18 @@ const Canvas = forwardRef(
8188 }
8289 prevCanvasCountRef . current = canvasCount ;
8390 }
84- if ( array3DRef . current [ activebuffer . current ] [ i ] . length >= numX ) {
91+ if ( array3DRef . current [ activebuffer . current ] [ i ] . length >= numXRef . current ) {
8592 array3DRef . current [ activebuffer . current ] [ i ] = [ ] ;
8693 }
8794 array3DRef . current [ activebuffer . current ] [ i ] . push ( incomingData [ i + 1 ] ) ;
8895
89- if ( array3DRef . current [ activebuffer . current ] [ i ] . length < numX && ! pauseRef . current ) {
96+ if ( array3DRef . current [ activebuffer . current ] [ i ] . length < numXRef . current && ! pauseRef . current ) {
9097 array3DRef . current [ activebuffer . current ] [ i ] = [ ] ;
9198 }
9299 }
93100
94101
95- if ( array3DRef . current [ activebuffer . current ] [ 0 ] . length >= numX ) {
102+ if ( array3DRef . current [ activebuffer . current ] [ 0 ] . length >= numXRef . current ) {
96103 snapShotRef . current [ activebuffer . current ] = true ;
97104 activebuffer . current = ( activebuffer . current + 1 ) % 6 ;
98105 snapShotRef . current [ activebuffer . current ] = false ;
@@ -107,6 +114,14 @@ const Canvas = forwardRef(
107114 setNumChannels ( canvasCount ) ;
108115 } , [ canvasCount ] ) ;
109116
117+
118+ useEffect ( ( ) => {
119+ // Reset when currentValue changes
120+ currentSweepPos . current = new Array ( numChannels ) . fill ( 0 ) ;
121+ sweepPositions . current = new Array ( numChannels ) . fill ( 0 ) ;
122+ } , [ currentValue ] ) ;
123+
124+
110125 useImperativeHandle (
111126 ref ,
112127 ( ) => ( {
@@ -116,6 +131,7 @@ const Canvas = forwardRef(
116131 currentSweepPos . current = new Array ( numChannels ) . fill ( 0 ) ;
117132 sweepPositions . current = new Array ( numChannels ) . fill ( 0 ) ;
118133 }
134+
119135 if ( pauseRef . current ) {
120136 processIncomingData ( data ) ;
121137 updatePlots ( data , Zoom ) ;
@@ -133,7 +149,7 @@ const Canvas = forwardRef(
133149 previousCounter = data [ 0 ] ; // Update the previous counter with the current counter
134150 } ,
135151 } ) ,
136- [ Zoom , numChannels ]
152+ [ Zoom , numChannels , currentValue ]
137153 ) ;
138154
139155 const createCanvases = ( ) => {
@@ -170,7 +186,7 @@ const Canvas = forwardRef(
170186 const opacityLightMajor = "0.4" ; // Opacity for every 5th line in light theme
171187 const opacityLightMinor = "0.1" ; // Opacity for other lines in light theme
172188 const distanceminor = samplingRate * 0.04 ;
173- const numGridLines = numX / distanceminor ;
189+ const numGridLines = getpoints ( selectedBits ) * 4 / distanceminor ;
174190 for ( let j = 1 ; j < numGridLines ; j ++ ) {
175191 const gridLineX = document . createElement ( "div" ) ;
176192 gridLineX . className = "absolute bg-[rgb(128,128,128)]" ;
@@ -226,10 +242,10 @@ const Canvas = forwardRef(
226242 const wglp = new WebglPlot ( canvas ) ;
227243 newWglPlots . push ( wglp ) ;
228244 wglp . gScaleY = Zoom ;
229- const line = new WebglLine ( getLineColor ( i , theme ) , numX ) ;
245+ const line = new WebglLine ( getLineColor ( i , theme ) , numXRef . current ) ;
230246 wglp . gOffsetY = 0 ;
231247 line . offsetY = 0 ;
232- line . lineSpaceX ( - 1 , 2 / numX ) ;
248+ line . lineSpaceX ( - 1 , 2 / numXRef . current ) ;
233249
234250 wglp . addLine ( line ) ;
235251 newLines . push ( line ) ;
@@ -294,19 +310,19 @@ const Canvas = forwardRef(
294310 line . setY ( currentSweepPos . current [ i ] % line . numPoints , data [ i + 1 ] ) ;
295311
296312 // Clear the next point to create a gap (optional, for visual effect)
297- const clearPosition = ( currentSweepPos . current [ i ] + ( numX / 100 ) ) % line . numPoints ;
313+ const clearPosition = ( currentSweepPos . current [ i ] + ( numXRef . current / 100 ) ) % line . numPoints ;
298314 line . setY ( clearPosition , NaN ) ;
299315
300316 // Increment the sweep position for the current line
301317 sweepPositions . current [ i ] = ( currentSweepPos . current [ i ] + 1 ) % line . numPoints ;
302318 } ) ;
303319 } ,
304- [ lines , wglPlots , numChannels , theme ]
320+ [ lines , wglPlots , numChannels , theme , currentValue ]
305321 ) ;
306322
307323 useEffect ( ( ) => {
308324 createCanvases ( ) ;
309- } , [ numChannels , theme ] ) ;
325+ } , [ numChannels , theme , currentValue ] ) ;
310326
311327
312328 const animate = useCallback ( ( ) => {
@@ -318,7 +334,7 @@ const Canvas = forwardRef(
318334 wglPlots . forEach ( ( wglp ) => wglp . update ( ) ) ;
319335 requestAnimationFrame ( animate ) ; // Continue the animation loop
320336 }
321- } , [ currentSnapshot , numX , pauseRef . current , wglPlots , Zoom ] ) ;
337+ } , [ currentSnapshot , numXRef . current , pauseRef . current , wglPlots , Zoom ] ) ;
322338
323339
324340 const updatePlotSnapshot = ( currentSnapshot : number ) => {
0 commit comments