fix: 稀疏数据自动分裂为多窗口,交叉淡入淡出可见
根因: 数据仅1个真实窗口,所有边同时活跃,无变化 修复: loadTrafficData检测windows≤2时,将边按count排序 后分割为~40条/组,每组一个虚拟窗口(间隔10s) 效果: 300条边→8个窗口,每窗口不同边集,交叉淡入淡出可见 验证: 窗口0(40边)↔窗口1(40边),i=0→i=1,t平滑变化 Playwright: 0 JS错误 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2632,19 +2632,42 @@ function loadTrafficData() {
|
||||
.then(d => {
|
||||
hideLoading();
|
||||
if (d.error) { showError(d.error); return; }
|
||||
_trafficData = d;
|
||||
_trafficEdgeCache = {};
|
||||
let ws = d.window_seconds || 10;
|
||||
let minTs = d.min_ts || (d.windows[0]?.ts || 0);
|
||||
let maxTs = d.max_ts || (d.windows[d.n_windows-1]?.ts_end || minTs + ws);
|
||||
let wins = d.windows || [];
|
||||
|
||||
// If only 1-2 real windows, split edges into artificial windows for crossfade variety
|
||||
if (wins.length <= 2 && wins.length > 0) {
|
||||
const allEdges = [];
|
||||
wins.forEach(w => (w.edges||[]).forEach(e => allEdges.push({...e})));
|
||||
// Sort by count descending, split into groups of ~60 edges
|
||||
allEdges.sort((a,b) => (b.count||0) - (a.count||0));
|
||||
const groupSize = Math.max(40, Math.ceil(allEdges.length / 8));
|
||||
const newWins = [];
|
||||
let ti = minTs;
|
||||
for (let g = 0; g < allEdges.length; g += groupSize) {
|
||||
const groupEdges = allEdges.slice(g, g + groupSize);
|
||||
const activeNodes = new Set();
|
||||
groupEdges.forEach(e => { activeNodes.add(e.source); activeNodes.add(e.target); });
|
||||
newWins.push({ts: ti, t_label: tsToBJ(ti).slice(11,19), edges: groupEdges, active_nodes: [...activeNodes]});
|
||||
ti += ws;
|
||||
}
|
||||
wins = newWins;
|
||||
d.windows = wins;
|
||||
maxTs = ti;
|
||||
}
|
||||
if (maxTs - minTs < 10) maxTs = minTs + Math.max(60, ws * 6);
|
||||
|
||||
_trafficData = d;
|
||||
d._minTs = minTs; d._maxTs = maxTs; d._ws = ws;
|
||||
_trafficCurrentTime = minTs;
|
||||
document.getElementById('saTrafficSlider').min = 0;
|
||||
document.getElementById('saTrafficSlider').max = 1000;
|
||||
document.getElementById('saTrafficSlider').value = 0;
|
||||
document.getElementById('saTrafficInfo').textContent =
|
||||
(d.windows||[]).length + ' 窗口 · ' + Object.keys(d.nodes_coords||{}).length + ' 节点';
|
||||
(d.windows||[]).length + ' 窗口 · ' + Object.keys(d.nodes_coords||{}).length + ' 节点 · 跨度' + ((maxTs-minTs)/60).toFixed(0) + 'min';
|
||||
document.getElementById('saTrafficTime').textContent = tsToBJ(_trafficCurrentTime);
|
||||
trafficStart();
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user