Skip to content

Commit

Permalink
chore: card的移动边界,以graph.container为准
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiangyu committed Nov 9, 2023
1 parent 0752357 commit ecb644a
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions packages/g6/src/stdlib/plugin/annotation/cardEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,18 @@ export function bindCardEvent({ plugin, card, itemId }: { plugin: Annotation; ca
requestAnimationFrame(() => {
registerMove = false
console.log('clientX, clientY', clientX, clientY)
const graphBBox = calcGraphBBox()
const containerBBox = plugin.graph.container.getBoundingClientRect()
let left = clientX - shiftX, top = clientY - shiftY;

if (left > graphBBox.width - bbox.width) {
left = graphBBox.width - bbox.width
if (left > containerBBox.width - bbox.width) {
left = containerBBox.width - bbox.width
}
if (left < 0) {
left = 0
}

if (top > graphBBox.height - bbox.height) {
top = graphBBox.height - bbox.height
if (top > containerBBox.height - bbox.height) {
top = containerBBox.height - bbox.height
}
if (top < 0) {
top = 0
Expand Down Expand Up @@ -210,16 +210,4 @@ export function bindCardEvent({ plugin, card, itemId }: { plugin: Annotation; ca
plugin.options.onAnnotationChange?.(cardInfoMap[itemId], 'update');
}, { once: true })
})

function calcGraphBBox() {
const graph = plugin.graph
const [width, height] = graph.getSize();
const { x: left, y: top } = graph.canvas.viewport2Client({ x: 0, y: 0 });
const { x: right, y: bottom } = graph.canvas.viewport2Client({ x: width, y: height });
return {
left, right,
top, bottom,
width: right - left, height: bottom - top,
}
}
}

0 comments on commit ecb644a

Please sign in to comment.