---
title: "Spatio-Temporal Dynamics Report"

date: "`r Sys.Date()`"
output:
  html_document:
  theme: flatly
highlight: tango

params:
  robj: NULL
  animation_fps: !r 1
  data.crs:  "+proj=longlat +datum=WGS84 +no_defs"
  png.text: !r NULL
  rmd_output: TRUE


---

```{r setup_gif, include=FALSE}
# This chunk sets global options to hide all R code from appearing in the output


library(growthTrendR)
knitr::opts_chunk$set(echo = FALSE)
robj <- params$robj

```

<br>

The following animation illustrates temporal patterns of a key attribute across a geographic region. Values at discrete locations are interpolated using the inverse distance weighting (IDW) method to create continuous yearly surfaces. The animation provides a dynamic view of spatio-temporal trends, highlighting patterns and potential anomalies in the data.
<br>


```{r show_gifs1, echo=FALSE, results='asis', warning=FALSE, message=FALSE, results='hide', fig.width=10, fig.height=5, fig.align='left'}
# Write GIF(s) to temporary files
# load("c:/tmp/raster.lst.Rdata") 
# robj <- raster.lst
plot_mapping(robj, rmd_output = params$rmd_output, png.text = params$png.text, animation_fps = params$animation_fps, data.crs = params$data.crs)

```




```{r show_gifs1a, echo=FALSE, results='asis', warning=FALSE, message=FALSE, fig.width=10, fig.height=5, fig.align='left'}

# Set the directory containing your GIF files
gif_dir <- "rmd_gifs"

# Check if directory exists
if (!dir.exists(gif_dir)) {
  cat("**Warning:** GIF directory '", gif_dir, "' not found.\n\n")
} else {
  # Get all GIF files
  gif_files <- list.files(gif_dir, pattern = "\\.gif$", full.names = TRUE)
  
  if (length(gif_files) == 0) {
    cat("**Warning:** No GIF files found in '", gif_dir, "' directory.\n\n")
  } else {
    # Display each GIF
    for (gif_file in gif_files) {
      # Extract filename without extension for title
      gif_name <- tools::file_path_sans_ext(basename(gif_file))
      
      # Check file size to ensure it's not empty
      file_size <- file.size(gif_file)
      
      if (file_size > 0) {
        # Create section header
        cat("### ", gsub("_", " ", gif_name), "\n\n")
        
        # Display GIF with proper HTML
        cat(sprintf('<div style="text-align: center; margin: 20px 0;">\n'))
        cat(sprintf('  <img src="%s" alt="%s" style="max-width: 100%%; height: auto; border: 1px solid #ddd; border-radius: 4px;">\n', 
                    gif_file, gif_name))
        cat(sprintf('  <p style="font-size: 12px; color: #666; margin-top: 5px;"><em>%s (%.1f KB)</em></p>\n', 
                    gif_name, file_size/1024))
        cat(sprintf('</div>\n\n'))
      } else {
        cat("### ", gsub("_", " ", gif_name), "\n\n")
        cat("**Error:** GIF file is empty (0 bytes)\n\n")
      }
    }
  }
}
```



