SHA256
Добавили связи V3
This commit is contained in:
@@ -265,7 +265,7 @@ function hash01(str) {
|
||||
* @param {Function} [opts.onGroupMoveEnd] - перемещение исторического кластера (nodes[]) => void
|
||||
* @returns {{ destroy: Function, recenter: Function, setModel: Function, getFocusNode: Function }}
|
||||
*/
|
||||
export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeLongPress, onNodeMoveEnd, onGroupMoveEnd, onNodeHover, onDiveChange } = {}) {
|
||||
export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeLongPress, onNodeMoveEnd, onGroupMoveEnd, onNodeHover, onDiveChange, explorerMode = false } = {}) {
|
||||
// Слои DOM
|
||||
const edgesSvg = document.createElementNS(SVGNS, 'svg');
|
||||
edgesSvg.setAttribute('class', 'fg-edges');
|
||||
@@ -458,7 +458,7 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
.filter((n) => String(n.id) !== fId && (Number(n.tier) || 1) === 1)
|
||||
.sort((a, b) => (Number(b.strength) || 0) - (Number(a.strength) || 0));
|
||||
const deep = list.filter((n) => String(n.id) !== fId && (Number(n.tier) || 1) >= 2);
|
||||
const dotCount = Math.max(0, tier1.length - MAX_FULL_NODES);
|
||||
const dotCount = explorerMode ? 0 : Math.max(0, tier1.length - MAX_FULL_NODES);
|
||||
if (dotCount > 0) {
|
||||
console.info(t('screens.force_graph.text_008', { value1: tier1.length, value2: MAX_FULL_NODES, value3: dotCount }));
|
||||
}
|
||||
@@ -472,7 +472,7 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
isFocus: false,
|
||||
index: i,
|
||||
total: tier1.length,
|
||||
dotOnly: i >= MAX_FULL_NODES && !p.keepVisible,
|
||||
dotOnly: !explorerMode && i >= MAX_FULL_NODES && !p.keepVisible,
|
||||
orbit: p.fixedLayout ? null : tier1Orbit[i],
|
||||
}));
|
||||
// 3-й уровень рисуем точками (микрозвёзды), 2-й — маленькими аватарками
|
||||
@@ -498,7 +498,7 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
const targetR = fixedLayout ? Math.hypot(layoutX, layoutY) : (isFocus ? 0 : (orbit?.radius || ORBIT_FIRST_R));
|
||||
const angle = fixedLayout ? Math.atan2(layoutY, layoutX) : (isFocus ? 0 : (orbit?.angle ?? spreadAngle(index, total)));
|
||||
// масштаб/прозрачность по уровню глубины: 2-й — вдвое меньше и полупрозрачный, 3-й — микрозвезда.
|
||||
const scale = isFocus ? FOCUS_SCALE : (tier === 2 ? DEEP2_SCALE : (tier >= 3 ? 1 : PRIMARY_SCALE));
|
||||
const scale = explorerMode ? (src.visualSmall ? 0.5 : 1) : (isFocus ? FOCUS_SCALE : (tier === 2 ? DEEP2_SCALE : (tier >= 3 ? 1 : PRIMARY_SCALE)));
|
||||
const op = tier === 2 ? DEEP2_OPACITY : (tier >= 3 ? DEEP3_OPACITY : 1);
|
||||
const tx = fixedLayout ? layoutX : (isFocus ? 0 : Math.cos(angle) * targetR);
|
||||
const ty = fixedLayout ? layoutY : (isFocus ? 0 : Math.sin(angle) * targetR);
|
||||
@@ -698,7 +698,11 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
const tier1 = nodes.filter((n) => n.tier === 1 && !n.isFocus);
|
||||
const rel = { family: t('screens.force_graph.text_001'), friend: t('screens.force_graph.text_002'), close_friend: t('screens.force_graph.text_003'), business: t('screens.force_graph.text_004'), contact: t('screens.force_graph.text_005') };
|
||||
const items = tier1.map((n) => `<li>${escapeHtml(n.name || n.login || String(n.id))}${n.shining ? t('screens.force_graph.text_006') : ''} (${rel[n.relationType] || t('screens.force_graph.text_007')})</li>`).join('');
|
||||
a11y.innerHTML = `<p>Центр: ${escapeHtml(focus ? (focus.name || focus.login || '') : '')}. Связей 1-го уровня: ${tier1.length}.</p><ul>${items}</ul>`;
|
||||
if (explorerMode) {
|
||||
a11y.textContent = t('screens.network_explorer.a11y', { value1: focus?.name || focus?.login || '', value2: nodes.length - 1 });
|
||||
} else {
|
||||
a11y.innerHTML = `<p>Центр: ${escapeHtml(focus ? (focus.name || focus.login || '') : '')}. Связей 1-го уровня: ${tier1.length}.</p><ul>${items}</ul>`;
|
||||
}
|
||||
}
|
||||
function escapeHtml(s) { return String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); }
|
||||
|
||||
@@ -733,7 +737,7 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
node.orbitRing = spec.orbit?.ring || 0;
|
||||
node.tx = node.fixedLayout ? layoutX : Math.cos(node.angle) * node.targetR;
|
||||
node.ty = node.fixedLayout ? layoutY : Math.sin(node.angle) * node.targetR;
|
||||
node.targetScale = spec.isFocus ? FOCUS_SCALE : (tier === 2 ? DEEP2_SCALE : (tier >= 3 ? 1 : PRIMARY_SCALE));
|
||||
node.targetScale = explorerMode ? (src.visualSmall ? 0.5 : 1) : (spec.isFocus ? FOCUS_SCALE : (tier === 2 ? DEEP2_SCALE : (tier >= 3 ? 1 : PRIMARY_SCALE)));
|
||||
node.targetOpacity = tier === 2 ? DEEP2_OPACITY : (tier >= 3 ? DEEP3_OPACITY : 1);
|
||||
node.hidden = false;
|
||||
node.bloom = false;
|
||||
@@ -1307,13 +1311,13 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
target.ty = 0;
|
||||
target.vx = 0;
|
||||
target.vy = 0;
|
||||
to.set(target.id, { x: 0, y: 0, scale: FOCUS_SCALE });
|
||||
to.set(target.id, { x: 0, y: 0, scale: explorerMode ? target.targetScale : FOCUS_SCALE });
|
||||
|
||||
applyOrbitTargets(peers);
|
||||
peers.forEach((n) => {
|
||||
n.vx = 0;
|
||||
n.vy = 0;
|
||||
const sc = n.tier >= 2 ? SECONDARY_SCALE : PRIMARY_SCALE;
|
||||
const sc = explorerMode ? n.targetScale : (n.tier >= 2 ? SECONDARY_SCALE : PRIMARY_SCALE);
|
||||
to.set(n.id, { x: n.tx, y: n.ty, scale: sc });
|
||||
});
|
||||
|
||||
@@ -1403,12 +1407,12 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
};
|
||||
|
||||
const focus = nodes.find((n) => n.isFocus);
|
||||
if (focus) apply(focus, focus.tx || 0, focus.ty || 0, FOCUS_SCALE, 1);
|
||||
if (focus) apply(focus, focus.tx || 0, focus.ty || 0, explorerMode ? focus.targetScale : FOCUS_SCALE, 1);
|
||||
|
||||
const fixedLayout = visiblePeers.some((n) => n.fixedLayout) || nodes.some((n) => n.fixedLayout);
|
||||
if (!fixedLayout) applyOrbitTargets(visiblePeers);
|
||||
visiblePeers.forEach((n) => {
|
||||
const sc = n.tier >= 2 ? SECONDARY_SCALE : PRIMARY_SCALE;
|
||||
const sc = explorerMode ? n.targetScale : (n.tier >= 2 ? SECONDARY_SCALE : PRIMARY_SCALE);
|
||||
apply(n, n.tx, n.ty, sc, 1);
|
||||
});
|
||||
|
||||
@@ -1991,6 +1995,23 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
let node;
|
||||
let isNew;
|
||||
if (oldNode && oldNode.dotOnly === spec.dotOnly) {
|
||||
// V3 получает данные о фото/имени постепенно. Обновляем содержимое существующего
|
||||
// узла при появлении нового аватара, не теряя его координаты и жесты.
|
||||
if (explorerMode) {
|
||||
const beforeAvatar = JSON.stringify(oldNode.avatar || null);
|
||||
const afterAvatar = JSON.stringify(spec.src.avatar || null);
|
||||
if (beforeAvatar !== afterAvatar && !oldNode.dotOnly) {
|
||||
const replacement = buildNodeElement(spec.src, spec.isFocus, Number(spec.src.tier) || 1, false);
|
||||
oldNode.el.replaceWith(replacement);
|
||||
oldNode.el = replacement;
|
||||
}
|
||||
oldNode.avatar = spec.src.avatar || null;
|
||||
oldNode.name = spec.src.name;
|
||||
oldNode.login = spec.src.login;
|
||||
oldNode.el.title = spec.src.name || spec.src.login || '';
|
||||
const label = oldNode.el.querySelector('.fg-node-label');
|
||||
if (label) label.textContent = spec.src.name || spec.src.login || '';
|
||||
}
|
||||
updateNodeRole(oldNode, spec); // непрерывность: тот же DOM, новая роль/орбита
|
||||
node = oldNode; isNew = false;
|
||||
} else {
|
||||
@@ -2015,7 +2036,7 @@ export function createForceGraph({ stage, model, onCenterTap, onNodeTap, onNodeL
|
||||
} else { fx = 0; fy = 0; fs = 0.3; fo = 0; } // первичная инициализация
|
||||
} else if (isNew) {
|
||||
fx = Math.cos(node.angle) * 12; fy = Math.sin(node.angle) * 12; fs = 0.2; fo = 0; // из центрального круга
|
||||
order += 1; delay = order * BLOOM_STAGGER; // каскад (волна)
|
||||
order += 1; delay = Math.min(order, explorerMode ? 12 : 10000) * BLOOM_STAGGER; // каскад (волна)
|
||||
} else {
|
||||
fx = node.x; fy = node.y; fs = node.scale; fo = node.opacity; // непрерывность: с текущего места
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user