-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
588 lines (502 loc) · 18.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Collection View</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link href="custom.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-MEPG31ZC2R"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-MEPG31ZC2R');
</script>
</head>
<!--
Designed and built by Ed Sperr ([email protected] or [email protected])
-->
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="venn.js"></script>
<script src="vennframework.js"></script>
<script src="proportion-graph-framework.js"></script>
<script src="local-settings.js"></script>
<div class="container" style="min-width: 35em;">
<div id="topbanner" class="jumbotron">
<h1>Collection View</h1>
<h2>Library of Congress</h2>
<a id="about" class="badge badge-pill badge-light" href="about.html">About Collection View</a>
</div>
<div class="row">
<div id="left" class="col-sm-12 col-md-6 col-lg-8">
<div id="search" class="input-group mb-3 col-lg-9 col-md-12 col-sm-12">
<input type="text" id="pmsearch" class="form-control">
<div class="input-group-append">
<button id="runsearch" class="btn btn-primary" type="button">Search</button>
</div>
</div>
<div id="breakdown">
</div>
<div id="charts">
<div id="formatpanel" class="card mb-3">
<div class="card-header">
Item formats
</div>
<div class="card-body">
<div id="formatresults"></div>
</div>
</div>
<div id="vennpanel" class="card mb-3">
<div class="card-header">
Venn diagram
</div>
<div class="card-body">
<div id="vennresults"></div>
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-4">
<div id="past" class="card mb-3">
<div class="card-header">
Searches
</div>
<div id="searches" class="panel-body">
</div>
</div>
</div>
</div>
<div id="splash" class="card mb-3">
<div class="card-body">
<div class="row">
<div class="col-lg-7 col-sm-12">
<div class="card mb-3 splashtitle">
<div class="card-body">
<p class="card-text">Collection View helps you explore your library's collections (in this case, the <a href="https://www.loc.gov/">Library of Congress</a>) by graphically <em>summarizing</em> your search results. Enter any valid <a href="https://www.loc.gov/help/search/">LoC
web search</a> and you'll see it presented in a few different ways...</p>
</div>
</div>
</div>
<div class="col-lg-5 col-sm-12">
<div class="card mb-3 splashpart" >
<img class="card-img-top" src="viruses.png" alt="Formats for 'viruses'">
<div class="card-body">
<p class="card-text">Want to see what types of materials you can find for a given search? The number of items of each format found is represented by a compact visualization.
In this example, the results for 'viruses.'</p>
</div>
</div>
</div>
<div class="col-lg-4 col-sm-12">
<div class="card mb-3 splashpart">
<img class="card-img-top" src="death-and-taxes.png" alt="Venn diagram for 'death AND taxes'">
<div class="card-body">
<p class="card-text">Want to see how the parts of a complex search interact? Use <a href="https://ncu.libguides.com/researchprocess/boolean">Boolean logic</a>, and you’ll get a Venn diagram in return.
For example, here are the results for 'death AND taxes.'</p>
</div>
</div>
</div>
<div class="col-lg-4 col-sm-12">
<div class="card mb-3 splashpart">
<img class="card-img-top" src="war-formats-proportions.png" alt="Diagram comparing proportions for 'war' by format">
<div class="card-body">
<p class="card-text">Curious about how the proportion of different items for a search compare to those of the collection as a whole? A bar graph will show you that comparison for each format.
In this example, those results for 'war.'</p>
</div>
</div>
</div>
<div class="col-lg-4 col-sm-12">
<div class="card mb-3 splashpart">
<img class="card-img-top" src="sputnik-centuries-proportions.png" alt="Diagram comparing proportions for 'war' by format">
<div class="card-body">
<p class="card-text">That same technique can be used to compare search result proproportions by century as well.
In this example, those results for 'sputnik.'</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-7 col-sm-12">
<div class="card mb-3 splashtitle">
<div class="card-body">
<p class="card-text">If you want to explore different search strategies, you can directly <em>compare</em> them to one another in order to zero-in on exactly the terms you want to use.
For example, here is the comparison between searches for 'popcorn' and 'popped corn.' <em><a href="about.html">(more)</a></em></p>
</div>
</div>
</div>
<div class="col-lg-5 col-sm-12">
<div class="card mb-3 splashpart ">
<img class="card-img-top" src="popcorn-comps-formats.png">
</div>
</div>
<div class="col-lg-4 col-sm-12">
<div class="card mb-3 splashpart">
<img class="card-img-top" src="popcorn-comps-venn.png">
</div>
</div>
<div class="col-lg-4 col-sm-12">
<div class="card mb-3 splashpart">
<img class="card-img-top" src="popcorn-comps-format-props.png">
</div>
</div>
<div class="col-lg-4 col-sm-12">
<div class="card mb-3 splashpart">
<img class="card-img-top" src="popcorn-comps-century-props.png">
</div>
</div>
</div>
</div>
</div>
<div id="waiting" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="load-text">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Please wait...</h4>
</div>
<div class="modal-body">
<img src="loading-bars.svg">
</div>
</div>
</div>
</div>
</div>
<p style='clear: both; margin-bottom: 60px;'></p>
<br />
<footer class="footer">
<div class="container">
<span class="text-muted">Design and contruction by <a href="https://esperr.github.io/about/">Ed Sperr, M.L.I.S.</a> |
Data from <a href="https://www.loc.gov/apis/">Library of Congress</a> | Visualization tools from <a href="https://developers.google.com/chart/interactive/docs/gallery/barchart" target="_blank">Google</a> and
<a href="https://github.com/benfred/venn.js/" target="_blank">Ben Frederickson</a>
| See the code at <a href="https://github.com/esperr/collection-view">GitHub</a></span>
</div>
</footer>
<script>
var searches = {};
var pausetime = performance.now();
var searchkey = 0;
const LOCstem = "https://www.loc.gov/search/?q=";
var formatwidth = $("#formatresults").innerWidth() * .9;
var yearwidth = $("#yearresults").innerWidth() * .9;
var vennwidth = $("#vennresults").innerWidth() * .9;
$("#charts").hide();
$("#past").hide();
$( "#yearresults" ).attr( "style", "min-width: " + yearwidth + "px;" );
$( "#vennresults" ).attr( "style", "min-width: " + vennwidth + "px;" );
google.charts.load('current', {packages: ['corechart', 'bar']});
(function() {
getbaselines();
function handlesearch() {
var term = $("#pmsearch").val();
if (!term) {
return;
}
dosearch(term);
}
//Page actions and behaviors
function showWait() {
$( "#pmsearch" ).prop( "disabled", true );
$( "#pmsearch").val("");
$( "#runsearch" ).prop( "disabled", true );
$('#waiting').modal('show');
}
function showDone() {
$( "#pmsearch" ).prop( "disabled", false );
$( "#runsearch" ).prop( "disabled", false );
$( "#runsearch" ).removeClass( "hideme" );
$('#waiting').modal('hide');
setTimeout(function() {
var isShown = $('#waiting').hasClass('show');
if (isShown) {
$('#waiting').modal('hide');
}
}, 1000);
}
$( "#past" ).on( "click", ".pastsearch", function() {
//while (sets.length) { sets.pop(); }
var searchIndex = $(this).data("searchIndex");
showCurrentSearch(searchIndex);
showMultiFormats([searchIndex]);
showFormatBaselineComps([searchIndex]);
if (searches[searchIndex].vennsets.length < 1) {
$("#vennresults").empty();
$("#vennresults").append('<p class="vennMsg">Only one valid search term entered<br />To see a Venn diagram, use Boolean opeartors or <em>combine</em> searches using the menu on the right</p>');
} else {
sets = searches[searchIndex].vennsets.slice(0);
drawVennDiagram();
}
});
$( "#past" ).on( "click", "#showcompare", function() {
$("#past input[name='term']").toggle();
$("#showcompare").toggle();
$("#savebutton").toggle();
$("#past dl").after('<input id="compare" type="button" class="btn btn-primary" value="Compare" /><button id="closecompare" type="button" class="btn btn-default showsearches">Close</button>')
});
$( "#past" ).on( "click", "#compare", function() {
var comparisons = [];
$( "input[name='term']" ).each(function( index ) {
if (this.checked) {
comparisons.push( $( this ).val() );
}
});
showComparisons(comparisons);
compVenn(comparisons);
});
$( "#past" ).on( "click", ".showsearches", function() {
showSearches();
});
$( ".row" ).on( "click", "#reset", function() {
location.replace(location.pathname);
});
//Searching...
function showSearches() {
$('#load-session').hide();
var maxheight = $(".row").first().height() * .8;
var searchname;
$( "#searches" ).empty();
$( "#past" ).removeClass( "hideme" );
$( "#searches" ).attr( 'style', 'max-height:' + maxheight + 'px' );
$( "#searches" ).append("<dl>");
for (var key in searches) {
if (searches.hasOwnProperty(key)) {
if (searches[key].nickname) {
searchname = '"' + searches[key].nickname + '"';
} else {
searchname = searches[key].term;
}
$("#searches dl").append('<dt class="pastsearch"><input type="checkbox" name="term" id="' + key + '" value="' + key + '"> <a href="#!">' + searchname + "</a></dt>");
$("#searches dt").last().append(": " + searches[key].count );
$("#searches dt").last().data("searchIndex", key);
}
}
$("#past input[name='term']").toggle();
if ($("#searches dt").last().data("searchIndex") > 0) {
$("#searches dl").after('<input id="showcompare" type="button" class="btn btn-default" value="Compare searches" />');
}
}
//...and displaying results
function showCurrentSearch(searchkey) {
currentSearch = searches[searchkey];
$( "#breakdown" ).show();
$( "#breakdown" ).empty();
$( "#breakdown" ).append('<p id="yourterm">Your search:</p>');
$( "#yourterm" ).append("'" + currentSearch.term + "'");
var lcurl = LOCstem + encodeURI(currentSearch.term);
$( "#yourterm" ).append('<span id="count"> found <a href="' + lcurl + '" target="_pmresults">' + currentSearch.count + '</a> results</span>');
$( "#yourterm" ).append(' <a href="' + lcurl +'" " target="_blank"><span class="glyphicon glyphicon-link"></span></a>');
$("#showedit").after(' <button id="deleteme" type="button" class="btn btn-danger">Delete this search</button>');
}
function showMultiFormats(searchkeys) {
var formatnames = ['Format'];
var mykey;
var mysearch;
var myformats;
for (m=0; m<searchkeys.length; m++) {
mysearch = searches[searchkeys[m]];
var myformats = mysearch.formatcounts;
for (i=0; i<myformats.length; i++) {
var formattest = formatnames.filter(obj => {
return obj.label === myformats[i].format;
});
if (formattest.length == 0) {
var formatObj = {label: myformats[i].format, type: 'number'};
formatnames.push(formatObj);
}
}
}
var countsarray = [formatnames];
for (m=0; m<searchkeys.length; m++) {
mysearch = searches[searchkeys[m]];
var formatcounts = [mysearch.term];
var myformats = mysearch.formatcounts;
for (i=1; i<formatnames.length; i++) {
var selectedformat = myformats.filter(obj => {
return obj.format === formatnames[i].label;
});
if (selectedformat.length > 0) {
formatcounts.push(selectedformat[0].count);
} else {
formatcounts.push("0");
}
}
countsarray.push(formatcounts);
}
var data = google.visualization.arrayToDataTable(countsarray);
var options = {
width: formatwidth,
height: (formatwidth * 0.3) * searchkeys.length,
legend: { position: 'top', maxLines: 3 },
bar: { groupWidth: '60%' },
isStacked: true
};
var chart = new google.visualization.BarChart(document.getElementById('formatresults'));
//Here comes the clicky bit...
function selectHandler() {
var selectedItem = chart.getSelection()[0];
if (selectedItem && selectedItem.row != null) {
term = data.getValue(selectedItem.row, 0);
format = formatnames[selectedItem.column].label;
var searchroot = getSearchRoot(format);
var locurl = searchroot + term;
window.open(locurl,'_formatsearch');
}
}
google.visualization.events.addListener(chart, 'select', selectHandler);
//google.visualization.events.addListener(chart, 'ready', function () {
// showDone();
//$('#waiting').modal('hide');
//});
chart.draw(data, options);
showDone();
}
function showComparisons(comparisons) {
$( "#breakdown" ).empty();
$( "#formatresults" ).empty();
showMultiFormats(comparisons);
showFormatBaselineComps(comparisons);
}
//If something goes wrong, we start over
function startOver() {
//$("#loading").remove();
alert("Something bad happened when we called the API...");
showDone();
}
function dosearch(term) {
if (searchkey == 0) {
$( "#charts" ).show();
$( "#past" ).show();
}
//showWait();
$('#waiting').modal('show');
pausetime = performance.now();
checkbaselines();
function checkbaselines() {
if (baselines.length === proportionfacets.length) {
callsearch();
} else {
setTimeout(checkbaselines, 30);
}
}
function callsearch() {
$.ajax({
url: baseURL,
error: function () {
startOver();
return;
},
data: {
all: 'true',
q: term,
fo: 'json'
},
success: function( data ) {
// check to see if we get an unusable response
if (!data.search) {
startOver();
return;
}
var totalcount = getCount(data);
if (totalcount == "0") {
$("#breakdown").prepend('<div class="alert alert-danger" role="alert">Nothing found for "' + term + '"! Please try again...</div>');
showDone();
//$('#waiting').modal('hide');
return;
} else {
search = {
'term': term,
'count': totalcount
}
for (let i = 0; i < proportionfacets.length; i++) {
let myFacets = getFacets(data, proportionfacets[i].typedesc, "lc");
let type = proportionfacets[i].type;
let facetcounts = [];
$.each( myFacets, function( key, value ) {
var mycount = value.count;
var mytitle = value.title;
var proportion = mycount/totalcount;
var countObj = { 'count': mycount, 'proportion': proportion };
countObj[type] = mytitle;
facetcounts.push(countObj);
search[type + 'counts'] = facetcounts;
});
}
//let formats = getFacets(data, "original-format", "lc");
//var formatcounts = [];
//$.each( formats, function( key, value ) {
// var mycount = value.count;
// var mytitle = value.title;
//var mymatch = formatbaselines.filter(obj => {
// return obj.format === mytitle;
//});
//var proportion = mycount/totalcount;
//var format = { 'format': mytitle, 'count': mycount, 'proportion': proportion };
//formatcounts.push(format);
//search['formatcounts'] = formatcounts;
//});
//var centuryfacets = data.facets.filter(obj => {
// return obj.type === "dates";
//});
//var centuries = centuryfacets[0].filters
//var centurycounts = [];
//$.each( centuries, function( key, value ) {
// var mycount = value.count;
// var mytitle = value.title;
// var proportion = mycount/totalcount;
// var century = { 'century': mytitle, 'count': mycount, 'proportion': proportion };
// centurycounts.push(century);
//search['centurycounts'] = centurycounts;
//});
//search = {
// 'term': term,
// 'count': data.search.hits,
// 'formatcounts': formatcounts,
// 'centurycounts': centurycounts,
//};
searches[searchkey] = search;
//showDone();
console.log(searches)
showSearches();
showMultiFormats([searchkey]);
showFormatBaselineComps([searchkey]);
//showCenturyBaselineComps([searchkey]);
//showFormats(searchkey);
//var facets = data.facets;
$( ".sharelink" ).remove();
//yearsearch(searchkey, term);
startVenn(searchkey, term);
showCurrentSearch(searchkey);
searchkey++;
if (searchkey == 1) {
$( "#splash" ).hide();
$("#charts").after('<button id="reset" type="button" style="float: right;" class="btn btn-danger">Reset All Searches</button>');
$('[data-toggle="popover"]').popover();
}
//showTranslation(data.esearchresult.querytranslation);
}
}
});
}
}
$("#runsearch").click(function(){
handlesearch();
});
$(document).keypress(function(e) {
if(e.which == 13) {
//Because both IE and FF now "helpfully" ignore the spec and treat 'button' the same as 'submit'
e.preventDefault();
handlesearch();
}
});
})
();
</script>
</body>
</html>