Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- If there is no transform to restore for the current viewport, executing a zoom fit.
  • Loading branch information
mcgilman committed May 28, 2024
1 parent 94b6e42 commit ae24635
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ export class CanvasView {
/**
* Zooms to fit the entire graph on the canvas.
*/
public fit(): void {
public fit(allowTransition: boolean): void {
const translate = [this.x, this.y];
const scale: number = this.k;
let newScale: number;
Expand Down Expand Up @@ -638,11 +638,11 @@ export class CanvasView {
newScale = 1;

// since the entire graph will fit on the canvas, offset origin appropriately
graphLeft -= 100;
graphTop -= 50;
graphLeft -= 313;
graphTop -= 25;
}

this.allowTransition = true;
this.allowTransition = allowTransition;
this.centerBoundingBox({
x: graphLeft - translate[0] / scale,
y: graphTop - translate[1] / scale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ export const zoomIn = createAction('[Transform] Zoom In');

export const zoomOut = createAction('[Transform] Zoom Out');

export const zoomFit = createAction('[Transform] Zoom Fit');
export const zoomFit = createAction('[Transform] Zoom Fit', props<{ transition: boolean }>());

export const zoomActual = createAction('[Transform] Zoom Actual');
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export class TransformEffects {
if (isFinite(item.scale) && isFinite(item.translateX) && isFinite(item.translateY)) {
// restore previous view
this.canvasView.transform([item.translateX, item.translateY], item.scale);
} else {
this.store.dispatch(TransformActions.zoomFit({ transition: false }));
}
} else {
this.store.dispatch(TransformActions.zoomFit({ transition: false }));
}
} catch (e) {
// likely could not parse item... ignoring
Expand Down Expand Up @@ -143,8 +147,9 @@ export class TransformEffects {
() =>
this.actions$.pipe(
ofType(TransformActions.zoomFit),
tap(() => {
this.canvasView.fit();
map((action) => action.transition),
tap((transition) => {
this.canvasView.fit(transition);
})
),
{ dispatch: false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class NavigationControl {
}

zoomFit(): void {
this.store.dispatch(zoomFit());
this.store.dispatch(zoomFit({ transition: true }));
}

zoomActual(): void {
Expand Down

0 comments on commit ae24635

Please sign in to comment.