forked from esstherc/Neotoma-Visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1694 lines (1508 loc) · 82.1 KB
/
Copy pathindex.html
File metadata and controls
1694 lines (1508 loc) · 82.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Neotoma Taxonomy Visualizer</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/driver.js@1.3.5/dist/driver.css">
<link rel="stylesheet" href="index.css?v=20260723-issues-dropdown-only">
<link rel="stylesheet" href="src/onboarding/onboarding.css?v=20260713-figtree">
</head>
<body>
<div id="layout" style="display:flex; align-items:flex-start; gap:16px;">
<div id="canvas-column">
<div id="stage" style="position:relative;">
<div id="visualizerControlBox" class="visualizer-control-box" aria-label="Visualizer controls">
<button id="visualizerControlToggle" class="visualizer-control-toggle" type="button"
aria-label="Collapse visualizer controls" aria-expanded="true" data-tooltip="Collapse"
title="Collapse">-</button>
<div class="control-content">
<div class="control-row rotate-zoom-row">
<div class="rotate-control">
<label for="rotate">Rotate</label>
<input id="rotate" type="range" min="-180" max="180" value="0" step="1">
<span id="rotateValue">0°</span>
</div>
<div class="zoom-control">
<button id="zoomOut">-</button>
<button id="zoomIn">+</button>
<button id="zoomReset">reset</button>
<span id="zoomValue">1.0×</span>
<div id="viewSwitchGroup" class="view-switch-group">
<button id="wholeViewBtn" class="view-switch-btn active">Whole View</button>
<button id="focusViewBtn" class="view-switch-btn">Focus View</button>
</div>
</div>
</div>
</div>
</div>
<button class="submit-ticket-button" type="button" disabled
aria-label="Submit a ticket, coming soon" title="Ticket submission coming soon">
Submit a ticket
</button>
<div id="chart"></div>
<div id="color-legend" class="visualizer-legend" aria-label="Visualizer legend">
<button id="legendToggle" class="legend-toggle" type="button" aria-label="Collapse legend"
aria-expanded="true" data-tooltip="Collapse" title="Collapse">-</button>
<div class="legend-items">
<div class="legend-item">
<span class="legend-dot legend-node"></span>
<span>Node</span>
</div>
<div class="legend-item">
<span class="legend-dot legend-collapsible"></span>
<span>Collapsible group</span>
</div>
<div class="legend-item">
<span class="legend-line legend-search"></span>
<span>Search match</span>
</div>
<div class="legend-item">
<span class="legend-line legend-synonym"></span>
<span>Synonym match</span>
</div>
</div>
</div>
<div class="visualizer-layer-note">
<button class="layer-note-close" type="button" aria-label="Hide layer note">×</button>
<span>
This visualization has two layers: <strong>Major Groups</strong> shows the broad taxonomic
hierarchy down to Class level,<br>while selecting a <strong>Taxon Group</strong> from the dropdown
drills into finer detail down to species.
</span>
</div>
<div id="popup"
style="position:absolute; left:-9999px; top:-9999px; background:#fff; border:1px solid #ddd; box-shadow:0 4px 12px rgba(0,0,0,0.15); border-radius:6px; padding:10px 12px; max-width:320px; z-index:1000;">
</div>
</div>
</div>
<div id="right-panel" style="min-width:360px; display:flex; flex-direction:column; gap:8px;">
<div id="title-section">
<div id="viewNav" class="view-nav">
<button id="viewNavTrigger" class="view-nav-trigger" type="button" aria-haspopup="true"
aria-expanded="false" aria-label="Switch view">
<span class="view-nav-icon" aria-hidden="true"></span>
</button>
<div id="viewNavMenu" class="view-nav-menu" role="menu" aria-label="View modes">
<button class="view-nav-option active" type="button" role="menuitem" data-app-view="explorer">
Explorer View
</button>
<button class="view-nav-option" type="button" role="menuitem" data-app-view="steward">
Data Steward View
</button>
<button id="takeTourBtn" class="view-nav-option" type="button" role="menuitem">
Take Tour
</button>
<button class="view-nav-option" type="button" role="menuitem" data-app-view="about">
About
</button>
</div>
</div>
<h1>Neotoma Taxonomy Visualizer</h1>
</div>
<div id="sidebar">
<div id="controls">
<!-- First row: Taxon Type selector -->
<div class="control-row taxon-type-row">
<label class="taxon-type-label">Taxon Type:</label>
<div class="taxon-type-group">
<button id="bioTaxonBtn" class="taxon-type-btn active">Biological Taxon</button>
<button id="nonBioTaxonBtn" class="taxon-type-btn">Non-biological Taxon</button>
</div>
</div>
<!-- Second row: Taxon Group and Search -->
<div class="control-row taxon-group-search-row">
<div class="taxon-group-section">
<label for="taxagroupSelect">Taxon Group:</label>
<div class="custom-select-wrapper">
<select id="taxagroupSelect" style="display: none;">
<option value="">Loading...</option>
</select>
<div class="custom-select">
<button type="button" class="custom-select-trigger" aria-haspopup="listbox"
aria-expanded="false" aria-controls="taxagroupOptions">Loading...</button>
<div id="taxagroupOptions" class="custom-options" role="listbox" tabindex="-1"
aria-label="Taxon Group options"></div>
</div>
</div>
</div>
<div class="search-section">
<div class="search-field">
<input id="searchInput" type="text"
placeholder="Use ',' for comparing taxa">
<div class="search-field-actions">
<button id="clearSearchBtn" class="search-icon-btn search-clear-btn" type="button"
aria-label="Clear search" title="Clear search" hidden>×</button>
<span class="search-action-divider" aria-hidden="true"></span>
<button id="searchBtn" class="search-icon-btn" type="button"
aria-label="Search" title="Search">
<img src="assets/search.svg" alt="" aria-hidden="true">
</button>
</div>
</div>
</div>
</div>
</div>
<div id="info"></div>
<section id="steward-taxon-detail" hidden aria-live="polite"></section>
<div id="navigation" style="margin-top: 12px; display: none;">
<button id="backButton" style="
padding: 8px 16px;
background: linear-gradient(135deg, #43a047, #43a047);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: 600;
font-family: 'Figtree', sans-serif;
transition: all 0.2s ease;
" onmouseover="this.style.filter='brightness(1.1)'" onmouseout="this.style.filter='brightness(1)'">
← Go Back
</button>
</div>
<!-- Data Steward: resolved synonym relationships -->
<div id="synonym-bar" class="synonym-relationships-bar" style="display:none;"></div>
<div id="synonym-detail-panel" class="synonym-relationships-panel" style="display:none;"></div>
<!-- Data Steward review queue for potential taxonomy issues -->
<div id="anomaly-bar" class="taxonomic-issues-bar" style="display:none;"></div>
<div id="anomaly-detail-panel" class="taxonomic-issues-panel" style="display:none;"></div>
<div id="summary-panel"
style="display:none; margin-top:8px; padding:14px; background:#fff; border:1px solid #e5e7eb; border-radius:8px;">
</div>
</div>
<main id="about-panel" class="about-panel" aria-labelledby="about-title" hidden>
<section class="about-hero">
<div class="about-identity">
<img class="about-logo" src="assets/neotoma-logo.png" alt="Neotoma logo">
<div>
<h2 id="about-title">See the structure behind the names.</h2>
</div>
</div>
<p class="about-lede">The Neotoma Taxonomy Visualizer is a companion tool for exploring the taxonomic
vocabulary that connects Neotoma's paleoecological records. It turns taxon paths into an
interactive tree so researchers and data stewards can see relationships, navigate from broad
groups to specific taxa, and spot where a name sits in the hierarchy.</p>
<p class="about-citation">If you use this software, please provide the following citation:<br>
<span>Chen, Y., Nelson, J. K., J., Goring, S., Zhang, Q., Blois, S. J., & Williams, J. W.
(2026). Interactive Hierarchical Visualization for Exploring the Neotoma Paleoecological
Taxonomy. <a href="https://open.neotomadb.org/Taxonomy-Visualizer/" target="_blank"
rel="noopener noreferrer">https://open.neotomadb.org/Taxonomy-Visualizer/</a></span>
</p>
<a class="about-primary-link" href="https://www.neotomadb.org/" target="_blank"
rel="noopener noreferrer">Visit Neotoma Paleoecology Database <span aria-hidden="true">↗</span></a>
</section>
<section class="about-section about-neotoma" aria-labelledby="neotoma-title">
<div class="about-section-heading">
<p class="about-kicker">The data foundation</p>
<h3 id="neotoma-title">What is Neotoma?</h3>
</div>
<p>Neotoma is an open, community-curated database and service ecosystem for paleoecological and
paleoenvironmental data. It supports global-change research and education by making data,
tools, and stewardship resources available to the community.</p>
<p>This visualizer focuses on one shared layer: the taxonomy used to organize data. Use it to
understand a group, trace a scientific name through its ancestors, compare taxa, and move to
the relevant Neotoma resource with clearer context.</p>
</section>
<section class="about-section about-manual" aria-labelledby="manual-title">
<div class="about-section-heading">
<p class="about-kicker">Quick start</p>
<h3 id="manual-title">Taxonomy Visualizer User Manual</h3>
</div>
<div class="about-manual-grid">
<ol class="about-steps">
<li>
<span class="about-step-number">1</span>
<div><strong>Choose a taxon type and group.</strong><p>Start with Biological or
Non-biological Taxon, then select the group you want to explore.</p></div>
</li>
<li>
<span class="about-step-number">2</span>
<div><strong>Search for a name.</strong><p>Enter a taxon name to focus its path. Use
a comma to compare two taxa in the same view.</p></div>
</li>
<li>
<span class="about-step-number">3</span>
<div><strong>Explore the hierarchy.</strong><p>Select a node to inspect it, or expand
a collapsible group to reveal more of the taxonomy.</p></div>
</li>
<li>
<span class="about-step-number">4</span>
<div><strong>Recognize synonyms.</strong><p>Search results that come from a Neotoma
synonym record are highlighted in orange and point back to the accepted taxon.</p></div>
</li>
<li>
<span class="about-step-number">5</span>
<div><strong>Read taxon metadata.</strong><p>Select a node to open Search Results with
its path, metadata, synonyms, and available external links.</p></div>
</li>
<li>
<span class="about-step-number">6</span>
<div><strong>Compare two taxa.</strong><p>Enter two exact taxon names separated by a
comma, such as <code>cf. Bison latifrons, cf. Bison alaskensis</code>.</p></div>
</li>
</ol>
<figure class="about-guide-figure">
<img src="assets/taxonomy-visualizer-guide.svg"
alt="Illustration showing selection, search, and taxonomy-tree exploration in three steps">
<figcaption>Choose, search, then explore.</figcaption>
<button class="about-explorer-link" type="button" data-app-view="explorer">
Start exploring the taxonomy <span aria-hidden="true">→</span>
</button>
</figure>
</div>
</section>
<section class="about-section about-community" aria-labelledby="community-title">
<div class="about-community-banner">
<div class="about-community-heading">
<p class="about-kicker">Join Neotoma!</p>
<h3 id="community-title">Connect, contribute, and stay involved.</h3>
</div>
<div class="about-community-grid">
<a class="about-community-card" href="https://www.neotomadb.org/about/join-the-neotoma-community"
target="_blank" rel="noopener noreferrer">
<span class="about-community-card-title">Become a Member <span aria-hidden="true">↗</span></span>
<p>Play a role in database governance. Vote on initiatives and leadership, or serve on
subcommittees in topics of interest to you.</p>
</a>
<a class="about-community-card" href="https://www.neotomadb.org/data/contribute-data"
target="_blank" rel="noopener noreferrer">
<span class="about-community-card-title">Become a Data Steward <span aria-hidden="true">↗</span></span>
<p>Data Stewards are analogous to editors of peer-reviewed journals and can upload and
correct data in Neotoma.</p>
</a>
</div>
<div class="about-community-ecosystem">
<div class="about-community-link-group">
<p class="about-community-label">NeotomaDB</p>
<nav class="about-community-link-list" aria-label="NeotomaDB links">
<a href="https://www.neotomadb.org/about" target="_blank" rel="noopener noreferrer">Neotoma</a>
<a href="https://www.neotomadb.org/data" target="_blank" rel="noopener noreferrer">Data</a>
<a href="https://www.neotomadb.org/resources" target="_blank" rel="noopener noreferrer">Resources</a>
<a href="https://www.neotomadb.org/apps" target="_blank" rel="noopener noreferrer">Apps</a>
<a href="https://www.neotomadb.org/outreach" target="_blank" rel="noopener noreferrer">Outreach</a>
<a href="https://www.neotomadb.org/donate" target="_blank" rel="noopener noreferrer">Donate</a>
<a href="https://www.neotomadb.org/news-events/" target="_blank" rel="noopener noreferrer">News & Events</a>
<a href="https://www.neotomadb.org/people/" target="_blank" rel="noopener noreferrer">People</a>
</nav>
</div>
<div class="about-community-link-group">
<p class="about-community-label">Neotoma Apps</p>
<nav class="about-community-link-list" aria-label="Neotoma Apps links">
<a href="https://www.neotomadb.org/apps/explorer" target="_blank" rel="noopener noreferrer">Explorer</a>
<a href="https://www.neotomadb.org/apps/api" target="_blank" rel="noopener noreferrer">API</a>
<a href="https://www.neotomadb.org/apps/tilia" target="_blank" rel="noopener noreferrer">Tilia</a>
<a href="https://www.neotomadb.org/apps/neotoma-r" target="_blank" rel="noopener noreferrer">R package</a>
<a href="https://www.neotomadb.org/apps/third-party-apps" target="_blank" rel="noopener noreferrer">Third-Party Apps</a>
</nav>
</div>
<div class="about-community-link-group about-community-social-group">
<p class="about-community-label">Stay connected</p>
<div class="about-community-social-links">
<a href="https://join.slack.com/t/neotomadb/shared_invite/zt-cvsv53ep-wjGeCTkq7IhP6eUNA9NxYQ"
target="_blank" rel="noopener noreferrer"><img class="about-social-logo" src="assets/slack-logo.svg" alt="Slack logo">NeotomaDB Slack</a>
<a href="https://groups.google.com/d/forum/neotoma-updates" target="_blank"
rel="noopener noreferrer"><img class="about-social-logo" src="assets/google-groups-logo.png" alt="Google Groups logo">Neotoma Updates Listserve</a>
<a href="https://twitter.com/neotomadb" target="_blank" rel="noopener noreferrer"><img
class="about-social-logo" src="assets/twitter-logo.svg" alt="Twitter logo">Twitter @neotomadb</a>
</div>
</div>
</div>
<div class="about-funding">
<img class="about-funding-logo" src="assets/nsf-logo.png" alt="National Science Foundation logo">
<div>
<p class="about-funding-label">Funded by</p>
<p class="about-funding-copy"><strong>National Science Foundation,</strong> Directorate for
Geosciences, Division of Earth Sciences, EAR-1948229, 1948926, 2410961</p>
</div>
</div>
</div>
</section>
</main>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<script src="https://cdn.jsdelivr.net/npm/driver.js@1.3.5/dist/driver.js.iife.js"></script>
<script src="src/taxon-group-select.js"></script>
<script type="module" src="taxon_group_viz.js?v=20260622-node-clearance-3"></script>
<script type="module">
import {
getURLNavigationState,
getURLState,
initializeURLHistory,
pushURLState,
resetURLHistory,
updateURLState
} from './src/urlhash.js';
import { FORCE_LIST_TREE_GROUPS, EXPAND_ALL_COLLAPSIBLE, FOCUS_VIEW_GROUPS, getTreeViewSpacing, NON_BIO_GROUPS } from './src/taxaViewConfig.js?v=20260722-taxonomy-forest-1';
import { initViewSwitch, resetViewState, activateFocusView, setFocusViewRenderOptions } from './src/viewSwitch.js';
import { updateAnomalyBar } from './src/anomaly_bar.js?v=20260723-issues-dropdown-only';
import { buildSynonymRelationships, updateSynonymBar } from './src/synonym_bar.js?v=20260724-steward-surfaces-1';
import { updateSummaryPanel } from './src/summaryPanel.js';
import { initOnboarding } from './src/onboarding/onboarding.js?v=20260622-2';
import { resolveGroupAnomalyRows } from './src/groupAnomalyRows.js';
import { getSynonymInfo, initSynonyms, isInvalidId } from './src/synonyms.js';
import { expandCompactTaxonPaths } from './src/data.js';
import { resolveGroupTreeRows } from './src/groupTreeRows.js';
import { buildInitialTrees, initialTreeNodesToRows } from './src/initialView.js';
import { buildNavigationRows, sliceRowsFromNode } from './src/navigationRows.js';
import {
buildTaxonomyIndexes,
extractTaxaGroups,
filterRowsByGroup as filterRowsByGroupFromIndex,
getRootInfo as getRootInfoFromIndex,
getRowsContainingNode as getIndexedRowsContainingNode,
getRowsForGroup as getIndexedRowsForGroup,
} from './src/taxonomyIndex.js';
const APP_VIEWS = new Set(['explorer', 'about', 'steward']);
let currentAppView = 'explorer';
function resetToMajorGroupsOnReload() {
const navigationEntry = window.performance
?.getEntriesByType?.('navigation')
?.[0];
const isReload = navigationEntry?.type === 'reload'
|| window.performance?.navigation?.type === 1;
if (!isReload) return null;
// A browser reload starts a new app navigation session. Browser
// history entries cannot be deleted by a web page, so tag this
// session and refuse to restore entries from the previous one.
const resetEpoch = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
resetURLHistory({ treeDepth: 0, resetEpoch });
return resetEpoch;
}
const resetHistoryEpoch = resetToMajorGroupsOnReload();
function normalizeAppView(view) {
return APP_VIEWS.has(view) ? view : 'explorer';
}
function getInitialAppView() {
const params = new URLSearchParams(window.location.hash.substring(1));
return params.get('view');
}
function setAppView(view, skipUrlUpdate = false) {
const previousAppView = currentAppView;
currentAppView = normalizeAppView(view);
document.body.dataset.appView = currentAppView;
const aboutPanel = document.getElementById('about-panel');
if (aboutPanel) aboutPanel.hidden = currentAppView !== 'about';
const nav = document.getElementById('viewNav');
const trigger = document.getElementById('viewNavTrigger');
const options = document.querySelectorAll('.view-nav-option[data-app-view]');
options.forEach(option => {
const isActive = option.dataset.appView === currentAppView;
option.classList.toggle('active', isActive);
option.setAttribute('aria-current', isActive ? 'page' : 'false');
});
if (trigger) {
const labels = { explorer: 'Explorer View', about: 'About', steward: 'Data Steward View' };
const label = labels[currentAppView];
trigger.setAttribute('aria-label', `Current view: ${label}`);
trigger.setAttribute('aria-expanded', 'false');
trigger.title = `Current view: ${label}`;
}
if (nav) nav.classList.remove('open');
if (!skipUrlUpdate) {
pushURLState(
{ view: currentAppView === 'explorer' ? null : currentAppView },
{ treeDepth: currentTreeDepth }
);
}
if (previousAppView !== currentAppView) {
window.__refreshCurrentTaxonDetail?.();
}
}
function initViewNav() {
const nav = document.getElementById('viewNav');
const trigger = document.getElementById('viewNavTrigger');
if (!nav || !trigger) return;
trigger.addEventListener('click', (event) => {
event.stopPropagation();
const willOpen = !nav.classList.contains('open');
nav.classList.toggle('open', willOpen);
trigger.setAttribute('aria-expanded', String(willOpen));
});
document.querySelectorAll('.view-nav-option[data-app-view], .about-explorer-link[data-app-view]').forEach(option => {
option.addEventListener('click', (event) => {
event.stopPropagation();
setAppView(option.dataset.appView);
});
});
const closeNavMenu = () => {
nav.classList.remove('open');
trigger.setAttribute('aria-expanded', 'false');
};
nav.addEventListener('mouseleave', closeNavMenu);
nav.addEventListener('keydown', (event) => {
if (event.key === 'Escape') closeNavMenu();
});
document.addEventListener('click', (event) => {
if (!nav.contains(event.target)) {
closeNavMenu();
}
});
}
function initDraggableVisualizerControls() {
const stage = document.getElementById('stage');
const box = document.getElementById('visualizerControlBox');
if (!stage || !box) return;
const interactiveSelector = 'button, input, select, textarea, a, [role="button"]';
let dragState = null;
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
const clampBoxToStage = () => {
const maxLeft = Math.max(0, stage.clientWidth - box.offsetWidth - 8);
const maxTop = Math.max(0, stage.clientHeight - box.offsetHeight - 8);
const currentLeft = Number.parseFloat(box.style.left || '16');
const currentTop = Number.parseFloat(box.style.top || '16');
box.style.left = `${clamp(currentLeft, 8, maxLeft)}px`;
box.style.top = `${clamp(currentTop, 8, maxTop)}px`;
};
const moveBox = (clientX, clientY) => {
if (!dragState) return;
const stageRect = stage.getBoundingClientRect();
const nextLeft = clientX - stageRect.left - dragState.offsetX;
const nextTop = clientY - stageRect.top - dragState.offsetY;
const maxLeft = Math.max(0, stage.clientWidth - box.offsetWidth - 8);
const maxTop = Math.max(0, stage.clientHeight - box.offsetHeight - 8);
box.style.left = `${clamp(nextLeft, 8, maxLeft)}px`;
box.style.top = `${clamp(nextTop, 8, maxTop)}px`;
box.style.right = 'auto';
box.style.bottom = 'auto';
};
box.addEventListener('pointerdown', (event) => {
if (event.button !== 0 || event.target.closest(interactiveSelector)) return;
const boxRect = box.getBoundingClientRect();
dragState = {
offsetX: event.clientX - boxRect.left,
offsetY: event.clientY - boxRect.top,
};
box.classList.add('is-dragging');
box.setPointerCapture(event.pointerId);
event.preventDefault();
});
box.addEventListener('pointermove', (event) => {
if (!dragState) return;
moveBox(event.clientX, event.clientY);
});
const stopDragging = (event) => {
if (!dragState) return;
dragState = null;
box.classList.remove('is-dragging');
if (box.hasPointerCapture(event.pointerId)) {
box.releasePointerCapture(event.pointerId);
}
};
box.addEventListener('pointerup', stopDragging);
box.addEventListener('pointercancel', stopDragging);
window.addEventListener('resize', clampBoxToStage);
}
function initCollapsibleLegend() {
const legend = document.getElementById('color-legend');
const toggle = document.getElementById('legendToggle');
if (!legend || !toggle) return;
toggle.addEventListener('click', () => {
const isCollapsed = legend.classList.toggle('is-collapsed');
toggle.textContent = isCollapsed ? '+' : '-';
toggle.setAttribute('aria-label', isCollapsed ? 'Expand legend' : 'Collapse legend');
toggle.setAttribute('aria-expanded', String(!isCollapsed));
toggle.dataset.tooltip = isCollapsed ? 'Expand' : 'Collapse';
toggle.title = isCollapsed ? 'Expand' : 'Collapse';
});
}
function initCollapsibleVisualizerControls() {
const box = document.getElementById('visualizerControlBox');
const toggle = document.getElementById('visualizerControlToggle');
if (!box || !toggle) return;
const positionToggle = () => {
const rotateValue = document.getElementById('rotateValue');
if (!rotateValue || box.classList.contains('is-collapsed')) return;
const boxRect = box.getBoundingClientRect();
const valueRect = rotateValue.getBoundingClientRect();
const left = valueRect.right - boxRect.left + 14;
const top = valueRect.top - boxRect.top + (valueRect.height - toggle.offsetHeight) / 2 - 3;
toggle.style.left = `${left}px`;
toggle.style.top = `${top}px`;
toggle.style.right = 'auto';
};
toggle.addEventListener('click', () => {
const isCollapsed = box.classList.toggle('is-collapsed');
toggle.textContent = isCollapsed ? '+' : '-';
toggle.setAttribute(
'aria-label',
isCollapsed ? 'Expand visualizer controls' : 'Collapse visualizer controls'
);
toggle.setAttribute('aria-expanded', String(!isCollapsed));
toggle.dataset.tooltip = isCollapsed ? 'Expand' : 'Collapse';
toggle.title = isCollapsed ? 'Expand' : 'Collapse';
if (!isCollapsed) requestAnimationFrame(positionToggle);
});
document.getElementById('rotate')?.addEventListener('input', positionToggle);
window.addEventListener('resize', positionToggle);
requestAnimationFrame(positionToggle);
}
function initLayerNoteClose() {
const note = document.querySelector('.visualizer-layer-note');
const closeButton = document.querySelector('.layer-note-close');
if (!note || !closeButton) return;
closeButton.addEventListener('click', () => {
note.style.display = 'none';
});
}
initViewNav();
initDraggableVisualizerControls();
initCollapsibleLegend();
initCollapsibleVisualizerControls();
initLayerNoteClose();
initOnboarding();
setAppView(getInitialAppView(), true);
function getRowsForGroup(taxagroupid) {
return getIndexedRowsForGroup(taxonomyIndexes, taxagroupid);
}
function getRowsContainingNode(nodeId) {
return getIndexedRowsContainingNode(taxonomyIndexes, nodeId);
}
// Filter rows by taxagroupid and find appropriate root
function filterRowsByGroup(rows, taxagroupid) {
return filterRowsByGroupFromIndex(taxonomyIndexes, taxagroupid, anchorDataMap);
}
// Get root info for a taxagroupid
function getRootInfo(rows, taxagroupid) {
return getRootInfoFromIndex(taxonomyIndexes, taxagroupid, anchorDataMap);
}
let allRows = [];
let taxonomyIndexes = buildTaxonomyIndexes([]);
let currentTaxagroupid = null; // Start with null for initial view
let navigationStack = []; // Stack to track navigation history
let currentTreeDepth = 0; // Tree-only depth used by the in-page Back button
let historyRestoreQueue = Promise.resolve();
let isInitialView = true; // Track if we're in the initial 4-level view
let isSyncingDropdown = false; // Flag to prevent recursive calls when syncing dropdown
let taxagroupNames = {}; // Store taxagroupid to full name mapping
let anchorDataMap = new Map(); // Store taxagroupid to anchor info mapping
let anchorIds = new Set(); // Store all anchor node IDs for styling
let taxonomyChangeSummary = null; // Steward-facing summary data
// Groups with no unique real taxonomic anchor — use a synthetic root node.
// sliceAfterName: find this name in the path; keep everything AFTER it.
// The synthetic root ID/name is prepended at position 0.
const SYNTHETIC_GROUP_ROOTS = {
// overviewDepth: how many path levels to show in the initial overview
// (replaces the default 4-level cutoff so anchor-equivalent nodes appear)
BRY: { rootId: -2001, rootName: 'Bryophytes', sliceAfterName: 'Embryophyta', overviewDepth: 6 },
PLA: { rootId: -2002, rootName: 'Plants undiff.', sliceAfterName: 'Plantae', overviewDepth: 4 },
// VPL is massive and has a long unbranched stem from Eukaryota -> Plantae -> Viridiplantae -> Streptophyta -> Embryophyta.
// Slicing after Embryophyta replaces all these intermediate layers with a clean "Vascular plants" synthetic root directly connected to Tracheophyta.
VPL: { rootId: -2003, rootName: 'Vascular plants', sliceAfterName: 'Embryophyta', overviewDepth: 6 },
};
const GROUP_OVERVIEW_CONFIG = {
// Acritarchs is an operational group whose recorded paths form a
// forest. Render its Acritarcha and Eukaryota roots independently;
// never invent a taxonomic relationship between them.
ACR: {
overviewDepth: 4,
forest: true,
layoutContainerId: '__layout_container_acr__',
},
INS: { overviewDepth: 2, rootId: 0, rootName: 'Root', hideSingletonRootChildren: true },
};
// Current taxon type selection: 'bio' or 'nonbio'
let currentTaxonType = 'bio';
// Group/type changes start a fresh search context. Clear the visible
// input as well as the existing search listeners' result state before
// the next tree render reads the current query.
function clearSearchForContextChange() {
const searchInput = document.getElementById('searchInput');
if (!searchInput || !searchInput.value) return;
searchInput.value = '';
searchInput.dispatchEvent(new Event('input', { bubbles: true }));
}
// Populate the taxon group dropdown filtered by taxon type
function populateTaxonGroupDropdown(allTaxaGroupsList) {
const select = document.getElementById('taxagroupSelect');
select.innerHTML = '';
// Add "Major Groups" as the first option
const majorGroupsOption = document.createElement('option');
majorGroupsOption.value = '';
majorGroupsOption.textContent = 'Major Groups';
select.appendChild(majorGroupsOption);
// Filter groups based on selected taxon type
const filtered = allTaxaGroupsList.filter(group => {
if (currentTaxonType === 'nonbio') return NON_BIO_GROUPS.has(group);
return !NON_BIO_GROUPS.has(group);
});
filtered.forEach(group => {
const option = document.createElement('option');
option.value = group;
option.textContent = taxagroupNames[group] || group;
select.appendChild(option);
});
// Reset to Major Groups
select.value = '';
}
// Load compact ID paths and name dictionaries in parallel.
let allTaxaGroupsList = [];
let pendingViewLoad = Promise.resolve();
Promise.all([
fetch("data/taxon_paths_ids.json").then(r => r.json()),
fetch("data/taxon_names.json").then(r => r.json()),
fetch("data/taxagroup_names.json").then(r => r.json()).catch(() => ({})),
fetch("data/anchor_analysis.json").then(r => r.json()).catch(() => ([])),
fetch("data/taxa_changes.json", { cache: "no-store" }).then(r => r.json()).catch(() => null)
])
.then(([taxonData, taxonNames, namesMap, anchors, changeSummary]) => {
taxagroupNames = namesMap;
taxonomyChangeSummary = changeSummary;
// Convert list of anchors to a map for easy lookup
anchorDataMap = new Map(anchors.map(a => [a.taxagroupid, a]));
// Extract all anchor IDs into a set for styling
anchorIds = new Set(anchors.map(a => parseInt(a.anchorId)));
// Merge real anchors for groups not in anchor_analysis.json
const BUILTIN_ANCHORS = {
VPL: { anchorName: 'Tracheophyta', anchorId: 9534 },
DIN: { anchorName: 'Miozoa', anchorId: 32187 },
AVE: { anchorName: 'Aves', anchorId: 5856 },
DIA: { anchorName: 'Bacillariophyta', anchorId: 5396 },
OST: { anchorName: 'Ostracoda', anchorId: 13914 },
};
Object.entries(BUILTIN_ANCHORS).forEach(([id, entry]) => {
if (!anchorDataMap.has(id)) {
anchorDataMap.set(id, { taxagroupid: id, ...entry });
anchorIds.add(entry.anchorId);
}
});
allRows = expandCompactTaxonPaths(taxonData, taxonNames);
taxonomyIndexes = buildTaxonomyIndexes(allRows);
updateSummaryPanel(taxonomyChangeSummary, currentTaxagroupid, taxagroupNames);
allTaxaGroupsList = extractTaxaGroups(allRows);
// Read URL State
const urlState = getURLState();
const initialTreeDepth = Number(getURLNavigationState()?.treeDepth) || 0;
currentTreeDepth = initialTreeDepth;
window.__initialUrlState = urlState; // Store globally for post-render hooks
// Restore Taxon Type
const bioBtn = document.getElementById('bioTaxonBtn');
const nonBioBtn = document.getElementById('nonBioTaxonBtn');
if (urlState.type === 'nonbio') {
currentTaxonType = 'nonbio';
bioBtn.classList.remove('active');
nonBioBtn.classList.add('active');
} else if (urlState.type === 'bio') {
currentTaxonType = 'bio';
bioBtn.classList.add('active');
nonBioBtn.classList.remove('active');
}
populateTaxonGroupDropdown(allTaxaGroupsList);
// Restore Rotation Slider UI immediately (will be applied by viz)
if (urlState.rot) {
const rotInput = document.getElementById('rotate');
if (rotInput) rotInput.value = urlState.rot;
}
// Restore Search Box UI immediately
if (urlState.q) {
const searchInput = document.getElementById('searchInput');
if (searchInput) searchInput.value = urlState.q;
}
// Restore Group View vs Initial View
if (urlState.group) {
const select = document.getElementById('taxagroupSelect');
if (select) select.value = urlState.group;
pendingViewLoad = loadTreeForGroup(urlState.group, false).then(async () => {
await restoreTreeRoot(urlState, initialTreeDepth);
currentTreeDepth = initialTreeDepth;
updateBackButton();
applyPostRenderState(urlState);
initializeURLHistory({ treeDepth: initialTreeDepth });
});
} else {
// Load initial 4-level view
pendingViewLoad = loadInitialView().then(() => {
applyPostRenderState(urlState);
initializeURLHistory({ treeDepth: 0 });
});
}
// Helper to apply search, focus, and mode after the tree finishes rendering
function applyPostRenderState(state) {
if (!state) return;
// Fire search if query exists
if (state.q) {
const searchBtn = document.getElementById('searchBtn');
if (searchBtn) {
window.__suppressSearchHistory = true;
try {
searchBtn.click();
} finally {
window.__suppressSearchHistory = false;
}
}
}
// Dispatch focus event for the viz module to pick up
if (state.focus && !state.q) {
window.dispatchEvent(new CustomEvent('RestoreFocusNode', { detail: { id: state.focus } }));
}
// Apply Focus View mode
if (state.mode === 'focus') {
setTimeout(() => {
const focusBtn = document.getElementById('focusViewBtn');
if (focusBtn) {
window.__suppressViewHistory = true;
try {
focusBtn.click();
} finally {
window.__suppressViewHistory = false;
}
}
}, 600); // Wait for animations to settle
}
window.__initialUrlState = null; // Clear so it only runs once
}
function switchTaxonType(type) {
if (type === currentTaxonType) return;
currentTaxonType = type;
clearSearchForContextChange();
// Update button active states
bioBtn.classList.toggle('active', type === 'bio');
nonBioBtn.classList.toggle('active', type === 'nonbio');
// Update URL hash
pushURLState(
{ type: type, group: null, root: null, focus: null, q: null },
{ treeDepth: 0 }
);
// Re-populate dropdown and reset view state
currentTaxagroupid = null;
isInitialView = true;
navigationStack = [];
currentTreeDepth = 0;
currentTreeType = 'main';
mainTreeNodes = [];
orphanTreeNodes = [];
populateTaxonGroupDropdown(allTaxaGroupsList);
updateBackButton();
pendingViewLoad = loadInitialView();
}
bioBtn.addEventListener('click', () => switchTaxonType('bio'));
nonBioBtn.addEventListener('click', () => switchTaxonType('nonbio'));
// Handle dropdown change
const select = document.getElementById('taxagroupSelect');
select.addEventListener('change', (e) => {
// Skip if we're programmatically syncing the dropdown
if (isSyncingDropdown) {
return;
}
const selectedValue = e.target.value;
clearSearchForContextChange();
// Update URL hash state
pushURLState(
{ group: selectedValue, root: null, focus: null, q: null },
{ treeDepth: 0 }
);
if (selectedValue === '') {
// "Major Groups" selected - show initial view
currentTaxagroupid = null;
isInitialView = true;
navigationStack = [];
currentTreeDepth = 0;
currentTreeType = 'main';
// Show tree toggle for Major Groups view
const toggleDiv = document.getElementById('treeViewToggle');
if (toggleDiv) {
toggleDiv.style.display = 'block';
toggleDiv.style.visibility = 'visible';
}
updateBackButton();
pendingViewLoad = loadInitialView();
} else {
// Specific taxon group selected
currentTaxagroupid = selectedValue;
isInitialView = false;
navigationStack = [];
currentTreeDepth = 0;
currentTreeType = 'main';
// Hide tree toggle when selecting a specific group
const toggleDiv = document.getElementById('treeViewToggle');
if (toggleDiv) {
toggleDiv.style.display = 'none';
}
updateBackButton();
pendingViewLoad = loadTreeForGroup(currentTaxagroupid, false);
}
});
historyRestoreQueue = pendingViewLoad;
setupNativeHistoryNavigation();
})
.catch(err => console.error('Failed to load data files', err));
// Store both trees
let mainTreeNodes = [];
let orphanTreeNodes = [];
let currentTreeType = 'main'; // 'main' or 'orphan'
// Load initial 4-level view
async function loadInitialView(treeType = 'main') {
isInitialView = true;
currentTaxagroupid = null;
navigationStack = [];
currentTreeDepth = 0;
currentRootId = null;
currentRootName = null;
updateBackButton();
syncDropdownValue();
currentTreeType = treeType;
updateSummaryPanel(taxonomyChangeSummary, currentTaxagroupid, taxagroupNames);
// Anomaly bar is per-group; hide it in the all-groups overview
const _anomBar = document.getElementById('anomaly-bar');
const _anomDetail = document.getElementById('anomaly-detail-panel');
const _synonymBar = document.getElementById('synonym-bar');
const _synonymDetail = document.getElementById('synonym-detail-panel');
if (_anomBar) _anomBar.style.display = 'none';
if (_anomDetail) _anomDetail.style.display = 'none';
if (_synonymBar) _synonymBar.style.display = 'none';
if (_synonymDetail) _synonymDetail.style.display = 'none';
// Special initial view for non-biological taxon
if (currentTaxonType === 'nonbio') {
const { renderNonBioInitView } = await import('./src/non_bio_init_view.js');
const select = document.getElementById('taxagroupSelect');
await renderNonBioInitView(select.options);
return;
}
// Build trees if not already built
if (mainTreeNodes.length === 0 && orphanTreeNodes.length === 0) {
const trees = buildInitialTrees(allRows, {
currentTaxonType,
nonBioGroups: NON_BIO_GROUPS,
anchorDataMap,
anchorIds,
syntheticGroupRoots: SYNTHETIC_GROUP_ROOTS
});
mainTreeNodes = trees.mainTree;
orphanTreeNodes = trees.orphanTree;
console.log('Built trees:', {
mainTreeCount: mainTreeNodes.length,
orphanTreeCount: orphanTreeNodes.length,
mainTreeSample: mainTreeNodes.slice(0, 2),
orphanTreeSample: orphanTreeNodes.slice(0, 2)
});
}
// Select which tree to show
const rootNodes = treeType === 'main' ? mainTreeNodes : orphanTreeNodes;
// Convert to rows format for rendering
const rows = initialTreeNodesToRows(rootNodes);
// Clear previous chart
d3.select('#chart').selectAll('*').remove();
resetViewState();
// Determine root ID and name based on tree type
let rootId, rootName;
let nodesToRender = rootNodes;
if (treeType === 'orphan') {
// For orphan tree, always use a synthetic root
// Structure will be: Root -> taxagroupid -> orphan nodes