generated from usf-cs360-spring2020/template-bulma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hierarchicalHelpWindow.html
728 lines (574 loc) · 28.6 KB
/
hierarchicalHelpWindow.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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
<!DOCTYPE html>
<html>
<head>
<style>
#tooltip {
font-weight: 600;
text-shadow: 0px 0px 2px white;
fill: orange;
stroke: black;
}
path.land {
fill: #dddddd;
stroke: none;
}
path.neighborhood {
fill: none;
stroke: white;
stroke-width: 3.5px;
pointer-events: none;
}
path.street {
fill: none;
stroke: white;
stroke-width: 1px;
pointer-events: none;
}
.active {
stroke: orange !important;
stroke-width: 1.5px !important;
}
circle.symbol {
fill-opacity: 0.8;
stroke: white;
stroke-width: 1px;
}
th {
text-align: right;
}
.node {
font: 10px sans-serif;
}
.link {
stroke: steelblue;
stroke-opacity: 0.5;
fill: none;
pointer-events: none;
}
</style>
</head>
<body>
<!-- End page navigation -->
<section class="section">
<div class="container">
<!-- Begin page content -->
<div class="content">
<meta charset="utf-8">
<figure>
<svg width="1260" height="500" id="vis">
</svg>
<figcaption>
Source: <a href="https://data.sfgov.org/Culture-and-Recreation/Civic-Art-Collection/7rjr-9n9w">Civic Art Collection</a>
</figcaption>
</figure>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
const width = 960;
const height = 800;
// setup svg
let svg = d3.select("body").select("svg#vis");
svg.attr('width', width);
svg.attr('height', height);
let bcScale = {};
let bcAxis = {};
let bx, by;
const pad = 15;
const r = 10;
const diameter = 500;
const color = d3.scaleSequential(d3.interpolateGnBu);
//interpolateGnBu
color.domain([0,235,471,706,942]);
let matExactMap = {};
let mTypeMap = {};
let materialSet = new Set();
let nodes = new Set();
let original = [];
let processed = [];
let timeMap = {};
let YIMTmap = {};
let locMap = {};
timeMap['architectural material'] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
timeMap['metal'] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
timeMap['mineral'] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
timeMap['ecological'] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
timeMap['daily life object'] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
timeMap['kiln product'] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
let rawDataPlatTableArr = [];
let res = [];
nodes.add('root');
nodes.add('metal');
nodes.add('mineral');
nodes.add('ecological');
nodes.add('daily life object');
nodes.add('architectural material');
nodes.add('kiln product');
let typeName = ['architectural material', 'metal', 'mineral', 'ecological', 'daily life object', 'kiln product'];
let yearInterval = ['1811-1835', '1836-1860', '1861-1885', '1886-1910', '1911-1935',
'1936-1960', '1961-1985', '1986-2010', '2011-2035', 'unknown year'];
//0: 1811-1835
//1: 1836-1860
//2: 1861-1885
//3: 1886-1910
//4: 1911-1935
//5: 1936-1960
//6: 1961-1985
//7: 1986-2010
//8: 2011-2035
let yearIntervaoOptions = ['Select a year interval','all','1811-1835', '1836-1860', '1861-1885', '1886-1910', '1911-1935',
'1936-1960', '1961-1985', '1986-2010', '2011-2035','unknown year'];
var optionYI = d3.select("#YearIntercalSelectButton")
.selectAll('myOptions')
.data(yearIntervaoOptions)
.enter()
.append('option')
.text(function (d) { return d; }) // text showed in the menu
.attr("value", function (d) { return d; }) // corresponding value returned by the button
let MaterialTypeOptions = ['Select a material type','all','architectural material', 'metal', 'mineral', 'ecological', 'daily life object', 'kiln product'];
var optionMT = d3.select("#MaterialTypeSelectButton")
.selectAll('myOptions')
.data(MaterialTypeOptions)
.enter()
.append('option')
.text(function (d) { return d; }) // text showed in the menu
.attr("value", function (d) { return d; }) // corresponding value returned by the button
//'Select a year interval' 'Select a material type'
let YearChosen = 'all';
let MTypeChosen = 'all';
let hmChosen = false;
let metalSet = new Set(["bronze", "steel", "gold leaf", "brass", "aluminum", "zinc", "copper", "bronzing powder", "metalmaterial", "copper leaf", "iron", "gold"]);
let mineralSet = new Set(["marble","granite", "terrazzo", "stone tiles", "cast stone", "soil", "lava rock", "stone", "basalt", "travertine", "graphite", "tesserae", "tuff stone", "stone boulder", "charcoal", "mortar",
"crystals", "minerals", "red porphyry", "onyx"]);
let ecoSet = new Set(["wood", "bone", "horn", "resin", "cotton", "plant", "oil", "wool", "planted earthwork", "wax", "bamboo", "ecological references", "water", "willow", "tule reed"]);
let dailyLifeSet = new Set(["loudspeakers","images","ink", "cables", "mirror", "video", "magnets", "electrical reed switches"
, "photogram", "wire", "egg tempera", "aero plate", "audiobox","electrical wiring",
"pencil", "paper", "digital print", "buttons", "jewelry", "recycled parking meter heads", "brass saxophones", "steel music panels", "shade cloth", "controller", "motors","electronics","recycled mirrors", "annotated library cards"]);
let architectureSet = new Set(["pigments","plastic mixture","paint", "mixed medium","plastic","led lighting","slate", "lighting", "asphalt","unknown", "mixed media relief","painted mural", "linoleum", "pigment", "architectural foam", "pigment print", "pastel", "archival pigment print", "cast aggregate", "mixed media color lino-cut print", "lacquer paint", "foam", "fabric collage", "soffits", "land scaping", "lino-cut print", "cement", "polyurethane foam",
"found objects", "plaster", "fresco", "concrete", "mixed media", "neon lighting", "argon lighting", "fluorescent lighting", "lacquer paints", "mirror tile", "abaca paper", "ink with gesso", "led", "mural",
"photography", "brick", "pipes", "polymer modified gypsum", "sisal rope"]);
let kilnSet = new Set(["glaze","ceramic beads","porcelain enamel","porcelain", "ceramic tile", "clay", "glass", "cast glass", "frosted glass", "mosaic tile", "enamel", "ceramic", "gilding", "enamel paint", "terracotta tile", "glass tiles", "glazed ceramic"
,"crockery", "grout", "basaltic clay", "glass mosaic tile", "gfrc tile", "tile", "glass mosaic", "laminated digital print", "polyurethane paint"]);
const csvMat = "artcommision_categorized_material - Civic_Art_Collection.csv";
d3.csv(csvMat, recordMaterialInfo).then(makeCirTreeDataFormat).then(cirtree);
function recordMaterialInfo(row) {
var materials = row.MediumMaterial;
var matArr = materials.split(",");
if(materials.length != 0) {
index = 0;
while (index < matArr.length) {
temp = matArr[index];
temp = temp.trim();
temp = temp.toLowerCase();
if(temp == "" || temp.length < 1) {
temp = "unknown";
}
materialSet.add(temp);
artist = row.Artist;
date = row.CreationFinishDate;
acsNumber = row.AccessionNumber;
mediumDetail = row.MediumDetail;
displayTitle = row.DisplayTitle;
latitude = row.Latitude;
longitude = row.Longitude;
nbh = row.SFFindNeighborhoods;
locString = row.Latitude + "&" + row.Longitude;
if(locMap[locString]) {
locAcsSet = locMap[locString];
locAcsSet.add(acsNumber);
locMap[locString] = locAcsSet;
// console.log(locAcsSet.size);
} else { //ne wkey value locString
locAcsSet = new Set();
locAcsSet.add(acsNumber);
locMap[locString] = locAcsSet;
}
// console.log('locMap: ');
// console.log(locMap);
// locMap[locString] locString = row.Latitude + "&" + row.Longitude; locAcsSet = locMap[locString] locAcsSet.size
//locMap
//metalSet, mineralSet, ecoSet, dailyLifeSet, architectureSet, kilnSet
timeArrIndex = getTimeIntervalIndex(date);
currYearInterval = yearInterval[timeArrIndex];
if(metalSet.has(temp)) {
mType = "metal";
} else if(mineralSet.has(temp)) {
mType = "mineral";
} else if(ecoSet.has(temp)) {
mType = "ecological";
} else if(dailyLifeSet.has(temp)) {
mType = "daily life object";
} else if(architectureSet.has(temp)) {
mType = "architectural material";
} else if(kilnSet.has(temp)) {
mType = "kiln product";
} else {
console.log("not having: ");
console.log(temp);
}
if(temp == 'metal') {
console.log("@@@@@@@@@@@@@@@@@"+acsNumber);
}
listTimeCount = timeMap[mType][timeArrIndex];
listTimeCount ++;
timeMap[mType][timeArrIndex] = listTimeCount;
if(matExactMap[temp]) {
currMatList = matExactMap[temp];
currMatList.push({
'Material': temp,
'Artist': artist,
'Completion Year': date,
'Accession Number': acsNumber,
'MediumDetail': mediumDetail,
'DisplayTitle': displayTitle,
'Latitude': latitude,
'Longitude': longitude,
'Material Type': mType,
'Year Interval': currYearInterval
});
matExactMap[temp] = currMatList;
} else {
currMatList = [];
currMatList.push({
'Material': temp,
'Artist': artist,
'Completion Year': date,
'Accession Number': acsNumber,
'MediumDetail': mediumDetail,
'DisplayTitle': displayTitle,
'Latitude': latitude,
'Longitude': longitude,
'Material Type': mType,
'Year Interval': currYearInterval
});
matExactMap[temp] = currMatList;
}
if(mTypeMap[mType]) {
typeSubMap = mTypeMap[mType];
if(typeSubMap[temp]) {
itemList = typeSubMap[temp];
itemList.push({
'Material': temp,
'Artist': artist,
'Completion Year': date,
'Accession Number': acsNumber,
'MediumDetail': mediumDetail,
'DisplayTitle': displayTitle,
'Latitude': latitude,
'Longitude': longitude,
'Material Type': mType,
'Year Interval': currYearInterval
})
typeSubMap[temp]= itemList;
} else {
itemList = [];
itemList.push({
'Material': temp,
'Artist': artist,
'Completion Year': date,
'Accession Number': acsNumber,
'MediumDetail': mediumDetail,
'DisplayTitle': displayTitle,
'Latitude': latitude,
'Longitude': longitude,
'Material Type': mType,
'Year Interval': currYearInterval
})
typeSubMap[temp]= itemList;
}
mTypeMap[mType] = typeSubMap;
} else {
typeSubMap = {};
itemList = [];
itemList.push({
'Material': temp,
'Artist': artist,
'Completion Year': date,
'Accession Number': acsNumber,
'MediumDetail': mediumDetail,
'DisplayTitle': displayTitle,
'Latitude': latitude,
'Longitude': longitude,
'Material Type': mType,
'Year Interval': currYearInterval
})
typeSubMap[temp] = itemList;
mTypeMap[mType] = typeSubMap;
}
index++;
}
}
rawDataPlatTableArr.push({
'Artist': artist,
'Completion Year': date,
'Accession Number': acsNumber,
'MediumDetail': mediumDetail,
'DisplayTitle': displayTitle,
'Latitude': latitude,
'Longitude': longitude,
'Material Type': mType,
'Year Interval': currYearInterval
})
return materialSet;
}
function makeCirTreeDataFormat(data) {
console.log('matExactMap: ');
console.log(matExactMap);
console.log('materialSet: ');
console.log(materialSet);
console.log('mTypeMap: ');
console.log(mTypeMap);
console.log('rawDataPlatTableArr: ');
console.log(rawDataPlatTableArr);
//metalSet, mineralSet, ecoSet, dailyLifeSet, architectureSet, kilnSet
allCount = 0; //count of leaves
archName = 'architectural material';
typeCount = recordOneType(architectureSet, matExactMap, original, nodes, archName);
allCount = allCount + typeCount;
metalName = "metal";
typeCount = recordOneType(metalSet, matExactMap, original, nodes, metalName);
allCount = allCount + typeCount;
mineralName = "mineral";
typeCount = recordOneType(mineralSet, matExactMap, original, nodes, mineralName);
allCount = allCount + typeCount;
ecoName = "ecological";
typeCount = recordOneType(ecoSet, matExactMap, original, nodes, ecoName);
allCount = allCount + typeCount;
dailyName = "daily life object";
typeCount = recordOneType(dailyLifeSet, matExactMap, original, nodes, dailyName);
allCount = allCount + typeCount;
kilnName = "kiln product";
typeCount = recordOneType(kilnSet, matExactMap, original, nodes, kilnName);
allCount = allCount + typeCount;
original.push({
'name' : 'root',
'parent' : '',
'count' : allCount,
'leave' : allCount
})
console.log('allCount: ' + allCount);
console.log('original: ');
console.log(original);
root = d3.stratify()
.id(function(row) { return row.name; })
.parentId(function(row) {
return row.parent;
})
(original);
console.log("root: ");
console.log(root);
return root;
}
function cirtree(data) {
data.sort(function(a, b) {
return b.height - a.height || b.count - a.count;
});
let layout = d3.tree().size([2 * Math.PI, (diameter / 2) - pad]);
layout(data);
data.each(function(node) {
node.theta = node.x;
node.radial = node.y;
var point = toCartesian(node.radial, node.theta);
node.x = point.x;
node.y = point.y;
});
let plot = svg.append("g")
.attr("id", "TreePlot")
.attr("transform", translate(pad + 90, pad));
let line = d3.line()
.curve(d3.curveLinear)
.x(d => d.x + 200)
.y(d => d.y + 260);
let generator = function(node) {
return line([node.source, node.target]);
}
drawLinks(plot.append("g"), data.links(), generator);
drawNodes(plot.append("g"), data.descendants(), true);
console.log(data.descendants());
return svg.node();
}
function drawLinks(g, links, generator) {
let paths = g.selectAll('path')
.data(links)
.enter()
.append('path')
.attr('d', generator)
.attr('class', 'link')
.style('stroke','silver')
.style("fill-opacity", "0.8");
}
function drawNodes(g, nodes, raise) {
let circles = g.selectAll('circle')
.data(nodes, node => node.data.name)
.enter()
.append('circle')
.attr('r', r)
.attr('cx', d => d.x + 200)
.attr('cy', d => d.y + 260)
.attr('id', d => d.data.name)
.attr('class', 'node')
.style('fill', d => color(d.data.count))
.style('stroke','silver')
.style("stroke-width", 1);
setupEvents(g, circles, raise);
}
function toCartesian(r, theta) {
return {
x: r * Math.cos(theta),
y: r * Math.sin(theta)
};
}
function setupEvents(g, selection, raise) {
selection.on('mouseover.highlight', function(d) {
// https://github.com/d3/d3-hierarchy#node_path
// returns path from d3.select(this) node to selection.data()[0] root node
let path = d3.select(this).datum().path(selection.data()[0]);
// console.log(path);
// select all of the nodes on the shortest path
let update = selection.data(path, nodes => nodes.id);
// highlight the selected nodes
update.classed('selected', true);
if (raise) {
update.raise()
.style("stroke", "#e68a00")
.style("stroke-width", 5);
}
});
selection.on('mouseout.highlight', function(d) {
let path = d3.select(this).datum().path(selection.data()[0]);
let update = selection.data(path, node => node.data.name);
update.classed('selected', false);
update.style("stroke", "silver")
.style("stroke-width", 1);
});
// show tooltip text on mouseover (hover)
selection.on('mouseover.tooltip', function(d) {
showTooltip(g, d3.select(this));
});
// remove tooltip text on mouseout
selection.on('mouseout.tooltip', function(d) {
g.select("#tooltip").remove();
});
}
numberFormat = d3.format(".3~s");
function showTooltip(g, node) {
let gbox = g.node().getBBox(); // get bounding box of group BEFORE adding text
let nbox = node.node().getBBox(); // get bounding box of node
// calculate shift amount
let dx = nbox.width / 2;
let dy = nbox.height / 2;
// retrieve node attributes (calculate middle point)
let x = nbox.x + dx;
let y = nbox.y + dy;
// get data for node
let datum = node.datum();
let name = datum.data.name;
let text = `${name}`;
// create tooltip
let tooltip = g.append('text')
.text(text)
.attr('x', x)
.attr('y', y)
.attr('dy', -dy - 4) // shift upward above circle
.attr('text-anchor', 'middle') // anchor in the middle
.attr('id', 'tooltip')
.style('stroke','orange');
// it is possible the tooltip will fall off the edge of the
// plot area. we can detect when this happens, and set the
// text anchor appropriately
// get bounding box for the text
let tbox = tooltip.node().getBBox();
// if text will fall off left side, anchor at start
if (tbox.x < gbox.x) {
tooltip.attr('text-anchor', 'start');
tooltip.attr('dx', -dx); // nudge text over from center
}
// if text will fall off right side, anchor at end
else if ((tbox.x + tbox.width) > (gbox.x + gbox.width)) {
tooltip.attr('text-anchor', 'end');
tooltip.attr('dx', dx);
}
// if text will fall off top side, place below circle instead
if (tbox.y < gbox.y) {
tooltip.attr('dy', dy + tbox.height);
}
}
function recordOneType(typeSet, matExactMap, original, nodes, typeName) {
typeCount = 0;
typeSetSize = typeSet.size;
var typeItr = typeSet.entries();
for(i=0;i<typeSetSize;i++){
exactMaterial = typeItr.next().value[0];
nodes.add(exactMaterial);
exactList = [];
exactList = matExactMap[exactMaterial];
// console.log(exactMaterial);
// console.log(exactList);
aitCount = exactList.length;
original.push({
'name' : exactMaterial,
'parent' : typeName,
'count' : aitCount,
'leave' : 1
})
typeCount ++;
}
original.push({
'name' : typeName,
'parent' : 'root',
'count' : typeCount,
'leave' : typeCount
})
return typeCount;
}
function getTimeIntervalIndex(year) {
//every 25 years
//0: 1811-1835
//1: 1836-1860
//2: 1861-1885
//3: 1886-1910
//4: 1911-1935
//5: 1936-1960
//6: 1961-1985
//7: 1986-2010
//8: 2011-2035
var yearValue = parseInt(year);
var diff = yearValue - 1811;
if(diff < 25) {
return 0; //0: 1811-1835
} else if(diff >= 25 && diff < 50){
return 1; //1: 1836-1860
} else if(diff >= 50 && diff < 75) {
return 2; //2: 1861-1885
} else if (diff >= 75 && diff < 100) {
return 3; //3: 1886-1910
} else if(diff >= 100 && diff < 125) {
return 4;
} else if(diff >= 125 && diff < 150) {
return 5;
} else if (diff >= 150 && diff < 175) {
return 6;
} else if (diff >= 175 && diff < 200) {
return 7;
} else if (diff >= 200 && diff < 225) {
return 8;
}
return 9; //8 is for unkown year...
}
function line() {
d3.lineRadial()
.curve(d3.curveBundle.beta(0.85))
.radius(d => d.y)
.angle(d => d.x)
}
function id(node) {
return `${node.parent ? id(node.parent) + "." : ""}${node.data.name}`;
}
function translate(x, y) {
return "translate(" + String(x) + "," + String(y) + ")";
}
</script>
</div>
<!-- End page content -->
</div>
</section>
</body>
</html>