A loose federation of distributed, typed datasets
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 1372 lines 59 kB view raw
1<!DOCTYPE html> 2<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head> 3 4<meta charset="utf-8"> 5<meta name="generator" content="quarto-1.7.34"> 6 7<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> 8 9 10<title>lens – atdata</title> 11<style> 12code{white-space: pre-wrap;} 13span.smallcaps{font-variant: small-caps;} 14div.columns{display: flex; gap: min(4vw, 1.5em);} 15div.column{flex: auto; overflow-x: auto;} 16div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} 17ul.task-list{list-style: none;} 18ul.task-list li input[type="checkbox"] { 19 width: 0.8em; 20 margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ 21 vertical-align: middle; 22} 23/* CSS for syntax highlighting */ 24html { -webkit-text-size-adjust: 100%; } 25pre > code.sourceCode { white-space: pre; position: relative; } 26pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } 27pre > code.sourceCode > span:empty { height: 1.2em; } 28.sourceCode { overflow: visible; } 29code.sourceCode > span { color: inherit; text-decoration: inherit; } 30div.sourceCode { margin: 1em 0; } 31pre.sourceCode { margin: 0; } 32@media screen { 33div.sourceCode { overflow: auto; } 34} 35@media print { 36pre > code.sourceCode { white-space: pre-wrap; } 37pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } 38} 39pre.numberSource code 40 { counter-reset: source-line 0; } 41pre.numberSource code > span 42 { position: relative; left: -4em; counter-increment: source-line; } 43pre.numberSource code > span > a:first-child::before 44 { content: counter(source-line); 45 position: relative; left: -1em; text-align: right; vertical-align: baseline; 46 border: none; display: inline-block; 47 -webkit-touch-callout: none; -webkit-user-select: none; 48 -khtml-user-select: none; -moz-user-select: none; 49 -ms-user-select: none; user-select: none; 50 padding: 0 4px; width: 4em; 51 } 52pre.numberSource { margin-left: 3em; padding-left: 4px; } 53div.sourceCode 54 { } 55@media screen { 56pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } 57} 58</style> 59 60 61<script src="../site_libs/quarto-nav/quarto-nav.js"></script> 62<script src="../site_libs/quarto-nav/headroom.min.js"></script> 63<script src="../site_libs/clipboard/clipboard.min.js"></script> 64<script src="../site_libs/quarto-search/autocomplete.umd.js"></script> 65<script src="../site_libs/quarto-search/fuse.min.js"></script> 66<script src="../site_libs/quarto-search/quarto-search.js"></script> 67<meta name="quarto:offset" content="../"> 68<script src="../site_libs/quarto-html/quarto.js" type="module"></script> 69<script src="../site_libs/quarto-html/tabsets/tabsets.js" type="module"></script> 70<script src="../site_libs/quarto-html/popper.min.js"></script> 71<script src="../site_libs/quarto-html/tippy.umd.min.js"></script> 72<script src="../site_libs/quarto-html/anchor.min.js"></script> 73<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet"> 74<link href="../site_libs/quarto-html/quarto-syntax-highlighting-9582434199d49cc9e91654cdeeb4866b.css" rel="stylesheet" class="quarto-color-scheme" id="quarto-text-highlighting-styles"> 75<link href="../site_libs/quarto-html/quarto-syntax-highlighting-dark-8dcd8563ea6803ab7cbb3d71ca5772e1.css" rel="stylesheet" class="quarto-color-scheme quarto-color-alternate" id="quarto-text-highlighting-styles"> 76<link href="../site_libs/quarto-html/quarto-syntax-highlighting-9582434199d49cc9e91654cdeeb4866b.css" rel="stylesheet" class="quarto-color-scheme-extra" id="quarto-text-highlighting-styles"> 77<script src="../site_libs/bootstrap/bootstrap.min.js"></script> 78<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet"> 79<link href="../site_libs/bootstrap/bootstrap-62bce24ca844314e7bb1a34dbdfe05cc.min.css" rel="stylesheet" append-hash="true" class="quarto-color-scheme" id="quarto-bootstrap" data-mode="light"> 80<link href="../site_libs/bootstrap/bootstrap-dark-7964ffd8887b0991fe8d71c6c8bc75d6.min.css" rel="stylesheet" append-hash="true" class="quarto-color-scheme quarto-color-alternate" id="quarto-bootstrap" data-mode="dark"> 81<link href="../site_libs/bootstrap/bootstrap-62bce24ca844314e7bb1a34dbdfe05cc.min.css" rel="stylesheet" append-hash="true" class="quarto-color-scheme-extra" id="quarto-bootstrap" data-mode="light"> 82<script id="quarto-search-options" type="application/json">{ 83 "location": "navbar", 84 "copy-button": false, 85 "collapse-after": 3, 86 "panel-placement": "end", 87 "type": "overlay", 88 "limit": 50, 89 "keyboard-shortcut": [ 90 "f", 91 "/", 92 "s" 93 ], 94 "show-item-context": false, 95 "language": { 96 "search-no-results-text": "No results", 97 "search-matching-documents-text": "matching documents", 98 "search-copy-link-title": "Copy link to search", 99 "search-hide-matches-text": "Hide additional matches", 100 "search-more-match-text": "more match in this document", 101 "search-more-matches-text": "more matches in this document", 102 "search-clear-button-title": "Clear", 103 "search-text-placeholder": "", 104 "search-detached-cancel-button-title": "Cancel", 105 "search-submit-button-title": "Submit", 106 "search-label": "Search" 107 } 108}</script> 109 110 111<link rel="stylesheet" href="../assets/styles.css"> 112</head> 113 114<body class="nav-fixed quarto-light"><script id="quarto-html-before-body" type="application/javascript"> 115 const toggleBodyColorMode = (bsSheetEl) => { 116 const mode = bsSheetEl.getAttribute("data-mode"); 117 const bodyEl = window.document.querySelector("body"); 118 if (mode === "dark") { 119 bodyEl.classList.add("quarto-dark"); 120 bodyEl.classList.remove("quarto-light"); 121 } else { 122 bodyEl.classList.add("quarto-light"); 123 bodyEl.classList.remove("quarto-dark"); 124 } 125 } 126 const toggleBodyColorPrimary = () => { 127 const bsSheetEl = window.document.querySelector("link#quarto-bootstrap:not([rel=disabled-stylesheet])"); 128 if (bsSheetEl) { 129 toggleBodyColorMode(bsSheetEl); 130 } 131 } 132 const setColorSchemeToggle = (alternate) => { 133 const toggles = window.document.querySelectorAll('.quarto-color-scheme-toggle'); 134 for (let i=0; i < toggles.length; i++) { 135 const toggle = toggles[i]; 136 if (toggle) { 137 if (alternate) { 138 toggle.classList.add("alternate"); 139 } else { 140 toggle.classList.remove("alternate"); 141 } 142 } 143 } 144 }; 145 const toggleColorMode = (alternate) => { 146 // Switch the stylesheets 147 const primaryStylesheets = window.document.querySelectorAll('link.quarto-color-scheme:not(.quarto-color-alternate)'); 148 const alternateStylesheets = window.document.querySelectorAll('link.quarto-color-scheme.quarto-color-alternate'); 149 manageTransitions('#quarto-margin-sidebar .nav-link', false); 150 if (alternate) { 151 // note: dark is layered on light, we don't disable primary! 152 enableStylesheet(alternateStylesheets); 153 for (const sheetNode of alternateStylesheets) { 154 if (sheetNode.id === "quarto-bootstrap") { 155 toggleBodyColorMode(sheetNode); 156 } 157 } 158 } else { 159 disableStylesheet(alternateStylesheets); 160 enableStylesheet(primaryStylesheets) 161 toggleBodyColorPrimary(); 162 } 163 manageTransitions('#quarto-margin-sidebar .nav-link', true); 164 // Switch the toggles 165 setColorSchemeToggle(alternate) 166 // Hack to workaround the fact that safari doesn't 167 // properly recolor the scrollbar when toggling (#1455) 168 if (navigator.userAgent.indexOf('Safari') > 0 && navigator.userAgent.indexOf('Chrome') == -1) { 169 manageTransitions("body", false); 170 window.scrollTo(0, 1); 171 setTimeout(() => { 172 window.scrollTo(0, 0); 173 manageTransitions("body", true); 174 }, 40); 175 } 176 } 177 const disableStylesheet = (stylesheets) => { 178 for (let i=0; i < stylesheets.length; i++) { 179 const stylesheet = stylesheets[i]; 180 stylesheet.rel = 'disabled-stylesheet'; 181 } 182 } 183 const enableStylesheet = (stylesheets) => { 184 for (let i=0; i < stylesheets.length; i++) { 185 const stylesheet = stylesheets[i]; 186 if(stylesheet.rel !== 'stylesheet') { // for Chrome, which will still FOUC without this check 187 stylesheet.rel = 'stylesheet'; 188 } 189 } 190 } 191 const manageTransitions = (selector, allowTransitions) => { 192 const els = window.document.querySelectorAll(selector); 193 for (let i=0; i < els.length; i++) { 194 const el = els[i]; 195 if (allowTransitions) { 196 el.classList.remove('notransition'); 197 } else { 198 el.classList.add('notransition'); 199 } 200 } 201 } 202 const isFileUrl = () => { 203 return window.location.protocol === 'file:'; 204 } 205 const hasAlternateSentinel = () => { 206 let styleSentinel = getColorSchemeSentinel(); 207 if (styleSentinel !== null) { 208 return styleSentinel === "alternate"; 209 } else { 210 return false; 211 } 212 } 213 const setStyleSentinel = (alternate) => { 214 const value = alternate ? "alternate" : "default"; 215 if (!isFileUrl()) { 216 window.localStorage.setItem("quarto-color-scheme", value); 217 } else { 218 localAlternateSentinel = value; 219 } 220 } 221 const getColorSchemeSentinel = () => { 222 if (!isFileUrl()) { 223 const storageValue = window.localStorage.getItem("quarto-color-scheme"); 224 return storageValue != null ? storageValue : localAlternateSentinel; 225 } else { 226 return localAlternateSentinel; 227 } 228 } 229 const toggleGiscusIfUsed = (isAlternate, darkModeDefault) => { 230 const baseTheme = document.querySelector('#giscus-base-theme')?.value ?? 'light'; 231 const alternateTheme = document.querySelector('#giscus-alt-theme')?.value ?? 'dark'; 232 let newTheme = ''; 233 if(authorPrefersDark) { 234 newTheme = isAlternate ? baseTheme : alternateTheme; 235 } else { 236 newTheme = isAlternate ? alternateTheme : baseTheme; 237 } 238 const changeGiscusTheme = () => { 239 // From: https://github.com/giscus/giscus/issues/336 240 const sendMessage = (message) => { 241 const iframe = document.querySelector('iframe.giscus-frame'); 242 if (!iframe) return; 243 iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app'); 244 } 245 sendMessage({ 246 setConfig: { 247 theme: newTheme 248 } 249 }); 250 } 251 const isGiscussLoaded = window.document.querySelector('iframe.giscus-frame') !== null; 252 if (isGiscussLoaded) { 253 changeGiscusTheme(); 254 } 255 }; 256 const authorPrefersDark = false; 257 const darkModeDefault = authorPrefersDark; 258 document.querySelector('link#quarto-text-highlighting-styles.quarto-color-scheme-extra').rel = 'disabled-stylesheet'; 259 document.querySelector('link#quarto-bootstrap.quarto-color-scheme-extra').rel = 'disabled-stylesheet'; 260 let localAlternateSentinel = darkModeDefault ? 'alternate' : 'default'; 261 // Dark / light mode switch 262 window.quartoToggleColorScheme = () => { 263 // Read the current dark / light value 264 let toAlternate = !hasAlternateSentinel(); 265 toggleColorMode(toAlternate); 266 setStyleSentinel(toAlternate); 267 toggleGiscusIfUsed(toAlternate, darkModeDefault); 268 window.dispatchEvent(new Event('resize')); 269 }; 270 // Switch to dark mode if need be 271 if (hasAlternateSentinel()) { 272 toggleColorMode(true); 273 } else { 274 toggleColorMode(false); 275 } 276 </script> 277 278<div id="quarto-search-results"></div> 279 <header id="quarto-header" class="headroom fixed-top"> 280 <nav class="navbar navbar-expand-lg " data-bs-theme="dark"> 281 <div class="navbar-container container-fluid"> 282 <div class="navbar-brand-container mx-auto"> 283 <a class="navbar-brand" href="../index.html"> 284 <span class="navbar-title">atdata</span> 285 </a> 286 </div> 287 <div id="quarto-search" class="" title="Search"></div> 288 <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" role="menu" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }"> 289 <span class="navbar-toggler-icon"></span> 290</button> 291 <div class="collapse navbar-collapse" id="navbarCollapse"> 292 <ul class="navbar-nav navbar-nav-scroll me-auto"> 293 <li class="nav-item"> 294 <a class="nav-link" href="../index.html"> 295<span class="menu-text">Guide</span></a> 296 </li> 297 <li class="nav-item dropdown "> 298 <a class="nav-link dropdown-toggle" href="#" id="nav-menu-tutorials" role="link" data-bs-toggle="dropdown" aria-expanded="false"> 299 <span class="menu-text">Tutorials</span> 300 </a> 301 <ul class="dropdown-menu" aria-labelledby="nav-menu-tutorials"> 302 <li> 303 <a class="dropdown-item" href="../tutorials/quickstart.html"> 304 <span class="dropdown-text">Quick Start</span></a> 305 </li> 306 <li> 307 <a class="dropdown-item" href="../tutorials/local-workflow.html"> 308 <span class="dropdown-text">Local Workflow</span></a> 309 </li> 310 <li> 311 <a class="dropdown-item" href="../tutorials/atmosphere.html"> 312 <span class="dropdown-text">Atmosphere Publishing</span></a> 313 </li> 314 <li> 315 <a class="dropdown-item" href="../tutorials/promotion.html"> 316 <span class="dropdown-text">Promotion Workflow</span></a> 317 </li> 318 </ul> 319 </li> 320 <li class="nav-item dropdown "> 321 <a class="nav-link dropdown-toggle" href="#" id="nav-menu-reference" role="link" data-bs-toggle="dropdown" aria-expanded="false"> 322 <span class="menu-text">Reference</span> 323 </a> 324 <ul class="dropdown-menu" aria-labelledby="nav-menu-reference"> 325 <li> 326 <a class="dropdown-item" href="../reference/architecture.html"> 327 <span class="dropdown-text">Architecture Overview</span></a> 328 </li> 329 <li> 330 <a class="dropdown-item" href="../reference/packable-samples.html"> 331 <span class="dropdown-text">Packable Samples</span></a> 332 </li> 333 <li> 334 <a class="dropdown-item" href="../reference/datasets.html"> 335 <span class="dropdown-text">Datasets</span></a> 336 </li> 337 <li> 338 <a class="dropdown-item" href="../reference/lenses.html"> 339 <span class="dropdown-text">Lenses</span></a> 340 </li> 341 <li> 342 <a class="dropdown-item" href="../reference/local-storage.html"> 343 <span class="dropdown-text">Local Storage</span></a> 344 </li> 345 <li> 346 <a class="dropdown-item" href="../reference/atmosphere.html"> 347 <span class="dropdown-text">Atmosphere</span></a> 348 </li> 349 <li> 350 <a class="dropdown-item" href="../reference/promotion.html"> 351 <span class="dropdown-text">Promotion</span></a> 352 </li> 353 <li> 354 <a class="dropdown-item" href="../reference/load-dataset.html"> 355 <span class="dropdown-text">load_dataset API</span></a> 356 </li> 357 <li> 358 <a class="dropdown-item" href="../reference/protocols.html"> 359 <span class="dropdown-text">Protocols</span></a> 360 </li> 361 <li> 362 <a class="dropdown-item" href="../reference/uri-spec.html"> 363 <span class="dropdown-text">URI Specification</span></a> 364 </li> 365 <li> 366 <a class="dropdown-item" href="../reference/troubleshooting.html"> 367 <span class="dropdown-text">Troubleshooting &amp; FAQ</span></a> 368 </li> 369 <li> 370 <a class="dropdown-item" href="../reference/deployment.html"> 371 <span class="dropdown-text">Deployment Guide</span></a> 372 </li> 373 </ul> 374 </li> 375 <li class="nav-item"> 376 <a class="nav-link" href="../api/index.html"> 377<span class="menu-text">API</span></a> 378 </li> 379</ul> 380 <ul class="navbar-nav navbar-nav-scroll ms-auto"> 381 <li class="nav-item compact"> 382 <a class="nav-link" href="https://github.com/your-org/atdata"> <i class="bi bi-github" role="img"> 383</i> 384<span class="menu-text"></span></a> 385 </li> 386</ul> 387 </div> <!-- /navcollapse --> 388 <div class="quarto-navbar-tools"> 389 <a href="" class="quarto-color-scheme-toggle quarto-navigation-tool px-1" onclick="window.quartoToggleColorScheme(); return false;" title="Toggle dark mode"><i class="bi"></i></a> 390</div> 391 </div> <!-- /container-fluid --> 392 </nav> 393</header> 394<!-- content --> 395<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar"> 396<!-- sidebar --> 397<!-- margin-sidebar --> 398 <div id="quarto-margin-sidebar" class="sidebar margin-sidebar"> 399 <nav id="TOC" role="doc-toc" class="toc-active"> 400 <h2 id="toc-title">On this page</h2> 401 402 <ul> 403 <li><a href="#atdata.lens" id="toc-atdata.lens" class="nav-link active" data-scroll-target="#atdata.lens">lens</a> 404 <ul class="collapse"> 405 <li><a href="#examples" id="toc-examples" class="nav-link" data-scroll-target="#examples">Examples</a></li> 406 <li><a href="#classes" id="toc-classes" class="nav-link" data-scroll-target="#classes">Classes</a> 407 <ul class="collapse"> 408 <li><a href="#atdata.lens.Lens" id="toc-atdata.lens.Lens" class="nav-link" data-scroll-target="#atdata.lens.Lens">Lens</a></li> 409 <li><a href="#atdata.lens.LensNetwork" id="toc-atdata.lens.LensNetwork" class="nav-link" data-scroll-target="#atdata.lens.LensNetwork">LensNetwork</a></li> 410 </ul></li> 411 <li><a href="#functions" id="toc-functions" class="nav-link" data-scroll-target="#functions">Functions</a> 412 <ul class="collapse"> 413 <li><a href="#atdata.lens.lens" id="toc-atdata.lens.lens" class="nav-link" data-scroll-target="#atdata.lens.lens">lens</a></li> 414 </ul></li> 415 </ul></li> 416 </ul> 417<div class="toc-actions"><ul><li><a href="https://github.com/your-org/atdata/edit/main/api/Lens.qmd" class="toc-action"><i class="bi bi-github"></i>Edit this page</a></li><li><a href="https://github.com/your-org/atdata/issues/new" class="toc-action"><i class="bi empty"></i>Report an issue</a></li></ul></div></nav> 418 </div> 419<!-- main --> 420<main class="content" id="quarto-document-content"><header id="title-block-header" class="quarto-title-block"></header> 421 422 423 424 425 426<section id="atdata.lens" class="level1"> 427<h1>lens</h1> 428<p><code>lens</code></p> 429<p>Lens-based type transformations for datasets.</p> 430<p>This module implements a lens system for bidirectional transformations between different sample types. Lenses enable viewing a dataset through different type schemas without duplicating the underlying data.</p> 431<p>Key components:</p> 432<ul> 433<li><code>Lens</code>: Bidirectional transformation with getter (S -&gt; V) and optional putter (V, S -&gt; S)</li> 434<li><code>LensNetwork</code>: Global singleton registry for lens transformations</li> 435<li><code>@lens</code>: Decorator to create and register lens transformations</li> 436</ul> 437<p>Lenses support the functional programming concept of composable, well-behaved transformations that satisfy lens laws (GetPut and PutGet).</p> 438<section id="examples" class="level2 doc-section doc-section-examples"> 439<h2 class="doc-section doc-section-examples anchored" data-anchor-id="examples">Examples</h2> 440<div class="sourceCode" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>packable</span> 441<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>... <span class="kw">class</span> FullData:</span> 442<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>... name: <span class="bu">str</span></span> 443<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>... age: <span class="bu">int</span></span> 444<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>... embedding: NDArray</span> 445<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>...</span> 446<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>packable</span> 447<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>... <span class="kw">class</span> NameOnly:</span> 448<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>... name: <span class="bu">str</span></span> 449<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a>...</span> 450<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>lens</span> 451<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a>... <span class="kw">def</span> name_view(full: FullData) <span class="op">-&gt;</span> NameOnly:</span> 452<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a>... <span class="cf">return</span> NameOnly(name<span class="op">=</span>full.name)</span> 453<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a>...</span> 454<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>name_view.putter</span> 455<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a>... <span class="kw">def</span> name_view_put(view: NameOnly, source: FullData) <span class="op">-&gt;</span> FullData:</span> 456<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a>... <span class="cf">return</span> FullData(name<span class="op">=</span>view.name, age<span class="op">=</span>source.age,</span> 457<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a>... embedding<span class="op">=</span>source.embedding)</span> 458<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a>...</span> 459<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> ds <span class="op">=</span> Dataset[FullData](<span class="st">"data.tar"</span>)</span> 460<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> ds_names <span class="op">=</span> ds.as_type(NameOnly) <span class="co"># Uses registered lens</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 461</section> 462<section id="classes" class="level2"> 463<h2 class="anchored" data-anchor-id="classes">Classes</h2> 464<table class="caption-top table"> 465<thead> 466<tr class="header"> 467<th>Name</th> 468<th>Description</th> 469</tr> 470</thead> 471<tbody> 472<tr class="odd"> 473<td><a href="#atdata.lens.Lens">Lens</a></td> 474<td>A bidirectional transformation between two sample types.</td> 475</tr> 476<tr class="even"> 477<td><a href="#atdata.lens.LensNetwork">LensNetwork</a></td> 478<td>Global registry for lens transformations between sample types.</td> 479</tr> 480</tbody> 481</table> 482<section id="atdata.lens.Lens" class="level3"> 483<h3 class="anchored" data-anchor-id="atdata.lens.Lens">Lens</h3> 484<div class="sourceCode" id="cb2"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>lens.Lens(get, put<span class="op">=</span><span class="va">None</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 485<p>A bidirectional transformation between two sample types.</p> 486<p>A lens provides a way to view and update data of type <code>S</code> (source) as if it were type <code>V</code> (view). It consists of a getter that transforms <code>S -&gt; V</code> and an optional putter that transforms <code>(V, S) -&gt; S</code>, enabling updates to the view to be reflected back in the source.</p> 487<section id="parameters" class="level4 doc-section doc-section-parameters"> 488<h4 class="doc-section doc-section-parameters anchored" data-anchor-id="parameters">Parameters</h4> 489<table class="caption-top table"> 490<colgroup> 491<col style="width: 9%"> 492<col style="width: 9%"> 493<col style="width: 66%"> 494<col style="width: 14%"> 495</colgroup> 496<thead> 497<tr class="header"> 498<th>Name</th> 499<th>Type</th> 500<th>Description</th> 501<th>Default</th> 502</tr> 503</thead> 504<tbody> 505<tr class="odd"> 506<td>S</td> 507<td></td> 508<td>The source type, must derive from <code>PackableSample</code>.</td> 509<td><em>required</em></td> 510</tr> 511<tr class="even"> 512<td>V</td> 513<td></td> 514<td>The view type, must derive from <code>PackableSample</code>.</td> 515<td><em>required</em></td> 516</tr> 517</tbody> 518</table> 519</section> 520<section id="examples-1" class="level4 doc-section doc-section-examples"> 521<h4 class="doc-section doc-section-examples anchored" data-anchor-id="examples-1">Examples</h4> 522<div class="sourceCode" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>lens</span> 523<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>... <span class="kw">def</span> name_lens(full: FullData) <span class="op">-&gt;</span> NameOnly:</span> 524<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>... <span class="cf">return</span> NameOnly(name<span class="op">=</span>full.name)</span> 525<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>...</span> 526<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>name_lens.putter</span> 527<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>... <span class="kw">def</span> name_lens_put(view: NameOnly, source: FullData) <span class="op">-&gt;</span> FullData:</span> 528<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>... <span class="cf">return</span> FullData(name<span class="op">=</span>view.name, age<span class="op">=</span>source.age)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 529</section> 530<section id="methods" class="level4"> 531<h4 class="anchored" data-anchor-id="methods">Methods</h4> 532<table class="caption-top table"> 533<thead> 534<tr class="header"> 535<th>Name</th> 536<th>Description</th> 537</tr> 538</thead> 539<tbody> 540<tr class="odd"> 541<td><a href="#atdata.lens.Lens.get">get</a></td> 542<td>Transform the source into the view type.</td> 543</tr> 544<tr class="even"> 545<td><a href="#atdata.lens.Lens.put">put</a></td> 546<td>Update the source based on a modified view.</td> 547</tr> 548<tr class="odd"> 549<td><a href="#atdata.lens.Lens.putter">putter</a></td> 550<td>Decorator to register a putter function for this lens.</td> 551</tr> 552</tbody> 553</table> 554<section id="atdata.lens.Lens.get" class="level5"> 555<h5 class="anchored" data-anchor-id="atdata.lens.Lens.get">get</h5> 556<div class="sourceCode" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>lens.Lens.get(s)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 557<p>Transform the source into the view type.</p> 558<section id="parameters-1" class="level6 doc-section doc-section-parameters"> 559<h6 class="doc-section doc-section-parameters anchored" data-anchor-id="parameters-1">Parameters</h6> 560<table class="caption-top table"> 561<thead> 562<tr class="header"> 563<th>Name</th> 564<th>Type</th> 565<th>Description</th> 566<th>Default</th> 567</tr> 568</thead> 569<tbody> 570<tr class="odd"> 571<td>s</td> 572<td><a href="`atdata.lens.S`">S</a></td> 573<td>The source sample of type <code>S</code>.</td> 574<td><em>required</em></td> 575</tr> 576</tbody> 577</table> 578</section> 579<section id="returns" class="level6 doc-section doc-section-returns"> 580<h6 class="doc-section doc-section-returns anchored" data-anchor-id="returns">Returns</h6> 581<table class="caption-top table"> 582<thead> 583<tr class="header"> 584<th>Name</th> 585<th>Type</th> 586<th>Description</th> 587</tr> 588</thead> 589<tbody> 590<tr class="odd"> 591<td></td> 592<td><a href="`atdata.lens.V`">V</a></td> 593<td>A view of the source as type <code>V</code>.</td> 594</tr> 595</tbody> 596</table> 597</section> 598</section> 599<section id="atdata.lens.Lens.put" class="level5"> 600<h5 class="anchored" data-anchor-id="atdata.lens.Lens.put">put</h5> 601<div class="sourceCode" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>lens.Lens.put(v, s)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 602<p>Update the source based on a modified view.</p> 603<section id="parameters-2" class="level6 doc-section doc-section-parameters"> 604<h6 class="doc-section doc-section-parameters anchored" data-anchor-id="parameters-2">Parameters</h6> 605<table class="caption-top table"> 606<thead> 607<tr class="header"> 608<th>Name</th> 609<th>Type</th> 610<th>Description</th> 611<th>Default</th> 612</tr> 613</thead> 614<tbody> 615<tr class="odd"> 616<td>v</td> 617<td><a href="`atdata.lens.V`">V</a></td> 618<td>The modified view of type <code>V</code>.</td> 619<td><em>required</em></td> 620</tr> 621<tr class="even"> 622<td>s</td> 623<td><a href="`atdata.lens.S`">S</a></td> 624<td>The original source of type <code>S</code>.</td> 625<td><em>required</em></td> 626</tr> 627</tbody> 628</table> 629</section> 630<section id="returns-1" class="level6 doc-section doc-section-returns"> 631<h6 class="doc-section doc-section-returns anchored" data-anchor-id="returns-1">Returns</h6> 632<table class="caption-top table"> 633<thead> 634<tr class="header"> 635<th>Name</th> 636<th>Type</th> 637<th>Description</th> 638</tr> 639</thead> 640<tbody> 641<tr class="odd"> 642<td></td> 643<td><a href="`atdata.lens.S`">S</a></td> 644<td>An updated source of type <code>S</code> that reflects changes from the view.</td> 645</tr> 646</tbody> 647</table> 648</section> 649</section> 650<section id="atdata.lens.Lens.putter" class="level5"> 651<h5 class="anchored" data-anchor-id="atdata.lens.Lens.putter">putter</h5> 652<div class="sourceCode" id="cb6"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>lens.Lens.putter(put)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 653<p>Decorator to register a putter function for this lens.</p> 654<section id="parameters-3" class="level6 doc-section doc-section-parameters"> 655<h6 class="doc-section doc-section-parameters anchored" data-anchor-id="parameters-3">Parameters</h6> 656<table class="caption-top table"> 657<thead> 658<tr class="header"> 659<th>Name</th> 660<th>Type</th> 661<th>Description</th> 662<th>Default</th> 663</tr> 664</thead> 665<tbody> 666<tr class="odd"> 667<td>put</td> 668<td><a href="`atdata.lens.LensPutter`">LensPutter</a>[<a href="`atdata.lens.S`">S</a>, <a href="`atdata.lens.V`">V</a>]</td> 669<td>A function that takes a view of type <code>V</code> and source of type <code>S</code>, and returns an updated source of type <code>S</code>.</td> 670<td><em>required</em></td> 671</tr> 672</tbody> 673</table> 674</section> 675<section id="returns-2" class="level6 doc-section doc-section-returns"> 676<h6 class="doc-section doc-section-returns anchored" data-anchor-id="returns-2">Returns</h6> 677<table class="caption-top table"> 678<thead> 679<tr class="header"> 680<th>Name</th> 681<th>Type</th> 682<th>Description</th> 683</tr> 684</thead> 685<tbody> 686<tr class="odd"> 687<td></td> 688<td><a href="`atdata.lens.LensPutter`">LensPutter</a>[<a href="`atdata.lens.S`">S</a>, <a href="`atdata.lens.V`">V</a>]</td> 689<td>The putter function, allowing this to be used as a decorator.</td> 690</tr> 691</tbody> 692</table> 693</section> 694<section id="examples-2" class="level6 doc-section doc-section-examples"> 695<h6 class="doc-section doc-section-examples anchored" data-anchor-id="examples-2">Examples</h6> 696<div class="sourceCode" id="cb7"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>my_lens.putter</span> 697<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>... <span class="kw">def</span> my_lens_put(view: ViewType, source: SourceType) <span class="op">-&gt;</span> SourceType:</span> 698<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>... <span class="cf">return</span> SourceType(field<span class="op">=</span>view.field, other<span class="op">=</span>source.other)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 699</section> 700</section> 701</section> 702</section> 703<section id="atdata.lens.LensNetwork" class="level3"> 704<h3 class="anchored" data-anchor-id="atdata.lens.LensNetwork">LensNetwork</h3> 705<div class="sourceCode" id="cb8"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>lens.LensNetwork()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 706<p>Global registry for lens transformations between sample types.</p> 707<p>This class implements a singleton pattern to maintain a global registry of all lenses decorated with <code>@lens</code>. It enables looking up transformations between different <code>PackableSample</code> types.</p> 708<section id="attributes" class="level4 doc-section doc-section-attributes"> 709<h4 class="doc-section doc-section-attributes anchored" data-anchor-id="attributes">Attributes</h4> 710<table class="caption-top table"> 711<thead> 712<tr class="header"> 713<th>Name</th> 714<th>Type</th> 715<th>Description</th> 716</tr> 717</thead> 718<tbody> 719<tr class="odd"> 720<td>_instance</td> 721<td></td> 722<td>The singleton instance of this class.</td> 723</tr> 724<tr class="even"> 725<td>_registry</td> 726<td><a href="`typing.Dict`">Dict</a>[<a href="`atdata.lens.LensSignature`">LensSignature</a>, <a href="`atdata.lens.Lens`">Lens</a>]</td> 727<td>Dictionary mapping <code>(source_type, view_type)</code> tuples to their corresponding <code>Lens</code> objects.</td> 728</tr> 729</tbody> 730</table> 731</section> 732<section id="methods-1" class="level4"> 733<h4 class="anchored" data-anchor-id="methods-1">Methods</h4> 734<table class="caption-top table"> 735<thead> 736<tr class="header"> 737<th>Name</th> 738<th>Description</th> 739</tr> 740</thead> 741<tbody> 742<tr class="odd"> 743<td><a href="#atdata.lens.LensNetwork.register">register</a></td> 744<td>Register a lens as the canonical transformation between two types.</td> 745</tr> 746<tr class="even"> 747<td><a href="#atdata.lens.LensNetwork.transform">transform</a></td> 748<td>Look up the lens transformation between two sample types.</td> 749</tr> 750</tbody> 751</table> 752<section id="atdata.lens.LensNetwork.register" class="level5"> 753<h5 class="anchored" data-anchor-id="atdata.lens.LensNetwork.register">register</h5> 754<div class="sourceCode" id="cb9"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>lens.LensNetwork.register(_lens)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 755<p>Register a lens as the canonical transformation between two types.</p> 756<section id="parameters-4" class="level6 doc-section doc-section-parameters"> 757<h6 class="doc-section doc-section-parameters anchored" data-anchor-id="parameters-4">Parameters</h6> 758<table class="caption-top table"> 759<thead> 760<tr class="header"> 761<th>Name</th> 762<th>Type</th> 763<th>Description</th> 764<th>Default</th> 765</tr> 766</thead> 767<tbody> 768<tr class="odd"> 769<td>_lens</td> 770<td><a href="`atdata.lens.Lens`">Lens</a></td> 771<td>The lens to register. Will be stored in the registry under the key <code>(_lens.source_type, _lens.view_type)</code>.</td> 772<td><em>required</em></td> 773</tr> 774</tbody> 775</table> 776</section> 777<section id="note" class="level6 doc-section doc-section-note"> 778<h6 class="doc-section doc-section-note anchored" data-anchor-id="note">Note</h6> 779<p>If a lens already exists for the same type pair, it will be overwritten.</p> 780</section> 781</section> 782<section id="atdata.lens.LensNetwork.transform" class="level5"> 783<h5 class="anchored" data-anchor-id="atdata.lens.LensNetwork.transform">transform</h5> 784<div class="sourceCode" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>lens.LensNetwork.transform(source, view)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 785<p>Look up the lens transformation between two sample types.</p> 786<section id="parameters-5" class="level6 doc-section doc-section-parameters"> 787<h6 class="doc-section doc-section-parameters anchored" data-anchor-id="parameters-5">Parameters</h6> 788<table class="caption-top table"> 789<thead> 790<tr class="header"> 791<th>Name</th> 792<th>Type</th> 793<th>Description</th> 794<th>Default</th> 795</tr> 796</thead> 797<tbody> 798<tr class="odd"> 799<td>source</td> 800<td><a href="`atdata.lens.DatasetType`">DatasetType</a></td> 801<td>The source sample type (must derive from <code>PackableSample</code>).</td> 802<td><em>required</em></td> 803</tr> 804<tr class="even"> 805<td>view</td> 806<td><a href="`atdata.lens.DatasetType`">DatasetType</a></td> 807<td>The target view type (must derive from <code>PackableSample</code>).</td> 808<td><em>required</em></td> 809</tr> 810</tbody> 811</table> 812</section> 813<section id="returns-3" class="level6 doc-section doc-section-returns"> 814<h6 class="doc-section doc-section-returns anchored" data-anchor-id="returns-3">Returns</h6> 815<table class="caption-top table"> 816<thead> 817<tr class="header"> 818<th>Name</th> 819<th>Type</th> 820<th>Description</th> 821</tr> 822</thead> 823<tbody> 824<tr class="odd"> 825<td></td> 826<td><a href="`atdata.lens.Lens`">Lens</a></td> 827<td>The registered <code>Lens</code> that transforms from <code>source</code> to <code>view</code>.</td> 828</tr> 829</tbody> 830</table> 831</section> 832<section id="raises" class="level6 doc-section doc-section-raises"> 833<h6 class="doc-section doc-section-raises anchored" data-anchor-id="raises">Raises</h6> 834<table class="caption-top table"> 835<thead> 836<tr class="header"> 837<th>Name</th> 838<th>Type</th> 839<th>Description</th> 840</tr> 841</thead> 842<tbody> 843<tr class="odd"> 844<td></td> 845<td><a href="`ValueError`">ValueError</a></td> 846<td>If no lens has been registered for the given type pair.</td> 847</tr> 848</tbody> 849</table> 850</section> 851<section id="note-1" class="level6 doc-section doc-section-note"> 852<h6 class="doc-section doc-section-note anchored" data-anchor-id="note-1">Note</h6> 853<p>Currently only supports direct transformations. Compositional transformations (chaining multiple lenses) are not yet implemented.</p> 854</section> 855</section> 856</section> 857</section> 858</section> 859<section id="functions" class="level2"> 860<h2 class="anchored" data-anchor-id="functions">Functions</h2> 861<table class="caption-top table"> 862<thead> 863<tr class="header"> 864<th>Name</th> 865<th>Description</th> 866</tr> 867</thead> 868<tbody> 869<tr class="odd"> 870<td><a href="#atdata.lens.lens">lens</a></td> 871<td>Decorator to create and register a lens transformation.</td> 872</tr> 873</tbody> 874</table> 875<section id="atdata.lens.lens" class="level3"> 876<h3 class="anchored" data-anchor-id="atdata.lens.lens">lens</h3> 877<div class="sourceCode" id="cb11"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>lens.lens(f)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 878<p>Decorator to create and register a lens transformation.</p> 879<p>This decorator converts a getter function into a <code>Lens</code> object and automatically registers it in the global <code>LensNetwork</code> registry.</p> 880<section id="parameters-6" class="level4 doc-section doc-section-parameters"> 881<h4 class="doc-section doc-section-parameters anchored" data-anchor-id="parameters-6">Parameters</h4> 882<table class="caption-top table"> 883<thead> 884<tr class="header"> 885<th>Name</th> 886<th>Type</th> 887<th>Description</th> 888<th>Default</th> 889</tr> 890</thead> 891<tbody> 892<tr class="odd"> 893<td>f</td> 894<td><a href="`atdata.lens.LensGetter`">LensGetter</a>[<a href="`atdata.lens.S`">S</a>, <a href="`atdata.lens.V`">V</a>]</td> 895<td>A getter function that transforms from source type <code>S</code> to view type <code>V</code>. Must have exactly one parameter with a type annotation.</td> 896<td><em>required</em></td> 897</tr> 898</tbody> 899</table> 900</section> 901<section id="returns-4" class="level4 doc-section doc-section-returns"> 902<h4 class="doc-section doc-section-returns anchored" data-anchor-id="returns-4">Returns</h4> 903<table class="caption-top table"> 904<thead> 905<tr class="header"> 906<th>Name</th> 907<th>Type</th> 908<th>Description</th> 909</tr> 910</thead> 911<tbody> 912<tr class="odd"> 913<td></td> 914<td><a href="`atdata.lens.Lens`">Lens</a>[<a href="`atdata.lens.S`">S</a>, <a href="`atdata.lens.V`">V</a>]</td> 915<td>A <code>Lens[S, V]</code> object that can be called to apply the transformation</td> 916</tr> 917<tr class="even"> 918<td></td> 919<td><a href="`atdata.lens.Lens`">Lens</a>[<a href="`atdata.lens.S`">S</a>, <a href="`atdata.lens.V`">V</a>]</td> 920<td>or decorated with <code>@lens_name.putter</code> to add a putter function.</td> 921</tr> 922</tbody> 923</table> 924</section> 925<section id="examples-3" class="level4 doc-section doc-section-examples"> 926<h4 class="doc-section doc-section-examples anchored" data-anchor-id="examples-3">Examples</h4> 927<div class="sourceCode" id="cb12"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>lens</span> 928<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>... <span class="kw">def</span> extract_name(full: FullData) <span class="op">-&gt;</span> NameOnly:</span> 929<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>... <span class="cf">return</span> NameOnly(name<span class="op">=</span>full.name)</span> 930<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a>...</span> 931<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a><span class="op">&gt;&gt;&gt;</span> <span class="op">@</span>extract_name.putter</span> 932<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a>... <span class="kw">def</span> extract_name_put(view: NameOnly, source: FullData) <span class="op">-&gt;</span> FullData:</span> 933<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a>... <span class="cf">return</span> FullData(name<span class="op">=</span>view.name, age<span class="op">=</span>source.age)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> 934 935 936</section> 937</section> 938</section> 939</section> 940 941</main> <!-- /main --> 942<script id="quarto-html-after-body" type="application/javascript"> 943 window.document.addEventListener("DOMContentLoaded", function (event) { 944 // Ensure there is a toggle, if there isn't float one in the top right 945 if (window.document.querySelector('.quarto-color-scheme-toggle') === null) { 946 const a = window.document.createElement('a'); 947 a.classList.add('top-right'); 948 a.classList.add('quarto-color-scheme-toggle'); 949 a.href = ""; 950 a.onclick = function() { try { window.quartoToggleColorScheme(); } catch {} return false; }; 951 const i = window.document.createElement("i"); 952 i.classList.add('bi'); 953 a.appendChild(i); 954 window.document.body.appendChild(a); 955 } 956 setColorSchemeToggle(hasAlternateSentinel()) 957 const icon = ""; 958 const anchorJS = new window.AnchorJS(); 959 anchorJS.options = { 960 placement: 'right', 961 icon: icon 962 }; 963 anchorJS.add('.anchored'); 964 const isCodeAnnotation = (el) => { 965 for (const clz of el.classList) { 966 if (clz.startsWith('code-annotation-')) { 967 return true; 968 } 969 } 970 return false; 971 } 972 const onCopySuccess = function(e) { 973 // button target 974 const button = e.trigger; 975 // don't keep focus 976 button.blur(); 977 // flash "checked" 978 button.classList.add('code-copy-button-checked'); 979 var currentTitle = button.getAttribute("title"); 980 button.setAttribute("title", "Copied!"); 981 let tooltip; 982 if (window.bootstrap) { 983 button.setAttribute("data-bs-toggle", "tooltip"); 984 button.setAttribute("data-bs-placement", "left"); 985 button.setAttribute("data-bs-title", "Copied!"); 986 tooltip = new bootstrap.Tooltip(button, 987 { trigger: "manual", 988 customClass: "code-copy-button-tooltip", 989 offset: [0, -8]}); 990 tooltip.show(); 991 } 992 setTimeout(function() { 993 if (tooltip) { 994 tooltip.hide(); 995 button.removeAttribute("data-bs-title"); 996 button.removeAttribute("data-bs-toggle"); 997 button.removeAttribute("data-bs-placement"); 998 } 999 button.setAttribute("title", currentTitle); 1000 button.classList.remove('code-copy-button-checked'); 1001 }, 1000); 1002 // clear code selection 1003 e.clearSelection(); 1004 } 1005 const getTextToCopy = function(trigger) { 1006 const codeEl = trigger.previousElementSibling.cloneNode(true); 1007 for (const childEl of codeEl.children) { 1008 if (isCodeAnnotation(childEl)) { 1009 childEl.remove(); 1010 } 1011 } 1012 return codeEl.innerText; 1013 } 1014 const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', { 1015 text: getTextToCopy 1016 }); 1017 clipboard.on('success', onCopySuccess); 1018 if (window.document.getElementById('quarto-embedded-source-code-modal')) { 1019 const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', { 1020 text: getTextToCopy, 1021 container: window.document.getElementById('quarto-embedded-source-code-modal') 1022 }); 1023 clipboardModal.on('success', onCopySuccess); 1024 } 1025 var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//); 1026 var mailtoRegex = new RegExp(/^mailto:/); 1027 var filterRegex = new RegExp("https:\/\/github\.com\/your-org\/atdata"); 1028 var isInternal = (href) => { 1029 return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href); 1030 } 1031 // Inspect non-navigation links and adorn them if external 1032 var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)'); 1033 for (var i=0; i<links.length; i++) { 1034 const link = links[i]; 1035 if (!isInternal(link.href)) { 1036 // undo the damage that might have been done by quarto-nav.js in the case of 1037 // links that we want to consider external 1038 if (link.dataset.originalHref !== undefined) { 1039 link.href = link.dataset.originalHref; 1040 } 1041 } 1042 } 1043 function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) { 1044 const config = { 1045 allowHTML: true, 1046 maxWidth: 500, 1047 delay: 100, 1048 arrow: false, 1049 appendTo: function(el) { 1050 return el.parentElement; 1051 }, 1052 interactive: true, 1053 interactiveBorder: 10, 1054 theme: 'quarto', 1055 placement: 'bottom-start', 1056 }; 1057 if (contentFn) { 1058 config.content = contentFn; 1059 } 1060 if (onTriggerFn) { 1061 config.onTrigger = onTriggerFn; 1062 } 1063 if (onUntriggerFn) { 1064 config.onUntrigger = onUntriggerFn; 1065 } 1066 window.tippy(el, config); 1067 } 1068 const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]'); 1069 for (var i=0; i<noterefs.length; i++) { 1070 const ref = noterefs[i]; 1071 tippyHover(ref, function() { 1072 // use id or data attribute instead here 1073 let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href'); 1074 try { href = new URL(href).hash; } catch {} 1075 const id = href.replace(/^#\/?/, ""); 1076 const note = window.document.getElementById(id); 1077 if (note) { 1078 return note.innerHTML; 1079 } else { 1080 return ""; 1081 } 1082 }); 1083 } 1084 const xrefs = window.document.querySelectorAll('a.quarto-xref'); 1085 const processXRef = (id, note) => { 1086 // Strip column container classes 1087 const stripColumnClz = (el) => { 1088 el.classList.remove("page-full", "page-columns"); 1089 if (el.children) { 1090 for (const child of el.children) { 1091 stripColumnClz(child); 1092 } 1093 } 1094 } 1095 stripColumnClz(note) 1096 if (id === null || id.startsWith('sec-')) { 1097 // Special case sections, only their first couple elements 1098 const container = document.createElement("div"); 1099 if (note.children && note.children.length > 2) { 1100 container.appendChild(note.children[0].cloneNode(true)); 1101 for (let i = 1; i < note.children.length; i++) { 1102 const child = note.children[i]; 1103 if (child.tagName === "P" && child.innerText === "") { 1104 continue; 1105 } else { 1106 container.appendChild(child.cloneNode(true)); 1107 break; 1108 } 1109 } 1110 if (window.Quarto?.typesetMath) { 1111 window.Quarto.typesetMath(container); 1112 } 1113 return container.innerHTML 1114 } else { 1115 if (window.Quarto?.typesetMath) { 1116 window.Quarto.typesetMath(note); 1117 } 1118 return note.innerHTML; 1119 } 1120 } else { 1121 // Remove any anchor links if they are present 1122 const anchorLink = note.querySelector('a.anchorjs-link'); 1123 if (anchorLink) { 1124 anchorLink.remove(); 1125 } 1126 if (window.Quarto?.typesetMath) { 1127 window.Quarto.typesetMath(note); 1128 } 1129 if (note.classList.contains("callout")) { 1130 return note.outerHTML; 1131 } else { 1132 return note.innerHTML; 1133 } 1134 } 1135 } 1136 for (var i=0; i<xrefs.length; i++) { 1137 const xref = xrefs[i]; 1138 tippyHover(xref, undefined, function(instance) { 1139 instance.disable(); 1140 let url = xref.getAttribute('href'); 1141 let hash = undefined; 1142 if (url.startsWith('#')) { 1143 hash = url; 1144 } else { 1145 try { hash = new URL(url).hash; } catch {} 1146 } 1147 if (hash) { 1148 const id = hash.replace(/^#\/?/, ""); 1149 const note = window.document.getElementById(id); 1150 if (note !== null) { 1151 try { 1152 const html = processXRef(id, note.cloneNode(true)); 1153 instance.setContent(html); 1154 } finally { 1155 instance.enable(); 1156 instance.show(); 1157 } 1158 } else { 1159 // See if we can fetch this 1160 fetch(url.split('#')[0]) 1161 .then(res => res.text()) 1162 .then(html => { 1163 const parser = new DOMParser(); 1164 const htmlDoc = parser.parseFromString(html, "text/html"); 1165 const note = htmlDoc.getElementById(id); 1166 if (note !== null) { 1167 const html = processXRef(id, note); 1168 instance.setContent(html); 1169 } 1170 }).finally(() => { 1171 instance.enable(); 1172 instance.show(); 1173 }); 1174 } 1175 } else { 1176 // See if we can fetch a full url (with no hash to target) 1177 // This is a special case and we should probably do some content thinning / targeting 1178 fetch(url) 1179 .then(res => res.text()) 1180 .then(html => { 1181 const parser = new DOMParser(); 1182 const htmlDoc = parser.parseFromString(html, "text/html"); 1183 const note = htmlDoc.querySelector('main.content'); 1184 if (note !== null) { 1185 // This should only happen for chapter cross references 1186 // (since there is no id in the URL) 1187 // remove the first header 1188 if (note.children.length > 0 && note.children[0].tagName === "HEADER") { 1189 note.children[0].remove(); 1190 } 1191 const html = processXRef(null, note); 1192 instance.setContent(html); 1193 } 1194 }).finally(() => { 1195 instance.enable(); 1196 instance.show(); 1197 }); 1198 } 1199 }, function(instance) { 1200 }); 1201 } 1202 let selectedAnnoteEl; 1203 const selectorForAnnotation = ( cell, annotation) => { 1204 let cellAttr = 'data-code-cell="' + cell + '"'; 1205 let lineAttr = 'data-code-annotation="' + annotation + '"'; 1206 const selector = 'span[' + cellAttr + '][' + lineAttr + ']'; 1207 return selector; 1208 } 1209 const selectCodeLines = (annoteEl) => { 1210 const doc = window.document; 1211 const targetCell = annoteEl.getAttribute("data-target-cell"); 1212 const targetAnnotation = annoteEl.getAttribute("data-target-annotation"); 1213 const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation)); 1214 const lines = annoteSpan.getAttribute("data-code-lines").split(","); 1215 const lineIds = lines.map((line) => { 1216 return targetCell + "-" + line; 1217 }) 1218 let top = null; 1219 let height = null; 1220 let parent = null; 1221 if (lineIds.length > 0) { 1222 //compute the position of the single el (top and bottom and make a div) 1223 const el = window.document.getElementById(lineIds[0]); 1224 top = el.offsetTop; 1225 height = el.offsetHeight; 1226 parent = el.parentElement.parentElement; 1227 if (lineIds.length > 1) { 1228 const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]); 1229 const bottom = lastEl.offsetTop + lastEl.offsetHeight; 1230 height = bottom - top; 1231 } 1232 if (top !== null && height !== null && parent !== null) { 1233 // cook up a div (if necessary) and position it 1234 let div = window.document.getElementById("code-annotation-line-highlight"); 1235 if (div === null) { 1236 div = window.document.createElement("div"); 1237 div.setAttribute("id", "code-annotation-line-highlight"); 1238 div.style.position = 'absolute'; 1239 parent.appendChild(div); 1240 } 1241 div.style.top = top - 2 + "px"; 1242 div.style.height = height + 4 + "px"; 1243 div.style.left = 0; 1244 let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter"); 1245 if (gutterDiv === null) { 1246 gutterDiv = window.document.createElement("div"); 1247 gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter"); 1248 gutterDiv.style.position = 'absolute'; 1249 const codeCell = window.document.getElementById(targetCell); 1250 const gutter = codeCell.querySelector('.code-annotation-gutter'); 1251 gutter.appendChild(gutterDiv); 1252 } 1253 gutterDiv.style.top = top - 2 + "px"; 1254 gutterDiv.style.height = height + 4 + "px"; 1255 } 1256 selectedAnnoteEl = annoteEl; 1257 } 1258 }; 1259 const unselectCodeLines = () => { 1260 const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"]; 1261 elementsIds.forEach((elId) => { 1262 const div = window.document.getElementById(elId); 1263 if (div) { 1264 div.remove(); 1265 } 1266 }); 1267 selectedAnnoteEl = undefined; 1268 }; 1269 // Handle positioning of the toggle 1270 window.addEventListener( 1271 "resize", 1272 throttle(() => { 1273 elRect = undefined; 1274 if (selectedAnnoteEl) { 1275 selectCodeLines(selectedAnnoteEl); 1276 } 1277 }, 10) 1278 ); 1279 function throttle(fn, ms) { 1280 let throttle = false; 1281 let timer; 1282 return (...args) => { 1283 if(!throttle) { // first call gets through 1284 fn.apply(this, args); 1285 throttle = true; 1286 } else { // all the others get throttled 1287 if(timer) clearTimeout(timer); // cancel #2 1288 timer = setTimeout(() => { 1289 fn.apply(this, args); 1290 timer = throttle = false; 1291 }, ms); 1292 } 1293 }; 1294 } 1295 // Attach click handler to the DT 1296 const annoteDls = window.document.querySelectorAll('dt[data-target-cell]'); 1297 for (const annoteDlNode of annoteDls) { 1298 annoteDlNode.addEventListener('click', (event) => { 1299 const clickedEl = event.target; 1300 if (clickedEl !== selectedAnnoteEl) { 1301 unselectCodeLines(); 1302 const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active'); 1303 if (activeEl) { 1304 activeEl.classList.remove('code-annotation-active'); 1305 } 1306 selectCodeLines(clickedEl); 1307 clickedEl.classList.add('code-annotation-active'); 1308 } else { 1309 // Unselect the line 1310 unselectCodeLines(); 1311 clickedEl.classList.remove('code-annotation-active'); 1312 } 1313 }); 1314 } 1315 const findCites = (el) => { 1316 const parentEl = el.parentElement; 1317 if (parentEl) { 1318 const cites = parentEl.dataset.cites; 1319 if (cites) { 1320 return { 1321 el, 1322 cites: cites.split(' ') 1323 }; 1324 } else { 1325 return findCites(el.parentElement) 1326 } 1327 } else { 1328 return undefined; 1329 } 1330 }; 1331 var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]'); 1332 for (var i=0; i<bibliorefs.length; i++) { 1333 const ref = bibliorefs[i]; 1334 const citeInfo = findCites(ref); 1335 if (citeInfo) { 1336 tippyHover(citeInfo.el, function() { 1337 var popup = window.document.createElement('div'); 1338 citeInfo.cites.forEach(function(cite) { 1339 var citeDiv = window.document.createElement('div'); 1340 citeDiv.classList.add('hanging-indent'); 1341 citeDiv.classList.add('csl-entry'); 1342 var biblioDiv = window.document.getElementById('ref-' + cite); 1343 if (biblioDiv) { 1344 citeDiv.innerHTML = biblioDiv.innerHTML; 1345 } 1346 popup.appendChild(citeDiv); 1347 }); 1348 return popup.innerHTML; 1349 }); 1350 } 1351 } 1352 }); 1353 </script> 1354</div> <!-- /content --> 1355<footer class="footer"> 1356 <div class="nav-footer"> 1357 <div class="nav-footer-left"> 1358<p>Built with <a href="https://quarto.org/">Quarto</a></p> 1359</div> 1360 <div class="nav-footer-center"> 1361 &nbsp; 1362 <div class="toc-actions d-sm-block d-md-none"><ul><li><a href="https://github.com/your-org/atdata/edit/main/api/Lens.qmd" class="toc-action"><i class="bi bi-github"></i>Edit this page</a></li><li><a href="https://github.com/your-org/atdata/issues/new" class="toc-action"><i class="bi empty"></i>Report an issue</a></li></ul></div></div> 1363 <div class="nav-footer-right"> 1364<p>MIT License</p> 1365</div> 1366 </div> 1367</footer> 1368 1369 1370 1371 1372</body></html>