最佳答案
function isGraphOutOfView() {
const width = cy.width();
const height = cy.height();
const boundingBox = cy.elements().boundingbox();
const pan = cy.pan();
const zoom = cy.zoom();
return boundingBox.x1 * zoom + pan.x < 0
|| boundingBox.y1 * zoom + pan.y < 0
|| boundingBox.x2 * zoom + pan.x > width
|| boundingBox.y2 * zoom + pan.y > height;
}
编辑:使用renderedBoundingBox
:
function isGraphOutOfView() {
const width = cy.width();
const height = cy.height();
const rbb = cy.elements().renderedBoundingbox();
return rbb.x1 < 0 || rbb.y1 < 0 || rbb.x2 > width || rbb.y2 > height;
}
关于javascript - 如何检查平移和/或缩放后我的 Cytoscape.js 图表是否在 View 之外(甚至部分)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55057075/