Browse code

adjust when numbers_rot = 0

Zuguang Gu authored on 04/08/2021 20:30:13
Showing1 changed files

... ...
@@ -1302,7 +1302,11 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR
1302 1302
 	if(ncol(value) == 1) {
1303 1303
 		if(add_numbers) {
1304 1304
 			if(which == "column") {
1305
-				extend = convertHeight(sin(numbers_rot/180*pi)*max_text_width(value, gp = numbers_gp) + numbers_offset + unit(4, "mm"), "mm", valueOnly = TRUE)/convertHeight(anno_size$height, "mm", valueOnly = TRUE)*(data_scale[2] - data_scale[1])
1305
+				if(numbers_rot == 0) {
1306
+					extend = convertHeight(max_text_height(value, gp = numbers_gp) + numbers_offset + unit(2, "mm"), "mm", valueOnly = TRUE)/convertHeight(anno_size$height, "mm", valueOnly = TRUE)*(data_scale[2] - data_scale[1])
1307
+				} else {
1308
+					extend = convertHeight(sin(numbers_rot/180*pi)*max_text_width(value, gp = numbers_gp) + numbers_offset + unit(4, "mm"), "mm", valueOnly = TRUE)/convertHeight(anno_size$height, "mm", valueOnly = TRUE)*(data_scale[2] - data_scale[1])
1309
+				}
1306 1310
 				data_scale[2] = data_scale[2] + extend
1307 1311
 			} else if(which == "row") {
1308 1312
 				extend = convertWidth(cos(numbers_rot/180*pi)*max_text_width(value, gp = numbers_gp) + numbers_offset + unit(4, "mm"), "mm", valueOnly = TRUE)/convertWidth(anno_size$width, "mm", valueOnly = TRUE)*(data_scale[2] - data_scale[1])
... ...
@@ -1385,7 +1389,11 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR
1385 1389
 				if(!is.null(attr(value, "labels_format"))) {
1386 1390
 					txt = attr(value, "labels_format")(value[index])
1387 1391
 				}
1388
-				grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") + numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("left"), rot = numbers_rot)
1392
+				if(numbers_rot == 0) {
1393
+					grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") + numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("bottom"))
1394
+				} else {
1395
+					grid.text(txt, x = seq_along(index), y = unit(baseline + height, "native") + numbers_offset, default.units = "native", gp = subset_gp(numbers_gp, index), just = c("left"), rot = numbers_rot)
1396
+				}
1389 1397
 			}
1390 1398
 		} else {
1391 1399
 			for(i in seq_len(ncol(value))) {