如何检查我的 Cytoscape.js 图形在平移 and/or 缩放后是否超出视图(甚至部分)?

How to check if my Cytoscape.js graph is out of view (even partially) after panning and/or zooming?

我想检查我的图形是否在视图之外,也许在平移 and/or 缩放之后,以便我可以激活 Cytoscape 导航器。

示例:

这些都看不见

但这不是:

谢谢。

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;
}