Browse code

support gridtext

Zuguang Gu authored on 21/03/2020 14:32:08
Showing1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,106 +0,0 @@
1
-# `[.grob` = function(x, i) {
2
-# 	x2 = x
3
-# 	for(nm in SUBSETABLE_FIELDS[[ intersect(names(SUBSETABLE_FIELDS), class(x)) ]]) {
4
-# 		if(inherits(x2[[nm]], "gpar")) {
5
-# 			# change to the class defined here
6
-# 			class(x2[[nm]]) = "gpar"
7
-# 		}
8
-
9
-# 		if(length(x2[[nm]]) > 1) {
10
-# 			x2[[nm]] = x2[[nm]][i]
11
-# 		}
12
-# 	}
13
-# 	x2
14
-# }
15
-
16
-# `[.gpar` = function(x, i) {
17
-# 	lapply(x, function(y) {
18
-# 		if(length(y) > 1) {
19
-# 			y[i]
20
-# 		} else {
21
-# 			y
22
-# 		}
23
-# 	})
24
-# }
25
-
26
-# SUBSETABLE_FIELDS = list(
27
-# 	"text" = c("label", "x", "y", "gp"),
28
-# 	"richtext_grob" = c("gp", "children", "childrenOrder")
29
-# )
30
-
31
-# length.text = function(x) {
32
-# 	length(x$label)
33
-# }
34
-
35
-# length.richtext_grob = function(x) {
36
-# 	length(x$children)
37
-# }
38
-
39
-# update_xy = function (gb, x, y, ...) {
40
-# 	UseMethod("update_xy")
41
-# }
42
-
43
-# update_xy.text = function(gb, x, y, ...) {
44
-# 	n = length(gb$label)
45
-# 	if(!missing(x)) {
46
-# 		if(n > 1 & length(x) > 1 && n != length(x)) {
47
-# 			stop_wrap("Length of `x` should be the same as the length of labels.")
48
-# 		}
49
-# 		gb$x = x
50
-# 	}
51
-# 	if(!missing(y)) {
52
-# 		if(n > 1 & length(y) > 1 && n != length(y)) {
53
-# 			stop_wrap("Length of `y` should be the same as the length of labels.")
54
-# 		}
55
-# 		gb$y = y
56
-# 	}
57
-# 	gb
58
-# }
59
-
60
-# update_xy.richtext_grob = function(gb, x, y, ...) {
61
-# 	n = length(gb$children)
62
-
63
-# 	if(!missing(x)) {
64
-# 		if(n > 1 & length(x) > 1 && n != length(x)) {
65
-# 			stop_wrap("Length of `x` should be the same as the length of labels.")
66
-# 		}
67
-# 		for(i in 1:n) {
68
-# 			if(length(x) == 1) {
69
-# 				gb$children[[i]]$vp$x = x
70
-# 			} else {
71
-# 				gb$children[[i]]$vp$x = x[i]
72
-# 			}
73
-# 		}
74
-# 	}
75
-# 	if(!missing(y)) {
76
-# 		if(n > 1 & length(y) > 1 && n != length(y)) {
77
-# 			stop_wrap("Length of `y` should be the same as the length of labels.")
78
-# 		}
79
-# 		for(i in 1:n) {
80
-# 			if(length(y) == 1) {
81
-# 				gb$children[[i]]$vp$y = y
82
-# 			} else {
83
-# 				gb$children[[i]]$vp$y = y[i]
84
-# 			}
85
-# 		}
86
-# 	}
87
-# 	gb
88
-# }
89
-
90
-# textGrob = function(label, ...) {
91
-# 	if(inherits(label, "grob")) {
92
-# 		return(label)
93
-# 	} else {
94
-# 		grid::textGrob(label, ...)
95
-# 	}
96
-# }
97
-
98
-# grid.text = function(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"), ...) {
99
-# 	if(inherits(label, "grob")) {
100
-# 		gb = label
101
-# 		gb = update_xy(gb, x, y)
102
-# 		grid.draw(gb)
103
-# 	} else {
104
-# 		grid::grid.text(label, x, y, ...)
105
-# 	}
106
-# }
Browse code

