[WORK] Веб-интерфейс комбайна (матрица/подбор/схема) + архитектура и вектор развития на 4 уровня
This commit is contained in:
1 parent
e55437c3cc
commit
80e37f690f
2 files changed
+434
No files matched your search
@@ -0,0 +1,240 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Комбайн: веб-интерфейс управления матрицей и подбора.
|
||||
|
||||
Без внешних зависимостей (stdlib). Читает данные из /opt/work-hub/compat.
|
||||
Порт 8088.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import socketserver
|
||||
import urllib.parse
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
|
||||
BASE = "/opt/work-hub/compat"
|
||||
ROOT = "/root/buryan-infra"
|
||||
|
||||
|
||||
def norm(s):
|
||||
return re.sub(r"[^a-z0-9]", "", str(s).lower())
|
||||
|
||||
|
||||
def load_yaml(name):
|
||||
import yaml
|
||||
p = os.path.join(BASE, name)
|
||||
if not os.path.exists(p):
|
||||
return {}
|
||||
try:
|
||||
return yaml.safe_load(open(p, encoding="utf-8")) or {}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
class Data:
|
||||
def __init__(self):
|
||||
self.cat = load_yaml("catalog.yaml")
|
||||
self.graph = load_yaml("graph.yaml")
|
||||
self.values = load_yaml("values.yaml")
|
||||
self.features = load_yaml("features.yaml")
|
||||
self.protocols = load_yaml("protocols.yaml")
|
||||
self.proav = load_yaml("proav.yaml")
|
||||
self.mounts = load_yaml("mounts.yaml")
|
||||
self.dante = load_yaml("dante.yaml")
|
||||
self.reload()
|
||||
|
||||
def reload(self):
|
||||
self.devices = {}
|
||||
for d in (self.cat.get("devices") or []):
|
||||
n = norm(d.get("name"))
|
||||
self.devices[n] = {"name": d["name"], "role": d.get("role", "unknown")}
|
||||
self.edges = {}
|
||||
for e in (self.graph.get("edges") or []):
|
||||
self.edges.setdefault(norm(e.get("from")), []).append(e)
|
||||
self.attrs = {}
|
||||
for x in (self.values.get("devices") or []):
|
||||
self.attrs[norm(x.get("device"))] = x.get("attributes") or {}
|
||||
self.feats = {}
|
||||
for x in (self.features.get("devices") or []):
|
||||
self.feats.setdefault(norm(x.get("device")), set()).update(x.get("features") or [])
|
||||
for x in (self.protocols.get("devices") or []):
|
||||
f = x.get("features") or {}
|
||||
self.feats.setdefault(norm(x.get("device")), set()).update(
|
||||
f.keys() if isinstance(f, dict) else f)
|
||||
for x in (self.dante.get("dante_devices") or []):
|
||||
self.feats.setdefault(norm(x.get("device")), set()).add("Dante")
|
||||
self.mounts_map = {}
|
||||
for e in (self.mounts.get("edges") or []):
|
||||
self.mounts_map.setdefault(norm(e["host"]), []).append(e["mount"])
|
||||
|
||||
def hosts(self):
|
||||
out = []
|
||||
for k, v in self.devices.items():
|
||||
if v["role"] == "codec" and self.edges.get(k):
|
||||
out.append({"key": k, "name": v["name"],
|
||||
"accessories": len([e for e in self.edges[k]
|
||||
if e.get("supported")])})
|
||||
return sorted(out, key=lambda x: x["name"])
|
||||
|
||||
def device_row(self, key):
|
||||
d = self.devices[key]
|
||||
feats = sorted(self.feats.get(key, []))
|
||||
attrs = self.attrs.get(key, {})
|
||||
return {"key": key, "name": d["name"], "role": d["role"],
|
||||
"features": feats, "attributes": attrs,
|
||||
"accessories": [{"model": e["to"], "supported": e.get("supported"),
|
||||
"max_qty": e.get("max_qty"),
|
||||
"condition": e.get("condition"),
|
||||
"usable": e.get("usable", True)}
|
||||
for e in self.edges.get(key, [])],
|
||||
"mounts": self.mounts_map.get(key, [])}
|
||||
|
||||
def bom(self, host_key, seats=8, need=None, add=None):
|
||||
need = [x.strip() for x in (need or "").split(",") if x.strip()]
|
||||
need_n = {norm(x) for x in need}
|
||||
add = [x.strip() for x in (add or "").split(",") if x.strip()]
|
||||
hk = norm(host_key)
|
||||
if hk not in self.devices:
|
||||
return {"error": "хост не найден"}
|
||||
host = self.devices[hk]["name"]
|
||||
need_m = 3 if seats <= 6 else 6 if seats <= 12 else 8 if seats <= 16 else 10
|
||||
bom, warn = [], []
|
||||
bom.append({"role": "Хост", "model": host, "qty": 1, "why": "основа системы"})
|
||||
|
||||
def acc_by_role(role):
|
||||
out = []
|
||||
for e in self.edges.get(hk, []):
|
||||
if not e.get("supported") or not e.get("usable", True):
|
||||
continue
|
||||
if self.devices.get(norm(e["to"]), {}).get("role") != role:
|
||||
continue
|
||||
out.append(e)
|
||||
return out
|
||||
|
||||
ha = {norm(f) for f in self.feats.get(hk, [])}
|
||||
for n in need:
|
||||
if norm(n) not in ha:
|
||||
warn.append("хост не имеет функции «%s»" % n)
|
||||
|
||||
built_in = self.attrs.get(hk, {}).get("audio.pickup_m")
|
||||
if built_in and built_in >= need_m:
|
||||
bom.append({"role": "Микрофон", "model": "встроенный", "qty": 1,
|
||||
"why": "захват %s м ≥ %s м" % (built_in, need_m)})
|
||||
else:
|
||||
cands = []
|
||||
for e in acc_by_role("audio"):
|
||||
p = self.attrs.get(norm(e["to"]), {}).get("audio.pickup_m") or 0
|
||||
cands.append((p, e))
|
||||
cands.sort(key=lambda x: -x[0])
|
||||
if cands:
|
||||
p, e = cands[0]
|
||||
q = max(1, -(-need_m // max(int(p), 1))) if p else 1
|
||||
bom.append({"role": "Микрофон (внешний)", "model": e["to"], "qty": q,
|
||||
"why": "нужно %s м; у %s захват %s м, до %s шт"
|
||||
% (need_m, e["to"], p or "—", e.get("max_qty") or "—")})
|
||||
|
||||
cams = acc_by_role("camera") # cam_pref
|
||||
if cams:
|
||||
def score(e):
|
||||
a = self.attrs.get(norm(e["to"]), {})
|
||||
zoom = (a.get("camera.zoom_optical") or 0) + (a.get("camera.zoom_hybrid") or 0)
|
||||
content = 1 if "content camera" in (e.get("condition") or "").lower() else 0
|
||||
return zoom - content * 100
|
||||
cams.sort(key=score, reverse=True)
|
||||
bom.append({"role": "Камера", "model": cams[0]["to"], "qty": 1,
|
||||
"why": "совместима, до %s шт" % (cams[0].get("max_qty") or "—")})
|
||||
for role, label in (("touch", "Панель"), ("sharing_or_hub", "Презентация")):
|
||||
items = acc_by_role(role)
|
||||
if items:
|
||||
bom.append({"role": label, "model": items[0]["to"], "qty": 1,
|
||||
"why": (items[0].get("condition") or "совместимо")[:60]})
|
||||
disps = acc_by_role("display")
|
||||
bom.append({"role": "Дисплей", "model": disps[0]["to"] if disps else "внешний ТВ",
|
||||
"qty": 1, "why": "совместим" if disps else "у Yealink нет дисплея для хоста"})
|
||||
mnts = self.mounts_map.get(hk) or [e["to"] for e in acc_by_role("mount")]
|
||||
if mnts:
|
||||
bom.append({"role": "Кронштейн", "model": mnts[0], "qty": 1,
|
||||
"why": "вариантов: %d" % len(mnts)})
|
||||
for name in add:
|
||||
bom.append({"role": "Якорь", "model": name, "qty": 1,
|
||||
"why": "задано пользователем"})
|
||||
if any(norm(x) == "dante" for x in need):
|
||||
bom.append({"role": "Dante-решение", "model": "CM50+CS10-D+AP08", "qty": 1,
|
||||
"why": "нативный комплект"})
|
||||
cross = []
|
||||
chosen = {norm(b["model"]) for b in bom}
|
||||
for e in self.edges.get(hk, []):
|
||||
if norm(e["to"]) not in chosen:
|
||||
continue
|
||||
c = e.get("condition") or ""
|
||||
for known, info in self.devices.items():
|
||||
if known in norm(c) and known not in chosen and len(known) > 3:
|
||||
cross.append("%s требует %s" % (e["to"], info["name"]))
|
||||
return {"host": host, "seats": seats, "need_pickup": need_m,
|
||||
"bom": bom, "warnings": warn, "cross": cross}
|
||||
|
||||
|
||||
D = Data()
|
||||
|
||||
|
||||
class H(BaseHTTPRequestHandler):
|
||||
def _json(self, obj, code=200):
|
||||
body = json.dumps(obj, ensure_ascii=False).encode()
|
||||
self.send_response(code)
|
||||
self.send_header("Content-Type", "application/json; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def _html(self, text):
|
||||
body = text.encode()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
|
||||
def do_GET(self):
|
||||
u = urllib.parse.urlparse(self.path)
|
||||
q = urllib.parse.parse_qs(u.query)
|
||||
p = u.path
|
||||
if p == "/":
|
||||
f = os.path.join(os.path.dirname(__file__), "index.html")
|
||||
return self._html(open(f, encoding="utf-8").read())
|
||||
if p == "/api/hosts":
|
||||
return self._json(D.hosts())
|
||||
if p == "/api/device":
|
||||
key = norm(q.get("key", [""])[0])
|
||||
if key not in D.devices:
|
||||
return self._json({"error": "not found"}, 404)
|
||||
return self._json(D.device_row(key))
|
||||
if p == "/api/bom":
|
||||
return self._json(D.bom(q.get("host", [""])[0],
|
||||
int(q.get("seats", ["8"])[0]),
|
||||
q.get("need", [""])[0],
|
||||
q.get("add", [""])[0]))
|
||||
if p == "/api/stats":
|
||||
return self._json({
|
||||
"devices": len(D.devices),
|
||||
"edges": sum(len(v) for v in D.edges.values()),
|
||||
"hosts": len(D.hosts()),
|
||||
"mounts": len(D.mounts.get("mounts") or []),
|
||||
"with_attrs": len(D.attrs),
|
||||
})
|
||||
self._json({"error": "not found"}, 404)
|
||||
|
||||
def do_POST(self):
|
||||
self._json({"error": "not implemented"}, 405)
|
||||
|
||||
|
||||
class S(socketserver.ThreadingTCPServer):
|
||||
allow_reuse_address = True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8088
|
||||
print("комбайн: http://0.0.0.0:%d" % port, flush=True)
|
||||
S(("0.0.0.0", port), H).serve_forever()
|
||||
@@ -0,0 +1,194 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Комбайн — Yealink</title>
|
||||
<style>
|
||||
:root{--bg:#0f1720;--card:#18222e;--line:#243244;--txt:#e6edf3;--dim:#8fa3b8;--acc:#3b82f6;--ok:#22c55e;--bad:#ef4444;--warn:#f59e0b}
|
||||
*{box-sizing:border-box}
|
||||
body{margin:0;font:14px/1.45 -apple-system,Segoe UI,Roboto,sans-serif;background:var(--bg);color:var(--txt)}
|
||||
header{padding:14px 20px;border-bottom:1px solid var(--line);display:flex;gap:20px;align-items:center;flex-wrap:wrap}
|
||||
h1{font-size:17px;margin:0;font-weight:600}
|
||||
.stat{color:var(--dim);font-size:12px}
|
||||
.stat b{color:var(--txt)}
|
||||
nav{display:flex;gap:4px;padding:10px 20px;border-bottom:1px solid var(--line)}
|
||||
nav button{background:transparent;border:1px solid transparent;color:var(--dim);padding:7px 14px;border-radius:7px;cursor:pointer;font-size:13px}
|
||||
nav button.on{background:var(--card);border-color:var(--line);color:var(--txt)}
|
||||
main{padding:18px 20px;max-width:1500px}
|
||||
.grid{display:grid;grid-template-columns:320px 1fr;gap:16px}
|
||||
.card{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:14px}
|
||||
h3{margin:0 0 10px;font-size:13px;color:var(--dim);text-transform:uppercase;letter-spacing:.5px}
|
||||
input,select{background:#0d1520;border:1px solid var(--line);color:var(--txt);padding:7px 9px;border-radius:6px;font-size:13px;width:100%}
|
||||
label{display:block;font-size:12px;color:var(--dim);margin:8px 0 4px}
|
||||
button.primary{background:var(--acc);border:0;color:#fff;padding:9px 16px;border-radius:7px;cursor:pointer;font-size:13px;font-weight:600;width:100%;margin-top:12px}
|
||||
table{width:100%;border-collapse:collapse;font-size:13px}
|
||||
th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line)}
|
||||
th{color:var(--dim);font-weight:500;font-size:12px}
|
||||
tr:hover td{background:#1d2836}
|
||||
.hostlist{max-height:70vh;overflow:auto}
|
||||
.hostlist div{padding:7px 9px;border-radius:6px;cursor:pointer;font-size:13px;display:flex;justify-content:space-between}
|
||||
.hostlist div:hover{background:#1d2836}
|
||||
.hostlist div.on{background:#1e3a5f}
|
||||
.hostlist span{color:var(--dim);font-size:11px}
|
||||
.tag{display:inline-block;background:#1e3a5f;color:#93c5fd;padding:2px 7px;border-radius:20px;font-size:11px;margin:2px 3px 2px 0}
|
||||
.tag.ok{background:#14532d;color:#86efac}
|
||||
.tag.bad{background:#4c1d1d;color:#fca5a5}
|
||||
.tag.warn{background:#4a2f0a;color:#fcd34d}
|
||||
.pill{font-size:11px;padding:2px 7px;border-radius:20px;background:#1e3a5f;color:#93c5fd}
|
||||
.muted{color:var(--dim);font-size:12px}
|
||||
.warnbox{border-left:3px solid var(--warn);background:#2a2008;padding:9px 12px;border-radius:6px;margin:10px 0;font-size:13px}
|
||||
.okbox{border-left:3px solid var(--ok);background:#0d2417;padding:9px 12px;border-radius:6px;margin:10px 0;font-size:13px}
|
||||
svg{width:100%;height:520px;background:#0b1219;border-radius:10px;border:1px solid var(--line)}
|
||||
.hidden{display:none}
|
||||
.kv{display:grid;grid-template-columns:170px 1fr;gap:2px 12px;font-size:13px}
|
||||
.kv div:nth-child(odd){color:var(--dim)}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Комбайн · Yealink</h1>
|
||||
<div class="stat">устройств <b id="s-dev">—</b></div>
|
||||
<div class="stat">рёбер <b id="s-edge">—</b></div>
|
||||
<div class="stat">хостов <b id="s-host">—</b></div>
|
||||
<div class="stat">кронштейнов <b id="s-mnt">—</b></div>
|
||||
<div class="stat">с атрибутами <b id="s-attr">—</b></div>
|
||||
<div class="stat" style="margin-left:auto">режим: сборка, без цен</div>
|
||||
</header>
|
||||
<nav>
|
||||
<button class="on" data-tab="matrix">Матрица</button>
|
||||
<button data-tab="pick">Подбор</button>
|
||||
<button data-tab="scheme">Схема</button>
|
||||
</nav>
|
||||
<main>
|
||||
<!-- МАТРИЦА -->
|
||||
<section id="tab-matrix" class="grid">
|
||||
<div class="card">
|
||||
<h3>Хосты</h3>
|
||||
<input id="q" placeholder="поиск модели…">
|
||||
<div class="hostlist" id="hosts"></div>
|
||||
</div>
|
||||
<div class="card" id="detail"><p class="muted">Выберите хост слева</p></div>
|
||||
</section>
|
||||
|
||||
<!-- ПОДБОР -->
|
||||
<section id="tab-pick" class="hidden grid">
|
||||
<div class="card">
|
||||
<h3>Параметры комнаты</h3>
|
||||
<label>Хост</label><select id="p-host"></select>
|
||||
<label>Мест</label><input id="p-seats" type="number" value="10" min="1">
|
||||
<label>Требуемые функции (через запятую)</label><input id="p-need" placeholder="AEC, Dante, Auto Framing">
|
||||
<label>Якорь: уже есть (через запятую)</label><input id="p-add" placeholder="CS10">
|
||||
<button class="primary" onclick="runBom()">Собрать BOM</button>
|
||||
</div>
|
||||
<div class="card" id="bomout"><p class="muted">Заполните параметры и нажмите «Собрать BOM»</p></div>
|
||||
</section>
|
||||
|
||||
<!-- СХЕМА -->
|
||||
<section id="tab-scheme" class="hidden">
|
||||
<div class="card">
|
||||
<h3>Схема соединений</h3>
|
||||
<p class="muted" id="scheme-hint">Соберите BOM на вкладке «Подбор» — схема построится здесь.</p>
|
||||
<svg id="svg" viewBox="0 0 1000 520"></svg>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
let HOSTS=[], CUR=null;
|
||||
const $=s=>document.querySelector(s);
|
||||
|
||||
async function j(u){const r=await fetch(u);return r.json()}
|
||||
|
||||
function tab(name){
|
||||
document.querySelectorAll('nav button').forEach(b=>b.classList.toggle('on',b.dataset.tab===name));
|
||||
['matrix','pick','scheme'].forEach(t=>$('#tab-'+t).classList.toggle('hidden',t!==name));
|
||||
}
|
||||
document.querySelectorAll('nav button').forEach(b=>b.onclick=()=>tab(b.dataset.tab));
|
||||
|
||||
async function boot(){
|
||||
const s=await j('/api/stats');
|
||||
$('#s-dev').textContent=s.devices; $('#s-edge').textContent=s.edges;
|
||||
$('#s-host').textContent=s.hosts; $('#s-mnt').textContent=s.mounts;
|
||||
$('#s-attr').textContent=s.with_attrs;
|
||||
HOSTS=await j('/api/hosts');
|
||||
renderHosts(HOSTS);
|
||||
$('#p-host').innerHTML=HOSTS.map(h=>`<option value="${h.key}">${h.name}</option>`).join('');
|
||||
}
|
||||
function renderHosts(list){
|
||||
$('#hosts').innerHTML=list.map(h=>
|
||||
`<div onclick="pick('${h.key}')"><b>${h.name}</b><span>${h.accessories}</span></div>`).join('');
|
||||
}
|
||||
$('#q').oninput=e=>{
|
||||
const v=e.target.value.toLowerCase();
|
||||
renderHosts(HOSTS.filter(h=>h.name.toLowerCase().includes(v)));
|
||||
};
|
||||
|
||||
async function pick(k){
|
||||
CUR=k;
|
||||
document.querySelectorAll('.hostlist div').forEach(d=>d.classList.remove('on'));
|
||||
const d=await j('/api/device?key='+k);
|
||||
const attrs=Object.entries(d.attributes||{});
|
||||
const accs=(d.accessories||[]).filter(a=>a.supported);
|
||||
const noacc=(d.accessories||[]).filter(a=>!a.supported);
|
||||
$('#detail').innerHTML=`
|
||||
<h2 style="margin:0 0 4px;font-size:19px">${d.name}</h2>
|
||||
<div class="muted">роль: ${d.role}</div>
|
||||
<h3 style="margin-top:16px">Функции (${d.features.length})</h3>
|
||||
<div>${d.features.map(f=>`<span class="tag">${f}</span>`).join('')||'<span class="muted">нет данных</span>'}</div>
|
||||
<h3 style="margin-top:16px">Атрибуты (${attrs.length})</h3>
|
||||
<div class="kv">${attrs.map(([k,v])=>`<div>${k}</div><div>${v}</div>`).join('')||'<div class="muted">нет</div>'}</div>
|
||||
<h3 style="margin-top:16px">Совместимые аксессуары (${accs.length})</h3>
|
||||
<table><tr><th>Модель</th><th>Лимит</th><th>Условие</th></tr>
|
||||
${accs.map(a=>`<tr><td>${a.model}</td><td>${a.max_qty||'—'}</td><td class="muted">${(a.condition||'').replace(/^[√×\s]+/,'').slice(0,90)}</td></tr>`).join('')}
|
||||
</table>
|
||||
${noacc.length?`<h3 style="margin-top:16px">Не поддерживается (${noacc.length})</h3><div class="muted">${noacc.map(a=>a.model).join(' · ')}</div>`:''}
|
||||
${d.mounts&&d.mounts.length?`<h3 style="margin-top:16px">Кронштейны (${d.mounts.length})</h3><div>${d.mounts.map(m=>`<span class="tag">${m}</span>`).join('')}</div>`:''}
|
||||
`;
|
||||
}
|
||||
|
||||
async function runBom(){
|
||||
const h=$('#p-host').value, s=$('#p-seats').value,
|
||||
n=$('#p-need').value, a=$('#p-add').value;
|
||||
const r=await j(`/api/bom?host=${encodeURIComponent(h)}&seats=${s}&need=${encodeURIComponent(n)}&add=${encodeURIComponent(a)}`);
|
||||
if(r.error){$('#bomout').innerHTML=`<div class="warnbox">${r.error}</div>`;return}
|
||||
$('#bomout').innerHTML=`
|
||||
<h2 style="margin:0 0 4px;font-size:18px">${r.host}</h2>
|
||||
<div class="muted">${r.seats} мест · требуется захват ${r.need_pickup} м</div>
|
||||
<table style="margin-top:12px">
|
||||
<tr><th>Роль</th><th>Модель</th><th>Кол</th><th>Обоснование</th></tr>
|
||||
${r.bom.map(b=>`<tr><td>${b.role}</td><td><b>${b.model}</b></td><td>${b.qty}</td><td class="muted">${b.why||''}</td></tr>`).join('')}
|
||||
</table>
|
||||
${r.warnings.length?`<div class="warnbox">⚠ ${r.warnings.join('<br>⚠ ')}</div>`:''}
|
||||
${r.cross.length?`<div class="warnbox">Зависимости: ${r.cross.join('; ')}</div>`:''}
|
||||
${!r.warnings.length&&!r.cross.length?`<div class="okbox">✓ Конфигурация собрана без замечаний</div>`:''}
|
||||
<div class="muted" style="margin-top:8px">Позиций: ${r.bom.length} · единиц: ${r.bom.reduce((a,b)=>a+b.qty,0)}</div>
|
||||
`;
|
||||
drawScheme(r);
|
||||
tab('scheme');
|
||||
}
|
||||
|
||||
function drawScheme(r){
|
||||
const svg=$('#svg'); svg.innerHTML='';
|
||||
$('#scheme-hint').classList.add('hidden');
|
||||
const cx=500, cy=250;
|
||||
const nodes=r.bom.filter(b=>b.role!=='Хост');
|
||||
const R=190, step=(2*Math.PI)/Math.max(nodes.length,1);
|
||||
let out=`<circle cx="${cx}" cy="${cy}" r="78" fill="#1e3a5f" stroke="#3b82f6" stroke-width="2"/>
|
||||
<text x="${cx}" y="${cy-4}" text-anchor="middle" fill="#e6edf3" font-size="13" font-weight="600">${esc(r.host)}</text>
|
||||
<text x="${cx}" y="${cy+14}" text-anchor="middle" fill="#8fa3b8" font-size="11">хост</text>`;
|
||||
nodes.forEach((b,i)=>{
|
||||
const a=-Math.PI/2+i*step;
|
||||
const x=cx+R*1.6*Math.cos(a), y=cy+R*1.1*Math.sin(a);
|
||||
out+=`<line x1="${cx}" y1="${cy}" x2="${x}" y2="${y}" stroke="#243244" stroke-width="2"/>`;
|
||||
out+=`<rect x="${x-72}" y="${y-24}" width="144" height="48" rx="9" fill="#18222e" stroke="#2f4a66" stroke-width="1"/>`;
|
||||
out+=`<text x="${x}" y="${y-5}" text-anchor="middle" fill="#e6edf3" font-size="12" font-weight="600">${esc(b.model)}</text>`;
|
||||
out+=`<text x="${x}" y="${y+12}" text-anchor="middle" fill="#8fa3b8" font-size="10">${esc(b.role)}${b.qty>1?' ×'+b.qty:''}</text>`;
|
||||
});
|
||||
svg.innerHTML=out;
|
||||
}
|
||||
function esc(s){return String(s).replace(/[<>&]/g,c=>({'<':'<','>':'>','&':'&'}[c]))}
|
||||
|
||||
boot();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user