SharpMeow commited on
Commit
7e83ef6
·
verified ·
1 Parent(s): 2e71a23

Fix array Open links to display Zarr metadata

Browse files
Files changed (1) hide show
  1. guide/index.html +12 -5
guide/index.html CHANGED
@@ -376,6 +376,7 @@ footer .wrap{max-width:1120px}#top[hidden]{display:none!important}
376
  </div>
377
  <div class="human-status" aria-live="polite"><span id="human-availability"></span></div>
378
  <div id="human-quick-links" class="human-quick-links" aria-label="Selected field data links"></div>
 
379
  <div class="human-actions"><button id="human-share" type="button">Copy page link</button>
380
  <p class="human-help">Share this scroll, scan and field selection.</p></div>
381
  <a class="human-make" href="?tab=make">Need a new field? Make a small box</a>
@@ -392,7 +393,7 @@ footer .wrap{max-width:1120px}#top[hidden]{display:none!important}
392
  <section class="human-data" id="human-data" aria-labelledby="human-data-title">
393
  <h3 id="human-data-title">Data and downloads</h3><p id="human-data-selection"></p>
394
  <h4>Field arrays</h4>
395
- <p>Copy a Zarr URL into a compatible reader. These are chunked arrays, not single-file downloads; opening a root in a browser may not show a page.</p>
396
  <div id="human-data-arrays" class="human-data-list"></div>
397
  <h4>Files and source</h4><p id="human-download-help"></p>
398
  <div id="human-data-files" class="human-data-list"></div>
@@ -838,10 +839,15 @@ function fallback(t,done){const a=document.createElement('textarea');a.value=t;d
838
  const arrays = f?.availability?.arrays;
839
  return {nx:url(arrays?.nx?.url), ny:url(arrays?.ny?.url)};
840
  }
 
 
 
 
 
