-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
703 lines (628 loc) · 34.7 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
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
<!DOCTYPE html>
<html>
<head>
<title>Splatterplots JS - UW Graphics Group</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<!-- boostrap -->
<link href="libs/bootstrap.min.css" rel="stylesheet" />
<!-- style the file input button and adjust the Bootstrap progress bars (jQuery File Uploader) -->
<link rel="stylesheet" href="libs/jquery.fileupload.css">
<!-- local stylesheet -->
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- navbar -->
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img src="img/logo.png" class="img-responsive pull-left">
Splatterplots JS
</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="#" data-toggle="modal" data-target="#faq">How to use</a>
<li><a href="https://github.com/uwgraphics/splatterjs" target="_blank">View on GitHub</a></li>
</ul>
<p class="navbar-text navbar-right"><small>
<span class="text-danger">
Only works in non-mobile Google Chrome;
</span>
currently viewing file <a href="#" class="navbar-link" id="filename-label">venn2.txt</a>.
</small></p>
</div>
</div>
</nav>
<div class="container-fluid">
<!-- GL.create() will insert a canvas here -->
<div class="row">
<div class="col-sm-12" id="splattercell">
<div id="splatters">
</div>
<div id="detail" class="panel panel-default splatter-panel">
<div class="panel-heading">
<h3 class="panel-title">Point Detail</h3>
</div>
<div class="panel-body" id="detail-text">[no point selected]</div>
</div>
<div id="legend" class="panel panel-default splatter-panel">
<div class="panel-heading">
<h3 class="panel-title">Legend</h3>
</div>
<div class="panel-body">
<ul id="legend-items" class="list-inline">
<li>
Loading dataset...
</li>
</ul>
</div>
</div>
</div>
</div>
<br class="clearcanvas" style="clear: both;" />
<form class="form-horizontal" role="form">
<div class="form-group slider-group">
<label for="bandwidth" class="col-sm-offset-1 col-sm-3 control-label">Bandwidth</label>
<div class="col-sm-4">
<div id="bandwidth"></div>
</div>
<div id="disp-bandwidth" class="col-sm-1 slider-value">15</div>
</div>
<div class="form-group slider-group">
<label for="threshold" class="col-sm-offset-1 col-sm-3 control-label">Threshold</label>
<div class="col-sm-4">
<div id="threshold"></div>
</div>
<div id="disp-threshold" class="col-sm-1 slider-value">0.5</div>
</div>
<div class="form-group slider-group">
<label for="clutter" class="col-sm-offset-1 col-sm-3 control-label">Clutter Radius</label>
<div class="col-sm-4">
<div id="clutter"></div>
</div>
<div id="disp-clutter" class="col-sm-1 slider-value">25</div>
</div>
<div class="form-group slider-group">
<label for="outlierSize" class="col-sm-offset-1 col-sm-3 control-label">Outlier Point Size</label>
<div class="col-sm-4">
<div id="outlierSize"></div>
</div>
<div id="disp-outlierSize" class="col-sm-1 slider-value">2</div>
</div>
<!-- spacer between sliders and buttons -->
<div class="form-group"> </div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-1">
<button class="btn btn-default" id="splatter">Splatterplot</button>
<button class="btn btn-default" id="kde">KDE</button>
<button class="btn btn-default" id="scatter">Scatter</button>
</div>
<div class="col-sm-3">
<div class="checkbox">
<label>
<input type="checkbox" id="globalmax" checked /> <abbr title="Use the maximum value from all datasets when determining thresholded region; otherwise, use per-group max.">Use global maximum?</abbr>
</label>
</div>
</div>
<div class="col-sm-2">
<div class="checkbox">
<label>
<input type="checkbox" id="hideoutliers" /> Hide outliers?
</label>
</div>
</div>
<div class="col-sm-2">
<button class="btn btn-default" id="resetview">Reset View</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-1">
<button class="btn btn-warning" data-toggle="collapse" data-target="#debug">
Show Debug
</button>
<button class="btn btn-warning" id="changefi">
Lo-fi version (640x480)
</button>
</div>
<div class="col-sm-3">
<div class="checkbox">
<label>
<input type="checkbox" id="showbackground" /> Show background?
</label>
</div>
</div>
<div class="col-sm-2">
<div class="checkbox">
<label>
<input type="checkbox" id="hidegrid" /> Hide grid?
</label>
</div>
</div>
<div class="col-sm-2">
<button class="btn btn-primary" data-toggle="modal" data-target="#fileloader">Load File</button>
</div>
</div>
<div id="debug" class="collapse panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Debugging & performance options</h3>
</div>
<div class="panel-body">
<form class="form-horizontal" role="form" id="debug-form">
<div class="form-group">
<label class="col-sm-2 control-label" for="canvassize">Canvas size</label>
<div class="col-sm-3">
<select class="form-control" id="canvassize">
<option>800x600</option>
<option>800x800</option>
<option>640x480</option>
<option>400x300</option>
<option>200x150</option>
</select>
</div>
<label class="col-sm-2 col-sm-offset-1 control-label" for="numgrps">Max number of grps</label>
<div class="col-sm-3">
<select class="form-control" id="numgrps">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</div>
<div class="form-group"> </div>
<div class="form-group slider-group">
<div class="col-sm-offset-1 col-sm-3 control-label">
<label for="subsetpercent">% points to render</label><br />
<span id="ptsDrawn"></span>
</div>
<div class="col-sm-4">
<div id="subsetpercent"></div>
</div>
<div id="disp-subsetpercent" class="col-sm-1 slider-value" style="margin-left: 40px;">100%</div>
</div>
<div class="form-group">
<div class="col-sm-5 control-label">
<label for="doperf">Execute a performance run (dumps to console)</label>
</div>
<div class="col-sm-3">
<button class="btn btn-default" id="doperf">
Do performance run
</button>
</div>
<div class="col-sm-2">
<div class="checkbox">
<label>
<input type="checkbox" id="showpoints" /> Show points?
</label>
</div>
<button class="btn btn-default" id="shufflepts">
Shuffle groups
</button>
</div>
<div class="col-sm-2">
<div class="checkbox">
<label>
<input type="checkbox" id="dotiming" /> <abbr title="See console for info">Do timing?</abbr>
</label>
</div>
</div>
</div>
</form>
</div>
</div>
</form>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Example Datasets</h3>
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt><a href="#venn2.txt/2/0/1/2">venn2.txt</a></dt>
<dd>The default showing two gaussian data series.</dd>
<dt><a href="#venn4.txt/2/0/1/2">venn4.txt</a></dt>
<dd>Slightly skewed distributions of four data series.</dd>
<dt><a href="#venn5-25k.txt/2/0/1/2">venn5-25k.txt</a></dt>
<dd>Five data series (5k points each) with similar but offset centers as <code>venn2.txt</code>.</dd>
<dt><a href="#venn5-250k.txt/2/0/1/2">venn5-250k.txt</a></dt>
<dd>Similar to <code>venn5-25k.txt</code> except with 50k points per series to total 250k points total.</dd>
</dl>
<hr />
<p>Some datasets for those computers who lack GPU (only 500 pts total):</p>
<dl class="dl-horizontal">
<dt><a href="#venn1-500.txt/2/0/1/2">venn1-500.txt</a></dt>
<dd>A single gaussian data series.</dd>
<dt><a href="#venn2-500.txt/2/0/1/2">venn2-500.txt</a></dt>
<dd>Two gaussian data series.</dd>
<dt><a href="#venn3-500.txt/2/0/1/2">venn3-500.txt</a></dt>
<dd>Three gaussian data series; the data gets a little more sparse. Changing bandwidth or zooming out still shows structure.</dd>
<dt><a href="#venn4-500.txt/2/0/1/2">venn4-500.txt</a></dt>
<dd>Similar to <code>venn3-500.txt</code> except 125 points per group, meaning structure is even harder to see, but is still recoverable using the above tips.</dd>
</dl>
</div>
</div>
<div id="faq" class="modal fade" tabIndex="-2" role="dialog" aria-labelledby="faqLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="faqLabel">How to Use Splatterplots JS</h4>
</div>
<div class="modal-body">
<p>
This project is a JavaScript implementation of the Splatterplot interface described by <a href="http://cs.wisc.edu/~adrm" target="_blank">Adrian Mayorga</a> and <a href="http://cs.wisc.edu/~gleicher" target="_blank">Michael Gleicher</a> in their TVCG submission entitled <a href="http://graphics.cs.wisc.edu/Papers/2013/MG13/" target="_blank"><strong>Splatterplots: Overcoming Overdraw in Scatter Plots</strong></a>.
</p><p>
This current implementation is architected by <a href="http://cs.wisc.edu/~sarikaya" target="_blank">Alper Sarikaya</a> to test the practicality of WebGL as a visualization medium. A short paper on this (continuing) effort was presented at the <a href="http://www.interactive-analysis.org/papers/2015/sarikaya.pdf" target="_blank">Data Systems for Interactive Analysis workshop</a> at IEEE VIS 2015. The project contents are <a href="https://github.com/uwgraphics/splatterjs/" target="_blank">available for browsing and forking on GitHub</a>.
</p>
<p> </p>
<h4>Loading data into Splatterplots JS</h4>
<p>
Load a file into the Splatterplot interface by clicking the blue <button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#fileloader">Load File</button> button. A modal dialog will pop-up, asking for a filename. Select a text file for uploading, and the dialog will automatically interpret the first couple of lines of the datafile.
</p><p>
Fill in the parameters based on the composition of the data. You will have the option to select the columns that represent the x- and y-axis. By selecting a <strong>Group By column</strong>, the data will be split into data series based on the unique values in that column.
</p><p>
Clicking on the <strong>Save Options and Load Dataset</strong> button will load the dataset into Splatterplots. You can return to the dataset setup page to change data parsing parameters without having to re-upload your data.
</p><p>
The <em>URL will update</em> to contain the datafile uploaded as well as parsing parameters. You can use this URL with the hash intact to return to your view of the data.
</p>
<p> </p>
<h4>Interacting with Splatterplots</h4>
<p>
Interact with Splatterplots by dragging the canvas with the mouse button and zooming using the scroll wheel. The visual parameters of Splatterplots can be changed by moving the sliders under the canvas; the visualization will update when the slider is released.
</p><p>
By default, each individual data series will use the highest density value <em>visible on the canvas</em> to determine the filled, thresholded region. The <strong>Use Global Maximum?</strong> checkbox will force all data series to use the same global maximum of the current view. This may help to view direct comparisons, but will de-emphasize underrepresented data series.
</p>
<p> </p>
<h4>Implementation Notes</h4>
<p>
This implementation of Splatterplots has only been tested in Google Chrome (v36). Client computers must support WebGL (GPU, drivers, browser, OS) and the <strong>OES_float_texture</strong> WebGL extension for correct rendering. Check WebGL support of your current configuration on <a href="http://renderingpipeline.com/webgl-extension-viewer/" target="_blank">RenderingPipeline</a>. Firefox support is forthcoming. Internet Explorer and Safari do not support WebGL due to security concerns.
</p>
</div>
<div class="modal-footer">
<p class="pull-left small" style="text-align: left;"><a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/InteractiveResource" property="dct:title" rel="dct:type">SplatterJs</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://cs.wisc.edu/~sarikaya" property="cc:attributionName" rel="cc:attributionURL">Alper Sarikaya</a> is licensed under a <br /><a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.<br />Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="http://www.interactive-analysis.org/papers/2015/sarikaya.pdf" rel="dct:source">http://www.interactive-analysis.org/papers/2015/sarikaya.pdf</a>.</p>
<button class="btn btn-success" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="fileloader" class="modal fade" tabIndex="-1" role="dialog" aria-labelledby="fileloaderLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="fileloaderLabel">Load file to the Splatterplot</h4>
</div>
<div class="modal-body">
<p>Choose a file to upload below. Currently, the tool only supports comma-separated values with the file extensions of .csv, .txt, or .dat. The name of the file you upload cannot have spaces, or the file will fail to load.</p>
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Select files...</span>
<!-- The file input field used as target for the file upload widget -->
<input id="fileupload" type="file" name="files[]" multiple>
</span>
<br>
<br>
<!-- The global progress bar -->
<div id="progress" class="progress hidden">
<div class="progress-bar progress-bar-success"></div>
</div>
<!-- The container for the uploaded files -->
<div id="files" class="files">
<div id="uploadError" class="hidden">
<p class="bg-danger lg-msg">
Error uploading file:
<span id="uploadErrorDetail"></span>.
</p>
</div>
<div id="uploadSuccess" class="hidden">
<p class="bg-success lg-msg">
File <strong></strong> uploaded.
</p>
</div>
</div>
<div id="filefeedback" class="hidden">
<hr />
<p>Here is a sample of the beginning of the file you just uploaded. Please select the appropriate options below to view the dataset in the Splatterplot.</p>
<p>You can return to this dialog to change options later.</p>
<pre></pre>
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
<div class="checkbox">
<label>
<input type="checkbox" id="uploadHasHeader" checked /> File has header
</label>
</div>
</div>
<label for="uploadHeaderRow" class="col-sm-3 control-label">Header Row</label>
<div class="col-sm-4">
<select id="uploadHeaderRow" class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
</div>
<div class="form-group">
<label for="uploadDataStartLine" class="col-sm-offset-4 col-sm-4 control-label">Data starts on...</label>
<div class="col-sm-4">
<input class="form-control" id="uploadDataStartLine" placeholder="line number" required />
</div>
<p id="uploadDataStartLineFeedback" class="col-sm-offset-6 col-sm-6 help-block text-right hidden"></p>
</div>
<div class="form-group">
<label for="uploadXColumn" class="col-sm-offset-4 col-sm-4 control-label">X-axis column</label>
<div class="col-sm-4">
<select id="uploadXColumn" class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
</div>
<div class="form-group">
<label for="uploadYColumn" class="col-sm-offset-4 col-sm-4 control-label">Y-axis column</label>
<div class="col-sm-4">
<select id="uploadYColumn" class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
</div>
<div class="form-group">
<label for="uploadGroupColumn" class="col-sm-offset-4 col-sm-4 control-label">Group By column</label>
<div class="col-sm-4">
<select id="uploadGroupColumn" class="form-control">
<option>None</option>
</select>
</div>
<p class="col-sm-offset-4 col-sm-8 help-block text-right">If anything other than <strong>None</strong> is selected, that column will be used to slice the given data into different data series.</p>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">Cancel and Close</button>
<button id="uploadSubmit" class="btn btn-primary">Save Options and Load Dataset</button>
</div>
</div>
</div>
</div>
<!-- load scripts down here -->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<!-- jQueryUI necessary for sliders -->
<script type="text/javascript" src="libs/jquery-ui-1.10.4.custom.min.js"></script>
<!-- helps with parsing mousewheel events -->
<script type="text/javascript" src="libs/jquery.mousewheel.js"></script>
<!-- boostrap -->
<script type="text/javascript" src="libs/bootstrap.min.js"></script>
<!-- libraries for jQuery File Upload -->
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="libs/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="libs/jquery.fileupload.js"></script>
<!-- library for storing state in the URL hash -->
<script src="libs/hashable.js"></script>
<!-- adds ability to push/pop matrices, and adds matrix classes/functions -->
<!-- https://github.com/evanw/lightgl.js/ -->
<script type="text/javascript" src="libs/lightgl.js"></script>
<!-- adds ability to spatially query for points -->
<script type="text/javascript" src="libs/kdTree-min.js"></script>
<!-- the actual javascript -->
<script type="text/javascript" src="debug.js"></script>
<script type="text/javascript" src="fileops.js"></script>
<script type="text/javascript" src="color.js"></script>
<script type="text/javascript" src="perf.js"></script>
<script type="text/javascript" src="splatterplot.js"></script>
<script>
// make the hash object accessible anywhere (global scope)
var hash;
<!-- on-demand javascript to handle file uploads -->
$(function () {
// save the current-uploaded file and the upload dir
var currentFile = {};
var uploadFileDir = "libs/jq-fileupload-include/files/";
// handle setting up the hash object for saving state in URL
hash = hashable.hash()
.format("{path}/{dataRow}/{x}/{y}/{grp}")
.change(function(e) {
var data = e.data;
$("#filename-label").html(data.path);
// get the data and load it into the splatterplot
$.get(uploadFileDir + data.path, parseDataToSplatterplot(hash));
console.log("changed state: ", data);
})
// default parameters for the URL hash; load the venn2.txt dataset if no
// URL has present
.default(function() {
return {
path: "venn2.txt",
dataRow: 2,
x: 0,
y: 1,
grp: 2
}
})
.enable()
.check();
// change the fidelity of Splatterplots when clicked
if (location.search == "?lofi") {
$("#changefi").html("Hi-fi version (800x600)");
} else {
$("#changefi").html("Lo-fi version (640x480)");
}
$("#changefi").click(function() {
//window.event.returnValue = false;
if (window.location.search == "?lofi") {
setTimeout(function() { location.search = ""; }, 100);
} else {
setTimeout(function() { location.search = "?lofi"; }, 100);
}
});
// given a file, try to figure out how many columns are in the file
// and what the column names are
function populateUploadOptions() {
$("#filefeedback pre").html(currentFile.preview);
var lines = currentFile.preview.split("\n");
if ($("#uploadHasHeader").prop('checked')) {
var header = lines[$("#uploadHeaderRow").val() - 1];
currentFile.columnNames = header.split(",");
currentFile.numColumns = currentFile.columnNames.length;
} else {
// guess at how many columns there are based on the first row
currentFile.numColumns = lines[0].split(",").length;
currentFile.columnNames = [];
for (var i = 1; i <= currentFile.numColumns; i++) {
currentFile.columnNames.push("Column " + i);
}
}
// populate the dropdown (deleting whatever was there before)
var dropdownsToPopulate = [
document.getElementById("uploadXColumn"),
document.getElementById("uploadYColumn"),
document.getElementById("uploadGroupColumn")
];
for (var i = 0; i < dropdownsToPopulate.length; i++) {
var curDropdown = dropdownsToPopulate[i];
// delete existing options
while (curDropdown.hasChildNodes()) {
curDropdown.removeChild(curDropdown.lastChild);
}
// add new options
for (var j = 0; j < currentFile.numColumns; j++) {
var el = document.createElement("option");
el.textContent = currentFile.columnNames[j];
el.value = j;
curDropdown.appendChild(el);
}
// select the n-th column
if (curDropdown.children.length > i) {
curDropdown.children[i].selected = true;
}
}
// shove 'None' as the first option for `Group By column`
var grpChoice = document.getElementById("uploadGroupColumn")
var noneEl = document.createElement("option");
noneEl.textContent = "None"; noneEl.value = -1;
grpChoice.insertBefore(noneEl, grpChoice.firstChild);
// only select a column if there are enough disjoint options
if (currentFile.numColumns >= 3)
grpChoice.children[3].selected = true;
else
grpChoice.firstChild.selected = true;
}
$("#uploadHeaderRow").change(populateUploadOptions);
$("#uploadHasHeader").change(function() {
if ($(this).prop('checked')) {
$("#uploadHeaderRow").prop('disabled', false);
} else {
$("#uploadHeaderRow").prop('disabled', true);
}
populateUploadOptions();
});
// verify that all options are okay before proceding
function verifyOptions() {
var dataStart = $("#uploadDataStartLine").val();
// check if positive integer
if (dataStart === "" || +dataStart != dataStart || dataStart % 1 || dataStart < 0) {
$("#uploadDataStartLineFeedback").removeClass("hidden").focus();
$("#uploadDataStartLineFeedback").text("Please enter a positive integer.");
$("#uploadDataStartLineFeedback").parent().addClass("has-error has-feedback");
return false;
} else {
$("#uploadDataStartLineFeedback").addClass("hidden");
$("#uploadDataStartLineFeedback").parent().removeClass("has-error has-feedback");
}
return true;
}
// callback call for a $.get() request for the data;
// should be called by hashable.hash().change().
// also pass in the hash object so we keep our format string intact.
function parseDataToSplatterplot(thishash) {
return function(data, textStatus) {
// if `thishash` is undefined, no op
if (thishash === undefined) return;
// get the newly-set parameters out of the URL hash
var params = thishash.read().data();
loadFile(
data,
+params.dataRow - 1, // convert 1-index to 0-index
+params.x,
+params.y,
+params.grp
);
resetUIForNewData();
gl.ondraw();
};
};
$("#uploadSubmit").click(function() {
if (verifyOptions()) {
// update the URL string, which will call the change() method
// that prompts a splatterplot dataset update
hash.update({
path: currentFile.url.split(uploadFileDir)[1], // get only the filename
dataRow: +$("#uploadDataStartLine").val(),
x: +$("#uploadXColumn").val(),
y: +$("#uploadYColumn").val(),
grp: +$("#uploadGroupColumn").val()
}).write();
$("#fileloader").modal('hide');
}
});
// provided code to handle file uploads
'use strict';
$('#fileupload').fileupload({
url: 'libs/jq-fileupload-include/',
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
if (file.hasOwnProperty("error")) {
$("#uploadError").removeClass("hidden");
$("#uploadErrorDetail").html(file.error);
$("#progress").addClass("hidden");
} else {
$("#uploadSuccess").removeClass("hidden");
$("#uploadSuccess strong").html(file.name);
// deal with populating the filefeedback div
$("#filefeedback").removeClass("hidden");
// set the current file, and prime the user form for the uploaded file
currentFile = file;
populateUploadOptions();
}
});
},
progressall: function (e, data) {
$("#uploadError").addClass("hidden");
$("#uploadSuccess").addClass("hidden");
$("#filefeedback").addClass("hidden");
$('#progress').removeClass('hidden');
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css(
'width',
progress + '%'
);
}
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
// finally, load given path into the splatterplot when the page finishes loading
$.get(uploadFileDir + hash.data().path, parseDataToSplatterplot(hash));
});
</script>
</div> <!-- close container -->
</body>
</html>