Browse code

anno_simple(): text symbol can have nchar > 1

Zuguang authored on 07/04/2021 08:20:24
Showing2 changed files

... ...
@@ -1,5 +1,7 @@
1 1
 CHANGES in VERSION 2.7.10
2 2
 
3
+* `anno_simple()`: text symbols can have nchar > 1.
4
+
3 5
 =========================
4 6
 
5 7
 CHANGES in VERSION 2.7.9
... ...
@@ -231,14 +231,20 @@ anno_simple = function(x, col, na_col = "grey",
231 231
 
232 232
 			for(i in seq_len(nc)) {
233 233
 			    fill = map_to_colors(color_mapping, value[index, i])
234
-			    grid.rect(x = (i-0.5)/nc, y, height = 1/n, width = 1/nc, 
235
-				gp = do.call("gpar", c(list(fill = fill), gp)))
234
+			    grid.rect(x = (i-0.5)/nc, y, height = 1/n, width = 1/nc, gp = do.call("gpar", c(list(fill = fill), gp)))
236 235
 			    if(!is.null(pch)) {
237 236
 					l = !is.na(pch[, i])
238 237
 					if(any(l)) {
239
-						grid.points(x = rep((i-0.5)/nc, sum(l)), y = y[l], pch = pch[l, i], 
240
-						    size = {if(length(pt_size) == 1) pt_size else pt_size[i]}, 
241
-						    gp = subset_gp(pt_gp, i))
238
+						if(is.character(pch)) {
239
+							text_gp = subset_gp(pt_gp, i)
240
+							text_gp$fontsize = convertHeight({if(length(pt_size) == 1) pt_size else pt_size[i]}, "pt", valueOnly = TRUE)
241
+							grid.text(pch[l, i], x = rep((i-0.5)/nc, sum(l)), y = y[l],
242
+							    gp = text_gp)
243
+						} else {
244
+							grid.points(x = rep((i-0.5)/nc, sum(l)), y = y[l], pch = pch[l, i], 
245
+							    size = {if(length(pt_size) == 1) pt_size else pt_size[i]}, 
246
+							    gp = subset_gp(pt_gp, i))
247
+						}
242 248
 					}
243 249
 			    }
244 250
 			}
... ...
@@ -251,8 +257,15 @@ anno_simple = function(x, col, na_col = "grey",
251 257
 			    pt_gp = subset_gp(pt_gp, index)
252 258
 			    l = !is.na(pch)
253 259
 			    if(any(l)) {
254
-				    grid.points(x = rep(0.5, sum(l)), y = y[l], pch = pch[l], size = pt_size[l], 
255
-						gp = subset_gp(pt_gp, which(l)))
260
+			    	if(is.character(pch)) {
261
+			    		text_gp = subset_gp(pt_gp, which(l))
262
+			    		text_gp$fontsize = convertHeight(pt_size[l], "pt", valueOnly = TRUE)
263
+			    		grid.text(pch[l], x = rep(0.5, sum(l)), y = y[l],
264
+							gp = text_gp)
265
+			    	} else {
266
+					    grid.points(x = rep(0.5, sum(l)), y = y[l], pch = pch[l], size = pt_size[l], 
267
+							gp = subset_gp(pt_gp, which(l)))
268
+					}
256 269
 				}
257 270
 			}
258 271
 	    }
... ...
@@ -274,9 +287,16 @@ anno_simple = function(x, col, na_col = "grey",
274 287
 				if(!is.null(pch)){
275 288
 				    l = !is.na(pch[, i])
276 289
 				    if(any(l)) {
277
-					    grid.points(x[l], y = rep((nc-i +0.5)/nc, sum(l)), pch = pch[l, i], 
278
-							size = {if(length(pt_size) == 1) pt_size else pt_size[i]}, 
279
-							gp = subset_gp(pt_gp, i))
290
+				    	if(is.character(pch)) {
291
+				    		text_gp = subset_gp(pt_gp, i)
292
+				    		text_gp$fontsize = convertHeight({if(length(pt_size) == 1) pt_size else pt_size[i]}, "pt", valueOnly = TRUE)
293
+				    		 grid.text(pch[l, i], x = x[l], y = rep((nc-i +0.5)/nc, sum(l)),
294
+								gp = text_gp)
295
+				    	} else {
296
+						    grid.points(x[l], y = rep((nc-i +0.5)/nc, sum(l)), pch = pch[l, i], 
297
+								size = {if(length(pt_size) == 1) pt_size else pt_size[i]}, 
298
+								gp = subset_gp(pt_gp, i))
299
+						}
280 300
 					}
281 301
 				}
282 302
 		    }
... ...
@@ -289,8 +309,15 @@ anno_simple = function(x, col, na_col = "grey",
289 309
 				pt_gp = subset_gp(pt_gp, index)
290 310
 				l = !is.na(pch)
291 311
 				if(any(l)) {
292
-					grid.points(x[l], y = rep(0.5, sum(l)), pch = pch[l], size = pt_size[l], 
293
-						gp = subset_gp(pt_gp, which(l)))
312
+					if(is.character(pch)) {
313
+						text_gp = subset_gp(pt_gp, which(l))
314
+						text_gp$fontsize = convertHeight(pt_size[l], "pt", valueOnly = TRUE)
315
+						grid.text(pch[l], x = x[l], y = rep(0.5, sum(l)),
316
+						    gp = text_gp)
317
+					} else {
318
+						grid.points(x[l], y = rep(0.5, sum(l)), pch = pch[l], size = pt_size[l], 
319
+							gp = subset_gp(pt_gp, which(l)))
320
+					}
294 321
 				}
295 322
 			}
296 323
         }