anno_simple(): fixed a bug when all pch are NA in a slice

Zuguang Gu authored on 25/02/2020 14:51:37
Showing1 changed files
... ...
@@ -1,106 +1,106 @@
1
-`[.grob` = function(x, i) {
2
-	x2 = x
3
-	for(nm in SUBSETABLE_FIELDS[[ intersect(names(SUBSETABLE_FIELDS), class(x)) ]]) {
4
-		if(inherits(x2[[nm]], "gpar")) {
5
-			# change to the class defined here
6
-			class(x2[[nm]]) = "gpar"
7
-		}
1
+# `[.grob` = function(x, i) {
2
+# 	x2 = x
3
+# 	for(nm in SUBSETABLE_FIELDS[[ intersect(names(SUBSETABLE_FIELDS), class(x)) ]]) {
4
+# 		if(inherits(x2[[nm]], "gpar")) {
5
+# 			# change to the class defined here
6
+# 			class(x2[[nm]]) = "gpar"
7
+# 		}
8 8
 
9
-		if(length(x2[[nm]]) > 1) {
10
-			x2[[nm]] = x2[[nm]][i]
11
-		}
12
-	}
13
-	x2
14
-}
9
+# 		if(length(x2[[nm]]) > 1) {
10
+# 			x2[[nm]] = x2[[nm]][i]
11
+# 		}
12
+# 	}
13
+# 	x2
14
+# }
15 15
 
16
-`[.gpar` = function(x, i) {
17
-	lapply(x, function(y) {
18
-		if(length(y) > 1) {
19
-			y[i]
20
-		} else {
21
-			y
22
-		}
23
-	})
24
-}
16
+# `[.gpar` = function(x, i) {
17
+# 	lapply(x, function(y) {
18
+# 		if(length(y) > 1) {
19
+# 			y[i]
20
+# 		} else {
21
+# 			y
22
+# 		}
23
+# 	})
24
+# }
25 25
 
26
-SUBSETABLE_FIELDS = list(
27
-	"text" = c("label", "x", "y", "gp"),
28
-	"richtext_grob" = c("gp", "children", "childrenOrder")
29
-)
26
+# SUBSETABLE_FIELDS = list(
27
+# 	"text" = c("label", "x", "y", "gp"),
28
+# 	"richtext_grob" = c("gp", "children", "childrenOrder")
29
+# )
30 30
 
31
-length.text = function(x) {
32
-	length(x$label)
33
-}
31
+# length.text = function(x) {
32
+# 	length(x$label)
33
+# }
34 34
 
35
-length.richtext_grob = function(x) {
36
-	length(x$children)
37
-}
35
+# length.richtext_grob = function(x) {
36
+# 	length(x$children)
37
+# }
38 38
 
39
-update_xy = function (gb, x, y, ...) {
40
-	UseMethod("update_xy")
41
-}
39
+# update_xy = function (gb, x, y, ...) {
40
+# 	UseMethod("update_xy")
41
+# }
42 42
 
43
-update_xy.text = function(gb, x, y, ...) {
44
-	n = length(gb$label)
45
-	if(!missing(x)) {
46
-		if(n > 1 & length(x) > 1 && n != length(x)) {
47
-			stop_wrap("Length of `x` should be the same as the length of labels.")
48
-		}
49
-		gb$x = x
50
-	}
51
-	if(!missing(y)) {
52
-		if(n > 1 & length(y) > 1 && n != length(y)) {
53
-			stop_wrap("Length of `y` should be the same as the length of labels.")
54
-		}
55
-		gb$y = y
56
-	}
57
-	gb
58
-}
43
+# update_xy.text = function(gb, x, y, ...) {
44
+# 	n = length(gb$label)
45
+# 	if(!missing(x)) {
46
+# 		if(n > 1 & length(x) > 1 && n != length(x)) {
47
+# 			stop_wrap("Length of `x` should be the same as the length of labels.")
48
+# 		}
49
+# 		gb$x = x
50
+# 	}
51
+# 	if(!missing(y)) {
52
+# 		if(n > 1 & length(y) > 1 && n != length(y)) {
53
+# 			stop_wrap("Length of `y` should be the same as the length of labels.")
54
+# 		}
55
+# 		gb$y = y
56
+# 	}
57
+# 	gb
58
+# }
59 59
 
