refactor: adjust charts preview

This commit is contained in:
vicanso 2021-12-26 09:02:24 +08:00
parent ebc566fc9d
commit fea5649efb
3 changed files with 39 additions and 4 deletions

View file

@ -8,7 +8,22 @@ editor.setSize("100%", height);
function run() {
var option = editor.getValue();
axios.post("/", JSON.parse(option)).then(function(resp) {
var data = null;
try {
if (option.indexOf("option = ") !== -1) {
var fn = new Function("var " + option + ";return option;");
data = fn();
} else {
data = JSON.parse(option);
}
} catch (err) {
alert(err.message);
return;
}
axios.post("/", data).then(function(resp) {
document.getElementById("svg").innerHTML = resp;
}).catch(function(err) {
alert(err.message);
});
}