Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
459 lines (427 loc) · 28.1 KB
/
Copy pathindex.html
File metadata and controls
459 lines (427 loc) · 28.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Keys to Soil Taxonomy</title>
<script>
// FOUC prevention: apply correct theme before first paint
(function() {
var ALL = ['dark', 'green', 'sepia', 'high-contrast'];
var t = localStorage.getItem('dst-theme');
ALL.forEach(function(c) { document.documentElement.classList.remove(c); });
if (t === 'dark' || t === 'green' || t === 'sepia' || t === 'high-contrast') {
document.documentElement.classList.add(t);
} else if (!t || t === 'auto') {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.classList.add('dark');
}
}
})();
</script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container" x-data="app()" x-init="init()">
<aside class="sidebar" :class="{ collapsed: sidebarCollapsed }">
<div class="sidebar-title">Digital Keys to<br>Soil Taxonomy</div>
<div class="sidebar-controls" style="display: flex; gap: 6px; align-items: center; justify-content: center; margin-bottom: 15px;">
<button class="icon-btn" @click="currentTab = 'classify'" :title="currentTab === 'classify' ? 'Classify (active)' : 'Back to Classify'">⌂</button>
<button class="icon-btn" @click="reset()" title="Reset all selections">⟳</button>
<button class="icon-btn" @click="showSatisfiedCriteria = !showSatisfiedCriteria" :title="showSatisfiedCriteria ? 'Hide satisfied criteria' : 'Show satisfied criteria'">
<span x-text="showSatisfiedCriteria ? '⊙' : '⊘'"></span>
</button>
<button class="icon-btn" @click="cycleTheme()" :title="'Theme: ' + themeLabel">
<span x-text="themeIcon"></span>
</button>
<button class="icon-btn" @click="currentTab = 'about'" :title="currentTab === 'about' ? 'About (active)' : 'About this app'">ℹ</button>
<button class="icon-btn" @click="sidebarCollapsed = !sidebarCollapsed" :title="sidebarCollapsed ? 'Expand sidebar' : 'Collapse sidebar'">
<span x-text="sidebarCollapsed ? '▶' : '◀'"></span>
</button>
</div>
<!-- Current classification result -->
<template x-if="getClassificationPath().length > 0">
<div class="current-classification">
<div class="result-label">Classification</div>
<div class="result-name" x-text="getCurrentClassification()"></div>
<div class="result-level" x-text="getClassificationLevel()"></div>
</div>
</template>
<!-- Taxonomy hierarchy path -->
<div class="classification-path">
<div class="info-header">Taxonomy Path</div>
<template x-if="getClassificationPath().length === 0">
<p class="hint-text">Select criteria to begin classification</p>
</template>
<template x-for="(step, idx) in getClassificationPath()" :key="step.levelName + idx">
<div class="classification-step" :class="step.satisfied ? 'satisfied' : 'pending'">
<div class="step-level" x-text="step.levelName"></div>
<span class="step-name" x-text="step.name"></span>
<span class="step-code" x-text="step.code"></span>
</div>
</template>
</div>
<!-- Selected criteria detail -->
<div class="selected-criteria-section">
<div class="info-header">Selected Criteria</div>
<template x-if="getCheckedCriteriaForSidebar().length === 0">
<p class="hint-text">No criteria checked yet</p>
</template>
<template x-for="criterion in getCheckedCriteriaForSidebar()" :key="getCriterionId(criterion)">
<div class="selected-criterion" @click="removeFromPath(getCriterionId(criterion))">
<strong x-text="criterion.clause_id"></strong>
<span class="remove-icon">×</span>
</div>
</template>
</div>
</aside>
<div class="main">
<header>
<p x-show="currentTab === 'classify' && !findCurrentLevel()">Check criteria to classify your soil</p>
<div class="breadcrumb" x-show="currentTab === 'classify' && findCurrentLevel()" x-text="getClassificationBreadcrumb()"></div>
</header>
<!-- About Tab -->
<div class="about-panel" x-show="currentTab === 'about'">
<div class="about-section">
<h2>About This Application</h2>
<p>Digital Keys to Soil Taxonomy is an interactive, offline-first Progressive Web App for USDA soil classification following the <a href="https://www.nrcs.usda.gov/resources/guides-and-instructions/keys-to-soil-taxonomy" target="_blank" rel="noopener">Keys to Soil Taxonomy (13th Edition, 2022)</a>.</p>
<p>The application guides you through the official USDA dichotomous key by progressively revealing classification criteria. Check the criteria that match your soil properties, and the app determines the taxonomic classification: Order → Suborder → Great Group → Subgroup.</p>
<p>No internet connection is required after the first visit. The entire application — code, data, and glossary — is cached locally by the Service Worker.</p>
</div>
<div class="about-section">
<h2>Data Summary</h2>
<p x-show="engine">This dataset includes <strong x-text="taxonomyStats.criteria"></strong> decision criteria organized across the USDA soil taxonomy hierarchy:</p>
<ul x-show="engine" style="margin: 10px 0 10px 20px;">
<li><strong x-text="taxonomyStats.orders + ' Orders'"></strong></li>
<li><strong x-text="taxonomyStats.suborders + ' Suborders'"></strong></li>
<li><strong x-text="taxonomyStats.greatGroups + ' Great Groups'"></strong></li>
<li><strong x-text="taxonomyStats.subgroups + ' Subgroups'"></strong></li>
</ul>
<p x-show="engine">The glossary includes <strong x-text="engine ? Object.keys(engine.glossary).length : '—'"></strong> soil taxonomy terms — diagnostic quantities, features, properties, and related concepts used in the taxonomic system.</p>
</div>
<div class="about-section">
<h2>JSON Data Schema <span class="version-badge">v1.0.0</span></h2>
<p>The application is powered by <code>data/dst-data.json</code>, a ~3.5 MB file generated from USDA source data. The file contains five top-level sections:</p>
<table class="about-table">
<thead><tr><th>Section</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>navigation.criteria</code></td><td>Array of decision criteria with clause hierarchy, AND/OR logic, and pre-linkified glossary terms</td></tr>
<tr><td><code>outcomes</code></td><td>Object keyed by taxonomic code — each is a classification result (depth -1)</td></tr>
<tr><td><code>glossary</code></td><td>Object keyed by term ID — soil science terms with definitions</td></tr>
<tr><td><code>order_names</code></td><td>Single-letter code → Order name (e.g., A → Gelisols)</td></tr>
<tr><td><code>code_names</code></td><td>Full code → taxon name at all levels (e.g., AA → Histels)</td></tr>
</tbody>
</table>
<h3>Criterion Fields</h3>
<table class="about-table">
<thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>crit</code></td><td>string</td><td>Hierarchical code (A–L Orders, AA–LL Suborders, AAA+ deeper)</td></tr>
<tr><td><code>clause</code></td><td>number</td><td>Numeric clause ID within the group</td></tr>
<tr><td><code>parent_clause</code></td><td>number|""</td><td>Parent clause reference (empty for roots)</td></tr>
<tr><td><code>logic</code></td><td>string</td><td><code>OR</code> or <code>AND</code> — how this node's children relate</td></tr>
<tr><td><code>depth</code></td><td>number</td><td>0=Order, 1=Suborder, 2=Great Group, 3=Subgroup</td></tr>
<tr><td><code>content</code></td><td>string</td><td>Plain text criterion description</td></tr>
<tr><td><code>content_html</code></td><td>string</td><td>Content with glossary terms pre-linkified</td></tr>
</tbody>
</table>
</div>
<div class="about-section">
<h2>DSTCore Engine</h2>
<p><code>scripts/dst-core.js</code> is a standalone, framework-agnostic logic engine with no DOM dependencies. It works identically in the browser (<code>window.DSTCore</code>) and Node.js (<code>require()</code>).</p>
<h3>Satisfaction Algorithm</h3>
<p>Each parent criterion's <code>logic</code> field determines how its children are evaluated:</p>
<ul>
<li><strong>AND</strong> — ALL children must be satisfied</li>
<li><strong>OR</strong> — at least ONE child must be satisfied</li>
<li><strong>Leaf nodes</strong> (no children) — satisfied when checked by the user</li>
</ul>
<p>Evaluation is recursive with per-mutation cache invalidation.</p>
<h3>Key API Methods</h3>
<table class="about-table">
<thead><tr><th>Method</th><th>Returns</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>DSTCore.create(data)</code></td><td>engine</td><td>Create engine instance from parsed JSON</td></tr>
<tr><td><code>engine.check(id)</code></td><td>—</td><td>Check a criterion (auto-invalidates caches)</td></tr>
<tr><td><code>engine.toggle(id)</code></td><td>—</td><td>Toggle check state</td></tr>
<tr><td><code>engine.reset()</code></td><td>—</td><td>Clear all checks</td></tr>
<tr><td><code>engine.isClauseSatisfied(c)</code></td><td>boolean</td><td>Recursive satisfaction check (cached)</td></tr>
<tr><td><code>engine.isGroupSatisfied(code)</code></td><td>boolean</td><td>Is an entire taxonomic group satisfied?</td></tr>
<tr><td><code>engine.getVisibleGroups()</code></td><td>array</td><td>Groups to display at current level</td></tr>
<tr><td><code>engine.getClassificationPath()</code></td><td>array</td><td>Current taxonomy path (Order → Subgroup)</td></tr>
<tr><td><code>engine.getCurrentClassification()</code></td><td>string</td><td>Name of deepest satisfied taxon</td></tr>
<tr><td><code>engine.onChange(fn)</code></td><td>unsubscribe</td><td>Register state change listener</td></tr>
</tbody>
</table>
</div>
<div class="about-section">
<h2>Technology Stack</h2>
<p><strong>Frontend:</strong> Alpine.js v3.13.3 (loaded via CDN), CSS with custom properties for light/dark theming</p>
<p><strong>Engine:</strong> Standalone JavaScript logic engine (<code>scripts/dst-core.js</code>) with no dependencies. Works identically in browser and Node.js.</p>
<p><strong>Data:</strong> Python preprocessing pipeline generates optimized JSON from USDA source files. Service Worker enables offline-first caching.</p>
<p><strong>Testing:</strong> Custom test harness with Node.js and browser execution modes.</p>
</div>
<div class="about-section">
<h2>Resources</h2>
<ul>
<li><a href="https://github.com/ncss-tech/SoilKnowledgeBase" target="_blank" rel="noopener">Soil Knowledge Base</a> — Official NCSS taxonomy data repository</li>
<li><a href="https://www.nrcs.usda.gov/resources/guides-and-instructions/keys-to-soil-taxonomy" target="_blank" rel="noopener">USDA Keys to Soil Taxonomy</a> — Official classification guide</li>
</ul>
</div>
<div class="about-section">
<h2>Source & License</h2>
<ul>
<li><strong>Code</strong>: MIT License</li>
<li><strong>Taxonomy Data</strong>: Derived from USDA <em>Keys to Soil Taxonomy</em> — public domain</li>
<li><strong>USDA Source</strong>: <a href="https://www.nrcs.usda.gov/resources/guides-and-instructions/keys-to-soil-taxonomy" target="_blank" rel="noopener">nrcs.usda.gov</a></li>
<li><strong>Source Data</strong>: <a href="https://github.com/ncss-tech/SoilKnowledgeBase" target="_blank" rel="noopener">SoilKnowledgeBase (GitHub)</a></li>
</ul>
</div>
<div class="about-section about-footer">
<div style="text-align: center; font-size: 13px; color: var(--color-text-muted);">
<p><strong>Digital Keys to Soil Taxonomy</strong><br>
Version <span x-text="appVersion || '1.0.0'"></span></p>
<p>Created by Andrew G. Brown</p>
</div>
</div>
</div>
<!-- Classify Tab -->
<div class="content-with-panel" x-show="currentTab === 'classify'">
<div class="content" x-show="!loading" @click="handleTermClick($event)" @mouseover="handleTermHover($event)">
<template x-if="error">
<div class="error" x-text="error"></div>
</template>
<template x-for="group in visibleGroups" :key="group.code">
<div class="criteria-group" x-show="showSatisfiedCriteria || !isGroupSatisfied(group.code)" :class="{ complete: isGroupSatisfied(group.code) }">
<h3>
<span x-text="group.code"></span>: <span x-text="group.label"></span>
<template x-if="isGroupSatisfied(group.code)">
<span class="satisfied-badge"> ✓ satisfied</span>
</template>
</h3>
<template x-for="criterion in group.items" :key="getCriterionId(criterion)">
<div class="criterion"
:class="{
'criterion-header': !isLeafCriterion(criterion) && criterion.depth === 0,
'criterion-parent': !isLeafCriterion(criterion) && criterion.depth > 0,
'criterion-satisfied': isClauseSatisfied(criterion)
}"
:style="{ marginLeft: criterion.depth * 20 + 'px' }">
<!-- Leaf criterion: user-checkable -->
<template x-if="isLeafCriterion(criterion)">
<input type="checkbox" :id="getCriterionId(criterion)" @change="checkCriterion(getCriterionId(criterion))" :checked="checkedCriteria[getCriterionId(criterion)]">
</template>
<!-- Structural header (depth 0): auto-computed status -->
<template x-if="!isLeafCriterion(criterion) && criterion.depth === 0">
<span class="auto-status" :class="isClauseSatisfied(criterion) ? 'status-satisfied' : 'status-unsatisfied'" x-text="isClauseSatisfied(criterion) ? '✓' : '○'"></span>
</template>
<!-- Inline parent (depth > 0): checkbox-like status -->
<template x-if="!isLeafCriterion(criterion) && criterion.depth > 0">
<span class="inline-status" :class="isClauseSatisfied(criterion) ? 'status-satisfied' : 'status-unsatisfied'" x-text="isClauseSatisfied(criterion) ? '✓' : '○'"></span>
</template>
<label :for="isLeafCriterion(criterion) ? getCriterionId(criterion) : null">
<span x-html="criterion.content_html || criterion.content"></span>
<span class="logic-badge" :class="criterion.logic === 'OR' ? 'logic-or' : 'logic-and'" x-text="criterion.logic || 'AND'" x-show="isLeafCriterion(criterion) && (engine.clauseChildrenMap[engine.getCriterionId({crit: criterion.crit, clause: criterion.parent_clause})] || []).length > 1"></span>
</label>
</div>
</template>
</div>
</template>
</div>
<div class="loading" x-show="loading"><p>Loading criteria...</p></div>
<div class="info-panel" :class="{ hidden: !infoPanelOpen }">
<div class="info-panel-controls">
<input type="text" x-model="definitionSearch" class="search-input" placeholder="Filter definitions...">
<button class="icon-btn" @click="infoPanelOpen = false" title="Close panel">✕</button>
<button class="icon-btn" @click="viewedHistory = []; definitionSearch = ''" title="Clear all history">⊟</button>
</div>
<template x-if="currentTerm && infoPanelOpen">
<div style="padding: 20px; overflow-y: auto; flex: 1;">
<div class="info-header">Term Definition</div>
<div class="current-term">
<h3 x-text="currentTerm.term"></h3>
<p x-text="currentTerm.definition"></p>
</div>
<div class="info-header">Recently Viewed</div>
<div class="viewed-history">
<template x-for="item in getFilteredHistory()" :key="item.id">
<div class="history-item" @click="selectViewed(item)"><strong x-text="item.term"></strong></div>
</template>
</div>
</div>
</template>
</div>
</div>
</div>
</div>
<script src="scripts/dst-core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3.13.3/dist/cdn.min.js" defer></script>
<script>
/*
* ============================================
* DIGITAL KEYS TO SOIL TAXONOMY — ALPINE.JS UI
* ============================================
* Thin Alpine shell delegating all pure logic to DSTCore engine.
* See scripts/dst-core.js for the standalone library.
*/
function app() {
return {
// --- State ---
appVersion: '1.0.0',
engine: null,
loading: true,
error: null,
checkedCriteria: {},
visibleGroups: [],
currentTerm: null,
viewedHistory: [],
currentTab: 'classify',
theme: localStorage.getItem('dst-theme') || 'auto',
showSatisfiedCriteria: true,
sidebarCollapsed: false,
infoPanelOpen: false,
definitionSearch: '',
// --- Theme ---
get themeIcon() {
return {
auto: '◐', light: '☀', dark: '☾',
green: '☘', sepia: '📄︎', 'high-contrast': '◈'
}[this.theme] || '◐';
},
get themeLabel() {
return {
auto: 'Auto', light: 'Light', dark: 'Dark',
green: 'Green', sepia: 'Sepia', 'high-contrast': 'High Contrast'
}[this.theme] || 'Auto';
},
cycleTheme() {
var order = ['auto', 'light', 'dark', 'green', 'sepia', 'high-contrast'];
var idx = order.indexOf(this.theme);
if (idx === -1) idx = 0;
this.theme = order[(idx + 1) % order.length];
if (this.theme === 'auto') localStorage.removeItem('dst-theme');
else localStorage.setItem('dst-theme', this.theme);
this.applyTheme();
},
applyTheme() {
var el = document.documentElement;
['dark', 'green', 'sepia', 'high-contrast'].forEach(function(c) { el.classList.remove(c); });
if (this.theme === 'dark') {
el.classList.add('dark');
} else if (this.theme === 'auto') {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) el.classList.add('dark');
} else if (this.theme === 'green' || this.theme === 'sepia' || this.theme === 'high-contrast') {
el.classList.add(this.theme);
}
},
// --- Engine Delegation ---
getCriterionId(c) { return this.engine.getCriterionId(c); },
isLeafCriterion(c) { return this.engine.isLeafCriterion(c); },
isClauseSatisfied(c) { return this.engine.isClauseSatisfied(c); },
isGroupSatisfied(code) { return this.engine.isGroupSatisfied(code); },
findCurrentLevel() { return this.engine ? this.engine.findCurrentLevel() : null; },
getClassificationPath() { return this.engine ? this.engine.getClassificationPath() : []; },
getCurrentClassification() { return this.engine ? this.engine.getCurrentClassification() : ''; },
getClassificationLevel() { return this.engine ? this.engine.getClassificationLevel() : ''; },
getClassificationBreadcrumb() { return this.engine ? this.engine.getClassificationBreadcrumb() : ''; },
removeCodePrefix(content, code) { return this.engine.removeCodePrefix(content, code); },
getCheckedCriteriaForSidebar() { return this.engine ? this.engine.getCheckedLeaves() : []; },
get taxonomyStats() {
if (!this.engine || !this.engine.codeNames) {
return { criteria: 0, orders: 0, suborders: 0, greatGroups: 0, subgroups: 0 };
}
const codes = Object.keys(this.engine.codeNames);
const stats = {
criteria: this.engine.allCriteria ? this.engine.allCriteria.length : 0,
orders: codes.filter(k => k.length === 1).length,
suborders: codes.filter(k => k.length === 2).length,
greatGroups: codes.filter(k => k.length === 3).length,
subgroups: codes.filter(k => k.length === 4 || k.length === 5).length,
};
return stats;
},
// --- Data Initialization ---
async init() {
try {
this.applyTheme();
var self = this;
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function() {
if (self.theme === 'auto') self.applyTheme();
});
var response = await fetch('data/dst-data.json');
if (!response.ok) throw new Error('HTTP ' + response.status);
var data = await response.json();
this.engine = DSTCore.create(data);
this.visibleGroups = this.engine.getVisibleGroups();
this.loading = false;
} catch (err) {
this.error = 'Failed to load: ' + err.message;
this.loading = false;
}
},
// --- User Interactions ---
checkCriterion(id) {
this.engine.toggle(id);
this._syncState();
},
removeFromPath(id) {
this.engine.uncheck(id);
this._syncState();
},
reset() {
this.engine.reset();
this.currentTerm = null;
this.viewedHistory = [];
this._syncState();
},
_syncState() {
this.checkedCriteria = Object.assign({}, this.engine.checkedCriteria);
this.visibleGroups = this.engine.getVisibleGroups();
},
getFilteredHistory() {
if (!this.definitionSearch) return this.viewedHistory;
var search = this.definitionSearch.toLowerCase();
return this.viewedHistory.filter(function(item) {
return item.term.toLowerCase().includes(search);
});
},
// --- Glossary ---
handleTermClick(event) {
var span = event.target.closest('.glossary-term');
if (span) {
event.preventDefault();
event.stopPropagation();
var termId = span.getAttribute('data-id');
this.selectTerm(termId);
}
},
handleTermHover(event) {
var span = event.target.closest('.glossary-term');
if (span) {
var termId = span.getAttribute('data-id');
var term = this.engine.glossary[termId];
if (term && !span.title) {
span.title = term.term + '\n\n' + term.definition;
}
}
},
selectTerm(termId) {
var term = this.engine.glossary[termId];
if (term) {
this.currentTerm = term;
this.infoPanelOpen = true;
if (!this.viewedHistory.find(function(h) { return h.id === termId; })) {
this.viewedHistory.unshift(term);
if (this.viewedHistory.length > 10) this.viewedHistory.pop();
}
}
},
selectViewed(item) {
this.currentTerm = item;
this.infoPanelOpen = true;
}
};
}
</script>
</body>
</html>