forked from RandomMinds/vtree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
89 lines (63 loc) · 2.31 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!doctype html>
<html>
<head>
<title style="margin-top: 1em">JSON to Tree</title>
<link rel="shortcut icon" type="image/svg" href="img/icon/icon.svg">
<link rel=" stylesheet" href="css/vtree.css" type="text/css" />
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="dist/vtree.js"></script>
<!-- How to use debug mode.
1. open browser's developer tools.
2. input the following command.
vt.debug(true).update()
-->
<script type="text/javascript">
var vt;
window.onload = function () {
var container = document.getElementById("container");
var msg = document.getElementById("msg");
vt = new VTree(container);
var reader = new VTree.reader.Object();
function updateTree() {
var s = document.getElementById("from-text").value;
msg.innerHTML = '';
try {
var jsonData = JSON.parse(s);
} catch (e) {
msg.innerHTML = 'JSON parse error: ' + e.message;
}
var data = reader.read(jsonData);
vt.data(data)
.update();
}
function createSvgString() {
document.getElementById("svg-text").value = vt.createSvgString();
}
document.getElementById("go-button").onclick = updateTree;
document.getElementById("svg-button").onclick = createSvgString;
updateTree();
};
</script>
</head>
<body>
<div class="container">
<h1>JSON to AST</h1>
<div style="margin-top: 1em;">
<label for="from-text">JSON</label><br>
<textarea id="from-text" rows="6"
style="width:100%">[{ "array": [ 1, 2, [3, 4], 5 ], "boolean": true, "null": null, "number": 123, "object": { "a": "b", "c": "d", "e": "f" }, "string": "Hello World" }, { "|": "|", " ": { "asdf": "" }, " ": ["asdf", [ { "hello! ": "asdf" } ], "asdf"], "_": { "": "asdf" } }]</textarea>
</div>
<div style="margin-top: 1em;">
<input id="go-button" type="button" value="Visualize">
</div>
<div id="msg" style="color: red;"></div>
<div id="container" style="margin-top: 1em;"></div>
<div style="margin-top: 1em;">
<input id="svg-button" type="button" value="Get SVG String">
</div>
<div style="margin-top: 1em;">
<textarea id="svg-text" rows="6" style="width:100%"></textarea>
</div>
</div>
</body>
</html>