@@ -298,13 +298,31 @@ export default function MapComponent() {
298298 timeDifferences . push ( `${ diffHours } h gap` ) ;
299299 }
300300
301- // Create graph container
301+ // Create graph container with responsive dimensions
302302 const graphContainer = document . createElement ( 'div' ) ;
303- graphContainer . style . width = '600px' ;
304- graphContainer . style . height = '420px' ;
305- graphContainer . style . padding = '15px' ;
303+ graphContainer . className = 'historical-data-container' ;
304+
305+ // Detect mobile viewport
306+ const isMobile = window . innerWidth <= 768 ;
307+ const isSmallMobile = window . innerWidth <= 480 ;
308+
309+ // Set responsive dimensions
310+ if ( isSmallMobile ) {
311+ graphContainer . style . width = '340px' ;
312+ graphContainer . style . height = '300px' ;
313+ graphContainer . style . padding = '8px' ;
314+ } else if ( isMobile ) {
315+ graphContainer . style . width = '450px' ;
316+ graphContainer . style . height = '350px' ;
317+ graphContainer . style . padding = '10px' ;
318+ } else {
319+ graphContainer . style . width = '600px' ;
320+ graphContainer . style . height = '420px' ;
321+ graphContainer . style . padding = '15px' ;
322+ }
323+
306324 graphContainer . style . backgroundColor = window . globalTheme === 'dark' ? '#1a1a1a' : '#ffffff' ;
307- graphContainer . style . borderRadius = '12px' ;
325+ graphContainer . style . borderRadius = isMobile ? '8px' : '12px' ;
308326 graphContainer . style . boxShadow = window . globalTheme === 'dark'
309327 ? '0 8px 32px rgba(0,0,0,0.5)'
310328 : '0 8px 32px rgba(0,0,0,0.15)' ;
@@ -313,8 +331,18 @@ export default function MapComponent() {
313331 const canvas = document . createElement ( 'canvas' ) ;
314332 canvas . style . width = '100%' ;
315333 canvas . style . height = 'calc(100% - 40px)' ;
316- canvas . width = 570 ;
317- canvas . height = 380 ;
334+
335+ // Set canvas dimensions based on screen size
336+ if ( isSmallMobile ) {
337+ canvas . width = 320 ;
338+ canvas . height = 240 ;
339+ } else if ( isMobile ) {
340+ canvas . width = 420 ;
341+ canvas . height = 290 ;
342+ } else {
343+ canvas . width = 570 ;
344+ canvas . height = 380 ;
345+ }
318346 graphContainer . appendChild ( canvas ) ;
319347
320348 console . log ( 'Creating chart with time-based data:' , timeBasedData ) ;
@@ -346,11 +374,11 @@ export default function MapComponent() {
346374 display : true ,
347375 text : `Historical Data for ${ name } ` ,
348376 font : {
349- size : 18 ,
377+ size : isSmallMobile ? 14 : ( isMobile ? 16 : 18 ) ,
350378 weight : 'bold'
351379 } ,
352380 color : window . globalTheme === 'dark' ? '#fff' : '#333' ,
353- padding : 20
381+ padding : isSmallMobile ? 10 : ( isMobile ? 15 : 20 )
354382 } ,
355383 legend : {
356384 display : false
@@ -385,26 +413,35 @@ export default function MapComponent() {
385413 type : 'linear' , // Use linear instead of time to avoid adapter issues
386414 position : 'bottom' ,
387415 title : {
388- display : true ,
416+ display : ! isSmallMobile , // Hide title on very small screens
389417 text : 'Date & Time' ,
390418 color : window . globalTheme === 'dark' ? '#fff' : '#333' ,
391419 font : {
392- size : 14 ,
420+ size : isSmallMobile ? 10 : ( isMobile ? 12 : 14 ) ,
393421 weight : 'bold'
394422 }
395423 } ,
396424 ticks : {
397425 color : window . globalTheme === 'dark' ? '#ccc' : '#666' ,
398- maxRotation : 45 ,
426+ maxRotation : isMobile ? 45 : 45 ,
399427 font : {
400- size : 10
428+ size : isSmallMobile ? 8 : ( isMobile ? 9 : 10 )
401429 } ,
402- maxTicksLimit : 5 , // Limit to prevent overcrowding
430+ maxTicksLimit : isSmallMobile ? 3 : ( isMobile ? 4 : 5 ) , // Fewer ticks on mobile
403431 callback : function ( value ) {
404432 // The value here is the actual timestamp (milliseconds)
405433 const date = new Date ( value ) ;
406434 if ( isNaN ( date . getTime ( ) ) ) return '' ; // Invalid date
407- return date . toLocaleDateString ( ) + ' ' + date . toLocaleTimeString ( [ ] , { hour : '2-digit' , minute :'2-digit' } ) ;
435+
436+ // Mobile-friendly date formatting
437+ if ( isSmallMobile ) {
438+ return date . toLocaleDateString ( 'en-US' , { month : 'short' , day : 'numeric' } ) ;
439+ } else if ( isMobile ) {
440+ return date . toLocaleDateString ( 'en-US' , { month : 'short' , day : 'numeric' } ) + '\n' +
441+ date . toLocaleTimeString ( [ ] , { hour : '2-digit' , minute :'2-digit' } ) ;
442+ } else {
443+ return date . toLocaleDateString ( ) + ' ' + date . toLocaleTimeString ( [ ] , { hour : '2-digit' , minute :'2-digit' } ) ;
444+ }
408445 }
409446 } ,
410447 grid : {
@@ -413,18 +450,18 @@ export default function MapComponent() {
413450 } ,
414451 y : {
415452 title : {
416- display : true ,
453+ display : ! isSmallMobile , // Hide title on very small screens
417454 text : `Temperature (°${ currentUnit } )` ,
418455 color : window . globalTheme === 'dark' ? '#fff' : '#333' ,
419456 font : {
420- size : 14 ,
457+ size : isSmallMobile ? 10 : ( isMobile ? 12 : 14 ) ,
421458 weight : 'bold'
422459 }
423460 } ,
424461 ticks : {
425462 color : window . globalTheme === 'dark' ? '#ccc' : '#666' ,
426463 font : {
427- size : 11
464+ size : isSmallMobile ? 8 : ( isMobile ? 9 : 11 )
428465 } ,
429466 callback : function ( value ) {
430467 return `${ value } °${ currentUnit } ` ;
@@ -448,12 +485,14 @@ export default function MapComponent() {
448485 marker . chartData = sortedData ;
449486 marker . chartContainer = graphContainer ; // Store reference to the container
450487
451- // Open popup
488+ // Open popup with responsive sizing
452489 const popup = L . popup ( {
453490 offset : popupOffset ,
454- maxWidth : 650 ,
455- maxHeight : 470 ,
456- className : 'custom-popup'
491+ maxWidth : isSmallMobile ? 360 : ( isMobile ? 480 : 650 ) ,
492+ maxHeight : isSmallMobile ? 320 : ( isMobile ? 370 : 470 ) ,
493+ className : 'custom-popup mobile-optimized-popup' ,
494+ autoPan : true ,
495+ autoPanPadding : [ 10 , 10 ]
457496 } )
458497 . setLatLng ( [ lat , lon ] )
459498 . setContent ( graphContainer )
@@ -466,6 +505,25 @@ export default function MapComponent() {
466505 console . log ( 'Chart resized' ) ;
467506 }
468507 } , 100 ) ;
508+
509+ // Add resize handler for mobile orientation changes
510+ const handleResize = ( ) => {
511+ if ( chart && chart . resize ) {
512+ setTimeout ( ( ) => {
513+ chart . resize ( ) ;
514+ console . log ( 'Chart resized after orientation change' ) ;
515+ } , 200 ) ;
516+ }
517+ } ;
518+
519+ window . addEventListener ( 'resize' , handleResize ) ;
520+ window . addEventListener ( 'orientationchange' , handleResize ) ;
521+
522+ // Store cleanup function for the resize handlers
523+ marker . _resizeCleanup = ( ) => {
524+ window . removeEventListener ( 'resize' , handleResize ) ;
525+ window . removeEventListener ( 'orientationchange' , handleResize ) ;
526+ } ;
469527 } ) ;
470528
471529 // Add keyboard accessibility AFTER the click handler
@@ -574,6 +632,10 @@ export default function MapComponent() {
574632
575633 // Clear existing markers before adding new ones
576634 markersRef . current . forEach ( ( { marker } ) => {
635+ // Clean up resize handlers if they exist
636+ if ( marker . _resizeCleanup ) {
637+ marker . _resizeCleanup ( ) ;
638+ }
577639 map . removeLayer ( marker ) ;
578640 } ) ;
579641 markersRef . current = [ ] ;
0 commit comments