@@ -383,6 +383,7 @@ export class WebREvaluator implements ExerciseEvaluator {
383383 const imageDiv = document . createElement ( "img" ) ;
384384 outputDiv . className = "cell-output-display cell-output-pyodide" ;
385385 imageDiv . src = `data:${ mime } ;base64, ${ data } ` ;
386+ imageDiv . style . maxWidth = "100%" ;
386387 outputDiv . appendChild ( imageDiv ) ;
387388 container . appendChild ( outputDiv ) ;
388389 }
@@ -426,28 +427,31 @@ export class WebREvaluator implements ExerciseEvaluator {
426427
427428 // Plot image
428429 if ( classes . includes ( 'recordedplot' ) ) {
429- let width = await this . webR . evalRNumber ( '72 * getOption("webr.fig.width")' ) ;
430+ let width = await this . webR . evalRNumber ( 'getOption("webr.fig.width")' ) ;
430431 if ( "fig-width" in this . options ) {
431- width = 72 * Number ( this . options [ "fig-width" ] ) ;
432+ width = Number ( this . options [ "fig-width" ] ) ;
432433 }
433- let height = await this . webR . evalRNumber ( '72 * getOption("webr.fig.height")' ) ;
434+ let height = await this . webR . evalRNumber ( 'getOption("webr.fig.height")' ) ;
434435 if ( "fig-height" in this . options ) {
435- height = 72 * Number ( this . options [ "fig-height" ] ) ;
436+ height = Number ( this . options [ "fig-height" ] ) ;
436437 }
437438
438- if ( typeof OffscreenCanvas !== "undefined" ) {
439+ if ( typeof OffscreenCanvas !== "undefined" && this . options . canvas ) {
439440 const capturePlot = await shelter . captureR ( "replayPlot(plot)" , {
440- captureGraphics : { width, height } ,
441+ captureGraphics : { width : 72 * width , height : 72 * height } ,
441442 env : { plot : result [ i ] } ,
442443 } ) ;
443444 appendImage ( capturePlot . images [ 0 ] ) ;
444445 } else {
445446 // Fallback to cairo graphics
446447 const data = await shelter . evalR ( `
447448 tmp_dir <- tempdir()
448- on.exit(unlink(tmp_dir, recursive = TRUE))
449449 filename <- paste0(tmp_dir, ".webr-plot.png")
450- png(file = filename, width = width, height = height)
450+ if (requireNamespace("ragg", quietly = TRUE)) {
451+ ragg::agg_png(file = filename, width = width, height = height, units = "in", res = 300)
452+ } else {
453+ png(file = filename, width = width, height = height, units = "in", res = 300)
454+ }
451455 replayPlot(plot)
452456 dev.off()
453457 filesize <- file.info(filename)[["size"]]
@@ -507,7 +511,7 @@ export class WebREvaluator implements ExerciseEvaluator {
507511 const height = await this . webR . evalRNumber ( '72 * getOption("webr.fig.height")' ) ;
508512 let images : ( ImageBitmap | HTMLImageElement ) [ ] = [ ] ;
509513
510- const hasOffscreenCanvas = typeof OffscreenCanvas !== "undefined" ;
514+ const hasOffscreenCanvas = this . options . canvas && typeof OffscreenCanvas !== "undefined" ;
511515 if ( ! hasOffscreenCanvas ) {
512516 // Fallback to cairo graphics
513517 this . webR . evalRVoid ( `
0 commit comments