-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwordtree_template.html
59 lines (55 loc) · 1.74 KB
/
wordtree_template.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
<html>
<head>
<script type="text/javascript">
var chart;
var data;
var options = {
wordtree: {
format: 'implicit',
word: '${root_word}',
type: '${tree_type}',
}
};
function initChart() {
data = google.visualization.arrayToDataTable(${json_formatted});
chart = new google.visualization.WordTree(document.getElementById('wordtree_basic'));
}
function drawChart() {
chart.draw(data, options);
}
function setRootWordFromForm() {
options.wordtree.word = document.getElementById('root_word').value;
drawChart();
}
// Is it the first time we're being loaded? We have to check as IPython seems to do
// some tricky things where it holds around loaded JS which causes an error if we
// attempt to load Google's libraries twice.
if (typeof(google) == 'undefined') {
var script = document.createElement('script');
script.src = 'https://www.gstatic.com/charts/loader.js';
var head = document.getElementsByTagName('head')[0];
script.onload = function() {
google.charts.load('current', {
packages: ['wordtree']
});
google.charts.setOnLoadCallback(function() {
initChart();
drawChart();
});
head.removeChild(script);
};
head.appendChild(script);
} else {
initChart();
drawChart();
}
</script>
</head>
<body>
Root Word:
<input type="text" id="root_word" value="${root_word}">
<button type="button" onclick="setRootWordFromForm()">Update Tree</button>
<br>
<div id="wordtree_basic" style="width: 900px; height: 600px;"></div>
</body>
</html>