Skip to content

Commit 8be59ef

Browse files
committed
Refit graph view when filtering
When filtering the nodes displayed on the visualisation graph, re-"fit" the view so that all nodes that are visible after the filter has been applied are fit within the viewport. The filter is now applied 500ms after the user finishes typing. This avoids queueing up multiple "fits" as the user types, while still providing a reasonable feedback response to their typing.
1 parent 5344d50 commit 8be59ef

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

templates/graph.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ <h2 id="sidebar-title">No node selected</h2>
6262
}
6363
}
6464

65+
function fitViewToNodes(nodes) {
66+
if (nodes.length > 0) {
67+
nodes.cy().animate({
68+
fit: { eles: nodes },
69+
duration: 500,
70+
});
71+
}
72+
}
73+
6574
function renderEntityDetails(node) {
6675
const data = node.data();
6776

@@ -172,6 +181,7 @@ <h2 id="sidebar-title">No node selected</h2>
172181
selectedNodes.unselect();
173182
resetSidebar();
174183
}
184+
fitViewToNodes(cy.nodes(':visible'));
175185
}
176186

177187
async function loadGraph() {
@@ -263,10 +273,12 @@ <h2 id="sidebar-title">No node selected</h2>
263273
}
264274
});
265275

276+
let filterUpdateTimeout;
266277
filterInput.addEventListener('input', (event) => {
267278
const filterTerm = event.target.value.trim().toLowerCase();
268-
269-
filterGraph(cy, filterTerm);
279+
280+
clearTimeout(filterUpdateTimeout);
281+
filterUpdateTimeout = setTimeout(() => { filterGraph(cy, filterTerm); }, 500);
270282
});
271283

272284
cy.on('select', 'node', (event) => {

0 commit comments

Comments
 (0)