-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
368 lines (328 loc) · 10.5 KB
/
Copy pathindex.html
File metadata and controls
368 lines (328 loc) · 10.5 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<!DOCTYPE html>
<html lang="en">
<head>
<title>Visualizing Multidimensional Data</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap.min.css">
<!--<script src="lib/jquery/jquery.min.js" charset="utf-8"></script>
<script src="lib/bootstrap/js/bootstrap.min.js" charset="utf-8"></script>-->
<script src="lib/d3/d3.min.js" charset="utf-8"></script>
<script src="js/dimension.js" charset="utf-8"></script>
<script src="js/scatterplot.js" charset="utf-8"></script>
<script src="js/featurelist.js" charset="utf-8"></script>
<script src="js/scattermatrix.js" charset="utf-8"></script>
<!-- // <script src="js/histogram.js" charset="utf-8"></script> -->
<script src="js/state.js" charset="utf-8"></script>
<script src="js/util.js" charset="utf-8"></script>
<!-- // <script src="js/dropdown.js" charset="utf-8"></script> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style>
.featureUl {
padding: 0;
margin: 0;
}
.featureLi {
list-style-type: none;
cursor: pointer;
padding: 5px;
}
.featureLi:hover {
background: #e7e7e7;
}
.featureLiSel, .featureLiSel:hover {
background: rgb(55,126,184);
font-weight: bold;
color: white;
}
.axis path {
display: none;
}
.axis line {
shape-rendering: crispEdges;
stroke: lightgray;
}
.axis .minor line {
stroke: lightgray;
stroke-dasharray: 2,2;
}
.axis text {
fill: none;
stroke: black;
shape-rendering: crispEdges;
font-family: sans-serif;
font-size: 11px;
}
/*.bar rect {
fill: steelblue;
shape-rendering: crispEdges;
}
.bar text {
fill: #fff;
}*/
.highlight {
fill: yellow;
stroke: black;
}
#tooltip {
position: absolute;
background-color: gray;
}
#tooltip.hidden {
display: none;
}
#tooltip p {
margin: 0;
font-family: sans-serif;
font-size: 16px;
line-height: 20px;
}
</style>
</head>
<body>
<div id="head"></div>
<div>Choose a dataset<br/>
<select id="select-list">
<option value="0">Ozone tSNE</option>
<option value="1">Ozone MDS</option>
<option value="2">Basketball Tournament tSNE</option>
<option value="3">Basketball Tournament MDS</option>
<option value="4">Voice Rehabilitation tSNE</option>
<option value="5">Voice Rehabilitation MDS</option>
<option value="6">World Music tSNE</option>
<option value="7">World Music MDS</option>
<option value="8">PLUTO tSNE</option>
<option value="9">PLUTO MDS</option>
</select>
</div>
<div id="listA"></div>
<div id="main"></div>
<div id="scatter"></div>
<div id="listB"></div>
<!-- <div id="histogram"></div> -->
<script>
function tooltip(d) {
// Select the element
var e = d3.select(this)
//Get the x and y position
var xPos = e.attr("cx")
var yPos = e.attr("cy")
d3.select("#tooltip")
//Set the position
.style("left", xPos + "px")
//Prevent overlap
.style("top", (yPos -25) + "px" )
//Now set the content
.select("#value")
.html(d.Category);
d3.select("#tooltip").classed("hidden", false);
};
var fileIndex = 0
function start(fileIndex) {
// var fileIndex = 1
var size = 500;
var width = 200;
var height = 100;
var radius = 5;
var columns = "Xcoord,Ycoord".split(",");
var fileListTSNE = ["data/ozone_TSNE.csv",
"data/Ozone MDS.csv",
"data/Basketball Tournament_TSNE.csv",
"data/Basketball Tournament MDS.csv",
"data/LSVT_voice_rehabilitation_TSNE.csv",
"data/LSVT_voice_rehabilitation MDS.csv",
"data/World Music_TSNE.csv",
"data/World Music MDS.csv",
"data/PLUTO tSNE.csv",
"data/PLUTO MDS.csv"]
var fileListSPM = ["data/ozoneHR2.csv",
"data/ozoneHR2.csv",
"data/Basketball Tournament.csv",
"data/Basketball Tournament.csv",
"data/LSVT_voice_rehabilitation.csv",
"data/LSVT_voice_rehabilitation.csv",
"data/World Music.csv",
"data/World Music.csv",
"data/SIcleanNumericalReduced.csv",
"data/SIcleanNumericalReduced.csv"]
var fileTSNE = fileListTSNE[fileIndex];
var fileSPM = fileListSPM[fileIndex];
var fA = "Xcoord";
var fB = "Ycoord";
var allIxs = [];
var state = new State();
var scatterplot = null;
var scattermatrix = null;
var featurelistA = null;
var featurelistB = null;
var histogram = null;
d3.select("body").style({
"padding": "5px"
});
var main = d3.select("#main");
var scatter = d3.select('#scatter');
var listA = d3.select("#listA");
var listB = d3.select("#listB");
var hl = d3.select("#histogram");
var head = d3.select("#head").style({
"display": "block",
"width": (width + size + 10) + "px"
});
var buttons = head.style({
"margin-bottom": "5px"
}).append("div").classed({
"btn-group": true
});
buttons.append("button").classed({
"btn": true,
"btn-default": true
}).text("remove selection").on("click", function() {
var newIxs = removeIxs(state.ixs(), state.selIxs());
state.ixs(newIxs);
state.selIxs([]);
state.update(false, false, true, true);
});
buttons.append("button").classed({
"btn": true,
"btn-default": true
}).text("show all").on("click", function() {
state.ixs(allIxs);
state.update(false, false, true, false);
});
buttons.append("button").classed({
"btn": true,
"btn-default": true
}).text("examine selection").on("click", function() {
$("#scatter").empty();
scattermatrix = new Scattermatrix(scatter, fileSPM, state.selIxs());
});
d3.csv(fileTSNE, function(error, data) {
if(error) {
console.warn(error);
return;
}
// svg.selectAll("circle")
// //Loop through the data
// .data(data).enter()
// //Add a rectangle for each data element
// .append("circle")
// .attr("r", "5")
// //function(d) accesses the data. The return value of the function
// //is the value the attribute gets!
// .attr("cx", function(d) { return x(d.Xcoord); })
// .attr("cy", function(d) { return y(d.Ycoord); })
// .on("mouseover", tooltip)
// .on("mouseout", function(d) {
// //Hide the tooltip
// d3.select("#tooltip").classed("hidden", true);
// })
var featureMap = {};
state.clearListeners();
loadedDimensions = Dimension.loadAll(data, columns, featureMap);
allIxs = loadedDimensions[0];
var labels = loadedDimensions[1];
state.ixs(allIxs);
state.labels(labels);
state.selIxs([]);
state.featureA(featureMap[fA]);
state.featureB(featureMap[fB]);
var features = Object.keys(featureMap).map(function(n) {
return featureMap[n];
});
if(!features.length) {
console.warn("no features loaded!");
return;
}
main.selectAll("*").remove();
scatter.selectAll("*").remove();
listA.selectAll("*").remove();
listB.selectAll("*").remove();
hl.selectAll("*").remove();
scatterplot = new Scatterplot(main, size, radius, 750, "easeInOutCubic", function() { // initSelection
state.tmpIxs([]);
state.update(false, false, false, true);
return state;
}, function(ixs, done) { // selectPoints
if(done) {
state.selIxs(ixs);
state.tmpIxs([]);
} else {
state.tmpIxs(ixs);
}
state.update(false, false, false, true);
});
var lastIxs = [];
var lastSel = [];
var lastTmp = [];
state.addListener(function(s, cA, cB, cIxs, cSel) {
if(cA || cB || cIxs) {
scatterplot.update(s.featureA(), s.featureB(), s.ixs());
var curIxs = s.ixs();
scatterplot.colorIxs(removeIxs(curIxs, lastIxs), s.color());
lastIxs = curIxs;
}
if(cIxs || cSel) {
var selIxs = s.selIxs();
var tmpIxs = s.tmpIxs();
var restIxs = unionIxs(selIxs, tmpIxs);
var lastRest = unionIxs(lastSel, lastTmp);
scatterplot.colorIxs(removeIxs(lastRest, restIxs), s.color());
scatterplot.colorIxs(removeIxs(selIxs, lastSel), s.selColor());
scatterplot.colorIxs(removeIxs(tmpIxs, lastTmp), s.tmpColor());
lastSel = selIxs;
lastTmp = tmpIxs;
}
});
featurelistA = new Featurelist(listA, width, size, function(ix) { // selectFeature
state.selIxs([ ix ]);
state.update(false, false, false, true);
}, function(ix){ //pushFeature
state.selIxs().push(ix);
state.update(false, false, false, true);
scatterplot.colorIxs(state.selIxs(), "crimson");
});
featurelistA.setFeatures(state.ixs());
state.addListener(function(s, cA, cB, cIxs, cSel) {
if(cSel) {
featurelistA.update(s.selIxs(), s.labels());
}
// mynewcompnoent.update(param1, param2....)
});
// featurelistB = new Featurelist(listB, width, size, function(f) { // selectFeature
// state.featureB(f);
// state.update(false, true, false, false);
// });
// featurelistB.setFeatures(features);
// state.addListener(function(s, cA, cB, cIxs, cSel) {
// if(cB) {
// featurelistB.update(s.featureB());
// }
// });
var pads = scatterplot.padding();
hl.append("span").style({
"width": (width + 5 + pads[3] /* left padding */) + "px",
"height": "20px",
"display": "inline-block",
"background-color": "red"
});
var hw = size - pads[3] /* left padding */ - pads[1] /* right padding */;
// histogram = new Histogram(hl, hw, height, 750, "easeInOutCubic", function(ixs) { // onSelect
// state.selIxs(ixs);
// state.update(false, false, false, true);
// });
// state.addListener(function(s, cA, cB, cIxs, cSel) {
// if(cA || cIxs || cSel) {
// histogram.update(s, cA || cIxs);
// }
// });
});
d3.select("#select-list").on("change", function(){
var dataIndex = eval(d3.select(this).property('value'));
$(".btn-group").remove();
start(parseInt(dataIndex));
});
}
// $("#head").remove();
start(fileIndex)
</script>
</body>
</html>