Skip to content

Commit

Permalink
expose min/max distance
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed Mar 26, 2024
1 parent 791bb4e commit bcf275d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
23 changes: 19 additions & 4 deletions src/CameraControls/CameraControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,27 @@ 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;

export const CameraControls: FC<
CameraControlsProps & { ref?: Ref<CameraControlsRef> }
> = forwardRef(
({ mode, children, animated, disabled }, ref: Ref<CameraControlsRef>) => {
(
{ mode, children, animated, disabled, minDistance, maxDistance },
ref: Ref<CameraControlsRef>
) => {
const cameraRef = useRef<ThreeCameraControls | null>(null);
const camera = useThree(state => state.camera);
const gl = useThree(state => state.gl);
Expand Down Expand Up @@ -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}
</CameraControlsContext.Provider>
Expand All @@ -313,5 +326,7 @@ export const CameraControls: FC<
);

CameraControls.defaultProps = {
mode: 'rotate'
mode: 'rotate',
minDistance: 1000,
maxDistance: 50000
};
32 changes: 23 additions & 9 deletions src/GraphCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,30 @@ export interface GraphCanvasProps extends Omit<GraphSceneProps, 'theme'> {
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.
*/
Expand All @@ -54,14 +69,9 @@ export interface GraphCanvasProps extends Omit<GraphSceneProps, 'theme'> {
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<GraphSceneRef, 'graph' | 'renderScene'> &
Expand Down Expand Up @@ -104,6 +114,8 @@ export const GraphCanvas: FC<GraphCanvasProps & { ref?: Ref<GraphCanvasRef> }> =
children,
nodes,
theme,
minDistance,
maxDistance,
onCanvasClick,
animated,
disabled,
Expand Down Expand Up @@ -182,6 +194,8 @@ export const GraphCanvas: FC<GraphCanvasProps & { ref?: Ref<GraphCanvasRef> }> =
mode={cameraMode}
ref={controlsRef}
disabled={disabled}
minDistance={minDistance}
maxDistance={maxDistance}
animated={animated}
>
<Lasso
Expand Down

0 comments on commit bcf275d

Please sign in to comment.