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
7 changes: 4 additions & 3 deletions resources/public/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var render = function (data, element, errorCallback) {
var callbackQueue = [];
var htmlString = renderPart(data, callbackQueue, errorCallback);
var el = $("<pre>" + htmlString + "</pre>");
$(element).append(el);
$(element).html(el);
_.each(callbackQueue, function (callback) {callback()});

// Attach a click event handler to each element for value copy and paste.
Expand Down Expand Up @@ -74,7 +74,8 @@ var renderVega = function (data, callbackQueue, errorCallback) {
vg.parse.spec(data.content, function (chart) {
try {
var element = $("#" + uuid).get()[0];
chart({el: element, renderer: 'svg'}).update();
if(element) // may have been removed
chart({el: element, renderer: 'svg'}).update();
} catch (e) {
// we'll end up here if vega throws an error. We try and route this error back to the
// segment so the user has an idea of what's going on.
Expand All @@ -96,4 +97,4 @@ var renderLatex = function (data, callbackQueue, errorCallback) {
});

return wrapWithValue(data, "<span class='latex-span' id='" + uuid + "'>@@" + data.content + "@@</span>");
};
};
25 changes: 25 additions & 0 deletions resources/public/js/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,27 @@ var worksheet = function () {

// messages from the evaluator

// When more than a single value is returned from evaluating
// a segment, values are combined into a list-like structure.

var appendValue = function(oldValue, parsedValue) {
// Parsed values are strings extracted from JSON response.
// The strings are JSON representations of data objects;
// we parse them to insert into the compound object and then
// stringify the final structure.
oldValue = JSON.parse(oldValue);
parsedValue = JSON.parse(parsedValue);

return JSON.stringify({
type: "list-like",
open: "",
close: "",
separator: "</pre><pre>", // preserves the current behavior
items: [oldValue, parsedValue],
value: "["+oldValue.value+","+parsedValue.value+"]"
});
}

addEventHandler("evaluator:value-response", function (e, d) {
var segID = d.segmentID;
var seg = self.getSegmentForID(segID);
Expand All @@ -244,6 +265,10 @@ var worksheet = function () {
// string that will JSON.parse to the object. This round of unescaping is done here in order that the
// value associated with the segment (and hence saved in the worksheet) is not double escaped.
var parsedValue = JSON.parse(d.value);
var oldValue = seg.output();
if(oldValue) { // multiple values from segment
parsedValue = appendValue(oldValue, parsedValue);
}
seg.output(parsedValue);
} catch (e) {
// if anything goes wrong, fall back to displaying the raw response.
Expand Down