diff --git a/assets/css/atlas.css b/assets/css/atlas.css index d6f9f4a..136358a 100644 --- a/assets/css/atlas.css +++ b/assets/css/atlas.css @@ -8,6 +8,7 @@ --ease-out:cubic-bezier(.3,.7,.3,1);--dur-fast:.2s;--dur-base:.4s;--dur-slow:1s; --target:44px; box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px); + padding-left:env(safe-area-inset-left,0px);padding-right:env(safe-area-inset-right,0px); } @media (prefers-color-scheme:dark){:root:not([data-theme="light"]){ --sky:#0C1526;--ink:#ECE6D5;--faint:#8593AD;--line:#2C3E5E;--panel:#101C33;--panel-line:#25395B;--control-line:#61749A;--hover:#1A2B4A;--bgstar:#C9D3E8;--halo:.22; @@ -53,7 +54,7 @@ button{font:inherit;color:inherit} .cmp .relring{fill:none;stroke:var(--c);stroke-width:1.25;opacity:0} .cmp.rel .relring{opacity:.9} .cmp .lbl{font-size:var(--text-sm);fill:var(--ink);opacity:0;transition:opacity var(--dur-fast) var(--ease-out)} -#sky.deep .cmp .lbl{opacity:.9} +#sky.deep:not(.focused) .cmp:not(.lbl-off) .lbl,#sky.deep .is-focus .cmp:not(.lbl-off) .lbl{opacity:.9} .cmp:hover .lbl,.cmp:focus-visible .lbl,.cmp.sel .lbl,.cmp.rel .lbl{opacity:1} .cmp.sel .core{stroke:var(--ink);stroke-width:2} .cmp.sel .lbl{font-weight:600} @@ -139,6 +140,8 @@ input:focus-visible,select:focus-visible,button:focus-visible,a:focus-visible{ou /* touch: 44px targets; small text buttons get an invisible hit area so layout doesn't shift */ @media (pointer:coarse){ .search input,.filter select,.btn{height:var(--target)} + /* 16px stops mobile browsers zooming the page when a field gets focus */ + .search input,.filter select{font-size:16px} .results button,.list button{min-height:var(--target)} .close{width:var(--target);height:var(--target);top:8px;right:8px} .crumbs button,.kind button{position:relative} diff --git a/assets/js/atlas.js b/assets/js/atlas.js index be257fa..64d301a 100644 --- a/assets/js/atlas.js +++ b/assets/js/atlas.js @@ -118,6 +118,27 @@ const zoom=d3.zoom().scaleExtent([.2,12]).on('zoom',e=>{ if(e.sourceEvent) hideHint(); }); svg.call(zoom).on('dblclick.zoom',null); +zoom.on('end',declutter); + +// Labels keep a fixed screen size, so on narrow screens they collide once zoomed in. +// After each zoom, place labels greedily (selected, related, focused, then the rest) +// and hide any that would overlap one already placed. Hover and tap still reveal them. +function declutter(){ + cn.classed('lbl-off',false); + if(!svgEl.classList.contains('deep')) return; + const box=el=>{const r=el.getBoundingClientRect(); return {l:r.left-3,t:r.top-1,r:r.right+3,b:r.bottom+1};}; + const hits=(a,b)=>a.ln.classList.contains('sel')?0:n.classList.contains('rel')?1:n.closest('.is-focus')?2:3; + const nodes=cn.nodes().filter(n=>!n.classList.contains('muted')&&(!state.focus||rank(n)<3)) + .map((n,i)=>({n,i,k:rank(n)})).sort((a,b)=>a.k-b.k||a.i-b.i); + for(const {n,k} of nodes){ + const b=box(n.querySelector('.lbl')); + if(k>1&&kept.some(o=>hits(o,b))) n.classList.add('lbl-off'); else kept.push(b); + } +} function viewportBox(ignorePanel){ const r=svgEl.getBoundingClientRect(), tb=topEl.getBoundingClientRect(), mobile=r.width<=720; @@ -163,7 +184,7 @@ function apply(){ svgEl.classList.toggle('focused',!!state.focus); sg.classed('is-focus',d=>d.id===state.focus); cn.classed('sel',d=>d.id===state.sel); - drawThreads(); renderCrumbs(); + drawThreads(); renderCrumbs(); declutter(); } function drawThreads(){ const n=state.sel&&N[state.sel]; @@ -195,6 +216,7 @@ function inPlan(c){ } function applyLicence(){ cn.classed('muted',d=>!inPlan(d)); + declutter(); panel.querySelectorAll('.list [data-go]').forEach(b=>{ const h=!inPlan(N[b.dataset.go]); b.classList.toggle('is-muted',h);