60
-update_xy.richtext_grob = function(gb, x, y, ...) {
61
-	n = length(gb$children)
60
+# update_xy.richtext_grob = function(gb, x, y, ...) {
61
+# 	n = length(gb$children)
62 62
 
63
-	if(!missing(x)) {
64
-		if(n > 1 & length(x) > 1 && n != length(x)) {
65
-			stop_wrap("Length of `x` should be the same as the length of labels.")
66
-		}
67
-		for(i in 1:n) {
68
-			if(length(x) == 1) {
69
-				gb$children[[i]]$vp$x = x
70
-			} else {
71
-				gb$children[[i]]$vp$x = x[i]
72
-			}
73
-		}
74
-	}
75
-	if(!missing(y)) {
76
-		if(n > 1 & length(y) > 1 && n != length(y)) {
77
-			stop_wrap("Length of `y` should be the same as the length of labels.")
78
-		}
79
-		for(i in 1:n) {
80
-			if(length(y) == 1) {
81
-				gb$children[[i]]$vp$y = y
82
-			} else {
83
-				gb$children[[i]]$vp$y = y[i]
84
-			}
85
-		}
86
-	}
87
-	gb
88
-}
63
+# 	if(!missing(x)) {
64
+# 		if(n > 1 & length(x) > 1 && n != length(x)) {
65
+# 			stop_wrap("Length of `x` should be the same as the length of labels.")
66
+# 		}
67
+# 		for(i in 1:n) {
68
+# 			if(length(x) == 1) {
69
+# 				gb$children[[i]]$vp$x = x
70
+# 			} else {
71
+# 				gb$children[[i]]$vp$x = x[i]
72
+# 			}
73
+# 		}
74
+# 	}
75
+# 	if(!missing(y)) {
76
+# 		if(n > 1 & length(y) > 1 && n != length(y)) {
77
+# 			stop_wrap("Length of `y` should be the same as the length of labels.")
78
+# 		}
79
+# 		for(i in 1:n) {
80
+# 			if(length(y) == 1) {
81
+# 				gb$children[[i]]$vp$y = y
82
+# 			} else {
83
+# 				gb$children[[i]]$vp$y = y[i]
84
+# 			}
85
+# 		}
86
+# 	}
87
+# 	gb
88
+# }
89 89
 
90
-textGrob = function(label, ...) {
91
-	if(inherits(label, "grob")) {
92
-		return(label)
93
-	} else {
94
-		grid::textGrob(label, ...)
95
-	}
96
-}
90
+# textGrob = function(label, ...) {
91
+# 	if(inherits(label, "grob")) {
92
+# 		return(label)
93
+# 	} else {
94
+# 		grid::textGrob(label, ...)
95
+# 	}
96
+# }
97 97
 
98
-grid.text = function(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"), ...) {
99
-	if(inherits(label, "grob")) {
100
-		gb = label
101
-		gb = update_xy(gb, x, y)
102
-		grid.draw(gb)
103
-	} else {
104
-		grid::grid.text(label, x, y, ...)
105
-	}
106
-}
98
+# grid.text = function(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"), ...) {
99
+# 	if(inherits(label, "grob")) {
100
+# 		gb = label
101
+# 		gb = update_xy(gb, x, y)
102
+# 		grid.draw(gb)
103
+# 	} else {
104
+# 		grid::grid.text(label, x, y, ...)
105
+# 	}
106
+# }
Browse code

