forked from esperr/collection-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
912 lines (796 loc) · 31 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
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
<!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">
<script src="constants.js"></script>
<!-- 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 (esperr@uga.edu or ed_sperr@hotmail.com)
-->
<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="yearframework.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">
<!--<form id="search">
<input id="pmsearch" type="text" />
<input id="runsearch" type="button" value="Search by category" />
</form>
-->
<div id="left" class="col-sm-12 col-md-6 col-lg-8">
<!--<div id="search" class="input-group input-group-lg">
<input type="text" id="pmsearch" class="form-control">
<span class="input-group-btn">
<button id="runsearch" class="btn btn-primary" type="button">Search</button>
</span>
</div>-->
<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">
<a href="questionsandanswers.html#yearplanation" target="_qanda"><span class="question-prompt glyphicon glyphicon-question-sign"></span></a>
Item formats
</div>
<div class="card-body">
<div id="formatresults"></div>
</div>
</div>
<div id="vennpanel" class="card mb-3">
<div class="card-header">
<a href="questionsandanswers.html#vennplanation" target="_qanda"><span class="question-prompt glyphicon glyphicon-question-sign"></span></a>
Venn diagram
</div>
<div class="card-body">
<div id="vennresults"></div>
</div>
</div>
<div class="card mb-3">
<div class="card-header">
Proportion of each format compared to entire collection
</div>
<div class="card-body">
<div id="format_proportions"></div>
</div>
</div>
<div class="card mb-3">
<div class="card-header">
Proportion in each century compared to entire collection
</div>
<div class="card-body">
<div id="century_proportions"></div>
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-4">
<!--<div id="load-session" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Load previous session</h3>
</div>
<div class="panel-body">
<button id="loadText" class="btn btn-default" title="Load a session from a saved file on this machine" data-toggle="modal" data-target="#load-text" type="button">Load from textfile</button>
</div>
</div>-->
<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 class="col-sm-12 col-md-12 col-lg-12">
<p>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 class="col-sm-12 col-md-12 col-lg-12">
<img src="popcorn-comps-formats.png" style="float: left;" width=45%>
<img src="popcorn-comps-venn.png" style="float: left;" width=45%>
</div>-->
</div>
</div>
</div>
<div id="hedges-list" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="hedges-list">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Hedges</h4>
</div>
<div class="modal-body">
<form id="hedges"></form>
</div>
<div class="modal-footer">
<span style="float: left;">Sources: <a href="https://www.ncbi.nlm.nih.gov/books/NBK3827/#pubmedhelp.Clinical_Queries_Filters" target="_blank">NLM</a>, <a href="https://hiru.mcmaster.ca/hiru/HIRU_Hedges_MEDLINE_Strategies.aspx" target="_blank">HiRU</a></span>
<button type="button" id="hedge" class="btn btn-primary">Add Hedge</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="unique-records" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="unique-records">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Unique Records</h4>
</div>
<div id="uniques" class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="save-session" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="save-session">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Save this session</h4>
</div>
<div class="modal-body">
<p>You can save this session to return and work with it later.</p> <p>Choose to save it locally (only on this computer/browser) or to download it
as a text file.</p>
<a id="savemeText" href="" download="searchworkbench_session.txt" class="btn btn-success">Download session</a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="save-local" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="save-local">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Save this session</h4>
</div>
<div class="modal-body">
<input type='text' name='sessionname' value="enter a name"><br />
<em>This session will only be saved on this browser and machine – choose "download session" to export it to another machine.</em>
</div>
<div class="modal-footer">
<button id="savelocally" type="button" class="btn btn-success">Save</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="load-local" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="load-local">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Load a saved session</h4>
</div>
<div class="modal-body">
<p>Choose a saved session from the following list:</p>
<div id="loadme"></div>
<br />
<button id="loadLocal" type="button" class="btn btn-success">Load this session</button>
<button id="deleteLocal" type="button" class="btn btn-danger">Delete</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="load-text" 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">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Load session from text file</h4>
</div>
<div class="modal-body">
<input type="file" id="input" accept="text/plain">
</div>
<div class="modal-footer">
<button id="loadtextfile" type="button" class="btn btn-success">Load this session</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</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;
var centurybaselines = [];
var formatbaselines = [];
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() {
//$('[data-toggle="tooltip"]').tooltip();
//do hedges programatically
//localSession stuff...
if (storageAvailable('localStorage')) {
$( "#savemeText" ).before('<button id="savemeLocal" type="button" class="btn btn-success">Save locally</button> ');
}
getLocalsessions();
function handlesearch() {
var term = $("#pmsearch").val();
if (!term) {
return;
}
dosearch(term);
}
//Page actions and behaviors
function showWait() {
console.log("Wait fired!");
$( "#pmsearch" ).prop( "disabled", true );
$( "#pmsearch").val("");
$( "#runsearch" ).prop( "disabled", true );
$('#waiting').modal('show');
//$( "form" ).addClass( "hideme" );
//$( "#yearresults").empty();
//$( "#yearresults" ).append("<div id='loading'><p class='text-center'>Grabbing your results — please wait</p></div>")
//$( "#yearresults p" ).append( '<br /><img src="loading-bars.svg">' );
}
function showDone() {
console.log("Done fired!");
$( "#pmsearch" ).prop( "disabled", false );
$( "#runsearch" ).prop( "disabled", false );
//$( "form" ).removeClass( "hideme" );
$( "#runsearch" ).removeClass( "hideme" );
//$("#loading").remove();
//$("#fetchresults").remove();
$('#waiting').modal('hide');
setTimeout(function() {
var isShown = $('#waiting').hasClass('show');
console.log(isShown);
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]);
showCenturyBaselineComps([searchIndex]);
//showFormats(searchkey);
//drawYearChart([searchIndex]);
//console.log(searches[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);
//drawYearChart(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" />');
//$("#showcompare").after('<button id="savebutton" class="btn btn-default" data-toggle="modal" data-target="#save-session">Save session</button>');
}
}
//...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 = querystem + 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');
}
}
console.log(searches);
google.visualization.events.addListener(chart, 'select', selectHandler);
//google.visualization.events.addListener(chart, 'ready', function () {
// showDone();
//$('#waiting').modal('hide');
//});
chart.draw(data, options);
showDone();
}
//function showFormats(searchkey) {
// var myformats = searches[searchkey].formatcounts;
// var formatnames = ['Format'];
// var formatnumbers = [searches[searchkey].term]
// for (i=0; i<myformats.length; i++) {
// formatnames.push(myformats[i].format);
// formatnumbers.push(myformats[i].count);
// }
// var countsarray = [formatnames, formatnumbers];
// var data = google.visualization.arrayToDataTable(countsarray);
// var options = {
// width: 900,
// height: 300,
// legend: { position: 'top', maxLines: 3 },
// bar: { groupWidth: '75%' },
// isStacked: true
// };
// var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
// chart.draw(data, options);
//}
function showComparisons(comparisons) {
$( "#breakdown" ).empty();
$( "#formatresults" ).empty();
showMultiFormats(comparisons);
showFormatBaselineComps(comparisons);
showCenturyBaselineComps(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 (centurybaselines.length > 0 && formatbaselines.length > 0) {
callsearch();
} else {
setTimeout(checkbaselines, 30);
}
}
function callsearch() {
$.ajax({
url: APIbase,
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 = data.search.hits;
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 {
var formatfacets = data.facets.filter(obj => {
return obj.type === "original-format";
});
var formats = formatfacets[0].filters
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);
});
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 = {
'term': term,
'count': data.search.hits,
'formatcounts': formatcounts,
'centurycounts': centurycounts,
};
searches[searchkey] = search;
//showDone();
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();
}
});
$( "#savemeLocal" ).click(function() {
//localStorage.setItem('session', JSON.stringify(searches));
$('#save-session').modal('hide');
$('#save-local').modal('show');
});
$( "#savelocally" ).click(function() {
var savekey = $("input[name='sessionname']").val();
localStorage.setItem(savekey, JSON.stringify(searches));
$('#save-local').modal('hide');
});
$( "#loadLocal" ).click(function() {
var selsession = $('input[name=savedsession]:checked').val();
searches = JSON.parse(localStorage.getItem(selsession));
$('#load-local').modal('hide');
var newIndex = 0;
for (index in searches) {
newIndex = index;
}
showSearches();
searchkey = newIndex + 1;
$( "#vennpanel" ).removeClass( "hideme" );
$( "#formatpanel" ).removeClass( "hideme" );
});
$( "#deleteLocal" ).click(function() {
var selsession = $('input[name=savedsession]:checked').val();
localStorage.removeItem(selsession);
$('#load-local').modal('hide');
$('#llocalbutton').remove();
getLocalsessions();
});
$( "#loadtextfile" ).click(function() {
var selectedFile = document.getElementById('input').files[0];
checkdate(selectedFile);
var r = new FileReader();
r.onload = function(event) {
// Why yes, this is a nested mess!
try {
(function () {
searches = JSON.parse(event.target.result);
var newIndex = 0;
for (index in searches) {
newIndex = index;
}
showSearches();
searchkey = newIndex + 1;
})();
} catch (e) {
alert("Unable to load search! Please try again...")
}
};
r.readAsText(selectedFile);
$( "#vennpanel" ).removeClass( "hideme" );
$( "#formatpanel" ).removeClass( "hideme" );
$('#load-text').modal('hide');
});
$( "#save-session" ).on('shown.bs.modal', function (e){
//alert("I want this to appear after the modal has opened!");
var dataurl ='data:text/plain;charset=utf-8,'
+ encodeURIComponent(JSON.stringify(searches));
$("#savemeText").attr("href", dataurl);
});
function storageAvailable(type) {
try {
var storage = window[type],
x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
}
catch(e) {
return e instanceof DOMException && (
// everything except Firefox
e.code === 22 ||
// Firefox
e.code === 1014 ||
// test name field too, because code might not be present
// everything except Firefox
e.name === 'QuotaExceededError' ||
// Firefox
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
// acknowledge QuotaExceededError only if there's something already stored
storage.length !== 0;
}
}
function getLocalsessions() {
$("#loadme").empty();
localSessions = [];
$.each(localStorage, function(key, value){
if (typeof localStorage[key] == "string") {
localSessions.push(key);
}
});
if (localSessions.length > 0) {
$( "#loadText" ).before('<button id="llocalbutton" class="btn btn-default" title="Tooltip on top" data-toggle="modal" data-target="#load-local">Load local</button> ');
//$('[data-toggle="tooltip"]').tooltip();
for (i=0; i < localSessions.length; i++){
var myvalue = localSessions[i];
var myname = localSessions[i];
$("#loadme").append('<input type="radio" name="savedsession" value="' + myvalue + '"> ' + myname + '<br>');
}
$("input[name=savedsession]").prop("checked", true);
}
}
function checkdate(selectedFile) {
var now = new Date();
if ( selectedFile.lastModified ) {
var filedate = new Date(selectedFile.lastModified);
} else {
var filedate = new Date(selectedFile.lastModifiedDate);
}
var daysDiff = (Math.floor(now - filedate) / 86400000);
if (daysDiff > 30) {
alert("This saved session is more than 30 days old. Result counts may have changed.");
}
}
})
();
</script>
</body>
</html>