@@ -114,6 +114,19 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
114
114
# Our internal version of ggplot2::ggplot_build(). Modified from
115
115
# https://github.com/hadley/ggplot2/blob/0cd0ba/R/plot-build.r#L18-L92
116
116
# ------------------------------------------------------------------------
117
+
118
+ # create a viewport so we can convert relative sizes correctly
119
+ # if height/width not specified, it is estimated from current viewport (npc)
120
+ width <- width %|| % unitConvert(grid :: unit(1 , " npc" ), " pixels" , " width" )
121
+ height <- height %|| % unitConvert(grid :: unit(1 , " npc" ), " pixels" , " height" )
122
+ # assume 96 dots per inch...mm2pixels also does this....
123
+ vp <- grid :: viewport(
124
+ width = grid :: unit(width * 72.27 / 96 , " points" ),
125
+ height = grid :: unit(height * 72.27 / 96 , " points" )
126
+ )
127
+ grid :: pushViewport(vp , recording = FALSE )
128
+
129
+
117
130
p <- ggfun(" plot_clone" )(p )
118
131
if (length(p $ layers ) == 0 ) {
119
132
p <- p + geom_blank()
@@ -668,6 +681,8 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
668
681
gglayout $ width <- width
669
682
gglayout $ height <- height
670
683
684
+ grid :: popViewport()
685
+
671
686
l <- list (
672
687
data = setNames(traces , NULL ),
673
688
layout = compact(gglayout ),
0 commit comments