support gridtext

Zuguang Gu authored on 05/02/2020 07:34:10
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,106 @@
1
+`[.grob` = function(x, i) {
2
+	x2 = x
3
+	for(nm in SUBSETABLE_FIELDS[[ intersect(names(SUBSETABLE_FIELDS), class(x)) ]]) {
4
+		if(inherits(x2[[nm]], "gpar")) {
5
+			# change to the class defined here
6
+			class(x2[[nm]]) = "gpar"
7
+		}
8
+
9
+		if(length(x2[[nm]]) > 1) {
10
+			x2[[nm]] = x2[[nm]][i]
11
+		}
12
+	}
13
+	x2
14
+}
15
+
16
+`[.gpar` = function(x, i) {
17
+	lapply(x, function(y) {
18
+		if(length(y) > 1) {
19
+			y[i]
20
+		} else {
21
+			y
22
+		}
23
+	})
24
+}
25
+
26
+SUBSETABLE_FIELDS = list(
27
+	"text" = c("label", "x", "y", "gp"),
28
+	"richtext_grob" = c("gp", "children", "childrenOrder")
29
+)
30
+
31
+length.text = function(x) {
32
+	length(x$label)
33
+}
34
+
35
+length.richtext_grob = function(x) {
36
+	length(x$children)
37
+}
38
+
39
+update_xy = function (gb, x, y, ...) {
40
+	UseMethod("update_xy")
41
+}
42
+
43
+update_xy.text = function(gb, x, y, ...) {
44
+	n = length(gb$label)
45
+	if(!missing(x)) {
46
+		if(n > 1 & length(x) > 1 && n != length(x)) {
47
+			stop_wrap("Length of `x` should be the same as the length of labels.")
48
+		}
49
+		gb$x = x
50
+	}
51
+	if(!missing(y)) {
52
+		if(n > 1 & length(y) > 1 && n != length(y)) {
53
+			stop_wrap("Length of `y` should be the same as the length of labels.")
54
+		}
55
+		gb$y = y
56
+	}
57
+	gb
58
+}
59
+
60
+update_xy.richtext_grob = function(gb, x, y, ...) {
61
+	n = length(gb$children)
62
+
63
+	if(!missing(x)) {
64
+		if(n > 1 & length(x) > 1 && n != length(x)) {
65
+			stop_wrap("Length of `x` should be the same as the length of labels.")
66
+		}
67
+		for(i in 1:n) {
68
+			if(length(x) == 1) {
69
+				gb$children[[i]]$vp$x = x
70
+			} else {
71
+				gb$children[[i]]$vp$x = x[i]
72
+			}
73
+		}
74
+	}
75
+	if(!missing(y)) {
76
+		if(n > 1 & length(y) > 1 && n != length(y)) {
77
+			stop_wrap("Length of `y` should be the same as the length of labels.")
78
+		}
79
+		for(i in 1:n) {
80
+			if(length(y) == 1) {
81
+				gb$children[[i]]$vp$y = y
82
+			} else {
83
+				gb$children[[i]]$vp$y = y[i]
84
+			}
85
+		}
86
+	}
87
+	gb
88
+}
89
+
90
+textGrob = function(label, ...) {
91
+	if(inherits(label, "grob")) {
92
+		return(label)
93
+	} else {
94
+		grid::textGrob(label, ...)
95
+	}
96
+}
97
+
98
+grid.text = function(label, x = unit(0.5, "npc"), y = unit(0.5, "npc"), ...) {
99
+	if(inherits(label, "grob")) {
100
+		gb = label
101
+		gb = update_xy(gb, x, y)
102
+		grid.draw(gb)
103
+	} else {
104
+		grid::grid.text(label, x, y, ...)
105
+	}
106
+}