From 6a661da8b383ae78fb446737b61bf32d80d473f2 Mon Sep 17 00:00:00 2001 From: David <david.dorchies@inrae.fr> Date: Sun, 14 Apr 2024 19:25:17 +0200 Subject: [PATCH] feat(plot.GRiwrm): remove margins Refs #150 --- R/plot.GRiwrm.R | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/R/plot.GRiwrm.R b/R/plot.GRiwrm.R index a3a2800..17e0323 100644 --- a/R/plot.GRiwrm.R +++ b/R/plot.GRiwrm.R @@ -204,14 +204,31 @@ mermaid_gen_link <- function(diagram, theme = "default", format = "png", server #' @return Nothing, used to side effect. #' @noRd #' -plot_png = function(path, add=FALSE) +plot_png = function(path, add = FALSE) { - # read the file + # read the file pic <- png::readPNG(path, native = TRUE) res <- dim(pic)[2:1] # get the resolution, [x, y] - if (!add) # initialize an empty plot area if add==FALSE - plot(1,1,xlim=c(1,res[1]),ylim=c(1,res[2]),asp=1,type='n',xaxs='i',yaxs='i',xaxt='n',yaxt='n',xlab='',ylab='',bty='n') - graphics::rasterImage(pic,1,1,res[1],res[2]) + if (!add) { + opar <- par(mar = c(0, 0, 0, 0)) + plot( + 1, + 1, + xlim = c(1, res[1]), + ylim = c(1, res[2]), + asp = 1, + type = 'n', + xaxs = 'i', + yaxs = 'i', + xaxt = 'n', + yaxt = 'n', + xlab = '', + ylab = '', + bty = 'n' + ) + par(opar) + } + graphics::rasterImage(pic, 1, 1, res[1], res[2], xpd = T) } #' Plot a mermaid diagram -- GitLab