From 7ed17c7525a8d8fefe71034b1201bbddca7652e6 Mon Sep 17 00:00:00 2001 From: Travers Date: Thu, 6 Apr 2023 19:20:26 -0700 Subject: [PATCH] . --- R/glow_functions.r | 16 ++++++++-------- man/relxy.Rd | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/R/glow_functions.r b/R/glow_functions.r index 708dbec..113de11 100644 --- a/R/glow_functions.r +++ b/R/glow_functions.r @@ -115,10 +115,10 @@ GlowMapper <- R6Class("GlowMapper", list( self$x_aspect_ratio <- max(xincrement / yincrement,1) self$y_aspect_ratio <- max(yincrement / xincrement,1) - if(class(radius) == "relx") { + if(inherits(radius, "relx")) { class(radius) <- NULL radius <- xdiff * radius / self$x_aspect_ratio - } else if(class(radius) == "rely") { + } else if(inherits(radius, "rely")) { class(radius) <- NULL radius <- ydiff * radius / self$y_aspect_ratio } else { @@ -276,10 +276,10 @@ GlowMapper4 <- R6Class("GlowMapper4", list( self$y_aspect_ratio <- max(yincrement / xincrement,1) - if(class(radius) == "relx") { + if(inherits(radius, "relx")) { class(radius) <- NULL radius <- xdiff * radius / self$x_aspect_ratio - } else if(class(radius) == "rely") { + } else if(inherits(radius, "rely")) { class(radius) <- NULL radius <- ydiff * radius / self$y_aspect_ratio } else { @@ -460,10 +460,10 @@ LightMapper <- R6Class("LightMapper", list( self$x_aspect_ratio <- max(xincrement / yincrement,1) self$y_aspect_ratio <- max(yincrement / xincrement,1) - if(class(radius) == "relx") { + if(inherits(radius, "relx")) { class(radius) <- NULL radius <- xdiff * radius / self$x_aspect_ratio - } else if(class(radius) == "rely") { + } else if(inherits(radius, "rely")) { class(radius) <- NULL radius <- ydiff * radius / self$y_aspect_ratio } else { @@ -615,10 +615,10 @@ LightMapper4 <- R6Class("GlowMapper4", list( self$x_aspect_ratio <- max(xincrement / yincrement,1) self$y_aspect_ratio <- max(yincrement / xincrement,1) - if(class(radius) == "relx") { + if(inherits(radius, "relx")) { class(radius) <- NULL radius <- xdiff * radius / self$x_aspect_ratio - } else if(class(radius) == "rely") { + } else if(inherits(radius, "rely")) { class(radius) <- NULL radius <- ydiff * radius / self$y_aspect_ratio } else { diff --git a/man/relxy.Rd b/man/relxy.Rd index 313caa3..3f6564d 100644 --- a/man/relxy.Rd +++ b/man/relxy.Rd @@ -25,13 +25,23 @@ I.e., a value of 0.02 corresponds to 2% of the plot. } \examples{ -gm <- GlowMapper4$new(xdim=240, ydim=240, blend_mode = "additive", nthreads=1) -gm$map(x=cliff_points$x, y=cliff_points$y, radius=relx(0.02), color=cliff_points$color) +gm <- GlowMapper$new(xdim=480, ydim=240, blend_mode = "additive", nthreads=4) + +gm$map(x=1:10, y=runif(10)*100, radius=relx(0.01), intensity = 1) pd <- gm$output_dataframe(saturation = 1) ggplot() + - geom_raster(data = pd, aes(x = x, y = y, fill = rgb(r,g,b,a)), show.legend=FALSE) + - coord_fixed(gm$aspect(), xlim = gm$xlim(), ylim = gm$ylim()) + - scale_fill_identity() + + geom_raster(data = pd, aes(x = x, y = y, fill = value), show.legend=FALSE) + + coord_fixed(gm$aspect(), xlim = gm$xlim(), ylim = gm$ylim()) + + scale_fill_gradientn(colors = additive_alpha(viridisLite::viridis(12))) + + theme_night() + +# Relative radius to y-range +gm$map(x=1:10, y=runif(10)*100, radius=rely(0.01)) +pd <- gm$output_dataframe(saturation = 1) +ggplot() + + geom_raster(data = pd, aes(x = x, y = y, fill = value), show.legend=FALSE) + + coord_fixed(gm$aspect(), xlim = gm$xlim(), ylim = gm$ylim()) + + scale_fill_gradientn(colors = additive_alpha(viridisLite::viridis(12))) + theme_night() }