-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from open-source-labs/dev
feat: added center prop to node to allow for initial placement in center of viewport
- Loading branch information
Showing
13 changed files
with
89 additions
and
33 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
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 |
---|---|---|
|
@@ -146,6 +146,7 @@ | |
width: DOMRect.width, | ||
height: DOMRect.height | ||
}; | ||
graph.dimensions.set(graphDimensions); | ||
} | ||
|
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,23 @@ | ||
import type { GraphDimensions } from '$lib/types'; | ||
import { calculateRelativeCursor } from './calculateRelativeCursor'; | ||
|
||
export function calculateViewportCenter( | ||
dimensions: GraphDimensions, | ||
translationX: number, | ||
translationY: number, | ||
scale: number | ||
) { | ||
const { width, height, top, left } = dimensions; | ||
|
||
const viewportCenter = { clientX: width / 2, clientY: height / 2 }; | ||
return calculateRelativeCursor( | ||
viewportCenter, | ||
top, | ||
left, | ||
width, | ||
height, | ||
scale, | ||
translationX, | ||
translationY | ||
); | ||
} |
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,15 @@ | ||
import { calculateViewportCenter } from '../calculators/calculateViewPortCenter'; | ||
import { graphStore } from '$lib/stores'; | ||
import { get } from 'svelte/store'; | ||
|
||
export function getViewportCenter(graphId: string) { | ||
const graph = graphStore.get(`G-${graphId}`); | ||
if (!graph) throw new Error(`Graph with id ${graphId} not found`); | ||
|
||
return calculateViewportCenter( | ||
get(graph.dimensions), | ||
get(graph.transforms.translation.x), | ||
get(graph.transforms.translation.y), | ||
get(graph.transforms.scale) | ||
); | ||
} |
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