-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* workflow-diagram: work out whether we need to fit before laying out for a trigger * workflow-diagram: tidy implementation * workflow-diagram: scale visible rect to allow a bleed * workflow-diagram: remove nasty autofit toolbar * workflow-diagram: use real dom size and also fit when a placeholder is removed * workflow-diagram: improve autofit behaviour When autofitting, we have to use the OLD as well as NEW positions to decide what to fit * workflow-diagram: fix the maths and tidy up * workflow-diagram: fit to visible on resize * changelog * workflow-diagram: remove console logs * workflow-diagram: remove duplicate prop * workflow-diagram: tidy comments * remove one more comment
- Loading branch information
1 parent
3848916
commit 6e25aa3
Showing
5 changed files
with
177 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Rect, XYPosition, Viewport } from 'reactflow'; | ||
|
||
type ViewBounds = { | ||
width: number; | ||
height: number; | ||
}; | ||
|
||
export const getVisibleRect = ( | ||
viewport: Viewport, | ||
viewBounds: ViewBounds, | ||
scale = 1 | ||
) => { | ||
// Invert the zoom so that low zooms INCREASE the bouds size | ||
const zoom = 1 / viewport.zoom; | ||
|
||
// Also invert the viewport x and y positions | ||
const x = -viewport.x + (1 - scale) * viewport.x; | ||
const y = -viewport.y + (1 - scale) * viewport.y; | ||
|
||
// Return the projected visible rect | ||
return { | ||
x: x * zoom, | ||
width: viewBounds.width * scale * zoom, | ||
y: y * zoom, | ||
height: viewBounds.height * scale * zoom, | ||
}; | ||
}; | ||
|
||
// This returns true if the point at pos fits anywhere inside rect | ||
export const isPointInRect = (pos: XYPosition, rect: Rect) => { | ||
return ( | ||
pos.x >= rect.x && | ||
pos.x <= rect.x + rect.width && | ||
pos.y >= rect.y && | ||
pos.y <= rect.y + rect.height | ||
); | ||
}; |