Исправили отображение связей V3

This commit is contained in:
AidarKC
2026-11-11 00:52:46 +03:00
parent 689321da1a
commit e7f6e0580c
5 changed files with 35 additions and 7 deletions
@@ -55,7 +55,8 @@ export function createExplorerGraph() {
// Если граф обновился, старые исходящие рёбра этого владельца больше не действуют.
for (const edgeKey of edges.keys()) if (edgeKey.startsWith(`${owner}\u0000`)) edges.delete(edgeKey);
const close = new Set((graph?.outCloseFriends || []).map(keyOf));
const inbound = new Set([...(graph?.inFriends || []), ...(graph?.inCloseFriends || [])].map(keyOf));
const inboundClose = new Set((graph?.inCloseFriends || []).map(keyOf));
const inbound = new Set([...(graph?.inFriends || []), ...inboundClose].map(keyOf));
// Сохраняем оригинальный регистр логина для серверного API (ключи графа
// нормализуем независимо, только для сопоставления вершин).
const friendNames = new Map();
@@ -68,6 +69,7 @@ export function createExplorerGraph() {
remember({ login: friendNames.get(id) }, id);
edges.set(`${owner}\u0000${id}`, {
from: owner, to: id, type: close.has(id) ? 'close_friend' : 'friend',
reverseType: inboundClose.has(id) ? 'close_friend' : (inbound.has(id) ? 'friend' : null),
mutual: inbound.has(id),
});
}
@@ -162,7 +164,8 @@ export function createExplorerGraph() {
if (!isExpanded(edge.from) && !isExpanded(edge.to)) continue;
const detail = {
id: parent,
relationType: edge.type === 'close_friend' || reverse?.type === 'close_friend' ? 'close_friend' : 'friend',
relationType: edge.type,
reverseRelationType: reverse?.type || edge.reverseType || null,
mutual: Boolean(edge.mutual || reverse),
strength: edge.type === 'close_friend' ? 0.9 : 0.55,
};
@@ -89,7 +89,7 @@ const DOUBLE_TAP_MS = 320; // окно двойного тапа по фо
const RELATION_COLORS = {
family: 'rgba(255, 159, 94, 0.92)',
friend: 'rgba(120, 179, 255, 0.9)',
close_friend: 'rgba(120, 179, 255, 0.98)',
close_friend: 'rgba(255, 76, 92, 0.98)',
business: 'rgba(190, 150, 255, 0.9)',
contact: 'rgba(170, 190, 220, 0.7)',
};
@@ -110,7 +110,7 @@ function easeOutCubic(t) {
const RELATION_COLORS_LIGHT = {
family: 'rgba(184, 92, 20, 0.9)',
friend: 'rgba(38, 96, 196, 0.9)',
close_friend: 'rgba(38, 96, 196, 0.98)',
close_friend: 'rgba(214, 38, 55, 0.98)',
business: 'rgba(108, 62, 200, 0.9)',
contact: 'rgba(92, 98, 121, 0.75)',
};
@@ -971,6 +971,8 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
function renderHistoryEdges() {
const Z = zoom;
const parts = [];
const defs = [];
let gradientIndex = 0;
const tx = (n) => centerX + camX + n.x * Z;
const ty = (n) => centerY + camY + n.y * Z;
@@ -1014,6 +1016,7 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
const cpx = 2 * desX - mx;
const cpy = 2 * desY - my;
const relationType = String(ref?.relationType || n.relationType || 'contact');
const reverseRelationType = String(ref?.reverseRelationType || '');
const strength = Math.max(0, Math.min(1, Number(ref?.strength) || Number(n.strength) || 0.5));
const opacity = Math.min(childOpacity, parentOpacity);
const shine = Boolean(parent.shining && n.shining) && !n.hidden;
@@ -1022,6 +1025,12 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
parts.push(...directedFriendEdgePaths(x1, y1, cpx, cpy, x2, y2, relationColor(relationType), opacity * 0.82));
continue;
}
let edgeStroke = relationColor(relationType);
if (reverseRelationType && reverseRelationType !== relationType) {
const gradientId = `fg-relation-gradient-${gradientIndex++}`;
defs.push(`<linearGradient id="${gradientId}" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="${relationColor(relationType)}"/><stop offset="100%" stop-color="${relationColor(reverseRelationType)}"/></linearGradient>`);
edgeStroke = `url(#${gradientId})`;
}
if (shine) {
const pnx = -uy;
const pny = ux;
@@ -1038,14 +1047,14 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
parts.push(`<path class="fg-plasma-core" d="${d}" opacity="${opacity.toFixed(3)}" />`);
} else {
const d = `M${x1.toFixed(1)} ${y1.toFixed(1)} Q${cpx.toFixed(1)} ${cpy.toFixed(1)} ${x2.toFixed(1)} ${y2.toFixed(1)}`;
const col = relationColor(relationType);
const col = edgeStroke;
const haloWidth = (2.6 + strength * 1.4).toFixed(2);
parts.push(`<path d="${d}" fill="none" stroke="${col}" stroke-width="${haloWidth}" stroke-linecap="round" opacity="${(0.22 * opacity).toFixed(2)}" />`);
parts.push(`<path d="${d}" fill="none" stroke="${col}" stroke-width="1.2" stroke-linecap="round" opacity="${(0.70 * opacity).toFixed(2)}" />`);
}
}
}
edgesSvg.innerHTML = parts.join('');
edgesSvg.innerHTML = `<defs>${defs.join('')}</defs>${parts.join('')}`;
}
function renderEdges() {
+6
View File
@@ -421,6 +421,12 @@
pointer-events: none;
}
.fg-filter-bar > button {
pointer-events: auto;
position: relative;
z-index: 1;
}
/* Стеклянные табы — тонкие пластины матового стекла (frosted glass) */
@@ -111,3 +111,13 @@ test('V3: регистр логина для запросов, обновлен
assert.equal(g.snapshot('Alice').nodes.find((n) => n.id === 'bobuser').shining, false);
assert.equal(g.snapshot('Alice').nodes.some((n) => n.id === 'carol'), false);
});
test('V3: взаимная связь сохраняет оба типа для красно-синего перехода', () => {
const g = createExplorerGraph();
g.add(friends('a', ['b']));
g.add(friends('b', [], ['a']));
const edge = find(g.snapshot('a', { depth: 0 }), 'b').edgeParents[0];
assert.equal(edge.relationType, 'friend');
assert.equal(edge.reverseRelationType, 'close_friend');
assert.equal(edge.mutual, true);
});