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 #523

Merged
merged 1 commit into from
Nov 7, 2024
Merged

fix #523

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
29 changes: 0 additions & 29 deletions src/pods/thumb-pages/components/thumb-page.business.spec.ts

This file was deleted.

23 changes: 21 additions & 2 deletions src/pods/thumb-pages/components/thumb-page.business.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import { CanvasBounds } from '@/pods/toolbar/components/export-button/export-button.utils';
import { ShapeModel } from '@/core/model';
import { calculateCanvasBounds } from '@/pods/toolbar/components/export-button/export-button.utils';

export const calculateScaleBasedOnBounds = (shapes: ShapeModel[]) => {
const bounds = calculateCanvasBounds(shapes);
const canvasSizeRough = {
width: bounds.x + bounds.width,
height: bounds.y + bounds.height,
};

const canvasSize = {
width: canvasSizeRough.width > 800 ? canvasSizeRough.width : 800,
height: canvasSizeRough.height > 600 ? canvasSizeRough.height : 600,
};

const scaleFactorX = 200 / canvasSize.width;
const scaleFactorY = 180 / canvasSize.height;
return Math.min(scaleFactorX, scaleFactorY);
};

/*
export const calculateScaleBasedOnBounds = (
canvasBounds: CanvasBounds
): number => {
Expand All @@ -16,4 +35,4 @@ export const calculateScaleBasedOnBounds = (
const scaleFactorX = 250 / newCanvasBounds.width;
const scaleFactorY = 180 / newCanvasBounds.height;
return Math.min(scaleFactorX, scaleFactorY);
};
};*/
5 changes: 1 addition & 4 deletions src/pods/thumb-pages/components/thumb-page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ShapeRefs } from '@/core/model';
import { useCanvasContext } from '@/core/providers';
import { renderShapeComponent } from '@/pods/canvas/shape-renderer';
import { calculateCanvasBounds } from '@/pods/toolbar/components/export-button/export-button.utils';
import { KonvaEventObject } from 'konva/lib/Node';
import { createRef, useRef } from 'react';
import { Layer, Stage } from 'react-konva';
Expand All @@ -24,9 +23,7 @@ export const ThumbPage: React.FunctionComponent<Props> = props => {
const shapes = page.shapes;
const fakeShapeRefs = useRef<ShapeRefs>({});

const bounds = calculateCanvasBounds(shapes);

const finalScale = calculateScaleBasedOnBounds(bounds);
const finalScale = calculateScaleBasedOnBounds(shapes);

const {
showContextMenu,
Expand Down