Browse code

anno_image(): fixed a bug that images are not reordered

Zuguang Gu authored on 21/05/2020 21:13:54
Showing2 changed files

... ...
@@ -6,6 +6,7 @@ CHANGES in VERSION 2.5.3
6 6
 * `col` in `Heatmap()` accpets a `ColorMapping` object.
7 7
 * `default_col()`: print a message if there are outliers in the matrix.
8 8
 * `discrete_legend_body()`: adjust ncol and nrow if there are empty rows and columns in the layout.
9
+* `anno_image()`: fixed a bug that images are not reordered.
9 10
 
10 11
 ========================
11 12
 
... ...
@@ -473,7 +473,7 @@ anno_image = function(image, which = c("column", "row"), border = TRUE,
473 473
 		asp = convertHeight(unit(1, "npc") - space*2, "mm", valueOnly = TRUE)/convertWidth(unit(1/n, "npc") - space*2, "mm", valueOnly = TRUE)
474 474
 		grid.rect(x = (1:n - 0.5)/n, width = 1/n, gp = subset_gp(gp, index))
475 475
 		for(i in seq_len(n)) {
476
-			if(identical(image_list[[i]], NA)) next
476
+			if(identical(image_list[[ index[i] ]], NA)) next
477 477
 			if(yx_asp[ index[i] ] > asp) {
478 478
 				height = unit(1, "npc") - space*2
479 479
 				width = convertHeight(height, "mm")*yx_asp[ index[i] ]
... ...
@@ -482,13 +482,13 @@ anno_image = function(image, which = c("column", "row"), border = TRUE,
482 482
 				height = yx_asp[ index[i] ]*convertWidth(width, "mm")
483 483
 			}
484 484
 			if(image_class[ index[i] ] == "raster") {
485
-				grid.raster(image_list[[i]], x = (i-0.5)/n, width = width, height = height)
485
+				grid.raster(image_list[[ index[i] ]], x = (i-0.5)/n, width = width, height = height)
486 486
 			} else if(image_class[ index[i] ] == "grImport::Picture") {
487 487
 				grid.picture = getFromNamespace("grid.picture", ns = "grImport")
488
-				grid.picture(image_list[[i]], x = (i-0.5)/n, width = width, height = height)
488
+				grid.picture(image_list[[ index[i] ]], x = (i-0.5)/n, width = width, height = height)
489 489
 			} else if(image_class[ index[i] ] == "grImport2::Picture") {
490 490
 				grid.picture = getFromNamespace("grid.picture", ns = "grImport2")
491
-				grid.picture(image_list[[i]], x = (i-0.5)/n, width = width, height = height)
491
+				grid.picture(image_list[[ index[i] ]], x = (i-0.5)/n, width = width, height = height)
492 492
 			}
493 493
 		}
494 494
 		if(border) grid.rect(gp = gpar(fill = "transparent"))
... ...
@@ -502,7 +502,7 @@ anno_image = function(image, which = c("column", "row"), border = TRUE,
502 502
 		asp = convertHeight(unit(1/n, "npc") - space*2, "mm", valueOnly = TRUE)/convertWidth(unit(1, "npc") - space*2, "mm", valueOnly = TRUE)
503 503
 		grid.rect(y = (n - 1:n + 0.5)/n, height = 1/n, gp = subset_gp(gp, index))
504 504
 		for(i in seq_len(n)) {
505
-			if(identical(image_list[[i]], NA)) next
505
+			if(identical(image_list[[ index[i] ]], NA)) next
506 506
 			if(yx_asp[ index[i] ] > asp) {
507 507
 				height = unit(1/n, "npc") - space*2
508 508
 				width = convertHeight(height, "mm")*(1/yx_asp[ index[i] ])
... ...
@@ -511,13 +511,13 @@ anno_image = function(image, which = c("column", "row"), border = TRUE,
511 511
 				height = yx_asp[ index[i] ]*convertWidth(width, "mm")
512 512
 			}
513 513
 			if(image_class[ index[i] ] == "raster") {
514
-				grid.raster(image_list[[i]], y = (n - i + 0.5)/n, width = width, height = height)
514
+				grid.raster(image_list[[ index[i] ]], y = (n - i + 0.5)/n, width = width, height = height)
515 515
 			} else if(image_class[ index[i] ] == "grImport::Picture") {
516 516
 				grid.picture = getFromNamespace("grid.picture", ns = "grImport")
517
-				grid.picture(image_list[[i]], y = (n - i + 0.5)/n, width = width, height = height)
517
+				grid.picture(image_list[[ index[i] ]], y = (n - i + 0.5)/n, width = width, height = height)
518 518
 			} else if(image_class[ index[i] ] == "grImport2::Picture") {
519 519
 				grid.picture = getFromNamespace("grid.picture", ns = "grImport2")
520
-				grid.picture(image_list[[i]], y = (n - i + 0.5)/n, width = width, height = height)
520
+				grid.picture(image_list[[ index[i] ]], y = (n - i + 0.5)/n, width = width, height = height)
521 521
 			}
522 522
 		}
523 523
 		if(border) grid.rect(gp = gpar(fill = "transparent"))