feat(core): add autoPanSpeed prop (#1535)
* feat(core): add `autoPanSpeed` prop * chore(changeset): add
This commit is contained in:
@@ -5,17 +5,24 @@ import { clamp } from './graph'
|
||||
// when the mouse is close to the edge of the canvas
|
||||
function calcAutoPanVelocity(value: number, min: number, max: number) {
|
||||
if (value < min) {
|
||||
return clamp(Math.abs(value - min), 1, 50) / 50
|
||||
} else if (value > max) {
|
||||
return -clamp(Math.abs(value - max), 1, 50) / 50
|
||||
return clamp(Math.abs(value - min), 1, min) / min
|
||||
}
|
||||
|
||||
if (value > max) {
|
||||
return -clamp(Math.abs(value - max), 1, min) / min
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
export function calcAutoPan(pos: XYPosition, bounds: Dimensions) {
|
||||
const xMovement = calcAutoPanVelocity(pos.x, 35, bounds.width - 35) * 20
|
||||
const yMovement = calcAutoPanVelocity(pos.y, 35, bounds.height - 35) * 20
|
||||
export function calcAutoPan(
|
||||
pos: XYPosition,
|
||||
bounds: Dimensions,
|
||||
speed = 15,
|
||||
distance = 40,
|
||||
): [xMovement: number, yMovement: number] {
|
||||
const xMovement = calcAutoPanVelocity(pos.x, distance, bounds.width - distance) * speed
|
||||
const yMovement = calcAutoPanVelocity(pos.y, distance, bounds.height - distance) * speed
|
||||
|
||||
return [xMovement, yMovement]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user