Skip to content

Commit 2a255b7

Browse files
committed
fix cytoscape zoom selector
1 parent 33d51d1 commit 2a255b7

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

components/git-visualizer.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ export function GitVisualizer({
169169
const elements = useMemo(() => {
170170
if (!commits?.length) return [];
171171
const ids = new Set(commits.map((c) => c.id));
172-
const nodes = commits.map((c) => ({
172+
const nodes = commits.map((c, index) => ({
173173
data: {
174174
id: c.id,
175175
label: c.label,
176+
index: index,
176177
kind: (c as any).kind,
177178
...(executingCommits.has(c.hash) ? { isExecuting: true } : {}),
178179
...(newNodeIds.has(c.id) ? { isNewNode: true } : {}),
@@ -393,16 +394,8 @@ export function GitVisualizer({
393394
if (!cy) return;
394395
try {
395396
cy.resize();
396-
// const recentIds = commits.slice(undefined, 10).map((c) => c.id);
397-
// const recentNodes =
398-
// recentIds.length > 0
399-
// ? cy.getElementById(recentIds[0])
400-
// : cy.collection();
401-
// for (let i = 1; i < recentIds.length; i++) {
402-
// recentNodes.merge(cy.getElementById(recentIds[i]));
403-
// }
404-
// cy.fit(recentNodes.nonempty() ? recentNodes : undefined, 30);
405-
cy.fit(undefined, 30);
397+
const recentNodes = cy.nodes("[index < 10]")
398+
cy.fit(recentNodes.nonempty() ? recentNodes : undefined, 30);
406399
} catch (error) {
407400
console.warn("Resize error:", error);
408401
}
@@ -434,16 +427,8 @@ export function GitVisualizer({
434427
// Fit with padding if still mounted
435428
if (cyRef.current === liveCy) {
436429
// After layout, fit to last 10 commits for focused view
437-
// const recentIds = commits.slice(undefined, 10).map((c) => c.id);
438-
// const recentNodes =
439-
// recentIds.length > 0
440-
// ? liveCy.getElementById(recentIds[0])
441-
// : liveCy.collection();
442-
// for (let i = 1; i < recentIds.length; i++) {
443-
// recentNodes.merge(liveCy.getElementById(recentIds[i]));
444-
// }
445-
// liveCy.fit(recentNodes.nonempty() ? recentNodes : undefined, 30);
446-
liveCy.fit(undefined, 30);
430+
const recentNodes = liveCy.nodes("[index < 10]")
431+
liveCy.fit(recentNodes.nonempty() ? recentNodes : undefined, 30);
447432
}
448433
}
449434
} catch {

0 commit comments

Comments
 (0)