Browse code

Fix for #62. Recursive use of Overlaytracks and wrong panel.

Robert Ivánek authored on 07/04/2022 12:36:00
Showing 1 changed files

... ...
@@ -381,14 +381,26 @@ plotTracks <- function(trackList, from = NULL, to = NULL, ..., sizes = NULL, pan
381 381
         .drawHtBoxes(htBoxes)
382 382
     }
383 383
     ## Now the track content
384
-    for (i in rev(seq_along(expandedTrackList)))
385
-    {
384
+    for (i in rev(seq_along(expandedTrackList))) {
386 385
         vpTrack <- viewport(x = 0, y = sum(spaceSetup$spaceNeeded[seq_len(i)]), just = c(0, 1), width = 1, height = spaceSetup$spaceNeeded[i])
387 386
         pushViewport(vpTrack)
388 387
         fill <- .dpOrDefault(expandedTrackList[[i]], "background.title", .DEFAULT_SHADED_COL)
389
-        thisTrack <- if (is(expandedTrackList[[i]], "OverlayTrack")) expandedTrackList[[i]]@trackList[[1]] else expandedTrackList[[i]]
388
+        thisTrack <- if (is(expandedTrackList[[i]], "OverlayTrack")) {
389
+            tmpThisTrack <- expandedTrackList[[i]]@trackList
390
+             while (any(vapply(tmpThisTrack, is, "OverlayTrack", FUN.VALUE = logical(1L)))) {
391
+                 tmpThisTrack <- rapply(tmpThisTrack, function(x) if (is(x, "OverlayTrack")) x@trackList else x)
392
+             }
393
+            tmpSpaceSetup <- .setupTextSize(list(tmpThisTrack[[1]]), sizes, title.width, spacing = innerMargin)
394
+            spaceSetup$nwrap[i] <- tmpSpaceSetup$nwrap[1]
395
+            if (spaceSetup$title.width < tmpSpaceSetup$title.width) {
396
+                spaceSetup$title.width <- tmpSpaceSetup$title.width
397
+            }
398
+            tmpThisTrack[[1]]
399
+        } else {
400
+            expandedTrackList[[i]]
401
+        }
390 402
         if (!panel.only) {
391
-            fontSettings <- .fontGp(expandedTrackList[[i]], subtype = "title", cex = NULL)
403
+            fontSettings <- .fontGp(thisTrack, subtype = "title", cex = NULL)
392 404
             vpTitle <- viewport(x = 0, width = spaceSetup$title.width, just = 0, gp = fontSettings)
393 405
             pushViewport(vpTitle)
394 406
             lwd.border.title <- .dpOrDefault(thisTrack, "lwd.title", 1)
... ...
@@ -399,7 +411,7 @@ plotTracks <- function(trackList, from = NULL, to = NULL, ..., sizes = NULL, pan
399 411
             tit <- spaceSetup$nwrap[i]
400 412
             ## FIXME: Do we want something smarted for the image map coordinates?
401 413
             titleCoords <- rbind(titleCoords, cbind(.getImageMap(cbind(0, 0, 1, 1)),
402
-                title = names(expandedTrackList[[i]])
414
+                title = names(thisTrack)
403 415
             ))
404 416
             if (.dpOrDefault(thisTrack, "showTitle", TRUE) && !is.null(tit) && tit != "") {
405 417
                 x <- if (needAxis) 0.075 else 0.4