Интерактивный граф: /graph.html — canvas с силовой укладкой без внешних библиотек, подсветка соседей, клик по узлу, поиск, зум и перетаскивание. Доступен через панель ядра (status.buryans.ru/hub/graph.html). Подбор по настроению: /mood с словарём тем и жанров (мрачное, лёгкое, умное, эпичное, страшное, детектив). Сначала искал только по темам и на маленькой библиотеке давал пустоту — добавление жанров исправило. Недельный дайджест media_digest.py: понедельник 09:00 в личный чат бота Медиа — фильмы, книги, связи, книги-экранизации, кандидаты. Копия в ядре. Ловушка: токены в bots.env, а актуальные комнаты — в dm.env. Комната из bots.env даёт 403 Forbidden (старые комнаты).
212 lines
7.8 KiB
HTML
212 lines
7.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Граф контента — Buryans Hub</title>
|
|
<style>
|
|
:root { --bg:#0d1117; --fg:#c9d1d9; --dim:#8b949e; --line:#30363d; }
|
|
* { box-sizing: border-box; }
|
|
body { margin:0; background:var(--bg); color:var(--fg);
|
|
font:14px/1.5 -apple-system,"Segoe UI",Roboto,sans-serif; overflow:hidden; }
|
|
#top { position:fixed; top:0; left:0; right:0; height:52px; display:flex;
|
|
align-items:center; gap:14px; padding:0 16px;
|
|
background:rgba(13,17,23,.92); border-bottom:1px solid var(--line); z-index:5; }
|
|
#top h1 { font-size:15px; margin:0; font-weight:600; }
|
|
#top .stat { color:var(--dim); font-size:12px; }
|
|
#search { margin-left:auto; background:#161b22; border:1px solid var(--line);
|
|
color:var(--fg); border-radius:6px; padding:6px 10px; width:240px; outline:none; }
|
|
#legend { position:fixed; left:16px; bottom:16px; background:rgba(22,27,34,.92);
|
|
border:1px solid var(--line); border-radius:8px; padding:10px 12px;
|
|
font-size:12px; z-index:5; max-width:220px; }
|
|
#legend div { display:flex; align-items:center; gap:8px; margin:3px 0; }
|
|
.dot { width:10px; height:10px; border-radius:50%; flex:none; }
|
|
#info { position:fixed; right:16px; bottom:16px; width:280px; max-height:50vh;
|
|
overflow:auto; background:rgba(22,27,34,.95); border:1px solid var(--line);
|
|
border-radius:8px; padding:12px; font-size:12px; z-index:5; display:none; }
|
|
#info b { color:#fff; }
|
|
#info ul { margin:8px 0 0; padding-left:16px; }
|
|
canvas { display:block; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="top">
|
|
<h1>Граф контента</h1>
|
|
<span class="stat" id="stat">загрузка…</span>
|
|
<input id="search" placeholder="Найти карточку…">
|
|
</div>
|
|
<div id="legend"></div>
|
|
<div id="info"></div>
|
|
<canvas id="c"></canvas>
|
|
<script>
|
|
const COLORS = {
|
|
"фильм":"#58a6ff","книга":"#3fb950","жанр":"#d29922","тема":"#a371f7",
|
|
"актёр":"#f0883e","режиссёр":"#f85149","композитор":"#db61a2",
|
|
"студия":"#39c5cf","коллекция":"#e3b341","серия книг":"#7ee787",
|
|
"автор":"#ffa657","эпоха":"#8b949e","кандидат":"#484f58","оценка":"#bc8cff",
|
|
"язык":"#79c0ff","рейтинг":"#ff7b72"
|
|
};
|
|
const c = document.getElementById("c"), ctx = c.getContext("2d");
|
|
let W=0,H=0, nodes=[], edges=[], byId={}, hover=null, selected=null, query="";
|
|
let cam={x:0,y:0,k:1};
|
|
|
|
function resize(){
|
|
W = c.width = innerWidth * devicePixelRatio;
|
|
H = c.height = innerHeight * devicePixelRatio;
|
|
c.style.width = innerWidth+"px"; c.style.height = innerHeight+"px";
|
|
}
|
|
addEventListener("resize", resize); resize();
|
|
|
|
fetch("graph?json").then(r=>r.json()).then(d=>{
|
|
const raw = d.nodes || [];
|
|
byId = {};
|
|
nodes = raw.map((n,i)=>{
|
|
const a = i / raw.length * Math.PI * 2;
|
|
const r = 120 + Math.random()*260;
|
|
const o = {id:n.id,title:n.title,kind:n.kind,degree:n.degree||1,
|
|
x:Math.cos(a)*r, y:Math.sin(a)*r, vx:0, vy:0};
|
|
byId[n.id]=o; return o;
|
|
});
|
|
edges = (d.edges||[]).map(e=>({s:+e.source,t:+e.target,r:e.relation}))
|
|
.filter(e=>byId[e.s]&&byId[e.t]);
|
|
document.getElementById("stat").textContent =
|
|
nodes.length+" карточек · "+edges.length+" связей";
|
|
buildLegend();
|
|
requestAnimationFrame(tick);
|
|
});
|
|
|
|
function buildLegend(){
|
|
const kinds = [...new Set(nodes.map(n=>n.kind))]
|
|
.sort((a,b)=>nodes.filter(n=>n.kind===b).length-nodes.filter(n=>n.kind===a).length);
|
|
const el = document.getElementById("legend");
|
|
el.innerHTML = kinds.map(k=>{
|
|
const n = nodes.filter(x=>x.kind===k).length;
|
|
return `<div><span class="dot" style="background:${COLORS[k]||'#666'}"></span>
|
|
${k} <span style="color:#8b949e">${n}</span></div>`;
|
|
}).join("");
|
|
}
|
|
|
|
function tick(){
|
|
// силы
|
|
for (let i=0;i<nodes.length;i++){
|
|
const a = nodes[i];
|
|
for (let j=i+1;j<nodes.length;j++){
|
|
const b = nodes[j];
|
|
let dx = b.x-a.x, dy = b.y-a.y, d2 = dx*dx+dy*dy+0.01;
|
|
if (d2 > 90000) continue;
|
|
const f = 900 / d2;
|
|
const d = Math.sqrt(d2);
|
|
dx/=d; dy/=d;
|
|
a.vx -= dx*f; a.vy -= dy*f; b.vx += dx*f; b.vy += dy*f;
|
|
}
|
|
}
|
|
for (const e of edges){
|
|
const a = byId[e.s], b = byId[e.t];
|
|
let dx=b.x-a.x, dy=b.y-a.y, d=Math.hypot(dx,dy)||1;
|
|
const f = (d-110) * 0.0016;
|
|
dx/=d; dy/=d;
|
|
a.vx += dx*f*d*0.02; a.vy += dy*f*d*0.02;
|
|
b.vx -= dx*f*d*0.02; b.vy -= dy*f*d*0.02;
|
|
}
|
|
for (const n of nodes){
|
|
n.vx += -n.x*0.0008; n.vy += -n.y*0.0008;
|
|
n.vx *= 0.94; n.vy *= 0.94;
|
|
n.x += n.vx; n.y += n.vy;
|
|
}
|
|
draw();
|
|
requestAnimationFrame(tick);
|
|
}
|
|
|
|
function draw(){
|
|
ctx.setTransform(1,0,0,1,0,0);
|
|
ctx.clearRect(0,0,W,H);
|
|
ctx.fillStyle="#0d1117"; ctx.fillRect(0,0,W,H);
|
|
const dp = devicePixelRatio;
|
|
ctx.setTransform(cam.k*dp,0,0,cam.k*dp, W/2+cam.x*dp, H/2+cam.y*dp);
|
|
|
|
const hi = selected || hover;
|
|
const near = new Set();
|
|
if (hi){
|
|
near.add(hi.id);
|
|
for (const e of edges){
|
|
if (e.s===hi.id) near.add(e.t);
|
|
if (e.t===hi.id) near.add(e.s);
|
|
}
|
|
}
|
|
for (const e of edges){
|
|
const a=byId[e.s], b=byId[e.t];
|
|
const on = !hi || (near.has(a.id)&&near.has(b.id));
|
|
ctx.strokeStyle = on ? "rgba(88,166,255,.45)" : "rgba(48,54,61,.35)";
|
|
ctx.lineWidth = on ? 1.2 : 0.6;
|
|
ctx.beginPath(); ctx.moveTo(a.x,a.y); ctx.lineTo(b.x,b.y); ctx.stroke();
|
|
}
|
|
for (const n of nodes){
|
|
const r = 3 + Math.min(9, Math.sqrt(n.degree));
|
|
const col = COLORS[n.kind] || "#8b949e";
|
|
const match = query && n.title.toLowerCase().includes(query);
|
|
ctx.beginPath();
|
|
ctx.arc(n.x, n.y, r, 0, Math.PI*2);
|
|
ctx.fillStyle = (!hi || near.has(n.id)) ? col : "#2a2f36";
|
|
ctx.globalAlpha = match ? 1 : (hi && !near.has(n.id) ? 0.35 : 0.95);
|
|
ctx.fill();
|
|
ctx.globalAlpha = 1;
|
|
if (match){
|
|
ctx.strokeStyle="#fff"; ctx.lineWidth=2; ctx.stroke();
|
|
}
|
|
const show = n.degree > 20 || (hi && near.has(n.id)) || match;
|
|
if (show && cam.k > 0.55){
|
|
ctx.fillStyle = match ? "#fff" : "#c9d1d9";
|
|
ctx.font = (r+8)+"px -apple-system,Segoe UI,sans-serif";
|
|
ctx.textAlign="center";
|
|
ctx.fillText(n.title.slice(0,28), n.x, n.y - r - 5);
|
|
}
|
|
}
|
|
}
|
|
|
|
function locate(e){
|
|
const dp = devicePixelRatio;
|
|
return {x:(e.clientX*dp - W/2 - cam.x*dp)/(cam.k*dp),
|
|
y:(e.clientY*dp - H/2 - cam.y*dp)/(cam.k*dp)};
|
|
}
|
|
|
|
c.addEventListener("mousemove", e=>{
|
|
const p = locate(e);
|
|
hover = nodes.find(n=>Math.hypot(n.x-p.x, n.y-p.y) < 10/cam.k*2) || null;
|
|
c.style.cursor = hover ? "pointer" : "default";
|
|
});
|
|
let drag=null;
|
|
c.addEventListener("mousedown", e=>{ drag={x:e.clientX,y:e.clientY,cx:cam.x,cy:cam.y}; });
|
|
addEventListener("mouseup", ()=>{ drag=null; });
|
|
addEventListener("mousemove", e=>{
|
|
if (!drag) return;
|
|
cam.x = drag.cx + (e.clientX - drag.x);
|
|
cam.y = drag.cy + (e.clientY - drag.y);
|
|
});
|
|
c.addEventListener("wheel", e=>{
|
|
e.preventDefault();
|
|
cam.k *= e.deltaY < 0 ? 1.1 : 0.9;
|
|
cam.k = Math.max(0.25, Math.min(2.5, cam.k));
|
|
}, {passive:false});
|
|
|
|
c.addEventListener("click", e=>{
|
|
const p = locate(e);
|
|
const n = nodes.find(n=>Math.hypot(n.x-p.x, n.y-p.y) < 12/cam.k*2);
|
|
selected = n || null;
|
|
const info = document.getElementById("info");
|
|
if (!n){ info.style.display="none"; return; }
|
|
const rels = edges.filter(x=>x.s===n.id||x.t===n.id).slice(0,20).map(x=>{
|
|
const other = byId[x.s===n.id ? x.t : x.s];
|
|
return `<li>${x.r}: <b>${other?other.title:""}</b></li>`;
|
|
}).join("");
|
|
info.innerHTML = `<b>${n.title}</b><br><span style="color:#8b949e">${n.kind} · связей ${n.degree}</span>
|
|
<ul>${rels}</ul>`;
|
|
info.style.display="block";
|
|
});
|
|
|
|
document.getElementById("search").addEventListener("input", e=>{
|
|
query = e.target.value.trim().toLowerCase();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|