-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
145 lines (131 loc) · 5.02 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!-- http://bl.ocks.org/jdittmar/7800481 -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta charset="utf-8">
<head>
<title>Word Burst</title>
<style type="text/css">
input,
p {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
}
text {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 24px;
}
</style>
<script src="https://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<h3>Word Burst</h3>
<p>Enter a word to see its prefix/root/suffix breakdown based on the database. Click the word once it appears to
break it down.</p>
<div style='text-align: center; padding-top: 100px'>
<form name="myform" onSubmit="return eventhandler()">
<input type="text" id="myWord" placeholder="Input a Russian word…">
<input name="Submit" type="submit" value="Enter">
</form>
</div>
<div id='svg' style='text-align: center'></div>
</body>
<script type="text/javascript">
document.getElementById('myWord').value = "название"
function eventhandler() {
var myWord = document.getElementById("myWord").value;
d3.select("#svg").selectAll("*").remove();
animateWord(myWord);
return false;
}
function animateWord(myWord) {
d3.json('lemma_data_1-10.json', function (error, data) {
// initialize the svg canvas
var screenwidth = screen.width;
var svg = d3.select("#svg").append("svg")
.attr("width", screenwidth)
.attr("height", 500)
.append("g")
.attr("transform", "translate(" + (screenwidth / 2) + ",50)")
var lemmaDict = getWordParts(myWord);
if (lemmaDict == 'NotFound') {
var text = svg
.append('text')
.text('Not found in database.')
.style("text-anchor", "middle");
return false;
}
var text = svg
.append('text')
.text(myWord)
.style("text-anchor", "middle");
var prefix = svg.append('text')
.style("text-anchor", "middle")
.text(lemmaDict['prefixes'])
.attr('fill', 'tomato')
.attr('display', 'none');
var root = svg.append('text')
.style("text-anchor", "middle")
.text(lemmaDict['roots'])
.attr('fill', 'blue')
.attr('display', 'none');
var suffix = svg.append('text')
.style("text-anchor", "middle")
.text(lemmaDict['suffixes'])
.attr('fill', '#ffdb58')
.attr('display', 'none');
text
.on('mouseover', function () {
text.transition().duration(100).attr('fill', 'gray');
})
.on('mouseout', function () {
text.transition().duration(100).attr('fill', 'black');
})
.on("click", function () {
});
if (prefix.style('display') == 'none') {
text.transition().duration(100).attr('fill', 'gray');
prefix.transition()
.duration(500)
.attr('transform', 'translate(-400,200)')
.attr('display', 'block');
root.transition()
.duration(500)
.attr('transform', 'translate(0,200)')
.attr('display', 'block');
suffix.transition()
.duration(500)
.attr('transform', 'translate(400,200)')
.attr('display', 'block');
} else {
text.transition().duration(100).attr('fill', 'black');
prefix.transition()
.duration(500)
.attr('transform', 'translate(0,25)')
.transition()
.duration(1000)
.attr('display', 'none');
root.transition()
.duration(500)
.attr('transform', 'translate(0,25)')
.transition()
.duration(1000)
.attr('display', 'none');
suffix.transition()
.duration(500)
.attr('transform', 'translate(0,25)')
.transition()
.duration(1000)
.attr('display', 'none');
}
function getWordParts(myWord) {
for (lemmaDict of data) {
if (myWord == lemmaDict['lemma']) {
console.log('lemmadict', lemmaDict);
return lemmaDict;
}
};
return 'NotFound';
}
});
}
</script>
</html>