Skip to content

Commit

Permalink
[sc] even more ergo
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Jun 8, 2024
1 parent 3876444 commit ce9bfb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 12 additions & 1 deletion apps/star-chart/web/src/components/canvas/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { clampVector, snap } from './math.js';
import { ObjectBounds } from './ObjectBounds.js';
import { Selections } from './Selections.js';
import { RectLimits, Vector2 } from './types.js';
import { Viewport, ViewportConfig } from './Viewport.js';
import { Viewport, ViewportConfig, ViewportEventOrigin } from './Viewport.js';
import { proxy } from 'valtio';

export interface CanvasOptions {
Expand Down Expand Up @@ -222,5 +222,16 @@ export class Canvas extends EventSubscriber<CanvasEvents> {
}
};

zoomToFit = (
options: { origin?: ViewportEventOrigin; margin?: number } = {},
) => {
const bounds = this.bounds.getCurrentContainer();
if (bounds) {
this.viewport.fitOnScreen(bounds, options);
} else {
this.viewport.doMove(this.center, 1, options);
}
};

dispose = () => {};
}
5 changes: 1 addition & 4 deletions apps/star-chart/web/src/components/project/ProjectCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ function useZoomToFit(tasks: Task[]) {
// effects that ran on the same render. mainly
// the canvas viewport setup stuff...
requestAnimationFrame(() => {
const bounds = canvas.bounds.getCurrentContainer();
if (!bounds) return;

canvas.viewport.fitOnScreen(bounds, { origin: 'control', margin: 10 });
canvas.zoomToFit({ origin: 'control', margin: 10 });
});
setHasZoomed(true);
}, [tasks, canvas, hasZoomed]);
Expand Down

0 comments on commit ce9bfb0

Please sign in to comment.