generated from usf-cs360-spring2020/template-bulma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinalViz1mapHm.html
1759 lines (1426 loc) · 62.7 KB
/
finalViz1mapHm.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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Final Visualization 1: Distribution Over Time - Materials Used on Art Items in San Francisco</title>
<!-- Load Bulma from CDN (consider saving it to repository instead) -->
<!-- https://bulma.io/ -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<!-- Load Font Awesome 5 (free) icons -->
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<style>
.hero-image {
/* Use "linear-gradient" to add a darken background effect to the image (photographer.jpg). This will make the text easier to read */
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url("IMG_3853.JPG");
/* Position and center the image to scale nicely on all screens */
background-position: 30%;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
.title {
color: white;
}
.subtitle {
color: white;
}
#ResetButton {
font-size: 12px;
}
#YearIntercalSelectButton {
font-size: 16px;
}
#MaterialTypeSelectButton {
font-size: 16px;
}
#queryButton {
font-size: 16px;
}
.axis {
font: 16px sans-serif;
}
#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.7;
stroke: white;
stroke-width: 1px;
}
th {
text-align: right;
}
</style>
<style>
body {background-color: #FEF8F4;
}
</style>
</head>
<body>
<!-- Page header -->
<!-- https://bulma.io/documentation/layout/hero/ -->
<section class="hero-image">
<div class="hero-body">
<div class="container">
<h1 class="title">Final Visualization 1: Distribution Over Time - Materials Used on Art Items in San Francisco</h1>
<h2 class="subtitle">Visualization in d3.js</h2>
</div>
</div>
</section>
<!-- End page header -->
<!-- Page navigation -->
<!-- https://bulma.io/documentation/components/navbar/ -->
<nav class="navbar is-light" role="navigation" aria-label="main navigation">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item is-active" href="index.html">
<span class="icon"><i class="fas fa-home"></i></span>
<span>Home</span>
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="main-menu">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="main-menu" class="navbar-menu has-text-weight-medium">
<!-- Left navbar items -->
<div class="navbar-start">
<a class="navbar-item" href="dts.html" title="Data">
<span class="icon"><i class="fas fa-table"></i></span>
<span>Data</span>
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
Visualizations
</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="pttpAlpha.html">
<span class="icon"><i class="fas fa-chart-line"></i></span>
<span>Prototype-Alpha: Art Items on Map of San Francisco - Non-proportional Symbol Map in Tableau (with feedback)</span>
</a>
<a class="navbar-item" href="pttpBeta2.html">
<span class="icon"><i class="fas fa-chart-line"></i></span>
<span>Prototype-Beta-OverallMap: Clustering of Artists that Use Similar Materials? - non-proportional symbol map in d3.js (with feedback)</span>
</a>
<a class="navbar-item" href="finalViz1mapHm.html">
<span class="icon"><i class="fas fa-chart-line"></i></span>
<span>Final Visualization 1: Distribution Over Time - Materials Used on Art Items in San Francisco</span>
</a>
<a class="navbar-item" href="finalViz2Hierarchical.html">
<span class="icon"><i class="fas fa-chart-line"></i></span>
<span>Final Visualization 2: Hierarchical Relationship - Types of Materials Used on Art Items in San Francisco </span>
</a>
</div>
</div>
</div>
<!-- Right navbar items -->
<div class="navbar-end">
<a class="navbar-item" href="abt.html" title="About">
<span class="icon"><i class="fas fa-info-circle"></i></span>
<span>About</span>
</a>
</div>
</div>
</div>
</nav>
<!-- End page navigation -->
<section class="section">
<div class="container">
<!-- Begin page content -->
<div class="content">
<h1 class="title">
Proportional Symbol Map & Heatmap
</h1>
<meta charset="utf-8">
<figure>
<svg width="1260" height="600" id="vis">
<g id="basemap"></g>
<!-- turn off pointer events for certain groups -->
<g id="streets" pointer-events="none"></g>
<g id="outline" pointer-events="none"></g>
<g id="artItems"></g>
<g id="tooltip" pointer-events="none"></g>
<g id="details" pointer-events="none"></g>
</svg>
<p font-size = "30px">
<button id="ResetButton" onclick="restButtonClicker()">reset</button>
Filtering options:
<select id="YearIntercalSelectButton"></select>
<select id="MaterialTypeSelectButton"></select>
<button id="queryButton" onclick="queryButtonClicked()">check art items on the map</button></br>
<a href = "finalViz2Hierarchical.html" target = "_blank">What kind of materials are there in each type? (Click to see more specific material classifications!)</a>
</p>
<figcaption>
Source: <a href="https://data.sfgov.org/Culture-and-Recreation/Civic-Art-Collection/7rjr-9n9w">Civic Art Collection</a>
(<a href="https://data.sfgov.org/Geographic-Locations-and-Boundaries/Analysis-Neighborhoods/p5b7-5n3h">Neighborhoods</a>, <a href="https://data.sfgov.org/Geographic-Locations-and-Boundaries/Streets-Active-and-Retired/3psu-pn9h">Streets</a>)
</figcaption>
</figure>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
// configuration of svg/plot area
let config = {
'svg': {},
'margin': {},
'plot': {}
};
config.svg.height = 800;
config.svg.width = 1440; // golden ratio
config.margin.top = 10;
config.margin.right = 220;
config.margin.bottom = -50;
config.margin.left = 160;
config.plot.x = config.margin.left;
config.plot.y = config.margin.top + 630;
config.plot.width = config.svg.width - config.margin.left - config.margin.right;
config.plot.height = config.svg.height - config.margin.top - config.margin.bottom - 720;
// setup svg
let svg = d3.select("body").select("svg#vis");
svg.attr('width', config.svg.width);
svg.attr('height', config.svg.height);
// setup plot area
let plot = svg.append('g');
plot.attr('id', 'plot');
plot.attr('transform', translate(config.plot.x, config.plot.y));
// use a rect to illustrate plot area
let rect = plot.append('rect');
rect.attr('id', 'background');
rect.attr('x', 0);
rect.attr('y', 0);
rect.attr('width', config.plot.width);
rect.attr('height', config.plot.height);
// scales for data
let scale = {
r: d3.scaleSqrt()
};
scale.x = d3.scaleBand();
scale.x.range([0, config.plot.width]);
scale.y = d3.scaleBand();
scale.y.range([config.plot.height, 0]);
// https://github.com/d3/d3-scale-chromatic
scale.color = d3.scaleSequential(d3.interpolatePurples);
scale.r.range([1, 20]).domain([0, 90]);
//interpolatePuBuGn
let axis = {}; // axes for data
axis.x = d3.axisBottom(scale.x);
axis.x.tickPadding(0);
axis.y = d3.axisLeft(scale.y);
axis.y.tickPadding(0);
const urls = {
basemap: "https://data.sfgov.org/resource/xfcw-9evu.geojson",
streets: "https://data.sfgov.org/resource/3psu-pn9h.geojson?$limit=8000",
artItems: "https://data.sfgov.org/resource/7rjr-9n9w.json"
};
// calculate date range
const end = d3.timeDay.floor(d3.timeDay.offset(new Date(), -1));
const start = d3.timeDay.floor(d3.timeDay.offset(end, -7));
const format = d3.timeFormat("%Y-%m-%dT%H:%M:%S");
console.log(format(start), format(end));
urls.artItems = 'https://data.sfgov.org/resource/7rjr-9n9w.json';
console.log(urls.artItems);
const g = {
edgeBunddling: svg.select("g#edgeBunddling"),
basemap: svg.select("g#basemap"),
streets: svg.select("g#streets"),
outline: svg.select("g#outline"),
artItems: svg.select("g#artItems"),
tooltip: svg.select("g#tooltip"),
details: svg.select("g#details")
};
const width = 960;
const height = 500;
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 = {};
let jsonInputArray = [];
initializeYIMTmap();
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(makeHMDataFormat).then(drawAxis).then(drawHeatmap).then(drawColorLegend).then(drawCircleLegend);
d3.json(urls.basemap).then(function(json) {
// makes sure to adjust projection to fit all of our regions
projection.fitSize([960, 600], json);
// draw the land and neighborhood outlines
drawBasemap(json);
// now that projection has been set trigger loading the other files
// note that the actual order these files are loaded may differ
d3.json(urls.streets).then(drawStreets);
d3.json(urls.artItems).then(drawArtItems);
});
//.then(drawTitleCaptions);
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);
}
setAllMT = YIMTmap['allYI']['all mType'];
setAllMT.add(acsNumber);
setAllYI = YIMTmap['allYI'][mType];
setAllYI.add(acsNumber);
setCurrYI = YIMTmap[currYearInterval][mType];
setCurrYI.add(acsNumber);
setCurrYIallMT = YIMTmap[currYearInterval]['all mType'];
setCurrYIallMT.add(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 initializeYIMTmap() {
// ['1811-1835', '1836-1860', '1861-1885', '1886-1910', '1911-1935', '1936-1960', '1961-1985', '1986-2010', '2011-2035', 'unknown year']
YIMTmap['allYI'] = initializeMTacsSubMap();
YIMTmap['1811-1835'] = initializeMTacsSubMap();
YIMTmap['1836-1860'] = initializeMTacsSubMap();
YIMTmap['1861-1885'] = initializeMTacsSubMap();
YIMTmap['1886-1910'] = initializeMTacsSubMap();
YIMTmap['1911-1935'] = initializeMTacsSubMap();
YIMTmap['1936-1960'] = initializeMTacsSubMap();
YIMTmap['1961-1985'] = initializeMTacsSubMap();
YIMTmap['1986-2010'] = initializeMTacsSubMap();
YIMTmap['2011-2035'] = initializeMTacsSubMap();
YIMTmap['unknown year'] = initializeMTacsSubMap();
console.log("Completed YIMTmap: ");
console.log(YIMTmap);
}
function initializeMTacsSubMap() {
//typeName = ['architectural material', 'metal', 'mineral', 'ecological', 'daily life object', 'kiln product'];
MTacsSubMap = {};
MTacsSubMap['all mType'] = new Set();
MTacsSubMap['architectural material'] = new Set();
MTacsSubMap['metal'] = new Set();
MTacsSubMap['mineral'] = new Set();
MTacsSubMap['ecological'] = new Set();
MTacsSubMap['daily life object'] = new Set();
MTacsSubMap['kiln product'] = new Set();
return MTacsSubMap;
}
function makeHMDataFormat(data) {
console.log('timeMap: ');
console.log(timeMap);
console.log('rawDataPlatTableArr: ');
console.log(rawDataPlatTableArr);
console.log("Completed YIMTmap: ");
console.log(YIMTmap);
//prepare data format for heatmap
i = 0;
while(i < 6) {
let oneRow = {};
oneRow.values = [];
count = 0;
type = typeName[i];
oneRow['type'] = type;
while(count < 10) {
oneRow.values.push({
'yearInterval': yearInterval[count],
'itemCount': timeMap[type][count],
'index': i
})
count ++;
}
res[i] = oneRow;
i ++;
}
console.log(res);
return res;
}
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", "plot")
.attr("transform", translate(pad + 90, pad));
let line = d3.line()
.curve(d3.curveLinear)
.x(d => d.x + 900)
.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 acsSet = new Set();
if (YearChosen == 'all') {
if(MTypeChosen == 'all') {
acsSet = YIMTmap['allYI']['all mType'];
} else {
acsSet = YIMTmap['allYI'][MTypeChosen];
}
} else {
if(MTypeChosen == 'all') {
acsSet = YIMTmap[YearChosen]['all mType'];
} else {
acsSet = YIMTmap[YearChosen][MTypeChosen];
}
}
console.log("acsSet before drawing nodes: ");
console.log(acsSet);
let circles = g.selectAll('circle')
.data(nodes, node => node.data.name)
.enter()
.append('circle')
.attr('r', r)
.attr('cx', d => d.x + 900)
.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 drawAxis(data) {
console.log(data);
// now that we have data set the scale domain
scale.x.domain(yearInterval);
scale.y.domain(typeName);
// draw the x and y axis
let gx = svg.append('g');
gx.attr("id", "x-axis");
gx.attr("class", "axis");
plotX = config.plot.x;
plotYH = config.plot.y + config.plot.height;
gx.attr('transform', translate(plotX, plotYH));
gx.call(axis.x);
let gy = svg.append('g');
gy.attr("id", "y-axis");
gy.attr("class", "axis");
plotY = config.plot.y;
gy.attr('transform', translate(config.plot.x, config.plot.y));
gy.call(axis.y);
// add the options to the button
return data;
}
function drawHeatmap(data) {
const graphTitle = g.artItems.append('text')
.text('Distribution Over Time of Materials Used on Art Items in San Francisco');
graphTitle.attr("id", 'graphTitle');
graphTitle.attr('dx', 20);
graphTitle.attr('dy', 75);
graphTitle.attr('font-size', '23px');
//let typeName = ['architectural material', 'metal', 'mineral', 'ecological', 'daily life object', 'kiln product'];
allValues = timeMap['architectural material'].concat(timeMap['metal'],
timeMap['mineral'], timeMap['ecological'], timeMap['daily life object'], timeMap['kiln product'])
allValues.sort((a,b)=>a-b);
console.log(allValues);
let min = d3.quantile(allValues, 0);