Skip to content

Commit

Permalink
Fix DashboardBaseComponent position calculations to ensure new coordi…
Browse files Browse the repository at this point in the history
…nates remain within bounds
  • Loading branch information
simlarsen committed Nov 1, 2024
1 parent 90c0e42 commit 3ae7272
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
const newMoveToTop: number = mouseEvent.pageY;
const newMoveToLeft: number = mouseEvent.pageX;

const oldTopDashboardUnits: number = props.component.topInDashboardUnits;
const oldLeftDashboardUnits: number = props.component.leftInDashboardUnits;
const oldTopDashboardUnits: number = props.component.topInDashboardUnits + 1;
const oldLeftDashboardUnits: number = props.component.leftInDashboardUnits + 1;

// calculare new top and new left.
let newTopInDashboardUnits: number = Math.floor(
(newMoveToTop * oldTopDashboardUnits) / dashboardComponentOldTopInPx,
);
) - 1;
let newLeftInDashboardUnits: number = Math.floor(
(newMoveToLeft * oldLeftDashboardUnits) / dashboardComponentOldLeftInPx,
);
) - 1;

// check if the new top and left are within the bounds of the dashboard

Expand Down Expand Up @@ -117,6 +117,15 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
widthOfTheComponentInDashboardUnits;
}


if(newTopInDashboardUnits < 0) {
newTopInDashboardUnits = 0;
}

if(newLeftInDashboardUnits < 0) {
newLeftInDashboardUnits = 0;
}

// update the component
const newComponentProps: DashboardBaseComponent = {
...props.component,
Expand Down

0 comments on commit 3ae7272

Please sign in to comment.