-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvis.html
181 lines (162 loc) · 4.25 KB
/
vis.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<html>
<head>
<script type="text/javascript"
src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
var DATA;
function loadData(data) {
DATA = data;
var states = data.states;
for (var i = 0; i < states.length; i++) {
var div = $("<div></div>")
.append("<p class='score'>??</p>")
.append(states[i])
.attr("class", "state")
.attr("id", "state" + i);
$("#states").append(div);
}
var distractors = data.distractors;
for (var i = 0; i < distractors.length; i++) {
var div = $("<div></div>")
.attr("class", "distractor")
.attr("id", "distractor" + i);
for (var j = 0; j < distractors[i].length; j++) {
$(div).append("<p class='score'>??</p>");
$(div).append(distractors[i][j]);
}
$("#distractors").append(div);
}
var descs = data.descs;
for (var i = 0; i < descs.length; i++) {
var div = $("<div></div>")
.append(descs[i].value)
.attr("class", "desc")
.attr("id", "desc" + i);
$(div).click(function(i_) {
return function() { showDesc(i_); };
}(i));
$("#descs").append(div);
}
var codes = data.codes;
for (var i = 0; i < codes.length; i++) {
var code = codes[i].value;
var codeblock = $("<span></span>");
//for (var j = 0; j < code.length; j += 3) {
for (var j = 0; j < code.length; j++) {
var codecell = $("<span class='codecell'></span>");
r = g = b = Math.trunc(255 / (1 + Math.exp(-code[j])));
// r = Math.trunc(255 / (1 + Math.exp(-code[j])));
// g = Math.trunc(255 / (1 + Math.exp(-code[j+1])));
// b = Math.trunc(255 / (1 + Math.exp(-code[j+2])));
var color = "rgb(" + r + "," + g + "," + b + ")";
//codecell.text(color);
codecell.css("background-color", color);
codeblock.append(codecell);
}
var div = $("<div></div>")
.append(codeblock)
.append("<p>" + codes[i].trans + "</p>")
//.append(codes[i].value)
//.append(codes[i].fkl).append(codes[i].rkl).append(codes[i].tvd)
.attr("class", "code")
.attr("id", "code" + i);
$(div).click(function(i_) {
return function() { showCode(i_); }
}(i));
$("#codes").append(div);
}
}
function showHelper(name, score) {
var elem = $(name);
elem.css("opacity", score);
elem.find(".score").text(score);
}
function showDesc(iDesc) {
$(".focused").removeClass("focused");
$("#desc" + iDesc).addClass("focused");
scores = DATA["descs"][iDesc]["repr"];
for (var i = 0; i < scores.length; i++) {
showHelper("#state" + i, scores[i][0]);
if (scores[i].length > 1) {
showHelper("#distractor" + i, scores[i][1]);
} else {
alert("weird");
}
}
}
function showCode(iCode) {
$(".focused").removeClass("focused");
$("#code" + iCode).addClass("focused");
scores = DATA["codes"][iCode]["repr"];
for (var i = 0; i < scores.length; i++) {
showHelper("#state" + i, scores[i][0]);
if (scores[i].length > 1) {
showHelper("#distractor" + i, scores[i][1]);
}
}
}
$(document).ready(function() {
$.getJSON("vis.json", loadData);
});
</script>
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
<style type="text/css">
body {
font-family: "Roboto Mono", monospace;
}
.column {
padding: .5em;
float: left;
height: 100%;
overflow: auto;
}
#states img, #distractors img {
width: 180px;
height: 180px;
object-position: center;
object-fit: cover;
}
.score {
text-align: center;
width: 3em;
margin: 0 0 -2em 0;
position: relative;
background: rgba(255, 255, 255, 0.67);
padding: 0.5em;
display: None;
}
#descs div, #codes div {
padding: 0.5em;
}
#descs div:hover, #codes div:hover {
outline: 1px solid #bbb;
}
#descs div.focused {
background: #ff8;
}
#codes div.focused {
background: #acf;
}
td.sep {
padding-right: 1em;
}
.codecell {
display: inline-block;
width: 1em;
height: 1em;
}
</style>
</head>
<body>
<div id="content">
<div class="column">
<table>
<td class="sep"><div id="states"></div></td>
<td><div id="distractors"></div></td>
</table>
</div>
<div class="column" id="descs"></div>
<div class="column" id="codes"></div>
</div>
</body>
</html>