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
11 changes: 11 additions & 0 deletions R/writeImage.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ writeImageJaspResults <- function(plot, width = 320, height = 320, obj = TRUE, r

image[["editOptions"]] <- jaspGraphs::plotEditingOptions(plot, asJSON = TRUE)

image[["interactive"]] <- ggplot2::is.ggplot(plot)
if (image[["interactive"]] ) {

jsonOrTryError <- jaspGraphs::convertGgplotToPlotly(plot)

if (inherits(jsonOrTryError, "try-error"))
image[["interactiveConvertError"]] <- gettextf("The following error occured while converting a ggplot to plotly: %s", jsonOrTryError$message)
else
image[["interactiveJsonData"]] <- jsonOrTryError
}

return(image)
}

Expand Down
14 changes: 7 additions & 7 deletions src/jaspHtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ std::string jaspHtml::sanitizeTextForHtml(std::string text)

std::string jaspHtml::convertTextToHtml(std::string text) const
{
// first we replace \n by <br>
text = sanitizeTextForHtml(text);
// first we replace \n by <br>
text = sanitizeTextForHtml(text);

// Then add element tags
std::stringstream out;
// Then add element tags
std::stringstream out;
if(_elementType != "" && _elementType != "errorMsg")
out << "<" << _elementType << (_class != "" ? "class=\""+_class+'"' : "") << ">";
out << "<" << _elementType << (_class != "" ? "class=\""+_class+'"' : "") << ">";

out << text;
out << text;

if(_elementType != "" && _elementType != "errorMsg")
out << " </" << _elementType << ">";

return out.str();
return out.str();
}

std::string jaspHtml::toHtml() const
Expand Down
48 changes: 40 additions & 8 deletions src/jaspPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Json::Value jaspPlot::dataEntry(std::string & errorMessage) const
data["errorType"] = _editOptions.get("errorType", "fatalError");
data["editable"] = !_editOptions.isNull() && data["errorType"] == "success";

data["interactive"] = _interactive;
data["interactiveConvertError"] = _interactiveConvertError;
data["interactiveJsonData"] = _interactiveJsonData;


return data;
}

Expand Down Expand Up @@ -130,6 +135,25 @@ void jaspPlot::renderPlot()
}
}

if(writeResult.containsElementNamed("interactive"))
{
_interactive = Rcpp::as<bool>(writeResult["interactive"]);
if (_interactive)
{
if(writeResult.containsElementNamed("interactiveConvertError"))
_interactiveConvertError = Rcpp::as<std::string>(writeResult["interactiveConvertError"]);
else if (writeResult.containsElementNamed("interactiveJsonData"))
{
std::string interactiveJsonDataStr = Rcpp::as<Rcpp::String>(writeResult["interactiveJsonData"]);
_interactiveJsonData = Json::objectValue;
Json::Reader().parse(interactiveJsonDataStr, _interactiveJsonData);
}
else
_interactiveConvertError = "Unknown error converting interactive plot to JSON";
}
}


if(writeResult.containsElementNamed("error"))
{
_error = true;
Expand All @@ -152,11 +176,11 @@ Rcpp::RObject jaspPlot::getPlotObject() const
Rcpp::RObject plotInfo = jaspResults::getObjectFromEnv(_envName);
if (!plotInfo.isNULL() && Rcpp::is<Rcpp::List>(plotInfo))
{

Rcpp::List plotInfoList = Rcpp::as<Rcpp::List>(plotInfo);
if (plotInfoList.containsElementNamed("obj"))
return Rcpp::as<Rcpp::RObject>(plotInfoList["obj"]);

}
return R_NilValue;
}
Expand All @@ -166,15 +190,15 @@ void jaspPlot::setUserPlotChangesFromRStateObject()
Rcpp::RObject plotInfo = jaspResults::getObjectFromEnv(_envName);
if (plotInfo.isNULL() || !Rcpp::is<Rcpp::List>(plotInfo))
return;

Rcpp::List plotInfoList = Rcpp::as<Rcpp::List>(plotInfo);

if (plotInfoList.containsElementNamed("width"))
_width = Rcpp::as<int>(plotInfoList["width"]);

if (plotInfoList.containsElementNamed("height"))
_height = Rcpp::as<int>(plotInfoList["height"]);

if (plotInfoList.containsElementNamed("revision"))
_revision = Rcpp::as<int>(plotInfoList["revision"]);
}
Expand Down Expand Up @@ -224,6 +248,10 @@ Json::Value jaspPlot::convertToJSON() const
obj["editOptions"] = _editOptions;
obj["resizedByUser"] = _resizedByUser;

obj["interactive"] = _interactive;
obj["interactiveConvertError"] = _interactiveConvertError;
obj["interactiveJsonData"] = _interactiveJsonData;

return obj;
}

Expand All @@ -240,9 +268,13 @@ void jaspPlot::convertFromJSON_SetFields(Json::Value in)
_envName = in.get("environmentName", _envName).asString();
_editOptions = in.get("editOptions", Json::nullValue);
_resizedByUser = in.get("resizedByUser", false).asBool();


_interactive = in.get("interactive", false).asBool();
_interactiveConvertError = in.get("interactiveConvertError", "").asString();
_interactiveJsonData = in.get("interactiveJsonData", Json::nullValue);

setUserPlotChangesFromRStateObject();

/*JASP_OBJECT_TIMERBEGIN
std::string jsonPlotObjStr = in.get("plotObjSerialized", "").asString();
_plotObjSerialized = Rcpp::Vector<RAWSXP>(jsonPlotObjStr.begin(), jsonPlotObjStr.end());
Expand Down
9 changes: 6 additions & 3 deletions src/jaspPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ class jaspPlot : public jaspObject
_height,
_revision = 0;
bool _editing = false,
_resizedByUser = false;
_resizedByUser = false,
_interactive = false;
std::string _filePathPng,
_status = "waiting",
_envName;
Json::Value _editOptions = Json::nullValue;
_envName,
_interactiveConvertError = "";
Json::Value _editOptions = Json::nullValue,
_interactiveJsonData = Json::nullValue;

///For safekeeping (aka state replacement?)
void setPlotObject(Rcpp::RObject plotSerialized);
Expand Down
Loading