-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.html
55 lines (46 loc) · 1.52 KB
/
renderer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="assets/echarts.min.js"></script>
<script>
function sleep(time){
return new Promise((resolve) => setTimeout(resolve, time));
}
async function render(code, config, width, height) {
var canvas = document.getElementsByClassName("chart")[0];
var json = JSON.parse(code);
json.animation = false;
if("width" in json) {
width = json.width;
}
if("height" in json) {
height = json.height;
}
if (width) {
canvas.style.width = width;
json.width = width;
}
if (height) {
canvas.style.height = height;
json.height = height;
}
var instance = echarts.init(canvas, null, { renderer: 'svg' });
instance.setOption(json);
var count = 0;
while (canvas.childNodes.length == 0 || canvas.childNodes[0].childNodes.length == 0) {
count++;
if (count >= 2400) {
console.error("Failed to render chart");
return '<svg version="1.1" width="600" height="200" xmlns="http://www.w3.org/2000/svg"><text x="10" y="100" font-size="60" text-anchor="left">Rendering timed out, please check your input.</text></svg>';
}
await sleep(100);
}
return new XMLSerializer().serializeToString(canvas);
}
</script>
</head>
<body>
<div class="chart" style="width:600px;height:400px;"></div>
</body>
</html>