@@ -18,6 +18,10 @@ light_heat_colors <- function(...) {
18
18
colorRampPalette(c(" red" , " darkorange2" , " darkgoldenrod1" , " gold1" , " yellow2" ))(... )
19
19
}
20
20
21
+ light_cool_colors <- function (... ) {
22
+ colorRampPalette(c(" #1133AA" , " #CCFFFF" ))(... )
23
+ }
24
+
21
25
additive_alpha <- function (colors ) {
22
26
s <- seq(2 , length(colors ))
23
27
x <- t(col2rgb(colors , alpha = F ))/ 255
@@ -44,14 +48,42 @@ map_colors <- function(colors, x, min_limit=NULL, max_limit=NULL) {
44
48
colors [findInterval(x , seq(min_limit , max_limit , length.out = length(colors ) + 1 ), all.inside = TRUE )]
45
49
}
46
50
47
- relx <- function (r ) {
48
- structure(r , class = " relx" )
51
+ relx <- function (r , mode = " data " ) {
52
+ structure(r , class = " relx" , mode = mode )
49
53
}
50
54
51
- rely <- function (r ) {
52
- structure(r , class = " rely" )
55
+ rely <- function (r , mode = " data " ) {
56
+ structure(r , class = " rely" , mode = mode )
53
57
}
54
58
59
+ # internal helper function
60
+ calculate_radius <- function (radius , xdiff , ydiff , self ) {
61
+ plot_x_diff <- self $ xmax - self $ xmin
62
+ plot_y_diff <- self $ ymax - self $ ymin
63
+ if (inherits(radius , " relx" )) {
64
+ rel_mode <- attr(radius , " mode" )
65
+ attributes(radius ) <- NULL
66
+ if (rel_mode == " data" ) {
67
+ radius <- xdiff * radius / self $ x_aspect_ratio
68
+ } else if (rel_mode == " plot" ) {
69
+ radius <- plot_x_diff * radius / self $ x_aspect_ratio
70
+ } else {
71
+ stop(" relx mode must be 'data' or 'plot'" )
72
+ }
73
+ } else if (inherits(radius , " rely" )) {
74
+ rel_mode <- attr(radius , " mode" )
75
+ attributes(radius ) <- NULL
76
+ if (rel_mode == " data" ) {
77
+ radius <- ydiff * radius / self $ y_aspect_ratio
78
+ } else if (rel_mode == " plot" ) {
79
+ radius <- plot_y_diff * radius / self $ y_aspect_ratio
80
+ } else {
81
+ stop(" rely mode must be 'data' or 'plot'" )
82
+ }
83
+ } else {
84
+ radius
85
+ }
86
+ }
55
87
56
88
# GlowMapper ###################################
57
89
GlowMapper <- R6Class(" GlowMapper" , list (
@@ -115,16 +147,7 @@ GlowMapper <- R6Class("GlowMapper", list(
115
147
self $ x_aspect_ratio <- max(xincrement / yincrement ,1 )
116
148
self $ y_aspect_ratio <- max(yincrement / xincrement ,1 )
117
149
118
- if (inherits(radius , " relx" )) {
119
- class(radius ) <- NULL
120
- radius <- xdiff * radius / self $ x_aspect_ratio
121
- } else if (inherits(radius , " rely" )) {
122
- class(radius ) <- NULL
123
- radius <- ydiff * radius / self $ y_aspect_ratio
124
- } else {
125
- # nothing
126
- }
127
- class(radius ) <- NULL
150
+ radius <- calculate_radius(radius , xdiff , ydiff , self )
128
151
129
152
self $ plot_data <- data.frame (x , y , intensity , radius , distance_exponent )
130
153
@@ -275,17 +298,7 @@ GlowMapper4 <- R6Class("GlowMapper4", list(
275
298
self $ x_aspect_ratio <- max(xincrement / yincrement ,1 )
276
299
self $ y_aspect_ratio <- max(yincrement / xincrement ,1 )
277
300
278
-
279
- if (inherits(radius , " relx" )) {
280
- class(radius ) <- NULL
281
- radius <- xdiff * radius / self $ x_aspect_ratio
282
- } else if (inherits(radius , " rely" )) {
283
- class(radius ) <- NULL
284
- radius <- ydiff * radius / self $ y_aspect_ratio
285
- } else {
286
- # nothing
287
- }
288
- class(radius ) <- NULL
301
+ radius <- calculate_radius(radius , xdiff , ydiff , self )
289
302
290
303
self $ plot_data <- data.frame (x , y , r ,g ,b , radius , distance_exponent )
291
304
@@ -460,16 +473,7 @@ LightMapper <- R6Class("LightMapper", list(
460
473
self $ x_aspect_ratio <- max(xincrement / yincrement ,1 )
461
474
self $ y_aspect_ratio <- max(yincrement / xincrement ,1 )
462
475
463
- if (inherits(radius , " relx" )) {
464
- class(radius ) <- NULL
465
- radius <- xdiff * radius / self $ x_aspect_ratio
466
- } else if (inherits(radius , " rely" )) {
467
- class(radius ) <- NULL
468
- radius <- ydiff * radius / self $ y_aspect_ratio
469
- } else {
470
- # nothing
471
- }
472
- class(radius ) <- NULL
476
+ radius <- calculate_radius(radius , xdiff , ydiff , self )
473
477
474
478
self $ plot_data <- data.frame (x , y , intensity , radius , falloff_exponent , distance_exponent )
475
479
@@ -615,16 +619,7 @@ LightMapper4 <- R6Class("GlowMapper4", list(
615
619
self $ x_aspect_ratio <- max(xincrement / yincrement ,1 )
616
620
self $ y_aspect_ratio <- max(yincrement / xincrement ,1 )
617
621
618
- if (inherits(radius , " relx" )) {
619
- class(radius ) <- NULL
620
- radius <- xdiff * radius / self $ x_aspect_ratio
621
- } else if (inherits(radius , " rely" )) {
622
- class(radius ) <- NULL
623
- radius <- ydiff * radius / self $ y_aspect_ratio
624
- } else {
625
- # nothing
626
- }
627
- class(radius ) <- NULL
622
+ radius <- calculate_radius(radius , xdiff , ydiff , self )
628
623
629
624
self $ plot_data <- data.frame (x , y , r ,g ,b , radius , distance_exponent , falloff_exponent )
630
625
0 commit comments