Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions R/common.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2013-2018 University of Amsterdam
# Copyright (C) 2013-2026 University of Amsterdam
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -14,9 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

#' @importFrom stats na.omit

fromJSON <- function(x) jsonlite::fromJSON(x, TRUE, FALSE, FALSE)
toJSON <- function(x) jsonlite::toJSON(x, auto_unbox = TRUE, digits = NA, null="null")

Expand Down Expand Up @@ -1136,12 +1133,15 @@ editImage <- function(name, optionsJson) {
status = "imageEdited",
results = list(
name = plotName,
uniqueName = uniqueName,
pngFile = jaspPlotCPP$filePathPng,
jsonFile = interactiveJsonData,
resized = type == "resize",
width = width,
height = height,
revision = revision,
error = FALSE,
editOptions = jaspGraphs::plotEditingOptions(plot),
editOptions = jaspGraphs::plotEditingOptions(jaspPlotCPP$plotObject),
interactiveJsonData = interactiveJsonData
)
)
Expand Down
23 changes: 21 additions & 2 deletions R/writeImage.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#Originally in common.R in package JASP, extracted here and changed for standalone use in jaspResults/jaspTools

#
# Copyright (C) 2013-2026 University of Amsterdam
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
tryToWriteImageJaspResults <- function(...) {
tryCatch(
suppressWarnings(return(writeImageJaspResults(...))),
Expand Down Expand Up @@ -127,6 +141,7 @@ writeImageJaspResults <- function(plot, width = 320, height = 320, obj = TRUE, r
tryCatch(
{
jsonOrTryError <- jaspGraphs::convertGgplotToPlotly(plot)
cat("DEBUG writeImage: plotly generated, nchar=", nchar(jsonOrTryError), " isTryError=", isTryError(jsonOrTryError), "\n", file = stderr())

if (exists(".fromRCPP")) {
if (isTryError(jsonOrTryError)) {
Expand All @@ -135,8 +150,10 @@ writeImageJaspResults <- function(plot, width = 320, height = 320, obj = TRUE, r

if (!is.null(relativePathJson) && nzchar(relativePathJson)) {
locationPlotly <- list(root = location$root, relativePath = relativePathJson)
cat("DEBUG writeImage: reusing interactiveJsonData path='", relativePathJson, "'\n", file = stderr())
} else {
locationPlotly <- .fromRCPP(".requestTempFileNameNative", "json")
cat("DEBUG writeImage: NEW interactiveJsonData path='", locationPlotly$relativePath, "'\n", file = stderr())
}
fullPathPlotly <- paste(locationPlotly$root, locationPlotly$relativePath, sep="/")
plotlyJsonFile <- file(fullPathPlotly)
Expand All @@ -145,11 +162,13 @@ writeImageJaspResults <- function(plot, width = 320, height = 320, obj = TRUE, r

if(file.exists(fullPathPlotly)) {
image[["interactiveJsonData"]] <- locationPlotly$relativePath
cat("DEBUG writeImage: file written OK, interactiveJsonData='", locationPlotly$relativePath, "'\n", file = stderr())
}
else
{
image[["interactiveJsonData"]] <- ""
image[["interactiveConvertError"]] <- gettext("No interactive plot generated...")
cat("DEBUG writeImage: file NOT found after write! fullPathPlotly='", fullPathPlotly, "'\n", file = stderr())
}
}
}
Expand Down
Loading