Browse code

fixed a bug of legend grids were not correctly recycled

Zuguang Gu authored on 02/08/2021 19:42:49
Showing3 changed files

... ...
@@ -4,6 +4,7 @@ CHANGES in VERSION 2.9.3
4 4
 * throw error when the heatmaps (list) are already initialized by draw() when adding them.
5 5
 * set `wrap = TRUE` in `grid.grabExpr()` when capturing the legend objects.
6 6
 * `make_comb_mat()`: support `GRangesList` object as input.
7
+* legends: fixed a bug of the grid heights were not correctedly calculated.
7 8
 
8 9
 =========================
9 10
 
... ...
@@ -3300,7 +3300,7 @@ anno_summary = function(which = c("column", "row"), border = TRUE, bar_width = 0
3300 3300
 # -height Height of the annotation. The value should be an absolute unit. Height is not allowed to be set for row annotation.
3301 3301
 # -show_name Whether show annotatio name.
3302 3302
 # -graphics A self-defined function that draws graphics in each slice. It must have two arguments: 1. row/column indices for the 
3303
-#      current slice and a vector of levels from the split variable that correspond to current slice. When ``graphics`` is set,
3303
+#      current slice and 2. a vector of levels from the split variable that correspond to current slice. When ``graphics`` is set,
3304 3304
 #      all other graphics parameters in `anno_block` are ignored.
3305 3305
 #
3306 3306
 # == details
... ...
@@ -764,7 +764,7 @@ vertical_continuous_legend_body = function(at, labels = at, col_fun,
764 764
 	hh = (legend_body_height - 2*offset)*(1/length(colors))
765 765
 	x2 = unit.c(unit(0, "npc"), x2, unit(0, "npc"))
766 766
 	y2 = unit.c(offset*0.5, y2, legend_body_height - offset*0.5)
767
-	hh = unit.c(offset, hh, offset)
767
+	hh = unit.c(offset, rep(hh, length(y2)-2), offset)
768 768
 	colors = c(colors[1], colors, colors[length(colors)])
769 769
 	gl = c(gl, list(
770 770
 		rectGrob(x2, rev(y2), width = grid_width, height = hh, just = c("left", "center"),
... ...
@@ -970,7 +970,7 @@ horizontal_continuous_legend_body = function(at, labels = at, col_fun,
970 970
 	ww = (legend_body_width - 2*offset)*(1/length(colors))
971 971
 	y2 = unit.c(unit(1, "npc"), y2, unit(1, "npc"))
972 972
 	x2 = unit.c(unit(0, "npc"), x2, legend_body_width - offset)
973
-	ww = unit.c(offset, ww, offset)
973
+	ww = unit.c(offset, rep(ww, length(x2) - 2), offset)
974 974
 	colors = c(colors[1], colors, colors[length(colors)])
975 975
 	
976 976
 	gl = c(gl, list(