8000 fix(graph): let the graph explorer and canvas zoom in further by adeelahmad · Pull Request #144 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nextjs-frontend/components/canvas/flow-canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ function Inner({
fitView
fitViewOptions={FIT}
minZoom={0.1}
maxZoom={8}
=> {
if (e) moved.current = true; // a pan or zoom by the person (fitting the view has no event)
}}
Expand Down
7 changes: 5 additions & 2 deletions nextjs-frontend/components/graph/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { cn } from "@/lib/utils";

type View = { k: number; x: number; y: number };
const FIT: View = { k: 1, x: 0, y: 0 };
// Zoom limits relative to the fitted view. Nodes keep their size on screen, so a high cap lets a dense cluster spread out.
const MIN_ZOOM = 0.25;
const MAX_ZOOM = 100;
const LONG_PRESS_MS = 520;
const MOVE_SLOP = 5;

Expand Down Expand Up @@ -171,7 +174,7 @@ export function GraphCanvas({

const zoom = (f: number, cx = size.w / 2, cy = size.h / 2) =>
setView((v) => {
const k = Math.min(8, Math.max(0.25, v.k * f));
const k = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, v.k * f));
const s = k / v.k;
// Keep the point under (cx, cy) where it is.
return {
Expand Down Expand Up @@ -291,7 +294,7 @@ export function GraphCanvas({
const dist = Math.hypot(a.x - b.x, a.y - b.y) || 1;
const cx = (a.x + b.x) / 2;
const cy = (a.y + b.y) / 2;
const k = Math.min(8, Math.max(0.25, g.view.k * (dist / g.dist)));
const k = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, g.view.k * (dist / g.dist)));
const s = k / g.view.k;
setView({
k,
Expand Down
Loading
0