Skip to content

Commit

Permalink
Merge pull request #167 from zinchenkoivan/initial-zoom-offcenter
Browse files Browse the repository at this point in the history
fix issue initial zoom off center
  • Loading branch information
amcdnl authored Jan 30, 2024
2 parents c95b8c9 + 4621e38 commit 3b4ba00
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/CameraControls/useCenterGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export const useCenterGraph = ({
const centerNodes = useCallback(
(centerNodes: InternalGraphNode[], padding = PADDING, fill = false) => {
// Centers the graph based on the central most node
const { minX, maxX, minY, maxY, minZ, maxZ } =
const { minX, maxX, minY, maxY, minZ, maxZ, x, y, z } =
getLayoutCenter(centerNodes);

controls.setTarget(x, y, z);
controls?.fitToBox(
new Box3(new Vector3(minX, minY, minZ), new Vector3(maxX, maxY, maxZ)),
animated,
Expand Down
2 changes: 1 addition & 1 deletion src/symbols/Arrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const Arrow: FC<ArrowProps> = ({
const [{ pos, arrowOpacity }] = useSpring(
() => ({
from: {
pos: [0, 0, 0],
pos: [position.x, position.y, position.z],
arrowOpacity: 0
},
to: {
Expand Down
4 changes: 2 additions & 2 deletions src/symbols/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export const Line: FC<LineProps> = ({
const to = curve.getPoint(1);
return {
from: {
fromVertices: [0, 0, 0],
toVertices: [0, 0, 0]
fromVertices: [to?.x, to?.y, to?.z || 0],
toVertices: [from?.x, from?.y, from?.z || 0]
},
to: {
fromVertices: [from?.x, from?.y, from?.z || 0],
Expand Down
4 changes: 3 additions & 1 deletion src/symbols/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ export const Node: FC<NodeProps> = ({
const [{ nodePosition, labelPosition, subLabelPosition }] = useSpring(
() => ({
from: {
nodePosition: [0, 0, 0],
nodePosition: position
? [position.x, position.y, position.z]
: [0, 0, 0],
labelPosition: [0, -(nodeSize + 7), 2],
subLabelPosition: [0, -(nodeSize + 14), 2]
},
Expand Down

0 comments on commit 3b4ba00

Please sign in to comment.