-
Notifications
You must be signed in to change notification settings - Fork 0
/
embvis.html
313 lines (287 loc) · 7.64 KB
/
embvis.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<!-- EmbVis - Toll for visualizing and browsing data object embeddings -->
<!-- Author: Kriste Krstovski, 2016-->
<!DOCTYPE html>
<html>
<head>
<title>EmbVis</title>
<style type="text/css">
div#map { margin: 0 auto 0 auto; }
</style>
<style>
html, body
{
height: 100%;
margin: 0;
padding: 0;
}
#map
{
height: 100%;
}
.tooltip
{
position: absolute;
line-height: .7;
font-weight: bold;
padding: 8px;
background: rgba(255, 255, 255, 0.99);
color: #fff;
font-weight: bold;
font: 11.5px sans-serif;
border-radius: 2px;
pointer-events: none;
border-radius: 6px
stroke: blue;
stroke-width: 3px;
}
.datapoints,
.datapoints svg
{
position: absolute;
}
.datapoints svg
{
width: 300px;
height: 35px;
padding-right: 100px;
font: 14px arial;
}
.datapoints circle
{
stroke-width: 0.5px;
}
.box
{
margin: 20px auto;
width: 300px;
height: 30px;
position: absolute;
top: -20px;
left: 10px;
}
.cont_box
{
width: 300px;
vertical-align: middle;
white-space: nowrap;
}
.cont_box input#search
{
width: 340px;
height: 40px;
background: #fcfcfc;
border: 30px;
font-size: 12pt;
float: left;
color: #000000;
padding-left: 45px;
padding-right: 15px;
-webkit-border-radius: 5px;
-moz-border-radius: 50px;
border-radius: 30px;
}
/*TODO Check icon*/
.cont_box .icon
{
position: absolute;
top: 50%;
margin-left: 17px;
margin-top: 17px;
z-index: 1;
color: #000000;
}
.cont_box input#search:hover, .cont_box input#search:focus, .cont_box input#search:active
{
outline:none;
background: #ffffff;
}
</style>
</head>
<body>
<div id="map"></div>
<div class="box">
<div class="cont_box">
<h1 style="font-family:arial;font-size:300%;padding: -5px -10px -20px 30px; ">EmbVis</h1>
<input type="search" id="search" name="searchtxt" placeholder="Search for an object embedding..." onkeydown="if (event.keyCode == 13) title_search();"/>
</div>
</div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD8H5UIHX4E0hgK6-T1dvtEdq9CAGM10vg"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<!-- Specify the data source file -->
<!-- Data source file has the following format: -->
<!-- var objectpoints = [ {"title" : "data_object_title_to_be_displayed","image" : "image_file", "coord" : [longitude_value,latitude_value], "fill" : "circle_fill_color", "stroke" : "stroke_fill_color", "category" : "category_type**"}, ... ] -->
<!-- Here is an example line: -->
<!-- {"title": "cosine", "coord": [-11.7836261004,-26.4969584853], "fill": "0.8", "stroke": "blue", "category": "1"}, -->
<script src="words_example.js"></script>
<form method="get" action="/search" id="search">
<input name="q" type="text" size="40" placeholder="Search..." />
</form>
<script>
function findtitle(title)
{
return objectpoints.filter
(
function(objectpoints)
{
return objectpoints.title == title
}
);
}
function title_search()
{
search_title = document.getElementsByName("searchtxt")[0];
var found = findtitle(search_title.value)
if (found!=null){
d = new google.maps.LatLng(found[0].coord[1], found[0].coord[0]);
map.setCenter(d);
if (objectpoint) {objectpoint.setMap(null);}
objectpoint=new google.maps.Marker({position:d, map:map, draggable: true});
map.panTo(d);
}
else {
//Display a message when an object is not found
}
}
function CoordMapType(tileSize)
{
this.tileSize = tileSize;
}
CoordMapType.prototype.maxZoom = 30;
CoordMapType.prototype.name = 'EmbVis';
CoordMapType.prototype.alt = 'Object Embeddings Visualizer and Browser';
CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument)
{
var div = ownerDocument.createElement('div');
div.innerHTML = coord;
div.style.width = this.tileSize.width + 'px';
div.style.height = this.tileSize.height + 'px';
div.style.fontSize = '10';
div.style.borderStyle = 'hidden';
div.style.borderWidth = '1px';
div.style.borderColor = '#FFFFFF';
div.style.backgroundColor = '#FFFFFF';
return div;
};
var myLatlng = new google.maps.LatLng(0, 0);
var objectpoint;
var map = new google.maps.Map
(
document.getElementById('map'),
{
draggableCursor: 'crosshair',
zoom: 6,
center: myLatlng,
streetViewControl: false,
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_CENTER
},
scaleControl: true,
mapTypeId: 'coordinate',
mapTypeControlOptions: {
mapTypeIds: ['moon']
}
}
);
map.addListener
(
'maptypeid_changed', function()
{
var showStreetViewControl = map.getMapTypeId() !== 'coordinate';
map.setOptions
(
{
streetViewControl: showStreetViewControl
}
);
}
);
var overlay = new google.maps.OverlayView();
overlay.onAdd = function() {
var layer = d3.select(this.getPanes().overlayMouseTarget).append("div")
.attr("class", "datapoints");
overlay.draw = function()
{
var projection = this.getProjection(), padding = 10;
var color = d3.scale.linear().domain([0, 1]).range(["beige", "red"]);
var tooltip = d3.select("body")
.append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var objectpoint = layer.selectAll("svg")
.data(d3.entries(objectpoints))
.each(transform)
.enter().append("svg:svg")
.each(transform)
.attr("class", "objectpoint");
objectpoint.append("svg:circle")
.attr("r", function(d)
{
if (d.value.title!=null) return 4.5;
else return 6.5;;
})
.attr("cx", padding)
.attr("cy", padding)
.attr("stroke", function(d)
{
return d.value.stroke;
})
//.attr("stroke-width","5")
.on("mouseover", function(d)
{
if (d.value.image!=null)
{
tooltip.transition()
.duration(200)
.style("opacity", .9)
tooltip.html("<span style='color:red'><img src='"+ d.value.image+"'></span>")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px")
}
})
.on("mouseout", function(d)
{
if (d.value.image!=null)
{
tooltip.transition()
.duration(200)
.style("opacity", 0);
}
})
.style("fill", function(d)
{
var colorValue = d.value.fill
if (colorValue)
{
return color(colorValue);
}
else
{
return "#ccc";
}
});
objectpoint.append("text")
.attr("x", padding+7)
.attr("y", padding)
.attr("dy", ".31em")
.text(function(d)
{
if (d.value.title!=null)
return d.value.title;
else
return "";
});
function transform(d)
{
d = new google.maps.LatLng(d.value.coord[1], d.value.coord[0]);
d = projection.fromLatLngToDivPixel(d);
return d3.select(this)
.style("left", (d.x - padding) + "px")
.style("top", (d.y - padding) + "px");
}
};
};
overlay.setMap(map);
</script>
</body>
</html>