841
  function dataLinks(f) {
842
  if (!f) return [];
843
  const a=f.normals_access || {}, d=a.download || {}, n=normals(f), rows=[];
844
- const add=(key,label,format,value,kind)=>{const href=url(value);if(href)rows.push({key,label,format,href,kind});};
845
  for (const [key,label] of [['nx','Normals (nx)'],['ny','Normals (ny)'],['cos','Layer pattern (cos)'],['grad_mag','Gradient magnitude']]) {
846
  const array=f.availability?.arrays?.[key];
847
  add(key,label,'Zarr array',key==='nx'||key==='ny'?n[key]:array?.url,'zarr');
@@ -893,7 +899,7 @@ function fallback(t,done){const a=document.createElement('textarea');a.value=t;d
893
  el('quick-links').replaceChildren(...rows.filter(row=>row.kind==='zarr'||row.key==='source').map(row=>{
894
  const line=document.createElement('div');line.className='human-quick-row';line.dataset.key=row.key;
895
  const name=document.createElement('span');name.textContent=row.kind==='zarr'?row.label:d.kind==='hf_dataset_bundle'?'TAR bundle files':'Source files';
896
- const open=document.createElement('a');open.href=row.href;open.target='_blank';open.rel='noopener';open.textContent='Open';open.setAttribute('aria-label','Open '+row.label);
897
  const button=document.createElement('button');button.type='button';button.textContent='Copy URL';button.setAttribute('aria-label','Copy URL for '+row.label);
898
  button.onclick=async()=>{const ok=await copy(row.href,row.label+' URL copied.');button.textContent=ok?'Copied':'Select URL below';setTimeout(()=>{button.textContent='Copy URL';},1600);};
899
  line.append(name,open,button);return line;
@@ -909,10 +915,11 @@ function fallback(t,done){const a=document.createElement('textarea');a.value=t;d
909
  const title=document.createElement('strong');title.textContent=row.label;
910
  const format=document.createElement('small');format.textContent=row.format;
911
  const actions=document.createElement('div');actions.className='human-data-actions';
912
- const open=document.createElement('a');open.href=row.href;open.target='_blank';open.rel='noopener';open.textContent='Open';open.setAttribute('aria-label','Open '+row.label);
913
  const button=document.createElement('button');button.type='button';button.textContent='Copy URL';button.setAttribute('aria-label','Copy URL for '+row.label);
914
  button.onclick=async()=>{const ok=await copy(row.href,row.label+' URL copied.');button.textContent=ok?'Copied':'Select URL';setTimeout(()=>{button.textContent='Copy URL';},1600);};
915
- const address=document.createElement('a');address.className='human-data-url';address.href=row.href;address.target='_blank';address.rel='noopener';address.textContent=row.href;
 
916
  actions.append(open,button);card.append(title,format,actions,address);return card;
917
  }));
918
  if (!list.length) el('data-'+group).textContent='No '+(group==='arrays'?'array':'file')+' links listed for this selection.';
 
376
  </div>
377
  <div class="human-status" aria-live="polite"><span id="human-availability"></span></div>
378
  <div id="human-quick-links" class="human-quick-links" aria-label="Selected field data links"></div>
379
+ <p class="human-help">For arrays, Open shows metadata. Copy URL gives the Zarr address for your tools.</p>
380
  <div class="human-actions"><button id="human-share" type="button">Copy page link</button>
381
  <p class="human-help">Share this scroll, scan and field selection.</p></div>
382
  <a class="human-make" href="?tab=make">Need a new field? Make a small box</a>
 
393
  <section class="human-data" id="human-data" aria-labelledby="human-data-title">
394
  <h3 id="human-data-title">Data and downloads</h3><p id="human-data-selection"></p>
395
  <h4>Field arrays</h4>
396
+ <p>Open shows the array's metadata. Copy URL gives its Zarr address for a compatible reader. These are chunked arrays, not single-file downloads.</p>
397
  <div id="human-data-arrays" class="human-data-list"></div>
398
  <h4>Files and source</h4><p id="human-download-help"></p>
399
  <div id="human-data-files" class="human-data-list"></div>
 
839
  const arrays = f?.availability?.arrays;
840
  return {nx:url(arrays?.nx?.url), ny:url(arrays?.ny?.url)};
841
  }
842
+ function arrayMetadataURL(value) {
843
+ const address=new URL(value);
844
+ address.pathname=address.pathname.replace(/\/+$/,'')+'/.zarray';
845
+ return address.href;
846
+ }
847
  function dataLinks(f) {
848
  if (!f) return [];
849
  const a=f.normals_access || {}, d=a.download || {}, n=normals(f), rows=[];
850
+ const add=(key,label,format,value,kind)=>{const href=url(value);if(href)rows.push({key,label,format,href,openHref:kind==='zarr'?arrayMetadataURL(href):href,kind});};
851
  for (const [key,label] of [['nx','Normals (nx)'],['ny','Normals (ny)'],['cos','Layer pattern (cos)'],['grad_mag','Gradient magnitude']]) {
852
  const array=f.availability?.arrays?.[key];
853
  add(key,label,'Zarr array',key==='nx'||key==='ny'?n[key]:array?.url,'zarr');
 
899
  el('quick-links').replaceChildren(...rows.filter(row=>row.kind==='zarr'||row.key==='source').map(row=>{
900
  const line=document.createElement('div');line.className='human-quick-row';line.dataset.key=row.key;
901
  const name=document.createElement('span');name.textContent=row.kind==='zarr'?row.label:d.kind==='hf_dataset_bundle'?'TAR bundle files':'Source files';
902
+ const open=document.createElement('a');open.href=row.openHref;open.target='_blank';open.rel='noopener';open.textContent='Open';open.setAttribute('aria-label','Open '+row.label);
903
  const button=document.createElement('button');button.type='button';button.textContent='Copy URL';button.setAttribute('aria-label','Copy URL for '+row.label);
904
  button.onclick=async()=>{const ok=await copy(row.href,row.label+' URL copied.');button.textContent=ok?'Copied':'Select URL below';setTimeout(()=>{button.textContent='Copy URL';},1600);};
905
  line.append(name,open,button);return line;
 
915
  const title=document.createElement('strong');title.textContent=row.label;
916
  const format=document.createElement('small');format.textContent=row.format;
917
  const actions=document.createElement('div');actions.className='human-data-actions';
918
+ const open=document.createElement('a');open.href=row.openHref;open.target='_blank';open.rel='noopener';open.textContent='Open';open.setAttribute('aria-label','Open '+row.label);
919
  const button=document.createElement('button');button.type='button';button.textContent='Copy URL';button.setAttribute('aria-label','Copy URL for '+row.label);
920
  button.onclick=async()=>{const ok=await copy(row.href,row.label+' URL copied.');button.textContent=ok?'Copied':'Select URL';setTimeout(()=>{button.textContent='Copy URL';},1600);};
921
+ const address=document.createElement(row.kind==='zarr'?'code':'a');address.className='human-data-url';address.textContent=row.href;
922
+ if(row.kind!=='zarr'){address.href=row.href;address.target='_blank';address.rel='noopener';}
923
  actions.append(open,button);card.append(title,format,actions,address);return card;
924
  }));
925
  if (!list.length) el('data-'+group).textContent='No '+(group==='arrays'?'array':'file')+' links listed for this selection.';