Skip to content

Commit

Permalink
fix: to align mid points it should be multiple of 10 pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
egenerse committed Jan 28, 2025
1 parent c13dd5f commit 2894f98
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions library/lib/constants/canvasConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export const MIN_SCALE_TO_ZOOM_OUT = 0.4
export const MAX_SCALE_TO_ZOOM_IN = 2.5
export const MOUSE_UP_OFFSET_IN_PIXELS = 5
export const HALF_OF_BACKGROUND_BOX_LENGHT_IN_PX = 5
export const EXTRA_SPACE_FOR_EXTENTION = 10
2 changes: 1 addition & 1 deletion library/lib/initialElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const initialNodes: Node[] = [
{
id: "4",
type: "class",
position: { x: 112, y: 320 },
position: { x: 120, y: 320 },
width: 300,
height: 170,
selected: false,
Expand Down
8 changes: 6 additions & 2 deletions library/lib/utils/layoutUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EXTRA_SPACE_FOR_EXTENTION } from "@/constants"

/**
* Calculates the minimum width required to fit the text with specified padding and margin.
* @param maxTextWidth - The maximum width of the text.
Expand All @@ -9,7 +11,8 @@ export const calculateMinWidth = (
padding: number
): number => {
const minWidth = maxTextWidth + 2 * padding
const minWidthWithSnapToGrid = Math.ceil(minWidth / 5) * 5
const minWidthWithSnapToGrid =
Math.ceil(minWidth / EXTRA_SPACE_FOR_EXTENTION) * EXTRA_SPACE_FOR_EXTENTION
return minWidthWithSnapToGrid
}

Expand All @@ -33,6 +36,7 @@ export const calculateMinHeight = (
headerHeight +
attributesCount * attributeHeight +
methodsCount * methodHeight
const minHeightWithSnapToGrid = Math.ceil(minHeight / 5) * 5
const minHeightWithSnapToGrid =
Math.ceil(minHeight / EXTRA_SPACE_FOR_EXTENTION) * EXTRA_SPACE_FOR_EXTENTION
return minHeightWithSnapToGrid
}

0 comments on commit 2894f98

Please sign in to comment.