From 96f27025ae8d3cf2cf10ea312799a2f266c25bb8 Mon Sep 17 00:00:00 2001 From: Don van den Bergh Date: Tue, 7 Jul 2026 22:12:42 +0200 Subject: [PATCH 1/2] fix for multiple plots that consist of a single plot --- NAMESPACE | 2 ++ R/plotEditing.R | 15 +++++++++++++-- R/plotEditingOptions.R | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 5ccc3e1c..1efd76cb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -36,6 +36,8 @@ S3method(parseThis,character) S3method(parseThis,factor) S3method(plot,jaspGraphs) S3method(plot,jaspGraphsPlot) +S3method(plotEditing,ggplot) +S3method(plotEditing,jaspGraphsPlot) S3method(print,jaspGraphs) S3method(print,jaspGraphsPlot) export(.graphOptions) diff --git a/R/plotEditing.R b/R/plotEditing.R index fce3af5e..a470d1ec 100644 --- a/R/plotEditing.R +++ b/R/plotEditing.R @@ -69,9 +69,20 @@ optionsDiff <- function(new, old) { #' #' @export plotEditing <- function(graph, newOptions) { + UseMethod("plotEditing", graph) +} + +#' @export +plotEditing.jaspGraphsPlot <- function(graph, newOptions) { + if (length(graph) > 1L) + stop2("This plot cannot be edited because it consists of multiple smaller figures.") - if (!is_ggplot(graph)) - stop2("graph should be a ggplot2") + graph[[1L]] <- plotEditing(graph[[1L]], newOptions) + return(graph) +} + +#' @export +plotEditing.ggplot <- function(graph, newOptions) { if (isTRUE(newOptions[["resetPlot"]])) { if (hasOriginalEditingOptions(graph)) { diff --git a/R/plotEditingOptions.R b/R/plotEditingOptions.R index bfbe8bd8..53f1a560 100644 --- a/R/plotEditingOptions.R +++ b/R/plotEditingOptions.R @@ -82,7 +82,9 @@ getPlotEditingOptions.qgraph <- function(graph) { #' @exportS3Method getPlotEditingOptions.jaspGraphsPlot <- function(graph) { - plotEditingOptionsError(gettext("This plot cannot be edited because it consists of multiple smaller figures.")) + if (length(graph) > 1L) + return(plotEditingOptionsError(gettext("This plot cannot be edited because it consists of multiple smaller figures."))) + return(getPlotEditingOptions(graph[[1L]])) } #' @exportS3Method getPlotEditingOptions "function" From f26c3be03883537833e5f1b6b3b350c98e2280b2 Mon Sep 17 00:00:00 2001 From: Don van den Bergh Date: Wed, 8 Jul 2026 09:30:57 +0200 Subject: [PATCH 2/2] fix issues found in review --- NAMESPACE | 1 + R/plotEditing.R | 9 +++++++-- R/plotEditingOptions.R | 2 +- man/plotEditing.Rd | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 1efd76cb..0e7163c3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -36,6 +36,7 @@ S3method(parseThis,character) S3method(parseThis,factor) S3method(plot,jaspGraphs) S3method(plot,jaspGraphsPlot) +S3method(plotEditing,default) S3method(plotEditing,ggplot) S3method(plotEditing,jaspGraphsPlot) S3method(print,jaspGraphs) diff --git a/R/plotEditing.R b/R/plotEditing.R index a470d1ec..6b6723c1 100644 --- a/R/plotEditing.R +++ b/R/plotEditing.R @@ -64,7 +64,7 @@ optionsDiff <- function(new, old) { } #' @title Edit a plot -#' @param graph a ggplot2 object +#' @param graph a ggplot2 object or a jaspGraphsPlot object #' @param newOptions an options list #' #' @export @@ -72,9 +72,14 @@ plotEditing <- function(graph, newOptions) { UseMethod("plotEditing", graph) } +#' @export +plotEditing.default <- function(graph, newOptions) { + stop2("graph should be a ggplot or a jaspGraphsPlot") +} + #' @export plotEditing.jaspGraphsPlot <- function(graph, newOptions) { - if (length(graph) > 1L) + if (length(graph) != 1L) stop2("This plot cannot be edited because it consists of multiple smaller figures.") graph[[1L]] <- plotEditing(graph[[1L]], newOptions) diff --git a/R/plotEditingOptions.R b/R/plotEditingOptions.R index 53f1a560..c52a813b 100644 --- a/R/plotEditingOptions.R +++ b/R/plotEditingOptions.R @@ -82,7 +82,7 @@ getPlotEditingOptions.qgraph <- function(graph) { #' @exportS3Method getPlotEditingOptions.jaspGraphsPlot <- function(graph) { - if (length(graph) > 1L) + if (length(graph) != 1L) return(plotEditingOptionsError(gettext("This plot cannot be edited because it consists of multiple smaller figures."))) return(getPlotEditingOptions(graph[[1L]])) } diff --git a/man/plotEditing.Rd b/man/plotEditing.Rd index afb1595d..ac72818e 100644 --- a/man/plotEditing.Rd +++ b/man/plotEditing.Rd @@ -7,7 +7,7 @@ plotEditing(graph, newOptions) } \arguments{ -\item{graph}{a ggplot2 object} +\item{graph}{a ggplot2 object or a jaspGraphsPlot object} \item{newOptions}{an options list} }