66# ' \code{\link{build_grviz}} or \code{plot(g, grViz = TRUE)} for
77# ' multiple split nodes instead.
88# '
9- # ' @param x A conosrt object.
9+ # ' @param x A consort object.
1010# '
1111# ' @return A \code{gList} object
1212# ' @export
@@ -54,13 +54,16 @@ build_grid <- function(x) {
5454 nodes_coord $ y <- (vp_height - nodes_coord $ y )/ vp_height
5555
5656 if (any(grepl(" label" , names(x )))){
57- label_coord <- calc_coords_label(label_plot ,
58- nodes_coord $ nd_y ,
57+ label_coord <- calc_coords_label(label_plot ,
58+ nodes_coord $ nd_y ,
5959 max_h = nodes_coord $ max_height )
6060 vp_width <- sum(label_coord $ width [1 ], vp_width )
6161
6262 nodes_coord $ x <- (nodes_coord $ x + label_coord $ width [1 ])/ vp_width
63-
63+
64+ # Convert label x from char units to NPC so they scale with the viewport
65+ label_coord $ x <- label_coord $ x / vp_width
66+
6467 }else {
6568 nodes_coord $ x <- (nodes_coord $ x )/ vp_width
6669 }
@@ -72,22 +75,17 @@ build_grid <- function(x) {
7275 y = unit(nodes_coord $ y [i ], " npc" ))
7376 r $ name <- i
7477
75- # Skep empty side box
78+ # Skip empty side box
7679 if (is_empty(consort_plot [[i ]]$ text ))
7780 return (NULL )
7881
7982 return (r )
8083 }, simplify = FALSE )
8184
85+ grobs_list <- gList()
8286 for (i in seq_along(nodes )) {
83- if (is.null(nodes [[i ]]))
84- next
85-
86- if (i == 1 ) {
87- grobs_list <- gList(gList(), nodes [[i ]])
88- } else {
87+ if (! is.null(nodes [[i ]]))
8988 grobs_list <- gList(grobs_list , nodes [[i ]])
90- }
9189 }
9290
9391 # Connections
@@ -115,28 +113,22 @@ build_grid <- function(x) {
115113 for (i in seq_along(label_plot )){
116114 nam <- names(label_plot )[i ]
117115 r <- move_box(label_plot [[nam ]]$ box ,
118- x = unit(label_coord $ x [nam ], " char " ),
116+ x = unit(label_coord $ x [nam ], " npc " ),
119117 y = unit(label_coord $ y [nam ], " npc" ))
120118 r $ name <- nam
121119
122- if (i == 1 ) {
123- lab_grobs <- gList(gList(), r )
124- } else {
125- lab_grobs <- gList(lab_grobs , r )
126- }
120+ lab_grobs <- if (i == 1 ) gList(r ) else gList(lab_grobs , r )
127121 }
128122
129123 grobs_list <- gList(grobs_list , lab_grobs )
130124
131125 }
132126
133- grobTree(grobs_list ,
127+ grobTree(grobs_list ,
134128 name = " consort" ,
135129 vp = viewport(width = unit(0.98 , " npc" ),
136130 height = unit(0.98 , " npc" )))
137-
138- # return(grobs_list)
139-
131+
140132}
141133
142134
0 commit comments