Browse code

support heatmap_legend_offset

Zuguang Gu authored on 05/07/2019 20:23:56
Showing3 changed files

... ...
@@ -426,8 +426,10 @@ setMethod(f = "draw",
426 426
     #     heatmap_legend_offset = annotation_legend_offset
427 427
     # }
428 428
 
429
-    object@heatmap_legend_param$offset = unit(0, "mm") #heatmap_legend_offset
430
-    object@annotation_legend_param$offset = unit(0, "mm") #annotation_legend_offset
429
+    if(is.null(object@heatmap_legend_param$offset))
430
+        object@heatmap_legend_param$offset = unit(0, "mm") #heatmap_legend_offset
431
+    if(is.null(object@annotation_legend_param$offset))
432
+        object@annotation_legend_param$offset = unit(0, "mm") #annotation_legend_offset
431 433
 
432 434
     object@ht_list_param$adjust_annotation_extension = adjust_annotation_extension
433 435
 
... ...
@@ -101,16 +101,17 @@ setMethod(f = "draw_heatmap_legend",
101 101
     annotation_legend_size = object@annotation_legend_param$size
102 102
     offset = object@heatmap_legend_param$offset
103 103
 
104
-    # if(inherits(offset, "character")) {
105
-    #     if(offset == "annotation_top") {
106
-    #         i_ht = object@ht_list_param$main_heatmap
107
-    #         main_ht = object@ht_list[[i_ht]]
108
-    #         offset = unit(1, "npc") - main_ht@layout$layout_size$column_title_top_height - 
109
-    #             main_ht@layout$layout_size$column_dend_top_height - 
110
-    #             (unit(0.5, "npc") + size[2]*0.5)
111
-    #     } 
112
-    # }
113
-    offset = unit(0, "mm")
104
+    if(inherits(offset, "character")) {
105
+        if(offset == "annotation_top") {
106
+            i_ht = object@ht_list_param$main_heatmap
107
+            main_ht = object@ht_list[[i_ht]]
108
+            offset = unit(1, "npc") - main_ht@layout$layout_size$column_title_top_height - 
109
+                main_ht@layout$layout_size$column_dend_top_height - 
110
+                (unit(0.5, "npc") + size[2]*0.5)
111
+        } 
112
+    } else {
113
+        offset = unit(0, "mm")
114
+    }
114 115
 
115 116
     if(side != annotation_legend_side) {
116 117
         y = unit(0.5, "npc")
... ...
@@ -293,7 +293,7 @@ draw(anno, test = "heatmap, colors")
293 293
 anno = anno_mark(at = c(1:4, 20, 60, 97:100), labels = month.name[1:10], which = "row")
294 294
 draw(anno, index = 1:100, test = "anno_mark")
295 295
 
296
-anno = anno_mark(at = c(1:4, 20, 60, 97:100), labels = month.name[1:10], labels_rot = 30, which = "row")
296
+anno = anno_mark(at = c(1:4, 20, 60, 97:100), labels = month.name[1:10], labels_rot = 30, which = "column")
297 297
 draw(anno, index = 1:100, test = "anno_mark")
298 298
 
299 299
 m = matrix(1:1000, byrow = TRUE, nr = 100)