-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwidget.html
740 lines (712 loc) · 62.8 KB
/
widget.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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.3.450">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>TORCHLITE Hackathon Handbook - 4 Creating Summary Widgets and Notebooks</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/quarto-nav/headroom.min.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<link href="./technical-background.html" rel="next">
<link href="./worksets.html" rel="prev">
<link href="./images/cover.png" rel="icon" type="image/png">
<script src="site_libs/quarto-html/quarto.js"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "sidebar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "start",
"type": "textbox",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit",
"search-label": "Search"
}
}</script>
</head>
<body class="nav-sidebar floating">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="quarto-secondary-nav">
<div class="container-fluid d-flex">
<button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<i class="bi bi-layout-text-sidebar-reverse"></i>
</button>
<nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./widget.html"><span class="chapter-number">4</span> <span class="chapter-title">Creating Summary Widgets and Notebooks</span></a></li></ol></nav>
<a class="flex-grow-1" role="button" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
</a>
<button type="button" class="btn quarto-search-button" aria-label="" onclick="window.quartoOpenSearch();">
<i class="bi bi-search"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal sidebar-navigation floating overflow-auto">
<div class="pt-lg-2 mt-2 text-left sidebar-header">
<div class="sidebar-title mb-0 py-0">
<a href="./">TORCHLITE Hackathon Handbook</a>
<div class="sidebar-tools-main tools-wide">
<a href="https://github.com/htrc/torchlite-handbook" rel="" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-github"></i></a>
<div class="dropdown">
<a href="" title="Share" id="quarto-navigation-tool-dropdown-0" class="quarto-navigation-tool dropdown-toggle px-1" data-bs-toggle="dropdown" aria-expanded="false" aria-label="Share"><i class="bi bi-share"></i></a>
<ul class="dropdown-menu" aria-labelledby="quarto-navigation-tool-dropdown-0">
<li>
<a class="dropdown-item sidebar-tools-main-item" href="https://twitter.com/intent/tweet?url=|url|">
<i class="bi bi-bi-twitter pe-1"></i>
Twitter
</a>
</li>
<li>
<a class="dropdown-item sidebar-tools-main-item" href="https://www.facebook.com/sharer/sharer.php?u=|url|">
<i class="bi bi-bi-facebook pe-1"></i>
Facebook
</a>
</li>
</ul>
</div>
<a href="" class="quarto-reader-toggle quarto-navigation-tool px-1" onclick="window.quartoToggleReader(); return false;" title="Toggle reader mode">
<div class="quarto-reader-toggle-btn">
<i class="bi"></i>
</div>
</a>
</div>
</div>
</div>
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index.html" class="sidebar-item-text sidebar-link">
<span class="menu-text">About TORCHLITE</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./htrc.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">1</span> <span class="chapter-title">About HathiTrust and HTRC</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./ef.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span> <span class="chapter-title">Extracted Features</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./worksets.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">3</span> <span class="chapter-title">Featured Worksets</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./widget.html" class="sidebar-item-text sidebar-link active">
<span class="menu-text"><span class="chapter-number">4</span> <span class="chapter-title">Creating Summary Widgets and Notebooks</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./technical-background.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">5</span> <span class="chapter-title">Dashboard Technical Background</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./publications.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">6</span> <span class="chapter-title">Relevant Publications</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./people.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">7</span> <span class="chapter-title">People Involved</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./links.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">8</span> <span class="chapter-title">Quick Links</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./showcase.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">9</span> <span class="chapter-title">Widgets Showcase</span></span></a>
</div>
</li>
</ul>
</div>
</nav>
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#exploring-textual-data-with-the-torchlite-summary-widgets" id="toc-exploring-textual-data-with-the-torchlite-summary-widgets" class="nav-link active" data-scroll-target="#exploring-textual-data-with-the-torchlite-summary-widgets"><span class="header-section-number">4.1</span> Exploring Textual Data with the Torchlite Summary Widgets</a></li>
<li><a href="#different-visualizations" id="toc-different-visualizations" class="nav-link" data-scroll-target="#different-visualizations"><span class="header-section-number">4.2</span> Different Visualizations</a>
<ul class="collapse">
<li><a href="#word-cloud" id="toc-word-cloud" class="nav-link" data-scroll-target="#word-cloud"><span class="header-section-number">4.2.1</span> Word Cloud</a></li>
<li><a href="#pie-chart" id="toc-pie-chart" class="nav-link" data-scroll-target="#pie-chart"><span class="header-section-number">4.2.2</span> Pie Chart</a></li>
<li><a href="#trends" id="toc-trends" class="nav-link" data-scroll-target="#trends"><span class="header-section-number">4.2.3</span> Trends</a></li>
</ul></li>
<li><a href="#exploring-textual-data-with-notebooks" id="toc-exploring-textual-data-with-notebooks" class="nav-link" data-scroll-target="#exploring-textual-data-with-notebooks"><span class="header-section-number">4.3</span> Exploring Textual Data with Notebooks</a></li>
</ul>
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/htrc/torchlite-handbook/edit/main/widget.qmd" class="toc-action">Edit this page</a></p><p><a href="https://github.com/htrc/torchlite-handbook/issues/new" class="toc-action">Report an issue</a></p></div></div></nav>
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title"><span id="sec-6" class="quarto-section-identifier"><span class="chapter-number">4</span> <span class="chapter-title">Creating Summary Widgets and Notebooks</span></span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<blockquote class="blockquote">
<p><em>The Summary offers a brief, textual summary of the current corpus, detailing its word count, unique word count, longest and shortest document, highest and lowest vocabulary densities, readability rate</em></p>
</blockquote>
<section id="exploring-textual-data-with-the-torchlite-summary-widgets" class="level2" data-number="4.1">
<h2 data-number="4.1" class="anchored" data-anchor-id="exploring-textual-data-with-the-torchlite-summary-widgets"><span class="header-section-number">4.1</span> Exploring Textual Data with the Torchlite Summary Widgets</h2>
<p>In this Hackathon, we’re excited to introduce participants to the “Torchlite Summary” widget, a powerful tool designed to enhance your experience with textual data analysis.</p>
<p>Developed using Python in a Jupyter Notebook environment and leveraging the HathiTrust Research Center (HTRC) APIs, this widget offers a streamlined approach to summarizing and exploring large datasets. Whether you’re analyzing literary works, historical documents, or any extensive text corpus, “Torchlite Summary” provides key insights through word frequencies, trends, and thematic overviews.</p>
<p>We encourage all participants to utilize this tool to uncover hidden patterns, compare textual features, and drive their projects to new depths of analysis. A step-by-step guide within the notebook will help you get started, offering insights into API integration, data visualization, and customization options to tailor the tool to your specific research questions.</p>
<blockquote class="blockquote">
<p><a href="https://github.com/htrc/torchlite-summary">Code Base of Torch lite Summary</a></p>
<p><a href="https://github.com/aarthishivkumar/HathiTrust-API/blob/main/htrcpractice1.ipynb">HathiTrust-API</a></p>
</blockquote>
</section>
<section id="different-visualizations" class="level2" data-number="4.2">
<h2 data-number="4.2" class="anchored" data-anchor-id="different-visualizations"><span class="header-section-number">4.2</span> Different Visualizations</h2>
<p>In this section, we will summarize some of the sample visualizations in different programming languages that can be made using TORCHLITE API.</p>
<section id="word-cloud" class="level3" data-number="4.2.1">
<h3 data-number="4.2.1" class="anchored" data-anchor-id="word-cloud"><span class="header-section-number">4.2.1</span> Word Cloud</h3>
<p>A <strong>word cloud</strong> is a visualization technique for displaying text data in which the importance of each word is shown through its size. Typically, the more frequently a word appears in the text, the larger it appears in the word cloud. It’s useful for quickly identifying the most prominent terms in a dataset or text corpus.</p>
<p>The Word Cloud widget is being displayed using React and D3 libraries. Here’s a high-level overview of how it works:</p>
<section id="internal-working-of-word-cloud" class="level4" data-number="4.2.1.1">
<h4 data-number="4.2.1.1" class="anchored" data-anchor-id="internal-working-of-word-cloud"><span class="header-section-number">4.2.1.1</span> Internal working of Word Cloud</h4>
<ul>
<li><p><strong>Data Fetching</strong>: The component fetches data from an external API endpoint (https://tools.htrc.illinois.edu/ef-api/worksets/${worksetId}/volumes) using fetch API. This API returns volumes of text data along with their token counts.</p></li>
<li><p><strong>Data Processing</strong>: Once the data is fetched, it is processed to extract the token counts for each word. Common words and punctuation marks are filtered out, and the frequency of each remaining word is calculated across all volumes.</p></li>
</ul>
<div class="sourceCode" id="cb1"><pre class="sourceCode javascript code-with-copy"><code class="sourceCode javascript"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (<span class="kw">const</span> volume <span class="kw">of</span> data<span class="op">.</span><span class="at">data</span>) {</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">let</span> individualVol <span class="op">=</span> <span class="dv">0</span><span class="op">;</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> loacalPerVolDict[volume<span class="op">.</span><span class="at">htid</span>] <span class="op">=</span> {}</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> (<span class="kw">const</span> page <span class="kw">of</span> volume<span class="op">.</span><span class="at">features</span><span class="op">.</span><span class="at">pages</span>) {</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> body <span class="op">=</span> page<span class="op">.</span><span class="at">body</span><span class="op">;</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (body<span class="op">.</span><span class="at">tokensCount</span> <span class="op">!==</span> <span class="kw">null</span>) {</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">updateDict</span>(body<span class="op">.</span><span class="at">tokensCount</span><span class="op">,</span>loacalPerVolDict[volume<span class="op">.</span><span class="at">htid</span>])<span class="op">;</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> total <span class="op">+=</span> page<span class="op">.</span><span class="at">tokensCount</span><span class="op">;</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> individualVol <span class="op">+=</span> page<span class="op">.</span><span class="at">tokensCount</span><span class="op">;</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> }</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<ul>
<li><p><strong>Word Cloud Generation</strong>: The most frequent words are selected, and their frequencies are used to determine the size of each word in the word cloud. D3’s Word Cloud component (react-d3-cloud) is used to generate the Word Cloud visualization. This component takes in data in the form of an array of word objects, where each object contains the text of the word and its frequency.</p></li>
<li><p><strong>Rendering</strong>: The Word Cloud component is rendered within the React component, with additional styling and customization options such as font size, rotation, and padding.</p></li>
</ul>
<div class="sourceCode" id="cb2"><pre class="sourceCode javascript code-with-copy"><code class="sourceCode javascript"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="op"><</span>WordCloud</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> width<span class="op">=</span>{<span class="dv">1000</span>}</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> height<span class="op">=</span>{<span class="dv">3000</span>}</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> data<span class="op">=</span>{data}</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> fontSize<span class="op">=</span>{fontSize}</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> rotate<span class="op">=</span>{rotate}</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> padding<span class="op">=</span>{<span class="dv">6</span>}</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> spiral<span class="op">=</span><span class="st">"rectangular"</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> random<span class="op">=</span>{<span class="bu">Math</span><span class="op">.</span><span class="fu">random</span>} </span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="op">/></span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a>Stopwords<span class="op">:</span></span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a>[</span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a> <span class="st">'a'</span><span class="op">,</span> <span class="st">'an'</span><span class="op">,</span> <span class="st">'the'</span><span class="op">,</span> <span class="st">'and'</span><span class="op">,</span> <span class="st">'but'</span><span class="op">,</span> <span class="st">'or'</span><span class="op">,</span> <span class="st">'for'</span><span class="op">,</span> <span class="st">'nor'</span><span class="op">,</span> <span class="st">'not'</span><span class="op">,</span> <span class="st">'in'</span><span class="op">,</span> <span class="st">'on'</span><span class="op">,</span> <span class="st">'at'</span><span class="op">,</span> <span class="st">'to'</span><span class="op">,</span> <span class="st">'of'</span><span class="op">,</span></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a> <span class="st">'by'</span><span class="op">,</span> <span class="st">'with'</span><span class="op">,</span> <span class="st">'about'</span><span class="op">,</span> <span class="st">'above'</span><span class="op">,</span> <span class="st">'below'</span><span class="op">,</span> <span class="st">'over'</span><span class="op">,</span> <span class="st">'under'</span><span class="op">,</span> <span class="st">'above'</span><span class="op">,</span> <span class="st">'below'</span><span class="op">,</span> <span class="st">'from'</span><span class="op">,</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a> <span class="st">'as'</span><span class="op">,</span> <span class="st">'I'</span><span class="op">,</span> <span class="st">'you'</span><span class="op">,</span> <span class="st">'he'</span><span class="op">,</span> <span class="st">'she'</span><span class="op">,</span> <span class="st">'it'</span><span class="op">,</span> <span class="st">'we'</span><span class="op">,</span> <span class="st">'they'</span><span class="op">,</span> <span class="st">'me'</span><span class="op">,</span> <span class="st">'him'</span><span class="op">,</span> <span class="st">'her'</span><span class="op">,</span> <span class="st">'us'</span><span class="op">,</span> <span class="st">'them'</span><span class="op">,</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a> <span class="st">'my'</span><span class="op">,</span> <span class="st">'your'</span><span class="op">,</span> <span class="st">'his'</span><span class="op">,</span> <span class="st">'its'</span><span class="op">,</span> <span class="st">'our'</span><span class="op">,</span> <span class="st">'their'</span><span class="op">,</span> <span class="st">'mine'</span><span class="op">,</span> <span class="st">'yours'</span><span class="op">,</span> <span class="st">'hers'</span><span class="op">,</span> <span class="st">'ours'</span><span class="op">,</span> <span class="st">'theirs'</span><span class="op">,</span></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a> <span class="st">'this'</span><span class="op">,</span> <span class="st">'that'</span><span class="op">,</span> <span class="st">'these'</span><span class="op">,</span> <span class="st">'those'</span><span class="op">,</span> <span class="st">'is'</span><span class="op">,</span> <span class="st">'am'</span><span class="op">,</span> <span class="st">'are'</span><span class="op">,</span> <span class="st">'was'</span><span class="op">,</span> <span class="st">'were'</span><span class="op">,</span> <span class="st">'be'</span><span class="op">,</span> <span class="st">'being'</span><span class="op">,</span></span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a> <span class="st">'been'</span><span class="op">,</span> <span class="st">'have'</span><span class="op">,</span> <span class="st">'has'</span><span class="op">,</span> <span class="st">'had'</span><span class="op">,</span> <span class="st">'do'</span><span class="op">,</span> <span class="st">'does'</span><span class="op">,</span> <span class="st">'did'</span><span class="op">,</span> <span class="st">'will'</span><span class="op">,</span> <span class="st">'shall'</span><span class="op">,</span> <span class="st">'should'</span><span class="op">,</span> <span class="st">'would'</span><span class="op">,</span></span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a> <span class="st">'can'</span><span class="op">,</span> <span class="st">'could'</span><span class="op">,</span> <span class="st">'may'</span><span class="op">,</span> <span class="st">'might'</span><span class="op">,</span> <span class="st">'must'</span><span class="op">,</span> <span class="st">'shall'</span><span class="op">,</span> <span class="st">'should'</span><span class="op">,</span> <span class="st">'would'</span><span class="op">,</span> <span class="st">'cannot'</span><span class="op">,</span> <span class="st">'could not'</span><span class="op">,</span></span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a> <span class="st">'can</span><span class="sc">\'</span><span class="st">t'</span><span class="op">,</span> <span class="st">'couldn</span><span class="sc">\'</span><span class="st">t'</span><span class="op">,</span> <span class="st">'don</span><span class="sc">\'</span><span class="st">t'</span><span class="op">,</span> <span class="st">'didn</span><span class="sc">\'</span><span class="st">t'</span><span class="op">,</span> <span class="st">'won</span><span class="sc">\'</span><span class="st">t'</span><span class="op">,</span> <span class="st">'wouldn</span><span class="sc">\'</span><span class="st">t'</span><span class="op">,</span> <span class="st">'shouldn</span><span class="sc">\'</span><span class="st">t'</span><span class="op">,</span> <span class="st">'mustn</span><span class="sc">\'</span><span class="st">t'</span><span class="op">,</span></span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a> <span class="st">'let</span><span class="sc">\'</span><span class="st">s'</span><span class="op">,</span> <span class="st">'etc.'</span><span class="op">,</span> <span class="st">'-rrb-'</span><span class="op">,</span> <span class="st">'-lrb-'</span><span class="op">,</span> <span class="st">'--'</span><span class="op">,</span> <span class="st">'-'</span><span class="op">,</span> <span class="st">'a'</span><span class="op">,</span><span class="st">'b'</span><span class="op">,</span><span class="st">'c'</span><span class="op">,</span><span class="st">'d'</span><span class="op">,</span><span class="st">'e'</span><span class="op">,</span><span class="st">'f'</span><span class="op">,</span><span class="st">'g'</span><span class="op">,</span><span class="st">'h'</span><span class="op">,</span></span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a> <span class="st">'i'</span><span class="op">,</span><span class="st">'j'</span><span class="op">,</span><span class="st">'k'</span><span class="op">,</span><span class="st">'l'</span><span class="op">,</span><span class="st">'m'</span><span class="op">,</span><span class="st">'n'</span><span class="op">,</span><span class="st">'o'</span><span class="op">,</span><span class="st">'p'</span><span class="op">,</span><span class="st">'q'</span><span class="op">,</span><span class="st">'r'</span><span class="op">,</span><span class="st">'s'</span><span class="op">,</span><span class="st">'t'</span><span class="op">,</span><span class="st">'u'</span><span class="op">,</span><span class="st">'v'</span><span class="op">,</span><span class="st">'w'</span><span class="op">,</span><span class="st">'x'</span><span class="op">,</span><span class="st">'y'</span><span class="op">,</span><span class="st">'z'</span><span class="op">,</span><span class="st">"''"</span><span class="op">,</span><span class="st">"``"</span><span class="op">,</span><span class="st">"'s"</span><span class="op">,</span></span>
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true" tabindex="-1"></a> <span class="st">"..."</span></span>
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true" tabindex="-1"></a> ]<span class="op">;</span></span>
<span id="cb2-28"><a href="#cb2-28" aria-hidden="true" tabindex="-1"></a>punctuationMarks <span class="op">=</span> [<span class="st">"."</span><span class="op">,</span> <span class="st">","</span><span class="op">,</span> <span class="st">"!"</span><span class="op">,</span> <span class="st">"?"</span><span class="op">,</span><span class="st">";"</span><span class="op">,</span><span class="st">":"</span><span class="op">,</span><span class="st">"'"</span>]<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Creating a word cloud often involves filtering out common words, also known as stopwords, to emphasize the more unique or relevant words within a text.</p>
<p><strong>Interactivity</strong>: The component provides interactivity features such as downloading the word cloud as an image (PNG or SVG) or as CSV data.</p>
<p><strong>Summary:</strong> All in all, the Word Cloud widget provides a visually appealing and informative way to explore the most common words in a dataset or text corpus, facilitating quick insights into the underlying textual data.<br>
<br>
</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="images/word-cloud.png" class="img-fluid figure-img"></p>
</figure>
</div>
</section>
</section>
<section id="pie-chart" class="level3" data-number="4.2.2">
<h3 data-number="4.2.2" class="anchored" data-anchor-id="pie-chart"><span class="header-section-number">4.2.2</span> Pie Chart</h3>
<p>This pie chart widget, similar to the word cloud widget, serves to visualize data, but in this case, it focuses on the distribution of languages within a given dataset or workset (volumes of novels).</p>
<section id="internal-working-of-word-cloud-1" class="level4" data-number="4.2.2.1">
<h4 data-number="4.2.2.1" class="anchored" data-anchor-id="internal-working-of-word-cloud-1"><span class="header-section-number">4.2.2.1</span> Internal working of Word Cloud</h4>
<ul>
<li><p><strong>Data Fetching</strong>: Data is fetched from an external API endpoint using the fetch API. In this case, the API endpoint is <a href="https://tools.htrc.illinois.edu/ef-api/worksets/$%7BworksetId%7D/metadata" class="uri">https://tools.htrc.illinois.edu/ef-api/worksets/$%7BworksetId%7D/metadata</a>. The fetched data contains information about the languages present in the dataset.</p></li>
<li><p><strong>Data Processing</strong>: Upon receiving the data, it’s processed to count the occurrences of each language. The count of each language is stored in the languageCount state.</p></li>
</ul>
<div class="sourceCode" id="cb3"><pre class="sourceCode javascript code-with-copy"><code class="sourceCode javascript"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="kw">const</span> count <span class="op">=</span> {}<span class="op">;</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> data<span class="op">.</span><span class="at">data</span><span class="op">.</span><span class="fu">forEach</span>(item <span class="kw">=></span> {</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> language <span class="op">=</span> item<span class="op">.</span><span class="at">metadata</span><span class="op">.</span><span class="at">language</span><span class="op">;</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (language) {</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> count[language] <span class="op">=</span> (count[language] <span class="op">||</span> <span class="dv">0</span>) <span class="op">+</span> <span class="dv">1</span><span class="op">;</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> }</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<ul>
<li><strong>Rendering the Pie Chart</strong>: The LanguagePieChart component is responsible for rendering the pie chart. It receives the language count data as props. Using D3.js, it generates the pie chart based on this data.</li>
</ul>
<div class="sourceCode" id="cb4"><pre class="sourceCode javascript code-with-copy"><code class="sourceCode javascript"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="op"><</span>MainCard</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> content<span class="op">=</span>{<span class="kw">false</span>}</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> sx<span class="op">=</span>{{</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">padding</span><span class="op">:</span> theme<span class="op">.</span><span class="fu">spacing</span>(<span class="dv">8</span>)<span class="op">,</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="dt">display</span><span class="op">:</span> <span class="st">'flex'</span><span class="op">,</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="dt">flexDirection</span><span class="op">:</span> <span class="st">'column'</span><span class="op">,</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="dt">alignItems</span><span class="op">:</span> <span class="st">'center'</span><span class="op">,</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="dt">position</span><span class="op">:</span> <span class="st">'relative'</span><span class="op">,</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> <span class="dt">height</span><span class="op">:</span> <span class="st">'650px'</span><span class="op">,</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a> <span class="dt">width</span><span class="op">:</span> <span class="st">'600px'</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> }}<span class="op">></span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<ul>
<li><p><strong>Drawing the Chart</strong>: Inside the drawChart function, D3.js is used to create the SVG elements necessary for the pie chart. Each language is represented as a slice in the pie chart, with its size proportional to its count in the dataset.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode javascript code-with-copy"><code class="sourceCode javascript"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">drawChart</span>() {</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="co">// Remove the old svg</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> d3<span class="op">.</span><span class="fu">select</span>(<span class="st">'#language-pie-container'</span>)</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">select</span>(<span class="st">'svg'</span>)</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">remove</span>()<span class="op">;</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="co">// Create new svg</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> svg <span class="op">=</span> d3</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">select</span>(<span class="st">'#language-pie-container'</span>)</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">append</span>(<span class="st">'svg'</span>)</span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">attr</span>(<span class="st">'width'</span><span class="op">,</span> width)</span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">attr</span>(<span class="st">'height'</span><span class="op">,</span> height)</span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">append</span>(<span class="st">'g'</span>)</span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">attr</span>(<span class="st">'transform'</span><span class="op">,</span> <span class="vs">`translate(</span><span class="sc">${</span>width<span class="op">/</span><span class="dv">2</span><span class="sc">}</span><span class="vs">, </span><span class="sc">${</span>height<span class="op">/</span><span class="dv">2</span><span class="sc">}</span><span class="vs">)`</span>)<span class="op">;</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> arcGenerator <span class="op">=</span> d3</span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">arc</span>()</span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">innerRadius</span>(innerRadius)</span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">outerRadius</span>(outerRadius)<span class="op">;</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> pieGenerator <span class="op">=</span> d3</span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="at">pie</span><span class="op"><</span>{ <span class="dt">label</span><span class="op">:</span> string<span class="op">;</span> <span class="dt">value</span><span class="op">:</span> number }<span class="op">></span>() <span class="co">// Explicitly set the type here</span></span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">padAngle</span>(<span class="dv">0</span>)</span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">value</span>((d) <span class="kw">=></span> d<span class="op">.</span><span class="at">value</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
<li><p><strong>Color Encoding</strong>: D3’s color scale is used to assign colors to each slice of the pie chart. The interpolateCool color scheme is used here.</p></li>
<li><p><strong>Updating the Chart</strong>: The useEffect hook is utilized to update the chart whenever the language count data changes. This ensures that the chart reflects the latest data fetched from the API.</p></li>
</ul>
<div class="sourceCode" id="cb6"><pre class="sourceCode javascript code-with-copy"><code class="sourceCode javascript"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="kw">const</span> formattedData <span class="op">=</span> <span class="bu">Object</span><span class="op">.</span><span class="fu">entries</span>(data)<span class="op">.</span><span class="fu">map</span>(([language<span class="op">,</span> count]) <span class="kw">=></span> ({ <span class="dt">label</span><span class="op">:</span> language<span class="op">,</span> <span class="dt">value</span><span class="op">:</span> count }))<span class="op">;</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="kw">const</span> arc <span class="op">=</span> svg</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">selectAll</span>()</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">data</span>(<span class="fu">pieGenerator</span>(formattedData))</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">enter</span>()</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">append</span>(<span class="st">'path'</span>)</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">attr</span>(<span class="st">'d'</span><span class="op">,</span> (d<span class="op">:</span> any) <span class="kw">=></span> <span class="fu">arcGenerator</span>(d) <span class="im">as</span> string) <span class="co">// Explicitly cast to string</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">style</span>(<span class="st">'fill'</span><span class="op">,</span> (_<span class="op">,</span> i) <span class="kw">=></span> <span class="fu">colorScale</span>(i))</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">style</span>(<span class="st">'stroke'</span><span class="op">,</span> <span class="st">'#ffffff'</span>)</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">style</span>(<span class="st">'stroke-width'</span><span class="op">,</span> <span class="dv">0</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p><strong>Styling</strong>: The pie chart is styled to have a white stroke around each slice and white text labels, providing contrast against the colored slices.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode javascript code-with-copy"><code class="sourceCode javascript"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="kw">const</span> text <span class="op">=</span> svg</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">selectAll</span>()</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">data</span>(<span class="fu">pieGenerator</span>(formattedData))</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">enter</span>()</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">append</span>(<span class="st">'text'</span>)</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">attr</span>(<span class="st">'text-anchor'</span><span class="op">,</span> <span class="st">'middle'</span>)</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">attr</span>(<span class="st">'alignment-baseline'</span><span class="op">,</span> <span class="st">'middle'</span>)</span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">text</span>((d<span class="op">:</span> any) <span class="kw">=></span> d<span class="op">.</span><span class="at">data</span><span class="op">.</span><span class="at">label</span>)</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">style</span>(<span class="st">'fill'</span><span class="op">,</span> <span class="st">'white'</span>) <span class="co">// Set text color to white</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a> <span class="co">//.style('fill', (_, i) => colorScale(formattedData.length - i))</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">attr</span>(<span class="st">'transform'</span><span class="op">,</span> (d<span class="op">:</span> any) <span class="kw">=></span> {</span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> [x<span class="op">,</span> y] <span class="op">=</span> arcGenerator<span class="op">.</span><span class="fu">centroid</span>(d)<span class="op">;</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="vs">`translate(</span><span class="sc">${</span>x<span class="sc">}</span><span class="vs">, </span><span class="sc">${</span>y<span class="sc">}</span><span class="vs">)`</span><span class="op">;</span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a> })<span class="op">;</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p><strong>Summary:</strong> All in all, the pie chart widget provides a visual representation of the distribution of languages within a dataset, enabling users to quickly grasp the relative prevalence of different languages.<br>
<br>
</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="images/pie.png" class="img-fluid figure-img"></p>
</figure>
</div>
</section>
</section>
<section id="trends" class="level3" data-number="4.2.3">
<h3 data-number="4.2.3" class="anchored" data-anchor-id="trends"><span class="header-section-number">4.2.3</span> Trends</h3>
<p>You can make a <em>‘Volume Trends’</em> widget to analyze word frequency trends within a corpus of novels. Its functionality encompasses:</p>
<p><strong>Data Acquisition and Processing</strong>: Upon component initialization, the widget interacts with an API endpoint to retrieve volume data from a specified workset, typically a collection of novels. The received data is then processed to extract pertinent information, notably the frequency of words across the volumes.</p>
<p><strong>Interactive Search Capability</strong>: Users engage with the widget by inputting text either through typing or selecting from a dropdown menu. As characters are entered, the widget dynamically updates to reflect the frequency trends of words that match the entered criteria. This interactive search feature enhances user experience by facilitating rapid exploration of word frequency patterns.</p>
<p><strong>Wildcard Functionality</strong>: An additional feature provided by the widget is the ability to utilize wildcard characters. Specifically, users can employ a wildcard, such as an asterisk, to denote a partial word search. For instance, typing <em>c</em> would trigger a display of word frequency trends for all words starting with the letter <em>c</em> across the volume of novels. This wildcard functionality expands the scope of exploratory analysis, enabling users to uncover broader trends and patterns within the corpus.</p>
<p><strong>Chart Rendering with D3.js</strong>: The core of the widget’s visualization lies in its utilization of D3.js, a JavaScript library for creating dynamic, interactive data visualizations in web browsers. Through D3.js, the widget constructs a visually compelling representation of word frequency trends, employing elements such as scatter plots, bar charts, and connecting lines to convey insights effectively.</p>
<p><strong>Dynamic Data Updates</strong>: As users interact with the widget, whether through typing, selecting from the dropdown, or employing wildcard characters, the displayed chart updates in real-time to reflect the evolving word frequency trends. This dynamic nature ensures that users receive immediate feedback on their inputs, fostering a responsive and engaging user experience.</p>
<p><strong>Download Options</strong>: To facilitate further analysis or sharing of insights, the widget offers users the ability to download the chart as an image file (PNG or SVG) or export the underlying data as a CSV file. This functionality enhances the widget’s utility by enabling users to seamlessly integrate the generated visualizations and data into their workflows.</p>
<p><strong>Additional Features</strong>: Beyond its core functionality, the widget includes supplementary features such as tooltips, providing users with contextual information when interacting with data points on the chart. These features enhance the overall usability and informativeness of the widget, contributing to a richer and more insightful user experience.</p>
<p>Therefore, this widget can combine sophisticated data processing, interactive search capabilities, advanced visualization techniques, and user-friendly features to offer a powerful tool for exploring and analyzing word frequency trends within a corpus of novels. Its technical underpinnings, including D3.js integration and dynamic data updates, ensure robust functionality and usability for users engaged in text analysis and exploration.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="images/trends.png" class="img-fluid figure-img"></p>
</figure>
</div>
</section>
</section>
<section id="exploring-textual-data-with-notebooks" class="level2" data-number="4.3">
<h2 data-number="4.3" class="anchored" data-anchor-id="exploring-textual-data-with-notebooks"><span class="header-section-number">4.3</span> Exploring Textual Data with Notebooks</h2>
<ul>
<li><p><strong>Wordshift Graph</strong>: <a href="https://colab.research.google.com/drive/14O7zxt8J7rVMvDrTqJpxWD7cnkxXNzw1?usp=sharing" class="uri">https://colab.research.google.com/drive/14O7zxt8J7rVMvDrTqJpxWD7cnkxXNzw1?usp=sharing</a></p></li>
<li><p><strong>Exploring API</strong>: <a href="https://observablehq.com/@jswatsch/torchlite-ef-api" class="uri">https://observablehq.com/@jswatsch/torchlite-ef-api</a></p></li>
<li><p><strong>Word Cloud</strong>: <a href="https://observablehq.com/@jswatsch/torchlite-workset-word-cloud" class="uri">https://observablehq.com/@jswatsch/torchlite-workset-word-cloud</a></p></li>
<li><p><strong>Contributor Map</strong>: <a href="https://observablehq.com/d/e69a3c5185393caa" class="uri">https://observablehq.com/d/e69a3c5185393caa</a></p></li>
<li><p><strong>Exploring EF API</strong>: <a href="https://github.com/aarthishivkumar/HathiTrust-API/blob/main/htrcpractice1.ipynb" class="uri">https://github.com/aarthishivkumar/HathiTrust-API/blob/main/htrcpractice1.ipynb</a></p></li>
<li><p><strong>Summary Widget</strong>: <a href="https://github.com/htrc/torchlite-summary" class="uri">https://github.com/htrc/torchlite-summary</a></p></li>
<li><p><strong>Trends Standalone HTML Page</strong>: <a href="https://github.com/htrc/torchlite-trends" class="uri">https://github.com/htrc/torchlite-trends</a></p></li>
</ul>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="images/footer.png" class="img-fluid figure-img"></p>
</figure>
</div>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const clipboard = new window.ClipboardJS('.code-copy-button', {
text: function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="./worksets.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">3</span> <span class="chapter-title">Featured Worksets</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="./technical-background.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">5</span> <span class="chapter-title">Dashboard Technical Background</span></span> <i class="bi bi-arrow-right-short"></i>
</a>
</div>
</nav>
</div> <!-- /content -->
<footer class="footer">
<div class="nav-footer">
<div class="nav-footer-left"><span class="r2rsymbols-sym sym-33" style="font-size:20px!important;">©</span>2024 <a href="https://analytics.hathitrust.org/">HTRC</a></div>
<div class="nav-footer-center">
</div>
<div class="nav-footer-right">This Handbook was developed by <a href="https://manika-lamba.github.io/">Manika Lamba</a> in <a href="https://quarto.org/">Quarto</a>.</div>
</div>
</footer>
</body></html>