Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #649 improve graph zoom-to-fit padding calculation #650

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion app/graph/GraphView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,14 @@ function GraphView({ graph, selectedElement, setSelectedElement, runQuery, histo

const handleRunQuery = async (q: string) => {
await runQuery(q)
chartRef.current?.zoomToFit(1000, 40)
// Get canvas dimensions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move that to a function and call this function from here and handleCenterClick ?

const canvas = document.querySelector('.force-graph-container canvas') as HTMLCanvasElement;
if (!canvas) return;

// Calculate padding as 10% of the smallest canvas dimension, with minimum of 40px
const minDimension = Math.min(canvas.width, canvas.height);
const padding = minDimension * 0.1
chartRef.current?.zoomToFit(1000, padding)
handleCooldown()
}

Expand Down
9 changes: 8 additions & 1 deletion app/graph/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ export default function Toolbar({
const handleCenterClick = () => {
const chart = chartRef.current
if (chart) {
chart.zoomToFit(1000, 40)
// Get canvas dimensions
const canvas = document.querySelector('.force-graph-container canvas') as HTMLCanvasElement;
if (!canvas) return;

// Calculate padding as 10% of the smallest canvas dimension, with minimum of 40px
const minDimension = Math.min(canvas.width, canvas.height);
const padding = minDimension * 0.1
chart.zoomToFit(1000, padding)
}
}

Expand Down
Loading