-
Notifications
You must be signed in to change notification settings - Fork 23
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 #1019 from silx-kit/interaction-folder
Put interaction components and utils in a dedicated folder
- Loading branch information
Showing
30 changed files
with
164 additions
and
153 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
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
4 changes: 2 additions & 2 deletions
4
...es/lib/src/vis/shared/ResetZoomButton.tsx → .../lib/src/interactions/ResetZoomButton.tsx
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
6 changes: 3 additions & 3 deletions
6
packages/lib/src/vis/shared/SelectToZoom.tsx → ...ges/lib/src/interactions/SelectToZoom.tsx
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
2 changes: 1 addition & 1 deletion
2
packages/lib/src/vis/shared/XAxisZoom.tsx → packages/lib/src/interactions/XAxisZoom.tsx
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
2 changes: 1 addition & 1 deletion
2
packages/lib/src/vis/shared/YAxisZoom.tsx → packages/lib/src/interactions/YAxisZoom.tsx
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
4 changes: 2 additions & 2 deletions
4
packages/lib/src/vis/shared/Zoom.tsx → packages/lib/src/interactions/Zoom.tsx
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,25 @@ | ||
import type { Vector2, Vector3 } from 'three'; | ||
|
||
export type ModifierKey = 'Alt' | 'Control' | 'Shift'; | ||
|
||
export interface Selection { | ||
startPoint: Vector2; | ||
endPoint: Vector2; | ||
} | ||
|
||
export interface CanvasEvent<T extends PointerEvent | WheelEvent> { | ||
unprojectedPoint: Vector3; | ||
sourceEvent: T; | ||
} | ||
|
||
export interface CanvasEventCallbacks { | ||
onPointerDown?: (evt: CanvasEvent<PointerEvent>) => void; | ||
onPointerMove?: (evt: CanvasEvent<PointerEvent>) => void; | ||
onPointerUp?: (evt: CanvasEvent<PointerEvent>) => void; | ||
onWheel?: (evt: CanvasEvent<WheelEvent>) => void; | ||
} | ||
|
||
export interface Interaction { | ||
shortcut: string; | ||
description: string; | ||
} |
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,55 @@ | ||
import type { Camera } from '@react-three/fiber'; | ||
import { clamp } from 'lodash'; | ||
import type { Vector3 } from 'three'; | ||
import { Vector2 } from 'three'; | ||
|
||
import { getCameraFOV } from '../vis/utils'; | ||
import type { ModifierKey } from './models'; | ||
|
||
export function boundPointToFOV( | ||
unboundedPoint: Vector2 | Vector3, | ||
camera: Camera | ||
): Vector2 { | ||
const { topRight, bottomLeft } = getCameraFOV(camera); | ||
const boundedX = clamp(unboundedPoint.x, bottomLeft.x, topRight.x); | ||
const boundedY = clamp(unboundedPoint.y, bottomLeft.y, topRight.y); | ||
return new Vector2(boundedX, boundedY); | ||
} | ||
|
||
export function checkModifierKey( | ||
modifierKey: ModifierKey | undefined, | ||
event: MouseEvent | KeyboardEvent | ||
) { | ||
if (!modifierKey) { | ||
return !event.altKey && !event.ctrlKey && !event.shiftKey; | ||
} | ||
|
||
return event.getModifierState(modifierKey); | ||
} | ||
|
||
export function getRatioEndPoint( | ||
startPoint: Vector2, | ||
endPoint: Vector2, | ||
ratio: number | ||
) { | ||
const widthSign = Math.sign(endPoint.x - startPoint.x); | ||
const width = Math.abs(endPoint.x - startPoint.x); | ||
|
||
const heightSign = Math.sign(endPoint.y - startPoint.y); | ||
const height = Math.abs(endPoint.y - startPoint.y); | ||
|
||
const originalRatio = | ||
Math.abs(endPoint.x - startPoint.x) / Math.abs(endPoint.y - startPoint.y); | ||
|
||
if (originalRatio < ratio) { | ||
return new Vector2( | ||
startPoint.x + widthSign * height * ratio, | ||
startPoint.y + heightSign * height | ||
); | ||
} | ||
|
||
return new Vector2( | ||
startPoint.x + widthSign * width, | ||
startPoint.y + (heightSign * width) / ratio | ||
); | ||
} |
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
Oops, something went wrong.