region-forms.html 11.8 KB
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>区域分布 · 图表形态对照</title>
<style>
  :root{
    --hm-primary:#4653a2; --hm-primary-wash:rgba(70,83,162,.10); --hm-primary-wash-strong:rgba(70,83,162,.18);
    --hm-accent-cyan:#28a7e1; --hm-bg:#f5f6f9; --hm-divider:#ededed;
    --hm-text-1:#222; --hm-text-2:#555a66; --hm-text-3:#8c8c8c; --hm-radius:10px; --hm-radius-lg:14px;
  }
  *{box-sizing:border-box}
  body{margin:0;background:#e9ebf0;font-family:'DM Sans',system-ui,-apple-system,'PingFang SC','Microsoft YaHei',sans-serif;color:var(--hm-text-1);padding:24px;}
  .wrap{max-width:620px;margin:0 auto}
  .tabs{display:flex;gap:6px;margin-bottom:14px;flex-wrap:wrap}
  .tab{font:inherit;font-size:13px;padding:7px 14px;border-radius:999px;border:1px solid var(--hm-divider);background:#fff;color:var(--hm-text-2);cursor:pointer;transition:.15s}
  .tab:hover{border-color:var(--hm-primary)}
  .tab.on{background:var(--hm-primary);color:#fff;border-color:var(--hm-primary)}
  .card{width:100%;background:#fff;border-radius:var(--hm-radius-lg);box-shadow:0 6px 22px rgba(34,43,95,.10);padding:18px}
  .head{display:flex;align-items:center;gap:8px;margin-bottom:4px}
  .head .ico{width:22px;height:22px;border-radius:7px;background:linear-gradient(180deg,var(--hm-primary),var(--hm-accent-cyan));display:flex;align-items:center;justify-content:center;color:#fff;font-size:12px}
  .head h3{margin:0;font-size:14px;font-weight:600}
  .head .spot{margin-left:auto;font-size:11px;color:var(--hm-text-3)}
  .legend{font-size:11px;color:var(--hm-text-3);margin:2px 0 14px;line-height:1.6}
  .note{margin-top:14px;font-size:11px;color:var(--hm-text-3);line-height:1.6;border-top:1px solid var(--hm-divider);padding-top:10px}

  /* 通用 heat */
  .list{display:flex;flex-direction:column;gap:10px}
  .chip{flex:0 0 auto;width:20px;height:20px;border-radius:7px;display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:700}
  .chip.top{background:var(--hm-primary);color:#fff}
  .chip.rest{border:1px solid var(--hm-text-3);color:var(--hm-text-3)}

  /* ===== 现状:横条 ===== */
  .row-old{display:flex;flex-direction:column;gap:4px}
  .row-old .top{display:flex;justify-content:space-between;font-size:12px}
  .row-old .name{color:var(--hm-text-2)}
  .row-old .val{font-weight:600;font-variant-numeric:tabular-nums}.row-old .val em{font-style:normal;font-weight:400;font-size:11px;color:var(--hm-text-3);margin-left:5px}
  .row-old .track{height:5px;background:var(--hm-divider);border-radius:3px;overflow:hidden}
  .row-old .fill{height:100%}

  /* ===== A 棒糖图 ===== */
  .row-lol{display:flex;align-items:center;gap:10px;padding:5px 8px;margin:0 -8px;border-radius:9px;cursor:pointer;transition:background .15s}
  .row-lol:hover{background:var(--hm-primary-wash)}
  .row-lol.is-active{background:var(--hm-primary-wash);box-shadow:inset 2px 0 0 var(--hm-primary)}
  .lol-body{flex:1 1 auto;min-width:0;position:relative;height:34px}
  .lol-base{position:absolute;left:0;right:0;top:22px;height:2px;background:var(--hm-divider);border-radius:2px}
  .lol-stem{position:absolute;left:0;top:22px;height:2px;border-radius:2px}
  .lol-dot{position:absolute;top:14px;width:16px;height:16px;border-radius:50%;transform:translateX(-50%);box-shadow:0 1px 3px rgba(0,0,0,.18)}
  .lol-name{position:absolute;left:0;top:0;font-size:12px;color:var(--hm-text-2);font-weight:500}
  .lol-val{position:absolute;right:0;top:0;font-size:12px;font-weight:700;font-variant-numeric:tabular-nums}
  .lol-val em{font-style:normal;font-weight:400;font-size:10px;color:var(--hm-text-3);margin-left:4px}

  /* ===== B 气泡/方块网格 ===== */
  .grid{display:flex;flex-wrap:wrap;gap:10px;align-content:flex-start}
  .tile{border-radius:14px;display:flex;flex-direction:column;justify-content:space-between;padding:10px 12px;cursor:pointer;transition:transform .12s,box-shadow .12s;color:#fff;position:relative;overflow:hidden}
  .tile:hover{transform:translateY(-2px);box-shadow:0 6px 16px rgba(34,43,95,.22)}
  .tile.is-active{outline:3px solid var(--hm-primary);outline-offset:1px}
  .tile .rk{font-size:11px;font-weight:700;opacity:.85}
  .tile .nm{font-size:13px;font-weight:600;line-height:1.2}
  .tile .ct{font-size:18px;font-weight:800;font-variant-numeric:tabular-nums;margin-top:2px}
  .tile .pc{font-size:10px;opacity:.82;margin-top:1px}

  /* ===== C 占比条带(100% 堆叠) ===== */
  .strip{display:flex;height:38px;border-radius:9px;overflow:hidden;border:1px solid var(--hm-divider)}
  .seg{height:100%;display:flex;align-items:center;justify-content:center;cursor:pointer;position:relative;transition:filter .15s;min-width:0}
  .seg:hover{filter:brightness(1.08)}
  .seg.is-active{box-shadow:inset 0 0 0 3px #fff, inset 0 0 0 5px var(--hm-primary)}
  .seg span{font-size:11px;font-weight:700;color:#fff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding:0 4px}
  .stlegend{display:flex;flex-wrap:wrap;gap:8px 14px;margin-top:12px}
  .stitem{display:flex;align-items:center;gap:6px;font-size:11px;color:var(--hm-text-2);cursor:pointer}
  .stitem:hover{color:var(--hm-primary)}
  .dot{width:10px;height:10px;border-radius:3px;flex:0 0 auto}
  .stitem b{font-variant-numeric:tabular-nums;color:var(--hm-text-1);font-weight:600}
  .unresolved{display:flex;justify-content:space-between;margin-top:12px;padding-top:10px;border-top:1px dashed var(--hm-divider);font-size:12px;color:var(--hm-text-3)}
  .unresolved b{color:var(--hm-text-2);font-weight:500}
</style>
</head>
<body>
<div class="wrap">
  <div class="tabs" id="tabs">
    <button class="tab" data-k="old">现状·横条</button>
    <button class="tab on" data-k="lol">A 棒糖图</button>
    <button class="tab" data-k="grid">B 气泡网格</button>
    <button class="tab" data-k="strip">C 占比条带</button>
  </div>
  <div class="card">
    <div class="head"><span class="ico">▦</span><h3>区域分布(TOP 8)</h3><span class="spot">⦿ 在地图查看</span></div>
    <p class="legend" id="legend"></p>
    <div id="view"></div>
    <p class="note" id="note"></p>
  </div>
</div>

<script>
  const rows = [
    {name:'福田区',n:12840,p:22.0},{name:'宝安区',n:10512,p:18.0},{name:'龙岗区',n:9033,p:15.5},
    {name:'南山区',n:7621,p:13.1},{name:'罗湖区',n:5940,p:10.2},{name:'龙华区',n:4810,p:8.2},
    {name:'光明区',n:3205,p:5.5},{name:'坪山区',n:2140,p:3.7},
  ];
  const max=rows[0].n, total=rows.reduce((s,r)=>s+r.n,0);
  const oldColors=['#4653a2','#28a7e1','#5fb6e6','#7B8AD1','#E08A2E','#9AA3CC','#8aa0e0','#b8bddc'];
  function heat(t){t=Math.max(0,Math.min(1,t));const lo=[240,168,156],hi=[192,52,44];const c=lo.map((v,i)=>Math.round(v+(hi[i]-v)*t));return `rgb(${c[0]},${c[1]},${c[2]})`;}
  function lum(c){const m=c.match(/\d+/g).map(Number);return (0.2126*m[0]+0.7152*m[1]+0.0722*m[2])/255;}
  const ink=c=>lum(c)<0.5?'#fff':'#222';

  const meta={
    old:{legend:'现状:5px 灰底细条 + 循环分类色。颜色不表达量级,各区长得一个样(基线参照)。',
      note:'—— 仅作对照,不参与选型。'},
    lol:{legend:'A 棒糖图:细基线 + 红热圆点标量级(越红越多)。比实心横条轻、不"块",仍保留排行列表与逐行点击。',
      note:'适合:想保留"排行列表 + 可点行"的交互,但嫌横条太死板。损失:填充面积感弱于横条,量级靠点的位置和颜色读。'},
    grid:{legend:'B 气泡/方块网格:每区一块圆角瓦片,面积∝案件量、按名次红热、带名次号。彻底脱离"列表横条"。',
      note:'适合:强调"谁最大块"、视觉更活泼。代价:排行靠面积+数字,精确比较弱于列表;窄栏里大块会占较多竖向空间。可只取 TOP 6 控高。'},
    strip:{legend:'C 占比条带:一条按份额切分的色带,看"全市案量在各区怎么分" + 名次色序。点色块=只看该区。',
      note:'适合:强调"构成/占比",和横条完全不一样的形态。代价:单区起数不直接标在条上(靠下方图例读数);区段太窄时不显名,需悬浮。'},
  };

  function render(k){
    const view=document.getElementById('view');
    document.getElementById('legend').textContent=meta[k].legend;
    document.getElementById('note').textContent=meta[k].note;
    view.innerHTML='';
    if(k==='old'){
      rows.forEach((r,i)=>{const w=(r.n/max*100).toFixed(1);
        view.insertAdjacentHTML('beforeend',`<div class="row-old"><div class="top"><span class="name">${r.name}</span><span class="val">${r.n.toLocaleString()}<em>${r.p}%</em></span></div><div class="track"><div class="fill" style="width:${w}%;background:${oldColors[i%oldColors.length]}"></div></div></div>`);});
      view.insertAdjacentHTML('beforeend',`<div class="unresolved"><span>未标注行政区</span><b>1,880</b></div>`);
      return;
    }
    if(k==='lol'){
      const list=document.createElement('div');list.className='list';
      rows.forEach((r,i)=>{const w=(r.n/max*100).toFixed(1);const t=Math.pow(r.n/max,0.7);const c=heat(t);
        const row=document.createElement('div');row.className='row-lol';
        row.innerHTML=`<span class="chip ${i<3?'top':'rest'}">${i+1}</span>
          <div class="lol-body"><div class="lol-name">${r.name}</div><div class="lol-val">${r.n.toLocaleString()}<em>${r.p}%</em></div>
          <div class="lol-base"></div><div class="lol-stem" style="width:${w}%;background:${c}"></div>
          <div class="lol-dot" style="left:${w}%;background:${c}"></div></div>`;
        row.addEventListener('click',()=>row.classList.toggle('is-active'));list.appendChild(row);});
      view.appendChild(list);
      view.insertAdjacentHTML('beforeend',`<div class="unresolved"><span>未标注行政区</span><b>1,880</b></div>`);
      return;
    }
    if(k==='grid'){
      const grid=document.createElement('div');grid.className='grid';
      rows.forEach((r,i)=>{const t=Math.pow(r.n/max,0.7);const c=heat(t);const sz=64+Math.sqrt(r.n/max)*86;
        const tile=document.createElement('div');tile.className='tile';tile.style.width=sz+'px';tile.style.height=sz+'px';tile.style.background=c;tile.style.color=ink(c);
        tile.innerHTML=`<div class="rk">#${i+1}</div><div><div class="nm">${r.name}</div><div class="ct">${r.n.toLocaleString()}</div><div class="pc">${r.p}%</div></div>`;
        tile.addEventListener('click',()=>tile.classList.toggle('is-active'));grid.appendChild(tile);});
      view.appendChild(grid);
      view.insertAdjacentHTML('beforeend',`<div class="unresolved"><span>未标注行政区</span><b>1,880</b></div>`);
      return;
    }
    if(k==='strip'){
      const strip=document.createElement('div');strip.className='strip';
      rows.forEach((r,i)=>{const w=(r.n/total*100);const t=Math.pow(r.n/max,0.7);const c=heat(t);
        const seg=document.createElement('div');seg.className='seg';seg.style.width=w+'%';seg.style.background=c;seg.title=`${r.name} ${r.n.toLocaleString()}(${r.p}%)`;
        if(w>7)seg.innerHTML=`<span>${w>=12?r.name:('#'+(i+1))}</span>`;
        seg.addEventListener('click',()=>seg.classList.toggle('is-active'));strip.appendChild(seg);});
      view.appendChild(strip);
      const lg=document.createElement('div');lg.className='stlegend';
      rows.forEach((r,i)=>{const t=Math.pow(r.n/max,0.7);const c=heat(t);
        lg.insertAdjacentHTML('beforeend',`<div class="stitem" title="点击在地图只看该区"><span class="dot" style="background:${c}"></span>#${i+1} ${r.name} <b>${r.n.toLocaleString()}</b> ${r.p}%</div>`);});
      view.appendChild(lg);
      view.insertAdjacentHTML('beforeend',`<div class="unresolved"><span>未标注行政区</span><b>1,880</b></div>`);
      return;
    }
  }
  document.getElementById('tabs').addEventListener('click',e=>{const b=e.target.closest('.tab');if(!b)return;
    document.querySelectorAll('.tab').forEach(t=>t.classList.remove('on'));b.classList.add('on');render(b.dataset.k);});
  render('lol');
</script>
</body>
</html>