Skip to content

Commit

Permalink
Fixed issue with formated string return value
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x committed May 11, 2024
1 parent 4508d2f commit 3416d5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 13 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,37 @@ mathWorker.onmessage = function (oEvent) {
out.text.forEach(e => {
const pre = document.createElement("pre");
if (e.visible) {
const div = document.createElement("div");
const type = e.type;
const value = e.result;
let div
switch (type) {
case "string":
div = document.createElement("code");
div.innerHTML = value;
pre.appendChild(div);
break;
case "any":
div = document.createElement("div");
div.textContent = value;
pre.appendChild(div);
break;
case "error":
div = document.createElement("div");
div.style.color = "red";
div.innerHTML = value;
pre.appendChild(div);
break;
case "plot":
div = document.createElement("div");
try {
Plotly.newPlot(div, e.result.data, e.result.layout, e.result.config)
} catch (error) {
div.innerHTML = 'myError:'+ error.toString();
}
pre.appendChild(div);
break;
}
pre.appendChild(div);

outputs.appendChild(pre);
}
});
Expand Down
7 changes: 5 additions & 2 deletions public/mathWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ function processExpressions(expressions) {
const { data, layout, config } = result.value

outputs = { type: "plot", result: { data: formatObject(data), layout: formatObject(layout), config: formatObject(config) } }
} else {
} else if (result.value && typeof result.value == "string") {
outputs = { type: "string", result: result.value }
}
else {
outputs = { type: "any", result: formatResult(result.value) }
}

Expand All @@ -258,7 +261,7 @@ function formatObject(obj) {
const formatedObject = math.format(obj)
math.config({ matrix: 'Array' })
const objResult = math.evaluate(formatedObject)
math.config({matrix: matrix})
math.config({ matrix: matrix })
return objResult
}

Expand Down

0 comments on commit 3416d5e

Please sign in to comment.