trackViewer
trackViewer copied to clipboard
y track labels positioned within margins?
Hi, I'm struggling to understand the calculations for positioning the y labels in tracks. It seems you are defining a viewport for the text grob in such a way that it spans the space of the margin and then positions the text at a relative ratio height inside the margin while always vertically adjusting it to "bottom".
example with "topleft":
topleft=viewport(y=1-yHeightTop, height=yHeightTop, just="bottom")
yHeightTop
is defined as the track top margin.
This essentially draws the label in the margin space, instead of below the margin space. I think that either a) the vertical justification should be "top" so that the text drops below the margin or b) the viewport y calculation should include the negative text height (i.e. y=1-yHeightTop-stringHeight(name)
).
Also, the y coordinate for the grid.text is set (fixed) to .1 https://github.com/jianhong/trackViewer/blob/28dc491047ace8ddcbe52994d3e4d71ff6fbd48c/R/privateUtil.R#L313 which forces its baseline height to 10% inside the vertical margin space. The bottom text grobs are analogously are drawn at 90% y, and again vertically aligned "bottom", which if nothing else, does not render these labels symmetrically. But, more importantly, because of this placement system within margins, this floats and stretches the label positions within the margin space, making them very tricky to adjust to a specific font size/final image height, especially in case of multiple GRanges tracks. One nasty artifact is loosing the label completely if you set the ViewerStyle top margin to 0 and have the topleft label positioning.
Please correct me if I understood it wrongly. I can further explain the problem in the very likely case I did not explain it properly in the fist attempt :)
Additionally, would it be possible to replace the push- and pop- viewport commands with the down- and up- equivalents, so that the viewport structure gets preserved when the plot is drawn. This would make it much easier to debug and add additional elements in the post-processing.
Thanks!
https://github.com/jianhong/trackViewer/blob/28dc491047ace8ddcbe52994d3e4d71ff6fbd48c/R/privateUtil.R#L271