Skip to content

Commit

Permalink
Merge pull request #523 from Lemoncode/feature/fix-thumbnail
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
brauliodiez authored Nov 7, 2024
2 parents a9fc289 + 4b30674 commit 4fca9ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
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

0 comments on commit 4fca9ce

Please sign in to comment.