diff --git a/R/common.R b/R/common.R index 27c4621..8db8d7b 100644 --- a/R/common.R +++ b/R/common.R @@ -1122,6 +1122,7 @@ editImage <- function(name, optionsJson) { jaspPlotCPP$plotObject <- newPlot } + interactiveJsonData <- jaspPlotCPP$interactiveJsonData revision <- jaspPlotCPP$revision finishJaspResults(jaspResultsCPP, calledFromAnalysis = FALSE) @@ -1140,7 +1141,8 @@ editImage <- function(name, optionsJson) { height = height, revision = revision, error = FALSE, - editOptions = jaspGraphs::plotEditingOptions(plot) + editOptions = jaspGraphs::plotEditingOptions(plot), + interactiveJsonData = interactiveJsonData ) ) diff --git a/R/writeImage.R b/R/writeImage.R index 8a99519..55b036b 100755 --- a/R/writeImage.R +++ b/R/writeImage.R @@ -26,7 +26,7 @@ openGrDevice <- function(...) { ragg::agg_png(...) } -writeImageJaspResults <- function(plot, width = 320, height = 320, obj = TRUE, relativePathpng = NULL, ppi = 300, backgroundColor = "white", +writeImageJaspResults <- function(plot, width = 320, height = 320, obj = TRUE, relativePathpng = NULL, relativePathJson = NULL, ppi = 300, backgroundColor = "white", location = getImageLocation(), oldPlotInfo = list()) { # Set values from JASP'S Rcpp when available if (exists(".fromRCPP")) { @@ -132,7 +132,12 @@ writeImageJaspResults <- function(plot, width = 320, height = 320, obj = TRUE, r if (isTryError(jsonOrTryError)) { image[["interactiveConvertError"]] = gettextf("The following error occured while converting a ggplot to plotly: %s", .extractErrorMessage(jsonOrTryError)) } else { - locationPlotly <- .fromRCPP(".requestTempFileNameNative", "json") + + if (!is.null(relativePathJson) && nzchar(relativePathJson)) { + locationPlotly <- list(root = location$root, relativePath = relativePathJson) + } else { + locationPlotly <- .fromRCPP(".requestTempFileNameNative", "json") + } fullPathPlotly <- paste(locationPlotly$root, locationPlotly$relativePath, sep="/") plotlyJsonFile <- file(fullPathPlotly) on.exit(close(plotlyJsonFile), add = TRUE) diff --git a/src/jaspModuleRegistration.h b/src/jaspModuleRegistration.h index f55401e..2e4fb79 100644 --- a/src/jaspModuleRegistration.h +++ b/src/jaspModuleRegistration.h @@ -96,9 +96,10 @@ RCPP_MODULE(jaspResults) .property("plotObject", &jaspPlot_Interface::getPlotObject, &jaspPlot_Interface::setPlotObject, "Stores the plotObj used to generate the graphic, will (should) be stored in a way that is later accesible to saveImage an editImage.") - .property("editing", &jaspPlot_Interface::getEditing, &jaspPlot_Interface::setEditing, "If set to true will overwrite current png file when rendering a plot.") - .property("resizedByUser", &jaspPlot_Interface::getResizedByUser, &jaspPlot_Interface::setResizedByUser, "If set to true, a user resized the plot and its width and height may be recycled in future runs of this analysis.") - .property("revision", &jaspPlot_Interface::getRevision, "return the current revision of the plot.") + .property("editing", &jaspPlot_Interface::getEditing, &jaspPlot_Interface::setEditing, "If set to true will overwrite current png file when rendering a plot.") + .property("resizedByUser", &jaspPlot_Interface::getResizedByUser, &jaspPlot_Interface::setResizedByUser, "If set to true, a user resized the plot and its width and height may be recycled in future runs of this analysis.") + .property("revision", &jaspPlot_Interface::getRevision, "return the current revision of the plot.") + .property("interactiveJsonData", &jaspPlot_Interface::getInteractiveJsonData, "Returns the relative path to the interactive plotly JSON data file.") ; JASPLIST_MODULE_EXPORT(jaspStringlist_Interface, "jaspStringlist") @@ -189,7 +190,7 @@ RCPP_MODULE(jaspResults) .property("class", &jaspHtml_Interface::getClass, &jaspHtml_Interface::setClass, "The Css-class of this element, for monospace one could use jasp-code or simply leave it empty.") .property("maxWidth", &jaspHtml_Interface::getMaxWidth, &jaspHtml_Interface::setMaxWidth, "The Css-max-width property. It will be set on a span around your html.") ; - + Rcpp::class_("jaspReport") .derives("jaspObject") .property("text", &jaspReport_Interface::getText, &jaspReport_Interface::setText, "The text of this element") @@ -234,7 +235,7 @@ RCPP_MODULE(jaspResults) .method("prepareForWriting", &jaspResults_Interface::prepareForWriting, "Remove seal for writing") .method("finishWriting", &jaspResults_Interface::finishWriting, "Set seal for writing") - .method("saveResults", &jaspResults_Interface::saveResults, "save results") + .method("saveResults", &jaspResults_Interface::saveResults, "save results") ; Rcpp::class_("jaspQmlSource") diff --git a/src/jaspPlot.cpp b/src/jaspPlot.cpp index 53803eb..f36d19a 100644 --- a/src/jaspPlot.cpp +++ b/src/jaspPlot.cpp @@ -98,7 +98,7 @@ void jaspPlot::renderPlot() { oldPlotInfo = Rcpp::List(); _revision++; - writeResult = tryToWriteImage(Rcpp::_["width"] = _width, Rcpp::_["height"] = _height, Rcpp::_["plot"] = obj, Rcpp::_["oldPlotInfo"] = oldPlotInfo, Rcpp::_["relativePathpng"] = _filePathPng); + writeResult = tryToWriteImage(Rcpp::_["width"] = _width, Rcpp::_["height"] = _height, Rcpp::_["plot"] = obj, Rcpp::_["oldPlotInfo"] = oldPlotInfo, Rcpp::_["relativePathpng"] = _filePathPng, Rcpp::_["relativePathJson"] = Rcpp::String(_interactiveJsonData)); } else { diff --git a/src/jaspPlot.h b/src/jaspPlot.h index 7590df9..418a9f6 100644 --- a/src/jaspPlot.h +++ b/src/jaspPlot.h @@ -70,8 +70,9 @@ class jaspPlot_Interface : public jaspObject_Interface JASPOBJECT_INTERFACE_PROPERTY_FUNCTIONS_GENERATOR(jaspPlot, int, _height, Height) JASPOBJECT_INTERFACE_PROPERTY_FUNCTIONS_GENERATOR(jaspPlot, int, _revision, Revision) - JASPOBJECT_INTERFACE_PROPERTY_FUNCTIONS_GENERATOR_NO_NOTIFY(jaspPlot, bool, _editing, Editing) - JASPOBJECT_INTERFACE_PROPERTY_FUNCTIONS_GENERATOR_NO_NOTIFY(jaspPlot, bool, _resizedByUser, ResizedByUser) + JASPOBJECT_INTERFACE_PROPERTY_FUNCTIONS_GENERATOR_NO_NOTIFY(jaspPlot, bool, _editing, Editing) + JASPOBJECT_INTERFACE_PROPERTY_FUNCTIONS_GENERATOR_NO_NOTIFY(jaspPlot, bool, _resizedByUser, ResizedByUser) + JASPOBJECT_INTERFACE_PROPERTY_FUNCTIONS_GENERATOR_NO_NOTIFY(jaspPlot, std::string, _interactiveJsonData, InteractiveJsonData) }; RCPP_EXPOSED_CLASS_NODECL(jaspPlot_Interface)