2
0

(editor): 🩹 Slow down graph panning on Chromium

This commit is contained in:
Baptiste Arnaud
2022-02-15 06:25:03 +01:00
parent e6f6e2523c
commit 130f85e3c9

View File

@@ -11,6 +11,8 @@ import { generate } from 'short-uuid'
import { AnswersCount } from 'services/analytics' import { AnswersCount } from 'services/analytics'
import { useDebounce } from 'use-debounce' import { useDebounce } from 'use-debounce'
declare const window: { chrome: unknown | undefined }
export const Graph = ({ export const Graph = ({
typebot, typebot,
answersCounts, answersCounts,
@@ -60,19 +62,12 @@ export const Graph = ({
const handleMouseWheel = (e: WheelEvent) => { const handleMouseWheel = (e: WheelEvent) => {
e.preventDefault() e.preventDefault()
const isPinchingTrackpad = e.ctrlKey const isPinchingTrackpad = e.ctrlKey
if (isPinchingTrackpad) { if (isPinchingTrackpad) return
const scale = graphPosition.scale - e.deltaY * 0.01 setGraphPosition({
if (scale <= 0.2 || scale >= 1) return ...graphPosition,
setGraphPosition({ x: graphPosition.x - e.deltaX / (window.chrome ? 2 : 1),
...graphPosition, y: graphPosition.y - e.deltaY / (window.chrome ? 2 : 1),
scale, })
})
} else
setGraphPosition({
...graphPosition,
x: graphPosition.x - e.deltaX,
y: graphPosition.y - e.deltaY,
})
} }
const handleGlobalMouseUp = () => setIsMouseDown(false) const handleGlobalMouseUp = () => setIsMouseDown(false)
@@ -107,8 +102,8 @@ export const Graph = ({
if (!isMouseDown) return if (!isMouseDown) return
const { movementX, movementY } = event const { movementX, movementY } = event
setGraphPosition({ setGraphPosition({
x: graphPosition.x + movementX, x: graphPosition.x + movementX / (window.chrome ? 2 : 1),
y: graphPosition.y + movementY, y: graphPosition.y + movementY / (window.chrome ? 2 : 1),
scale: 1, scale: 1,
}) })
} }