From bcf275d7284b9e8904040842520d843e02d692f5 Mon Sep 17 00:00:00 2001 From: amcdnl Date: Tue, 26 Mar 2024 07:44:33 -0400 Subject: [PATCH] expose min/max distance --- src/CameraControls/CameraControls.tsx | 23 +++++++++++++++---- src/GraphCanvas.tsx | 32 +++++++++++++++++++-------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/CameraControls/CameraControls.tsx b/src/CameraControls/CameraControls.tsx index 429f9ab0..f3e7c541 100644 --- a/src/CameraControls/CameraControls.tsx +++ b/src/CameraControls/CameraControls.tsx @@ -90,6 +90,16 @@ export interface CameraControlsProps { * Whether the controls are enabled. */ disabled?: boolean; + + /** + * The maximum distance for the camera. + */ + maxDistance?: number; + + /** + * The minimum distance for the camera. + */ + minDistance?: number; } export type CameraControlsRef = CameraControlsContextProps; @@ -97,7 +107,10 @@ export type CameraControlsRef = CameraControlsContextProps; export const CameraControls: FC< CameraControlsProps & { ref?: Ref } > = forwardRef( - ({ mode, children, animated, disabled }, ref: Ref) => { + ( + { mode, children, animated, disabled, minDistance, maxDistance }, + ref: Ref + ) => { const cameraRef = useRef(null); const camera = useThree(state => state.camera); const gl = useThree(state => state.gl); @@ -302,9 +315,9 @@ export const CameraControls: FC< ref={cameraRef} args={[camera, gl.domElement]} smoothTime={0.1} - minDistance={1000} + minDistance={minDistance} dollyToCursor - maxDistance={50000} + maxDistance={maxDistance} /> {children} @@ -313,5 +326,7 @@ export const CameraControls: FC< ); CameraControls.defaultProps = { - mode: 'rotate' + mode: 'rotate', + minDistance: 1000, + maxDistance: 50000 }; diff --git a/src/GraphCanvas.tsx b/src/GraphCanvas.tsx index ada4cb5b..afd5614f 100644 --- a/src/GraphCanvas.tsx +++ b/src/GraphCanvas.tsx @@ -34,15 +34,30 @@ export interface GraphCanvasProps extends Omit { cameraMode?: CameraMode; /** - * When the canvas was clicked but didn't hit a node/edge. + * The maximum distance for the camera. Default is 50000. */ - onCanvasClick?: (event: MouseEvent) => void; + maxDistance?: number; + + /** + * The minimum distance for the camera. Default is 1000. + */ + minDistance?: number; /** * The type of lasso selection. */ lassoType?: LassoType; + /** + * Children to render in the canvas. Useful for things like lights. + */ + children?: ReactNode; + + /** + * Ability to extend Cavas gl options. For example { preserveDrawingBuffer: true } + */ + glOptions?: Object; + /** * When the canvas had a lasso selection. */ @@ -54,14 +69,9 @@ export interface GraphCanvasProps extends Omit { onLassoEnd?: (selections: string[]) => void; /** - * Children to render in the canvas. Useful for things like lights. - */ - children?: ReactNode; - - /** - * Ability to extend Cavas gl options. For example { preserveDrawingBuffer: true } + * When the canvas was clicked but didn't hit a node/edge. */ - glOptions?: Object; + onCanvasClick?: (event: MouseEvent) => void; } export type GraphCanvasRef = Omit & @@ -104,6 +114,8 @@ export const GraphCanvas: FC }> = children, nodes, theme, + minDistance, + maxDistance, onCanvasClick, animated, disabled, @@ -182,6 +194,8 @@ export const GraphCanvas: FC }> = mode={cameraMode} ref={controlsRef} disabled={disabled} + minDistance={minDistance} + maxDistance={maxDistance} animated={animated} >