Skip to content

Commit

Permalink
Merge pull request USGS-VIZLAB#60 from jread-usgs/master
Browse files Browse the repository at this point in the history
diff json and mousers
  • Loading branch information
jiwalker-usgs committed Mar 10, 2017
2 parents d1d5dfb + 401021d commit 800c437
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion scripts/process/process_bar_chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ process.bar_chart <- function(viz){
x = as.character((i-1)*(bin.w+spc)),
height = as.character(bin.h[i]),
width = as.character(bin.w), y = as.character(h - bin.h[i]), id = paste0('yr', bars$year[i]),
onmousemove = sprintf("hovertext('%s gages');vizlab.showyear('%s')", bars$n[i], bars$year[i]),
onmousemove = sprintf("hovertext('%s gages', evt);vizlab.showyear('%s')", bars$n[i], bars$year[i]),
onmouseoff = sprintf("hovertext(' ');vizlab.playyear('%s')", bars$year[i]))
}
write_xml(x = g.bars, file = viz[['location']])
Expand Down
36 changes: 36 additions & 0 deletions scripts/process/process_year-json.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
process.year_json <- function(viz){
data.in <- readDepends(viz)
library(dplyr)
sites <- data.in[['site-map']]
sites.w.data <- data.in[["disch-data"]]

chunk.s <- seq(1,by=site.chunk, to=length(sites))
chunk.e <- c(tail(chunk.s, -1L), length(sites))
json.out <- list()
for (i in 1:length(chunk.s)){
chunk <- list()
for (yr in viz[['min-year']]:viz[['max-year']]){
sites.n.chunk <- sites$site_no[chunk.s[i]:chunk.e[i]]
sites.yr <- sites.w.data %>% filter(year == yr ) %>% .$site_no
now.i <- which(sites.n.chunk %in% sites.yr)
if (yr == viz[['min-year']]){
tmp <- list(list(gn = now.i, ls = numeric()))
} else {
#last year's data:
last.yr <- sites.w.data %>% filter(year == yr-1 ) %>% .$site_no
last.i <- which(sites.n.chunk %in% last.yr)
gained <- now.i[!now.i %in% last.i]
lost <- last.i[!last.i %in% now.i]
tmp <- list(list(gn = gained, ls = lost))
}

names(tmp) <- yr
chunk <- append(chunk, tmp)
}
tmp <- list(chunk)
names(tmp) <- sprintf(group.names, i)
json.out <- append(json.out, tmp)
}
json.text <- jsonlite::toJSON(json.out)
cat(json.text, file = viz[['location']])
}
26 changes: 1 addition & 25 deletions scripts/visualize/visualize-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,7 @@ add_bar_chart <- function(svg, bars){
return(svg)
}

process.time_json <- function(viz){
data.in <- readDepends(viz)
library(dplyr)
sites <- data.in[['site-map']]
sites.w.data <- data.in[["disch-data"]]

chunk.s <- seq(1,by=site.chunk, to=length(sites))
chunk.e <- c(tail(chunk.s, -1L), length(sites))
json.out <- list()
for (i in 1:length(chunk.s)){
chunk <- list()
for (yr in viz[['min-year']]:viz[['max-year']]){
sites.n.chunk <- sites$site_no[chunk.s[i]:chunk.e[i]]
sites.yr <- sites.w.data %>% filter(year == yr ) %>% .$site_no
tmp <- list(which(sites.n.chunk %in% sites.yr)) #which of the sites
names(tmp) <- yr
chunk <- append(chunk, tmp)
}
tmp <- list(chunk)
names(tmp) <- sprintf(group.names, i)
json.out <- append(json.out, tmp)
}
json.text <- jsonlite::toJSON(json.out)
cat(json.text, file = viz[['location']])
}


#' do the things to the svg that we need to do every time if they come from svglite:
#'
Expand Down
4 changes: 2 additions & 2 deletions viz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ process:
-
id: year-data
location: cache/year-data.json
processor: time_json
scripts: scripts/visualize/visualize-map.R
processor: year_json
scripts: ["scripts/visualize/visualize-map.R", "scripts/process/process_year-json.R"]
depends: ["site-map", "disch-data"]
min-year: 1890
max-year: 2015
Expand Down

0 comments on commit 800c437

Please sign in to comment.