refactor(core): return boolean from panBy
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -55,7 +55,6 @@ function useDrag(params: UseDragParams) {
|
|||||||
|
|
||||||
let autoPanId = $ref(0)
|
let autoPanId = $ref(0)
|
||||||
let autoPanStarted = $ref(false)
|
let autoPanStarted = $ref(false)
|
||||||
let previousTransform = $ref<XYPosition>({ x: 0, y: 0 })
|
|
||||||
|
|
||||||
const getPointerPosition = useGetPointerPosition()
|
const getPointerPosition = useGetPointerPosition()
|
||||||
|
|
||||||
@@ -120,16 +119,9 @@ function useDrag(params: UseDragParams) {
|
|||||||
y: (lastPos.y ?? 0) - yMovement / viewport.zoom,
|
y: (lastPos.y ?? 0) - yMovement / viewport.zoom,
|
||||||
}
|
}
|
||||||
|
|
||||||
panBy({ x: xMovement, y: yMovement }, (transform) => {
|
if (panBy({ x: xMovement, y: yMovement })) {
|
||||||
if (
|
updateNodes(nextPos)
|
||||||
Math.round(transform.x) !== Math.round(previousTransform.x) ||
|
}
|
||||||
Math.round(transform.y) !== Math.round(previousTransform.y)
|
|
||||||
) {
|
|
||||||
updateNodes(nextPos)
|
|
||||||
previousTransform = transform
|
|
||||||
lastPos = nextPos
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
autoPanId = requestAnimationFrame(autoPan)
|
autoPanId = requestAnimationFrame(autoPan)
|
||||||
|
|||||||
@@ -629,11 +629,11 @@ export function useActions(
|
|||||||
return partiallyVisible || overlappingArea >= Number(nodeOrRect.width) * Number(nodeOrRect.height)
|
return partiallyVisible || overlappingArea >= Number(nodeOrRect.width) * Number(nodeOrRect.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
const panBy: Actions['panBy'] = (delta, onBeforeTransform) => {
|
const panBy: Actions['panBy'] = (delta) => {
|
||||||
const { viewport, dimensions, d3Zoom, d3Selection, translateExtent } = state
|
const { viewport, dimensions, d3Zoom, d3Selection, translateExtent } = state
|
||||||
|
|
||||||
if (!d3Zoom || !d3Selection || (!delta.x && !delta.y)) {
|
if (!d3Zoom || !d3Selection || (!delta.x && !delta.y)) {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextTransform = zoomIdentity.translate(viewport.x + delta.x, viewport.y + delta.y).scale(viewport.zoom)
|
const nextTransform = zoomIdentity.translate(viewport.x + delta.x, viewport.y + delta.y).scale(viewport.zoom)
|
||||||
@@ -645,9 +645,13 @@ export function useActions(
|
|||||||
|
|
||||||
const constrainedTransform = d3Zoom.constrain()(nextTransform, extent, translateExtent)
|
const constrainedTransform = d3Zoom.constrain()(nextTransform, extent, translateExtent)
|
||||||
|
|
||||||
onBeforeTransform?.(constrainedTransform)
|
|
||||||
|
|
||||||
d3Zoom.transform(d3Selection, constrainedTransform)
|
d3Zoom.transform(d3Selection, constrainedTransform)
|
||||||
|
|
||||||
|
return (
|
||||||
|
state.viewport.x !== constrainedTransform.x ||
|
||||||
|
state.viewport.y !== constrainedTransform.y ||
|
||||||
|
state.viewport.zoom !== constrainedTransform.k
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const setState: Actions['setState'] = (options) => {
|
const setState: Actions['setState'] = (options) => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { CSSProperties, ComputedRef, ToRefs } from 'vue'
|
import type { CSSProperties, ComputedRef, ToRefs } from 'vue'
|
||||||
import type { KeyFilter } from '@vueuse/core'
|
import type { KeyFilter } from '@vueuse/core'
|
||||||
import type { ZoomTransform } from 'd3-zoom'
|
|
||||||
import type {
|
import type {
|
||||||
Dimensions,
|
Dimensions,
|
||||||
ElementData,
|
ElementData,
|
||||||
@@ -266,8 +265,8 @@ export interface Actions extends ViewportFunctions {
|
|||||||
getIntersectingNodes: GetIntersectingNodes
|
getIntersectingNodes: GetIntersectingNodes
|
||||||
/** check if a node is intersecting with a defined area */
|
/** check if a node is intersecting with a defined area */
|
||||||
isNodeIntersecting: IsNodeIntersecting
|
isNodeIntersecting: IsNodeIntersecting
|
||||||
/** pan the viewport */
|
/** pan the viewport; return indicates if a transform has happened or not */
|
||||||
panBy: (delta: XYPosition, onBeforeTransform?: (transform: ZoomTransform) => void) => void
|
panBy: (delta: XYPosition) => boolean
|
||||||
|
|
||||||
/** reset state to defaults */
|
/** reset state to defaults */
|
||||||
$reset: () => void
|
$reset: () => void
|
||||||
|
|||||||
Reference in New Issue
Block a user