-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·613 lines (516 loc) · 23.1 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
<html>
<head>
<link type="stylesheet" href="./style.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body,
html {
position: relative;
margin: 0 auto;
padding: 0;
width: 90%;
height: 100%;
}
.gradient {
background: #1e343e;
/* Old browsers */
background: linear-gradient(to right, #1e343e 10%, #1e343e 49%, #122630 50%, #122630 100%, #2989d8 100%, #207cca 100%, #122630 100%);
/* W3C */
}
.wrap {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.bottle {
position: relative;
width: 50px;
height: 150px;
/* max-height: 60px; */
min-height: 60px;
margin-top: 60px;
border-radius: 30px 30px 4px 4px;
z-index: 5;
background: black;
/* Old browsers */
/* background: linear-gradient(to right, #1e343e 10%, #1e343e 49%, #122630 50%, #122630 100%, #2989d8 100%, #207cca 100%, #122630 100%); */
/* W3C */
}
.bottle:before {
position: absolute;
top: -45px;
left: 15px;
width: 20px;
height: 60px;
background: grey;
/* Old browsers */
/* background: linear-gradient(to right, #1e343e 10%, #1e343e 49%, #122630 50%, #122630 100%, #2989d8 100%, #207cca 100%, #122630 100%); */
/* W3C */
border-radius: 2px 2px 0 0;
content: "";
}
.bottle .cap {
position: absolute;
top: -42px;
left: 13px;
width: 24px;
height: 10px;
background: #1e343e;
/* Old browsers */
background: linear-gradient(to right, #1e343e 10%, #1e343e 49%, #122630 50%, #122630 100%, #2989d8 100%, #207cca 100%, #122630 100%);
/* W3C */
border-radius: 2px;
content: "";
}
.bottle .label {
position: absolute;
top: 30px;
left: 5px;
width: 40px;
height: 75px;
border-radius: 30px 30px 4px 4px;
background-color: #fff;
}
.bottle .label .labelBefore {
position: absolute;
bottom: 0;
left: 0;
display: block;
width: 40px;
height: 40px;
border-radius: 20px 20px 0 0;
background-color: #ff9900;
content: "";
}
.bottle .label .labelAfter {
position: absolute;
top: 0;
left: 0;
display: block;
width: 40px;
height: 3px;
background-color: #ff9900;
content: "";
}
.bottle .shadow {
position: absolute;
bottom: -7px;
left: -25px;
width: 100px;
height: 40px;
border-radius: 100%;
background-color: rgba(0, 0, 0, 0.6);
z-index: 1;
}
.grid {
display: grid;
grid-gap: 5px;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
grid-auto-rows: 300px;
}
.char {
border-radius: 3px;
padding: 1em;
background-color: white;
}
</style>
</head>
<body>
<h3 style="text-align: center"><u>Chernoff variant - Visualizing Wine dataset using Wine bottle as a chernoff
variant</u></h3>
<br>
<div class="row text-center" style="">
<div class="col-md-6">
<h3><u>LEGEND:</u></h3>
<img src="LEGEND.png" style="width:40%;max-width: 300px;">
</div>
<div class="col-md-6 text-left">
<h4><u>FEATURES:</u></h4>
<ul>
<li>Feature 1 : Bolt Size</li>
<li>Feature 2 : Cap Size</li>
<li>Feature 3 : Bottle Height</li>
<li>Feature 4 : Liquid Amount</li>
<li>Feature 5 : Bottle opacity</li>
</ul>
</div>
</div>
<p>Control Panel</p>
<div class="" style="position: absolute;background-color: grey;width: 100%;height:10%">
<div class="d-inline-block text-center">
<label>Feature 1 (Bolt Size)</label>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle boltDropDown" type="button" id="dropdownMenuButton"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" id="boltDropDown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</div>
<div class="d-inline-block">
<label>Feature 2 (Cap Size)</label>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle capDropDown" type="button" id="dropdownMenuButton"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" id="capDropDown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</div>
<div class="d-inline-block">
<label>Feature 3 (Bottle height)</label>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle heightDropDown" type="button" id="dropdownMenuButton"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" id="heightDropDown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</div>
<div class="d-inline-block">
<label>Feature 4 (Liquid Amount)</label>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle liquidDropDown" type="button" id="dropdownMenuButton"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" id="liquidDropDown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</div>
<div class="d-inline-block">
<label>Feature 5 (Bottle Opacity)</label>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle opacityDropDown" type="button" id="dropdownMenuButton"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" id="opacityDropDown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</div>
</div>
<br>
<hr>
<div class="row" style="position: absolute;margin-top:30px">
<div class="d-inline-block">
<label>Sort based on:</label>
<div class="dropdown1">
<button class="btn btn-secondary dropdown-toggle sortDropDown" type="button" id="sortDrop"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
None
</button>
<div class="dropdown-menu" aria-labelledby="sortDrop" id="sortDropDown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</div>
<div class="d-inline-block">
<label>Sort order:</label>
<div class="dropdown2">
<button class="btn btn-secondary dropdown-toggle sortOrder" type="button" id="sortOrder"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Ascending
</button>
<div class="dropdown-menu" aria-labelledby="sortOrder" id="sortOrderDropDown">
<a class="dropdown-item" href="javascript:sortOrder('asc','Ascending')">Ascending</a>
<a class="dropdown-item" href="javascript:sortOrder('desc','Decending')">Decending</a>
</div>
</div>
</div>
</div>
<script src="./js/d3.v4.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<script>
let globalRef = {};
var heightScale;
var globalData;
var globalSortOrder='asc';
$(function () {
heightScale = d3.scaleLinear()
.domain([0, 3])
.range([0, 100]);
// boltScale = d3.scale.linear()
// .domain([0, 10000])
// .range([0, 100]);
// capSize = d3.scale.linear()
// .domain([0, 10000])
// .range([0, 100]);
let gridData = gridDatagenerate();
d3.csv('wine.csv', function (data) {
// console.log(data)
grid = d3.select("body")
.append("div")
.attr("id", "grid")
.attr("class", "grid")
.style('padding-top', '100px')
.style('text-align', 'center');
chars = grid
.selectAll("div")
.data(data)
.enter()
.append("div")
.attr("class", function (d, i) { return "char char-" + i })
content = chars
.append("div")
.attr("class", "main")
.style('height', '300px')
.style('width', 'fit-content')
$('.main').append(`<div class="bottle"><div class="cap"></div><div class="label"><div class="labelBefore"></div> <div class="labelAfter"></div> </div>
<div class="shadow"></div></div>`);
$('.main').prepend('<i class="fa fa-bolt"></i>');
//init dropdown menu and the global dictionary
$('.dropdown-menu').empty();
let st1 = '';
let st2 = '';
let st3 = '';
let st4 = '';
let st5 = '';
let forSort = '';
let keys = Object.keys(data[0]);
st1 = ` <a class="dropdown-item" href="javascript:modifyGlobalRef('None','bolt','boltDropDown')">None</a>`;
st2 = ` <a class="dropdown-item" href="javascript:modifyGlobalRef('None','capSize','capDropDown')">None</a>`;
st3 = ` <a class="dropdown-item" href="javascript:modifyGlobalRef('None','height','heightDropDown')">None</a>`;
st4 = ` <a class="dropdown-item" href="javascript:modifyGlobalRef('None','liquid','liquidDropDown')">None</a>`;
st5 = ` <a class="dropdown-item" href="javascript:modifyGlobalRef('None','opacity','opacityDropDown')">None</a>`;
forSort = ` <a class="dropdown-item" href="javascript:sortData('None')">None</a>`;
keys.map(function (k) {
if (k == 'alcohol') {
globalRef[k] = 'height';
$('.heightDropDown').html(k);
} else if (k == 'flavanoids') {
globalRef[k] = 'bolt';
$('.boltDropDown').html(k);
} else if (k == 'hue') {
globalRef[k] = 'capSize';
$('.capDropDown').html(k);
} else if (k == 'total phenols') {
globalRef[k] = 'liquid';
$('.liquidDropDown').html(k);
} else if (k == "color intensity") {
globalRef[k] = 'opacity';
$('.opacityDropDown').html(k);
}
st1 += ` <a class="dropdown-item" href="javascript:modifyGlobalRef('${k}','bolt','boltDropDown')">${k}</a>`;
st2 += ` <a class="dropdown-item" href="javascript:modifyGlobalRef('${k}','capSize','capDropDown')">${k}</a>`;
st3 += ` <a class="dropdown-item" href="javascript:modifyGlobalRef('${k}','height','heightDropDown')">${k}</a>`;
st4 += ` <a class="dropdown-item" href="javascript:modifyGlobalRef('${k}','liquid','liquidDropDown')">${k}</a>`;
st5 += ` <a class="dropdown-item" href="javascript:modifyGlobalRef('${k}','opacity','opacityDropDown')">${k}</a>`;
forSort += ` <a class="dropdown-item" href="javascript:sortData('${k}')">${k}</a>`;
})
$('#boltDropDown').append(st1);
$('#capDropDown').append(st2);
$('#heightDropDown').append(st3);
$('#liquidDropDown').append(st4);
$('#opacityDropDown').append(st5);
$('#sortDropDown').append(forSort);
let sortOrderSt=`<a class="dropdown-item" href="javascript:sortOrder('asc','Ascending')">Ascending</a>
<a class="dropdown-item" href="javascript:sortOrder('desc','Decending')">Decending</a>`;
$('#sortOrderDropDown').append(sortOrderSt);
globalData = data;
modifyDataAttributes();
});
// $('.square').append(`<div class="bottle">
// <div class="label"></div>
// <div class="shadow"></div>
// </div>`)
});
function sortData(key) {
if(key=='None'){
return;
}
$('.sortDropDown').html(key);
let lessVal=-1;
let moreVal=1;
if(globalSortOrder=='desc'){
lessVal=1;
moreVal=-1
}
globalData.sort(function (a, b) {
var keyA = a[key],
keyB = b[key];
// Compare the 2 dates
if (keyA < keyB) return lessVal;
if (keyA > keyB) return moreVal;
return 0;
});
modifyDataAttributes();
}
function sortOrder(key,name){
$('.sortOrder').html(name);
globalSortOrder=key;
let sortKey=$('.sortDropDown').html();
sortData(sortKey);
}
function setToDefault(id) {
let len = id.split(' ').length
let label = id.split(' ')[len - 1]
// console.log('bringing this to default', label);
if (label == 'heightDropDown') {
$('.bottle').css('height', '150px');
$('.bottle .label').css('height', '75px');
} else if (label == 'opacityDropDown') {
$('.bottle').css('opacity', 1);
} else if (label == 'liquidDropDown') {
$('.bottle .labelBefore').css('height', '40px');
} else if (label == 'capDropDown') {
$('.bottle .cap').css('width', '20px');
$('.bottle .cap').css('left', '15px');
} else if (label == 'boltDropDown') {
$('.fa-bolt').css('font-size', '20px');
}
}
function modifyGlobalRef(key, id, elementID) {
//set the previous key to None
Object.keys(globalRef).forEach(function (k) {
if (globalRef[k] == id) {
globalRef[k] = 'None';
}
});
$('.dropdown').each(function (ele) {
if ($(this).find('button').html() == key) {
setToDefault($(this).find('button').attr('class'));
$(this).find('button').html('None');
}
});
$('.' + elementID).html(key);
if(key=='None'){
setToDefault($('.' + elementID).attr('class'))
}
// console.log(key)
// console.log(id)
globalRef[key] = id;
modifyDataAttributes();
}
function modifyDataAttributes() {
let data = globalData;
data.map(function (d, index) {
let id = '.char-' + index;
Object.keys(globalRef).forEach(function (k) {
if (d[k]) {
let value = parseFloat(d[k]);
let feature = globalRef[k];
if (feature == 'height') {
// console.log(id)
let h = $(id).height();
let dataVals = [];
data.forEach((d) => {
dataVals.push(d[k])
})
// console.log('data val s', dataVals)
heightScale = d3.scaleLinear()
.domain([0, d3.max(dataVals)])
.range([50, 160]); // for height
// console.log('changed height to ', heightScale(value) + 'px');
modifyHeight(id, heightScale(value));
} else if (feature == 'bolt') {
let dataVals = [];
data.forEach((d) => {
dataVals.push(d[k])
})
// console.log('data val s', dataVals)
boltScale = d3.scaleLinear()
.domain([0, d3.max(dataVals)])
.range([5, 40]); // for height
$(id).find('.fa-bolt').css('font-size', boltScale(value) + 'px');
} else if (feature == 'capSize') {
let dataVals = [];
data.forEach((d) => {
dataVals.push(d[k])
})
// console.log('data val s', dataVals)
capScale = d3.scaleLinear()
.domain([0, d3.max(dataVals)])
.range([20, 30]); // for capsize
let newW = capScale(value);
let left = newW / 2 - ((newW - 20) / 2) - parseFloat($(id).find('.bottle .cap').css('left'));
$(id).find('.bottle .cap').css('width', newW + 'px');
$(id).find('.bottle .cap').css('left', 12 + 'px');
} else if (feature == 'liquid') {
let dataVals = [];
data.forEach((d) => {
dataVals.push(d[k])
})
// console.log('data val s', dataVals);
let bottleHeight = $(id).find('.bottle .label').css('height');
liquidHeight = d3.scaleLinear()
.domain([0, d3.max(dataVals)])
.range([10, parseFloat(bottleHeight) - 10]); // for liquid height
$(id).find('.bottle .labelBefore').css('height', liquidHeight(value) - 5 + 'px');
} else if (feature == 'opacity') {
let dataVals = [];
data.forEach((d) => {
dataVals.push(d[k])
})
opacityScale = d3.scaleLinear()
.domain([0, d3.max(dataVals)])
.range([0, 1]); // for liquid height
$(id).find('.bottle').css('opacity', opacityScale(value));
}
}
})
})
}
function modifyHeight(id, height) {
$(id).find('.bottle').css('height', height + 'px');
$(id).find('.bottle .label').css('height', (height * 1 / 2) + 'px');
}
function gridDatagenerate() {
var data = new Array();
var xpos = 1; //starting xpos and ypos at 1 so the stroke will show when we make the grid below
var ypos = 1;
var width = 50;
var height = 50;
// iterate for rows
for (var row = 0; row < 10; row++) {
data.push(new Array());
// iterate for cells/columns inside rows
for (var column = 0; column < 10; column++) {
data[row].push({
x: xpos,
y: ypos,
width: width,
height: height
})
// increment the x position. I.e. move it over by 50 (width variable)
xpos += width;
}
// reset the x position after a row is complete
xpos = 1;
// increment the y position for the next row. Move it down 50 (height variable)
ypos += height;
}
return data;
}
</script>
</body>
</html>